xref: /optee_os/ldelf/ta_elf.h (revision 0242833aad7b016d788bfc9ab49140e42ba54182)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2019, Linaro Limited
4  */
5 
6 #ifndef TA_ELF_H
7 #define TA_ELF_H
8 
9 #include <ldelf.h>
10 #include <sys/queue.h>
11 #include <tee_api_types.h>
12 #include <types_ext.h>
13 
14 struct segment {
15 	size_t offset;
16 	size_t vaddr;
17 	size_t filesz;
18 	size_t memsz;
19 	size_t flags;
20 	size_t align;
21 	bool remapped_writeable;
22 	TAILQ_ENTRY(segment) link;
23 };
24 
25 TAILQ_HEAD(segment_head, segment);
26 
27 struct ta_elf {
28 	bool is_main;
29 	bool is_32bit;	/* Initialized from Elf32_Ehdr/Elf64_Ehdr */
30 	bool is_legacy;
31 
32 	vaddr_t load_addr;
33 	vaddr_t max_addr;
34 	vaddr_t max_offs;
35 
36 	vaddr_t ehdr_addr;
37 
38 	/* Initialized from Elf32_Ehdr/Elf64_Ehdr */
39 	vaddr_t e_entry;
40 	vaddr_t e_phoff;
41 	vaddr_t e_shoff;
42 	unsigned int e_phnum;
43 	unsigned int e_shnum;
44 	unsigned int e_phentsize;
45 	unsigned int e_shentsize;
46 
47 	void *phdr;
48 	void *shdr;
49 	/*
50 	 * dynsymtab and dynstr are used for external symbols, they may hold
51 	 * other symbols too.
52 	 */
53 	void *dynsymtab;
54 	size_t num_dynsyms;
55 	const char *dynstr;
56 	size_t dynstr_size;
57 
58 	struct segment_head segs;
59 
60 	vaddr_t exidx_start;
61 	size_t exidx_size;
62 
63 	uint32_t handle;
64 
65 	TEE_UUID uuid;
66 	TAILQ_ENTRY(ta_elf) link;
67 };
68 
69 TAILQ_HEAD(ta_elf_queue, ta_elf);
70 
71 extern struct ta_elf_queue main_elf_queue;
72 
73 void ta_elf_load_main(const TEE_UUID *uuid, uint32_t *is_32bit,
74 		      uint64_t *entry, uint64_t *sp, uint32_t *ta_flags);
75 void ta_elf_load_dependency(struct ta_elf *elf, bool is_32bit);
76 void ta_elf_relocate(struct ta_elf *elf);
77 void ta_elf_finalize_mappings(struct ta_elf *elf);
78 
79 void ta_elf_print_mappings(struct ta_elf_queue *elf_queue, size_t num_maps,
80 			   struct dump_map *maps, vaddr_t mpool_base);
81 #ifdef CFG_UNWIND
82 void ta_elf_stack_trace_a32(uint32_t regs[16]);
83 void ta_elf_stack_trace_a64(uint64_t fp, uint64_t sp, uint64_t pc);
84 #else
85 static inline void ta_elf_stack_trace_a32(uint32_t regs[16] __unused) { }
86 static inline void ta_elf_stack_trace_a64(uint64_t fp __unused,
87 					  uint64_t sp __unused,
88 					  uint64_t pc __unused) { }
89 #endif /*CFG_UNWIND*/
90 #endif /*TA_ELF_H*/
91