xref: /optee_os/core/arch/arm/kernel/asm-defines.c (revision b1d7375c01ec8bcbf3561d27425d320afed23bce)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2016, Linaro Limited
4  */
5 
6 #include <kernel/thread.h>
7 #include <sm/pm.h>
8 #include <sm/sm.h>
9 #include <types_ext.h>
10 #include "thread_private.h"
11 
12 #define DEFINES void __defines(void); void __defines(void)
13 
14 #define DEFINE(def, val) \
15 	asm volatile("\n==>" #def " %0 " #val : : "i" (val))
16 
17 DEFINES
18 {
19 #ifdef ARM32
20 	DEFINE(SM_NSEC_CTX_R0, offsetof(struct sm_nsec_ctx, r0));
21 	DEFINE(SM_NSEC_CTX_R8, offsetof(struct sm_nsec_ctx, r8));
22 	DEFINE(SM_SEC_CTX_R0, offsetof(struct sm_sec_ctx, r0));
23 	DEFINE(SM_SEC_CTX_MON_LR, offsetof(struct sm_sec_ctx, mon_lr));
24 	DEFINE(SM_CTX_SIZE, sizeof(struct sm_ctx));
25 	DEFINE(SM_CTX_NSEC, offsetof(struct sm_ctx, nsec));
26 	DEFINE(SM_CTX_SEC, offsetof(struct sm_ctx, sec));
27 
28 	DEFINE(THREAD_VECTOR_TABLE_FIQ_ENTRY,
29 	       offsetof(struct thread_vector_table, fiq_entry));
30 
31 	DEFINE(THREAD_SVC_REG_R0, offsetof(struct thread_svc_regs, r0));
32 	DEFINE(THREAD_SVC_REG_R5, offsetof(struct thread_svc_regs, r5));
33 	DEFINE(THREAD_SVC_REG_R6, offsetof(struct thread_svc_regs, r6));
34 
35 	/* struct thread_core_local */
36 	DEFINE(THREAD_CORE_LOCAL_R0, offsetof(struct thread_core_local, r[0]));
37 	DEFINE(THREAD_CORE_LOCAL_SM_PM_CTX_PHYS,
38 	       offsetof(struct thread_core_local, sm_pm_ctx_phys));
39 	DEFINE(THREAD_CORE_LOCAL_SIZE, sizeof(struct thread_core_local));
40 
41 	DEFINE(SM_PM_CTX_SIZE, sizeof(struct sm_pm_ctx));
42 #endif /*ARM32*/
43 
44 #ifdef ARM64
45 	DEFINE(THREAD_SMC_ARGS_X0, offsetof(struct thread_smc_args, a0));
46 	DEFINE(THREAD_SMC_ARGS_SIZE, sizeof(struct thread_smc_args));
47 
48 	DEFINE(THREAD_SVC_REG_X0, offsetof(struct thread_svc_regs, x0));
49 	DEFINE(THREAD_SVC_REG_X2, offsetof(struct thread_svc_regs, x2));
50 	DEFINE(THREAD_SVC_REG_X5, offsetof(struct thread_svc_regs, x5));
51 	DEFINE(THREAD_SVC_REG_X6, offsetof(struct thread_svc_regs, x6));
52 	DEFINE(THREAD_SVC_REG_X30, offsetof(struct thread_svc_regs, x30));
53 	DEFINE(THREAD_SVC_REG_ELR, offsetof(struct thread_svc_regs, elr));
54 	DEFINE(THREAD_SVC_REG_SPSR, offsetof(struct thread_svc_regs, spsr));
55 	DEFINE(THREAD_SVC_REG_SP_EL0, offsetof(struct thread_svc_regs, sp_el0));
56 	DEFINE(THREAD_SVC_REG_SIZE, sizeof(struct thread_svc_regs));
57 
58 	/* struct thread_abort_regs */
59 	DEFINE(THREAD_ABT_REG_X0, offsetof(struct thread_abort_regs, x0));
60 	DEFINE(THREAD_ABT_REG_X2, offsetof(struct thread_abort_regs, x2));
61 	DEFINE(THREAD_ABT_REG_X30, offsetof(struct thread_abort_regs, x30));
62 	DEFINE(THREAD_ABT_REG_SPSR, offsetof(struct thread_abort_regs, spsr));
63 	DEFINE(THREAD_ABT_REGS_SIZE, sizeof(struct thread_abort_regs));
64 
65 	/* struct thread_ctx */
66 	DEFINE(THREAD_CTX_KERN_SP, offsetof(struct thread_ctx, kern_sp));
67 	DEFINE(THREAD_CTX_SIZE, sizeof(struct thread_ctx));
68 
69 	/* struct thread_ctx_regs */
70 	DEFINE(THREAD_CTX_REGS_SP, offsetof(struct thread_ctx_regs, sp));
71 	DEFINE(THREAD_CTX_REGS_X0, offsetof(struct thread_ctx_regs, x[0]));
72 	DEFINE(THREAD_CTX_REGS_X1, offsetof(struct thread_ctx_regs, x[1]));
73 	DEFINE(THREAD_CTX_REGS_X4, offsetof(struct thread_ctx_regs, x[4]));
74 	DEFINE(THREAD_CTX_REGS_X19, offsetof(struct thread_ctx_regs, x[19]));
75 
76 	/* struct thread_user_mode_rec */
77 	DEFINE(THREAD_USER_MODE_REC_EXIT_STATUS0_PTR,
78 		offsetof(struct thread_user_mode_rec, exit_status0_ptr));
79 	DEFINE(THREAD_USER_MODE_REC_X19,
80 		offsetof(struct thread_user_mode_rec, x[0]));
81 	DEFINE(THREAD_USER_MODE_REC_SIZE, sizeof(struct thread_user_mode_rec));
82 
83 	/* struct thread_core_local */
84 	DEFINE(THREAD_CORE_LOCAL_X0, offsetof(struct thread_core_local, x[0]));
85 	DEFINE(THREAD_CORE_LOCAL_X2, offsetof(struct thread_core_local, x[2]));
86 #endif /*ARM64*/
87 
88 	/* struct thread_core_local */
89 	DEFINE(THREAD_CORE_LOCAL_TMP_STACK_VA_END,
90 		offsetof(struct thread_core_local, tmp_stack_va_end));
91 	DEFINE(THREAD_CORE_LOCAL_CURR_THREAD,
92 		offsetof(struct thread_core_local, curr_thread));
93 	DEFINE(THREAD_CORE_LOCAL_FLAGS,
94 		offsetof(struct thread_core_local, flags));
95 	DEFINE(THREAD_CORE_LOCAL_ABT_STACK_VA_END,
96 		offsetof(struct thread_core_local, abt_stack_va_end));
97 
98 }
99