2 * GeekOS interrupt handling data structures and functions
3 * Copyright (c) 2001,2003 David H. Hovemeyer <daveho@cs.umd.edu>
6 * This is free software. You are permitted to use,
7 * redistribute, and modify it as specified in the file "COPYING".
10 #include <geekos/idt.h> /* x86-specific int handling stuff */
11 #include <geekos/screen.h>
12 #include <geekos/kassert.h>
13 #include <geekos/int.h>
14 #include <geekos/irq.h>
15 #include <geekos/debug.h>
17 #include <geekos/cpu.h>
20 * Defined in lowlevel.asm.
22 ulong_t Get_Current_EFLAGS(void);
24 /* ----------------------------------------------------------------------
25 * Private functions and data
26 * ---------------------------------------------------------------------- */
29 * A dummy interrupt handler function.
30 * Ensures that the low-level interrupt code always
31 * has a handler to call.
33 static void Dummy_Interrupt_Handler(struct Interrupt_State* state)
37 PrintBoth("*** Unexpected interrupt! *** Ignoring!\n");
38 Dump_Interrupt_State(state);
46 static void Print_Selector(const char* regName, uint_t value)
48 PrintBoth("%s: index=%d, ti=%d, rpl=%d\n",
49 regName, value >> 3, (value >> 2) & 1, value & 3);
54 /* ----------------------------------------------------------------------
56 * ---------------------------------------------------------------------- */
59 * Initialize the interrupt system.
61 void Init_Interrupts(void)
65 PrintBoth("Initializing Interrupts\n");
67 /* Low-level initialization. Build and initialize the IDT. */
71 * Initialize all entries of the handler table with a dummy handler.
72 * This will ensure that we always have a handler function to call.
74 for (i = 0; i < NUM_IDT_ENTRIES; ++i) {
75 Install_Interrupt_Handler(i, Dummy_Interrupt_Handler);
78 /* Re-enable interrupts */
83 * Query whether or not interrupts are currently enabled.
85 bool Interrupts_Enabled(void)
87 ulong_t eflags = Get_Current_EFLAGS();
88 return (eflags & EFLAGS_IF) != 0;
92 * Dump interrupt state struct to screen
94 void Dump_Interrupt_State(struct Interrupt_State* state)
96 uint_t errorCode = state->errorCode;
98 PrintBoth("eax=%08x ebx=%08x ecx=%08x edx=%08x\n"
99 "esi=%08x edi=%08x ebp=%08x\n"
100 "eip=%08x cs=%08x eflags=%08x\n"
101 "Interrupt number=%d, error code=%d\n"
102 "index=%d, TI=%d, IDT=%d, EXT=%d\n",
103 state->eax, state->ebx, state->ecx, state->edx,
104 state->esi, state->edi, state->ebp,
105 state->eip, state->cs, state->eflags,
106 state->intNum, errorCode,
107 errorCode >> 3, (errorCode >> 2) & 1, (errorCode >> 1) & 1, errorCode & 1
109 if (Is_User_Interrupt(state)) {
110 struct User_Interrupt_State *ustate = (struct User_Interrupt_State*) state;
111 PrintBoth("user esp=%08x, user ss=%08x\n", ustate->espUser, ustate->ssUser);
113 Print_Selector("cs", state->cs);
114 Print_Selector("ds", state->ds);
115 Print_Selector("es", state->es);
116 Print_Selector("fs", state->fs);
117 Print_Selector("gs", state->gs);