source: trunk/kernel/libk/elf.h @ 270

Last change on this file since 270 was 270, checked in by max@…, 7 years ago

Comment out EI_OSABI, and use ELFCLASS.

File size: 9.2 KB
RevLine 
[1]1/* This file defines standard ELF types, structures, and macros.
2   Copyright (C) 1995-2003,2004,2005,2006,2007,2008,2009
3        Free Software Foundation, Inc.
4   This file is part of the GNU C Library.
5
6   The GNU C Library is free software; you can redistribute it and/or
7   modify it under the terms of the GNU Lesser General Public
8   License as published by the Free Software Foundation; either
9   version 2.1 of the License, or (at your option) any later version.
10
11   The GNU C Library is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   Lesser General Public License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with the GNU C Library; if not, write to the Free
18   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19   02111-1307 USA.  */
20
21#ifndef _ELF_H_
22#define _ELF_H_ 1
23
24#include <hal_types.h>
25
[157]26/*
27 * Standard ELF types.
28 */
[1]29
[227]30#define EI_NIDENT (16)
31
32/* 32bit version */
[1]33typedef uint16_t Elf32_Half;
34typedef uint32_t Elf32_Word;
[227]35typedef int32_t  Elf32_Sword;
[1]36typedef uint32_t Elf32_Addr;
37typedef uint32_t Elf32_Off;
38
[227]39/* 64bit version */
40typedef uint16_t Elf64_Half;
41typedef uint32_t Elf64_Word;
42typedef int32_t  Elf64_Sword;
43typedef uint64_t Elf64_Addr;
44typedef uint64_t Elf64_Off;
[1]45
[227]46/* ELF header - 32bit version. */
[1]47typedef struct
48{
[227]49        unsigned char   e_ident[EI_NIDENT]; /* Magic number and other info */
[1]50        Elf32_Half      e_type;             /* Object file type */
51        Elf32_Half      e_machine;          /* Architecture */
52        Elf32_Word      e_version;          /* Object file version */
[227]53        Elf32_Addr      e_entry;            /* Entry point virtual address */
54        Elf32_Off       e_phoff;            /* Program header table file offset */
55        Elf32_Off       e_shoff;            /* Section header table file offset */
[1]56        Elf32_Word      e_flags;            /* Processor-specific flags */
57        Elf32_Half      e_ehsize;           /* ELF header size in bytes */
58        Elf32_Half      e_phentsize;        /* Program header table entry size */
59        Elf32_Half      e_phnum;            /* Program header table entry count */
60        Elf32_Half      e_shentsize;        /* Section header table entry size */
61        Elf32_Half      e_shnum;            /* Section header table entry count */
62        Elf32_Half      e_shstrndx;         /* Section header string table index */
[156]63}
[1]64Elf32_Ehdr;
65
[227]66/* ELF header - 64bit version. */
67typedef struct
68{
69        unsigned char   e_ident[EI_NIDENT]; /* Magic number and other info */
70        Elf64_Half      e_type;             /* Object file type */
71        Elf64_Half      e_machine;          /* Architecture */
72        Elf64_Word      e_version;          /* Object file version */
73        Elf64_Addr      e_entry;            /* Entry point virtual address */
74        Elf64_Off       e_phoff;            /* Program header table file offset */
75        Elf64_Off       e_shoff;            /* Section header table file offset */
76        Elf64_Word      e_flags;            /* Processor-specific flags */
77        Elf64_Half      e_ehsize;           /* ELF header size in bytes */
78        Elf64_Half      e_phentsize;        /* Program header table entry size */
79        Elf64_Half      e_phnum;            /* Program header table entry count */
80        Elf64_Half      e_shentsize;        /* Section header table entry size */
81        Elf64_Half      e_shnum;            /* Section header table entry count */
82        Elf64_Half      e_shstrndx;             /* Section header string table index */
83}
84Elf64_Ehdr;
85
[157]86/*
87 * Fields in the e_ident array. The EI_* macros are indices into the
88 * array. The macros under each EI_* macro are the values the byte
89 * may have.
90 */
[1]91#define EI_MAG0         0               /* File identification byte 0 index */
92#define ELFMAG0         0x7f            /* Magic number byte 0 */
93
94#define EI_MAG1         1               /* File identification byte 1 index */
95#define ELFMAG1         'E'             /* Magic number byte 1 */
96
97#define EI_MAG2         2               /* File identification byte 2 index */
98#define ELFMAG2         'L'             /* Magic number byte 2 */
99
100#define EI_MAG3         3               /* File identification byte 3 index */
101#define ELFMAG3         'F'             /* Magic number byte 3 */
102
103#define EI_CLASS        4               /* File class byte index */
104#define ELFCLASSNONE    0               /* Invalid class */
105#define ELFCLASS32      1               /* 32-bit objects */
[270]106#define ELFCLASS64      2       /* 64-bit objects */
107
[1]108#define ELFCLASSNUM     3
109
110#define EI_DATA         5               /* Data encoding byte index */
111#define ELFDATANONE     0               /* Invalid data encoding */
112#define ELFDATA2LSB     1               /* 2's complement, little endian */
113#define ELFDATA2MSB     2               /* 2's complement, big endian */
114#define ELFDATANUM      3
115
116#define EI_VERSION      6               /* File version byte index */
117                                        /* Value must be EV_CURRENT */
118
119#define EI_OSABI        7               /* OS ABI identification */
120#define ELFOSABI_NONE           0       /* UNIX System V ABI */
121
122/* Legal values for e_type (object file type).  */
123#define ET_NONE         0               /* No file type */
124#define ET_REL          1               /* Relocatable file */
125#define ET_EXEC         2               /* Executable file */
126#define ET_DYN          3               /* Shared object file */
127#define ET_CORE         4               /* Core file */
128#define ET_NUM          5               /* Number of defined types */
129#define ET_LOOS         0xfe00          /* OS-specific range start */
130#define ET_HIOS         0xfeff          /* OS-specific range end */
131#define ET_LOPROC       0xff00          /* Processor-specific range start */
132#define ET_HIPROC       0xffff          /* Processor-specific range end */
133
134/* Legal values for e_machine (architecture).  */
135#define EM_NONE          0              /* No machine */
136#define EM_MIPS          8              /* MIPS R3000 big-endian */
137#define EM_MIPS_RS3_LE  10              /* MIPS R3000 little-endian */
138#define EM_PPC          20              /* PowerPC */
139#define EM_PPC64        21              /* PowerPC 64-bit */
140#define EM_ARM          40              /* ARM */
[158]141#define EM_X86_64       62              /* AMD x86-64 architecture */
[1]142
143/* Legal values for e_version (version).  */
144#define EV_NONE         0               /* Invalid ELF version */
145#define EV_CURRENT      1               /* Current version */
146#define EV_NUM          2
147
[227]148/* Program segment header - 32bit version. */
[1]149typedef struct
150{
[227]151        Elf32_Word  p_type;     /* Segment type */
152        Elf32_Off   p_offset;   /* Segment file offset */
153        Elf32_Addr  p_vaddr;    /* Segment virtual address */
154        Elf32_Addr  p_paddr;    /* Segment physical address */
155        Elf32_Word  p_filesz;   /* Segment size in file */
156        Elf32_Word  p_memsz;    /* Segment size in memory */
157        Elf32_Word  p_flags;    /* Segment flags */
158        Elf32_Word  p_align;    /* Segment alignment */
[156]159}
[1]160Elf32_Phdr;
161
[227]162/* Program segment header - 64bit version. */
163typedef struct
164{
165        Elf64_Word  p_type;     /* Segment type */
166        Elf64_Word  p_flags;    /* Segment flags */
167        Elf64_Off   p_offset;   /* Segment file offset */
168        Elf64_Addr  p_vaddr;    /* Segment virtual address */
169        Elf64_Addr  p_paddr;    /* Segment physical address */
170        Elf64_Word  p_filesz;   /* Segment size in file */
171        Elf64_Word  p_memsz;    /* Segment size in memory */
172        Elf64_Word  p_align;    /* Segment alignment */
173}
174Elf64_Phdr;
175
[1]176/* Legal values for p_type (segment type).  */
177#define PT_NULL         0               /* Program header table entry unused */
178#define PT_LOAD         1               /* Loadable program segment */
179#define PT_DYNAMIC      2               /* Dynamic linking information */
180#define PT_INTERP       3               /* Program interpreter */
181#define PT_NOTE         4               /* Auxiliary information */
182#define PT_SHLIB        5               /* Reserved */
183#define PT_PHDR         6               /* Entry for header table itself */
184#define PT_TLS          7               /* Thread-local storage segment */
185#define PT_NUM          8               /* Number of defined types */
186#define PT_LOOS         0x60000000      /* Start of OS-specific */
187#define PT_GNU_EH_FRAME 0x6474e550      /* GCC .eh_frame_hdr segment */
188#define PT_GNU_STACK    0x6474e551      /* Indicates stack executability */
189#define PT_GNU_RELRO    0x6474e552      /* Read-only after relocation */
190#define PT_LOSUNW       0x6ffffffa
191#define PT_SUNWBSS      0x6ffffffa      /* Sun Specific segment */
192#define PT_SUNWSTACK    0x6ffffffb      /* Stack segment */
193#define PT_HISUNW       0x6fffffff
194#define PT_HIOS         0x6fffffff      /* End of OS-specific */
195#define PT_LOPROC       0x70000000      /* Start of processor-specific */
196#define PT_HIPROC       0x7fffffff      /* End of processor-specific */
197
198/* Legal values for p_flags (segment flags).  */
199#define PF_X            (1 << 0)        /* Segment is executable */
200#define PF_W            (1 << 1)        /* Segment is writable */
201#define PF_R            (1 << 2)        /* Segment is readable */
202#define PF_MASKOS       0x0ff00000      /* OS-specific */
203#define PF_MASKPROC     0xf0000000      /* Processor-specific */
204
[227]205#if defined(HAL_32BIT)
206#define Elf_Half  Elf32_Half
207#define Elf_Word  Elf32_Word
208#define Elf_Sword Elf32_Sword
209#define Elf_Addr  Elf32_Addr
210#define Elf_Off   Elf32_Off
211#define Elf_Ehdr  Elf32_Ehdr
212#define Elf_Phdr  Elf32_Phdr
[270]213#define ELFCLASS  ELFCLASS32
[227]214#elif defined (HAL_64BIT)
215#define Elf_Half  Elf64_Half
216#define Elf_Word  Elf64_Word
217#define Elf_Sword Elf64_Sword
218#define Elf_Addr  Elf64_Addr
219#define Elf_Off   Elf64_Off
220#define Elf_Ehdr  Elf64_Ehdr
221#define Elf_Phdr  Elf64_Phdr
[270]222#define ELFCLASS  ELFCLASS64
[227]223#else
224#error "Must define HAL_64BIT/HAL_32BIT"
225#endif
[1]226
227/****************************************************************************************
[156]228 * This function registers in VMM the CODE and DATA vsegs defined in the .elf file.
[1]229 * The segments are not loaded in memory.
[156]230 * It also registers the process entry point in VMM.
[1]231 ****************************************************************************************
[204]232 * @ pathname : local pointer on .elf file pathname (in kernel space).
[1]233 * @ process  : local pointer on target process descriptor.
234 ***************************************************************************************/
235error_t elf_load_process( char      * pathname,
236                          process_t * process);
237
238#endif  /* elf.h */
Note: See TracBrowser for help on using the repository browser.