Subversion Repositories HelenOS-historic

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
854 bondari 1
/*
2
 * Copyright (C) 2006 Sergey Bondari
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
#ifndef __ELF32_H__
30
#define __ELF32_H__
31
 
32
#include <arch/types.h>
33
#include <mm/as.h>
34
 
35
/**
36
 * current ELF version
37
 */
38
#define EV_CURRENT  1
39
 
40
/**
41
 * ELF types
42
 */
43
#define ET_NONE     0   // No type
44
#define ET_REL      1   // Relocatable file
45
#define ET_EXEC     2   // Executable
46
#define ET_DYN      3   // Shared object
47
#define ET_CORE     4   // Core
48
#define ET_LOPROC   0xff00  // Processor specific
49
#define ET_HIPROC   0xffff  // Processor specific
50
 
51
/**
52
 * ELF machine types
53
 */
54
#define EM_NO       0   // No machine
55
#define EM_M32      1   // AT&T WE 32100
56
#define EM_SPARC    2   // SPARC
57
#define EM_386      3   // i386
58
#define EM_68K      4   // Motorola 68000
59
#define EM_88K      5   // Motorola 88000
60
#define EM_860      7   // i80860
61
#define EM_MIPS     8   // MIPS RS3000
62
 
63
/**
64
 * ELF identification indexes
65
 */
66
#define EI_MAG0     0
67
#define EI_MAG1     1
68
#define EI_MAG2     2
69
#define EI_MAG3     3
70
#define EI_CLASS    4   // File class
71
#define EI_DATA     5   // Data encoding
72
#define EI_VERSION  6   // File version
73
#define EI_PAD      7   // Start of padding bytes
74
#define EI_NIDENT   16  // ELF identification table size
75
 
76
/**
77
 * ELF magic number
78
 */
79
#define ELFMAG0     0x7f
80
#define ELFMAG1     'E'
81
#define ELFMAG2     'L'
82
#define ELFMAG3     'F'
83
 
84
/**
85
 * ELF file classes
86
 */
87
#define ELFCLASSNONE    0
88
#define ELFCLASS32  1
89
#define ELFCLASS64  2
90
 
91
/**
92
 * ELF data encoding types
93
 */
94
#define ELFDATANONE 0
95
#define ELFDATA2LSB 1   // Least significant byte first (little endian)
96
#define ELFDATA2MSB 2   // Most signigicant byte first (Big endian)
97
 
98
/**
99
 * ELF error return codes
100
 */
101
#define EE_OK           0   // No error
102
#define EE_INVALID      1   // invalid ELF image
103
#define EE_MEMORY       2   // cannot allocate address space
104
#define EE_INCOMPATIBLE     3   // ELF image is not compatible with current architecture
105
#define EE_UNSUPPORTED      4   // Non-supported ELF (e.g. dynamic ELFs)
106
 
107
 
108
/*
109
 * 32-bit ELF data types
110
 */
111
typedef __u32 elf32_addr;
112
typedef __u16 elf32_half;
113
typedef __u32 elf32_off;
114
typedef int elf32_sword;
115
typedef __u32 elf32_word;
116
 
117
/*
118
 * 32-bit ELF header
119
 */
120
struct elf32_header {
121
    __u8 e_ident[EI_NIDENT];
122
    elf32_half e_type;
123
    elf32_half e_machine;
124
    elf32_word e_version;
125
    elf32_addr e_entry;
126
    elf32_off e_phoff;
127
    elf32_off e_shoff;
128
    elf32_word e_flags;
129
    elf32_half e_ehsize;
130
    elf32_half e_phentsize;
131
    elf32_half e_phnum;
132
    elf32_half e_shentsize;
133
    elf32_half e_shnum;
134
    elf32_half e_shstrndx;
135
};
136
 
137
extern int elf32_load(__address header, as_t * as);
138
 
139
#endif