|
@@ -30,6 +30,7 @@ _start:
|
|
|
|
|
|
|
|
call setup_stack
|
|
call setup_stack
|
|
|
call init_gdt
|
|
call init_gdt
|
|
|
|
|
+ call init_idt
|
|
|
call setup_paging
|
|
call setup_paging
|
|
|
|
|
|
|
|
|
|
|
|
@@ -102,6 +103,42 @@ spl: stosq
|
|
|
|
|
|
|
|
ret
|
|
ret
|
|
|
|
|
|
|
|
|
|
+init_idt:
|
|
|
|
|
+ leaq default_int_handler(%rip), %rdx
|
|
|
|
|
+ movq $(8 << 16), %rax
|
|
|
|
|
+
|
|
|
|
|
+ movw %dx, %ax
|
|
|
|
|
+
|
|
|
|
|
+ /* 0x8e: interrupt gate */
|
|
|
|
|
+ movq $(0x8e00 << 32), %rcx
|
|
|
|
|
+ addq %rcx, %rax
|
|
|
|
|
+
|
|
|
|
|
+ movl %edx, %ecx
|
|
|
|
|
+
|
|
|
|
|
+ shrl $16, %ecx
|
|
|
|
|
+ shlq $48, %rcx
|
|
|
|
|
+
|
|
|
|
|
+ addq %rcx, %rax
|
|
|
|
|
+ shrq $32, %rdx
|
|
|
|
|
+
|
|
|
|
|
+ movq $256, %rcx
|
|
|
|
|
+ leaq idt(%rip), %rdi
|
|
|
|
|
+
|
|
|
|
|
+rsidt: movq %rax, (%rdi)
|
|
|
|
|
+ movq %rdx, 8(%rdi)
|
|
|
|
|
+ addq $16, %rdi
|
|
|
|
|
+
|
|
|
|
|
+ decq %rcx
|
|
|
|
|
+ jnz rsidt
|
|
|
|
|
+
|
|
|
|
|
+ lidt idt_descr(%rip)
|
|
|
|
|
+
|
|
|
|
|
+ ret
|
|
|
|
|
+
|
|
|
|
|
+default_int_handler:
|
|
|
|
|
+ incq 0xb8000
|
|
|
|
|
+ iretq
|
|
|
|
|
+
|
|
|
|
|
|
|
|
.globl __stack_chk_fail
|
|
.globl __stack_chk_fail
|
|
|
|
|
|
|
@@ -129,6 +166,8 @@ gdt_descr:
|
|
|
|
|
|
|
|
.globl idt
|
|
.globl idt
|
|
|
|
|
|
|
|
|
|
+.align 16
|
|
|
|
|
+
|
|
|
idt: .fill 512, 8, 0
|
|
idt: .fill 512, 8, 0
|
|
|
|
|
|
|
|
idt_descr:
|
|
idt_descr:
|