faults.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  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. static void dump_fault_frame(struct x86_iframe *frame)
  27. {
  28. dprintf(CRITICAL, " CS: %04x EIP: %08x EFL: %08x CR2: %08x\n",
  29. frame->cs, frame->eip, frame->eflags, x86_get_cr2());
  30. dprintf(CRITICAL, "EAX: %08x ECX: %08x EDX: %08x EBX: %08x\n",
  31. frame->eax, frame->ecx, frame->edx, frame->ebx);
  32. dprintf(CRITICAL, "ESP: %08x EBP: %08x ESI: %08x EDI: %08x\n",
  33. frame->esp, frame->ebp, frame->esi, frame->edi);
  34. dprintf(CRITICAL, " DS: %04x ES: %04x FS: %04x GS: %04x\n",
  35. frame->ds, frame->es, frame->fs, frame->gs);
  36. // dump the bottom of the current stack
  37. addr_t stack = (addr_t) frame; //(addr_t) (((uint32_t *) frame) + (sizeof(struct x86_iframe) / sizeof(uint32_t) - 1));
  38. if (stack != 0) {
  39. dprintf(CRITICAL, "bottom of stack at 0x%08x:\n", (unsigned int)stack);
  40. hexdump((void *)stack, 192);
  41. }
  42. }
  43. static void exception_die(struct x86_iframe *frame, const char *msg)
  44. {
  45. inc_critical_section();
  46. dprintf(CRITICAL, msg);
  47. dump_fault_frame(frame);
  48. for (;;) {
  49. x86_cli();
  50. x86_hlt();
  51. }
  52. }
  53. void x86_syscall_handler(struct x86_iframe *frame)
  54. {
  55. exception_die(frame, "unhandled syscall, halting\n");
  56. }
  57. void x86_gpf_handler(struct x86_iframe *frame)
  58. {
  59. exception_die(frame, "unhandled gpf, halting\n");
  60. }
  61. void x86_invop_handler(struct x86_iframe *frame)
  62. {
  63. exception_die(frame, "unhandled invalid op, halting\n");
  64. }
  65. void x86_unhandled_exception(struct x86_iframe *frame)
  66. {
  67. exception_die(frame, "unhandled exception, halting\n");
  68. }