1 /* 2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 */ 4 5 #include <k_api.h> 6 cpu_task_stack_init(cpu_stack_t * stack_base,size_t stack_size,void * arg,task_entry_t entry)7void *cpu_task_stack_init(cpu_stack_t *stack_base, size_t stack_size, 8 void *arg, task_entry_t entry) 9 { 10 cpu_stack_t *stk; 11 uint32_t temp = (uint32_t)(stack_base + stack_size); 12 13 /* stack aligned by 8 byte */ 14 temp &= 0xfffffff8; 15 stk = (cpu_stack_t *)temp; 16 17 /* task context saved & restore by hardware: */ 18 *(--stk) = (cpu_stack_t)0x01000000L; /* xPSR: EPSR.T = 1, thumb mode */ 19 *(--stk) = (cpu_stack_t)entry; /* Entry Point */ 20 *(--stk) = (cpu_stack_t)krhino_task_deathbed; /* R14 (LR) */ 21 *(--stk) = (cpu_stack_t)0x12121212L; /* R12 */ 22 *(--stk) = (cpu_stack_t)0x03030303L; /* R3 */ 23 *(--stk) = (cpu_stack_t)0x02020202L; /* R2 */ 24 *(--stk) = (cpu_stack_t)0x01010101L; /* R1 */ 25 *(--stk) = (cpu_stack_t)arg; /* R0 : argument */ 26 27 /* task context saved & restore by software: */ 28 /* EXC_RETURN = 0xFFFFFFFDL 29 Task begin state: Thread mode + non-floating-point state + PSP */ 30 *(--stk) = (cpu_stack_t)0xFFFFFFFDL; 31 32 *(--stk) = (cpu_stack_t)0x11111111L; /* R11 */ 33 *(--stk) = (cpu_stack_t)0x10101010L; /* R10 */ 34 *(--stk) = (cpu_stack_t)0x09090909L; /* R9 */ 35 *(--stk) = (cpu_stack_t)0x08080808L; /* R8 */ 36 *(--stk) = (cpu_stack_t)0x07070707L; /* R7 */ 37 *(--stk) = (cpu_stack_t)0x06060606L; /* R6 */ 38 *(--stk) = (cpu_stack_t)0x05050505L; /* R5 */ 39 *(--stk) = (cpu_stack_t)0x04040404L; /* R4 */ 40 41 return stk; 42 } 43 44