xref: /haiku/headers/private/kernel/boot/elf.h (revision 46b7da1f4f40f7157d74fc7fb26ff9ec7f2416f2)
1b73b3e5aSAxel Dörfler /*
2ccadfaeeSAlex Smith  * Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3ccadfaeeSAlex Smith  * Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
488461898SAlex Smith  * Distributed under the terms of the MIT License.
5b73b3e5aSAxel Dörfler  */
6b73b3e5aSAxel Dörfler #ifndef KERNEL_BOOT_ELF_H
7b73b3e5aSAxel Dörfler #define KERNEL_BOOT_ELF_H
8b73b3e5aSAxel Dörfler 
9b73b3e5aSAxel Dörfler 
10ca109e72SAxel Dörfler #include <boot/addr_range.h>
11e07c1f2cSAxel Dörfler #include <sys/stat.h>
12b73b3e5aSAxel Dörfler #include <elf_priv.h>
13d8efc6caSAlex Smith #include <util/FixedWidthPointer.h>
14b73b3e5aSAxel Dörfler 
15f1244978SAlex Smith typedef struct elf32_region {
16f1244978SAlex Smith 	area_id		id;
17f1244978SAlex Smith 	uint32		start;
18f1244978SAlex Smith 	uint32		size;
19f1244978SAlex Smith 	int32		delta;
20f1244978SAlex Smith } _PACKED elf32_region;
21f1244978SAlex Smith 
22f1244978SAlex Smith typedef struct elf64_region {
23f1244978SAlex Smith 	area_id		id;
24f1244978SAlex Smith 	uint64		start;
25f1244978SAlex Smith 	uint64		size;
26f1244978SAlex Smith 	int64		delta;
27f1244978SAlex Smith } _PACKED elf64_region;
28b73b3e5aSAxel Dörfler 
29b73b3e5aSAxel Dörfler struct preloaded_image {
30d8efc6caSAlex Smith 	FixedWidthPointer<struct preloaded_image> next;
31f1244978SAlex Smith 	FixedWidthPointer<char> name;
32f1244978SAlex Smith 	uint8		elf_class;
33c2c0779eSAxel Dörfler 	addr_range	dynamic_section;
346e062dd1SAxel Dörfler 
3569a8b954SIngo Weinhold 	FixedWidthPointer<char> debug_string_table;
36f1244978SAlex Smith 	uint32		num_debug_symbols;
37f1244978SAlex Smith 	uint32		debug_string_table_size;
38fa1ddc4fSAxel Dörfler 
39e07c1f2cSAxel Dörfler 	ino_t		inode;
406e062dd1SAxel Dörfler 	image_id	id;
416e062dd1SAxel Dörfler 		// the ID field will be filled out in the kernel
429e8dc2a9SIngo Weinhold 	bool		is_module;
439e8dc2a9SIngo Weinhold 		// set by the module initialization code
44d8efc6caSAlex Smith } _PACKED;
45b73b3e5aSAxel Dörfler 
46f1244978SAlex Smith struct preloaded_elf32_image : public preloaded_image {
47f1244978SAlex Smith 	Elf32_Ehdr	elf_header;
48f1244978SAlex Smith 	elf32_region text_region;
49f1244978SAlex Smith 	elf32_region data_region;
50f1244978SAlex Smith 
51f1244978SAlex Smith 	FixedWidthPointer<Elf32_Sym> syms;
52f1244978SAlex Smith 	FixedWidthPointer<Elf32_Rel> rel;
53f1244978SAlex Smith 	int32		rel_len;
54f1244978SAlex Smith 	FixedWidthPointer<Elf32_Rela> rela;
55f1244978SAlex Smith 	int32		rela_len;
56f1244978SAlex Smith 	FixedWidthPointer<Elf32_Rel> pltrel;
57f1244978SAlex Smith 	int32		pltrel_len;
58f1244978SAlex Smith 	int32		pltrel_type;
59f1244978SAlex Smith 
60f1244978SAlex Smith 	FixedWidthPointer<Elf32_Sym> debug_symbols;
61f1244978SAlex Smith } _PACKED;
62f1244978SAlex Smith 
63f1244978SAlex Smith struct preloaded_elf64_image : public preloaded_image {
64f1244978SAlex Smith 	Elf64_Ehdr	elf_header;
65f1244978SAlex Smith 	elf64_region text_region;
66f1244978SAlex Smith 	elf64_region data_region;
67f1244978SAlex Smith 
68f1244978SAlex Smith 	FixedWidthPointer<Elf64_Sym> syms;
69f1244978SAlex Smith 	FixedWidthPointer<Elf64_Rel> rel;
70f1244978SAlex Smith 	int64		rel_len;
71f1244978SAlex Smith 	FixedWidthPointer<Elf64_Rela> rela;
72f1244978SAlex Smith 	int64		rela_len;
73f1244978SAlex Smith 	FixedWidthPointer<Elf64_Rel> pltrel;
74f1244978SAlex Smith 	int64		pltrel_len;
75f1244978SAlex Smith 	int64		pltrel_type;
76f1244978SAlex Smith 
77f1244978SAlex Smith 	FixedWidthPointer<Elf64_Sym> debug_symbols;
78f1244978SAlex Smith } _PACKED;
79f1244978SAlex Smith 
803b802628SAlex Smith 
813b802628SAlex Smith #if B_HAIKU_64_BIT
823b802628SAlex Smith typedef preloaded_elf64_image preloaded_elf_image;
833b802628SAlex Smith #else
843b802628SAlex Smith typedef preloaded_elf32_image preloaded_elf_image;
853b802628SAlex Smith #endif
863b802628SAlex Smith 
873b802628SAlex Smith 
8888461898SAlex Smith #ifdef _BOOT_MODE
89ccadfaeeSAlex Smith extern status_t boot_elf_resolve_symbol(preloaded_elf32_image* image,
9075c31ae2SSimon South 	Elf32_Sym* symbol, Elf32_Addr* symbolAddress);
91ccadfaeeSAlex Smith extern status_t boot_elf_resolve_symbol(preloaded_elf64_image* image,
9275c31ae2SSimon South 	Elf64_Sym* symbol, Elf64_Addr* symbolAddress);
93*6117e0c2SDavid Karoly extern Elf32_Addr boot_elf32_get_relocation(Elf32_Addr resolveAddress);
94*6117e0c2SDavid Karoly extern void boot_elf32_set_relocation(Elf32_Addr resolveAddress,
95*6117e0c2SDavid Karoly 	Elf32_Addr finalAddress);
966f6d78e8SAlex Smith extern void boot_elf64_set_relocation(Elf64_Addr resolveAddress,
976f6d78e8SAlex Smith 	Elf64_Addr finalAddress);
9888461898SAlex Smith #endif
9988461898SAlex Smith 
100b73b3e5aSAxel Dörfler #endif	/* KERNEL_BOOT_ELF_H */
101