Implement PIT interrupts
This commit is contained in:
@ -6,6 +6,9 @@
|
||||
#include "hal/hal.h"
|
||||
#include "kprintf.h"
|
||||
#include "compiler/attr.h"
|
||||
#include "pic.h"
|
||||
#include "apic.h"
|
||||
#include "pit.h"
|
||||
|
||||
void hal_intr_disable(void) {
|
||||
asm volatile("cli");
|
||||
@ -104,54 +107,58 @@ static const char *exceptions[] = {
|
||||
"#CP",
|
||||
};
|
||||
|
||||
extern void intr_vec0(void);
|
||||
extern void intr_vec1(void);
|
||||
extern void intr_vec2(void);
|
||||
extern void intr_vec3(void);
|
||||
extern void intr_vec4(void);
|
||||
extern void intr_vec5(void);
|
||||
extern void intr_vec6(void);
|
||||
extern void intr_vec7(void);
|
||||
extern void intr_vec8(void);
|
||||
extern void intr_vec10(void);
|
||||
extern void intr_vec11(void);
|
||||
extern void intr_vec12(void);
|
||||
extern void intr_vec13(void);
|
||||
extern void intr_vec14(void);
|
||||
extern void intr_vec16(void);
|
||||
extern void intr_vec17(void);
|
||||
extern void intr_vec18(void);
|
||||
extern void intr_vec19(void);
|
||||
extern void intr_vec20(void);
|
||||
extern void intr_vec21(void);
|
||||
extern void intr_vec32(void);
|
||||
extern void intr_vec33(void);
|
||||
extern void intr_vec39(void);
|
||||
|
||||
void intr_init(void) {
|
||||
idt_setentry(0, (uint64_t)&intr_vec0, 0, 0x8E);
|
||||
idt_setentry(1, (uint64_t)&intr_vec1, 0, 0x8E);
|
||||
idt_setentry(2, (uint64_t)&intr_vec2, 2, 0x8E);
|
||||
idt_setentry(3, (uint64_t)&intr_vec3, 0, 0x8E);
|
||||
idt_setentry(4, (uint64_t)&intr_vec4, 0, 0x8E);
|
||||
idt_setentry(5, (uint64_t)&intr_vec5, 0, 0x8E);
|
||||
idt_setentry(6, (uint64_t)&intr_vec6, 0, 0x8E);
|
||||
idt_setentry(7, (uint64_t)&intr_vec7, 0, 0x8E);
|
||||
idt_setentry(8, (uint64_t)&intr_vec8, 1, 0x8E);
|
||||
idt_setentry(10, (uint64_t)&intr_vec10, 0, 0x8E);
|
||||
idt_setentry(11, (uint64_t)&intr_vec11, 0, 0x8E);
|
||||
idt_setentry(12, (uint64_t)&intr_vec12, 0, 0x8E);
|
||||
idt_setentry(13, (uint64_t)&intr_vec13, 0, 0x8E);
|
||||
idt_setentry(14, (uint64_t)&intr_vec14, 0, 0x8E);
|
||||
idt_setentry(16, (uint64_t)&intr_vec16, 0, 0x8E);
|
||||
idt_setentry(17, (uint64_t)&intr_vec17, 0, 0x8E);
|
||||
idt_setentry(18, (uint64_t)&intr_vec18, 0, 0x8E);
|
||||
idt_setentry(19, (uint64_t)&intr_vec19, 0, 0x8E);
|
||||
idt_setentry(20, (uint64_t)&intr_vec20, 0, 0x8E);
|
||||
idt_setentry(21, (uint64_t)&intr_vec21, 0, 0x8E);
|
||||
idt_setentry(32, (uint64_t)&intr_vec32, 0, 0x8E);
|
||||
idt_setentry(33, (uint64_t)&intr_vec33, 0, 0x8E);
|
||||
idt_setentry(39, (uint64_t)&intr_vec39, 0, 0x8E);
|
||||
#define MKINTR(N, IST) \
|
||||
extern void intr_vec##N(void); \
|
||||
idt_setentry(N, (uint64_t)&intr_vec##N, IST, 0x8E);
|
||||
|
||||
MKINTR(0, 0);
|
||||
MKINTR(1, 0);
|
||||
MKINTR(2, 2);
|
||||
MKINTR(4, 0);
|
||||
MKINTR(5, 0);
|
||||
MKINTR(6, 0);
|
||||
MKINTR(7, 0);
|
||||
MKINTR(8, 1);
|
||||
MKINTR(9, 0);
|
||||
MKINTR(10, 0);
|
||||
MKINTR(11, 0);
|
||||
MKINTR(12, 0);
|
||||
MKINTR(13, 0);
|
||||
MKINTR(14, 0);
|
||||
MKINTR(15, 0);
|
||||
MKINTR(16, 0);
|
||||
MKINTR(17, 0);
|
||||
MKINTR(18, 0);
|
||||
MKINTR(19, 0);
|
||||
MKINTR(20, 0);
|
||||
MKINTR(21, 0);
|
||||
MKINTR(22, 0);
|
||||
MKINTR(23, 0);
|
||||
MKINTR(24, 0);
|
||||
MKINTR(25, 0);
|
||||
MKINTR(26, 0);
|
||||
MKINTR(27, 0);
|
||||
MKINTR(28, 0);
|
||||
MKINTR(29, 0);
|
||||
MKINTR(30, 0);
|
||||
MKINTR(31, 0);
|
||||
MKINTR(32, 0);
|
||||
MKINTR(33, 0);
|
||||
MKINTR(34, 0);
|
||||
MKINTR(35, 0);
|
||||
MKINTR(36, 0);
|
||||
MKINTR(37, 0);
|
||||
MKINTR(38, 0);
|
||||
MKINTR(39, 0);
|
||||
MKINTR(40, 3);
|
||||
MKINTR(41, 0);
|
||||
MKINTR(42, 0);
|
||||
MKINTR(43, 0);
|
||||
MKINTR(44, 0);
|
||||
MKINTR(45, 0);
|
||||
MKINTR(46, 0);
|
||||
MKINTR(47, 0);
|
||||
|
||||
idt_init();
|
||||
}
|
||||
@ -175,9 +182,20 @@ void intr_dumpframe(IntrStackFrame *frame) {
|
||||
}
|
||||
|
||||
void intr_handleintr(IntrStackFrame *frame) {
|
||||
hal_intr_disable();
|
||||
ERR("ERROR", "%s, 0x%lX\n", exceptions[frame->trapnum], frame->errnum);
|
||||
intr_dumpframe(frame);
|
||||
hal_hang();
|
||||
if (frame->trapnum >= 0 && frame->trapnum <= 31) {
|
||||
// EXCEPTION
|
||||
ERR("ERROR", "%s, 0x%lX\n", exceptions[frame->trapnum], frame->errnum);
|
||||
intr_dumpframe(frame);
|
||||
hal_hang();
|
||||
} else if (frame->trapnum >= 32 && frame->trapnum <= 47) {
|
||||
if (frame->trapnum == INTR_TIMER) {
|
||||
kprintf("ACK %d\n", PIT_TICKS);
|
||||
PIT_TICKS++;
|
||||
io_out8(PIC2_CMD, 0x20);
|
||||
}
|
||||
|
||||
io_out8(PIC1_CMD, 0x20);
|
||||
lapic_write(LAPIC_EOI, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user