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.


Release 1.0
[palacios.git] / geekos / 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 $
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 // to stop the compilation warnings
25 extern void Print(const char* fmt, ...); 
26 extern void Set_Current_Attr(uchar_t attrib);
27
28 /*
29  * This struct reflects the contents of the stack when
30  * a C interrupt handler function is called.
31  * It must be kept up to date with the code in "lowlevel.asm".
32  */
33 struct Interrupt_State {
34     /*
35      * The register contents at the time of the exception.
36      * We save these explicitly.
37      */
38     uint_t gs;
39     uint_t fs;
40     uint_t es;
41     uint_t ds;
42     uint_t ebp;
43     uint_t edi;
44     uint_t esi;
45     uint_t edx;
46     uint_t ecx;
47     uint_t ebx;
48     uint_t eax;
49
50     /*
51      * We explicitly push the interrupt number.
52      * This makes it easy for the handler function to determine
53      * which interrupt occurred.
54      */
55     uint_t intNum;
56
57     /*
58      * This may be pushed by the processor; if not, we push
59      * a dummy error code, so the stack layout is the same
60      * for every type of interrupt.
61      */
62     uint_t errorCode;
63
64     /* These are always pushed on the stack by the processor. */
65     uint_t eip;
66     uint_t cs;
67     uint_t eflags;
68 };
69
70 /*
71  * An interrupt that occurred in user mode.
72  * If Is_User_Interrupt(state) returns true, then the
73  * Interrupt_State object may be cast to this kind of struct.
74  */
75 struct User_Interrupt_State {
76     struct Interrupt_State state;
77     uint_t espUser;
78     uint_t ssUser;
79 };
80
81 static __inline__ bool Is_User_Interrupt(struct Interrupt_State *state)
82 {
83     return (state->cs & 3) == USER_PRIVILEGE;
84 }
85
86
87 /*
88  * The signature of an interrupt handler.
89  */
90 typedef void (*Interrupt_Handler)(struct Interrupt_State* state);
91
92 /*
93  * Perform all low- and high-level initialization of the
94  * interrupt system.
95  */
96 void Init_Interrupts(void);
97
98 /*
99  * Query whether or not interrupts are currently enabled.
100  */
101 bool Interrupts_Enabled(void);
102
103 /*
104  * Block interrupts.
105  */
106 static __inline__ void __Disable_Interrupts(void)
107 {
108     __asm__ __volatile__ ("cli");
109 }
110 #define Disable_Interrupts()            \
111 do {                                    \
112     KASSERT(Interrupts_Enabled());      \
113     __Disable_Interrupts();             \
114 } while (0)
115
116 /*
117  * Unblock interrupts.
118  */
119 static __inline__ void __Enable_Interrupts(void)
120 {
121     __asm__ __volatile__ ("sti");
122 }
123 #define Enable_Interrupts()             \
124 do {                                    \
125     KASSERT(!Interrupts_Enabled());     \
126     __Enable_Interrupts();              \
127 } while (0)
128
129 /*
130  * Dump interrupt state struct to screen
131  */
132 void Dump_Interrupt_State(struct Interrupt_State* state);
133
134 /**
135  * Start interrupt-atomic region.
136  * @return true if interrupts were enabled at beginning of call,
137  * false otherwise.
138  */
139 static __inline__ bool Begin_Int_Atomic(void) 
140 {
141     bool enabled = Interrupts_Enabled();
142     if (enabled)
143         Disable_Interrupts();
144     return enabled;
145 }
146
147 /**
148  * End interrupt-atomic region.
149  * @param iflag the value returned from the original Begin_Int_Atomic() call.
150  */
151 static __inline__ void End_Int_Atomic(bool iflag)
152 {
153     KASSERT(!Interrupts_Enabled());
154     if (iflag) {
155         /* Interrupts were originally enabled, so turn them back on */
156         Enable_Interrupts();
157     }
158 }
159
160 #define EXCEPTION_DE   0   // Divide by zero
161 #define EXCEPTION_DB   1   // reserved
162 #define EXCEPTION_NMI  2   // NMI
163 #define EXCEPTION_BP   3   // Breakpoint
164 #define EXCEPTION_OF   4   // Overflow
165 #define EXCEPTION_BR   5   // Bound range exceeded
166 #define EXCEPTION_UD   6   // Undefined opcode
167 #define EXCEPTION_NM   7   // Math coprocessor gone missing
168 #define EXCEPTION_DF   8   // Double fault
169 #define EXCEPTION_CO   9   // Coprocessor segment overrrun
170 #define EXCEPTION_TS   10  // Invalid TSS
171 #define EXCEPTION_NP   11  // Segment not present
172 #define EXCEPTION_SS   12  // Stack segment fault
173 #define EXCEPTION_GP   13  // General Protection fault
174 #define EXCEPTION_PF   14  // Page Fault
175 #define EXCEPTION_RES  15  // reserved
176 #define EXCEPTION_MF   16  // Math fault
177 #define EXCEPTION_AC   17  // Alignment check
178 #define EXCEPTION_MC   18  // Machine check
179 #define EXCEPTION_XF   19  // SIMD FP exception
180 // 20+ are reserved
181
182
183
184
185 #endif  /* GEEKOS_INT_H */