xref: /optee_os/core/arch/arm/kernel/asm-defines.c (revision cb5f271c1eaed4c18fd26873f152afc0590b0413)
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 <sm/pm.h>
11 #include <sm/sm.h>
12 #include <types_ext.h>
13 
14 DEFINES
15 {
16 #ifdef ARM32
17 	DEFINE(SM_NSEC_CTX_R0, offsetof(struct sm_nsec_ctx, r0));
18 	DEFINE(SM_NSEC_CTX_R8, offsetof(struct sm_nsec_ctx, r8));
19 	DEFINE(SM_SEC_CTX_R0, offsetof(struct sm_sec_ctx, r0));
20 	DEFINE(SM_SEC_CTX_MON_LR, offsetof(struct sm_sec_ctx, mon_lr));
21 	DEFINE(SM_CTX_SEC_SIZE, sizeof(struct sm_sec_ctx));
22 	DEFINE(SM_CTX_SIZE, sizeof(struct sm_ctx));
23 	DEFINE(SM_CTX_NSEC, offsetof(struct sm_ctx, nsec));
24 	DEFINE(SM_CTX_SEC, offsetof(struct sm_ctx, sec));
25 
26 	DEFINE(THREAD_SCALL_REG_R0, offsetof(struct thread_scall_regs, r0));
27 	DEFINE(THREAD_SCALL_REG_R5, offsetof(struct thread_scall_regs, r5));
28 	DEFINE(THREAD_SCALL_REG_R6, offsetof(struct thread_scall_regs, r6));
29 
30 	/* struct thread_ctx */
31 	DEFINE(THREAD_CTX_STACK_VA_END, offsetof(struct thread_ctx,
32 						 stack_va_end));
33 
34 	/* struct thread_ctx_regs */
35 	DEFINE(THREAD_CTX_REGS_USR_SP,
36 	       offsetof(struct thread_ctx_regs, usr_sp));
37 	DEFINE(THREAD_CTX_REGS_PC, offsetof(struct thread_ctx_regs, pc));
38 	DEFINE(THREAD_CTX_REGS_CPSR, offsetof(struct thread_ctx_regs, cpsr));
39 
40 	/* struct thread_core_local */
41 	DEFINE(THREAD_CORE_LOCAL_R0, offsetof(struct thread_core_local, r[0]));
42 	DEFINE(THREAD_CORE_LOCAL_SM_PM_CTX_PHYS,
43 	       offsetof(struct thread_core_local, sm_pm_ctx_phys));
44 	DEFINE(THREAD_CORE_LOCAL_SIZE, sizeof(struct thread_core_local));
45 
46 	DEFINE(SM_PM_CTX_SIZE, sizeof(struct sm_pm_ctx));
47 #endif /*ARM32*/
48 
49 #ifdef ARM64
50 	DEFINE(THREAD_SMC_ARGS_X0, offsetof(struct thread_smc_args, a0));
51 	DEFINE(THREAD_SMC_ARGS_SIZE, sizeof(struct thread_smc_args));
52 
53 	DEFINE(THREAD_SCALL_REG_X0, offsetof(struct thread_scall_regs, x0));
54 	DEFINE(THREAD_SCALL_REG_X2, offsetof(struct thread_scall_regs, x2));
55 	DEFINE(THREAD_SCALL_REG_X5, offsetof(struct thread_scall_regs, x5));
56 	DEFINE(THREAD_SCALL_REG_X6, offsetof(struct thread_scall_regs, x6));
57 	DEFINE(THREAD_SCALL_REG_X30, offsetof(struct thread_scall_regs, x30));
58 	DEFINE(THREAD_SCALL_REG_ELR, offsetof(struct thread_scall_regs, elr));
59 	DEFINE(THREAD_SCALL_REG_SPSR, offsetof(struct thread_scall_regs, spsr));
60 	DEFINE(THREAD_SCALL_REG_SP_EL0, offsetof(struct thread_scall_regs,
61 						 sp_el0));
62 #ifdef CFG_TA_PAUTH
63 	DEFINE(THREAD_SCALL_REG_APIAKEY_HI, offsetof(struct thread_scall_regs,
64 						     apiakey_hi));
65 #endif
66 	DEFINE(THREAD_SCALL_REG_SIZE, sizeof(struct thread_scall_regs));
67 
68 	/* struct thread_abort_regs */
69 	DEFINE(THREAD_ABT_REG_X0, offsetof(struct thread_abort_regs, x0));
70 	DEFINE(THREAD_ABT_REG_X2, offsetof(struct thread_abort_regs, x2));
71 	DEFINE(THREAD_ABT_REG_X30, offsetof(struct thread_abort_regs, x30));
72 	DEFINE(THREAD_ABT_REG_SPSR, offsetof(struct thread_abort_regs, spsr));
73 	DEFINE(THREAD_ABT_REGS_SIZE, sizeof(struct thread_abort_regs));
74 #if defined(CFG_TA_PAUTH) || defined(CFG_CORE_PAUTH)
75 	DEFINE(THREAD_ABT_REGS_APIAKEY_HI, offsetof(struct thread_abort_regs,
76 						    apiakey_hi));
77 #endif
78 
79 	/* struct thread_ctx */
80 	DEFINE(THREAD_CTX_KERN_SP, offsetof(struct thread_ctx, kern_sp));
81 	DEFINE(THREAD_CTX_STACK_VA_END, offsetof(struct thread_ctx,
82 						 stack_va_end));
83 #if defined(CFG_CORE_PAUTH)
84 	DEFINE(THREAD_CTX_KEYS, offsetof(struct thread_ctx, keys));
85 #endif
86 
87 	/* struct thread_ctx_regs */
88 	DEFINE(THREAD_CTX_REGS_SP, offsetof(struct thread_ctx_regs, sp));
89 	DEFINE(THREAD_CTX_REGS_X0, offsetof(struct thread_ctx_regs, x[0]));
90 	DEFINE(THREAD_CTX_REGS_X1, offsetof(struct thread_ctx_regs, x[1]));
91 	DEFINE(THREAD_CTX_REGS_X2, offsetof(struct thread_ctx_regs, x[2]));
92 	DEFINE(THREAD_CTX_REGS_X4, offsetof(struct thread_ctx_regs, x[4]));
93 	DEFINE(THREAD_CTX_REGS_X19, offsetof(struct thread_ctx_regs, x[19]));
94 	DEFINE(THREAD_CTX_REGS_TPIDR_EL0, offsetof(struct thread_ctx_regs,
95 						   tpidr_el0));
96 #if defined(CFG_TA_PAUTH) || defined(CFG_CORE_PAUTH)
97 	DEFINE(THREAD_CTX_REGS_APIAKEY_HI, offsetof(struct thread_ctx_regs,
98 						    apiakey_hi));
99 #endif
100 
101 	/* struct thread_user_mode_rec */
102 	DEFINE(THREAD_USER_MODE_REC_CTX_REGS_PTR,
103 	       offsetof(struct thread_user_mode_rec, ctx_regs_ptr));
104 	DEFINE(THREAD_USER_MODE_REC_EXIT_STATUS0_PTR,
105 	       offsetof(struct thread_user_mode_rec, exit_status0_ptr));
106 	DEFINE(THREAD_USER_MODE_REC_X19,
107 	       offsetof(struct thread_user_mode_rec, x[0]));
108 	DEFINE(THREAD_USER_MODE_REC_SIZE, sizeof(struct thread_user_mode_rec));
109 
110 	/* struct thread_core_local */
111 	DEFINE(THREAD_CORE_LOCAL_X0, offsetof(struct thread_core_local, x[0]));
112 	DEFINE(THREAD_CORE_LOCAL_X2, offsetof(struct thread_core_local, x[2]));
113 	DEFINE(THREAD_CORE_LOCAL_KCODE_OFFSET,
114 	       offsetof(struct thread_core_local, kcode_offset));
115 #ifdef CFG_CORE_WORKAROUND_SPECTRE_BP_SEC
116 	DEFINE(THREAD_CORE_LOCAL_BHB_LOOP_COUNT,
117 	       offsetof(struct thread_core_local, bhb_loop_count));
118 #endif
119 #if defined(CFG_CORE_PAUTH)
120 	DEFINE(THREAD_CORE_LOCAL_KEYS,
121 	       offsetof(struct thread_core_local, keys));
122 #endif
123 #endif /*ARM64*/
124 
125 	/* struct thread_ctx */
126 	DEFINE(THREAD_CTX_SIZE, sizeof(struct thread_ctx));
127 #ifdef CFG_CORE_FFA
128 	DEFINE(THREAD_CTX_TSD_RPC_TARGET_INFO,
129 	       offsetof(struct thread_ctx, tsd.rpc_target_info))
130 #endif
131 
132 	/* struct thread_core_local */
133 	DEFINE(THREAD_CORE_LOCAL_TMP_STACK_VA_END,
134 		offsetof(struct thread_core_local, tmp_stack_va_end));
135 	DEFINE(THREAD_CORE_LOCAL_CURR_THREAD,
136 		offsetof(struct thread_core_local, curr_thread));
137 	DEFINE(THREAD_CORE_LOCAL_FLAGS,
138 		offsetof(struct thread_core_local, flags));
139 	DEFINE(THREAD_CORE_LOCAL_ABT_STACK_VA_END,
140 		offsetof(struct thread_core_local, abt_stack_va_end));
141 
142 	DEFINE(STACK_TMP_GUARD, STACK_CANARY_SIZE / 2 + STACK_TMP_OFFS);
143 
144 	/* struct core_mmu_config */
145 	DEFINE(CORE_MMU_CONFIG_SIZE, sizeof(struct core_mmu_config));
146 	DEFINE(CORE_MMU_CONFIG_LOAD_OFFSET,
147 	       offsetof(struct core_mmu_config, load_offset));
148 
149 	/* struct boot_embdata */
150 	DEFINE(BOOT_EMBDATA_HASHES_OFFSET,
151 	       offsetof(struct boot_embdata, hashes_offset));
152 	DEFINE(BOOT_EMBDATA_HASHES_LEN,
153 	       offsetof(struct boot_embdata, hashes_len));
154 	DEFINE(BOOT_EMBDATA_RELOC_OFFSET,
155 	       offsetof(struct boot_embdata, reloc_offset));
156 	DEFINE(BOOT_EMBDATA_RELOC_LEN,
157 	       offsetof(struct boot_embdata, reloc_len));
158 }
159