Skip to content

Commit

Permalink
core: riscv: Implement thread_vector_table for ABI and FIQ entries
Browse files Browse the repository at this point in the history
Implement thread_vector_table which only includes entries for standard
ABI, fast ABI, and foreign interrupts. Most of code is referenced from
ARM architecture. The thread_vector_table will be registered into higher
privileged software, such as M-mode firmware. The higher privileged
software can jump(mret) to OP-TEE based on this vector table.

Signed-off-by: Alvin Chang <alvinga@andestech.com>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
gagachang authored and jforissier committed Oct 13, 2023
1 parent 0fb2293 commit 0cbfd09
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/arch/riscv/kernel/asm-defines.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ DEFINES
DEFINE(CORE_MMU_CONFIG_SIZE, sizeof(struct core_mmu_config));
DEFINE(CORE_MMU_CONFIG_SATP,
offsetof(struct core_mmu_config, satp));

/* struct thread_abi_args */
DEFINE(THREAD_ABI_ARGS_A0, offsetof(struct thread_abi_args, a0));
DEFINE(THREAD_ABI_ARGS_SIZE, sizeof(struct thread_abi_args));
}
64 changes: 64 additions & 0 deletions core/arch/riscv/kernel/thread_optee_abi_rv.S
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,67 @@ FUNC thread_rpc , :
addi sp, sp, REGOFF(4)
ret
END_FUNC thread_rpc

LOCAL_FUNC vector_std_abi_entry, : , .identity_map
jal thread_handle_std_abi
/*
* Normally thread_handle_std_abi() should return via
* thread_exit(), thread_rpc(), but if thread_handle_std_abi()
* hasn't switched stack (error detected) it will do a normal "C"
* return.
*/
/* Restore thread_handle_std_abi() return value */
mv a1, a0
li a2, 0
li a3, 0
li a4, 0
li a0, TEEABI_OPTEED_RETURN_CALL_DONE

/* Return to untrusted domain */
j thread_return_to_ree
END_FUNC vector_std_abi_entry

LOCAL_FUNC vector_fast_abi_entry , : , .identity_map
addi sp, sp, -THREAD_ABI_ARGS_SIZE
store_xregs sp, THREAD_ABI_ARGS_A0, REG_A0, REG_A7
mv a0, sp
jal thread_handle_fast_abi
load_xregs sp, THREAD_ABI_ARGS_A0, REG_A1, REG_A7
addi sp, sp, THREAD_ABI_ARGS_SIZE

li a0, TEEABI_OPTEED_RETURN_CALL_DONE
/* Return to untrusted domain */
j thread_return_to_ree
END_FUNC vector_fast_abi_entry

LOCAL_FUNC vector_fiq_entry , : , .identity_map
/* Secure Monitor received a FIQ and passed control to us. */
jal interrupt_main_handler

li a0, TEEABI_OPTEED_RETURN_FIQ_DONE
/* Return to untrusted domain */
j thread_return_to_ree
END_FUNC vector_fiq_entry

/*
* Vector table supplied to M-mode secure monitor (e.g., openSBI) at
* initialization.
*
* Note that M-mode secure monitor depends on the layout of this vector table,
* any change in layout has to be synced with M-mode secure monitor.
*/
FUNC thread_vector_table , : , .identity_map, , nobti
.option push
.option norvc
j vector_std_abi_entry
j vector_fast_abi_entry
j .
j .
j .
j .
j vector_fiq_entry
j .
j .
.option pop
END_FUNC thread_vector_table
DECLARE_KEEP_PAGER thread_vector_table

0 comments on commit 0cbfd09

Please sign in to comment.