file_formats.h
7.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* Copyright (C) 1996-1998 by the Board of Trustees
* of Leland Stanford Junior University.
*
* This file is part of the SimOS distribution.
* See LICENSE file for terms of the license.
*
*/
/*****************************************************************
* Structures needed to load and interpret an SGI kernel.
*
* $Author: blythe $
* $Date: 2003/03/05 08:05:57 $
*****************************************************************/
#ifndef _FILE_FORMATS_H
#define _FILE_FORMATS_H
#ifdef sgi
#define __ELF_H__ /* Prevent the system's elf.h from being included */
#define __LIBELF_H__
#define __SYS_ELFTYPES_H__
#endif
#include "simtypes.h"
typedef struct filehdr {
uint16 f_magic; /* magic number */
uint16 f_nscns; /* number of sections */
int32 f_timdat; /* time & date stamp */
int32 f_symptr; /* file pointer to symbolic header */
int32 f_nsyms; /* sizeof(symbolic hdr) */
uint16 f_opthdr; /* sizeof(optional hdr) */
uint16 f_flags; /* flags */
} FILHDR;
typedef struct scnhdr {
char s_name[8]; /* section name */
int32 s_paddr; /* physical address, aliased s_nlib */
int32 s_vaddr; /* virtual address */
int32 s_size; /* section size */
int32 s_scnptr; /* file ptr to raw data for section */
int32 s_relptr; /* file ptr to relocation */
int32 s_lnnoptr; /* file ptr to gp histogram */
uint16 s_nreloc; /* number of relocation entries */
uint16 s_nlnno; /* number of gp histogram entries */
int32 s_flags; /* flags field */
int32 s_type; /* type field */
} SCNHDR;
typedef struct aouthdr {
int16 magic; /* see above */
int16 vstamp; /* version stamp */
int32 tsize; /* text size in bytes, padded to DW bdry*/
int32 dsize; /* initialized data " " */
int32 bsize; /* uninitialized data " " */
int32 entry; /* entry pt. */
int32 text_start; /* base of text used for this file */
int32 data_start; /* base of data used for this file */
int32 bss_start; /* base of bss used for this file */
int32 gprmask; /* general purpose register mask */
int32 cprmask[4]; /* co-processor register masks */
int32 gp_value; /* the gp value used for this object */
} AOUTHDR;
/* ELF header
*/
typedef __uint32_t Elf32_Addr;
typedef unsigned short Elf32_Half;
typedef __uint32_t Elf32_Off;
typedef __int32_t Elf32_Sword;
typedef __uint32_t Elf32_Word;
typedef unsigned char Elf32_Byte;
typedef unsigned short Elf32_Section;
/* 64 bit data types */
typedef __uint64_t Elf64_Addr;
typedef unsigned short Elf64_Half;
typedef __uint64_t Elf64_Off;
typedef __int32_t Elf64_Sword;
typedef __int64_t Elf64_Sxword;
typedef __uint32_t Elf64_Word;
typedef __uint64_t Elf64_Xword;
typedef unsigned char Elf64_Byte; /* unsigned tiny integer */
typedef unsigned short Elf64_Section; /* section index (unsigned) */
#define EI_NIDENT 16
typedef struct {
unsigned char e_ident[EI_NIDENT]; /* ident bytes */
Elf32_Half e_type; /* file type */
Elf32_Half e_machine; /* target machine */
Elf32_Word e_version; /* file version */
Elf32_Addr e_entry; /* start address */
Elf32_Off e_phoff; /* phdr file offset */
Elf32_Off e_shoff; /* shdr file offset */
Elf32_Word e_flags; /* file flags */
Elf32_Half e_ehsize; /* sizeof ehdr */
Elf32_Half e_phentsize; /* sizeof phdr */
Elf32_Half e_phnum; /* number phdrs */
Elf32_Half e_shentsize; /* sizeof shdr */
Elf32_Half e_shnum; /* number shdrs */
Elf32_Half e_shstrndx; /* shdr string index */
} Elf32_Ehdr;
typedef struct {
unsigned char e_ident[EI_NIDENT]; /* ident bytes */
Elf64_Half e_type; /* file type */
Elf64_Half e_machine; /* target machine */
Elf64_Word e_version; /* file version */
Elf64_Addr e_entry; /* start address */
Elf64_Off e_phoff; /* phdr file offset */
Elf64_Off e_shoff; /* shdr file offset */
Elf64_Word e_flags; /* file flags */
Elf64_Half e_ehsize; /* sizeof ehdr */
Elf64_Half e_phentsize; /* sizeof phdr */
Elf64_Half e_phnum; /* number phdrs */
Elf64_Half e_shentsize; /* sizeof shdr */
Elf64_Half e_shnum; /* number shdrs */
Elf64_Half e_shstrndx; /* shdr string index */
} Elf64_Ehdr;
#define EI_MAG0 0 /* e_ident[] indexes */
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3
#define EI_CLASS 4
#define EI_DATA 5
#define EI_VERSION 6
#define EI_PAD 7
#define ELFMAG0 0x7f /* EI_MAG */
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define ELFMAG "\177ELF"
#define SELFMAG 4
#define ELFCLASSNONE 0 /* EI_CLASS */
#define ELFCLASS32 1
#define ELFCLASS64 2
#define ELFCLASSNUM 3
typedef struct {
Elf32_Word sh_name; /* section name */
Elf32_Word sh_type; /* SHT_... */
Elf32_Word sh_flags; /* SHF_... */
Elf32_Addr sh_addr; /* virtual address */
Elf32_Off sh_offset; /* file offset */
Elf32_Word sh_size; /* section size */
Elf32_Word sh_link; /* misc info */
Elf32_Word sh_info; /* misc info */
Elf32_Word sh_addralign; /* memory alignment */
Elf32_Word sh_entsize; /* entry size if table */
} Elf32_Shdr;
typedef struct {
Elf64_Word sh_name; /* section name */
Elf64_Word sh_type; /* SHT_... */
Elf64_Xword sh_flags; /* SHF_... */
Elf64_Addr sh_addr; /* virtual address */
Elf64_Off sh_offset; /* file offset */
Elf64_Xword sh_size; /* section size */
Elf64_Word sh_link; /* misc info */
Elf64_Word sh_info; /* misc info */
Elf64_Xword sh_addralign; /* memory alignment */
Elf64_Xword sh_entsize; /* entry size if table */
} Elf64_Shdr;
#define OMAGIC 0407
/* Taken from /usr/include/filehdr.h */
#define MIPSEBMAGIC 0x0160
#define MIPSEBMAGIC_2 0x0163
#define MIPSEBMAGIC_3 0x0140
#define IS_MIPSEBMAGIC(x) ((x) == MIPSEBMAGIC || (x) == MIPSEBMAGIC_2 || (x) == MIPSEBMAGIC_3)
#define ISCOFF(x) IS_MIPSEBMAGIC(x)
#define ELFMAG0 0x7f /* EI_MAG */
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define ELFMAG "\177ELF"
#define SELFMAG 4
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
#endif /* _FILE_FORMATS_H */