xref: /optee_os/core/arch/arm/kernel/asm-defines.c (revision 651d75378f517f798eba7a508e8b457504c0a05c)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2016, Linaro Limited
4  */
5 
6 #include <gen-asm-defines.h>
7 #include <kernel/boot.h>
8 #include <kernel/thread.h>
9 #include <sm/pm.h>
10 #include <sm/sm.h>
11 #include <types_ext.h>
12 #include "thread_private.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_SVC_REG_R0, offsetof(struct thread_svc_regs, r0));
27 	DEFINE(THREAD_SVC_REG_R5, offsetof(struct thread_svc_regs, r5));
28 	DEFINE(THREAD_SVC_REG_R6, offsetof(struct thread_svc_regs, r6));
29 
30 	/* struct thread_ctx_regs */
31 	DEFINE(THREAD_CTX_REGS_USR_SP,
32 	       offsetof(struct thread_ctx_regs, usr_sp));
33 	DEFINE(THREAD_CTX_REGS_PC, offsetof(struct thread_ctx_regs, pc));
34 	DEFINE(THREAD_CTX_REGS_CPSR, offsetof(struct thread_ctx_regs, cpsr));
35 
36 	/* struct thread_core_local */
37 	DEFINE(THREAD_CORE_LOCAL_R0, offsetof(struct thread_core_local, r[0]));
38 	DEFINE(THREAD_CORE_LOCAL_SM_PM_CTX_PHYS,
39 	       offsetof(struct thread_core_local, sm_pm_ctx_phys));
40 	DEFINE(THREAD_CORE_LOCAL_SIZE, sizeof(struct thread_core_local));
41 
42 	DEFINE(SM_PM_CTX_SIZE, sizeof(struct sm_pm_ctx));
43 #endif /*ARM32*/
44 
45 #ifdef ARM64
46 	DEFINE(THREAD_SMC_ARGS_X0, offsetof(struct thread_smc_args, a0));
47 	DEFINE(THREAD_SMC_ARGS_SIZE, sizeof(struct thread_smc_args));
48 
49 	DEFINE(THREAD_SVC_REG_X0, offsetof(struct thread_svc_regs, x0));
50 	DEFINE(THREAD_SVC_REG_X2, offsetof(struct thread_svc_regs, x2));
51 	DEFINE(THREAD_SVC_REG_X5, offsetof(struct thread_svc_regs, x5));
52 	DEFINE(THREAD_SVC_REG_X6, offsetof(struct thread_svc_regs, x6));
53 	DEFINE(THREAD_SVC_REG_X30, offsetof(struct thread_svc_regs, x30));
54 	DEFINE(THREAD_SVC_REG_ELR, offsetof(struct thread_svc_regs, elr));
55 	DEFINE(THREAD_SVC_REG_SPSR, offsetof(struct thread_svc_regs, spsr));
56 	DEFINE(THREAD_SVC_REG_SP_EL0, offsetof(struct thread_svc_regs, sp_el0));
57 	DEFINE(THREAD_SVC_REG_SIZE, sizeof(struct thread_svc_regs));
58 
59 	/* struct thread_abort_regs */
60 	DEFINE(THREAD_ABT_REG_X0, offsetof(struct thread_abort_regs, x0));
61 	DEFINE(THREAD_ABT_REG_X2, offsetof(struct thread_abort_regs, x2));
62 	DEFINE(THREAD_ABT_REG_X30, offsetof(struct thread_abort_regs, x30));
63 	DEFINE(THREAD_ABT_REG_SPSR, offsetof(struct thread_abort_regs, spsr));
64 	DEFINE(THREAD_ABT_REGS_SIZE, sizeof(struct thread_abort_regs));
65 
66 	/* struct thread_ctx */
67 	DEFINE(THREAD_CTX_KERN_SP, offsetof(struct thread_ctx, kern_sp));
68 	DEFINE(THREAD_CTX_SIZE, sizeof(struct thread_ctx));
69 
70 	/* struct thread_ctx_regs */
71 	DEFINE(THREAD_CTX_REGS_SP, offsetof(struct thread_ctx_regs, sp));
72 	DEFINE(THREAD_CTX_REGS_X0, offsetof(struct thread_ctx_regs, x[0]));
73 	DEFINE(THREAD_CTX_REGS_X1, offsetof(struct thread_ctx_regs, x[1]));
74 	DEFINE(THREAD_CTX_REGS_X2, offsetof(struct thread_ctx_regs, x[2]));
75 	DEFINE(THREAD_CTX_REGS_X4, offsetof(struct thread_ctx_regs, x[4]));
76 	DEFINE(THREAD_CTX_REGS_X19, offsetof(struct thread_ctx_regs, x[19]));
77 
78 	/* struct thread_user_mode_rec */
79 	DEFINE(THREAD_USER_MODE_REC_CTX_REGS_PTR,
80 	       offsetof(struct thread_user_mode_rec, ctx_regs_ptr));
81 	DEFINE(THREAD_USER_MODE_REC_EXIT_STATUS0_PTR,
82 	       offsetof(struct thread_user_mode_rec, exit_status0_ptr));
83 	DEFINE(THREAD_USER_MODE_REC_X19,
84 	       offsetof(struct thread_user_mode_rec, x[0]));
85 	DEFINE(THREAD_USER_MODE_REC_SIZE, sizeof(struct thread_user_mode_rec));
86 
87 	/* struct thread_core_local */
88 	DEFINE(THREAD_CORE_LOCAL_X0, offsetof(struct thread_core_local, x[0]));
89 	DEFINE(THREAD_CORE_LOCAL_X2, offsetof(struct thread_core_local, x[2]));
90 #endif /*ARM64*/
91 
92 	/* struct thread_ctx */
93 	DEFINE(THREAD_CTX_SIZE, sizeof(struct thread_ctx));
94 #ifdef CFG_CORE_FFA
95 	DEFINE(THREAD_CTX_TSD_RPC_TARGET_INFO,
96 	       offsetof(struct thread_ctx, tsd.rpc_target_info))
97 #endif
98 
99 	/* struct thread_core_local */
100 	DEFINE(THREAD_CORE_LOCAL_TMP_STACK_VA_END,
101 		offsetof(struct thread_core_local, tmp_stack_va_end));
102 	DEFINE(THREAD_CORE_LOCAL_CURR_THREAD,
103 		offsetof(struct thread_core_local, curr_thread));
104 	DEFINE(THREAD_CORE_LOCAL_FLAGS,
105 		offsetof(struct thread_core_local, flags));
106 	DEFINE(THREAD_CORE_LOCAL_ABT_STACK_VA_END,
107 		offsetof(struct thread_core_local, abt_stack_va_end));
108 
109 	/* struct core_mmu_config */
110 	DEFINE(CORE_MMU_CONFIG_SIZE, sizeof(struct core_mmu_config));
111 	DEFINE(CORE_MMU_CONFIG_LOAD_OFFSET,
112 	       offsetof(struct core_mmu_config, load_offset));
113 
114 	/* struct boot_embdata */
115 	DEFINE(BOOT_EMBDATA_HASHES_OFFSET,
116 	       offsetof(struct boot_embdata, hashes_offset));
117 	DEFINE(BOOT_EMBDATA_HASHES_LEN,
118 	       offsetof(struct boot_embdata, hashes_len));
119 	DEFINE(BOOT_EMBDATA_RELOC_OFFSET,
120 	       offsetof(struct boot_embdata, reloc_offset));
121 	DEFINE(BOOT_EMBDATA_RELOC_LEN,
122 	       offsetof(struct boot_embdata, reloc_len));
123 }
124