- Implemented execp*.
[planlOS.git] / system / include / ke / elf.h
blob0e31d79024bc92a8e9696c85bb18baf156f036a1
1 /*
2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #ifndef KE_ELF_H_INCLUDED
23 #define KE_ELF_H_INCLUDED
25 #include <stdint.h>
26 #include "mm/memory.h"
28 #define EI_NIDENT 16
30 #define EI_MAG0 0
31 #define EI_MAG1 1
32 #define EI_MAG2 2
33 #define EI_MAG3 3
34 #define EI_CLASS 4
35 #define EI_DATA 5
36 #define EI_VERSION 6
37 #define EI_PAD 7
39 #define ELFMAG0 0x7F
40 #define ELFMAG1 'E'
41 #define ELFMAG2 'L'
42 #define ELFMAG3 'F'
44 #define ELFCLASSNONE 0
45 #define ELFCLASS32 1
46 #define ELFCLASS64 2
48 #define ET_DYN 3
50 #define EM_386 3
52 #define SHT_NULL 0
53 #define SHT_PROGBITS 1
54 #define SHT_SYMTAB 2
55 #define SHT_STRTAB 3
56 #define SHT_RELA 4
57 #define SHT_HASH 5
58 #define SHT_DYNAMIC 6
59 #define SHT_NOTE 7
60 #define SHT_NOBITS 8
61 #define SHT_REL 9
62 #define SHT_SHLIB 10
63 #define SHT_DYNSYM 11
65 #define SHF_WRITE 1
66 #define SHF_ALLOC 2
67 #define SHF_EXECINSTR 4
68 #define SHF_MASKPROC 0xF0000000
70 #define STB_LOCAL 0
71 #define STB_GLOBAL 1
72 #define STB_WEAK 2
74 #define STT_NOTYPE 0
75 #define STT_OBJECT 1
76 #define STT_FUNCTION 2
77 #define STT_SECTION 3
78 #define STT_FILE 4
80 #define ELF32_ST_BIND(i) ((i)>>4)
81 #define ELF32_ST_TYPE(i) ((i)&0xF)
83 #define SHN_ABS 0
84 #define SHN_COMMON 0
85 #define SHN_UNDEF 0
87 #define PT_NULL 0
88 #define PT_LOAD 1
89 #define PT_DYNAMIC 2
90 #define PT_INTERP 3
91 #define PT_NOTE 4
92 #define PT_SHLIB 5
93 #define PT_PHDR 6
95 #define ELF32_R_SYM(i) ((i)>>8)
96 #define ELF32_R_TYPE(i) ((unsigned char)(i))
98 #define R_386_NONE 0
99 #define R_386_32 1
100 #define R_386_PC32 2
102 #define R_386_GLOB_DAT 6
103 #define R_386_JUMP_SLOT 7
104 #define R_386_RELATIVE 8
106 typedef struct ElfHeader
108 uint8_t e_ident[EI_NIDENT];
109 uint16_t e_type;
110 uint16_t e_machine;
111 uint32_t e_version;
112 uint32_t e_entry;
113 uint32_t e_phoff;
114 uint32_t e_shoff;
115 uint32_t e_flags;
116 uint16_t e_ehsize;
117 uint16_t e_phentsize;
118 uint16_t e_phnum;
119 uint16_t e_shentsize;
120 uint16_t e_shnum;
121 uint16_t e_shstrndx;
122 } ElfHeader;
124 typedef struct ElfSectionHeader
126 uint32_t sh_name;
127 uint32_t sh_type;
128 uint32_t sh_flags;
129 uint32_t sh_addr;
130 uint32_t sh_offset;
131 uint32_t sh_size;
132 uint32_t sh_link;
133 uint32_t sh_info;
134 uint32_t sh_addralign;
135 uint32_t sh_entsize;
136 } ElfSectionHeader;
138 typedef struct ElfSymbol
140 uint32_t st_name;
141 uint32_t st_value;
142 uint32_t st_size;
143 uint8_t st_info;
144 uint8_t st_other;
145 uint16_t st_shndx;
146 } ElfSymbol;
148 typedef struct ElfRel
150 uint32_t r_offset;
151 uint32_t r_info;
152 } ElfRel;
154 typedef struct ElfRela
156 uint32_t r_offset;
157 uint32_t r_info;
158 uint32_t r_addend;
159 } ElfRela;
161 typedef struct ElfProgramHeader
163 uint32_t p_type;
164 uint32_t p_offset;
165 uint32_t p_vaddr;
166 uint32_t p_paddr;
167 uint32_t p_filesz;
168 uint32_t p_memsz;
169 uint32_t p_flags;
170 uint32_t p_align;
171 } ElfProgramHeader;
173 int keElfMapProgram(MmAddressSpace *addrspace, char *program, uint32_t size);
175 #endif