view src/gba/elf.h @ 24:59790d015f25 works-incomplete

checkpoint
author Robert McIntyre <rlm@mit.edu>
date Sun, 04 Mar 2012 17:50:56 -0600
parents f9f4f1b99eed
children
line wrap: on
line source
1 #ifndef VBA_ELF_H
2 #define VBA_ELF_H
4 #if _MSC_VER > 1000
5 #pragma once
6 #endif // _MSC_VER > 1000
8 enum LocationType
9 {
10 LOCATION_register,
11 LOCATION_memory,
12 LOCATION_value
13 };
15 #define DW_ATE_boolean 0x02
16 #define DW_ATE_signed 0x05
17 #define DW_ATE_unsigned 0x07
18 #define DW_ATE_unsigned_char 0x08
20 struct ELFHeader
21 {
22 u32 magic;
23 u8 clazz;
24 u8 data;
25 u8 version;
26 u8 pad[9];
27 u16 e_type;
28 u16 e_machine;
29 u32 e_version;
30 u32 e_entry;
31 u32 e_phoff;
32 u32 e_shoff;
33 u32 e_flags;
34 u16 e_ehsize;
35 u16 e_phentsize;
36 u16 e_phnum;
37 u16 e_shentsize;
38 u16 e_shnum;
39 u16 e_shstrndx;
40 };
42 struct ELFProgramHeader
43 {
44 u32 type;
45 u32 offset;
46 u32 vaddr;
47 u32 paddr;
48 u32 filesz;
49 u32 memsz;
50 u32 flags;
51 u32 align;
52 };
54 struct ELFSectionHeader
55 {
56 u32 name;
57 u32 type;
58 u32 flags;
59 u32 addr;
60 u32 offset;
61 u32 size;
62 u32 link;
63 u32 info;
64 u32 addralign;
65 u32 entsize;
66 };
68 struct ELFSymbol
69 {
70 u32 name;
71 u32 value;
72 u32 size;
73 u8 info;
74 u8 other;
75 u16 shndx;
76 };
78 struct ELFBlock
79 {
80 int length;
81 u8 *data;
82 };
84 struct ELFAttr
85 {
86 u32 name;
87 u32 form;
88 union
89 {
90 u32 value;
91 char * string;
92 u8 * data;
93 bool flag;
94 ELFBlock *block;
95 };
96 };
98 struct ELFAbbrev
99 {
100 u32 number;
101 u32 tag;
102 bool hasChildren;
103 int numAttrs;
104 ELFAttr * attrs;
105 ELFAbbrev *next;
106 };
108 enum TypeEnum
109 {
110 TYPE_base,
111 TYPE_pointer,
112 TYPE_function,
113 TYPE_void,
114 TYPE_array,
115 TYPE_struct,
116 TYPE_reference,
117 TYPE_enum,
118 TYPE_union
119 };
121 struct Type;
122 struct Object;
124 struct FunctionType
125 {
126 Type * returnType;
127 Object *args;
128 };
130 struct Member
131 {
132 char * name;
133 Type * type;
134 int bitSize;
135 int bitOffset;
136 int byteSize;
137 ELFBlock *location;
138 };
140 struct Struct
141 {
142 int memberCount;
143 Member *members;
144 };
146 struct Array
147 {
148 Type *type;
149 int maxBounds;
150 int * bounds;
151 };
153 struct EnumMember
154 {
155 char *name;
156 u32 value;
157 };
159 struct Enum
160 {
161 int count;
162 EnumMember *members;
163 };
165 struct Type
166 {
167 u32 offset;
168 TypeEnum type;
169 char * name;
170 int encoding;
171 int size;
172 int bitSize;
173 union
174 {
175 Type * pointer;
176 FunctionType *function;
177 Array * array;
178 Struct * structure;
179 Enum * enumeration;
180 };
181 Type *next;
182 };
184 struct Object
185 {
186 char * name;
187 int file;
188 int line;
189 bool external;
190 Type * type;
191 ELFBlock *location;
192 u32 startScope;
193 u32 endScope;
194 Object * next;
195 };
197 struct Function
198 {
199 char * name;
200 u32 lowPC;
201 u32 highPC;
202 int file;
203 int line;
204 bool external;
205 Type * returnType;
206 Object * parameters;
207 Object * variables;
208 ELFBlock *frameBase;
209 Function *next;
210 };
212 struct LineInfoItem
213 {
214 u32 address;
215 char *file;
216 int line;
217 };
219 struct LineInfo
220 {
221 int fileCount;
222 char ** files;
223 int number;
224 LineInfoItem *lines;
225 };
227 struct ARange
228 {
229 u32 lowPC;
230 u32 highPC;
231 };
233 struct ARanges
234 {
235 u32 offset;
236 int count;
237 ARange *ranges;
238 };
240 struct CompileUnit
241 {
242 u32 length;
243 u8 * top;
244 u32 offset;
245 ELFAbbrev ** abbrevs;
246 ARanges * ranges;
247 char * name;
248 char * compdir;
249 u32 lowPC;
250 u32 highPC;
251 bool hasLineInfo;
252 u32 lineInfo;
253 LineInfo * lineInfoTable;
254 Function * functions;
255 Function * lastFunction;
256 Object * variables;
257 Type * types;
258 CompileUnit *next;
259 };
261 struct DebugInfo
262 {
263 u8 * debugfile;
264 u8 * abbrevdata;
265 u8 * debugdata;
266 u8 * infodata;
267 int numRanges;
268 ARanges *ranges;
269 };
271 struct Symbol
272 {
273 char *name;
274 int type;
275 int binding;
276 u32 address;
277 u32 value;
278 u32 size;
279 };
281 extern u32 elfReadLEB128(u8 *, int *);
282 extern s32 elfReadSignedLEB128(u8 *, int *);
283 extern bool elfRead(const char *, int &, FILE *f);
284 extern bool elfGetSymbolAddress(char *, u32 *, u32 *, int *);
285 extern char *elfGetAddressSymbol(u32);
286 extern char *elfGetSymbol(int, u32 *, u32 *, int *);
287 extern void elfCleanUp();
288 extern bool elfGetCurrentFunction(u32, Function **, CompileUnit **c);
289 extern bool elfGetObject(char *, Function *, CompileUnit *, Object * *);
290 extern bool elfFindLineInUnit(u32 *, CompileUnit *, int);
291 extern bool elfFindLineInModule(u32 *, char *, int);
292 u32 elfDecodeLocation(Function *, ELFBlock *, LocationType *);
293 u32 elfDecodeLocation(Function *, ELFBlock *, LocationType *, u32);
294 int elfFindLine(CompileUnit *unit, Function *func, u32 addr, char * *);
296 #endif // VBA_ELF_H