]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/32/thread-dbf.cpp
Some minor fixes.
[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   // cannot use current_cpu() here because this must run on a thread stack,
32   // not 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    CPU=%u\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           cxx::int_value<Cpu_number>(current_cpu()));
51
52   if (may_enter_jdb)
53     {
54       puts ("Return reboots, \"k\" tries to enter the L4 kernel debugger...");
55
56       while ((c = Kconsole::console()->getchar(false)) == -1)
57         Proc::pause();
58
59       if (c == 'k' || c == 'K')
60         {
61           Mword dummy;
62           Trap_state ts;
63
64           // built a nice trap state the jdb can work with
65           ts._ax    = tss->_eax;
66           ts._bx    = tss->_ebx;
67           ts._cx    = tss->_ecx;
68           ts._dx    = tss->_edx;
69           ts._si    = tss->_esi;
70           ts._di    = tss->_edi;
71           ts._bp    = tss->_ebp;
72           ts.sp(tss->_esp);
73           ts.cs(tss->_cs);
74           ts._ds     = tss->_ds;
75           ts._es     = tss->_es;
76           ts.ss(tss->_ss);
77           ts._fs     = tss->_fs;
78           ts._gs     = tss->_gs;
79           ts._trapno = 8;
80           ts._err    = 0;
81           ts.ip(tss->_eip);
82           ts.flags(tss->_eflags);
83
84           asm volatile
85             (
86              "call   *%2        \n\t"
87              : "=a"(dummy)
88              : "a"(&ts), "m"(nested_trap_handler)
89              : "ecx", "edx", "memory");
90         }
91     }
92   else
93     {
94       puts ("Return reboots");
95       while ((Kconsole::console()->getchar(false)) == -1)
96         Proc::pause();
97     }
98
99   puts ("\033[1mRebooting...\033[0m");
100   platform_reset();
101 }