Page 1 of 1
Interrupt help
Posted: Sat Aug 31, 2002 7:21 pm
by beyondsociety
Could Somebody give me a example of how to create and set up a interrupt handler.
Also examples of how to program the pic and the interrupt service routine.
Re:Interrupt help
Posted: Sat Aug 31, 2002 9:46 pm
by Warmaster199
Interrupt handler entry point...
Code: Select all
push gs
push fs
push es
push ds
push ss
pusha
mov eax, KERNEL_DS
mov ds,eax
mov es,eax
mov fs,eax
mov gs,eax
sti
mov eax,esp
push eax
mov eax, _handler_name
call eax
add esp,4
pop eax
cli
popa
pop ss
pop ds
pop es
pop fs
pop gs
iret
Set-up an interrupt gate... Set-up the idt first for this to work. To set a vector(Intr gate), call as:
void set_intr_gate(int vector, void *addr);
...and now:
Code: Select all
_set_intr_gate:
push ebp
mov ebp,esp
push ebx
pushad
mov eax,8
mul byte [ebp + 8]
mov ebx,eax
add ebx,idt
mov eax,[ebp + 12]
mov [ebx],ax
shr eax,16
mov [ebx + 6],ax
popad
pop ebx
pop ebp
ret
; 256 ring 0 interrupt gates
idt:
%rep 256
dw 0
dw KERNEL_CS
db 0
db 8Eh
dw 0
%endrep
idt_end:
idt_ptr:
dw idt_end - idt - 1
dd idt
...MANY OS'es made by us hobbyist use the above code or something very similar. LINUX has a similar variant. Mainly because this is the only easy way to do it...