; vi:filetype=nasm ts=8 sts=8 sw=8:
section .text
+%define INTR_ASM_
%include "intr.inc"
+GATE_INTR equ 0600h
+GATE_TRAP equ 0700h
+GATE_DEFAULT equ 0800h
+GATE_PRESENT equ 8000h
+
global init_intr
init_intr:
call init_pic
global set_intr
set_intr:
+ push ebp
+ mov ebp, esp
+ push ebx
+
+ mov ebx, [ebp + 8]
+ mov eax, GATE_TRAP
+ cmp ebx, 32 ; determine if it's an IRQ or an exception (trap)
+ jb .notirq
+ mov eax, GATE_INTR
+.notirq:
+ shl ebx, 1
+ lea ebx, [ebx * 8 + idt] ; ebx <- pointer to gate descriptor
+ ; type|dpl goes to the 3rd dword of the descriptor (dpl is 0)
+ or eax, (GATE_DEFAULT | GATE_PRESENT)
+ mov [ebx + 8], eax
+ ; address low 16bits go to the first dword of the descriptor
+ mov eax, [ebp + 12]
+ mov [ebx], ax
+ ; address high 16bits go to the last dword of the descriptor
+ shr eax, 16
+ mov [ebx + 12], eax
+ ; selector (kcode:1) goes to the second dword of the descriptor
+ mov dword [ebx + 4], 08h
+
+ pop ebx
+ pop ebp
ret
PIC1_CMD equ 20h