15dffb46cSSoby Mathew /* 25dffb46cSSoby Mathew * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. 35dffb46cSSoby Mathew * 4*82cb2c1aSdp-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> 115dffb46cSSoby Mathew 125dffb46cSSoby Mathew #define SECURE 0x0 135dffb46cSSoby Mathew #define NON_SECURE 0x1 145dffb46cSSoby Mathew #define sec_state_is_valid(s) (((s) == SECURE) || ((s) == NON_SECURE)) 155dffb46cSSoby Mathew 165dffb46cSSoby Mathew /******************************************************************************* 175dffb46cSSoby Mathew * Constants that allow assembler code to access members of and the 185dffb46cSSoby Mathew * 'entry_point_info' structure at their correct offsets. 195dffb46cSSoby Mathew ******************************************************************************/ 205dffb46cSSoby Mathew #define ENTRY_POINT_INFO_PC_OFFSET 0x08 215dffb46cSSoby Mathew #ifdef AARCH32 225dffb46cSSoby Mathew #define ENTRY_POINT_INFO_ARGS_OFFSET 0x10 235dffb46cSSoby Mathew #else 245dffb46cSSoby Mathew #define ENTRY_POINT_INFO_ARGS_OFFSET 0x18 255dffb46cSSoby Mathew #endif 265dffb46cSSoby Mathew 275dffb46cSSoby Mathew /* The following are used to set/get image attributes. */ 285dffb46cSSoby Mathew #define PARAM_EP_SECURITY_MASK (0x1) 295dffb46cSSoby Mathew 305dffb46cSSoby Mathew #define GET_SECURITY_STATE(x) (x & PARAM_EP_SECURITY_MASK) 315dffb46cSSoby Mathew #define SET_SECURITY_STATE(x, security) \ 325dffb46cSSoby Mathew ((x) = ((x) & ~PARAM_EP_SECURITY_MASK) | (security)) 335dffb46cSSoby Mathew 345dffb46cSSoby Mathew #define EP_EE_MASK 0x2 355dffb46cSSoby Mathew #define EP_EE_LITTLE 0x0 365dffb46cSSoby Mathew #define EP_EE_BIG 0x2 375dffb46cSSoby Mathew #define EP_GET_EE(x) (x & EP_EE_MASK) 385dffb46cSSoby Mathew #define EP_SET_EE(x, ee) ((x) = ((x) & ~EP_EE_MASK) | (ee)) 395dffb46cSSoby Mathew 405dffb46cSSoby Mathew #define EP_ST_MASK 0x4 415dffb46cSSoby Mathew #define EP_ST_DISABLE 0x0 425dffb46cSSoby Mathew #define EP_ST_ENABLE 0x4 435dffb46cSSoby Mathew #define EP_GET_ST(x) (x & EP_ST_MASK) 445dffb46cSSoby Mathew #define EP_SET_ST(x, ee) ((x) = ((x) & ~EP_ST_MASK) | (ee)) 455dffb46cSSoby Mathew 465dffb46cSSoby Mathew #define EP_EXE_MASK 0x8 475dffb46cSSoby Mathew #define NON_EXECUTABLE 0x0 485dffb46cSSoby Mathew #define EXECUTABLE 0x8 495dffb46cSSoby Mathew #define EP_GET_EXE(x) (x & EP_EXE_MASK) 505dffb46cSSoby Mathew #define EP_SET_EXE(x, ee) ((x) = ((x) & ~EP_EXE_MASK) | (ee)) 515dffb46cSSoby Mathew 525dffb46cSSoby Mathew #define EP_FIRST_EXE_MASK 0x10 535dffb46cSSoby Mathew #define EP_FIRST_EXE 0x10 545dffb46cSSoby Mathew #define EP_GET_FIRST_EXE(x) ((x) & EP_FIRST_EXE_MASK) 555dffb46cSSoby Mathew #define EP_SET_FIRST_EXE(x, ee) ((x) = ((x) & ~EP_FIRST_EXE_MASK) | (ee)) 565dffb46cSSoby Mathew 575dffb46cSSoby Mathew #ifndef __ASSEMBLY__ 585dffb46cSSoby Mathew 595dffb46cSSoby Mathew #include <cassert.h> 605dffb46cSSoby Mathew #include <types.h> 615dffb46cSSoby Mathew 625dffb46cSSoby Mathew typedef struct aapcs64_params { 635dffb46cSSoby Mathew u_register_t arg0; 645dffb46cSSoby Mathew u_register_t arg1; 655dffb46cSSoby Mathew u_register_t arg2; 665dffb46cSSoby Mathew u_register_t arg3; 675dffb46cSSoby Mathew u_register_t arg4; 685dffb46cSSoby Mathew u_register_t arg5; 695dffb46cSSoby Mathew u_register_t arg6; 705dffb46cSSoby Mathew u_register_t arg7; 715dffb46cSSoby Mathew } aapcs64_params_t; 725dffb46cSSoby Mathew 735dffb46cSSoby Mathew typedef struct aapcs32_params { 745dffb46cSSoby Mathew u_register_t arg0; 755dffb46cSSoby Mathew u_register_t arg1; 765dffb46cSSoby Mathew u_register_t arg2; 775dffb46cSSoby Mathew u_register_t arg3; 785dffb46cSSoby Mathew } aapcs32_params_t; 795dffb46cSSoby Mathew 805dffb46cSSoby Mathew /***************************************************************************** 815dffb46cSSoby Mathew * This structure represents the superset of information needed while 825dffb46cSSoby Mathew * switching exception levels. The only two mechanisms to do so are 835dffb46cSSoby Mathew * ERET & SMC. Security state is indicated using bit zero of header 845dffb46cSSoby Mathew * attribute 855dffb46cSSoby Mathew * NOTE: BL1 expects entrypoint followed by spsr at an offset from the start 865dffb46cSSoby Mathew * of this structure defined by the macro `ENTRY_POINT_INFO_PC_OFFSET` while 875dffb46cSSoby Mathew * processing SMC to jump to BL31. 885dffb46cSSoby Mathew *****************************************************************************/ 895dffb46cSSoby Mathew typedef struct entry_point_info { 905dffb46cSSoby Mathew param_header_t h; 915dffb46cSSoby Mathew uintptr_t pc; 925dffb46cSSoby Mathew uint32_t spsr; 935dffb46cSSoby Mathew #ifdef AARCH32 945dffb46cSSoby Mathew aapcs32_params_t args; 955dffb46cSSoby Mathew #else 965dffb46cSSoby Mathew aapcs64_params_t args; 975dffb46cSSoby Mathew #endif 985dffb46cSSoby Mathew } entry_point_info_t; 995dffb46cSSoby Mathew 1005dffb46cSSoby Mathew /* 1015dffb46cSSoby Mathew * Compile time assertions related to the 'entry_point_info' structure to 1025dffb46cSSoby Mathew * ensure that the assembler and the compiler view of the offsets of 1035dffb46cSSoby Mathew * the structure members is the same. 1045dffb46cSSoby Mathew */ 1055dffb46cSSoby Mathew CASSERT(ENTRY_POINT_INFO_PC_OFFSET == 1065dffb46cSSoby Mathew __builtin_offsetof(entry_point_info_t, pc), \ 1075dffb46cSSoby Mathew assert_BL31_pc_offset_mismatch); 1085dffb46cSSoby Mathew 1095dffb46cSSoby Mathew CASSERT(ENTRY_POINT_INFO_ARGS_OFFSET == \ 1105dffb46cSSoby Mathew __builtin_offsetof(entry_point_info_t, args), \ 1115dffb46cSSoby Mathew assert_BL31_args_offset_mismatch); 1125dffb46cSSoby Mathew 1135dffb46cSSoby Mathew CASSERT(sizeof(uintptr_t) == 1145dffb46cSSoby Mathew __builtin_offsetof(entry_point_info_t, spsr) - \ 1155dffb46cSSoby Mathew __builtin_offsetof(entry_point_info_t, pc), \ 1165dffb46cSSoby Mathew assert_entrypoint_and_spsr_should_be_adjacent); 1175dffb46cSSoby Mathew 1185dffb46cSSoby Mathew #endif /*__ASSEMBLY__*/ 1195dffb46cSSoby Mathew 1205dffb46cSSoby Mathew #endif /* __EP_INFO_H__ */ 1215dffb46cSSoby Mathew 122