Here is my IDT code:
Code: Select all
; idt
; setup the IDT
IDT_init:
; exceptions to go here too
mov ebx, 0x20 ; timer
mov ecx, [_irq0]
call IDT_addint
mov ebx, 0x21 ; keyboard
mov ecx, [_irq1]
call IDT_addint
lidt [IDT_list]
sti
ret
IDT_list:
rept 256 ; repeat 256 times (FASM style loop)
{
dw 0 ; offset
dw 0x0008 ; kernel segment
db 00000000b
db 00001110b ; 1st byte = is segment present
dw 0 ; offset
}
IDT_listend:
IDT_listpointer: dw IDT_listend - IDT_list - 1
dd IDT_list
; add an idt entry, ebx = int number, ecx = pointer to function
IDT_addint:
mov esi, ecx
and esi, 0xFFFF
mov eax, esi
mov edi, [(IDT_list + (ebx * 8))]
mov [edi], ax
mov esi, ecx
mov eax, esi
shr eax, 16
mov [edi + 6], ax
mov ax, 00001110b
mov [edi + 6], ax
ret
Code: Select all
; 32: IRQ0
_irq0:
cli
push 0
push 32
jmp irq_common_stub
; 33: IRQ1
_irq1:
cli
push 0
push 33
jmp irq_common_stub
irq_common_stub:
pusha
push ds
push es
push fs
push gs
; push eax
; mov eax, [handle_irq]
; call eax
; pop eax
call cls ; clear the screen, useless but I just want to get it working ATM
pop gs
pop fs
pop es
pop ds
popa
add esp, 8
iret
Code: Select all
Timer_enable:
mov cl, 0
call IRQ_enable
ret
Code: Select all
Keyboard_enable:
mov cl, 1
call IRQ_enable
ret
Code: Select all
PICs_remap:
mov al, 0x11
out 0x20, al
out 0xA0, al
mov al, 0x20
out 0x21, al
mov al, 0x28
out 0xA1, al
mov al, 0x04
out 0x21, al
mov al, 0x02
out 0xA1, al
mov al, 0x01
out 0x21, al
out 0xA1, al
mov al, 0xFF
out 0x21, al
mov al, 0xFB
out 0xA1, al
ret
; enable IRQ, cl = irq
IRQ_enable:
push ax
push cx
cmp cl, 8
jb .IRQ_enable_master
sub cl, 8
mov ah, 1
shl ah, cl
xor ah, 0xFF
in al, 0xA1
and al, ah
out 0xA1, al
pop cx
pop ax
ret
.IRQ_enable_master:
mov ah, 1
shl ah, cl
xor ah, 0xFF
in al, 0x21
and al, ah
out 0x21, al
pop cx
pop ax
ret
Code: Select all
lgdt [GDT_pointer]
call PICs_remap
; call Timer_init ; set timer to 100Hz
call IDT_init
; call Timer_enable ; commented out for now
call Keyboard_enable