xref: /optee_os/core/arch/riscv/kernel/asm-defines.c (revision cb03400251f98aed22a2664509e3ed9e183800b0)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright 2022-2023 NXP
4  */
5 
6 #include <kernel/thread.h>
7 #include <kernel/thread_private.h>
8 #include <gen-asm-defines.h>
9 #include <kernel/boot.h>
10 #include <mm/core_memprot.h>
11 #include <mm/core_mmu.h>
12 #include <mm/core_mmu_arch.h>
13 #include <types_ext.h>
14 
15 DEFINES
16 {
17 	/* struct thread_ctx */
18 	DEFINE(THREAD_CTX_KERN_SP, offsetof(struct thread_ctx, kern_sp));
19 	DEFINE(THREAD_CTX_STACK_VA_END, offsetof(struct thread_ctx,
20 						 stack_va_end));
21 	DEFINE(THREAD_CTX_SIZE, sizeof(struct thread_ctx));
22 
23 	/* struct thread_core_local */
24 	DEFINE(THREAD_CORE_LOCAL_SIZE, sizeof(struct thread_core_local));
25 	DEFINE(THREAD_CORE_LOCAL_HART_ID,
26 	       offsetof(struct thread_core_local, hart_id));
27 	DEFINE(THREAD_CORE_LOCAL_TMP_STACK_VA_END,
28 	       offsetof(struct thread_core_local, tmp_stack_va_end));
29 	DEFINE(THREAD_CORE_LOCAL_CURR_THREAD,
30 	       offsetof(struct thread_core_local, curr_thread));
31 	DEFINE(THREAD_CORE_LOCAL_FLAGS,
32 	       offsetof(struct thread_core_local, flags));
33 	DEFINE(THREAD_CORE_LOCAL_ABT_STACK_VA_END,
34 	       offsetof(struct thread_core_local, abt_stack_va_end));
35 	DEFINE(THREAD_CORE_LOCAL_X0, offsetof(struct thread_core_local, x[0]));
36 	DEFINE(THREAD_CORE_LOCAL_X1, offsetof(struct thread_core_local, x[1]));
37 
38 	DEFINE(STACK_TMP_GUARD, STACK_CANARY_SIZE / 2 + STACK_TMP_OFFS);
39 
40 	/* struct thread_ctx_regs */
41 	DEFINE(THREAD_CTX_REG_STATUS, offsetof(struct thread_ctx_regs, status));
42 	DEFINE(THREAD_CTX_REG_EPC, offsetof(struct thread_ctx_regs, epc));
43 	DEFINE(THREAD_CTX_REG_IE, offsetof(struct thread_ctx_regs, ie));
44 	DEFINE(THREAD_CTX_REG_RA, offsetof(struct thread_ctx_regs, ra));
45 	DEFINE(THREAD_CTX_REG_SP, offsetof(struct thread_ctx_regs, sp));
46 	DEFINE(THREAD_CTX_REG_GP, offsetof(struct thread_ctx_regs, gp));
47 	DEFINE(THREAD_CTX_REG_TP, offsetof(struct thread_ctx_regs, tp));
48 	DEFINE(THREAD_CTX_REG_T0, offsetof(struct thread_ctx_regs, t0));
49 	DEFINE(THREAD_CTX_REG_S0, offsetof(struct thread_ctx_regs, s0));
50 	DEFINE(THREAD_CTX_REG_A0, offsetof(struct thread_ctx_regs, a0));
51 	DEFINE(THREAD_CTX_REG_S2, offsetof(struct thread_ctx_regs, s2));
52 	DEFINE(THREAD_CTX_REG_T3, offsetof(struct thread_ctx_regs, t3));
53 	DEFINE(THREAD_CTX_REGS_SIZE, sizeof(struct thread_ctx_regs));
54 
55 	/* struct thread_user_mode_rec */
56 	DEFINE(THREAD_USER_MODE_REC_CTX_REGS_PTR,
57 	       offsetof(struct thread_user_mode_rec, ctx_regs_ptr));
58 	DEFINE(THREAD_USER_MODE_REC_RA,
59 	       offsetof(struct thread_user_mode_rec, x[0]));
60 	DEFINE(THREAD_USER_MODE_REC_S0,
61 	       offsetof(struct thread_user_mode_rec, x[1]));
62 	DEFINE(THREAD_USER_MODE_REC_S2,
63 	       offsetof(struct thread_user_mode_rec, x[3]));
64 	DEFINE(THREAD_USER_MODE_REC_SIZE, sizeof(struct thread_user_mode_rec));
65 
66 	/* struct thread_abort_regs */
67 	DEFINE(THREAD_ABT_REG_RA, offsetof(struct thread_abort_regs, ra));
68 	DEFINE(THREAD_ABT_REG_SP, offsetof(struct thread_abort_regs, sp));
69 	DEFINE(THREAD_ABT_REG_GP, offsetof(struct thread_abort_regs, gp));
70 	DEFINE(THREAD_ABT_REG_TP, offsetof(struct thread_abort_regs, tp));
71 	DEFINE(THREAD_ABT_REG_T0, offsetof(struct thread_abort_regs, t0));
72 	DEFINE(THREAD_ABT_REG_S0, offsetof(struct thread_abort_regs, s0));
73 	DEFINE(THREAD_ABT_REG_A0, offsetof(struct thread_abort_regs, a0));
74 	DEFINE(THREAD_ABT_REG_S2, offsetof(struct thread_abort_regs, s2));
75 	DEFINE(THREAD_ABT_REG_T3, offsetof(struct thread_abort_regs, t3));
76 	DEFINE(THREAD_ABT_REG_EPC, offsetof(struct thread_abort_regs, epc));
77 	DEFINE(THREAD_ABT_REG_STATUS,
78 	       offsetof(struct thread_abort_regs, status));
79 	DEFINE(THREAD_ABT_REG_IE, offsetof(struct thread_abort_regs, ie));
80 	DEFINE(THREAD_ABT_REG_CAUSE, offsetof(struct thread_abort_regs, cause));
81 	DEFINE(THREAD_ABT_REG_TVAL, offsetof(struct thread_abort_regs, tval));
82 	DEFINE(THREAD_ABT_REGS_SIZE, sizeof(struct thread_abort_regs));
83 
84 	/* struct thread_scall_regs */
85 	DEFINE(THREAD_SCALL_REG_RA, offsetof(struct thread_scall_regs, ra));
86 	DEFINE(THREAD_SCALL_REG_SP, offsetof(struct thread_scall_regs, sp));
87 	DEFINE(THREAD_SCALL_REG_GP, offsetof(struct thread_scall_regs, gp));
88 	DEFINE(THREAD_SCALL_REG_TP, offsetof(struct thread_scall_regs, tp));
89 	DEFINE(THREAD_SCALL_REG_T0, offsetof(struct thread_scall_regs, t0));
90 	DEFINE(THREAD_SCALL_REG_A0, offsetof(struct thread_scall_regs, a0));
91 	DEFINE(THREAD_SCALL_REG_T3, offsetof(struct thread_scall_regs, t3));
92 	DEFINE(THREAD_SCALL_REG_EPC, offsetof(struct thread_scall_regs, epc));
93 	DEFINE(THREAD_SCALL_REG_STATUS,
94 	       offsetof(struct thread_scall_regs, status));
95 	DEFINE(THREAD_SCALL_REG_IE, offsetof(struct thread_scall_regs, ie));
96 	DEFINE(THREAD_SCALL_REGS_SIZE, sizeof(struct thread_scall_regs));
97 
98 	/* struct core_mmu_config */
99 	DEFINE(CORE_MMU_CONFIG_SIZE, sizeof(struct core_mmu_config));
100 	DEFINE(CORE_MMU_CONFIG_SATP,
101 	       offsetof(struct core_mmu_config, satp[0]));
102 	DEFINE(CORE_MMU_CONFIG_SATP_SIZE, sizeof(unsigned long));
103 
104 	/* struct thread_abi_args */
105 	DEFINE(THREAD_ABI_ARGS_A0, offsetof(struct thread_abi_args, a0));
106 	DEFINE(THREAD_ABI_ARGS_SIZE, sizeof(struct thread_abi_args));
107 }
108