]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/32/thread-dbf.cpp
Inital import
[l4.git] / kernel / fiasco / src / kern / ia32 / 32 / thread-dbf.cpp
1 INTERFACE:
2
3 EXTENSION class Thread
4 {
5 private:
6   static void handle_double_fault (void) asm ("thread_handle_double_fault");
7
8 public:
9   static bool may_enter_jdb;
10 };
11
12
13 IMPLEMENTATION:
14
15 #include <cstdio>
16 #include "cpu.h"
17 #include "kernel_console.h"
18 #include "processor.h"
19 #include "reset.h"
20 #include "trap_state.h"
21 #include "tss.h"
22 #include "watchdog.h"
23
24
25 bool Thread::may_enter_jdb = false;
26
27 IMPLEMENT
28 void
29 Thread::handle_double_fault (void)
30 {
31   // XXX: will not work, because currnt_cpu() must run on a thread stack, not
32   // on a dbf stack!!!
33   volatile Tss *tss = Cpu::boot_cpu()->get_tss();
34   int c;
35
36   Watchdog::disable();
37
38   printf ("\n"
39           "\033[1;31mDOUBLE FAULT!\033[m\n"
40           "EAX=%08x  ESI=%08x  DS=%04x  \n"
41           "EBX=%08x  EDI=%08x  ES=%04x\n"
42           "ECX=%08x  EBP=%08x  GS=%04x\n"
43           "EDX=%08x  ESP=%08x  SS=%04x   ESP0=%08lx\n"
44           "EFL=%08x  EIP=%08x  CS=%04x\n",
45           tss->_eax,    tss->_esi, tss->_ds & 0xffff,
46           tss->_ebx,    tss->_edi, tss->_es & 0xffff,
47           tss->_ecx,    tss->_ebp, tss->_gs & 0xffff,
48           tss->_edx,    tss->_esp, tss->_ss & 0xffff, tss->_esp0,
49           tss->_eflags, tss->_eip, tss->_cs & 0xffff);
50
51   if (may_enter_jdb)
52     {
53       puts ("Return reboots, \"k\" tries to enter the L4 kernel debugger...");
54
55       while ((c=Kconsole::console()->getchar(false)) == -1)
56         Proc::pause();
57
58       if (c == 'k' || c == 'K')
59         {
60           Mword dummy;
61           Trap_state ts;
62
63           // built a nice trap state the jdb can work with
64           ts._ax    = tss->_eax;
65           ts._bx    = tss->_ebx;
66           ts._cx    = tss->_ecx;
67           ts._dx    = tss->_edx;
68           ts._si    = tss->_esi;
69           ts._di    = tss->_edi;
70           ts._bp    = tss->_ebp;
71           ts.sp(tss->_esp);
72           ts.cs(tss->_cs);
73           ts._ds     = tss->_ds;
74           ts._es     = tss->_es;
75           ts.ss(tss->_ss);
76           ts._fs     = tss->_fs;
77           ts._gs     = tss->_gs;
78           ts._trapno = 8;
79           ts._err    = 0;
80           ts.ip(tss->_eip);
81           ts.flags(tss->_eflags);
82
83           asm volatile
84             (
85              "call   *%2        \n\t"
86              : "=a"(dummy)
87              : "a"(&ts), "m"(nested_trap_handler)
88              : "ecx", "edx", "memory");
89         }
90     }
91   else
92     {
93       puts ("Return reboots");
94       while ((Kconsole::console()->getchar(false)) == -1)
95         Proc::pause();
96     }
97
98   puts ("\033[1mRebooting...\033[0m");
99   pc_reset();
100 }