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, size_t pc)
  9. {
  10. /* Cannot use con_printf() here */
  11. const uint16_t *pcp;
  12. size_t mtval;
  13. asm volatile("csrr %0,mtval" : "=r" (mtval));
  14. /* Try to move back to the previous instruction (if not a jump...) */
  15. pc += -4 + (pc & 1);
  16. pcp = (const uint16_t *)pc;
  17. con_puts(hotstr("ERROR: "));
  18. con_puts(how);
  19. con_puts(hotstr(" at 0x"));
  20. con_print_hex(pc);
  21. con_puts(hotstr(" (0x"));
  22. con_print_hex((pcp[1] << 16) + pcp[0]);
  23. con_puts(hotstr(")\nBad address: 0x"));
  24. con_print_hex(mtval);
  25. con_putc('\n');
  26. for (int i = 0; i < 32; i += 8) {
  27. for (int j = 0; j < 8; j++) {
  28. uint32_t v = rdxreg(i+j);
  29. con_print_hex(v);
  30. con_putc((j == 7) ? '\n' : ' ');
  31. }
  32. }
  33. con_flush();
  34. udelay(5000000);
  35. reset(SYS_RESET_SOFT);
  36. }
  37. register size_t _pc asm(IRQ_PC_REGISTER);
  38. IRQHANDLER(buserr,0)
  39. {
  40. killed(hotstr("misaligned"), _pc);
  41. }
  42. IRQHANDLER(ebreak,0)
  43. {
  44. killed(hotstr("invalid instruction"), _pc);
  45. }