9 friend class Jdb_stack_view;
12 typedef FIASCO_FASTCALL int (*Handler)(Trap_state*, unsigned cpu);
13 static Handler base_handler asm ("BASE_TRAP_HANDLER");
15 // Saved segment registers
18 Mword _gs; // => utcb->values[ 0]
19 Mword _fs; // => utcb->values[ 1]
21 // PUSHA register state frame
22 Mword _di; // => utcb->values[ 2]
23 Mword _si; // => utcb->values[ 3]
24 Mword _bp; // => utcb->values[ 4]
25 Mword _cr2; // we save cr2 over esp for PFs // => utcb->values[ 5]
26 Mword _bx; // => utcb->values[ 6]
27 Mword _dx; // => utcb->values[ 7]
28 Mword _cx; // => utcb->values[ 8]
29 Mword _ax; // => utcb->values[ 9]
31 // Processor trap number, 0-31
32 Mword _trapno; // => utcb->values[10]
34 // Error code pushed by the processor, 0 if none
35 Mword _err; // => utcb->values[11]
37 // Processor state frame
38 Mword _ip; // => utcb->values[12]
39 Mword _cs; // => utcb->values[13]
40 Mword _flags; // => utcb->values[14]
41 Mword _sp; // => utcb->values[15]
55 void dump() { s.dump(); }
58 //---------------------------------------------------------------------------
59 IMPLEMENTATION [ia32]:
64 PUBLIC inline NEEDS["regdefs.h", "gdt.h"]
66 Trap_state::sanitize_user_state()
68 _cs = Gdt::gdt_code_user | Gdt::Selector_user;
69 _ss = Gdt::gdt_data_user | Gdt::Selector_user;
70 _flags = (_flags & ~(EFLAGS_IOPL | EFLAGS_NT)) | EFLAGS_IF;
73 //---------------------------------------------------------------------------
76 #include "emulation.h"
79 PUBLIC inline NEEDS["emulation.h", "regdefs.h"]
81 Trap_state::sanitize_user_state()
83 _cs = Emulation::kernel_cs() & ~1;
84 _ss = Emulation::kernel_ss();
85 _flags = (_flags & ~(EFLAGS_IOPL | EFLAGS_NT)) | EFLAGS_IF;
88 //---------------------------------------------------------------------------
89 IMPLEMENTATION [ia32 || ux]:
97 Trap_state::Handler Trap_state::base_handler FIASCO_FASTCALL;
99 PUBLIC inline NEEDS[Trap_state::sanitize_user_state, "mem.h"]
101 Trap_state::copy_and_sanitize(Trap_state const *src)
103 Mem::memcpy_mwords(this, src, sizeof(*this) / sizeof(Mword));
104 sanitize_user_state();
109 Trap_state::set_pagefault(Mword pfa, Mword error)
118 Trap_state::trapno() const
123 Trap_state::error() const
128 Trap_state::ip() const
133 Trap_state::cs() const
138 Trap_state::flags() const
143 Trap_state::sp() const
148 Trap_state::ss() const
153 Trap_state::value() const
158 Trap_state::value2() const
163 Trap_state::dx() const
168 Trap_state::value3() const
173 Trap_state::value4() const
178 Trap_state::ip(Mword ip)
183 Trap_state::cs(Mword cs)
188 Trap_state::flags(Mword flags)
193 Trap_state::sp(Mword sp)
198 Trap_state::ss(Mword ss)
203 Trap_state::value(Mword value)
208 Trap_state::value3(Mword value)
211 PUBLIC inline NEEDS["atomic.h"]
213 Trap_state::consume_instruction(unsigned count)
214 { cas ((Address*)(&_ip), _ip, _ip + count); }
218 Trap_state::is_debug_exception() const
219 { return _trapno == 1 || _trapno == 3; }
225 int from_user = _cs & 3;
227 printf("EAX %08lx EBX %08lx ECX %08lx EDX %08lx\n"
228 "ESI %08lx EDI %08lx EBP %08lx ESP %08lx\n"
229 "EIP %08lx EFLAGS %08lx\n"
230 "CS %04lx SS %04lx DS %04lx ES %04lx FS %04lx GS %04lx\n"
231 "trap %lu (%s), error %08lx, from %s mode\n",
233 _si, _di, _bp, from_user ? _sp : (Unsigned32)&_sp,
235 _cs & 0xffff, from_user ? _ss & 0xffff : Cpu::get_ss() & 0xffff,
236 _ds & 0xffff, _es & 0xffff, _fs & 0xffff, _gs & 0xffff,
237 _trapno, Cpu::exception_string(_trapno), _err, from_user ? "user" : "kernel");
242 printf("(external event");
244 printf("(internal event");
246 printf(" regarding IDT gate descriptor no. 0x%02lx)\n", _err >> 3);
248 printf(" regarding %s entry no. 0x%02lx)\n",
249 _err & 4 ? "LDT" : "GDT", _err >> 3);
251 else if (_trapno == 14)
252 printf("page fault linear address %08lx\n", _cr2);
255 extern "C" FIASCO_FASTCALL
257 trap_dump_panic(Trap_state *ts)
260 panic("terminated due to trap");
265 Trap_state::exclude_logging()
266 { return _trapno == 1 || _trapno == 3; }