Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


(no commit message)
[palacios.git] / palacios / include / geekos / int.h
1 /*
2  * GeekOS interrupt handling data structures and functions
3  * Copyright (c) 2001, David H. Hovemeyer <daveho@cs.umd.edu>
4  * $Revision: 1.1.1.1 $
5  * 
6  * This is free software.  You are permitted to use,
7  * redistribute, and modify it as specified in the file "COPYING".
8  */
9
10 /*
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.
14  */
15
16 #ifndef GEEKOS_INT_H
17 #define GEEKOS_INT_H
18
19 #include <geekos/kassert.h>
20 #include <geekos/ktypes.h>
21 #include <geekos/defs.h>
22
23 /*
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".
27  */
28 struct Interrupt_State {
29     /*
30      * The register contents at the time of the exception.
31      * We save these explicitly.
32      */
33     uint_t gs;
34     uint_t fs;
35     uint_t es;
36     uint_t ds;
37     uint_t ebp;
38     uint_t edi;
39     uint_t esi;
40     uint_t edx;
41     uint_t ecx;
42     uint_t ebx;
43     uint_t eax;
44
45     /*
46      * We explicitly push the interrupt number.
47      * This makes it easy for the handler function to determine
48      * which interrupt occurred.
49      */
50     uint_t intNum;
51
52     /*
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.
56      */
57     uint_t errorCode;
58
59     /* These are always pushed on the stack by the processor. */
60     uint_t eip;
61     uint_t cs;
62     uint_t eflags;
63 };
64
65 /*
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.
69  */
70 struct User_Interrupt_State {
71     struct Interrupt_State state;
72     uint_t espUser;
73     uint_t ssUser;
74 };
75
76 static __inline__ bool Is_User_Interrupt(struct Interrupt_State *state)
77 {
78     return (state->cs & 3) == USER_PRIVILEGE;
79 }
80
81
82 /*
83  * The signature of an interrupt handler.
84  */
85 typedef void (*Interrupt_Handler)(struct Interrupt_State* state);
86
87 /*
88  * Perform all low- and high-level initialization of the
89  * interrupt system.
90  */
91 void Init_Interrupts(void);
92
93 /*
94  * Query whether or not interrupts are currently enabled.
95  */
96 bool Interrupts_Enabled(void);
97
98 /*
99  * Block interrupts.
100  */
101 static __inline__ void __Disable_Interrupts(void)
102 {
103     __asm__ __volatile__ ("cli");
104 }
105 #define Disable_Interrupts()            \
106 do {                                    \
107     KASSERT(Interrupts_Enabled());      \
108     __Disable_Interrupts();             \
109 } while (0)
110
111 /*
112  * Unblock interrupts.
113  */
114 static __inline__ void __Enable_Interrupts(void)
115 {
116     __asm__ __volatile__ ("sti");
117 }
118 #define Enable_Interrupts()             \
119 do {                                    \
120     KASSERT(!Interrupts_Enabled());     \
121     __Enable_Interrupts();              \
122 } while (0)
123
124 /*
125  * Dump interrupt state struct to screen
126  */
127 void Dump_Interrupt_State(struct Interrupt_State* state);
128
129 /**
130  * Start interrupt-atomic region.
131  * @return true if interrupts were enabled at beginning of call,
132  * false otherwise.
133  */
134 static __inline__ bool Begin_Int_Atomic(void) 
135 {
136     bool enabled = Interrupts_Enabled();
137     if (enabled)
138         Disable_Interrupts();
139     return enabled;
140 }
141
142 /**
143  * End interrupt-atomic region.
144  * @param iflag the value returned from the original Begin_Int_Atomic() call.
145  */
146 static __inline__ void End_Int_Atomic(bool iflag)
147 {
148     KASSERT(!Interrupts_Enabled());
149     if (iflag) {
150         /* Interrupts were originally enabled, so turn them back on */
151         Enable_Interrupts();
152     }
153 }
154
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
175 // 20+ are reserved
176
177
178
179
180 #endif  /* GEEKOS_INT_H */