xref: /haiku/headers/private/kernel/boot/elf.h (revision 002f37b0cca92e4cf72857c72ac95db5a8b09615)
1 /*
2  * Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef KERNEL_BOOT_ELF_H
7 #define KERNEL_BOOT_ELF_H
8 
9 
10 #include <boot/addr_range.h>
11 #include <sys/stat.h>
12 #include <elf_priv.h>
13 #include <util/FixedWidthPointer.h>
14 
15 typedef struct elf32_region {
16 	area_id		id;
17 	uint32		start;
18 	uint32		size;
19 	int32		delta;
20 } _PACKED elf32_region;
21 
22 typedef struct elf64_region {
23 	area_id		id;
24 	uint64		start;
25 	uint64		size;
26 	int64		delta;
27 } _PACKED elf64_region;
28 
29 struct preloaded_image {
30 	FixedWidthPointer<struct preloaded_image> next;
31 	FixedWidthPointer<char> name;
32 	uint8		elf_class;
33 	addr_range	dynamic_section;
34 
35 	FixedWidthPointer<char> debug_string_table;
36 	uint32		num_debug_symbols;
37 	uint32		debug_string_table_size;
38 
39 	ino_t		inode;
40 	image_id	id;
41 		// the ID field will be filled out in the kernel
42 	bool		is_module;
43 		// set by the module initialization code
44 } _PACKED;
45 
46 struct preloaded_elf32_image : public preloaded_image {
47 	Elf32_Ehdr	elf_header;
48 	elf32_region text_region;
49 	elf32_region data_region;
50 
51 	FixedWidthPointer<Elf32_Sym> syms;
52 	FixedWidthPointer<Elf32_Rel> rel;
53 	int32		rel_len;
54 	FixedWidthPointer<Elf32_Rela> rela;
55 	int32		rela_len;
56 	FixedWidthPointer<Elf32_Rel> pltrel;
57 	int32		pltrel_len;
58 	int32		pltrel_type;
59 
60 	FixedWidthPointer<Elf32_Sym> debug_symbols;
61 } _PACKED;
62 
63 struct preloaded_elf64_image : public preloaded_image {
64 	Elf64_Ehdr	elf_header;
65 	elf64_region text_region;
66 	elf64_region data_region;
67 
68 	FixedWidthPointer<Elf64_Sym> syms;
69 	FixedWidthPointer<Elf64_Rel> rel;
70 	int64		rel_len;
71 	FixedWidthPointer<Elf64_Rela> rela;
72 	int64		rela_len;
73 	FixedWidthPointer<Elf64_Rel> pltrel;
74 	int64		pltrel_len;
75 	int64		pltrel_type;
76 
77 	FixedWidthPointer<Elf64_Sym> debug_symbols;
78 } _PACKED;
79 
80 
81 #if B_HAIKU_64_BIT
82 typedef preloaded_elf64_image preloaded_elf_image;
83 #else
84 typedef preloaded_elf32_image preloaded_elf_image;
85 #endif
86 
87 
88 #ifdef _BOOT_MODE
89 extern status_t boot_elf_resolve_symbol(preloaded_elf32_image* image,
90 	struct Elf32_Sym* symbol, Elf32_Addr* symbolAddress);
91 extern status_t boot_elf_resolve_symbol(preloaded_elf64_image* image,
92 	struct Elf64_Sym* symbol, Elf64_Addr* symbolAddress);
93 extern void boot_elf64_set_relocation(Elf64_Addr resolveAddress,
94 	Elf64_Addr finalAddress);
95 #endif
96 
97 #endif	/* KERNEL_BOOT_ELF_H */
98