15dffb46cSSoby Mathew /* 293c78ed2SAntonio Nino Diaz * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. 35dffb46cSSoby Mathew * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 55dffb46cSSoby Mathew */ 65dffb46cSSoby Mathew 7*c3cf06f1SAntonio Nino Diaz #ifndef EP_INFO_H 8*c3cf06f1SAntonio Nino Diaz #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 233fe81dcfSEtienne Carriere #define ENTRY_POINT_INFO_LR_SVC_OFFSET U(0x10) 243fe81dcfSEtienne Carriere #define ENTRY_POINT_INFO_ARGS_OFFSET U(0x14) 255dffb46cSSoby Mathew #else 26030567e6SVarun Wadekar #define ENTRY_POINT_INFO_ARGS_OFFSET U(0x18) 275dffb46cSSoby Mathew #endif 285dffb46cSSoby Mathew 295dffb46cSSoby Mathew /* The following are used to set/get image attributes. */ 30030567e6SVarun Wadekar #define PARAM_EP_SECURITY_MASK U(0x1) 315dffb46cSSoby Mathew 324ab2c0a4SAntonio Nino Diaz /* Secure or Non-secure image */ 33a0fee747SAntonio Nino Diaz #define GET_SECURITY_STATE(x) ((x) & PARAM_EP_SECURITY_MASK) 345dffb46cSSoby Mathew #define SET_SECURITY_STATE(x, security) \ 355dffb46cSSoby Mathew ((x) = ((x) & ~PARAM_EP_SECURITY_MASK) | (security)) 365dffb46cSSoby Mathew 374ab2c0a4SAntonio Nino Diaz /* Endianness of the image. */ 38030567e6SVarun Wadekar #define EP_EE_MASK U(0x2) 394ab2c0a4SAntonio Nino Diaz #define EP_EE_SHIFT U(1) 40030567e6SVarun Wadekar #define EP_EE_LITTLE U(0x0) 41030567e6SVarun Wadekar #define EP_EE_BIG U(0x2) 424ab2c0a4SAntonio Nino Diaz #define EP_GET_EE(x) ((x) & EP_EE_MASK) 435dffb46cSSoby Mathew #define EP_SET_EE(x, ee) ((x) = ((x) & ~EP_EE_MASK) | (ee)) 445dffb46cSSoby Mathew 454ab2c0a4SAntonio Nino Diaz /* Enable or disable access to the secure timer from secure images. */ 46030567e6SVarun Wadekar #define EP_ST_MASK U(0x4) 47030567e6SVarun Wadekar #define EP_ST_DISABLE U(0x0) 48030567e6SVarun Wadekar #define EP_ST_ENABLE U(0x4) 494ab2c0a4SAntonio Nino Diaz #define EP_GET_ST(x) ((x) & EP_ST_MASK) 505dffb46cSSoby Mathew #define EP_SET_ST(x, ee) ((x) = ((x) & ~EP_ST_MASK) | (ee)) 515dffb46cSSoby Mathew 524ab2c0a4SAntonio Nino Diaz /* Determine if an image is executable or not. */ 53030567e6SVarun Wadekar #define EP_EXE_MASK U(0x8) 54030567e6SVarun Wadekar #define NON_EXECUTABLE U(0x0) 55030567e6SVarun Wadekar #define EXECUTABLE U(0x8) 564ab2c0a4SAntonio Nino Diaz #define EP_GET_EXE(x) ((x) & EP_EXE_MASK) 575dffb46cSSoby Mathew #define EP_SET_EXE(x, ee) ((x) = ((x) & ~EP_EXE_MASK) | (ee)) 585dffb46cSSoby Mathew 594ab2c0a4SAntonio Nino Diaz /* Flag to indicate the first image that is executed. */ 60030567e6SVarun Wadekar #define EP_FIRST_EXE_MASK U(0x10) 61030567e6SVarun Wadekar #define EP_FIRST_EXE U(0x10) 625dffb46cSSoby Mathew #define EP_GET_FIRST_EXE(x) ((x) & EP_FIRST_EXE_MASK) 635dffb46cSSoby Mathew #define EP_SET_FIRST_EXE(x, ee) ((x) = ((x) & ~EP_FIRST_EXE_MASK) | (ee)) 645dffb46cSSoby Mathew 655dffb46cSSoby Mathew #ifndef __ASSEMBLY__ 665dffb46cSSoby Mathew 675dffb46cSSoby Mathew #include <cassert.h> 6893c78ed2SAntonio Nino Diaz #include <stdint.h> 695dffb46cSSoby Mathew 705dffb46cSSoby Mathew typedef struct aapcs64_params { 715dffb46cSSoby Mathew u_register_t arg0; 725dffb46cSSoby Mathew u_register_t arg1; 735dffb46cSSoby Mathew u_register_t arg2; 745dffb46cSSoby Mathew u_register_t arg3; 755dffb46cSSoby Mathew u_register_t arg4; 765dffb46cSSoby Mathew u_register_t arg5; 775dffb46cSSoby Mathew u_register_t arg6; 785dffb46cSSoby Mathew u_register_t arg7; 795dffb46cSSoby Mathew } aapcs64_params_t; 805dffb46cSSoby Mathew 815dffb46cSSoby Mathew typedef struct aapcs32_params { 825dffb46cSSoby Mathew u_register_t arg0; 835dffb46cSSoby Mathew u_register_t arg1; 845dffb46cSSoby Mathew u_register_t arg2; 855dffb46cSSoby Mathew u_register_t arg3; 865dffb46cSSoby Mathew } aapcs32_params_t; 875dffb46cSSoby Mathew 885dffb46cSSoby Mathew /***************************************************************************** 895dffb46cSSoby Mathew * This structure represents the superset of information needed while 905dffb46cSSoby Mathew * switching exception levels. The only two mechanisms to do so are 915dffb46cSSoby Mathew * ERET & SMC. Security state is indicated using bit zero of header 925dffb46cSSoby Mathew * attribute 935dffb46cSSoby Mathew * NOTE: BL1 expects entrypoint followed by spsr at an offset from the start 945dffb46cSSoby Mathew * of this structure defined by the macro `ENTRY_POINT_INFO_PC_OFFSET` while 955dffb46cSSoby Mathew * processing SMC to jump to BL31. 965dffb46cSSoby Mathew *****************************************************************************/ 975dffb46cSSoby Mathew typedef struct entry_point_info { 985dffb46cSSoby Mathew param_header_t h; 995dffb46cSSoby Mathew uintptr_t pc; 1005dffb46cSSoby Mathew uint32_t spsr; 1015dffb46cSSoby Mathew #ifdef AARCH32 1023fe81dcfSEtienne Carriere uintptr_t lr_svc; 1035dffb46cSSoby Mathew aapcs32_params_t args; 1045dffb46cSSoby Mathew #else 1055dffb46cSSoby Mathew aapcs64_params_t args; 1065dffb46cSSoby Mathew #endif 1075dffb46cSSoby Mathew } entry_point_info_t; 1085dffb46cSSoby Mathew 1095dffb46cSSoby Mathew /* 1105dffb46cSSoby Mathew * Compile time assertions related to the 'entry_point_info' structure to 1115dffb46cSSoby Mathew * ensure that the assembler and the compiler view of the offsets of 1125dffb46cSSoby Mathew * the structure members is the same. 1135dffb46cSSoby Mathew */ 1145dffb46cSSoby Mathew CASSERT(ENTRY_POINT_INFO_PC_OFFSET == 1155dffb46cSSoby Mathew __builtin_offsetof(entry_point_info_t, pc), \ 1165dffb46cSSoby Mathew assert_BL31_pc_offset_mismatch); 1175dffb46cSSoby Mathew 1183fe81dcfSEtienne Carriere #ifdef AARCH32 1193fe81dcfSEtienne Carriere CASSERT(ENTRY_POINT_INFO_LR_SVC_OFFSET == 1203fe81dcfSEtienne Carriere __builtin_offsetof(entry_point_info_t, lr_svc), 1213fe81dcfSEtienne Carriere assert_entrypoint_lr_offset_error); 1223fe81dcfSEtienne Carriere #endif 1233fe81dcfSEtienne Carriere 1245dffb46cSSoby Mathew CASSERT(ENTRY_POINT_INFO_ARGS_OFFSET == \ 1255dffb46cSSoby Mathew __builtin_offsetof(entry_point_info_t, args), \ 1265dffb46cSSoby Mathew assert_BL31_args_offset_mismatch); 1275dffb46cSSoby Mathew 1285dffb46cSSoby Mathew CASSERT(sizeof(uintptr_t) == 1295dffb46cSSoby Mathew __builtin_offsetof(entry_point_info_t, spsr) - \ 1305dffb46cSSoby Mathew __builtin_offsetof(entry_point_info_t, pc), \ 1315dffb46cSSoby Mathew assert_entrypoint_and_spsr_should_be_adjacent); 1325dffb46cSSoby Mathew 1335dffb46cSSoby Mathew #endif /*__ASSEMBLY__*/ 1345dffb46cSSoby Mathew 135*c3cf06f1SAntonio Nino Diaz #endif /* EP_INFO_H */ 136