⚠️ The code is based on: https://gitlab.com/riseproject/riscv-optee/optee_os/-/tree/dev-optee-mpxy
Commit ID:
75df9ba41a404aec897399ead0ff0aebcbff48ca
| |
| |
| |
| |
| |
thread_handle_std_abi()- If
args->a0 == OPTEE_ABI_CALL_RETURN_FROM_RPC: - Otherwise:
- If
-
thread_alloc_and_run()- Call
__thread_alloc_and_run()withpcparameter set to thread_std_abi_entry(). So when thread is resumed, thread_std_abi_entry() will be executed.
- Call
-
__thread_alloc_and_run()- Find the free thread whose state is
THREAD_STATE_FREE.- If found, set thread’s state to
THREAD_STATE_ACTIVE.
- If found, set thread’s state to
- Set the current thread ID (
l->curr_thread) to the founded thread ID. - Call
init_regs()to initialize the registers to be restored of the thread.thread->regs.epcis set topc.
- Call thread_resume() to resume the thread.
- Find the free thread whose state is
-
thread_resume_from_rpc()- Check if the state of the thread to be resumed (indicated by
thread_id) isTHREAD_STATE_SUSPENDED.- If yes, set thread’s state to
THREAD_STATE_ACTIVE.- Set the current thread ID (
l->curr_thread) tothread_id. - Call thread_resume() to resume the thread.
- Set the current thread ID (
- Otherwise, return and do nothing.
- If yes, set thread’s state to
- Check if the state of the thread to be resumed (indicated by
| |
| |
__thread_std_abi_entry()- Call
std_abi_entry()
- Call
thread_handle_fast_abi()-
tee_entry_fast() -
__tee_entry_fast()- If
args->a0:OPTEE_ABI_CALLS_COUNT:tee_entry_get_api_call_count()
OPTEE_ABI_CALLS_UID:tee_entry_get_api_uuid()
- …
- If
-
thread_enter_user_mode()- Disable all interrupts.
- Call
xstatus_for_xret()to getxstatuswithxstatus.PIEset to1,xstatus.PPset toU-mode.- The returned
xstatuswill be saved along with$a0,$a1,$a2,$a3,user_sp,entry_func, and$xieto current thread’s reg context (struct thread_ctx_regs).
- The returned
- Call
__thread_enter_user_mode()to switch to U-mode.entry_funcis set tothread_ctx_regs.raand then set to$xepcso that whenxretis called to return to U-mode,entry_funcwill be executed. - Re-enable original interrupts.
thread_state_suspend()- Current thread’s context (
struct thread_ctx) will be updated with:flags |= THREAD_FLAGS_COPY_ARGS_ON_RETURNregs.status = xstatus to returnregs.epc = [.thread_rpc_return](/posts/optee-rpc/#hl-0-84)(defined withinthread_rpc_xstatus())- So when the thread is returned from RPC by
thread_resume_from_rpc(),.thread_rpc_returnwill be called.
- So when the thread is returned from RPC by
state = THREAD_STATE_SUSPENDED- Current thread ID (
l->curr_thread) is set toTHREAD_ID_INVALIDto indicate no active current thread.
- Current thread’s context (
thread_mask_exceptions()- Mask the interrupts.
thread_unmask_exceptions()- Unmask the interrupts.