xref: /optee_os/ldelf/include/ldelf.h (revision 757331fc1216e0c1742c00123cc8c3349de3e884)
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  */
27 struct ldelf_arg {
28 	TEE_UUID uuid;
29 	uint32_t is_32bit;
30 	uint32_t flags;
31 	uint64_t entry_func;
32 	uint64_t stack_ptr;
33 	uint64_t dump_entry;
34 	uint64_t ftrace_entry;
35 	struct ftrace_buf *fbuf;
36 };
37 
38 #define DUMP_MAP_READ	BIT(0)
39 #define DUMP_MAP_WRITE	BIT(1)
40 #define DUMP_MAP_EXEC	BIT(2)
41 #define DUMP_MAP_SECURE	BIT(3)
42 #define DUMP_MAP_EPHEM	BIT(4)
43 #define DUMP_MAP_LDELF	BIT(7)
44 
45 /*
46  * struct dump_entry_arg - argument for ldelf_dump()
47  */
48 struct dump_entry_arg {
49 	union {
50 		struct {
51 			uint32_t regs[16];
52 		} arm32;
53 		struct {
54 			uint64_t fp;
55 			uint64_t sp;
56 			uint64_t pc;
57 		} arm64;
58 	};
59 	bool is_arm32;
60 	size_t num_maps;
61 	struct dump_map {
62 		vaddr_t va;
63 		paddr_t pa;
64 		size_t sz;
65 		uint32_t flags;
66 	} maps[];
67 };
68 
69 /*
70  * ldelf is loaded into memory by TEE Core. BSS is initialized and a
71  * stack is allocated and supplied in SP register. A struct ldelf_arg
72  * is placed in the stack and a pointer to the struct is provided in
73  * r0/x0.
74  *
75  * ldelf relocates itself to the address where it is loaded before the main
76  * C routine is called.
77  *
78  * In the main C routine the TA is loaded using the PTA System interface.
79  */
80 
81 #endif /*__LDELF_H*/
82