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