trap.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Date Author Notes
  7. * 2018-10-06 ZhaoXiaowei the first version
  8. */
  9. #include <rtthread.h>
  10. #include <rthw.h>
  11. #include "interrupt.h"
  12. #include "armv8.h"
  13. extern struct rt_thread *rt_current_thread;
  14. #ifdef RT_USING_FINSH
  15. extern long list_thread(void);
  16. #endif
  17. /**
  18. * this function will show registers of CPU
  19. *
  20. * @param regs the registers point
  21. */
  22. void rt_hw_show_register(struct rt_hw_exp_stack *regs)
  23. {
  24. rt_kprintf("Execption:\n");
  25. rt_kprintf("r00:0x%16.16lx r01:0x%16.16lx r02:0x%16.16lx r03:0x%16.16lx\n", regs->x0, regs->x1, regs->x2, regs->x3);
  26. rt_kprintf("r04:0x%16.16lx r05:0x%16.16lx r06:0x%16.16lx r07:0x%16.16lx\n", regs->x4, regs->x5, regs->x6, regs->x7);
  27. rt_kprintf("r08:0x%16.16lx r09:0x%16.16lx r10:0x%16.16lx r11:0x%16.16lx\n", regs->x8, regs->x9, regs->x10, regs->x11);
  28. rt_kprintf("r12:0x%16.16lx r13:0x%16.16lx r14:0x%16.16lx r15:0x%16.16lx\n", regs->x12, regs->x13, regs->x14, regs->x15);
  29. rt_kprintf("r16:0x%16.16lx r17:0x%16.16lx r18:0x%16.16lx r19:0x%16.16lx\n", regs->x16, regs->x17, regs->x18, regs->x19);
  30. rt_kprintf("r20:0x%16.16lx r21:0x%16.16lx r22:0x%16.16lx r23:0x%16.16lx\n", regs->x20, regs->x21, regs->x22, regs->x23);
  31. rt_kprintf("r24:0x%16.16lx r25:0x%16.16lx r26:0x%16.16lx r27:0x%16.16lx\n", regs->x24, regs->x25, regs->x26, regs->x27);
  32. rt_kprintf("r28:0x%16.16lx r29:0x%16.16lx r30:0x%16.16lx\n", regs->x28, regs->x29, regs->x30);
  33. rt_kprintf("spsr:0x%16.16lx\n", regs->spsr);
  34. rt_kprintf("return pc:0x%16.16lx\n", regs->pc);
  35. }
  36. /**
  37. * When comes across an instruction which it cannot handle,
  38. * it takes the undefined instruction trap.
  39. *
  40. * @param regs system registers
  41. *
  42. * @note never invoke this function in application
  43. */
  44. void rt_hw_trap_error(struct rt_hw_exp_stack *regs)
  45. {
  46. rt_kprintf("error exception:\n");
  47. rt_hw_show_register(regs);
  48. #ifdef RT_USING_FINSH
  49. list_thread();
  50. #endif
  51. rt_hw_cpu_shutdown();
  52. }
  53. #define GIC_ACK_INTID_MASK 0x000003ff
  54. int rt_hw_interrupt_get_irq(void);
  55. void rt_hw_interrupt_ack(int fiq_irq);
  56. void rt_hw_trap_irq(void)
  57. {
  58. void *param;
  59. int ir;
  60. rt_isr_handler_t isr_func;
  61. extern struct rt_irq_desc isr_table[];
  62. ir = rt_hw_interrupt_get_irq();
  63. if (ir == 1023)
  64. {
  65. /* Spurious interrupt */
  66. return;
  67. }
  68. /* get interrupt service routine */
  69. isr_func = isr_table[ir].handler;
  70. #ifdef RT_USING_INTERRUPT_INFO
  71. isr_table[ir].counter++;
  72. #endif
  73. if (isr_func)
  74. {
  75. /* Interrupt for myself. */
  76. param = isr_table[ir].param;
  77. /* turn to interrupt service routine */
  78. isr_func(ir, param);
  79. }
  80. /* end of interrupt */
  81. rt_hw_interrupt_ack(ir);
  82. }
  83. void rt_hw_trap_fiq(void)
  84. {
  85. }