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 <types_ext.h> 29 #include <kernel/thread.h> 30 #include "thread_private.h" 31 32 #define DEFINES void __defines(void); void __defines(void) 33 34 #define DEFINE(def, val) \ 35 asm volatile("\n==>" #def " %0 " #val : : "i" (val)) 36 37 DEFINES 38 { 39 #ifdef ARM32 40 DEFINE(THREAD_SVC_REG_R0, offsetof(struct thread_svc_regs, r0)); 41 DEFINE(THREAD_SVC_REG_R5, offsetof(struct thread_svc_regs, r5)); 42 DEFINE(THREAD_SVC_REG_R6, offsetof(struct thread_svc_regs, r6)); 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_X5, offsetof(struct thread_svc_regs, x5)); 51 DEFINE(THREAD_SVC_REG_X6, offsetof(struct thread_svc_regs, x6)); 52 DEFINE(THREAD_SVC_REG_X30, offsetof(struct thread_svc_regs, x30)); 53 DEFINE(THREAD_SVC_REG_ELR, offsetof(struct thread_svc_regs, elr)); 54 DEFINE(THREAD_SVC_REG_SPSR, offsetof(struct thread_svc_regs, spsr)); 55 DEFINE(THREAD_SVC_REG_SP_EL0, offsetof(struct thread_svc_regs, sp_el0)); 56 DEFINE(THREAD_SVC_REG_SIZE, sizeof(struct thread_svc_regs)); 57 58 /* struct thread_abort_regs */ 59 DEFINE(THREAD_ABT_REG_X0, offsetof(struct thread_abort_regs, x0)); 60 DEFINE(THREAD_ABT_REG_X2, offsetof(struct thread_abort_regs, x2)); 61 DEFINE(THREAD_ABT_REG_X30, offsetof(struct thread_abort_regs, x30)); 62 DEFINE(THREAD_ABT_REG_SPSR, offsetof(struct thread_abort_regs, spsr)); 63 DEFINE(THREAD_ABT_REGS_SIZE, sizeof(struct thread_abort_regs)); 64 65 /* struct thread_ctx */ 66 DEFINE(THREAD_CTX_KERN_SP, offsetof(struct thread_ctx, kern_sp)); 67 DEFINE(THREAD_CTX_SIZE, sizeof(struct thread_ctx)); 68 69 /* struct thread_ctx_regs */ 70 DEFINE(THREAD_CTX_REGS_SP, offsetof(struct thread_ctx_regs, sp)); 71 DEFINE(THREAD_CTX_REGS_X0, offsetof(struct thread_ctx_regs, x[0])); 72 DEFINE(THREAD_CTX_REGS_X1, offsetof(struct thread_ctx_regs, x[1])); 73 DEFINE(THREAD_CTX_REGS_X4, offsetof(struct thread_ctx_regs, x[4])); 74 DEFINE(THREAD_CTX_REGS_X19, offsetof(struct thread_ctx_regs, x[19])); 75 76 /* struct thread_user_mode_rec */ 77 DEFINE(THREAD_USER_MODE_REC_EXIT_STATUS0_PTR, 78 offsetof(struct thread_user_mode_rec, exit_status0_ptr)); 79 DEFINE(THREAD_USER_MODE_REC_X19, 80 offsetof(struct thread_user_mode_rec, x[0])); 81 DEFINE(THREAD_USER_MODE_REC_SIZE, sizeof(struct thread_user_mode_rec)); 82 83 /* struct thread_core_local */ 84 DEFINE(THREAD_CORE_LOCAL_TMP_STACK_VA_END, 85 offsetof(struct thread_core_local, tmp_stack_va_end)); 86 DEFINE(THREAD_CORE_LOCAL_CURR_THREAD, 87 offsetof(struct thread_core_local, curr_thread)); 88 DEFINE(THREAD_CORE_LOCAL_FLAGS, 89 offsetof(struct thread_core_local, flags)); 90 DEFINE(THREAD_CORE_LOCAL_ABT_STACK_VA_END, 91 offsetof(struct thread_core_local, abt_stack_va_end)); 92 DEFINE(THREAD_CORE_LOCAL_X0, offsetof(struct thread_core_local, x[0])); 93 DEFINE(THREAD_CORE_LOCAL_X2, offsetof(struct thread_core_local, x[2])); 94 #endif /*ARM64*/ 95 } 96