Mercurial > vba-linux
diff src/gba/elf.h @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/gba/elf.h Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,296 @@ 1.4 +#ifndef VBA_ELF_H 1.5 +#define VBA_ELF_H 1.6 + 1.7 +#if _MSC_VER > 1000 1.8 +#pragma once 1.9 +#endif // _MSC_VER > 1000 1.10 + 1.11 +enum LocationType 1.12 +{ 1.13 + LOCATION_register, 1.14 + LOCATION_memory, 1.15 + LOCATION_value 1.16 +}; 1.17 + 1.18 +#define DW_ATE_boolean 0x02 1.19 +#define DW_ATE_signed 0x05 1.20 +#define DW_ATE_unsigned 0x07 1.21 +#define DW_ATE_unsigned_char 0x08 1.22 + 1.23 +struct ELFHeader 1.24 +{ 1.25 + u32 magic; 1.26 + u8 clazz; 1.27 + u8 data; 1.28 + u8 version; 1.29 + u8 pad[9]; 1.30 + u16 e_type; 1.31 + u16 e_machine; 1.32 + u32 e_version; 1.33 + u32 e_entry; 1.34 + u32 e_phoff; 1.35 + u32 e_shoff; 1.36 + u32 e_flags; 1.37 + u16 e_ehsize; 1.38 + u16 e_phentsize; 1.39 + u16 e_phnum; 1.40 + u16 e_shentsize; 1.41 + u16 e_shnum; 1.42 + u16 e_shstrndx; 1.43 +}; 1.44 + 1.45 +struct ELFProgramHeader 1.46 +{ 1.47 + u32 type; 1.48 + u32 offset; 1.49 + u32 vaddr; 1.50 + u32 paddr; 1.51 + u32 filesz; 1.52 + u32 memsz; 1.53 + u32 flags; 1.54 + u32 align; 1.55 +}; 1.56 + 1.57 +struct ELFSectionHeader 1.58 +{ 1.59 + u32 name; 1.60 + u32 type; 1.61 + u32 flags; 1.62 + u32 addr; 1.63 + u32 offset; 1.64 + u32 size; 1.65 + u32 link; 1.66 + u32 info; 1.67 + u32 addralign; 1.68 + u32 entsize; 1.69 +}; 1.70 + 1.71 +struct ELFSymbol 1.72 +{ 1.73 + u32 name; 1.74 + u32 value; 1.75 + u32 size; 1.76 + u8 info; 1.77 + u8 other; 1.78 + u16 shndx; 1.79 +}; 1.80 + 1.81 +struct ELFBlock 1.82 +{ 1.83 + int length; 1.84 + u8 *data; 1.85 +}; 1.86 + 1.87 +struct ELFAttr 1.88 +{ 1.89 + u32 name; 1.90 + u32 form; 1.91 + union 1.92 + { 1.93 + u32 value; 1.94 + char * string; 1.95 + u8 * data; 1.96 + bool flag; 1.97 + ELFBlock *block; 1.98 + }; 1.99 +}; 1.100 + 1.101 +struct ELFAbbrev 1.102 +{ 1.103 + u32 number; 1.104 + u32 tag; 1.105 + bool hasChildren; 1.106 + int numAttrs; 1.107 + ELFAttr * attrs; 1.108 + ELFAbbrev *next; 1.109 +}; 1.110 + 1.111 +enum TypeEnum 1.112 +{ 1.113 + TYPE_base, 1.114 + TYPE_pointer, 1.115 + TYPE_function, 1.116 + TYPE_void, 1.117 + TYPE_array, 1.118 + TYPE_struct, 1.119 + TYPE_reference, 1.120 + TYPE_enum, 1.121 + TYPE_union 1.122 +}; 1.123 + 1.124 +struct Type; 1.125 +struct Object; 1.126 + 1.127 +struct FunctionType 1.128 +{ 1.129 + Type * returnType; 1.130 + Object *args; 1.131 +}; 1.132 + 1.133 +struct Member 1.134 +{ 1.135 + char * name; 1.136 + Type * type; 1.137 + int bitSize; 1.138 + int bitOffset; 1.139 + int byteSize; 1.140 + ELFBlock *location; 1.141 +}; 1.142 + 1.143 +struct Struct 1.144 +{ 1.145 + int memberCount; 1.146 + Member *members; 1.147 +}; 1.148 + 1.149 +struct Array 1.150 +{ 1.151 + Type *type; 1.152 + int maxBounds; 1.153 + int * bounds; 1.154 +}; 1.155 + 1.156 +struct EnumMember 1.157 +{ 1.158 + char *name; 1.159 + u32 value; 1.160 +}; 1.161 + 1.162 +struct Enum 1.163 +{ 1.164 + int count; 1.165 + EnumMember *members; 1.166 +}; 1.167 + 1.168 +struct Type 1.169 +{ 1.170 + u32 offset; 1.171 + TypeEnum type; 1.172 + char * name; 1.173 + int encoding; 1.174 + int size; 1.175 + int bitSize; 1.176 + union 1.177 + { 1.178 + Type * pointer; 1.179 + FunctionType *function; 1.180 + Array * array; 1.181 + Struct * structure; 1.182 + Enum * enumeration; 1.183 + }; 1.184 + Type *next; 1.185 +}; 1.186 + 1.187 +struct Object 1.188 +{ 1.189 + char * name; 1.190 + int file; 1.191 + int line; 1.192 + bool external; 1.193 + Type * type; 1.194 + ELFBlock *location; 1.195 + u32 startScope; 1.196 + u32 endScope; 1.197 + Object * next; 1.198 +}; 1.199 + 1.200 +struct Function 1.201 +{ 1.202 + char * name; 1.203 + u32 lowPC; 1.204 + u32 highPC; 1.205 + int file; 1.206 + int line; 1.207 + bool external; 1.208 + Type * returnType; 1.209 + Object * parameters; 1.210 + Object * variables; 1.211 + ELFBlock *frameBase; 1.212 + Function *next; 1.213 +}; 1.214 + 1.215 +struct LineInfoItem 1.216 +{ 1.217 + u32 address; 1.218 + char *file; 1.219 + int line; 1.220 +}; 1.221 + 1.222 +struct LineInfo 1.223 +{ 1.224 + int fileCount; 1.225 + char ** files; 1.226 + int number; 1.227 + LineInfoItem *lines; 1.228 +}; 1.229 + 1.230 +struct ARange 1.231 +{ 1.232 + u32 lowPC; 1.233 + u32 highPC; 1.234 +}; 1.235 + 1.236 +struct ARanges 1.237 +{ 1.238 + u32 offset; 1.239 + int count; 1.240 + ARange *ranges; 1.241 +}; 1.242 + 1.243 +struct CompileUnit 1.244 +{ 1.245 + u32 length; 1.246 + u8 * top; 1.247 + u32 offset; 1.248 + ELFAbbrev ** abbrevs; 1.249 + ARanges * ranges; 1.250 + char * name; 1.251 + char * compdir; 1.252 + u32 lowPC; 1.253 + u32 highPC; 1.254 + bool hasLineInfo; 1.255 + u32 lineInfo; 1.256 + LineInfo * lineInfoTable; 1.257 + Function * functions; 1.258 + Function * lastFunction; 1.259 + Object * variables; 1.260 + Type * types; 1.261 + CompileUnit *next; 1.262 +}; 1.263 + 1.264 +struct DebugInfo 1.265 +{ 1.266 + u8 * debugfile; 1.267 + u8 * abbrevdata; 1.268 + u8 * debugdata; 1.269 + u8 * infodata; 1.270 + int numRanges; 1.271 + ARanges *ranges; 1.272 +}; 1.273 + 1.274 +struct Symbol 1.275 +{ 1.276 + char *name; 1.277 + int type; 1.278 + int binding; 1.279 + u32 address; 1.280 + u32 value; 1.281 + u32 size; 1.282 +}; 1.283 + 1.284 +extern u32 elfReadLEB128(u8 *, int *); 1.285 +extern s32 elfReadSignedLEB128(u8 *, int *); 1.286 +extern bool elfRead(const char *, int &, FILE *f); 1.287 +extern bool elfGetSymbolAddress(char *, u32 *, u32 *, int *); 1.288 +extern char *elfGetAddressSymbol(u32); 1.289 +extern char *elfGetSymbol(int, u32 *, u32 *, int *); 1.290 +extern void elfCleanUp(); 1.291 +extern bool elfGetCurrentFunction(u32, Function **, CompileUnit **c); 1.292 +extern bool elfGetObject(char *, Function *, CompileUnit *, Object * *); 1.293 +extern bool elfFindLineInUnit(u32 *, CompileUnit *, int); 1.294 +extern bool elfFindLineInModule(u32 *, char *, int); 1.295 +u32 elfDecodeLocation(Function *, ELFBlock *, LocationType *); 1.296 +u32 elfDecodeLocation(Function *, ELFBlock *, LocationType *, u32); 1.297 +int elfFindLine(CompileUnit *unit, Function *func, u32 addr, char * *); 1.298 + 1.299 +#endif // VBA_ELF_H