kernel/elf: structures must be packed
[meinos.git] / kernel2 / include / elf.h
blob6d0a0035ffe8dc12c7d4a7599ab5effe354cbd28
1 /*
2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef _ELF_H_
20 #define _ELF_H_
22 #include <sys/types.h>
23 #include <stdint.h>
24 #include <memuser.h>
26 #define ET_NONE 0
27 #define ET_REL 1
28 #define ET_EXEC 2
29 #define ET_DYN 3
30 #define ET_CORE 4
31 #define ET_LOPROC 0xff00
32 #define ET_HIPROC 0xffff
33 // Elf Header Machine
34 #define EM_NONE 0
35 #define EM_M32 1
36 #define EM_SPARC 2
37 #define EM_386 3
38 #define EM_68K 4
39 #define EM_88K 5
40 #define EM_860 7
41 #define EM_MIPS 8
42 // Elf Header Version
43 #define EV_NONE 0
44 #define EV_CURRENT 1
45 // Elf Header ident
46 #define EI_MAG0 0
47 #define EI_MAG1 1
48 #define EI_MAG2 2
49 #define EI_MAG3 3
50 #define EI_CLASS 4
51 #define EI_DATA 5
52 #define EI_VERSION 6
53 #define EI_PAD 7
54 #define EI_NIDENT 16
55 #define ELFMAG0 0x7f
56 #define ELFMAG1 'E'
57 #define ELFMAG2 'L'
58 #define ELFMAG3 'F'
59 #define ELFCLASSNONE 0
60 #define ELFCLASS32 1
61 #define ELFCLASS64 2
62 #define ELFDATANONE 0
63 #define ELFDATA2LSB 1
64 #define ELFDATA2MSB 2
66 // Programm Header Type
67 #define PT_NULL 0x00000000
68 #define PT_LOAD 0x00000001
69 #define PT_DYNAMIC 0x00000002
70 #define PT_INTERP 0x00000003
71 #define PT_NOTE 0x00000004
72 #define PT_SHLIB 0x00000005
73 #define PT_PHDR 0x00000006
74 #define PT_LOPROC 0x70000000
75 #define PT_HIPROC 0x7fffffff
76 // unofficial
77 #define PT_LOOS 0x60000000
78 #define PT_HIOS 0x6fffffff
79 #define PT_GNU_EH_FRAME 0x6474e550
80 #define PT_GNU_STACK (PT_LOOS+0x474e551)
82 // Programm Header Flag
83 #define PF_X 0x1
84 #define PF_W 0x2
85 #define PF_R 0x4
87 typedef struct {
88 uint8_t ident[EI_NIDENT];
89 uint16_t type;
90 uint16_t machine;
91 uint32_t version;
92 uint32_t entry;
93 uint32_t phoff;
94 uint32_t shoff;
95 uint32_t flags;
96 uint16_t ehsize;
97 uint16_t phentsize;
98 uint16_t phnum;
99 uint16_t shentsize;
100 uint16_t shnum;
101 uint16_t shstrndx;
102 } __attribute__ ((packed)) elf_header_t;
104 typedef struct {
105 uint32_t type;
106 uint32_t offset;
107 uint32_t vaddr;
108 uint32_t paddr;
109 uint32_t filesz;
110 uint32_t memsz;
111 uint32_t flags;
112 uint32_t align;
113 } __attribute__ ((packed)) elf_progheader_t;
115 int elf_validate(elf_header_t *header);
116 int elf_loadseg(void *memaddr,size_t memsize,void *fileaddr,size_t filesize,addrspace_t *addrspace,int writable);
117 void *elf_load(addrspace_t *addrspace,void *file,size_t filesize);
119 #endif