1;/* 2; * Copyright (c) 2006-2022, RT-Thread Development Team 3; * 4; * SPDX-License-Identifier: Apache-2.0 5; * 6; * Change Logs: 7; * Date Author Notes 8; * 2019-10-25 tyx first version 9; * 2021-03-26 lxf modify bad instruction 10; */ 11 12;/* 13; * @addtogroup cortex-m33 14; */ 15 16 17 SECTION .text:CODE(2) 18 THUMB 19 REQUIRE8 20 PRESERVE8 21 22 IMPORT rt_secure_svc_handle 23 24;/* 25; * int tzcall(int id, rt_ubase_t arg0, rt_ubase_t arg1, rt_ubase_t arg2); 26; */ 27 EXPORT tzcall 28tzcall: 29 SVC 1 ;/* call SVC 1 */ 30 BX LR 31 32tzcall_entry: 33 PUSH {R1, R4, LR} 34 MOV R4, R1 ;/* copy thread SP to R4 */ 35 LDMFD R4!, {r0 - r3} ;/* pop user stack, get input arg0, arg1, arg2 */ 36 STMFD R4!, {r0 - r3} ;/* push stack, user stack recovery */ 37 BL rt_secure_svc_handle ;/* call fun */ 38 POP {R1, R4, LR} 39 STR R0, [R1] ;/* update return value */ 40 BX LR ;/* return to thread */ 41 42syscall_entry: 43 BX LR ;/* return to user app */ 44 45 EXPORT SVC_Handler 46SVC_Handler: 47 48 ;/* get SP, save to R1 */ 49 MRS R1, MSP ;/* get fault context from handler. */ 50 TST LR, #0x04 ;/* if(!EXC_RETURN[2]) */ 51 BEQ get_sp_done 52 MRS R1, PSP ;/* get fault context from thread. */ 53get_sp_done: 54 55 ;/* get svc index */ 56 LDR R0, [R1, #24] 57 LDRB R0, [R0, #-2] 58 59 ;/* if svc == 0, do system call */ 60 CMP R0, #0x0 61 BEQ syscall_entry 62 63 ;/* if svc == 1, do TrustZone call */ 64 CMP R0, #0x1 65 BEQ tzcall_entry 66 67 END 68