-static uint64_t
-make_intr_gate (void (*target) (void), int dpl)
-{
- return make_gate (target, dpl, TYPE_INT_32);
-}
-
-static uint64_t
-make_trap_gate (void (*target) (void), int dpl)
-{
- return make_gate (target, dpl, TYPE_TRAP_32);
-}
-
-void
-intr_register (uint8_t vec_no, int dpl, enum if_level level,
- intr_handler_func *handler,
- const char *name)
-{
- /* Interrupts generated by external hardware (0x20 <= VEC_NO <=
- 0x2f) should specify IF_OFF for LEVEL. Otherwise a timer
- interrupt could cause a task switch during interrupt
- handling. Most other interrupts can and should be handled
- with interrupts enabled. */
- ASSERT (vec_no < 0x20 || vec_no > 0x2f || level == IF_OFF);
-
- if (level == IF_ON)
- idt[vec_no] = make_trap_gate (intr_stubs[vec_no], dpl);
- else
- idt[vec_no] = make_intr_gate (intr_stubs[vec_no], dpl);
- intr_handlers[vec_no] = handler;
- intr_names[vec_no] = name;
-}
-
-void
-intr_init (void)
-{
- uint64_t idtr_operand;
- int i;
-
- pic_init ();
-
- /* Install default handlers. */
- for (i = 0; i < 256; i++)
- intr_register (i, 0, IF_OFF, intr_panic, NULL);
-
- /* Most exceptions require ring 0.
- Exceptions 3, 4, and 5 can be caused by ring 3 directly. */
- intr_register (0, 0, IF_ON, intr_kill, "#DE Divide Error");
- intr_register (1, 0, IF_ON, intr_kill, "#DB Debug Exception");
- intr_register (2, 0, IF_ON, intr_panic, "NMI Interrupt");
- intr_register (3, 3, IF_ON, intr_kill, "#BP Breakpoint Exception");
- intr_register (4, 3, IF_ON, intr_kill, "#OF Overflow Exception");
- intr_register (5, 3, IF_ON, intr_kill, "#BR BOUND Range Exceeded Exception");
- intr_register (6, 0, IF_ON, intr_kill, "#UD Invalid Opcode Exception");
- intr_register (7, 0, IF_ON, intr_kill, "#NM Device Not Available Exception");
- intr_register (8, 0, IF_ON, intr_panic, "#DF Double Fault Exception");
- intr_register (9, 0, IF_ON, intr_panic, "Coprocessor Segment Overrun");
- intr_register (10, 0, IF_ON, intr_panic, "#TS Invalid TSS Exception");
- intr_register (11, 0, IF_ON, intr_kill, "#NP Segment Not Present");
- intr_register (12, 0, IF_ON, intr_kill, "#SS Stack Fault Exception");
- intr_register (13, 0, IF_ON, intr_kill, "#GP General Protection Exception");
- intr_register (16, 0, IF_ON, intr_kill, "#MF x87 FPU Floating-Point Error");
- intr_register (17, 0, IF_ON, intr_panic, "#AC Alignment Check Exception");
- intr_register (18, 0, IF_ON, intr_panic, "#MC Machine-Check Exception");
- intr_register (19, 0, IF_ON, intr_kill, "#XF SIMD Floating-Point Exception");
-
- /* Most exceptions can be handled with interrupts turned on.
- We need to disable interrupts for page faults because the
- fault address is stored in CR2 and needs to be preserved. */
- intr_register (14, 0, IF_OFF, intr_kill, "#PF Page-Fault Exception");
-
- idtr_operand = make_dtr_operand (sizeof idt - 1, idt);
- asm volatile ("lidt %0" :: "m" (idtr_operand));
-}
-
-static void
-dump_intr_frame (struct intr_frame *f)
-{
- uint32_t cr2, ss;