xref: /optee_os/core/arch/arm/kernel/asm-defines.c (revision 1bb929836182ecb96d2d9d268daa807c67596396)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2016, Linaro Limited
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <kernel/thread.h>
30 #include <sm/pm.h>
31 #include <sm/sm.h>
32 #include <types_ext.h>
33 #include "thread_private.h"
34 
35 #define DEFINES void __defines(void); void __defines(void)
36 
37 #define DEFINE(def, val) \
38 	asm volatile("\n==>" #def " %0 " #val : : "i" (val))
39 
40 DEFINES
41 {
42 #ifdef ARM32
43 	DEFINE(SM_NSEC_CTX_R0, offsetof(struct sm_nsec_ctx, r0));
44 	DEFINE(SM_NSEC_CTX_R8, offsetof(struct sm_nsec_ctx, r8));
45 	DEFINE(SM_SEC_CTX_R0, offsetof(struct sm_sec_ctx, r0));
46 	DEFINE(SM_SEC_CTX_MON_LR, offsetof(struct sm_sec_ctx, mon_lr));
47 	DEFINE(SM_CTX_SIZE, sizeof(struct sm_ctx));
48 	DEFINE(SM_CTX_NSEC, offsetof(struct sm_ctx, nsec));
49 	DEFINE(SM_CTX_SEC, offsetof(struct sm_ctx, sec));
50 
51 	DEFINE(THREAD_VECTOR_TABLE_FIQ_ENTRY,
52 	       offsetof(struct thread_vector_table, fiq_entry));
53 
54 	DEFINE(THREAD_SVC_REG_R0, offsetof(struct thread_svc_regs, r0));
55 	DEFINE(THREAD_SVC_REG_R5, offsetof(struct thread_svc_regs, r5));
56 	DEFINE(THREAD_SVC_REG_R6, offsetof(struct thread_svc_regs, r6));
57 
58 	/* struct thread_core_local */
59 	DEFINE(THREAD_CORE_LOCAL_R0, offsetof(struct thread_core_local, r[0]));
60 	DEFINE(THREAD_CORE_LOCAL_SM_PM_CTX_PHYS,
61 	       offsetof(struct thread_core_local, sm_pm_ctx_phys));
62 	DEFINE(THREAD_CORE_LOCAL_SIZE, sizeof(struct thread_core_local));
63 
64 	DEFINE(SM_PM_CTX_SIZE, sizeof(struct sm_pm_ctx));
65 #endif /*ARM32*/
66 
67 #ifdef ARM64
68 	DEFINE(THREAD_SMC_ARGS_X0, offsetof(struct thread_smc_args, a0));
69 	DEFINE(THREAD_SMC_ARGS_SIZE, sizeof(struct thread_smc_args));
70 
71 	DEFINE(THREAD_SVC_REG_X0, offsetof(struct thread_svc_regs, x0));
72 	DEFINE(THREAD_SVC_REG_X2, offsetof(struct thread_svc_regs, x2));
73 	DEFINE(THREAD_SVC_REG_X5, offsetof(struct thread_svc_regs, x5));
74 	DEFINE(THREAD_SVC_REG_X6, offsetof(struct thread_svc_regs, x6));
75 	DEFINE(THREAD_SVC_REG_X30, offsetof(struct thread_svc_regs, x30));
76 	DEFINE(THREAD_SVC_REG_ELR, offsetof(struct thread_svc_regs, elr));
77 	DEFINE(THREAD_SVC_REG_SPSR, offsetof(struct thread_svc_regs, spsr));
78 	DEFINE(THREAD_SVC_REG_SP_EL0, offsetof(struct thread_svc_regs, sp_el0));
79 	DEFINE(THREAD_SVC_REG_SIZE, sizeof(struct thread_svc_regs));
80 
81 	/* struct thread_abort_regs */
82 	DEFINE(THREAD_ABT_REG_X0, offsetof(struct thread_abort_regs, x0));
83 	DEFINE(THREAD_ABT_REG_X2, offsetof(struct thread_abort_regs, x2));
84 	DEFINE(THREAD_ABT_REG_X30, offsetof(struct thread_abort_regs, x30));
85 	DEFINE(THREAD_ABT_REG_SPSR, offsetof(struct thread_abort_regs, spsr));
86 	DEFINE(THREAD_ABT_REGS_SIZE, sizeof(struct thread_abort_regs));
87 
88 	/* struct thread_ctx */
89 	DEFINE(THREAD_CTX_KERN_SP, offsetof(struct thread_ctx, kern_sp));
90 	DEFINE(THREAD_CTX_SIZE, sizeof(struct thread_ctx));
91 
92 	/* struct thread_ctx_regs */
93 	DEFINE(THREAD_CTX_REGS_SP, offsetof(struct thread_ctx_regs, sp));
94 	DEFINE(THREAD_CTX_REGS_X0, offsetof(struct thread_ctx_regs, x[0]));
95 	DEFINE(THREAD_CTX_REGS_X1, offsetof(struct thread_ctx_regs, x[1]));
96 	DEFINE(THREAD_CTX_REGS_X4, offsetof(struct thread_ctx_regs, x[4]));
97 	DEFINE(THREAD_CTX_REGS_X19, offsetof(struct thread_ctx_regs, x[19]));
98 
99 	/* struct thread_user_mode_rec */
100 	DEFINE(THREAD_USER_MODE_REC_EXIT_STATUS0_PTR,
101 		offsetof(struct thread_user_mode_rec, exit_status0_ptr));
102 	DEFINE(THREAD_USER_MODE_REC_X19,
103 		offsetof(struct thread_user_mode_rec, x[0]));
104 	DEFINE(THREAD_USER_MODE_REC_SIZE, sizeof(struct thread_user_mode_rec));
105 
106 	/* struct thread_core_local */
107 	DEFINE(THREAD_CORE_LOCAL_X0, offsetof(struct thread_core_local, x[0]));
108 	DEFINE(THREAD_CORE_LOCAL_X2, offsetof(struct thread_core_local, x[2]));
109 #endif /*ARM64*/
110 
111 	/* struct thread_core_local */
112 	DEFINE(THREAD_CORE_LOCAL_TMP_STACK_VA_END,
113 		offsetof(struct thread_core_local, tmp_stack_va_end));
114 	DEFINE(THREAD_CORE_LOCAL_CURR_THREAD,
115 		offsetof(struct thread_core_local, curr_thread));
116 	DEFINE(THREAD_CORE_LOCAL_FLAGS,
117 		offsetof(struct thread_core_local, flags));
118 	DEFINE(THREAD_CORE_LOCAL_ABT_STACK_VA_END,
119 		offsetof(struct thread_core_local, abt_stack_va_end));
120 
121 }
122