OP-TEE: Threads
2024-10-6
| 2025-1-12
本文字數 1021閱讀時長 3 分鐘
type
status
date
slug
summary
tags
category
icon
password
⚠️
The code is based on: https://gitlab.com/riseproject/riscv-optee/optee_os/-/tree/dev-optee-mpxy Commit ID: 75df9ba41a404aec897399ead0ff0aebcbff48ca


  • __thread_alloc_and_run()
    • Find the free thread whose state is THREAD_STATE_FREE.
      • If found, set thread’s state to THREAD_STATE_ACTIVE.
    • 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.epc is set to pc.
    • Call thread_resume() to resume the thread.
  • thread_resume_from_rpc()
    • Check if the state of the thread to be resumed (indicated by thread_id) is THREAD_STATE_SUSPENDED.
      • If yes, set thread’s state to THREAD_STATE_ACTIVE.
        • Set the current thread ID (l->curr_thread) to thread_id.
        • Call thread_resume() to resume the thread.
      • Otherwise, return and do nothing.


  • __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()

  • thread_enter_user_mode()
    • Disable all interrupts.
    • Call xstatus_for_xret() to get xstatus with xstatus.PIE set to 1, xstatus.PP set to U-mode.
      • The returned xstatus will be saved along with $a0, $a1, $a2, $a3, user_sp, entry_func, and $xie to current thread’s reg context (struct thread_ctx_regs).
    • Call __thread_enter_user_mode() to switch to U-mode. entry_func is set to thread_ctx_regs.ra and then set to $xepc so that when xret is called to return to U-mode, entry_func will be executed.
    • Re-enable original interrupts.
  • thread_state_suspend()
    • Current thread's context (struct thread_ctx) will be updated with:

  • thread_mask_exceptions()
    • Mask the interrupts.
  • thread_unmask_exceptions()
    • Unmask the interrupts.
  • OP-TEE
  • OP-TEE: SBI MPXYOP-TEE: Interrupts / Exceptions
    Loading...
    目錄