update build instructions
[rofl0r-VisualBoyAdvance.git] / src / elf.h
blobd92a7b5cffe677dd3d4d81b528c6ecd58a27f65a
1 // -*- C++ -*-
2 // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
3 // Copyright (C) 1999-2003 Forgotten
4 // Copyright (C) 2004 Forgotten and the VBA development team
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or(at your option)
9 // any later version.
11 // This program 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
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef VBA_ELF_H
21 #define VBA_ELF_H
23 #include "System.h"
24 #include <stdio.h>
26 typedef enum LocationType {
27 LOCATION_register,
28 LOCATION_memory,
29 LOCATION_value
30 } LocationType;
32 #define DW_ATE_boolean 0x02
33 #define DW_ATE_signed 0x05
34 #define DW_ATE_unsigned 0x07
35 #define DW_ATE_unsigned_char 0x08
37 typedef struct ELFHeader {
38 u32 magic;
39 u8 clazz;
40 u8 data;
41 u8 version;
42 u8 pad[9];
43 u16 e_type;
44 u16 e_machine;
45 u32 e_version;
46 u32 e_entry;
47 u32 e_phoff;
48 u32 e_shoff;
49 u32 e_flags;
50 u16 e_ehsize;
51 u16 e_phentsize;
52 u16 e_phnum;
53 u16 e_shentsize;
54 u16 e_shnum;
55 u16 e_shstrndx;
56 } ELFHeader;
58 typedef struct ELFProgramHeader {
59 u32 type;
60 u32 offset;
61 u32 vaddr;
62 u32 paddr;
63 u32 filesz;
64 u32 memsz;
65 u32 flags;
66 u32 align;
67 } ELFProgramHeader;
69 typedef struct ELFSectionHeader {
70 u32 name;
71 u32 type;
72 u32 flags;
73 u32 addr;
74 u32 offset;
75 u32 size;
76 u32 link;
77 u32 info;
78 u32 addralign;
79 u32 entsize;
80 } ELFSectionHeader;
82 typedef struct ELFSymbol {
83 u32 name;
84 u32 value;
85 u32 size;
86 u8 info;
87 u8 other;
88 u16 shndx;
89 } ELFSymbol;
91 typedef struct ELFBlock {
92 int length;
93 u8 *data;
94 } ELFBlock;
96 typedef struct ELFAttr {
97 u32 name;
98 u32 form;
99 union {
100 u32 value;
101 char *string;
102 u8 *data;
103 bool flag;
104 ELFBlock *block;
106 } ELFAttr;
108 typedef struct ELFAbbrev {
109 u32 number;
110 u32 tag;
111 bool hasChildren;
112 int numAttrs;
113 struct ELFAttr *attrs;
114 struct ELFAbbrev *next;
115 } ELFAbbrev;
117 typedef enum TypeEnum {
118 TYPE_base,
119 TYPE_pointer,
120 TYPE_function,
121 TYPE_void,
122 TYPE_array,
123 TYPE_struct,
124 TYPE_reference,
125 TYPE_enum,
126 TYPE_union
127 } TypeEnum;
129 struct Type;
130 struct Object;
132 typedef struct FunctionType {
133 struct Type *returnType;
134 struct Object *args;
135 } FunctionType;
137 typedef struct Member {
138 char *name;
139 struct Type *type;
140 int bitSize;
141 int bitOffset;
142 int byteSize;
143 ELFBlock *location;
144 } Member;
146 typedef struct Struct {
147 int memberCount;
148 Member *members;
149 } Struct;
151 typedef struct Array {
152 struct Type *type;
153 int maxBounds;
154 int *bounds;
155 } Array;
157 typedef struct EnumMember {
158 char *name;
159 u32 value;
160 } EnumMember;
162 typedef struct Enum {
163 int count;
164 EnumMember *members;
165 } Enum;
167 typedef struct Type {
168 u32 offset;
169 TypeEnum type;
170 char *name;
171 int encoding;
172 int size;
173 int bitSize;
174 union {
175 struct Type *pointer;
176 FunctionType *function;
177 Array *array;
178 Struct *structure;
179 Enum *enumeration;
181 struct Type *next;
182 } Type;
184 typedef struct Object {
185 char *name;
186 int file;
187 int line;
188 bool external;
189 Type *type;
190 ELFBlock *location;
191 u32 startScope;
192 u32 endScope;
193 struct Object *next;
194 } Object;
196 typedef struct Function {
197 char *name;
198 u32 lowPC;
199 u32 highPC;
200 int file;
201 int line;
202 bool external;
203 Type *returnType;
204 Object *parameters;
205 Object *variables;
206 ELFBlock *frameBase;
207 struct Function *next;
208 } Function;
210 typedef struct LineInfoItem {
211 u32 address;
212 char *file;
213 int line;
214 } LineInfoItem;
216 typedef struct LineInfo {
217 int fileCount;
218 char **files;
219 int number;
220 LineInfoItem *lines;
221 } LineInfo;
223 typedef struct ARange {
224 u32 lowPC;
225 u32 highPC;
226 } ARange;
228 typedef struct ARanges {
229 u32 offset;
230 int count;
231 ARange *ranges;
232 } ARanges;
234 typedef struct CompileUnit {
235 u32 length;
236 u8 *top;
237 u32 offset;
238 ELFAbbrev **abbrevs;
239 ARanges *ranges;
240 char *name;
241 char *compdir;
242 u32 lowPC;
243 u32 highPC;
244 bool hasLineInfo;
245 u32 lineInfo;
246 LineInfo *lineInfoTable;
247 Function *functions;
248 Function *lastFunction;
249 Object *variables;
250 Type *types;
251 struct CompileUnit *next;
252 } CompileUnit;
254 typedef struct DebugInfo {
255 u8 *debugfile;
256 u8 *abbrevdata;
257 u8 *debugdata;
258 u8 *infodata;
259 int numRanges;
260 ARanges *ranges;
261 } DebugInfo;
263 typedef struct Symbol {
264 char *name;
265 int type;
266 int binding;
267 u32 address;
268 u32 value;
269 u32 size;
270 } Symbol;
272 extern u32 elfReadLEB128(u8 *, int *);
273 extern s32 elfReadSignedLEB128(u8 *, int *);
274 extern bool elfRead(const char *, int*, FILE *f);
275 extern bool elfGetSymbolAddress(char *,u32 *, u32 *, int *);
276 extern char *elfGetAddressSymbol(u32);
277 extern char *elfGetSymbol(int, u32 *, u32 *, int *);
278 extern void elfCleanUp(void);
279 extern bool elfGetCurrentFunction(u32, Function **, CompileUnit **c);
280 extern bool elfGetObject(char *, Function *, CompileUnit *, Object **);
281 extern bool elfFindLineInUnit(u32 *, CompileUnit *, int);
282 extern bool elfFindLineInModule(u32 *, char *, int);
283 u32 elfDecodeLocation(Function *, ELFBlock *, LocationType *);
284 u32 elfDecodeLocation4(Function *, ELFBlock *, LocationType *, u32);
285 int elfFindLine(CompileUnit *unit, Function *func, u32 addr, char **);
286 #endif