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/sm.h> 30 #include <types_ext.h> 31 #include "thread_private.h" 32 33 #define DEFINES void __defines(void); void __defines(void) 34 35 #define DEFINE(def, val) \ 36 asm volatile("\n==>" #def " %0 " #val : : "i" (val)) 37 38 DEFINES 39 { 40 #ifdef ARM32 41 DEFINE(SM_NSEC_CTX_R0, offsetof(struct sm_nsec_ctx, r0)); 42 DEFINE(SM_NSEC_CTX_R8, offsetof(struct sm_nsec_ctx, r8)); 43 DEFINE(SM_SEC_CTX_R0, offsetof(struct sm_sec_ctx, r0)); 44 DEFINE(SM_SEC_CTX_MON_LR, offsetof(struct sm_sec_ctx, mon_lr)); 45 DEFINE(SM_CTX_SIZE, sizeof(struct sm_ctx)); 46 DEFINE(SM_CTX_NSEC, offsetof(struct sm_ctx, nsec)); 47 DEFINE(SM_CTX_SEC, offsetof(struct sm_ctx, sec)); 48 49 DEFINE(THREAD_VECTOR_TABLE_FIQ_ENTRY, 50 offsetof(struct thread_vector_table, fiq_entry)); 51 52 DEFINE(THREAD_SVC_REG_R0, offsetof(struct thread_svc_regs, r0)); 53 DEFINE(THREAD_SVC_REG_R5, offsetof(struct thread_svc_regs, r5)); 54 DEFINE(THREAD_SVC_REG_R6, offsetof(struct thread_svc_regs, r6)); 55 #endif /*ARM32*/ 56 57 #ifdef ARM64 58 DEFINE(THREAD_SMC_ARGS_X0, offsetof(struct thread_smc_args, a0)); 59 DEFINE(THREAD_SMC_ARGS_SIZE, sizeof(struct thread_smc_args)); 60 61 DEFINE(THREAD_SVC_REG_X0, offsetof(struct thread_svc_regs, x0)); 62 DEFINE(THREAD_SVC_REG_X5, offsetof(struct thread_svc_regs, x5)); 63 DEFINE(THREAD_SVC_REG_X6, offsetof(struct thread_svc_regs, x6)); 64 DEFINE(THREAD_SVC_REG_X30, offsetof(struct thread_svc_regs, x30)); 65 DEFINE(THREAD_SVC_REG_ELR, offsetof(struct thread_svc_regs, elr)); 66 DEFINE(THREAD_SVC_REG_SPSR, offsetof(struct thread_svc_regs, spsr)); 67 DEFINE(THREAD_SVC_REG_SP_EL0, offsetof(struct thread_svc_regs, sp_el0)); 68 DEFINE(THREAD_SVC_REG_SIZE, sizeof(struct thread_svc_regs)); 69 70 /* struct thread_abort_regs */ 71 DEFINE(THREAD_ABT_REG_X0, offsetof(struct thread_abort_regs, x0)); 72 DEFINE(THREAD_ABT_REG_X2, offsetof(struct thread_abort_regs, x2)); 73 DEFINE(THREAD_ABT_REG_X30, offsetof(struct thread_abort_regs, x30)); 74 DEFINE(THREAD_ABT_REG_SPSR, offsetof(struct thread_abort_regs, spsr)); 75 DEFINE(THREAD_ABT_REGS_SIZE, sizeof(struct thread_abort_regs)); 76 77 /* struct thread_ctx */ 78 DEFINE(THREAD_CTX_KERN_SP, offsetof(struct thread_ctx, kern_sp)); 79 DEFINE(THREAD_CTX_SIZE, sizeof(struct thread_ctx)); 80 81 /* struct thread_ctx_regs */ 82 DEFINE(THREAD_CTX_REGS_SP, offsetof(struct thread_ctx_regs, sp)); 83 DEFINE(THREAD_CTX_REGS_X0, offsetof(struct thread_ctx_regs, x[0])); 84 DEFINE(THREAD_CTX_REGS_X1, offsetof(struct thread_ctx_regs, x[1])); 85 DEFINE(THREAD_CTX_REGS_X4, offsetof(struct thread_ctx_regs, x[4])); 86 DEFINE(THREAD_CTX_REGS_X19, offsetof(struct thread_ctx_regs, x[19])); 87 88 /* struct thread_user_mode_rec */ 89 DEFINE(THREAD_USER_MODE_REC_EXIT_STATUS0_PTR, 90 offsetof(struct thread_user_mode_rec, exit_status0_ptr)); 91 DEFINE(THREAD_USER_MODE_REC_X19, 92 offsetof(struct thread_user_mode_rec, x[0])); 93 DEFINE(THREAD_USER_MODE_REC_SIZE, sizeof(struct thread_user_mode_rec)); 94 95 /* struct thread_core_local */ 96 DEFINE(THREAD_CORE_LOCAL_TMP_STACK_VA_END, 97 offsetof(struct thread_core_local, tmp_stack_va_end)); 98 DEFINE(THREAD_CORE_LOCAL_CURR_THREAD, 99 offsetof(struct thread_core_local, curr_thread)); 100 DEFINE(THREAD_CORE_LOCAL_FLAGS, 101 offsetof(struct thread_core_local, flags)); 102 DEFINE(THREAD_CORE_LOCAL_ABT_STACK_VA_END, 103 offsetof(struct thread_core_local, abt_stack_va_end)); 104 DEFINE(THREAD_CORE_LOCAL_X0, offsetof(struct thread_core_local, x[0])); 105 DEFINE(THREAD_CORE_LOCAL_X2, offsetof(struct thread_core_local, x[2])); 106 #endif /*ARM64*/ 107 } 108