1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2019, Linaro Limited 4 * Copyright (c) 2020, Arm Limited 5 * Copyright 2022-2023 NXP 6 */ 7 8 #ifndef __LDELF_H 9 #define __LDELF_H 10 11 #ifndef __ASSEMBLER__ 12 #include <types_ext.h> 13 #include <tee_api_types.h> 14 #include <user_ta_header.h> 15 16 /* Size of stack for TEE Core to allocate */ 17 #define LDELF_STACK_SIZE (4096 * 2) 18 19 /* 20 * struct ldelf_arg - argument for ldelf 21 * @uuid: [in] UUID of TA to load 22 * @is_32bit: [out] 1 if a 32bit TA or 0 if a 64bit TA 23 * @flags: [out] Flags field of TA header 24 * @entry_func: [out] TA entry function 25 * @stack_ptr: [out] TA stack pointer 26 * @dump_entry: [out] Dump TA mappings and stack trace 27 * @ftrace_entry: [out] Dump TA mappings and ftrace buffer 28 * @fbuf: [out] ftrace buffer pointer 29 * @dl_entry: [out] Dynamic linking interface (for libdl) 30 */ 31 struct ldelf_arg { 32 TEE_UUID uuid; 33 uint32_t is_32bit; 34 uint32_t flags; 35 uint64_t entry_func; 36 uint64_t stack_ptr; 37 uint64_t dump_entry; 38 uint64_t ftrace_entry; 39 uint64_t dl_entry; 40 struct ftrace_buf *fbuf; 41 }; 42 43 #define DUMP_MAP_READ BIT(0) 44 #define DUMP_MAP_WRITE BIT(1) 45 #define DUMP_MAP_EXEC BIT(2) 46 #define DUMP_MAP_SECURE BIT(3) 47 #define DUMP_MAP_EPHEM BIT(4) 48 #define DUMP_MAP_LDELF BIT(7) 49 50 /* 51 * struct dump_entry_arg - argument for ldelf_arg::dump_entry() 52 */ 53 struct dump_entry_arg { 54 union { 55 struct { 56 uint32_t regs[16]; 57 } arm32; 58 struct { 59 uint64_t fp; 60 uint64_t sp; 61 uint64_t pc; 62 } arm64; 63 struct { 64 unsigned long fp; 65 unsigned long sp; 66 unsigned long pc; 67 } rv; 68 }; 69 bool is_32bit; 70 size_t num_maps; 71 struct dump_map { 72 vaddr_t va; 73 paddr_t pa; 74 size_t sz; 75 uint32_t flags; 76 } maps[]; 77 }; 78 79 /* 80 * struct dl_entry_arg - argument for ldelf_arg::dl_entry() 81 */ 82 struct dl_entry_arg { 83 uint32_t cmd; 84 TEE_Result ret; 85 union { 86 struct { 87 TEE_UUID uuid; /* in */ 88 uint32_t flags; /* in */ 89 } dlopen; 90 struct { 91 TEE_UUID uuid; /* in */ 92 vaddr_t val; /* out */ 93 char symbol[]; /* in */ 94 } dlsym; 95 }; 96 }; 97 98 /* 99 * Values for dl_entry_arg::cmd 100 */ 101 #define LDELF_DL_ENTRY_DLOPEN 0 102 #define LDELF_DL_ENTRY_DLSYM 1 103 104 /* 105 * Values for dl_entry_arg::dlopen::flags 106 */ 107 #define RTLD_NOW 2 108 #define RTLD_GLOBAL 0x100 109 #define RTLD_NODELETE 0x1000 110 111 #define LDELF_MAP_FLAG_SHAREABLE BIT32(0) 112 #define LDELF_MAP_FLAG_WRITEABLE BIT32(1) 113 #define LDELF_MAP_FLAG_EXECUTABLE BIT32(2) 114 #define LDELF_MAP_FLAG_BTI BIT32(3) 115 116 #endif /*!__ASSEMBLER__*/ 117 118 #define LDELF_RETURN 0 119 #define LDELF_LOG 1 120 #define LDELF_PANIC 2 121 #define LDELF_MAP_ZI 3 122 #define LDELF_UNMAP 4 123 #define LDELF_OPEN_BIN 5 124 #define LDELF_CLOSE_BIN 6 125 #define LDELF_MAP_BIN 7 126 #define LDELF_CP_FROM_BIN 8 127 #define LDELF_SET_PROT 9 128 #define LDELF_REMAP 10 129 #define LDELF_GEN_RND_NUM 11 130 131 #define LDELF_SCN_MAX 11 132 133 /* 134 * ldelf is loaded into memory by TEE Core. BSS is initialized and a 135 * stack is allocated and supplied in SP register. A struct ldelf_arg 136 * is placed in the stack and a pointer to the struct is provided in 137 * r0/x0 on ARM and in a0/x10 on RISC-V. 138 * 139 * ldelf relocates itself to the address where it is loaded before the main 140 * C routine is called. 141 * 142 * In the main C routine the TA is loaded using the PTA System interface. 143 */ 144 145 #endif /*__LDELF_H*/ 146