cpuport.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * File : cpuport.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2018-09-01 xuzhuoyi the first version.
  13. */
  14. #include <rtthread.h>
  15. /* exception and interrupt handler table */
  16. rt_uint32_t rt_interrupt_from_thread;
  17. rt_uint32_t rt_interrupt_to_thread;
  18. rt_uint32_t rt_thread_switch_interrupt_flag;
  19. /* exception hook */
  20. static rt_err_t (*rt_exception_hook)(void *context) = RT_NULL;
  21. struct exception_stack_frame
  22. {
  23. rt_uint32_t t_st0;
  24. rt_uint32_t acc;
  25. rt_uint32_t p;
  26. rt_uint32_t ar1_ar0;
  27. rt_uint32_t dp_st1;
  28. rt_uint32_t dbgstat_ier;
  29. rt_uint32_t return_address;
  30. };
  31. struct stack_frame
  32. {
  33. struct exception_stack_frame exception_stack_frame;
  34. /* r4 ~ r11 register */
  35. rt_uint16_t ar0h;
  36. rt_uint16_t ar1h;
  37. rt_uint32_t xar2;
  38. rt_uint32_t xar3;
  39. rt_uint32_t xar4;
  40. rt_uint32_t xar5;
  41. rt_uint32_t xar6;
  42. rt_uint32_t xar7;
  43. rt_uint32_t xt;
  44. rt_uint32_t rpc;
  45. };
  46. rt_uint8_t *rt_hw_stack_init(void *tentry,
  47. void *parameter,
  48. rt_uint8_t *stack_addr,
  49. void *texit)
  50. {
  51. struct stack_frame *stack_frame;
  52. rt_uint8_t *stk;
  53. unsigned long i;
  54. stk = stack_addr;
  55. stk = (rt_uint8_t *)RT_ALIGN((rt_uint32_t)stk, 8);
  56. //stk -= sizeof(struct stack_frame);
  57. stack_frame = (struct stack_frame *)stk;
  58. /* init all register */
  59. for (i = 0; i < sizeof(struct stack_frame) / sizeof(rt_uint32_t); i ++)
  60. {
  61. ((rt_uint32_t *)stack_frame)[i] = 0xdeadbeef;
  62. }
  63. stack_frame->exception_stack_frame.t_st0 = 0x11110000 | rt_hw_get_st0();
  64. stack_frame->exception_stack_frame.acc = 0x33332222;
  65. stack_frame->exception_stack_frame.ar1_ar0 = 0x00001111 & (unsigned long)parameter; /* ar0 : argument */
  66. stack_frame->exception_stack_frame.p = 0x55554444; /* p */
  67. stack_frame->exception_stack_frame.dp_st1 = (0x00000000) | rt_hw_get_st1(); /* dp_st1 */
  68. stack_frame->exception_stack_frame.dbgstat_ier = 0; /* dbgstat_ier */
  69. stack_frame->exception_stack_frame.return_address = (unsigned long)tentry; /* return_address */
  70. stack_frame->rpc = (unsigned long)texit;
  71. /* return task's current stack address */
  72. return stk + sizeof(struct stack_frame);
  73. }
  74. /**
  75. * This function set the hook, which is invoked on fault exception handling.
  76. *
  77. * @param exception_handle the exception handling hook function.
  78. */
  79. void rt_hw_exception_install(rt_err_t (*exception_handle)(void *context))
  80. {
  81. rt_exception_hook = exception_handle;
  82. }
  83. struct exception_info
  84. {
  85. rt_uint32_t exc_return;
  86. struct stack_frame stack_frame;
  87. };
  88. /**
  89. * shutdown CPU
  90. */
  91. void rt_hw_cpu_shutdown(void)
  92. {
  93. rt_kprintf("shutdown...\n");
  94. RT_ASSERT(0);
  95. }