1000Hz PIC timer working + IDT dispatch/handler fixes
This commit is contained in:
135
src/idt/idt.S
135
src/idt/idt.S
@@ -34,22 +34,22 @@ interrupt_stub:
|
||||
; executed when the interrupt happened.
|
||||
; (except rsp because it will already be saved in the iret frame)
|
||||
|
||||
push rax
|
||||
push rbx
|
||||
push rcx
|
||||
push rdx
|
||||
push rsi
|
||||
push rdi
|
||||
push rsp
|
||||
push rbp
|
||||
push r8
|
||||
push r9
|
||||
push r10
|
||||
push r11
|
||||
push r12
|
||||
push r13
|
||||
push r14
|
||||
push r15
|
||||
push qword rax
|
||||
push qword rbx
|
||||
push qword rcx
|
||||
push qword rdx
|
||||
push qword rsi
|
||||
push qword rdi
|
||||
;push qword rsp
|
||||
push qword rbp
|
||||
push qword r8
|
||||
push qword r9
|
||||
push qword r10
|
||||
push qword r11
|
||||
push qword r12
|
||||
push qword r13
|
||||
push qword r14
|
||||
push qword r15
|
||||
|
||||
; Put stack pointer as first argument of our function
|
||||
mov rdi, rsp
|
||||
@@ -57,22 +57,22 @@ interrupt_stub:
|
||||
; What the function returns (new stack pointer) is saved in rbp
|
||||
mov rsp, rax
|
||||
|
||||
pop r15
|
||||
pop r14
|
||||
pop r13
|
||||
pop r12
|
||||
pop r11
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
pop rbp
|
||||
pop rsp
|
||||
pop rdi
|
||||
pop rsi
|
||||
pop rdx
|
||||
pop rcx
|
||||
pop rbx
|
||||
pop rax
|
||||
pop qword r15
|
||||
pop qword r14
|
||||
pop qword r13
|
||||
pop qword r12
|
||||
pop qword r11
|
||||
pop qword r10
|
||||
pop qword r9
|
||||
pop qword r8
|
||||
pop qword rbp
|
||||
;pop qword rsp
|
||||
pop qword rdi
|
||||
pop qword rsi
|
||||
pop qword rdx
|
||||
pop qword rcx
|
||||
pop qword rbx
|
||||
pop qword rax
|
||||
|
||||
; Removing the error code and vector number so stack doesn't
|
||||
; get corrupted
|
||||
@@ -80,7 +80,7 @@ interrupt_stub:
|
||||
|
||||
; Restore ss, rsp, rflags, cs, rip of code that was executing
|
||||
; before the interrupt
|
||||
iret
|
||||
iretq
|
||||
|
||||
; Vector handlers will be 16-byte aligned so that we can loop over them
|
||||
; like <vector_no> * 16 to get each one's address
|
||||
@@ -233,4 +233,71 @@ vector_21_handler:
|
||||
push qword 21
|
||||
jmp interrupt_stub
|
||||
|
||||
; The others are reserved (22->31) or external (32->255) interrupts
|
||||
; The others are reserved (22->31) or external (32->255) interrupts
|
||||
|
||||
align 16
|
||||
vector_22_handler:
|
||||
push qword 0
|
||||
push qword 22
|
||||
jmp interrupt_stub
|
||||
|
||||
align 16
|
||||
vector_23_handler:
|
||||
push qword 0
|
||||
push qword 23
|
||||
jmp interrupt_stub
|
||||
|
||||
align 16
|
||||
vector_24_handler:
|
||||
push qword 0
|
||||
push qword 24
|
||||
jmp interrupt_stub
|
||||
|
||||
align 16
|
||||
vector_25_handler:
|
||||
push qword 0
|
||||
push qword 25
|
||||
jmp interrupt_stub
|
||||
|
||||
align 16
|
||||
vector_26_handler:
|
||||
push qword 0
|
||||
push qword 26
|
||||
jmp interrupt_stub
|
||||
|
||||
align 16
|
||||
vector_27_handler:
|
||||
push qword 0
|
||||
push qword 27
|
||||
jmp interrupt_stub
|
||||
|
||||
align 16
|
||||
vector_28_handler:
|
||||
push qword 0
|
||||
push qword 28
|
||||
jmp interrupt_stub
|
||||
|
||||
align 16
|
||||
vector_29_handler:
|
||||
push qword 0
|
||||
push qword 29
|
||||
jmp interrupt_stub
|
||||
|
||||
align 16
|
||||
vector_30_handler:
|
||||
push qword 0
|
||||
push qword 30
|
||||
jmp interrupt_stub
|
||||
|
||||
align 16
|
||||
vector_31_handler:
|
||||
push qword 0
|
||||
push qword 31
|
||||
jmp interrupt_stub
|
||||
|
||||
; PIT timer
|
||||
align 16
|
||||
vector_32_handler:
|
||||
push qword 0
|
||||
push qword 32
|
||||
jmp interrupt_stub
|
||||
@@ -9,6 +9,9 @@ struct idtr idt_reg;
|
||||
// Address to our first interrupt handler
|
||||
extern char vector_0_handler[];
|
||||
|
||||
// Timer ticks
|
||||
extern uint64_t ticks;
|
||||
|
||||
void idt_set_entry(uint8_t vector, void* handler, uint8_t dpl)
|
||||
{
|
||||
uint64_t handler_addr = (uint64_t)handler;
|
||||
@@ -119,6 +122,13 @@ struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context)
|
||||
serial_kputs("kernel: idt: Control Protection Exception!\n");
|
||||
break;
|
||||
|
||||
case 32:
|
||||
serial_kputs("Tick!");
|
||||
ticks++;
|
||||
// Send an EOI so that we can continue having interrupts
|
||||
outb(0x20, 0x20);
|
||||
break;
|
||||
|
||||
default:
|
||||
serial_kputs("kernel: idt: Unexpected interrupt\n");
|
||||
break;
|
||||
|
||||
@@ -36,7 +36,7 @@ struct cpu_status_t
|
||||
uint64_t r9;
|
||||
uint64_t r8;
|
||||
uint64_t rbp;
|
||||
uint64_t rsp;
|
||||
//uint64_t rsp;
|
||||
uint64_t rdi;
|
||||
uint64_t rsi;
|
||||
uint64_t rdx;
|
||||
|
||||
Reference in New Issue
Block a user