cpuport.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * File : cpu.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009, 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. * 2010-01-25 Bernard first version
  13. * 2012-05-31 aozima Merge all of the C source code into cpuport.c
  14. */
  15. #include <rtthread.h>
  16. struct stack_contex
  17. {
  18. rt_uint32_t r0;
  19. rt_uint32_t r1;
  20. rt_uint32_t r2;
  21. rt_uint32_t r3;
  22. rt_uint32_t r12;
  23. rt_uint32_t lr;
  24. rt_uint32_t pc;
  25. rt_uint32_t psr;
  26. };
  27. /* flag in interrupt handling */
  28. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  29. rt_uint32_t rt_thread_switch_interrupt_flag;
  30. /**
  31. * This function will initialize thread stack
  32. *
  33. * @param tentry the entry of thread
  34. * @param parameter the parameter of entry
  35. * @param stack_addr the beginning stack address
  36. * @param texit the function will be called when thread exit
  37. *
  38. * @return stack address
  39. */
  40. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
  41. rt_uint8_t *stack_addr, void *texit)
  42. {
  43. unsigned long *stk;
  44. stk = (unsigned long *)stack_addr;
  45. *(stk) = 0x01000000L; /* PSR */
  46. *(--stk) = (unsigned long)tentry; /* entry point, pc */
  47. *(--stk) = (unsigned long)texit; /* lr */
  48. *(--stk) = 0; /* r12 */
  49. *(--stk) = 0; /* r3 */
  50. *(--stk) = 0; /* r2 */
  51. *(--stk) = 0; /* r1 */
  52. *(--stk) = (unsigned long)parameter; /* r0 : argument */
  53. *(--stk) = 0; /* r7 */
  54. *(--stk) = 0; /* r6 */
  55. *(--stk) = 0; /* r5 */
  56. *(--stk) = 0; /* r4 */
  57. /* return task's current stack address */
  58. return (rt_uint8_t *)stk;
  59. }
  60. extern long list_thread(void);
  61. extern rt_thread_t rt_current_thread;
  62. void rt_hw_hard_fault_exception(struct stack_contex* contex)
  63. {
  64. rt_kprintf("psr: 0x%08x\n", contex->psr);
  65. rt_kprintf(" pc: 0x%08x\n", contex->pc);
  66. rt_kprintf(" lr: 0x%08x\n", contex->lr);
  67. rt_kprintf("r12: 0x%08x\n", contex->r12);
  68. rt_kprintf("r03: 0x%08x\n", contex->r3);
  69. rt_kprintf("r02: 0x%08x\n", contex->r2);
  70. rt_kprintf("r01: 0x%08x\n", contex->r1);
  71. rt_kprintf("r00: 0x%08x\n", contex->r0);
  72. rt_kprintf("hard fault on thread: %s\n", rt_current_thread->name);
  73. #ifdef RT_USING_FINSH
  74. list_thread();
  75. #endif
  76. while (1);
  77. }