blob: 3d4c8d2e0280c17de9488360c671cd6609b02b22 [file] [log] [blame]
Corey Tabaka84697242009-03-26 02:32:01 -04001/*
2 * Copyright (c) 2009 Corey Tabaka
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <debug.h>
24#include <arch/x86.h>
25#include <kernel/thread.h>
26
27static void dump_fault_frame(struct x86_iframe *frame)
28{
29 dprintf(CRITICAL, " CS: %04x EIP: %08x EFL: %08x CR2: %08x\n",
30 frame->cs, frame->eip, frame->eflags, x86_get_cr2());
31 dprintf(CRITICAL, "EAX: %08x ECX: %08x EDX: %08x EBX: %08x\n",
32 frame->eax, frame->ecx, frame->edx, frame->ebx);
33 dprintf(CRITICAL, "ESP: %08x EBP: %08x ESI: %08x EDI: %08x\n",
34 frame->esp, frame->ebp, frame->esi, frame->edi);
35 dprintf(CRITICAL, " DS: %04x ES: %04x FS: %04x GS: %04x\n",
36 frame->ds, frame->es, frame->fs, frame->gs);
37
38 // dump the bottom of the current stack
39 addr_t stack = (addr_t) frame; //(addr_t) (((uint32_t *) frame) + (sizeof(struct x86_iframe) / sizeof(uint32_t) - 1));
40
41 if (stack != 0) {
42 dprintf(CRITICAL, "bottom of stack at 0x%08x:\n", (unsigned int)stack);
43 hexdump((void *)stack, 192);
44 }
45}
46
47static void exception_die(struct x86_iframe *frame, const char *msg)
48{
49 inc_critical_section();
50 dprintf(CRITICAL, msg);
51 dump_fault_frame(frame);
52
53 for (;;) {
54 x86_cli();
55 x86_hlt();
56 }
57}
58
59void x86_syscall_handler(struct x86_iframe *frame)
60{
61 exception_die(frame, "unhandled syscall, halting\n");
62}
63
64void x86_gpf_handler(struct x86_iframe *frame)
65{
66 exception_die(frame, "unhandled gpf, halting\n");
67}
68
69void x86_invop_handler(struct x86_iframe *frame)
70{
71 exception_die(frame, "unhandled invalid op, halting\n");
72}
73
74void x86_unhandled_exception(struct x86_iframe *frame)
75{
76 exception_die(frame, "unhandled exception, halting\n");
77}