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