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.


*** empty log message ***
[palacios.git] / palacios / src / geekos / int.c
1 /*
2  * GeekOS interrupt handling data structures and functions
3  * Copyright (c) 2001,2003 David H. Hovemeyer <daveho@cs.umd.edu>
4  * $Revision: 1.6 $
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 #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/serial.h>
15 #include <geekos/debug.h>
16
17 #include <geekos/cpu.h>
18
19 /*
20  * Defined in lowlevel.asm.
21  */
22 ulong_t Get_Current_EFLAGS(void);
23
24 /* ----------------------------------------------------------------------
25  * Private functions and data
26  * ---------------------------------------------------------------------- */
27
28
29
30
31
32
33
34
35
36
37
38
39 char *exception_names[] = {
40   "#DE (Divide Error)",
41   "#DB (Reserved)",
42   "NMI",
43   "#BP (Breakpoint)",
44   "#OF (Overflow)",
45   "#BR (BOUND Range Exceeded)",
46   "#UD (Invalid Opcode)",
47   "#NM (No Math Coprocessor)",
48   "#DF (Double Fault)",
49   "Coprocessor Segment Overrun",
50   "#TS (Invalid TSS)",
51   "#NP (Segment Not Present)",
52   "#SS (Stack Segment Fault)",
53   "#GP (General Protection Fault)",
54   "#PF (Page Fault)",
55   "(Reserved - 15)",
56   "#MF (Math Fault x87)",
57   "#AC (Alignment Check)",
58   "#MC (Machine Check)",
59   "#XF (SIMD FP Exception)",
60   "(Reserved - 20)",
61   "(Reserved - 21)",
62   "(Reserved - 22)",
63   "(Reserved - 23)",
64   "(Reserved - 24)",
65   "(Reserved - 25)",
66   "(Reserved - 26)",
67   "(Reserved - 27)",
68   "(Reserved - 28)",
69   "(Reserved - 29)",
70   "(Reserved - 30)",
71   "(Reserved - 31)",
72   "USER 32",
73   "USER 33",
74   "USER 34",
75   "USER 35",
76   "USER 36",
77   "USER 37",
78   "USER 38",
79   "USER 39",
80   "USER 40",
81   "USER 41",
82   "USER 42",
83   "USER 43",
84   "USER 44",
85   "USER 45",
86   "USER 46",
87   "USER 47",
88   "USER 48",
89   "USER 49",
90   "USER 50",
91   "USER 51",
92   "USER 52",
93   "USER 53",
94   "USER 54",
95   "USER 55",
96   "USER 56",
97   "USER 57",
98   "USER 58",
99   "USER 59",
100   "USER 60",
101   "USER 61",
102   "USER 62",
103   "USER 63",
104   "USER 64",
105   "USER 65",
106   "USER 66",
107   "USER 67",
108   "USER 68",
109   "USER 69",
110   "USER 70",
111   "USER 71",
112   "USER 72",
113   "USER 73",
114   "USER 74",
115   "USER 75",
116   "USER 76",
117   "USER 77",
118   "USER 78",
119   "USER 79",
120   "USER 80",
121   "USER 81",
122   "USER 82",
123   "USER 83",
124   "USER 84",
125   "USER 85",
126   "USER 86",
127   "USER 87",
128   "USER 88",
129   "USER 89",
130   "USER 90",
131   "USER 91",
132   "USER 92",
133   "USER 93",
134   "USER 94",
135   "USER 95",
136   "USER 96",
137   "USER 97",
138   "USER 98",
139   "USER 99",
140   "USER 100",
141   "USER 101",
142   "USER 102",
143   "USER 103",
144   "USER 104",
145   "USER 105",
146   "USER 106",
147   "USER 107",
148   "USER 108",
149   "USER 109",
150   "USER 110",
151   "USER 111",
152   "USER 112",
153   "USER 113",
154   "USER 114",
155   "USER 115",
156   "USER 116",
157   "USER 117",
158   "USER 118",
159   "USER 119",
160   "USER 120",
161   "USER 121",
162   "USER 122",
163   "USER 123",
164   "USER 124",
165   "USER 125",
166   "USER 126",
167   "USER 127",
168   "USER 128",
169   "USER 129",
170   "USER 130",
171   "USER 131",
172   "USER 132",
173   "USER 133",
174   "USER 134",
175   "USER 135",
176   "USER 136",
177   "USER 137",
178   "USER 138",
179   "USER 139",
180   "USER 140",
181   "USER 141",
182   "USER 142",
183   "USER 143",
184   "USER 144",
185   "USER 145",
186   "USER 146",
187   "USER 147",
188   "USER 148",
189   "USER 149",
190   "USER 150",
191   "USER 151",
192   "USER 152",
193   "USER 153",
194   "USER 154",
195   "USER 155",
196   "USER 156",
197   "USER 157",
198   "USER 158",
199   "USER 159",
200   "USER 160",
201   "USER 161",
202   "USER 162",
203   "USER 163",
204   "USER 164",
205   "USER 165",
206   "USER 166",
207   "USER 167",
208   "USER 168",
209   "USER 169",
210   "USER 170",
211   "USER 171",
212   "USER 172",
213   "USER 173",
214   "USER 174",
215   "USER 175",
216   "USER 176",
217   "USER 177",
218   "USER 178",
219   "USER 179",
220   "USER 180",
221   "USER 181",
222   "USER 182",
223   "USER 183",
224   "USER 184",
225   "USER 185",
226   "USER 186",
227   "USER 187",
228   "USER 188",
229   "USER 189",
230   "USER 190",
231   "USER 191",
232   "USER 192",
233   "USER 193",
234   "USER 194",
235   "USER 195",
236   "USER 196",
237   "USER 197",
238   "USER 198",
239   "USER 199",
240   "USER 200",
241   "USER 201",
242   "USER 202",
243   "USER 203",
244   "USER 204",
245   "USER 205",
246   "USER 206",
247   "USER 207",
248   "USER 208",
249   "USER 209",
250   "USER 210",
251   "USER 211",
252   "USER 212",
253   "USER 213",
254   "USER 214",
255   "USER 215",
256   "USER 216",
257   "USER 217",
258   "USER 218",
259   "USER 219",
260   "USER 220",
261   "USER 221",
262   "USER 222",
263   "USER 223",
264   "USER 224",
265   "USER 225",
266   "USER 226",
267   "USER 227",
268   "USER 228",
269   "USER 229",
270   "USER 230",
271   "USER 231",
272   "USER 232",
273   "USER 233",
274   "USER 234",
275   "USER 235",
276   "USER 236",
277   "USER 237",
278   "USER 238",
279   "USER 239",
280   "USER 240",
281   "USER 241",
282   "USER 242",
283   "USER 243",
284   "USER 244",
285   "USER 245",
286   "USER 246",
287   "USER 247",
288   "USER 248",
289   "USER 249",
290   "USER 250",
291   "USER 251",
292   "USER 252",
293   "USER 253",
294   "USER 254",
295   "USER 255",
296 };  
297
298 char *exception_type_names[] = {
299   "External Interrupt",
300   "NOT USED",
301   "NMI",
302   "Hardware Exception",
303   "NOT USED",
304   "NOT USED",
305   "Software Exception",
306   "NOT USED"
307 };
308
309
310
311
312 /*
313  * A dummy interrupt handler function.
314  * Ensures that the low-level interrupt code always
315  * has a handler to call.
316  */
317 static void Dummy_Interrupt_Handler(struct Interrupt_State* state)
318 {
319   Begin_IRQ(state);
320   
321   /* A "feature" of some chipsets is that if an interrupt is raised by mistake
322    * then its automatically assigned to IRQ 7(Int 39). 
323    * Makes perfect sense...
324    * See:
325    * http://forums12.itrc.hp.com/service/forums/questionanswer.do?admit=109447627+1204759699215+28353475&threadId=1118488
326    */
327   if (state->intNum != 39) {
328     Print("Unexpected Interrupt!  Ignoring!\n");
329     SerialPrint("*** Unexpected interrupt! *** Ignoring!\n");
330     Dump_Interrupt_State(state);
331   } 
332   End_IRQ(state);
333
334   //STOP();
335 }
336
337 #if 0
338 static void Print_Selector(const char* regName, uint_t value)
339 {
340     Print("%s: index=%d, ti=%d, rpl=%d\n",
341         regName, value >> 3, (value >> 2) & 1, value & 3);
342 }
343 #endif
344
345 static void SerialPrint_Selector(const char* regName, uint_t value)
346 {
347     SerialPrint("%s: index=%d, ti=%d, rpl=%d\n",
348         regName, value >> 3, (value >> 2) & 1, value & 3);
349 }
350
351 /* ----------------------------------------------------------------------
352  * Public functions
353  * ---------------------------------------------------------------------- */
354
355 /*
356  * Initialize the interrupt system.
357  */
358 void Init_Interrupts(void)
359 {
360     int i;
361
362     PrintBoth("Initializing Interrupts\n");
363
364     /* Low-level initialization.  Build and initialize the IDT. */
365     Init_IDT();
366
367     /*
368      * Initialize all entries of the handler table with a dummy handler.
369      * This will ensure that we always have a handler function to call.
370      */
371     for (i = 0; i < NUM_IDT_ENTRIES; ++i) {
372         Install_Interrupt_Handler(i, Dummy_Interrupt_Handler);
373     }
374
375     /* JRL */
376     // Disable_IRQ(7);
377     /* ** */
378
379     /* Re-enable interrupts */
380     Enable_Interrupts();
381 }
382
383 /*
384  * Query whether or not interrupts are currently enabled.
385  */
386 bool Interrupts_Enabled(void)
387 {
388     ulong_t eflags = Get_Current_EFLAGS();
389     return (eflags & EFLAGS_IF) != 0;
390 }
391
392 /*
393  * Dump interrupt state struct to screen
394  */
395 void Dump_Interrupt_State(struct Interrupt_State* state)
396 {
397     uint_t errorCode = state->errorCode;
398
399    PrintBoth("eax=%08x ebx=%08x ecx=%08x edx=%08x\n"
400            "esi=%08x edi=%08x ebp=%08x\n"
401            "eip=%08x cs=%08x eflags=%08x\n"
402            "Interrupt number=%d (%s), error code=%d\n"
403            "index=%d, TI=%d, IDT=%d, EXT=%d\n",
404         state->eax, state->ebx, state->ecx, state->edx,
405         state->esi, state->edi, state->ebp,
406         state->eip, state->cs, state->eflags,
407         state->intNum, exception_names[state->intNum], errorCode,
408         errorCode >> 3, (errorCode >> 2) & 1, (errorCode >> 1) & 1, errorCode & 1
409     );
410
411
412     if (Is_User_Interrupt(state)) {
413         struct User_Interrupt_State *ustate = (struct User_Interrupt_State*) state;
414         SerialPrint("user esp=%08x, user ss=%08x\n", ustate->espUser, ustate->ssUser);
415     }
416     SerialPrint_Selector("cs", state->cs);
417     SerialPrint_Selector("ds", state->ds);
418     SerialPrint_Selector("es", state->es);
419     SerialPrint_Selector("fs", state->fs);
420     SerialPrint_Selector("gs", state->gs);
421
422
423
424 }
425