I'm working on a 64 bit kernel for the first time and stuck with interrupts.
What my problem is :
When I load my IDT and call
Code: Select all
sti
continously fire interrupt no 13.(General Protection Fault)
I temporarily disabled PIC and that went away. (I was
thinking that maybe the problem was with the fact that I
haven't remapped the PIC yet)
However when I try to raise a software interrupt(using int
$0x1 etc) I again get the general protection fault. I read
here that gpe interrupt pushes RIP(instruction pointer) to
help figure out the faulty instruction. So I took this value
and compared it with the objdump of my kernel. It points
to some instruction in my
Code: Select all
isr_common_stub
Code: Select all
%macro Fill_IDT_Entry 2
mov qword rax, %1Handler%2
mov word [rbx], ax
mov word [rbx+2], 0x08
mov word [rbx+4], 0b1000111100000000
shr qword rax, 16
mov word [rbx+6], ax
shr qword rax, 16
mov dword [rbx+8], eax
mov dword [rbx+12], 0
add rbx, 16
%endmacro
setup_interrupts:
; disbale PIC
mov al, 0xff
out 0xa1, al
out 0x21, al
mov qword rbx, idt
; ISR
Fill_IDT_Entry isr, 0
Fill_IDT_Entry isr, 1
Fill_IDT_Entry isr, 2
Fill_IDT_Entry isr, 3
Fill_IDT_Entry isr, 4
Fill_IDT_Entry isr, 5
Fill_IDT_Entry isr, 6
Fill_IDT_Entry isr, 7
Fill_IDT_Entry isr, 8
Fill_IDT_Entry isr, 9
Fill_IDT_Entry isr, 10
Fill_IDT_Entry isr, 11
Fill_IDT_Entry isr, 12
Fill_IDT_Entry isr, 13
Fill_IDT_Entry isr, 14
Fill_IDT_Entry isr, 15
...
lidt [idt.idt_pointer]
ret
Code: Select all
%macro ISR_Handler 1
isrHandler%1:
cli
mov rdi, %1
mov rsi, 0
pop rdx
jmp isr_common_stub
%endmacro
%macro ISR_Handler_ERR 1
isrHandler%1:
cli
mov rdi, %1
pop rsi
pop rdx
jmp isr_common_stub
%endmacro
%macro pushallregisters 0
push rax
push rcx
push rdx
push rdi
push rsi
push r8
push r9
push r10
push r11
%endmacro
%macro popallregisters 0
pop r11
pop r10
pop r9
pop r8
pop rsi
pop rdi
pop rdx
pop rcx
pop rax
%endmacro
isr_common_stub:
pushallregisters
call kernel_isr_handler
popallregisters
sti
iretq
ISR_Handler 0
ISR_Handler 1
ISR_Handler 2
ISR_Handler 3
ISR_Handler 4
ISR_Handler 5
ISR_Handler 6
ISR_Handler 7
ISR_Handler_ERR 8
ISR_Handler 9
ISR_Handler_ERR 10
ISR_Handler_ERR 11
ISR_Handler_ERR 12
ISR_Handler_ERR 13
ISR_Handler_ERR 14
ISR_Handler 15
...