/* Change Logs: Date Author Notes  Jesven first version  Shell Move part of the codes to C from asm in signal handling  Shell Support a new backtrace framework  */
int arch_set_thread_context(void(*exit)(void), void *new_thread_stack, void *user_stack, void **thread_sp)
/* Change Logs: Date Author Notes  Jesven first version  Shell Move part of the codes to C from asm in signal handling  Shell Support a new backtrace framework  */
int arch_set_thread_context(void(*exit)(void), void *new_thread_stack, void *user_stack, void **thread_sp)
{
    struct rt_hw_exp_stack *syscall_frame;
    struct rt_hw_exp_stack *thread_frame;
    struct rt_hw_exp_stack *ori_syscall = rt_thread_self()->user_ctx.ctx;
    RT_ASSERT(ori_syscall != RT_NULL);
    thread_frame = (void *)((long)new_thread_stack - sizeof(struct rt_hw_exp_stack));
    syscall_frame = (void *)((long)new_thread_stack - 2 * sizeof(struct rt_hw_exp_stack));
    memcpy(syscall_frame, ori_syscall, sizeof(*syscall_frame));
    syscall_frame->sp_el0 = (long)user_stack;
    syscall_frame->x0 = 0;
    thread_frame->cpsr = ((3 << 6) | 0x4 | 0x1);
    thread_frame->pc = (long)exit;
    thread_frame->x0 = 0;
    *thread_sp = syscall_frame;
    return 0;
}