2 * GeekOS interrupt handling data structures and functions
3 * Copyright (c) 2001, 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".
11 * This module describes the C interface which must be implemented
12 * by interrupt handlers, and has the initialization function
13 * for the interrupt system as a whole.
19 #include <geekos/kassert.h>
20 #include <geekos/ktypes.h>
21 #include <geekos/defs.h>
24 * This struct reflects the contents of the stack when
25 * a C interrupt handler function is called.
26 * It must be kept up to date with the code in "lowlevel.asm".
28 struct Interrupt_State {
30 * The register contents at the time of the exception.
31 * We save these explicitly.
46 * We explicitly push the interrupt number.
47 * This makes it easy for the handler function to determine
48 * which interrupt occurred.
53 * This may be pushed by the processor; if not, we push
54 * a dummy error code, so the stack layout is the same
55 * for every type of interrupt.
59 /* These are always pushed on the stack by the processor. */
66 * An interrupt that occurred in user mode.
67 * If Is_User_Interrupt(state) returns true, then the
68 * Interrupt_State object may be cast to this kind of struct.
70 struct User_Interrupt_State {
71 struct Interrupt_State state;
76 static __inline__ bool Is_User_Interrupt(struct Interrupt_State *state)
78 return (state->cs & 3) == USER_PRIVILEGE;
83 * The signature of an interrupt handler.
85 typedef void (*Interrupt_Handler)(struct Interrupt_State* state);
88 * Perform all low- and high-level initialization of the
91 void Init_Interrupts(void);
94 * Query whether or not interrupts are currently enabled.
96 bool Interrupts_Enabled(void);
101 static __inline__ void __Disable_Interrupts(void)
103 __asm__ __volatile__ ("cli");
105 #define Disable_Interrupts() \
107 KASSERT(Interrupts_Enabled()); \
108 __Disable_Interrupts(); \
112 * Unblock interrupts.
114 static __inline__ void __Enable_Interrupts(void)
116 __asm__ __volatile__ ("sti");
118 #define Enable_Interrupts() \
120 KASSERT(!Interrupts_Enabled()); \
121 __Enable_Interrupts(); \
125 * Dump interrupt state struct to screen
127 void Dump_Interrupt_State(struct Interrupt_State* state);
130 * Start interrupt-atomic region.
131 * @return true if interrupts were enabled at beginning of call,
134 static __inline__ bool Begin_Int_Atomic(void)
136 bool enabled = Interrupts_Enabled();
138 Disable_Interrupts();
143 * End interrupt-atomic region.
144 * @param iflag the value returned from the original Begin_Int_Atomic() call.
146 static __inline__ void End_Int_Atomic(bool iflag)
148 KASSERT(!Interrupts_Enabled());
150 /* Interrupts were originally enabled, so turn them back on */
155 #define EXCEPTION_DE 0 // Divide by zero
156 #define EXCEPTION_DB 1 // reserved
157 #define EXCEPTION_NMI 2 // NMI
158 #define EXCEPTION_BP 3 // Breakpoint
159 #define EXCEPTION_OF 4 // Overflow
160 #define EXCEPTION_BR 5 // Bound range exceeded
161 #define EXCEPTION_UD 6 // Undefined opcode
162 #define EXCEPTION_NM 7 // Math coprocessor gone missing
163 #define EXCEPTION_DF 8 // Double fault
164 #define EXCEPTION_CO 9 // Coprocessor segment overrrun
165 #define EXCEPTION_TS 10 // Invalid TSS
166 #define EXCEPTION_NP 11 // Segment not present
167 #define EXCEPTION_SS 12 // Stack segment fault
168 #define EXCEPTION_GP 13 // General Protection fault
169 #define EXCEPTION_PF 14 // Page Fault
170 #define EXCEPTION_RES 15 // reserved
171 #define EXCEPTION_MF 16 // Math fault
172 #define EXCEPTION_AC 17 // Alignment check
173 #define EXCEPTION_MC 18 // Machine check
174 #define EXCEPTION_XF 19 // SIMD FP exception
180 #endif /* GEEKOS_INT_H */