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