killed.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "common.h"
  2. #include "io.h"
  3. #include "sys.h"
  4. #include "console.h"
  5. #include "esp.h"
  6. #include "irq.h"
  7. /* Don't mark no_return or gcc moves it to SDRAM */
  8. static void __hot __text_hot killed(const char *how)
  9. {
  10. /* Cannot use con_printf() here */
  11. const uint16_t *pcp;
  12. size_t mtval;
  13. size_t mepc;
  14. size_t pc;
  15. /* Try to move back to the previous instruction (wrong for jumps...) */
  16. asm volatile("csrr %0,mepc" : "=r" (mepc));
  17. pc = mepc-4 + (mepc & 1);
  18. pcp = (const uint16_t *)pc;
  19. con_puts(hotstr("ERROR: "));
  20. con_puts(how);
  21. con_puts(hotstr(" at 0x"));
  22. con_print_hex(pc);
  23. con_puts(hotstr(" (0x"));
  24. con_print_hex((pcp[1] << 16) + pcp[0]);
  25. con_puts(hotstr(")\nBad address: 0x"));
  26. asm volatile("csrr %0,mtval" : "=r" (mtval));
  27. con_print_hex(mtval);
  28. con_putc('\n');
  29. for (int i = 0; i < 32; i += 8) {
  30. for (int j = 0; j < 8; j++) {
  31. uint32_t v = rdxreg(i+j);
  32. con_print_hex(v);
  33. con_putc((j == 7) ? '\n' : ' ');
  34. }
  35. }
  36. con_flush();
  37. udelay(5000000);
  38. reset(SYS_RESET_SOFT);
  39. }
  40. IRQHANDLER(buserr,0)
  41. {
  42. killed(hotstr("misaligned"));
  43. }
  44. IRQHANDLER(ebreak,0)
  45. {
  46. killed(hotstr("invalid instruction"));
  47. }