Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ SVC_Handler PROC
IF :DEF:MPU_LOAD
IMPORT osRtxMpuLoad
ENDIF
#if (MBED_TZ_DEFAULT_ACCESS == 1)
IF DOMAIN_NS = 1
IMPORT TZ_LoadContext_S
IMPORT TZ_StoreContext_S
ENDIF
#endif

TST LR,#0x04 ; Determine return stack from EXC_RETURN bit 2
ITE EQ
Expand Down Expand Up @@ -100,13 +102,15 @@ SVC_Context
ENDIF

SVC_ContextSave
#if (MBED_TZ_DEFAULT_ACCESS == 1)
IF DOMAIN_NS = 1
LDR R0,[R1,#TCB_TZM_OFS] ; Load TrustZone memory identifier
CBZ R0,SVC_ContextSave1 ; Branch if there is no secure context
PUSH {R1,R2,R3,LR} ; Save registers and EXC_RETURN
BL TZ_StoreContext_S ; Store secure context
POP {R1,R2,R3,LR} ; Restore registers and EXC_RETURN
ENDIF
#endif

SVC_ContextSave1
MRS R0,PSP ; Get PSP
Expand All @@ -132,13 +136,15 @@ SVC_ContextSwitch
ENDIF

SVC_ContextRestore
#if (MBED_TZ_DEFAULT_ACCESS == 1)
IF DOMAIN_NS = 1
LDR R0,[R2,#TCB_TZM_OFS] ; Load TrustZone memory identifier
CBZ R0,SVC_ContextRestore1 ; Branch if there is no secure context
PUSH {R2,R3} ; Save registers
BL TZ_LoadContext_S ; Load secure context
POP {R2,R3} ; Restore registers
ENDIF
#endif

SVC_ContextRestore1
LDR R0,[R2,#TCB_SM_OFS] ; Load stack memory base
Expand All @@ -147,10 +153,12 @@ SVC_ContextRestore1
LDR R0,[R2,#TCB_SP_OFS] ; Load SP
ORR LR,R1,#0xFFFFFF00 ; Set EXC_RETURN

#if (MBED_TZ_DEFAULT_ACCESS == 1)
IF DOMAIN_NS = 1
TST LR,#0x40 ; Check domain of interrupted thread
BNE SVC_ContextRestore2 ; Branch if secure
ENDIF
#endif

IF __FPU_USED = 1
TST LR,#0x10 ; Check if extended stack frame
Expand Down Expand Up @@ -216,10 +224,12 @@ Sys_Context PROC
IF :DEF:MPU_LOAD
IMPORT osRtxMpuLoad
ENDIF
#if (MBED_TZ_DEFAULT_ACCESS == 1)
IF DOMAIN_NS = 1
IMPORT TZ_LoadContext_S
IMPORT TZ_StoreContext_S
ENDIF
#endif

LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run
LDM R3,{R1,R2} ; Load osRtxInfo.thread.run: curr & next
Expand All @@ -228,6 +238,7 @@ Sys_Context PROC
BXEQ LR ; Exit when threads are the same

Sys_ContextSave
#if (MBED_TZ_DEFAULT_ACCESS == 1)
IF DOMAIN_NS = 1
LDR R0,[R1,#TCB_TZM_OFS] ; Load TrustZone memory identifier
CBZ R0,Sys_ContextSave1 ; Branch if there is no secure context
Expand All @@ -239,6 +250,7 @@ Sys_ContextSave
MRSNE R0,PSP ; Get PSP
BNE Sys_ContextSave2 ; Branch if secure
ENDIF
#endif

Sys_ContextSave1
MRS R0,PSP ; Get PSP
Expand All @@ -264,13 +276,15 @@ Sys_ContextSwitch
ENDIF

Sys_ContextRestore
#if (MBED_TZ_DEFAULT_ACCESS == 1)
IF DOMAIN_NS = 1
LDR R0,[R2,#TCB_TZM_OFS] ; Load TrustZone memory identifier
CBZ R0,Sys_ContextRestore1 ; Branch if there is no secure context
PUSH {R2,R3} ; Save registers
BL TZ_LoadContext_S ; Load secure context
POP {R2,R3} ; Restore registers
ENDIF
#endif

Sys_ContextRestore1
LDR R0,[R2,#TCB_SM_OFS] ; Load stack memory base
Expand All @@ -279,10 +293,12 @@ Sys_ContextRestore1
LDR R0,[R2,#TCB_SP_OFS] ; Load SP
ORR LR,R1,#0xFFFFFF00 ; Set EXC_RETURN

#if (MBED_TZ_DEFAULT_ACCESS == 1)
IF DOMAIN_NS = 1
TST LR,#0x40 ; Check domain of interrupted thread
BNE Sys_ContextRestore2 ; Branch if secure
ENDIF
#endif

IF __FPU_USED = 1
TST LR,#0x10 ; Check if extended stack frame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ SVC_Context:
.endif

SVC_ContextSave:
#if (MBED_TZ_DEFAULT_ACCESS == 1)
.if DOMAIN_NS == 1
LDR R0,[R1,#TCB_TZM_OFS] // Load TrustZone memory identifier
CBZ R0,SVC_ContextSave1 // Branch if there is no secure context
PUSH {R1,R2,R3,LR} // Save registers and EXC_RETURN
BL TZ_StoreContext_S // Store secure context
POP {R1,R2,R3,LR} // Restore registers and EXC_RETURN
.endif
#endif

SVC_ContextSave1:
MRS R0,PSP // Get PSP
Expand All @@ -121,13 +123,15 @@ SVC_ContextSwitch:
STR R2,[R3] // osRtxInfo.thread.run: curr = next

SVC_ContextRestore:
#if (MBED_TZ_DEFAULT_ACCESS == 1)
.if DOMAIN_NS == 1
LDR R0,[R2,#TCB_TZM_OFS] // Load TrustZone memory identifier
CBZ R0,SVC_ContextRestore1 // Branch if there is no secure context
PUSH {R2,R3} // Save registers
BL TZ_LoadContext_S // Load secure context
POP {R2,R3} // Restore registers
.endif
#endif

SVC_ContextRestore1:
LDR R0,[R2,#TCB_SM_OFS] // Load stack memory base
Expand Down Expand Up @@ -219,6 +223,7 @@ Sys_Context:
BXEQ LR // Exit when threads are the same

Sys_ContextSave:
#if (MBED_TZ_DEFAULT_ACCESS == 1)
.if DOMAIN_NS == 1
LDR R0,[R1,#TCB_TZM_OFS] // Load TrustZone memory identifier
CBZ R0,Sys_ContextSave1 // Branch if there is no secure context
Expand All @@ -230,6 +235,7 @@ Sys_ContextSave:
MRSNE R0,PSP // Get PSP
BNE Sys_ContextSave2 // Branch if secure
.endif
#endif

Sys_ContextSave1:
MRS R0,PSP // Get PSP
Expand All @@ -248,13 +254,15 @@ Sys_ContextSwitch:
STR R2,[R3] // osRtxInfo.run: curr = next

Sys_ContextRestore:
#if (MBED_TZ_DEFAULT_ACCESS == 1)
.if DOMAIN_NS == 1
LDR R0,[R2,#TCB_TZM_OFS] // Load TrustZone memory identifier
CBZ R0,Sys_ContextRestore1 // Branch if there is no secure context
PUSH {R2,R3} // Save registers
BL TZ_LoadContext_S // Load secure context
POP {R2,R3} // Restore registers
.endif
#endif

Sys_ContextRestore1:
LDR R0,[R2,#TCB_SM_OFS] // Load stack memory base
Expand Down
2 changes: 1 addition & 1 deletion rtos/TARGET_CORTEX/rtx5/RTX/Source/rtx_kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static osStatus_t svcRtxKernelInitialize (void) {
return osError;
}

#if (DOMAIN_NS == 1)
#if (DOMAIN_NS == 1) && (MBED_TZ_DEFAULT_ACCESS == 1)
// Initialize Secure Process Stack
if (TZ_InitContextSystem_S() == 0U) {
EvrRtxKernelError(osRtxErrorTZ_InitContext_S);
Expand Down
12 changes: 6 additions & 6 deletions rtos/TARGET_CORTEX/rtx5/RTX/Source/rtx_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ static osThreadId_t svcRtxThreadNew (osThreadFunc_t func, void *argument, const
const char *name;
uint32_t *ptr;
uint32_t n;
#if (DOMAIN_NS == 1)
#if (DOMAIN_NS == 1) && (MBED_TZ_DEFAULT_ACCESS == 1)
TZ_ModuleId_t tz_module;
TZ_MemoryId_t tz_memory;
#endif
Expand All @@ -616,7 +616,7 @@ static osThreadId_t svcRtxThreadNew (osThreadFunc_t func, void *argument, const
stack_mem = attr->stack_mem;
stack_size = attr->stack_size;
priority = attr->priority;
#if (DOMAIN_NS == 1)
#if (DOMAIN_NS == 1) && (MBED_TZ_DEFAULT_ACCESS == 1)
tz_module = attr->tz_module;
#endif
if (thread != NULL) {
Expand Down Expand Up @@ -657,7 +657,7 @@ static osThreadId_t svcRtxThreadNew (osThreadFunc_t func, void *argument, const
stack_mem = NULL;
stack_size = 0U;
priority = osPriorityNormal;
#if (DOMAIN_NS == 1)
#if (DOMAIN_NS == 1) && (MBED_TZ_DEFAULT_ACCESS == 1)
tz_module = 0U;
#endif
}
Expand Down Expand Up @@ -727,7 +727,7 @@ static osThreadId_t svcRtxThreadNew (osThreadFunc_t func, void *argument, const
flags |= osRtxFlagSystemMemory;
}

#if (DOMAIN_NS == 1)
#if (DOMAIN_NS == 1) && (MBED_TZ_DEFAULT_ACCESS == 1)
// Allocate secure process stack
if ((thread != NULL) && (tz_module != 0U)) {
tz_memory = TZ_AllocModuleContext_S(tz_module);
Expand Down Expand Up @@ -784,7 +784,7 @@ static osThreadId_t svcRtxThreadNew (osThreadFunc_t func, void *argument, const
thread->stack_size = stack_size;
thread->sp = (uint32_t)stack_mem + stack_size - 64U;
thread->thread_addr = (uint32_t)func;
#if (DOMAIN_NS == 1)
#if (DOMAIN_NS == 1) && (MBED_TZ_DEFAULT_ACCESS == 1)
thread->tz_memory = tz_memory;
#ifdef RTX_TF_M_EXTENSION
thread->tz_module = tz_module;
Expand Down Expand Up @@ -1104,7 +1104,7 @@ static void osRtxThreadFree (os_thread_t *thread) {
thread->state = osRtxThreadInactive;
thread->id = osRtxIdInvalid;

#if (DOMAIN_NS == 1)
#if (DOMAIN_NS == 1) && (MBED_TZ_DEFAULT_ACCESS == 1)
// Free secure process stack
if (thread->tz_memory != 0U) {
(void)TZ_FreeModuleContext_S(thread->tz_memory);
Expand Down