kernel: ~Stack can grow now (upto 4MB)
[meinos.git] / apps / init / exe_elf.h
blobee66c51a5c08ef8b4dd0213d3f65ed7841c481a8
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 _EXE_ELF_H_
20 #define _EXE_ELF_H_
22 #include <stdint.h>
24 #define ET_NONE 0
25 #define ET_REL 1
26 #define ET_EXEC 2
27 #define ET_DYN 3
28 #define ET_CORE 4
29 #define ET_LOPROC 0xff00
30 #define ET_HIPROC 0xffff
31 // Elf Header Machine
32 #define EM_NONE 0
33 #define EM_M32 1
34 #define EM_SPARC 2
35 #define EM_386 3
36 #define EM_68K 4
37 #define EM_88K 5
38 #define EM_860 7
39 #define EM_MIPS 8
40 // Elf Header Version
41 #define EV_NONE 0
42 #define EV_CURRENT 1
43 // Elf Header ident
44 #define EI_MAG0 0
45 #define EI_MAG1 1
46 #define EI_MAG2 2
47 #define EI_MAG3 3
48 #define EI_CLASS 4
49 #define EI_DATA 5
50 #define EI_VERSION 6
51 #define EI_PAD 7
52 #define EI_NIDENT 16
53 #define ELFMAG0 0x7f
54 #define ELFMAG1 'E'
55 #define ELFMAG2 'L'
56 #define ELFMAG3 'F'
57 #define ELFCLASSNONE 0
58 #define ELFCLASS32 1
59 #define ELFCLASS64 2
60 #define ELFDATANONE 0
61 #define ELFDATA2LSB 1
62 #define ELFDATA2MSB 2
64 // Programm Header Type
65 #define PT_NULL 0x00000000
66 #define PT_LOAD 0x00000001
67 #define PT_DYNAMIC 0x00000002
68 #define PT_INTERP 0x00000003
69 #define PT_NOTE 0x00000004
70 #define PT_SHLIB 0x00000005
71 #define PT_PHDR 0x00000006
72 #define PT_LOPROC 0x70000000
73 #define PT_HIPROC 0x7fffffff
74 // unofficial
75 #define PT_LOOS 0x60000000
76 #define PT_HIOS 0x6fffffff
77 #define PT_GNU_EH_FRAME 0x6474e550
78 #define PT_GNU_STACK (PT_LOOS+0x474e551)
80 // Programm Header Flag
81 #define PF_X 0x1
82 #define PF_W 0x2
83 #define PF_R 0x4
85 typedef struct {
86 uint8_t ident[EI_NIDENT];
87 uint16_t type;
88 uint16_t machine;
89 uint32_t version;
90 uint32_t entry;
91 uint32_t phoff;
92 uint32_t shoff;
93 uint32_t flags;
94 uint16_t ehsize;
95 uint16_t phentsize;
96 uint16_t phnum;
97 uint16_t shentsize;
98 uint16_t shnum;
99 uint16_t shstrndx;
100 } __attribute__ ((packed)) elf_header_t;
102 typedef struct {
103 uint32_t type;
104 uint32_t offset;
105 uint32_t vaddr;
106 uint32_t paddr;
107 uint32_t filesz;
108 uint32_t memsz;
109 uint32_t flags;
110 uint32_t align;
111 } __attribute__ ((packed)) elf_progheader_t;
113 typedef struct {
114 elf_header_t header;
115 int fh;
116 } elf_t;
118 elf_t *elf_create(const char *file);
119 void elf_destroy(elf_t *elf);
120 void *elf_load(elf_t *elf,pid_t pid);
122 #endif /* _EXE_ELF_H_ */