15dffb46cSSoby Mathew /* 25dffb46cSSoby Mathew * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. 35dffb46cSSoby Mathew * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 55dffb46cSSoby Mathew */ 65dffb46cSSoby Mathew 75dffb46cSSoby Mathew #ifndef __EP_INFO_H__ 85dffb46cSSoby Mathew #define __EP_INFO_H__ 95dffb46cSSoby Mathew 105dffb46cSSoby Mathew #include <param_header.h> 11030567e6SVarun Wadekar #include <utils_def.h> 125dffb46cSSoby Mathew 13030567e6SVarun Wadekar #define SECURE U(0x0) 14030567e6SVarun Wadekar #define NON_SECURE U(0x1) 155dffb46cSSoby Mathew #define sec_state_is_valid(s) (((s) == SECURE) || ((s) == NON_SECURE)) 165dffb46cSSoby Mathew 175dffb46cSSoby Mathew /******************************************************************************* 185dffb46cSSoby Mathew * Constants that allow assembler code to access members of and the 195dffb46cSSoby Mathew * 'entry_point_info' structure at their correct offsets. 205dffb46cSSoby Mathew ******************************************************************************/ 21030567e6SVarun Wadekar #define ENTRY_POINT_INFO_PC_OFFSET U(0x08) 225dffb46cSSoby Mathew #ifdef AARCH32 23030567e6SVarun Wadekar #define ENTRY_POINT_INFO_ARGS_OFFSET U(0x10) 245dffb46cSSoby Mathew #else 25030567e6SVarun Wadekar #define ENTRY_POINT_INFO_ARGS_OFFSET U(0x18) 265dffb46cSSoby Mathew #endif 275dffb46cSSoby Mathew 285dffb46cSSoby Mathew /* The following are used to set/get image attributes. */ 29030567e6SVarun Wadekar #define PARAM_EP_SECURITY_MASK U(0x1) 305dffb46cSSoby Mathew 315dffb46cSSoby Mathew #define GET_SECURITY_STATE(x) (x & PARAM_EP_SECURITY_MASK) 325dffb46cSSoby Mathew #define SET_SECURITY_STATE(x, security) \ 335dffb46cSSoby Mathew ((x) = ((x) & ~PARAM_EP_SECURITY_MASK) | (security)) 345dffb46cSSoby Mathew 35030567e6SVarun Wadekar #define EP_EE_MASK U(0x2) 36*18f2efd6SDavid Cunado #define EP_EE_SHIFT 1 37030567e6SVarun Wadekar #define EP_EE_LITTLE U(0x0) 38030567e6SVarun Wadekar #define EP_EE_BIG U(0x2) 395dffb46cSSoby Mathew #define EP_GET_EE(x) (x & EP_EE_MASK) 405dffb46cSSoby Mathew #define EP_SET_EE(x, ee) ((x) = ((x) & ~EP_EE_MASK) | (ee)) 415dffb46cSSoby Mathew 42030567e6SVarun Wadekar #define EP_ST_MASK U(0x4) 43030567e6SVarun Wadekar #define EP_ST_DISABLE U(0x0) 44030567e6SVarun Wadekar #define EP_ST_ENABLE U(0x4) 455dffb46cSSoby Mathew #define EP_GET_ST(x) (x & EP_ST_MASK) 465dffb46cSSoby Mathew #define EP_SET_ST(x, ee) ((x) = ((x) & ~EP_ST_MASK) | (ee)) 475dffb46cSSoby Mathew 48030567e6SVarun Wadekar #define EP_EXE_MASK U(0x8) 49030567e6SVarun Wadekar #define NON_EXECUTABLE U(0x0) 50030567e6SVarun Wadekar #define EXECUTABLE U(0x8) 515dffb46cSSoby Mathew #define EP_GET_EXE(x) (x & EP_EXE_MASK) 525dffb46cSSoby Mathew #define EP_SET_EXE(x, ee) ((x) = ((x) & ~EP_EXE_MASK) | (ee)) 535dffb46cSSoby Mathew 54030567e6SVarun Wadekar #define EP_FIRST_EXE_MASK U(0x10) 55030567e6SVarun Wadekar #define EP_FIRST_EXE U(0x10) 565dffb46cSSoby Mathew #define EP_GET_FIRST_EXE(x) ((x) & EP_FIRST_EXE_MASK) 575dffb46cSSoby Mathew #define EP_SET_FIRST_EXE(x, ee) ((x) = ((x) & ~EP_FIRST_EXE_MASK) | (ee)) 585dffb46cSSoby Mathew 595dffb46cSSoby Mathew #ifndef __ASSEMBLY__ 605dffb46cSSoby Mathew 615dffb46cSSoby Mathew #include <cassert.h> 625dffb46cSSoby Mathew #include <types.h> 635dffb46cSSoby Mathew 645dffb46cSSoby Mathew typedef struct aapcs64_params { 655dffb46cSSoby Mathew u_register_t arg0; 665dffb46cSSoby Mathew u_register_t arg1; 675dffb46cSSoby Mathew u_register_t arg2; 685dffb46cSSoby Mathew u_register_t arg3; 695dffb46cSSoby Mathew u_register_t arg4; 705dffb46cSSoby Mathew u_register_t arg5; 715dffb46cSSoby Mathew u_register_t arg6; 725dffb46cSSoby Mathew u_register_t arg7; 735dffb46cSSoby Mathew } aapcs64_params_t; 745dffb46cSSoby Mathew 755dffb46cSSoby Mathew typedef struct aapcs32_params { 765dffb46cSSoby Mathew u_register_t arg0; 775dffb46cSSoby Mathew u_register_t arg1; 785dffb46cSSoby Mathew u_register_t arg2; 795dffb46cSSoby Mathew u_register_t arg3; 805dffb46cSSoby Mathew } aapcs32_params_t; 815dffb46cSSoby Mathew 825dffb46cSSoby Mathew /***************************************************************************** 835dffb46cSSoby Mathew * This structure represents the superset of information needed while 845dffb46cSSoby Mathew * switching exception levels. The only two mechanisms to do so are 855dffb46cSSoby Mathew * ERET & SMC. Security state is indicated using bit zero of header 865dffb46cSSoby Mathew * attribute 875dffb46cSSoby Mathew * NOTE: BL1 expects entrypoint followed by spsr at an offset from the start 885dffb46cSSoby Mathew * of this structure defined by the macro `ENTRY_POINT_INFO_PC_OFFSET` while 895dffb46cSSoby Mathew * processing SMC to jump to BL31. 905dffb46cSSoby Mathew *****************************************************************************/ 915dffb46cSSoby Mathew typedef struct entry_point_info { 925dffb46cSSoby Mathew param_header_t h; 935dffb46cSSoby Mathew uintptr_t pc; 945dffb46cSSoby Mathew uint32_t spsr; 955dffb46cSSoby Mathew #ifdef AARCH32 965dffb46cSSoby Mathew aapcs32_params_t args; 975dffb46cSSoby Mathew #else 985dffb46cSSoby Mathew aapcs64_params_t args; 995dffb46cSSoby Mathew #endif 1005dffb46cSSoby Mathew } entry_point_info_t; 1015dffb46cSSoby Mathew 1025dffb46cSSoby Mathew /* 1035dffb46cSSoby Mathew * Compile time assertions related to the 'entry_point_info' structure to 1045dffb46cSSoby Mathew * ensure that the assembler and the compiler view of the offsets of 1055dffb46cSSoby Mathew * the structure members is the same. 1065dffb46cSSoby Mathew */ 1075dffb46cSSoby Mathew CASSERT(ENTRY_POINT_INFO_PC_OFFSET == 1085dffb46cSSoby Mathew __builtin_offsetof(entry_point_info_t, pc), \ 1095dffb46cSSoby Mathew assert_BL31_pc_offset_mismatch); 1105dffb46cSSoby Mathew 1115dffb46cSSoby Mathew CASSERT(ENTRY_POINT_INFO_ARGS_OFFSET == \ 1125dffb46cSSoby Mathew __builtin_offsetof(entry_point_info_t, args), \ 1135dffb46cSSoby Mathew assert_BL31_args_offset_mismatch); 1145dffb46cSSoby Mathew 1155dffb46cSSoby Mathew CASSERT(sizeof(uintptr_t) == 1165dffb46cSSoby Mathew __builtin_offsetof(entry_point_info_t, spsr) - \ 1175dffb46cSSoby Mathew __builtin_offsetof(entry_point_info_t, pc), \ 1185dffb46cSSoby Mathew assert_entrypoint_and_spsr_should_be_adjacent); 1195dffb46cSSoby Mathew 1205dffb46cSSoby Mathew #endif /*__ASSEMBLY__*/ 1215dffb46cSSoby Mathew 1225dffb46cSSoby Mathew #endif /* __EP_INFO_H__ */ 1235dffb46cSSoby Mathew 124