1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-05-25 10:18:45 +00:00

fix(core): fix exc_return codes for non-secure world

[no changelog]
This commit is contained in:
cepetr 2025-05-07 16:17:07 +02:00 committed by cepetr
parent 9df360785e
commit 0f0c28404b
3 changed files with 18 additions and 2 deletions

View File

@ -188,8 +188,11 @@ __attribute((naked, no_stack_protector)) void ensure_thread_mode(void) {
"MRS R0, CONTROL \n" // Clear SPSEL to use MSP for thread "MRS R0, CONTROL \n" // Clear SPSEL to use MSP for thread
"BIC R0, R0, #3 \n" // Clear nPRIV to run in privileged mode "BIC R0, R0, #3 \n" // Clear nPRIV to run in privileged mode
"MSR CONTROL, R0 \n" "MSR CONTROL, R0 \n"
#if !defined(__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE == 3U)
"LDR LR, = 0xFFFFFFF9 \n" // Return to Secure Thread mode, use MSP "LDR LR, = 0xFFFFFFF9 \n" // Return to Secure Thread mode, use MSP
#else
"LDR LR, = 0xFFFFFFB8 \n" // Return to Thread mode, use MSP
#endif
"BX LR \n"); "BX LR \n");
} }

View File

@ -66,8 +66,13 @@ __attribute__((naked, no_stack_protector)) static uint32_t _invoke_app_callback(
"vmov r0, s0 \n" // Use FPU instruction to ensure lazy "vmov r0, s0 \n" // Use FPU instruction to ensure lazy
// stacking // stacking
#if !defined(__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE == 3U)
// return to Secure Thread mode (use Secure PSP) // return to Secure Thread mode (use Secure PSP)
"ldr lr, = 0xFFFFFFFD \n" "ldr lr, = 0xFFFFFFFD \n"
#else
// return to Thread mode (use PSP)
"ldr lr, = 0xFFFFFFBC \n"
#endif
"bx lr \n"); "bx lr \n");
} }

View File

@ -149,7 +149,11 @@ bool systask_init(systask_t* task, uint32_t stack_ptr, uint32_t stack_size,
memset(task, 0, sizeof(systask_t)); memset(task, 0, sizeof(systask_t));
task->sp = stack_ptr + stack_size; task->sp = stack_ptr + stack_size;
task->sp_lim = stack_ptr + 256; task->sp_lim = stack_ptr + 256;
task->exc_return = 0xFFFFFFED; // Thread mode, use PSP, pop FP context #if !defined(__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE == 3U)
task->exc_return = 0xFFFFFFED; // Secure Thread mode, use PSP, pop FP context
#else
task->exc_return = 0xFFFFFFAC; // Thread mode, use PSP, pop FP context
#endif
task->id = id; task->id = id;
task->mpu_mode = MPU_MODE_APP; task->mpu_mode = MPU_MODE_APP;
task->applet = applet; task->applet = applet;
@ -216,7 +220,11 @@ bool systask_push_call(systask_t* task, void* entrypoint, uint32_t arg1,
} }
// Return to thread mode, use PSP, pop FP context // Return to thread mode, use PSP, pop FP context
#if !defined(__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE == 3U)
task->exc_return = 0xFFFFFFED; task->exc_return = 0xFFFFFFED;
#else
task->exc_return = 0xFFFFFFAC;
#endif
stk_frame[STK_FRAME_R0] = arg1; stk_frame[STK_FRAME_R0] = arg1;
stk_frame[STK_FRAME_R1] = arg2; stk_frame[STK_FRAME_R1] = arg2;