annotate src/gba/elf.h @ 268:82ee2704c973

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