mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-17 07:05:31 +08:00
[libcpu][cm33] support cortex-m33
This commit is contained in:
1 parent
5a1349ab96
commit
a16f27d84e
9 files changed
+1751
No files matched your search
@@ -0,0 +1,23 @@
|
||||
# RT-Thread building script for component
|
||||
|
||||
from building import *
|
||||
|
||||
Import('rtconfig')
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c') + Glob('*.cpp')
|
||||
CPPPATH = [cwd]
|
||||
|
||||
if rtconfig.PLATFORM == 'armcc':
|
||||
src += Glob('*_rvds.S')
|
||||
|
||||
if rtconfig.PLATFORM == 'gcc':
|
||||
src += Glob('*_init.S')
|
||||
src += Glob('*_gcc.S')
|
||||
|
||||
if rtconfig.PLATFORM == 'iar':
|
||||
src += Glob('*_iar.S')
|
||||
|
||||
group = DefineGroup('cpu', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-10-25 tyx first version
|
||||
*/
|
||||
|
||||
.cpu cortex-m4
|
||||
.syntax unified
|
||||
.thumb
|
||||
.text
|
||||
|
||||
/*
|
||||
* int tzcall(int id, rt_ubase_t arg0, rt_ubase_t arg1, rt_ubase_t arg2);
|
||||
*/
|
||||
.global tzcall
|
||||
.type tzcall, %function
|
||||
tzcall:
|
||||
SVC 1 /* call SVC 1 */
|
||||
BX LR
|
||||
|
||||
tzcall_entry:
|
||||
PUSH {R1, R4, LR}
|
||||
MOV R4, R1 /* copy thread SP to R4 */
|
||||
LDMFD R4!, {r0 - r3} /* pop user stack, get input arg0, arg1, arg2 */
|
||||
STMFD R4!, {r0 - r3} /* push stack, user stack recovery */
|
||||
BL rt_secure_svc_handle /* call fun */
|
||||
POP {R1, R4, LR}
|
||||
STR R0, [R1] /* update return value */
|
||||
BX LR /* return to thread */
|
||||
|
||||
syscall_entry:
|
||||
BX LR /* return to user app */
|
||||
|
||||
.global SVC_Handler
|
||||
.type SVC_Handler, %function
|
||||
SVC_Handler:
|
||||
|
||||
/* get SP, save to R1 */
|
||||
MRS R1, MSP /* get fault context from handler. */
|
||||
TST LR, #0x04 /* if(!EXC_RETURN[2]) */
|
||||
BEQ get_sp_done
|
||||
MRS R1, PSP /* get fault context from thread. */
|
||||
get_sp_done:
|
||||
|
||||
/* get svc index */
|
||||
LDR R0, [R1, #24]
|
||||
LDRB R0, [R0, #-2]
|
||||
|
||||
/* if svc == 0, do system call */
|
||||
CMP R0, #0x0
|
||||
BEQ syscall_entry
|
||||
|
||||
/* if svc == 1, do TrustZone call */
|
||||
CMP R0, #0x1
|
||||
BEQ tzcall_entry
|
||||
@@ -0,0 +1,63 @@
|
||||
;/*
|
||||
; * Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
; *
|
||||
; * SPDX-License-Identifier: Apache-2.0
|
||||
; *
|
||||
; * Change Logs:
|
||||
; * Date Author Notes
|
||||
; * 2019-10-25 tyx first version
|
||||
; */
|
||||
|
||||
;/*
|
||||
; * @addtogroup cortex-m33
|
||||
; */
|
||||
|
||||
SECTION .text:CODE(2)
|
||||
THUMB
|
||||
REQUIRE8
|
||||
PRESERVE8
|
||||
|
||||
;/*
|
||||
; * int tzcall(int id, rt_ubase_t arg0, rt_ubase_t arg1, rt_ubase_t arg2);
|
||||
; */
|
||||
.global tzcall
|
||||
.type tzcall, %function
|
||||
tzcall:
|
||||
SVC 1 ;/* call SVC 1 */
|
||||
BX LR
|
||||
|
||||
tzcall_entry:
|
||||
PUSH {R1, R4, LR}
|
||||
MOV R4, R1 ;/* copy thread SP to R4 */
|
||||
LDMFD R4!, {r0 - r3} ;/* pop user stack, get input arg0, arg1, arg2 */
|
||||
STMFD R4!, {r0 - r3} ;/* push stack, user stack recovery */
|
||||
BL rt_secure_svc_handle ;/* call fun */
|
||||
POP {R1, R4, LR}
|
||||
STR R0, [R1] ;/* update return value */
|
||||
BX LR ;/* return to thread */
|
||||
|
||||
syscall_entry:
|
||||
BX LR ;/* return to user app */
|
||||
|
||||
.global SVC_Handler
|
||||
.type SVC_Handler, %function
|
||||
SVC_Handler:
|
||||
|
||||
;/* get SP, save to R1 */
|
||||
MRS R1, MSP ;/* get fault context from handler. */
|
||||
TST LR, #0x04 ;/* if(!EXC_RETURN[2]) */
|
||||
BEQ get_sp_done
|
||||
MRS R1, PSP ;/* get fault context from thread. */
|
||||
get_sp_done:
|
||||
|
||||
;/* get svc index */
|
||||
LDR R0, [R1, #24]
|
||||
LDRB R0, [R0, #-2]
|
||||
|
||||
;/* if svc == 0, do system call */
|
||||
CMP R0, #0x0
|
||||
BEQ syscall_entry
|
||||
|
||||
;/* if svc == 1, do TrustZone call */
|
||||
CMP R0, #0x1
|
||||
BEQ tzcall_entry
|
||||
@@ -0,0 +1,74 @@
|
||||
;/*
|
||||
; * Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
; *
|
||||
; * SPDX-License-Identifier: Apache-2.0
|
||||
; *
|
||||
; * Change Logs:
|
||||
; * Date Author Notes
|
||||
; * 2019-10-25 tyx first version
|
||||
; */
|
||||
|
||||
AREA |.text|, CODE, READONLY, ALIGN=2
|
||||
THUMB
|
||||
REQUIRE8
|
||||
PRESERVE8
|
||||
|
||||
IMPORT rt_secure_svc_handle
|
||||
|
||||
;/*
|
||||
; * int tzcall(int id, rt_ubase_t arg0, rt_ubase_t arg1, rt_ubase_t arg2);
|
||||
; */
|
||||
tzcall PROC
|
||||
EXPORT tzcall
|
||||
SVC 1 ;call SVC 1
|
||||
BX LR
|
||||
|
||||
ENDP
|
||||
|
||||
tzcall_entry PROC
|
||||
PUSH {R1, R4, LR}
|
||||
MOV R4, R1 ; copy thread SP to R4
|
||||
LDMFD R4!, {r0 - r3} ; pop user stack, get input arg0, arg1, arg2
|
||||
STMFD R4!, {r0 - r3} ; push stack, user stack recovery
|
||||
BL rt_secure_svc_handle ; call fun
|
||||
POP {R1, R4, LR}
|
||||
STR R0, [R1] ; update return value
|
||||
BX LR ; return to thread
|
||||
|
||||
ENDP
|
||||
|
||||
syscall_entry PROC
|
||||
BX LR ; return to user app
|
||||
|
||||
ENDP
|
||||
|
||||
;/*
|
||||
; * void SVC_Handler(void);
|
||||
; */
|
||||
SVC_Handler PROC
|
||||
EXPORT SVC_Handler
|
||||
|
||||
; get SP, save to R1
|
||||
MRS R1, MSP ;get fault context from handler
|
||||
TST LR, #0x04 ;if(!EXC_RETURN[2])
|
||||
BEQ get_sp_done
|
||||
MRS R1, PSP ;get fault context from thread
|
||||
get_sp_done
|
||||
|
||||
; get svc index
|
||||
LDR R0, [R1, #24]
|
||||
LDRB R0, [R0, #-2]
|
||||
|
||||
;if svc == 0, do system call
|
||||
CMP R0, #0x0
|
||||
BEQ syscall_entry
|
||||
|
||||
;if svc == 1, do TrustZone call
|
||||
CMP R0, #0x1
|
||||
BEQ tzcall_entry
|
||||
|
||||
ENDP
|
||||
|
||||
ALIGN
|
||||
|
||||
END
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2019, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-10-28 tyx the first version.
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
extern void TZ_InitContextSystem_S(void);
|
||||
extern rt_uint32_t TZ_AllocModuleContext_S (rt_uint32_t module);
|
||||
extern rt_uint32_t TZ_FreeModuleContext_S(rt_uint32_t id);
|
||||
extern rt_uint32_t TZ_LoadContext_S(rt_uint32_t id);
|
||||
extern rt_uint32_t TZ_StoreContext_S(rt_uint32_t id);
|
||||
extern int tzcall(int id, rt_ubase_t arg0, rt_ubase_t arg1, rt_ubase_t arg2);
|
||||
|
||||
#define TZ_INIT_CONTEXT_ID (0x1001)
|
||||
#define TZ_ALLOC_CONTEXT_ID (0x1002)
|
||||
#define TZ_FREE_CONTEXT_ID (0x1003)
|
||||
|
||||
rt_ubase_t rt_trustzone_current_context;
|
||||
|
||||
#if defined(__CC_ARM)
|
||||
static __inline rt_uint32_t __get_IPSR(void)
|
||||
{
|
||||
register rt_uint32_t result __asm("ipsr");
|
||||
return(result);
|
||||
}
|
||||
#elif defined(__CLANG_ARM)
|
||||
__attribute__((always_inline)) static __inline rt_uint32_t __get_IPSR(void)
|
||||
{
|
||||
rt_uint32_t result;
|
||||
|
||||
__asm volatile ("MRS %0, ipsr" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
#elif defined(__IAR_SYSTEMS_ICC__)
|
||||
_Pragma("inline=forced") static inline int __get_IPSR(int value)
|
||||
{
|
||||
rt_uint32_t result;
|
||||
|
||||
asm("MRS %0, ipsr" : "=r"(result));
|
||||
return result;
|
||||
}
|
||||
#elif defined(__GNUC__)
|
||||
__attribute__((always_inline)) static inline rt_uint32_t __get_IPSR(void)
|
||||
{
|
||||
rt_uint32_t result;
|
||||
|
||||
__asm volatile ("MRS %0, ipsr" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
#endif
|
||||
|
||||
void rt_trustzone_init(void)
|
||||
{
|
||||
static rt_uint8_t _init;
|
||||
|
||||
if (_init)
|
||||
return;
|
||||
tzcall(TZ_INIT_CONTEXT_ID, 0, 0, 0);
|
||||
_init = 1;
|
||||
}
|
||||
|
||||
rt_err_t rt_trustzone_enter(rt_ubase_t module)
|
||||
{
|
||||
rt_trustzone_init();
|
||||
if (tzcall(TZ_ALLOC_CONTEXT_ID, module, 0, 0))
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t rt_trustzone_exit(void)
|
||||
{
|
||||
tzcall(TZ_FREE_CONTEXT_ID, 0, 0, 0);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
void rt_trustzone_context_store(rt_ubase_t context)
|
||||
{
|
||||
TZ_StoreContext_S(context);
|
||||
}
|
||||
|
||||
void rt_trustzone_context_load(rt_ubase_t context)
|
||||
{
|
||||
TZ_LoadContext_S(context);
|
||||
}
|
||||
|
||||
int rt_secure_svc_handle(int svc_id, rt_ubase_t arg0, rt_ubase_t arg1, rt_ubase_t arg2)
|
||||
{
|
||||
rt_ubase_t tmp;
|
||||
int res = 0;
|
||||
|
||||
switch (svc_id)
|
||||
{
|
||||
case TZ_INIT_CONTEXT_ID:
|
||||
TZ_InitContextSystem_S();
|
||||
break;
|
||||
case TZ_ALLOC_CONTEXT_ID:
|
||||
res = TZ_AllocModuleContext_S(arg0);
|
||||
if (res <= 0)
|
||||
{
|
||||
rt_kprintf("Alloc Context Failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_trustzone_current_context = res;
|
||||
TZ_LoadContext_S(res);
|
||||
}
|
||||
break;
|
||||
case TZ_FREE_CONTEXT_ID:
|
||||
TZ_FreeModuleContext_S(rt_trustzone_current_context);
|
||||
rt_trustzone_current_context = 0;
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user