OOStuBS - Technische Informatik II (TI-II)  2.4
exceptions.cc
gehe zur Dokumentation dieser Datei
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2  * Technische Informatik II *
3  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4  * *
5  * G U A R D I A N *
6  * *
7 \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
8 
9 /* INCLUDES */
10 
11 #include "object/imanager.h"
12 #include "object/kout.h"
13 #include "object/cpu.h"
14 #include "object/lock.h"
15 
16 #include <stdint.h>
17 
18 /* GLOBAL OBJECTS */
19 
20 /* declare methods as c-like */
21 extern "C" void exception(unsigned short slot, void** esp);
22 
23 struct Exception{
24  const char* const name;
25  bool isReserved;
27 };
28 
29 static const Exception exceptions[32]={
30  {"Divide Error" , false, false},
31  {"RESERVED" , true , false},
32  {"NMI" , true , false},
33  {"Breakpoint" , false, false},
34  {"Overflow" , false, false},
35  {"BOUND Range Exceeded" , false, false},
36  {"Invalid Opcode" , false, false},
37  {"No Math Coprocessor" , false, false},
38  {"Double Fault" , false, true },
39  {"Coprocessor Segment Overrun" , false, false},
40  {"Invalid TSS" , false, true },
41  {"Segment Not Present" , false, true },
42  {"Stack-Segment Fault" , false, true },
43  {"General Protection" , false, true },
44  {"Page Fault" , false, true },
45  {"RESERVED" , true , false},
46  {"Divide Error" , false, false},
47  {"x87 FPU Floating Point Error" , false, false},
48  {"Alignement Check" , false, true },
49  {"Machine Check" , false, false},
50  {"SIMD Floating-Point Exception", false, false},
51  {"Virtualization Exception" , false, false},
52  {"RESERVED" , true , false},
53  {"RESERVED" , true , false},
54  {"RESERVED" , true , false},
55  {"RESERVED" , true , false},
56  {"RESERVED" , true , false},
57  {"RESERVED" , true , false},
58  {"RESERVED" , true , false},
59  {"RESERVED" , true , false},
60  {"RESERVED" , true , false},
61  {"RESERVED" , true , false}
62 };
63 
64 /* METHODS */
65 
66 void printException(unsigned short slot, void** esp){
67  const Exception& e=exceptions[slot];
68  //Fehler melden
69  kout.clear();
71  kout.flush();
72  kout << "Exception " << slot << ": " << e.name << " occured" << endl;
73  if(!e.isReserved){
74  esp+=e.hasErrorCode?4:3;
75  uint32_t eflags = reinterpret_cast<uint32_t>(*--esp);
76  uint32_t cs = reinterpret_cast<uint32_t>(*--esp);
77  void* eip = *--esp;
78 
79  kout << " eip : " << hex << eip << endl;
80  kout << " cs : " << dec << cs << endl;
81  kout << " eflags : " << bin << eflags << endl;
82 
83  if(e.hasErrorCode){
84  union ErroCode{
85  uint32_t value;
86  struct{
87  uint8_t ext : 1;
88  uint8_t idt : 1;
89  uint8_t ti : 1;
90  uint16_t segmentSelectorIndex : 13;
91  };
92  } ec;
93  ec.value = *reinterpret_cast<uint32_t*>(*--esp);
94  kout << " Segment Selector Index: " << dec << ec.segmentSelectorIndex << endl;
95  kout << " External : " << (ec.ext?"true":"false") << endl;
96  kout << " Location : " << (ec.idt?"IDT":ec.ti?"GDT":"LDT") << endl;
97  }
98  }
99  //und anhalten
100  cpu.disable_int();
101  cpu.halt();
102 }
103 
110 void exception(unsigned short slot, void** esp) {
111  if(slot < 32 && slot != 2) {
112  printException(slot, esp);
113  }
114  lock.enter();
115  iManager.handle(slot);
116  lock.leave();
117 }