How to patch 0x1c interrupt handler in protected mode
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to patch 0x1c interrupt handler in protected mode
As a part of a larger project I need to patch the timer interrupt so it switches to my handler. The main language is c but some parts are done in assembly. The architecture is x86 32-bit. The solution should be as portable between opereating systems as possible. I am trying to do it in assembly (nasm).
I tried to do it with _sidt_ and then trying to point the 0x1c vector to my routine but it doesn't work. Here is the code:
Code:
CPU 386
segment .bss
idt: resb 6
segment .text
; variables
extern idtp, idtl, old_segment, old_offset
; functions
extern setIVT, checkIDT, intRoutine
global setIVTasm
setIVTasm:
cli
push eax
;call setIVT
xor eax, eax
sidt [idt]
;store IDTP to idtp
mov eax, [idt + 2]
mov [idtp], eax
;store IDT Limit to idtl
mov eax, [idt]
mov [idtl], eax
; save old int handler
xor eax, eax
; save old segment
mov ax, [idtp + 2]
mov [old_segment], ax
; save old offset low word
mov ax, [idtp]
mov [old_offset], ax
; save old offset high word
mov ax, [idtp + 6]
mov [old_offset + 2], ax
call checkIDT
; set new int handler
xor eax, eax
; set new segment
mov ax, cs
mov [idtp + 2], ax
; set new offset low word
mov ax, [intRoutineAsm]
mov [idtp], ax
; set new offset high word
mov ax, [intRoutineAsm + 2]
mov [idtp + 6], ax
pop eax
sti
ret
In any modern operating-system .. Linux, Windows, OS/X, whatever .. you don't have direct access to interrupts, vectors and so-forth.
You do have various kinds of asynchronous notifications, timers, and so-forth. In the Unix-variant systems, these are called signals, and the specific signal you're interested in here is named SIGALARM.
(By the way, this is the same mechanism Unix/Linux uses to handle other things, like program errors or your decision to kill a program. All of these result in a signal being issued.)
Forget about the hardware: you can't control it; can't touch it. You're not allowed, and with very good reason! But you can ask the operating-system to send a signal to your process, say, approximately so-many times a second. Then you define a handler routine to service the signal. When the signal arrives, your program will be diverted to the handler routine, asynchronously.
All of this signal-handling occurs comfortably within the context of your own process.
You do not get "precision intervals." You do not get guaranteed latency.
Standard libraries in various languages all provide for some analog of this facility and it can be expected to be portable across any operating-system without source-code changes.
Last edited by sundialsvcs; 04-04-2007 at 07:54 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.