xref: /optee_os/core/arch/arm/kernel/asm-defines.c (revision 59724f223500ec9bf077e8caaa5fc0d8fece39a9)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2016-2022, Linaro Limited
4  */
5 
6 #include <gen-asm-defines.h>
7 #include <kernel/boot.h>
8 #include <kernel/thread.h>
9 #include <kernel/thread_private.h>
10 #include <kernel/thread_private_arch.h>
11 #include <mm/core_mmu_arch.h>
12 #include <sm/pm.h>
13 #include <sm/sm.h>
14 #include <types_ext.h>
15 
16 DEFINES
17 {
18 #ifdef ARM32
19 	DEFINE(SM_NSEC_CTX_R0, offsetof(struct sm_nsec_ctx, r0));
20 	DEFINE(SM_NSEC_CTX_R8, offsetof(struct sm_nsec_ctx, r8));
21 	DEFINE(SM_SEC_CTX_R0, offsetof(struct sm_sec_ctx, r0));
22 	DEFINE(SM_SEC_CTX_MON_LR, offsetof(struct sm_sec_ctx, mon_lr));
23 	DEFINE(SM_CTX_SEC_SIZE, sizeof(struct sm_sec_ctx));
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_SCALL_REG_R0, offsetof(struct thread_scall_regs, r0));
29 	DEFINE(THREAD_SCALL_REG_R5, offsetof(struct thread_scall_regs, r5));
30 	DEFINE(THREAD_SCALL_REG_R6, offsetof(struct thread_scall_regs, r6));
31 
32 	/* struct thread_ctx */
33 	DEFINE(THREAD_CTX_STACK_VA_END, offsetof(struct thread_ctx,
34 						 stack_va_end));
35 
36 	/* struct thread_ctx_regs */
37 	DEFINE(THREAD_CTX_REGS_USR_SP,
38 	       offsetof(struct thread_ctx_regs, usr_sp));
39 	DEFINE(THREAD_CTX_REGS_PC, offsetof(struct thread_ctx_regs, pc));
40 	DEFINE(THREAD_CTX_REGS_CPSR, offsetof(struct thread_ctx_regs, cpsr));
41 
42 	/* struct thread_core_local */
43 	DEFINE(THREAD_CORE_LOCAL_R0, offsetof(struct thread_core_local, r[0]));
44 	DEFINE(THREAD_CORE_LOCAL_SM_PM_CTX_PHYS,
45 	       offsetof(struct thread_core_local, sm_pm_ctx_phys));
46 
47 	DEFINE(SM_PM_CTX_SIZE, sizeof(struct sm_pm_ctx));
48 	DEFINE(__STACK_TMP_OFFS, STACK_TMP_OFFS);
49 #endif /*ARM32*/
50 
51 #ifdef ARM64
52 	DEFINE(THREAD_SMC_ARGS_X0, offsetof(struct thread_smc_args, a0));
53 	DEFINE(THREAD_SMC_ARGS_SIZE, sizeof(struct thread_smc_args));
54 	DEFINE(THREAD_SMC_1_2_REGS_SIZE, sizeof(struct thread_smc_1_2_regs));
55 
56 	DEFINE(THREAD_SCALL_REG_X0, offsetof(struct thread_scall_regs, x0));
57 	DEFINE(THREAD_SCALL_REG_X2, offsetof(struct thread_scall_regs, x2));
58 	DEFINE(THREAD_SCALL_REG_X5, offsetof(struct thread_scall_regs, x5));
59 	DEFINE(THREAD_SCALL_REG_X6, offsetof(struct thread_scall_regs, x6));
60 	DEFINE(THREAD_SCALL_REG_X30, offsetof(struct thread_scall_regs, x30));
61 	DEFINE(THREAD_SCALL_REG_ELR, offsetof(struct thread_scall_regs, elr));
62 	DEFINE(THREAD_SCALL_REG_SPSR, offsetof(struct thread_scall_regs, spsr));
63 	DEFINE(THREAD_SCALL_REG_SP_EL0, offsetof(struct thread_scall_regs,
64 						 sp_el0));
65 #ifdef CFG_TA_PAUTH
66 	DEFINE(THREAD_SCALL_REG_APIAKEY_HI, offsetof(struct thread_scall_regs,
67 						     apiakey_hi));
68 #endif
69 	DEFINE(THREAD_SCALL_REG_SIZE, sizeof(struct thread_scall_regs));
70 
71 	/* struct thread_abort_regs */
72 	DEFINE(THREAD_ABT_REG_X0, offsetof(struct thread_abort_regs, x0));
73 	DEFINE(THREAD_ABT_REG_X2, offsetof(struct thread_abort_regs, x2));
74 	DEFINE(THREAD_ABT_REG_X30, offsetof(struct thread_abort_regs, x30));
75 	DEFINE(THREAD_ABT_REG_SPSR, offsetof(struct thread_abort_regs, spsr));
76 	DEFINE(THREAD_ABT_REGS_SIZE, sizeof(struct thread_abort_regs));
77 #if defined(CFG_TA_PAUTH) || defined(CFG_CORE_PAUTH)
78 	DEFINE(THREAD_ABT_REGS_APIAKEY_HI, offsetof(struct thread_abort_regs,
79 						    apiakey_hi));
80 #endif
81 
82 	/* struct thread_ctx */
83 	DEFINE(THREAD_CTX_KERN_SP, offsetof(struct thread_ctx, kern_sp));
84 	DEFINE(THREAD_CTX_STACK_VA_END, offsetof(struct thread_ctx,
85 						 stack_va_end));
86 #if defined(CFG_CORE_PAUTH)
87 	DEFINE(THREAD_CTX_KEYS, offsetof(struct thread_ctx, keys));
88 #endif
89 
90 	/* struct thread_ctx_regs */
91 	DEFINE(THREAD_CTX_REGS_SP, offsetof(struct thread_ctx_regs, sp));
92 	DEFINE(THREAD_CTX_REGS_X0, offsetof(struct thread_ctx_regs, x[0]));
93 	DEFINE(THREAD_CTX_REGS_X1, offsetof(struct thread_ctx_regs, x[1]));
94 	DEFINE(THREAD_CTX_REGS_X2, offsetof(struct thread_ctx_regs, x[2]));
95 	DEFINE(THREAD_CTX_REGS_X4, offsetof(struct thread_ctx_regs, x[4]));
96 	DEFINE(THREAD_CTX_REGS_X19, offsetof(struct thread_ctx_regs, x[19]));
97 	DEFINE(THREAD_CTX_REGS_TPIDR_EL0, offsetof(struct thread_ctx_regs,
98 						   tpidr_el0));
99 #if defined(CFG_TA_PAUTH) || defined(CFG_CORE_PAUTH)
100 	DEFINE(THREAD_CTX_REGS_APIAKEY_HI, offsetof(struct thread_ctx_regs,
101 						    apiakey_hi));
102 #endif
103 
104 	/* struct thread_user_mode_rec */
105 	DEFINE(THREAD_USER_MODE_REC_CTX_REGS_PTR,
106 	       offsetof(struct thread_user_mode_rec, ctx_regs_ptr));
107 	DEFINE(THREAD_USER_MODE_REC_EXIT_STATUS0_PTR,
108 	       offsetof(struct thread_user_mode_rec, exit_status0_ptr));
109 	DEFINE(THREAD_USER_MODE_REC_X19,
110 	       offsetof(struct thread_user_mode_rec, x[0]));
111 	DEFINE(THREAD_USER_MODE_REC_SIZE, sizeof(struct thread_user_mode_rec));
112 
113 	/* struct thread_core_local */
114 	DEFINE(THREAD_CORE_LOCAL_X0, offsetof(struct thread_core_local, x[0]));
115 	DEFINE(THREAD_CORE_LOCAL_X2, offsetof(struct thread_core_local, x[2]));
116 	DEFINE(THREAD_CORE_LOCAL_KCODE_OFFSET,
117 	       offsetof(struct thread_core_local, kcode_offset));
118 #ifdef CFG_CORE_WORKAROUND_SPECTRE_BP_SEC
119 	DEFINE(THREAD_CORE_LOCAL_BHB_LOOP_COUNT,
120 	       offsetof(struct thread_core_local, bhb_loop_count));
121 #endif
122 #if defined(CFG_CORE_PAUTH)
123 	DEFINE(THREAD_CORE_LOCAL_KEYS,
124 	       offsetof(struct thread_core_local, keys));
125 #endif
126 #endif /*ARM64*/
127 
128 	/* struct thread_ctx */
129 	DEFINE(THREAD_CTX_SIZE, sizeof(struct thread_ctx));
130 #ifdef CFG_CORE_FFA
131 	DEFINE(THREAD_CTX_TSD_RPC_TARGET_INFO,
132 	       offsetof(struct thread_ctx, tsd.rpc_target_info))
133 	DEFINE(THREAD_CTX_FLAGS,
134 	       offsetof(struct thread_ctx, flags))
135 #endif
136 
137 	/* struct thread_core_local */
138 	DEFINE(THREAD_CORE_LOCAL_TMP_STACK_VA_END,
139 	       offsetof(struct thread_core_local, tmp_stack_va_end));
140 #ifdef ARM32
141 	DEFINE(THREAD_CORE_LOCAL_TMP_STACK_PA_END,
142 	       offsetof(struct thread_core_local, tmp_stack_pa_end));
143 #endif
144 	DEFINE(THREAD_CORE_LOCAL_CURR_THREAD,
145 	       offsetof(struct thread_core_local, curr_thread));
146 	DEFINE(THREAD_CORE_LOCAL_FLAGS,
147 	       offsetof(struct thread_core_local, flags));
148 	DEFINE(THREAD_CORE_LOCAL_ABT_STACK_VA_END,
149 	       offsetof(struct thread_core_local, abt_stack_va_end));
150 	DEFINE(THREAD_CORE_LOCAL_SIZE, sizeof(struct thread_core_local));
151 #if defined(ARM64) && defined(CFG_CORE_FFA)
152 	DEFINE(THREAD_CORE_LOCAL_DIRECT_RESP_FID,
153 	       offsetof(struct thread_core_local, direct_resp_fid));
154 #endif
155 
156 	DEFINE(STACK_TMP_GUARD, STACK_CANARY_SIZE / 2 + STACK_TMP_OFFS);
157 
158 	/* struct core_mmu_config */
159 	DEFINE(CORE_MMU_CONFIG_SIZE, sizeof(struct core_mmu_config));
160 	DEFINE(CORE_MMU_CONFIG_MAP_OFFSET,
161 	       offsetof(struct core_mmu_config, map_offset));
162 
163 	/* struct boot_embdata */
164 	DEFINE(BOOT_EMBDATA_HASHES_OFFSET,
165 	       offsetof(struct boot_embdata, hashes_offset));
166 	DEFINE(BOOT_EMBDATA_HASHES_LEN,
167 	       offsetof(struct boot_embdata, hashes_len));
168 	DEFINE(BOOT_EMBDATA_RELOC_OFFSET,
169 	       offsetof(struct boot_embdata, reloc_offset));
170 	DEFINE(BOOT_EMBDATA_RELOC_LEN,
171 	       offsetof(struct boot_embdata, reloc_len));
172 
173 #ifdef CORE_MMU_BASE_TABLE_OFFSET
174 	/*
175 	 * This define is too complex to be used as an argument for the
176 	 * macros add_imm and sub_imm so evaluate it here.
177 	 */
178 	DEFINE(__CORE_MMU_BASE_TABLE_OFFSET, CORE_MMU_BASE_TABLE_OFFSET);
179 #endif
180 	DEFINE(__STACK_CANARY_SIZE, STACK_CANARY_SIZE);
181 
182 }
183