xref: /haiku/headers/private/kernel/boot/elf.h (revision f1244978152350f9cc010e766d09c2e9ad34dfce)
1b73b3e5aSAxel Dörfler /*
262dbb799SAxel Dörfler ** Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3b73b3e5aSAxel Dörfler ** Distributed under the terms of the OpenBeOS License.
4b73b3e5aSAxel Dörfler */
5b73b3e5aSAxel Dörfler #ifndef KERNEL_BOOT_ELF_H
6b73b3e5aSAxel Dörfler #define KERNEL_BOOT_ELF_H
7b73b3e5aSAxel Dörfler 
8b73b3e5aSAxel Dörfler 
9ca109e72SAxel Dörfler #include <boot/addr_range.h>
10e07c1f2cSAxel Dörfler #include <sys/stat.h>
11b73b3e5aSAxel Dörfler #include <elf_priv.h>
12d8efc6caSAlex Smith #include <util/FixedWidthPointer.h>
13b73b3e5aSAxel Dörfler 
14*f1244978SAlex Smith typedef struct elf32_region {
15*f1244978SAlex Smith 	area_id		id;
16*f1244978SAlex Smith 	uint32		start;
17*f1244978SAlex Smith 	uint32		size;
18*f1244978SAlex Smith 	int32		delta;
19*f1244978SAlex Smith } _PACKED elf32_region;
20*f1244978SAlex Smith 
21*f1244978SAlex Smith typedef struct elf64_region {
22*f1244978SAlex Smith 	area_id		id;
23*f1244978SAlex Smith 	uint64		start;
24*f1244978SAlex Smith 	uint64		size;
25*f1244978SAlex Smith 	int64		delta;
26*f1244978SAlex Smith } _PACKED elf64_region;
27b73b3e5aSAxel Dörfler 
28b73b3e5aSAxel Dörfler struct preloaded_image {
29d8efc6caSAlex Smith 	FixedWidthPointer<struct preloaded_image> next;
30*f1244978SAlex Smith 	FixedWidthPointer<char> name;
31*f1244978SAlex Smith 	uint8		elf_class;
32c2c0779eSAxel Dörfler 	addr_range	dynamic_section;
336e062dd1SAxel Dörfler 
34*f1244978SAlex Smith 	FixedWidthPointer<const char> debug_string_table;
35*f1244978SAlex Smith 	uint32		num_debug_symbols;
36*f1244978SAlex Smith 	uint32		debug_string_table_size;
37fa1ddc4fSAxel Dörfler 
38e07c1f2cSAxel Dörfler 	ino_t		inode;
396e062dd1SAxel Dörfler 	image_id	id;
406e062dd1SAxel Dörfler 		// the ID field will be filled out in the kernel
419e8dc2a9SIngo Weinhold 	bool		is_module;
429e8dc2a9SIngo Weinhold 		// set by the module initialization code
43d8efc6caSAlex Smith } _PACKED;
44b73b3e5aSAxel Dörfler 
45*f1244978SAlex Smith struct preloaded_elf32_image : public preloaded_image {
46*f1244978SAlex Smith 	Elf32_Ehdr elf_header;
47*f1244978SAlex Smith 	elf32_region text_region;
48*f1244978SAlex Smith 	elf32_region data_region;
49*f1244978SAlex Smith 
50*f1244978SAlex Smith 	FixedWidthPointer<Elf32_Sym> syms;
51*f1244978SAlex Smith 	FixedWidthPointer<Elf32_Rel> rel;
52*f1244978SAlex Smith 	int32		rel_len;
53*f1244978SAlex Smith 	FixedWidthPointer<Elf32_Rela> rela;
54*f1244978SAlex Smith 	int32		rela_len;
55*f1244978SAlex Smith 	FixedWidthPointer<Elf32_Rel> pltrel;
56*f1244978SAlex Smith 	int32		pltrel_len;
57*f1244978SAlex Smith 	int32		pltrel_type;
58*f1244978SAlex Smith 
59*f1244978SAlex Smith 	FixedWidthPointer<Elf32_Sym> debug_symbols;
60*f1244978SAlex Smith } _PACKED;
61*f1244978SAlex Smith 
62*f1244978SAlex Smith struct preloaded_elf64_image : public preloaded_image {
63*f1244978SAlex Smith 	Elf64_Ehdr elf_header;
64*f1244978SAlex Smith 	elf64_region text_region;
65*f1244978SAlex Smith 	elf64_region data_region;
66*f1244978SAlex Smith 
67*f1244978SAlex Smith 	FixedWidthPointer<Elf64_Sym> syms;
68*f1244978SAlex Smith 	FixedWidthPointer<Elf64_Rel> rel;
69*f1244978SAlex Smith 	int64		rel_len;
70*f1244978SAlex Smith 	FixedWidthPointer<Elf64_Rela> rela;
71*f1244978SAlex Smith 	int64		rela_len;
72*f1244978SAlex Smith 	FixedWidthPointer<Elf64_Rel> pltrel;
73*f1244978SAlex Smith 	int64		pltrel_len;
74*f1244978SAlex Smith 	int64		pltrel_type;
75*f1244978SAlex Smith 
76*f1244978SAlex Smith 	FixedWidthPointer<Elf64_Sym> debug_symbols;
77*f1244978SAlex Smith } _PACKED;
78*f1244978SAlex Smith 
79957a1b17SIngo Weinhold #ifdef __cplusplus
80957a1b17SIngo Weinhold extern "C" {
81957a1b17SIngo Weinhold #endif
82957a1b17SIngo Weinhold 
83*f1244978SAlex Smith extern status_t boot_elf_resolve_symbol(struct preloaded_elf32_image *image,
84957a1b17SIngo Weinhold 	struct Elf32_Sym *symbol, addr_t *symbolAddress);
85957a1b17SIngo Weinhold 
86957a1b17SIngo Weinhold #ifdef __cplusplus
87957a1b17SIngo Weinhold }
88957a1b17SIngo Weinhold #endif
89957a1b17SIngo Weinhold 
90b73b3e5aSAxel Dörfler #endif	/* KERNEL_BOOT_ELF_H */
91