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