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]
38 // Processor state frame
39 Mword _ip; // => utcb->values[12]
40 Mword _cs; // => utcb->values[13]
41 Mword _flags; // => utcb->values[14]
42 Mword _sp; // => utcb->values[15]
47 //---------------------------------------------------------------------------
48 IMPLEMENTATION [ia32]:
53 PUBLIC inline NEEDS["regdefs.h", "gdt.h"]
55 Trap_state::sanitize_user_state()
57 _cs = Gdt::gdt_code_user | Gdt::Selector_user;
58 _ss = Gdt::gdt_data_user | Gdt::Selector_user;
59 _flags = (_flags & ~(EFLAGS_IOPL | EFLAGS_NT)) | EFLAGS_IF;
62 //---------------------------------------------------------------------------
65 #include "emulation.h"
68 PUBLIC inline NEEDS["emulation.h", "regdefs.h"]
70 Trap_state::sanitize_user_state()
72 _cs = Emulation::kernel_cs() & ~1;
73 _ss = Emulation::kernel_ss();
74 _flags = (_flags & ~(EFLAGS_IOPL | EFLAGS_NT)) | EFLAGS_IF;
77 //---------------------------------------------------------------------------
78 IMPLEMENTATION [ia32 || ux]:
85 Trap_state::Handler Trap_state::base_handler FIASCO_FASTCALL;
89 Trap_state::set_ipc_upcall()
97 Trap_state::set_pagefault(Mword pfa, Mword error)
106 Trap_state::trapno() const
111 Trap_state::error() const
116 Trap_state::ip() const
121 Trap_state::cs() const
126 Trap_state::flags() const
131 Trap_state::sp() const
136 Trap_state::ss() const
141 Trap_state::value() const
146 Trap_state::value2() const
151 Trap_state::dx() const
156 Trap_state::value3() const
161 Trap_state::value4() const
166 Trap_state::ip(Mword ip)
171 Trap_state::cs(Mword cs)
176 Trap_state::flags(Mword flags)
181 Trap_state::sp(Mword sp)
186 Trap_state::ss(Mword ss)
191 Trap_state::value(Mword value)
196 Trap_state::value3(Mword value)
199 PUBLIC inline NEEDS["atomic.h"]
201 Trap_state::consume_instruction(unsigned count)
202 { cas ((Address*)(&_ip), _ip, _ip + count); }
206 Trap_state::is_debug_exception() const
207 { return _trapno == 1 || _trapno == 3; }
213 int from_user = _cs & 3;
215 printf("EAX %08lx EBX %08lx ECX %08lx EDX %08lx\n"
216 "ESI %08lx EDI %08lx EBP %08lx ESP %08lx\n"
217 "EIP %08lx EFLAGS %08lx\n"
218 "CS %04lx SS %04lx DS %04lx ES %04lx FS %04lx GS %04lx\n"
219 "trap %ld (%s), error %08lx, from %s mode\n",
221 _si, _di, _bp, from_user ? _sp : (Unsigned32)&_sp,
223 _cs & 0xffff, from_user ? _ss & 0xffff : Cpu::get_ss() & 0xffff,
224 _ds & 0xffff, _es & 0xffff, _fs & 0xffff, _gs & 0xffff,
225 _trapno, Cpu::exception_string(_trapno), _err, from_user ? "user" : "kernel");
230 printf("(external event");
232 printf("(internal event");
234 printf(" regarding IDT gate descriptor no. 0x%02lx)\n", _err >> 3);
236 printf(" regarding %s entry no. 0x%02lx)\n",
237 _err & 4 ? "LDT" : "GDT", _err >> 3);
239 else if (_trapno == 14)
240 printf("page fault linear address %08lx\n", _cr2);
243 extern "C" FIASCO_FASTCALL
245 trap_dump_panic(Trap_state *ts)
248 panic("terminated due to trap");
253 Trap_state::exclude_logging()
254 { return _trapno == 1 || _trapno == 3; }