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 / 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.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 #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/vmcs.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  * A dummy interrupt handler function.
30  * Ensures that the low-level interrupt code always
31  * has a handler to call.
32  */
33 static void Dummy_Interrupt_Handler(struct Interrupt_State* state)
34 {
35   Begin_IRQ(state);
36
37   Print("Unexpected Interrupt!  Ignoring!\n");
38   SerialPrint("*** Unexpected interrupt! *** Ignoring!\n");
39   Dump_Interrupt_State(state);
40   SerialPrint_VMCS_ALL();
41
42   End_IRQ(state);
43   
44   //  STOP();
45 }
46
47 #if 0
48 static void Print_Selector(const char* regName, uint_t value)
49 {
50     Print("%s: index=%d, ti=%d, rpl=%d\n",
51         regName, value >> 3, (value >> 2) & 1, value & 3);
52 }
53 #endif
54
55 static void SerialPrint_Selector(const char* regName, uint_t value)
56 {
57     SerialPrint("%s: index=%d, ti=%d, rpl=%d\n",
58         regName, value >> 3, (value >> 2) & 1, value & 3);
59 }
60
61 /* ----------------------------------------------------------------------
62  * Public functions
63  * ---------------------------------------------------------------------- */
64
65 /*
66  * Initialize the interrupt system.
67  */
68 void Init_Interrupts(void)
69 {
70     int i;
71
72     PrintBoth("Initializing Interrupts\n");
73
74     /* Low-level initialization.  Build and initialize the IDT. */
75     Init_IDT();
76
77     /*
78      * Initialize all entries of the handler table with a dummy handler.
79      * This will ensure that we always have a handler function to call.
80      */
81     for (i = 0; i < NUM_IDT_ENTRIES; ++i) {
82         Install_Interrupt_Handler(i, Dummy_Interrupt_Handler);
83     }
84
85     /* Re-enable interrupts */
86     Enable_Interrupts();
87 }
88
89 /*
90  * Query whether or not interrupts are currently enabled.
91  */
92 bool Interrupts_Enabled(void)
93 {
94     ulong_t eflags = Get_Current_EFLAGS();
95     return (eflags & EFLAGS_IF) != 0;
96 }
97
98 /*
99  * Dump interrupt state struct to screen
100  */
101 void Dump_Interrupt_State(struct Interrupt_State* state)
102 {
103     uint_t errorCode = state->errorCode;
104
105    SerialPrint("eax=%08x ebx=%08x ecx=%08x edx=%08x\n"
106            "esi=%08x edi=%08x ebp=%08x\n"
107            "eip=%08x cs=%08x eflags=%08x\n"
108            "Interrupt number=%d (%s), error code=%d\n"
109            "index=%d, TI=%d, IDT=%d, EXT=%d\n",
110         state->eax, state->ebx, state->ecx, state->edx,
111         state->esi, state->edi, state->ebp,
112         state->eip, state->cs, state->eflags,
113         state->intNum, exception_names[state->intNum], errorCode,
114         errorCode >> 3, (errorCode >> 2) & 1, (errorCode >> 1) & 1, errorCode & 1
115     );
116     if (Is_User_Interrupt(state)) {
117         struct User_Interrupt_State *ustate = (struct User_Interrupt_State*) state;
118         SerialPrint("user esp=%08x, user ss=%08x\n", ustate->espUser, ustate->ssUser);
119     }
120     SerialPrint_Selector("cs", state->cs);
121     SerialPrint_Selector("ds", state->ds);
122     SerialPrint_Selector("es", state->es);
123     SerialPrint_Selector("fs", state->fs);
124     SerialPrint_Selector("gs", state->gs);
125 }