|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, Shenzhen Academy of Aerospace Technology |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * |
| 6 | + * Change Logs: |
| 7 | + * Date Author Notes |
| 8 | + * 2021-11-16 Dystopia the first version |
| 9 | + */ |
| 10 | + |
| 11 | +#include <rtthread.h> |
| 12 | +#include <c66xx.h> |
| 13 | + |
| 14 | +extern rt_uint32_t rt_hw_get_current_dp(void); |
| 15 | + |
| 16 | +/** |
| 17 | + * @addtogroup C66xx |
| 18 | + */ |
| 19 | +/*@{*/ |
| 20 | + |
| 21 | +/** |
| 22 | + * This function will initialize thread stack |
| 23 | + * |
| 24 | + * @param tentry the entry of thread |
| 25 | + * @param parameter the parameter of entry |
| 26 | + * @param stack_addr the beginning stack address |
| 27 | + * @param texit the function will be called when thread exit |
| 28 | + * |
| 29 | + * @return stack address |
| 30 | + */ |
| 31 | +rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter, |
| 32 | + rt_uint8_t *stack_addr, void *texit) |
| 33 | +{ |
| 34 | + rt_hw_thread_stack_register *thread_context; |
| 35 | + rt_uint32_t stk; |
| 36 | + |
| 37 | + stack_addr += sizeof(rt_uint32_t); |
| 38 | + stack_addr = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8); |
| 39 | + stk = (rt_uint32_t)stack_addr; |
| 40 | + thread_context = (rt_hw_thread_stack_register *)(stk - sizeof(rt_hw_thread_stack_register)); |
| 41 | + |
| 42 | + thread_context->pc = (rt_uint32_t)tentry; |
| 43 | + thread_context->csr = 0x0103; |
| 44 | + thread_context->tsr = 0x3; |
| 45 | + thread_context->orig_a4 = 1; |
| 46 | + thread_context->ilc = 0; |
| 47 | + thread_context->rilc = 0; |
| 48 | + |
| 49 | + thread_context->hw_register.b17 = 0xB17; |
| 50 | + thread_context->hw_register.b16 = 0xB16; |
| 51 | + thread_context->hw_register.b19 = 0xB19; |
| 52 | + thread_context->hw_register.b18 = 0xB18; |
| 53 | + thread_context->hw_register.b21 = 0xB21; |
| 54 | + thread_context->hw_register.b20 = 0xB20; |
| 55 | + thread_context->hw_register.b23 = 0xB23; |
| 56 | + thread_context->hw_register.b22 = 0xB22; |
| 57 | + thread_context->hw_register.b25 = 0xB25; |
| 58 | + thread_context->hw_register.b24 = 0xB24; |
| 59 | + thread_context->hw_register.b27 = 0xB27; |
| 60 | + thread_context->hw_register.b26 = 0xB26; |
| 61 | + thread_context->hw_register.b29 = 0xB29; |
| 62 | + thread_context->hw_register.b28 = 0xB28; |
| 63 | + thread_context->hw_register.b31 = 0xB31; |
| 64 | + thread_context->hw_register.b30 = 0xB30; |
| 65 | + |
| 66 | + thread_context->hw_register.b1 = 0xB01; |
| 67 | + thread_context->hw_register.b0 = 0xB00; |
| 68 | + thread_context->hw_register.b3 = (rt_uint32_t)texit; |
| 69 | + thread_context->hw_register.b2 = 0xB02; |
| 70 | + thread_context->hw_register.b5 = 0xB05; |
| 71 | + thread_context->hw_register.b4 = 0xB04; |
| 72 | + thread_context->hw_register.b7 = 0xB07; |
| 73 | + thread_context->hw_register.b6 = 0xB06; |
| 74 | + thread_context->hw_register.b9 = 0xB09; |
| 75 | + thread_context->hw_register.b8 = 0xB08; |
| 76 | + thread_context->hw_register.b11 = 0xB11; |
| 77 | + thread_context->hw_register.b10 = 0xB10; |
| 78 | + thread_context->hw_register.b13 = 0xB13; |
| 79 | + thread_context->hw_register.b12 = 0xB12; |
| 80 | + |
| 81 | + thread_context->hw_register.a17 = 0xA17; |
| 82 | + thread_context->hw_register.a16 = 0xA16; |
| 83 | + thread_context->hw_register.a19 = 0xA19; |
| 84 | + thread_context->hw_register.a18 = 0xA18; |
| 85 | + thread_context->hw_register.a21 = 0xA21; |
| 86 | + thread_context->hw_register.a20 = 0xA20; |
| 87 | + thread_context->hw_register.a23 = 0xA23; |
| 88 | + thread_context->hw_register.a22 = 0xA22; |
| 89 | + thread_context->hw_register.a25 = 0xA25; |
| 90 | + thread_context->hw_register.a24 = 0xA24; |
| 91 | + thread_context->hw_register.a27 = 0xA27; |
| 92 | + thread_context->hw_register.a26 = 0xA26; |
| 93 | + thread_context->hw_register.a29 = 0xA29; |
| 94 | + thread_context->hw_register.a28 = 0xA28; |
| 95 | + thread_context->hw_register.a31 = 0xA31; |
| 96 | + thread_context->hw_register.a30 = 0xA30; |
| 97 | + |
| 98 | + thread_context->hw_register.a1 = 0xA01; |
| 99 | + thread_context->hw_register.a0 = 0xA00; |
| 100 | + thread_context->hw_register.a3 = 0xA03; |
| 101 | + thread_context->hw_register.a2 = 0xA02; |
| 102 | + thread_context->hw_register.a5 = 0xA05; |
| 103 | + thread_context->hw_register.a4 = (rt_uint32_t)parameter; |
| 104 | + thread_context->hw_register.a7 = 0xA07; |
| 105 | + thread_context->hw_register.a6 = 0xA06; |
| 106 | + thread_context->hw_register.a9 = 0xA09; |
| 107 | + thread_context->hw_register.a8 = 0xA08; |
| 108 | + thread_context->hw_register.a11 = 0xA11; |
| 109 | + thread_context->hw_register.a10 = 0xA10; |
| 110 | + thread_context->hw_register.a13 = 0xA13; |
| 111 | + thread_context->hw_register.a12 = 0xA12; |
| 112 | + |
| 113 | + thread_context->hw_register.a15 = 0xA15; |
| 114 | + thread_context->hw_register.a14 = 0xA14; |
| 115 | + thread_context->hw_register.dp = rt_hw_get_current_dp(); |
| 116 | + thread_context->hw_register.sp = (rt_uint32_t)stk; |
| 117 | + |
| 118 | + /* return task's current stack address */ |
| 119 | + return (rt_uint8_t *)thread_context - 8; |
| 120 | +} |
0 commit comments