I could go on, but really this is just more typedef removal
This commit is contained in:
parent
5f73631f84
commit
79820311d3
|
@ -127,11 +127,11 @@ void flashSetSize(int size)
|
||||||
// Added to make 64k saves compatible with 128k ones
|
// Added to make 64k saves compatible with 128k ones
|
||||||
// (allow wrongfuly set 64k saves to work for Pokemon games)
|
// (allow wrongfuly set 64k saves to work for Pokemon games)
|
||||||
if ((size == 0x20000) && (flashSize == 0x10000))
|
if ((size == 0x20000) && (flashSize == 0x10000))
|
||||||
memcpy((u8*)(flashSaveMemory + 0x10000), (u8*)(flashSaveMemory), 0x10000);
|
memcpy((uint8_t*)(flashSaveMemory + 0x10000), (uint8_t*)(flashSaveMemory), 0x10000);
|
||||||
flashSize = size;
|
flashSize = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 flashRead(u32 address)
|
uint8_t flashRead(uint32_t address)
|
||||||
{
|
{
|
||||||
// log("Reading %08x from %08x\n", address, reg[15].I);
|
// log("Reading %08x from %08x\n", address, reg[15].I);
|
||||||
// log("Current read state is %d\n", flashReadState);
|
// log("Current read state is %d\n", flashReadState);
|
||||||
|
@ -158,7 +158,7 @@ u8 flashRead(u32 address)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void flashSaveDecide(u32 address, u8 byte)
|
void flashSaveDecide(uint32_t address, uint8_t byte)
|
||||||
{
|
{
|
||||||
if (saveType == 1)
|
if (saveType == 1)
|
||||||
return;
|
return;
|
||||||
|
@ -175,14 +175,14 @@ void flashSaveDecide(u32 address, u8 byte)
|
||||||
(*cpuSaveGameFunc)(address, byte);
|
(*cpuSaveGameFunc)(address, byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
void flashDelayedWrite(u32 address, u8 byte)
|
void flashDelayedWrite(uint32_t address, uint8_t byte)
|
||||||
{
|
{
|
||||||
saveType = 3;
|
saveType = 3;
|
||||||
cpuSaveGameFunc = flashWrite;
|
cpuSaveGameFunc = flashWrite;
|
||||||
flashWrite(address, byte);
|
flashWrite(address, byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
void flashWrite(u32 address, u8 byte)
|
void flashWrite(uint32_t address, uint8_t byte)
|
||||||
{
|
{
|
||||||
// log("Writing %02x at %08x\n", byte, address);
|
// log("Writing %02x at %08x\n", byte, address);
|
||||||
// log("Current state is %d\n", flashState);
|
// log("Current state is %d\n", flashState);
|
||||||
|
|
|
@ -4,22 +4,22 @@
|
||||||
#define FLASH_128K_SZ 0x20000
|
#define FLASH_128K_SZ 0x20000
|
||||||
|
|
||||||
#ifdef __LIBRETRO__
|
#ifdef __LIBRETRO__
|
||||||
extern void flashSaveGame(u8*& data);
|
extern void flashSaveGame(uint8_t*& data);
|
||||||
extern void flashReadGame(const u8*& data, int);
|
extern void flashReadGame(const uint8_t*& data, int);
|
||||||
#else
|
#else
|
||||||
extern void flashSaveGame(gzFile _gzFile);
|
extern void flashSaveGame(gzFile _gzFile);
|
||||||
extern void flashReadGame(gzFile _gzFile, int version);
|
extern void flashReadGame(gzFile _gzFile, int version);
|
||||||
extern void flashReadGameSkip(gzFile _gzFile, int version);
|
extern void flashReadGameSkip(gzFile _gzFile, int version);
|
||||||
#endif
|
#endif
|
||||||
extern u8 flashRead(u32 address);
|
extern uint8_t flashRead(uint32_t address);
|
||||||
extern void flashWrite(u32 address, u8 byte);
|
extern void flashWrite(uint32_t address, uint8_t byte);
|
||||||
extern void flashDelayedWrite(u32 address, u8 byte);
|
extern void flashDelayedWrite(uint32_t address, uint8_t byte);
|
||||||
#ifdef __LIBRETRO__
|
#ifdef __LIBRETRO__
|
||||||
extern uint8_t* flashSaveMemory;
|
extern uint8_t* flashSaveMemory;
|
||||||
#else
|
#else
|
||||||
extern u8 flashSaveMemory[FLASH_128K_SZ];
|
extern uint8_t flashSaveMemory[FLASH_128K_SZ];
|
||||||
#endif
|
#endif
|
||||||
extern void flashSaveDecide(u32 address, u8 byte);
|
extern void flashSaveDecide(uint32_t address, uint8_t byte);
|
||||||
extern void flashReset();
|
extern void flashReset();
|
||||||
extern void flashSetSize(int size);
|
extern void flashSetSize(int size);
|
||||||
extern void flashInit();
|
extern void flashInit();
|
||||||
|
|
524
src/gba/GBA.cpp
524
src/gba/GBA.cpp
File diff suppressed because it is too large
Load Diff
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "../System.h"
|
#include "../System.h"
|
||||||
|
|
||||||
const u64 TICKS_PER_SECOND = 16777216;
|
const uint64_t TICKS_PER_SECOND = 16777216;
|
||||||
|
|
||||||
#define SAVE_GAME_VERSION_1 1
|
#define SAVE_GAME_VERSION_1 1
|
||||||
#define SAVE_GAME_VERSION_2 2
|
#define SAVE_GAME_VERSION_2 2
|
||||||
|
@ -18,43 +18,43 @@ const u64 TICKS_PER_SECOND = 16777216;
|
||||||
#define SAVE_GAME_VERSION SAVE_GAME_VERSION_10
|
#define SAVE_GAME_VERSION SAVE_GAME_VERSION_10
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u8* address;
|
uint8_t* address;
|
||||||
u32 mask;
|
uint32_t mask;
|
||||||
#ifdef BKPT_SUPPORT
|
#ifdef BKPT_SUPPORT
|
||||||
u8* breakPoints;
|
uint8_t* breakPoints;
|
||||||
u8* searchMatch;
|
uint8_t* searchMatch;
|
||||||
u8* trace;
|
uint8_t* trace;
|
||||||
u32 size;
|
uint32_t size;
|
||||||
#endif
|
#endif
|
||||||
} memoryMap;
|
} memoryMap;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
struct {
|
struct {
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
u8 B3;
|
uint8_t B3;
|
||||||
u8 B2;
|
uint8_t B2;
|
||||||
u8 B1;
|
uint8_t B1;
|
||||||
u8 B0;
|
uint8_t B0;
|
||||||
#else
|
#else
|
||||||
u8 B0;
|
uint8_t B0;
|
||||||
u8 B1;
|
uint8_t B1;
|
||||||
u8 B2;
|
uint8_t B2;
|
||||||
u8 B3;
|
uint8_t B3;
|
||||||
#endif
|
#endif
|
||||||
} B;
|
} B;
|
||||||
struct {
|
struct {
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
u16 W1;
|
uint16_t W1;
|
||||||
u16 W0;
|
uint16_t W0;
|
||||||
#else
|
#else
|
||||||
u16 W0;
|
uint16_t W0;
|
||||||
u16 W1;
|
uint16_t W1;
|
||||||
#endif
|
#endif
|
||||||
} W;
|
} W;
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
volatile u32 I;
|
volatile uint32_t I;
|
||||||
#else
|
#else
|
||||||
u32 I;
|
uint32_t I;
|
||||||
#endif
|
#endif
|
||||||
} reg_pair;
|
} reg_pair;
|
||||||
|
|
||||||
|
@ -62,16 +62,16 @@ typedef union {
|
||||||
extern memoryMap map[256];
|
extern memoryMap map[256];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern u8 biosProtected[4];
|
extern uint8_t biosProtected[4];
|
||||||
|
|
||||||
extern void (*cpuSaveGameFunc)(u32, u8);
|
extern void (*cpuSaveGameFunc)(uint32_t, uint8_t);
|
||||||
|
|
||||||
#ifdef BKPT_SUPPORT
|
#ifdef BKPT_SUPPORT
|
||||||
extern u8 freezeWorkRAM[0x40000];
|
extern uint8_t freezeWorkRAM[0x40000];
|
||||||
extern u8 freezeInternalRAM[0x8000];
|
extern uint8_t freezeInternalRAM[0x8000];
|
||||||
extern u8 freezeVRAM[0x18000];
|
extern uint8_t freezeVRAM[0x18000];
|
||||||
extern u8 freezeOAM[0x400];
|
extern uint8_t freezeOAM[0x400];
|
||||||
extern u8 freezePRAM[0x400];
|
extern uint8_t freezePRAM[0x400];
|
||||||
extern bool debugger_last;
|
extern bool debugger_last;
|
||||||
extern int oldreg[18];
|
extern int oldreg[18];
|
||||||
extern char oldbuffer[10];
|
extern char oldbuffer[10];
|
||||||
|
@ -93,8 +93,8 @@ extern void CPUUpdateRenderBuffers(bool);
|
||||||
extern bool CPUReadMemState(char*, int);
|
extern bool CPUReadMemState(char*, int);
|
||||||
extern bool CPUWriteMemState(char*, int);
|
extern bool CPUWriteMemState(char*, int);
|
||||||
#ifdef __LIBRETRO__
|
#ifdef __LIBRETRO__
|
||||||
extern bool CPUReadState(const u8*, unsigned);
|
extern bool CPUReadState(const uint8_t*, unsigned);
|
||||||
extern unsigned int CPUWriteState(u8* data, unsigned int size);
|
extern unsigned int CPUWriteState(uint8_t* data, unsigned int size);
|
||||||
#else
|
#else
|
||||||
extern bool CPUReadState(const char*);
|
extern bool CPUReadState(const char*);
|
||||||
extern bool CPUWriteState(const char*);
|
extern bool CPUWriteState(const char*);
|
||||||
|
@ -102,7 +102,7 @@ extern bool CPUWriteState(const char*);
|
||||||
extern int CPULoadRom(const char*);
|
extern int CPULoadRom(const char*);
|
||||||
extern int CPULoadRomData(const char* data, int size);
|
extern int CPULoadRomData(const char* data, int size);
|
||||||
extern void doMirroring(bool);
|
extern void doMirroring(bool);
|
||||||
extern void CPUUpdateRegister(u32, u16);
|
extern void CPUUpdateRegister(uint32_t, uint16_t);
|
||||||
extern void applyTimer();
|
extern void applyTimer();
|
||||||
extern void CPUInit(const char*, bool);
|
extern void CPUInit(const char*, bool);
|
||||||
void SetSaveType(int st);
|
void SetSaveType(int st);
|
||||||
|
|
284
src/gba/elf.cpp
284
src/gba/elf.cpp
|
@ -162,21 +162,21 @@
|
||||||
|
|
||||||
struct ELFcie {
|
struct ELFcie {
|
||||||
ELFcie* next;
|
ELFcie* next;
|
||||||
u32 offset;
|
uint32_t offset;
|
||||||
u8* augmentation;
|
uint8_t* augmentation;
|
||||||
u32 codeAlign;
|
uint32_t codeAlign;
|
||||||
s32 dataAlign;
|
int32_t dataAlign;
|
||||||
int returnAddress;
|
int returnAddress;
|
||||||
u8* data;
|
uint8_t* data;
|
||||||
u32 dataLen;
|
uint32_t dataLen;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ELFfde {
|
struct ELFfde {
|
||||||
ELFcie* cie;
|
ELFcie* cie;
|
||||||
u32 address;
|
uint32_t address;
|
||||||
u32 end;
|
uint32_t end;
|
||||||
u8* data;
|
uint8_t* data;
|
||||||
u32 dataLen;
|
uint32_t dataLen;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ELFRegMode {
|
enum ELFRegMode {
|
||||||
|
@ -188,7 +188,7 @@ enum ELFRegMode {
|
||||||
struct ELFFrameStateRegister {
|
struct ELFFrameStateRegister {
|
||||||
ELFRegMode mode;
|
ELFRegMode mode;
|
||||||
int reg;
|
int reg;
|
||||||
s32 offset;
|
int32_t offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ELFFrameStateRegisters {
|
struct ELFFrameStateRegisters {
|
||||||
|
@ -206,9 +206,9 @@ struct ELFFrameState {
|
||||||
|
|
||||||
ELFCfaMode cfaMode;
|
ELFCfaMode cfaMode;
|
||||||
int cfaRegister;
|
int cfaRegister;
|
||||||
s32 cfaOffset;
|
int32_t cfaOffset;
|
||||||
|
|
||||||
u32 pc;
|
uint32_t pc;
|
||||||
|
|
||||||
int dataAlign;
|
int dataAlign;
|
||||||
int codeAlign;
|
int codeAlign;
|
||||||
|
@ -224,7 +224,7 @@ int elfSymbolsCount = 0;
|
||||||
ELFSectionHeader** elfSectionHeaders = NULL;
|
ELFSectionHeader** elfSectionHeaders = NULL;
|
||||||
char* elfSectionHeadersStringTable = NULL;
|
char* elfSectionHeadersStringTable = NULL;
|
||||||
int elfSectionHeadersCount = 0;
|
int elfSectionHeadersCount = 0;
|
||||||
u8* elfFileData = NULL;
|
uint8_t* elfFileData = NULL;
|
||||||
|
|
||||||
CompileUnit* elfCompileUnits = NULL;
|
CompileUnit* elfCompileUnits = NULL;
|
||||||
DebugInfo* elfDebugInfo = NULL;
|
DebugInfo* elfDebugInfo = NULL;
|
||||||
|
@ -236,10 +236,10 @@ int elfFdeCount = 0;
|
||||||
|
|
||||||
CompileUnit* elfCurrentUnit = NULL;
|
CompileUnit* elfCurrentUnit = NULL;
|
||||||
|
|
||||||
u32 elfRead4Bytes(u8*);
|
uint32_t elfRead4Bytes(uint8_t*);
|
||||||
u16 elfRead2Bytes(u8*);
|
uint16_t elfRead2Bytes(uint8_t*);
|
||||||
|
|
||||||
CompileUnit* elfGetCompileUnit(u32 addr)
|
CompileUnit* elfGetCompileUnit(uint32_t addr)
|
||||||
{
|
{
|
||||||
if (elfCompileUnits) {
|
if (elfCompileUnits) {
|
||||||
CompileUnit* unit = elfCompileUnits;
|
CompileUnit* unit = elfCompileUnits;
|
||||||
|
@ -263,7 +263,7 @@ CompileUnit* elfGetCompileUnit(u32 addr)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* elfGetAddressSymbol(u32 addr)
|
const char* elfGetAddressSymbol(uint32_t addr)
|
||||||
{
|
{
|
||||||
static char buffer[256];
|
static char buffer[256];
|
||||||
|
|
||||||
|
@ -313,7 +313,7 @@ const char* elfGetAddressSymbol(u32 addr)
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool elfFindLineInModule(u32* addr, const char* name, int line)
|
bool elfFindLineInModule(uint32_t* addr, const char* name, int line)
|
||||||
{
|
{
|
||||||
CompileUnit* unit = elfCompileUnits;
|
CompileUnit* unit = elfCompileUnits;
|
||||||
|
|
||||||
|
@ -347,7 +347,7 @@ bool elfFindLineInModule(u32* addr, const char* name, int line)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int elfFindLine(CompileUnit* unit, Function* /* func */, u32 addr, const char** f)
|
int elfFindLine(CompileUnit* unit, Function* /* func */, uint32_t addr, const char** f)
|
||||||
{
|
{
|
||||||
int currentLine = -1;
|
int currentLine = -1;
|
||||||
if (unit->hasLineInfo) {
|
if (unit->hasLineInfo) {
|
||||||
|
@ -366,7 +366,7 @@ int elfFindLine(CompileUnit* unit, Function* /* func */, u32 addr, const char**
|
||||||
return currentLine;
|
return currentLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool elfFindLineInUnit(u32* addr, CompileUnit* unit, int line)
|
bool elfFindLineInUnit(uint32_t* addr, CompileUnit* unit, int line)
|
||||||
{
|
{
|
||||||
if (unit->hasLineInfo) {
|
if (unit->hasLineInfo) {
|
||||||
int count = unit->lineInfoTable->number;
|
int count = unit->lineInfoTable->number;
|
||||||
|
@ -382,7 +382,7 @@ bool elfFindLineInUnit(u32* addr, CompileUnit* unit, int line)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool elfGetCurrentFunction(u32 addr, Function** f, CompileUnit** u)
|
bool elfGetCurrentFunction(uint32_t addr, Function** f, CompileUnit** u)
|
||||||
{
|
{
|
||||||
CompileUnit* unit = elfGetCompileUnit(addr);
|
CompileUnit* unit = elfGetCompileUnit(addr);
|
||||||
// found unit, need to find function
|
// found unit, need to find function
|
||||||
|
@ -449,7 +449,7 @@ bool elfGetObject(const char* name, Function* f, CompileUnit* u, Object** o)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* elfGetSymbol(int i, u32* value, u32* size, int* type)
|
const char* elfGetSymbol(int i, uint32_t* value, uint32_t* size, int* type)
|
||||||
{
|
{
|
||||||
if (i < elfSymbolsCount) {
|
if (i < elfSymbolsCount) {
|
||||||
Symbol* s = &elfSymbols[i];
|
Symbol* s = &elfSymbols[i];
|
||||||
|
@ -461,7 +461,7 @@ const char* elfGetSymbol(int i, u32* value, u32* size, int* type)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool elfGetSymbolAddress(const char* sym, u32* addr, u32* size, int* type)
|
bool elfGetSymbolAddress(const char* sym, uint32_t* addr, uint32_t* size, int* type)
|
||||||
{
|
{
|
||||||
if (elfSymbolsCount) {
|
if (elfSymbolsCount) {
|
||||||
for (int i = 0; i < elfSymbolsCount; i++) {
|
for (int i = 0; i < elfSymbolsCount; i++) {
|
||||||
|
@ -477,7 +477,7 @@ bool elfGetSymbolAddress(const char* sym, u32* addr, u32* size, int* type)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ELFfde* elfGetFde(u32 address)
|
ELFfde* elfGetFde(uint32_t address)
|
||||||
{
|
{
|
||||||
if (elfFdes) {
|
if (elfFdes) {
|
||||||
int i;
|
int i;
|
||||||
|
@ -491,16 +491,16 @@ ELFfde* elfGetFde(u32 address)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void elfExecuteCFAInstructions(ELFFrameState* state, u8* data, u32 len,
|
void elfExecuteCFAInstructions(ELFFrameState* state, uint8_t* data, uint32_t len,
|
||||||
u32 pc)
|
uint32_t pc)
|
||||||
{
|
{
|
||||||
u8* end = data + len;
|
uint8_t* end = data + len;
|
||||||
int bytes;
|
int bytes;
|
||||||
int reg;
|
int reg;
|
||||||
ELFFrameStateRegisters* fs;
|
ELFFrameStateRegisters* fs;
|
||||||
|
|
||||||
while (data < end && state->pc < pc) {
|
while (data < end && state->pc < pc) {
|
||||||
u8 op = *data++;
|
uint8_t op = *data++;
|
||||||
|
|
||||||
switch (op >> 6) {
|
switch (op >> 6) {
|
||||||
case DW_CFA_advance_loc:
|
case DW_CFA_advance_loc:
|
||||||
|
@ -509,7 +509,7 @@ void elfExecuteCFAInstructions(ELFFrameState* state, u8* data, u32 len,
|
||||||
case DW_CFA_offset:
|
case DW_CFA_offset:
|
||||||
reg = op & 0x3f;
|
reg = op & 0x3f;
|
||||||
state->registers.regs[reg].mode = REG_OFFSET;
|
state->registers.regs[reg].mode = REG_OFFSET;
|
||||||
state->registers.regs[reg].offset = state->dataAlign * (s32)elfReadLEB128(data, &bytes);
|
state->registers.regs[reg].offset = state->dataAlign * (int32_t)elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
break;
|
break;
|
||||||
case DW_CFA_restore:
|
case DW_CFA_restore:
|
||||||
|
@ -536,7 +536,7 @@ void elfExecuteCFAInstructions(ELFFrameState* state, u8* data, u32 len,
|
||||||
reg = elfReadLEB128(data, &bytes);
|
reg = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
state->registers.regs[reg].mode = REG_OFFSET;
|
state->registers.regs[reg].mode = REG_OFFSET;
|
||||||
state->registers.regs[reg].offset = state->dataAlign * (s32)elfReadLEB128(data, &bytes);
|
state->registers.regs[reg].offset = state->dataAlign * (int32_t)elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
break;
|
break;
|
||||||
case DW_CFA_restore_extended:
|
case DW_CFA_restore_extended:
|
||||||
|
@ -571,7 +571,7 @@ void elfExecuteCFAInstructions(ELFFrameState* state, u8* data, u32 len,
|
||||||
case DW_CFA_def_cfa:
|
case DW_CFA_def_cfa:
|
||||||
state->cfaRegister = elfReadLEB128(data, &bytes);
|
state->cfaRegister = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
state->cfaOffset = (s32)elfReadLEB128(data, &bytes);
|
state->cfaOffset = (int32_t)elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
state->cfaMode = CFA_REG_OFFSET;
|
state->cfaMode = CFA_REG_OFFSET;
|
||||||
break;
|
break;
|
||||||
|
@ -581,7 +581,7 @@ void elfExecuteCFAInstructions(ELFFrameState* state, u8* data, u32 len,
|
||||||
state->cfaMode = CFA_REG_OFFSET;
|
state->cfaMode = CFA_REG_OFFSET;
|
||||||
break;
|
break;
|
||||||
case DW_CFA_def_cfa_offset:
|
case DW_CFA_def_cfa_offset:
|
||||||
state->cfaOffset = (s32)elfReadLEB128(data, &bytes);
|
state->cfaOffset = (int32_t)elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
state->cfaMode = CFA_REG_OFFSET;
|
state->cfaMode = CFA_REG_OFFSET;
|
||||||
break;
|
break;
|
||||||
|
@ -597,7 +597,7 @@ void elfExecuteCFAInstructions(ELFFrameState* state, u8* data, u32 len,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ELFFrameState* elfGetFrameState(ELFfde* fde, u32 address)
|
ELFFrameState* elfGetFrameState(ELFfde* fde, uint32_t address)
|
||||||
{
|
{
|
||||||
ELFFrameState* state = (ELFFrameState*)calloc(1, sizeof(ELFFrameState));
|
ELFFrameState* state = (ELFFrameState*)calloc(1, sizeof(ELFFrameState));
|
||||||
state->pc = fde->address;
|
state->pc = fde->address;
|
||||||
|
@ -617,7 +617,7 @@ ELFFrameState* elfGetFrameState(ELFfde* fde, u32 address)
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void elfPrintCallChain(u32 address)
|
void elfPrintCallChain(uint32_t address)
|
||||||
{
|
{
|
||||||
int count = 1;
|
int count = 1;
|
||||||
|
|
||||||
|
@ -647,7 +647,7 @@ void elfPrintCallChain(u32 address)
|
||||||
|
|
||||||
if (state->cfaMode == CFA_REG_OFFSET) {
|
if (state->cfaMode == CFA_REG_OFFSET) {
|
||||||
memcpy(&newRegs[0], ®s[0], sizeof(reg_pair) * 15);
|
memcpy(&newRegs[0], ®s[0], sizeof(reg_pair) * 15);
|
||||||
u32 addr = 0;
|
uint32_t addr = 0;
|
||||||
for (int i = 0; i < 15; i++) {
|
for (int i = 0; i < 15; i++) {
|
||||||
ELFFrameStateRegister* r = &state->registers.regs[i];
|
ELFFrameStateRegister* r = &state->registers.regs[i];
|
||||||
|
|
||||||
|
@ -688,9 +688,9 @@ void elfPrintCallChain(u32 address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 elfDecodeLocation(Function* f, ELFBlock* o, LocationType* type, u32 base)
|
uint32_t elfDecodeLocation(Function* f, ELFBlock* o, LocationType* type, uint32_t base)
|
||||||
{
|
{
|
||||||
u32 framebase = 0;
|
uint32_t framebase = 0;
|
||||||
if (f && f->frameBase) {
|
if (f && f->frameBase) {
|
||||||
ELFBlock* b = f->frameBase;
|
ELFBlock* b = f->frameBase;
|
||||||
switch (*b->data) {
|
switch (*b->data) {
|
||||||
|
@ -719,7 +719,7 @@ u32 elfDecodeLocation(Function* f, ELFBlock* o, LocationType* type, u32 base)
|
||||||
}
|
}
|
||||||
|
|
||||||
ELFBlock* loc = o;
|
ELFBlock* loc = o;
|
||||||
u32 location = 0;
|
uint32_t location = 0;
|
||||||
int bytes = 0;
|
int bytes = 0;
|
||||||
if (loc) {
|
if (loc) {
|
||||||
switch (*loc->data) {
|
switch (*loc->data) {
|
||||||
|
@ -752,7 +752,7 @@ u32 elfDecodeLocation(Function* f, ELFBlock* o, LocationType* type, u32 base)
|
||||||
break;
|
break;
|
||||||
case DW_OP_fbreg: {
|
case DW_OP_fbreg: {
|
||||||
int bytes;
|
int bytes;
|
||||||
s32 off = elfReadSignedLEB128(loc->data + 1, &bytes);
|
int32_t off = elfReadSignedLEB128(loc->data + 1, &bytes);
|
||||||
location = framebase + off;
|
location = framebase + off;
|
||||||
*type = LOCATION_memory;
|
*type = LOCATION_memory;
|
||||||
} break;
|
} break;
|
||||||
|
@ -764,30 +764,30 @@ u32 elfDecodeLocation(Function* f, ELFBlock* o, LocationType* type, u32 base)
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 elfDecodeLocation(Function* f, ELFBlock* o, LocationType* type)
|
uint32_t elfDecodeLocation(Function* f, ELFBlock* o, LocationType* type)
|
||||||
{
|
{
|
||||||
return elfDecodeLocation(f, o, type, 0);
|
return elfDecodeLocation(f, o, type, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// reading function
|
// reading function
|
||||||
|
|
||||||
u32 elfRead4Bytes(u8* data)
|
uint32_t elfRead4Bytes(uint8_t* data)
|
||||||
{
|
{
|
||||||
u32 value = *data++;
|
uint32_t value = *data++;
|
||||||
value |= (*data++ << 8);
|
value |= (*data++ << 8);
|
||||||
value |= (*data++ << 16);
|
value |= (*data++ << 16);
|
||||||
value |= (*data << 24);
|
value |= (*data << 24);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 elfRead2Bytes(u8* data)
|
uint16_t elfRead2Bytes(uint8_t* data)
|
||||||
{
|
{
|
||||||
u16 value = *data++;
|
uint16_t value = *data++;
|
||||||
value |= (*data << 8);
|
value |= (*data << 8);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* elfReadString(u8* data, int* bytesRead)
|
char* elfReadString(uint8_t* data, int* bytesRead)
|
||||||
{
|
{
|
||||||
if (*data == 0) {
|
if (*data == 0) {
|
||||||
*bytesRead = 1;
|
*bytesRead = 1;
|
||||||
|
@ -797,13 +797,13 @@ char* elfReadString(u8* data, int* bytesRead)
|
||||||
return (char*)data;
|
return (char*)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 elfReadSignedLEB128(u8* data, int* bytesRead)
|
int32_t elfReadSignedLEB128(uint8_t* data, int* bytesRead)
|
||||||
{
|
{
|
||||||
s32 result = 0;
|
int32_t result = 0;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
u8 byte;
|
uint8_t byte;
|
||||||
do {
|
do {
|
||||||
byte = *data++;
|
byte = *data++;
|
||||||
count++;
|
count++;
|
||||||
|
@ -816,12 +816,12 @@ s32 elfReadSignedLEB128(u8* data, int* bytesRead)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 elfReadLEB128(u8* data, int* bytesRead)
|
uint32_t elfReadLEB128(uint8_t* data, int* bytesRead)
|
||||||
{
|
{
|
||||||
u32 result = 0;
|
uint32_t result = 0;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
u8 byte;
|
uint8_t byte;
|
||||||
do {
|
do {
|
||||||
byte = *data++;
|
byte = *data++;
|
||||||
count++;
|
count++;
|
||||||
|
@ -832,7 +832,7 @@ u32 elfReadLEB128(u8* data, int* bytesRead)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8* elfReadSection(u8* data, ELFSectionHeader* sh)
|
uint8_t* elfReadSection(uint8_t* data, ELFSectionHeader* sh)
|
||||||
{
|
{
|
||||||
return data + READ32LE(&sh->offset);
|
return data + READ32LE(&sh->offset);
|
||||||
}
|
}
|
||||||
|
@ -857,9 +857,9 @@ ELFSectionHeader* elfGetSectionByNumber(int number)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompileUnit* elfGetCompileUnitForData(u8* data)
|
CompileUnit* elfGetCompileUnitForData(uint8_t* data)
|
||||||
{
|
{
|
||||||
u8* end = elfCurrentUnit->top + 4 + elfCurrentUnit->length;
|
uint8_t* end = elfCurrentUnit->top + 4 + elfCurrentUnit->length;
|
||||||
|
|
||||||
if (data >= elfCurrentUnit->top && data < end)
|
if (data >= elfCurrentUnit->top && data < end)
|
||||||
return elfCurrentUnit;
|
return elfCurrentUnit;
|
||||||
|
@ -880,7 +880,7 @@ CompileUnit* elfGetCompileUnitForData(u8* data)
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
u8* elfReadAttribute(u8* data, ELFAttr* attr)
|
uint8_t* elfReadAttribute(uint8_t* data, ELFAttr* attr)
|
||||||
{
|
{
|
||||||
int bytes;
|
int bytes;
|
||||||
int form = attr->form;
|
int form = attr->form;
|
||||||
|
@ -934,7 +934,7 @@ start:
|
||||||
data += bytes;
|
data += bytes;
|
||||||
break;
|
break;
|
||||||
case DW_FORM_ref_addr:
|
case DW_FORM_ref_addr:
|
||||||
attr->value = (u32)((elfDebugInfo->infodata + elfRead4Bytes(data)) - elfGetCompileUnitForData(data)->top);
|
attr->value = (uint32_t)((elfDebugInfo->infodata + elfRead4Bytes(data)) - elfGetCompileUnitForData(data)->top);
|
||||||
data += 4;
|
data += 4;
|
||||||
break;
|
break;
|
||||||
case DW_FORM_ref4:
|
case DW_FORM_ref4:
|
||||||
|
@ -942,7 +942,7 @@ start:
|
||||||
data += 4;
|
data += 4;
|
||||||
break;
|
break;
|
||||||
case DW_FORM_ref_udata:
|
case DW_FORM_ref_udata:
|
||||||
attr->value = (u32)((elfDebugInfo->infodata + (elfGetCompileUnitForData(data)->top - elfDebugInfo->infodata) + elfReadLEB128(data, &bytes)) - elfCurrentUnit->top);
|
attr->value = (uint32_t)((elfDebugInfo->infodata + (elfGetCompileUnitForData(data)->top - elfDebugInfo->infodata) + elfReadLEB128(data, &bytes)) - elfCurrentUnit->top);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
break;
|
break;
|
||||||
case DW_FORM_indirect:
|
case DW_FORM_indirect:
|
||||||
|
@ -956,7 +956,7 @@ start:
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
ELFAbbrev* elfGetAbbrev(ELFAbbrev** table, u32 number)
|
ELFAbbrev* elfGetAbbrev(ELFAbbrev** table, uint32_t number)
|
||||||
{
|
{
|
||||||
int hash = number % 121;
|
int hash = number % 121;
|
||||||
|
|
||||||
|
@ -970,12 +970,12 @@ ELFAbbrev* elfGetAbbrev(ELFAbbrev** table, u32 number)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ELFAbbrev** elfReadAbbrevs(u8* data, u32 offset)
|
ELFAbbrev** elfReadAbbrevs(uint8_t* data, uint32_t offset)
|
||||||
{
|
{
|
||||||
data += offset;
|
data += offset;
|
||||||
ELFAbbrev** abbrevs = (ELFAbbrev**)calloc(sizeof(ELFAbbrev*) * 121, 1);
|
ELFAbbrev** abbrevs = (ELFAbbrev**)calloc(sizeof(ELFAbbrev*) * 121, 1);
|
||||||
int bytes = 0;
|
int bytes = 0;
|
||||||
u32 number = elfReadLEB128(data, &bytes);
|
uint32_t number = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
while (number) {
|
while (number) {
|
||||||
ELFAbbrev* abbrev = (ELFAbbrev*)calloc(sizeof(ELFAbbrev), 1);
|
ELFAbbrev* abbrev = (ELFAbbrev*)calloc(sizeof(ELFAbbrev), 1);
|
||||||
|
@ -1020,7 +1020,7 @@ ELFAbbrev** elfReadAbbrevs(u8* data, u32 offset)
|
||||||
return abbrevs;
|
return abbrevs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void elfParseCFA(u8* top)
|
void elfParseCFA(uint8_t* top)
|
||||||
{
|
{
|
||||||
ELFSectionHeader* h = elfGetSectionByName(".debug_frame");
|
ELFSectionHeader* h = elfGetSectionByName(".debug_frame");
|
||||||
|
|
||||||
|
@ -1028,22 +1028,22 @@ void elfParseCFA(u8* top)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8* data = elfReadSection(top, h);
|
uint8_t* data = elfReadSection(top, h);
|
||||||
|
|
||||||
u8* topOffset = data;
|
uint8_t* topOffset = data;
|
||||||
|
|
||||||
u8* end = data + READ32LE(&h->size);
|
uint8_t* end = data + READ32LE(&h->size);
|
||||||
|
|
||||||
ELFcie* cies = NULL;
|
ELFcie* cies = NULL;
|
||||||
|
|
||||||
while (data < end) {
|
while (data < end) {
|
||||||
u32 offset = (u32)(data - topOffset);
|
uint32_t offset = (uint32_t)(data - topOffset);
|
||||||
u32 len = elfRead4Bytes(data);
|
uint32_t len = elfRead4Bytes(data);
|
||||||
data += 4;
|
data += 4;
|
||||||
|
|
||||||
u8* dataEnd = data + len;
|
uint8_t* dataEnd = data + len;
|
||||||
|
|
||||||
u32 id = elfRead4Bytes(data);
|
uint32_t id = elfRead4Bytes(data);
|
||||||
data += 4;
|
data += 4;
|
||||||
|
|
||||||
if (id == 0xffffffff) {
|
if (id == 0xffffffff) {
|
||||||
|
@ -1077,7 +1077,7 @@ void elfParseCFA(u8* top)
|
||||||
cie->returnAddress = *data++;
|
cie->returnAddress = *data++;
|
||||||
|
|
||||||
cie->data = data;
|
cie->data = data;
|
||||||
cie->dataLen = (u32)(dataEnd - data);
|
cie->dataLen = (uint32_t)(dataEnd - data);
|
||||||
} else {
|
} else {
|
||||||
ELFfde* fde = (ELFfde*)calloc(1, sizeof(ELFfde));
|
ELFfde* fde = (ELFfde*)calloc(1, sizeof(ELFfde));
|
||||||
|
|
||||||
|
@ -1103,7 +1103,7 @@ void elfParseCFA(u8* top)
|
||||||
data += 4;
|
data += 4;
|
||||||
|
|
||||||
fde->data = data;
|
fde->data = data;
|
||||||
fde->dataLen = (u32)(dataEnd - data);
|
fde->dataLen = (uint32_t)(dataEnd - data);
|
||||||
|
|
||||||
if ((elfFdeCount % 10) == 0) {
|
if ((elfFdeCount % 10) == 0) {
|
||||||
elfFdes = (ELFfde**)realloc(elfFdes, (elfFdeCount + 10) * sizeof(ELFfde*));
|
elfFdes = (ELFfde**)realloc(elfFdes, (elfFdeCount + 10) * sizeof(ELFfde*));
|
||||||
|
@ -1116,7 +1116,7 @@ void elfParseCFA(u8* top)
|
||||||
elfCies = cies;
|
elfCies = cies;
|
||||||
}
|
}
|
||||||
|
|
||||||
void elfAddLine(LineInfo* l, u32 a, int file, int line, int* max)
|
void elfAddLine(LineInfo* l, uint32_t a, int file, int line, int* max)
|
||||||
{
|
{
|
||||||
if (l->number == *max) {
|
if (l->number == *max) {
|
||||||
*max += 1000;
|
*max += 1000;
|
||||||
|
@ -1129,7 +1129,7 @@ void elfAddLine(LineInfo* l, u32 a, int file, int line, int* max)
|
||||||
l->number++;
|
l->number++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void elfParseLineInfo(CompileUnit* unit, u8* top)
|
void elfParseLineInfo(CompileUnit* unit, uint8_t* top)
|
||||||
{
|
{
|
||||||
ELFSectionHeader* h = elfGetSectionByName(".debug_line");
|
ELFSectionHeader* h = elfGetSectionByName(".debug_line");
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
|
@ -1141,21 +1141,21 @@ void elfParseLineInfo(CompileUnit* unit, u8* top)
|
||||||
int max = 1000;
|
int max = 1000;
|
||||||
l->lines = (LineInfoItem*)malloc(1000 * sizeof(LineInfoItem));
|
l->lines = (LineInfoItem*)malloc(1000 * sizeof(LineInfoItem));
|
||||||
|
|
||||||
u8* data = elfReadSection(top, h);
|
uint8_t* data = elfReadSection(top, h);
|
||||||
data += unit->lineInfo;
|
data += unit->lineInfo;
|
||||||
u32 totalLen = elfRead4Bytes(data);
|
uint32_t totalLen = elfRead4Bytes(data);
|
||||||
data += 4;
|
data += 4;
|
||||||
u8* end = data + totalLen;
|
uint8_t* end = data + totalLen;
|
||||||
// u16 version = elfRead2Bytes(data);
|
// uint16_t version = elfRead2Bytes(data);
|
||||||
data += 2;
|
data += 2;
|
||||||
// u32 offset = elfRead4Bytes(data);
|
// uint32_t offset = elfRead4Bytes(data);
|
||||||
data += 4;
|
data += 4;
|
||||||
int minInstrSize = *data++;
|
int minInstrSize = *data++;
|
||||||
int defaultIsStmt = *data++;
|
int defaultIsStmt = *data++;
|
||||||
int lineBase = (s8)*data++;
|
int lineBase = (int8_t)*data++;
|
||||||
int lineRange = *data++;
|
int lineRange = *data++;
|
||||||
int opcodeBase = *data++;
|
int opcodeBase = *data++;
|
||||||
u8* stdOpLen = (u8*)malloc(opcodeBase * sizeof(u8));
|
uint8_t* stdOpLen = (uint8_t*)malloc(opcodeBase * sizeof(uint8_t));
|
||||||
stdOpLen[0] = 1;
|
stdOpLen[0] = 1;
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i < opcodeBase; i++)
|
for (i = 1; i < opcodeBase; i++)
|
||||||
|
@ -1197,7 +1197,7 @@ void elfParseLineInfo(CompileUnit* unit, u8* top)
|
||||||
data += bytes;
|
data += bytes;
|
||||||
|
|
||||||
while (data < end) {
|
while (data < end) {
|
||||||
u32 address = 0;
|
uint32_t address = 0;
|
||||||
int file = 1;
|
int file = 1;
|
||||||
int line = 1;
|
int line = 1;
|
||||||
int col = 0;
|
int col = 0;
|
||||||
|
@ -1272,7 +1272,7 @@ void elfParseLineInfo(CompileUnit* unit, u8* top)
|
||||||
l->lines = (LineInfoItem*)realloc(l->lines, l->number * sizeof(LineInfoItem));
|
l->lines = (LineInfoItem*)realloc(l->lines, l->number * sizeof(LineInfoItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
u8* elfSkipData(u8* data, ELFAbbrev* abbrev, ELFAbbrev** abbrevs)
|
uint8_t* elfSkipData(uint8_t* data, ELFAbbrev* abbrev, ELFAbbrev** abbrevs)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int bytes;
|
int bytes;
|
||||||
|
@ -1286,7 +1286,7 @@ u8* elfSkipData(u8* data, ELFAbbrev* abbrev, ELFAbbrev** abbrevs)
|
||||||
if (abbrev->hasChildren) {
|
if (abbrev->hasChildren) {
|
||||||
int nesting = 1;
|
int nesting = 1;
|
||||||
while (nesting) {
|
while (nesting) {
|
||||||
u32 abbrevNum = elfReadLEB128(data, &bytes);
|
uint32_t abbrevNum = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
|
|
||||||
if (!abbrevNum) {
|
if (!abbrevNum) {
|
||||||
|
@ -1310,14 +1310,14 @@ u8* elfSkipData(u8* data, ELFAbbrev* abbrev, ELFAbbrev** abbrevs)
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type* elfParseType(CompileUnit* unit, u32);
|
Type* elfParseType(CompileUnit* unit, uint32_t);
|
||||||
u8* elfParseObject(u8* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
uint8_t* elfParseObject(uint8_t* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
Object** object);
|
Object** object);
|
||||||
u8* elfParseFunction(u8* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
uint8_t* elfParseFunction(uint8_t* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
Function** function);
|
Function** function);
|
||||||
void elfCleanUp(Function*);
|
void elfCleanUp(Function*);
|
||||||
|
|
||||||
void elfAddType(Type* type, CompileUnit* unit, u32 offset)
|
void elfAddType(Type* type, CompileUnit* unit, uint32_t offset)
|
||||||
{
|
{
|
||||||
if (type->next == NULL) {
|
if (type->next == NULL) {
|
||||||
if (unit->types != type && type->offset == 0) {
|
if (unit->types != type && type->offset == 0) {
|
||||||
|
@ -1328,12 +1328,12 @@ void elfAddType(Type* type, CompileUnit* unit, u32 offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void elfParseType(u8* data, u32 offset, ELFAbbrev* abbrev, CompileUnit* unit,
|
void elfParseType(uint8_t* data, uint32_t offset, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
Type** type)
|
Type** type)
|
||||||
{
|
{
|
||||||
switch (abbrev->tag) {
|
switch (abbrev->tag) {
|
||||||
case DW_TAG_typedef: {
|
case DW_TAG_typedef: {
|
||||||
u32 typeref = 0;
|
uint32_t typeref = 0;
|
||||||
char* name = NULL;
|
char* name = NULL;
|
||||||
for (int i = 0; i < abbrev->numAttrs; i++) {
|
for (int i = 0; i < abbrev->numAttrs; i++) {
|
||||||
ELFAttr* attr = &abbrev->attrs[i];
|
ELFAttr* attr = &abbrev->attrs[i];
|
||||||
|
@ -1396,7 +1396,7 @@ void elfParseType(u8* data, u32 offset, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
}
|
}
|
||||||
if (abbrev->hasChildren) {
|
if (abbrev->hasChildren) {
|
||||||
int bytes;
|
int bytes;
|
||||||
u32 num = elfReadLEB128(data, &bytes);
|
uint32_t num = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (num) {
|
while (num) {
|
||||||
|
@ -1568,7 +1568,7 @@ void elfParseType(u8* data, u32 offset, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
return;
|
return;
|
||||||
} break;
|
} break;
|
||||||
case DW_TAG_volatile_type: {
|
case DW_TAG_volatile_type: {
|
||||||
u32 typeref = 0;
|
uint32_t typeref = 0;
|
||||||
|
|
||||||
for (int i = 0; i < abbrev->numAttrs; i++) {
|
for (int i = 0; i < abbrev->numAttrs; i++) {
|
||||||
ELFAttr* attr = &abbrev->attrs[i];
|
ELFAttr* attr = &abbrev->attrs[i];
|
||||||
|
@ -1589,7 +1589,7 @@ void elfParseType(u8* data, u32 offset, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
return;
|
return;
|
||||||
} break;
|
} break;
|
||||||
case DW_TAG_const_type: {
|
case DW_TAG_const_type: {
|
||||||
u32 typeref = 0;
|
uint32_t typeref = 0;
|
||||||
|
|
||||||
for (int i = 0; i < abbrev->numAttrs; i++) {
|
for (int i = 0; i < abbrev->numAttrs; i++) {
|
||||||
ELFAttr* attr = &abbrev->attrs[i];
|
ELFAttr* attr = &abbrev->attrs[i];
|
||||||
|
@ -1636,7 +1636,7 @@ void elfParseType(u8* data, u32 offset, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
}
|
}
|
||||||
if (abbrev->hasChildren) {
|
if (abbrev->hasChildren) {
|
||||||
int bytes;
|
int bytes;
|
||||||
u32 num = elfReadLEB128(data, &bytes);
|
uint32_t num = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
while (num) {
|
while (num) {
|
||||||
ELFAbbrev* abbr = elfGetAbbrev(unit->abbrevs, num);
|
ELFAbbrev* abbr = elfGetAbbrev(unit->abbrevs, num);
|
||||||
|
@ -1698,7 +1698,7 @@ void elfParseType(u8* data, u32 offset, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
}
|
}
|
||||||
if (abbrev->hasChildren) {
|
if (abbrev->hasChildren) {
|
||||||
int bytes;
|
int bytes;
|
||||||
u32 num = elfReadLEB128(data, &bytes);
|
uint32_t num = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
Object* lastVar = NULL;
|
Object* lastVar = NULL;
|
||||||
while (num) {
|
while (num) {
|
||||||
|
@ -1735,7 +1735,7 @@ void elfParseType(u8* data, u32 offset, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
return;
|
return;
|
||||||
} break;
|
} break;
|
||||||
case DW_TAG_array_type: {
|
case DW_TAG_array_type: {
|
||||||
u32 typeref = 0;
|
uint32_t typeref = 0;
|
||||||
int i;
|
int i;
|
||||||
Array* array = (Array*)calloc(sizeof(Array), 1);
|
Array* array = (Array*)calloc(sizeof(Array), 1);
|
||||||
Type* t = (Type*)calloc(sizeof(Type), 1);
|
Type* t = (Type*)calloc(sizeof(Type), 1);
|
||||||
|
@ -1758,7 +1758,7 @@ void elfParseType(u8* data, u32 offset, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
}
|
}
|
||||||
if (abbrev->hasChildren) {
|
if (abbrev->hasChildren) {
|
||||||
int bytes;
|
int bytes;
|
||||||
u32 num = elfReadLEB128(data, &bytes);
|
uint32_t num = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int maxBounds = 0;
|
int maxBounds = 0;
|
||||||
|
@ -1811,7 +1811,7 @@ void elfParseType(u8* data, u32 offset, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Type* elfParseType(CompileUnit* unit, u32 offset)
|
Type* elfParseType(CompileUnit* unit, uint32_t offset)
|
||||||
{
|
{
|
||||||
Type* t = unit->types;
|
Type* t = unit->types;
|
||||||
|
|
||||||
|
@ -1827,7 +1827,7 @@ Type* elfParseType(CompileUnit* unit, u32 offset)
|
||||||
elfAddType(t, unit, 0);
|
elfAddType(t, unit, 0);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
u8* data = unit->top + offset;
|
uint8_t* data = unit->top + offset;
|
||||||
int bytes;
|
int bytes;
|
||||||
int abbrevNum = elfReadLEB128(data, &bytes);
|
int abbrevNum = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
|
@ -1839,11 +1839,11 @@ Type* elfParseType(CompileUnit* unit, u32 offset)
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void elfGetObjectAttributes(CompileUnit* unit, u32 offset, Object* o)
|
void elfGetObjectAttributes(CompileUnit* unit, uint32_t offset, Object* o)
|
||||||
{
|
{
|
||||||
u8* data = unit->top + offset;
|
uint8_t* data = unit->top + offset;
|
||||||
int bytes;
|
int bytes;
|
||||||
u32 abbrevNum = elfReadLEB128(data, &bytes);
|
uint32_t abbrevNum = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
|
|
||||||
if (!abbrevNum) {
|
if (!abbrevNum) {
|
||||||
|
@ -1894,7 +1894,7 @@ void elfGetObjectAttributes(CompileUnit* unit, u32 offset, Object* o)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u8* elfParseObject(u8* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
uint8_t* elfParseObject(uint8_t* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
Object** object)
|
Object** object)
|
||||||
{
|
{
|
||||||
Object* o = (Object*)calloc(sizeof(Object), 1);
|
Object* o = (Object*)calloc(sizeof(Object), 1);
|
||||||
|
@ -1946,12 +1946,12 @@ u8* elfParseObject(u8* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8* elfParseBlock(u8* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
uint8_t* elfParseBlock(uint8_t* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
Function* func, Object** lastVar)
|
Function* func, Object** lastVar)
|
||||||
{
|
{
|
||||||
int bytes;
|
int bytes;
|
||||||
u32 start = func->lowPC;
|
uint32_t start = func->lowPC;
|
||||||
u32 end = func->highPC;
|
uint32_t end = func->highPC;
|
||||||
|
|
||||||
for (int i = 0; i < abbrev->numAttrs; i++) {
|
for (int i = 0; i < abbrev->numAttrs; i++) {
|
||||||
ELFAttr* attr = &abbrev->attrs[i];
|
ELFAttr* attr = &abbrev->attrs[i];
|
||||||
|
@ -1977,7 +1977,7 @@ u8* elfParseBlock(u8* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
int nesting = 1;
|
int nesting = 1;
|
||||||
|
|
||||||
while (nesting) {
|
while (nesting) {
|
||||||
u32 abbrevNum = elfReadLEB128(data, &bytes);
|
uint32_t abbrevNum = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
|
|
||||||
if (!abbrevNum) {
|
if (!abbrevNum) {
|
||||||
|
@ -2033,11 +2033,11 @@ u8* elfParseBlock(u8* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void elfGetFunctionAttributes(CompileUnit* unit, u32 offset, Function* func)
|
void elfGetFunctionAttributes(CompileUnit* unit, uint32_t offset, Function* func)
|
||||||
{
|
{
|
||||||
u8* data = unit->top + offset;
|
uint8_t* data = unit->top + offset;
|
||||||
int bytes;
|
int bytes;
|
||||||
u32 abbrevNum = elfReadLEB128(data, &bytes);
|
uint32_t abbrevNum = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
|
|
||||||
if (!abbrevNum) {
|
if (!abbrevNum) {
|
||||||
|
@ -2106,7 +2106,7 @@ void elfGetFunctionAttributes(CompileUnit* unit, u32 offset, Function* func)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8* elfParseFunction(u8* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
uint8_t* elfParseFunction(uint8_t* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
Function** f)
|
Function** f)
|
||||||
{
|
{
|
||||||
Function* func = (Function*)calloc(sizeof(Function), 1);
|
Function* func = (Function*)calloc(sizeof(Function), 1);
|
||||||
|
@ -2184,7 +2184,7 @@ u8* elfParseFunction(u8* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
*f = NULL;
|
*f = NULL;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
u32 abbrevNum = elfReadLEB128(data, &bytes);
|
uint32_t abbrevNum = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
|
|
||||||
if (!abbrevNum) {
|
if (!abbrevNum) {
|
||||||
|
@ -2203,7 +2203,7 @@ u8* elfParseFunction(u8* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
Object* lastVar = NULL;
|
Object* lastVar = NULL;
|
||||||
|
|
||||||
while (nesting) {
|
while (nesting) {
|
||||||
u32 abbrevNum = elfReadLEB128(data, &bytes);
|
uint32_t abbrevNum = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
|
|
||||||
if (!abbrevNum) {
|
if (!abbrevNum) {
|
||||||
|
@ -2272,7 +2272,7 @@ u8* elfParseFunction(u8* data, ELFAbbrev* abbrev, CompileUnit* unit,
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8* elfParseUnknownData(u8* data, ELFAbbrev* abbrev, ELFAbbrev** abbrevs)
|
uint8_t* elfParseUnknownData(uint8_t* data, ELFAbbrev* abbrev, ELFAbbrev** abbrevs)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int bytes;
|
int bytes;
|
||||||
|
@ -2289,7 +2289,7 @@ u8* elfParseUnknownData(u8* data, ELFAbbrev* abbrev, ELFAbbrev** abbrevs)
|
||||||
if (abbrev->hasChildren) {
|
if (abbrev->hasChildren) {
|
||||||
int nesting = 1;
|
int nesting = 1;
|
||||||
while (nesting) {
|
while (nesting) {
|
||||||
u32 abbrevNum = elfReadLEB128(data, &bytes);
|
uint32_t abbrevNum = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
|
|
||||||
if (!abbrevNum) {
|
if (!abbrevNum) {
|
||||||
|
@ -2316,10 +2316,10 @@ u8* elfParseUnknownData(u8* data, ELFAbbrev* abbrev, ELFAbbrev** abbrevs)
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8* elfParseCompileUnitChildren(u8* data, CompileUnit* unit)
|
uint8_t* elfParseCompileUnitChildren(uint8_t* data, CompileUnit* unit)
|
||||||
{
|
{
|
||||||
int bytes;
|
int bytes;
|
||||||
u32 abbrevNum = elfReadLEB128(data, &bytes);
|
uint32_t abbrevNum = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
Object* lastObj = NULL;
|
Object* lastObj = NULL;
|
||||||
while (abbrevNum) {
|
while (abbrevNum) {
|
||||||
|
@ -2359,21 +2359,21 @@ u8* elfParseCompileUnitChildren(u8* data, CompileUnit* unit)
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompileUnit* elfParseCompUnit(u8* data, u8* abbrevData)
|
CompileUnit* elfParseCompUnit(uint8_t* data, uint8_t* abbrevData)
|
||||||
{
|
{
|
||||||
int bytes;
|
int bytes;
|
||||||
u8* top = data;
|
uint8_t* top = data;
|
||||||
|
|
||||||
u32 length = elfRead4Bytes(data);
|
uint32_t length = elfRead4Bytes(data);
|
||||||
data += 4;
|
data += 4;
|
||||||
|
|
||||||
u16 version = elfRead2Bytes(data);
|
uint16_t version = elfRead2Bytes(data);
|
||||||
data += 2;
|
data += 2;
|
||||||
|
|
||||||
u32 offset = elfRead4Bytes(data);
|
uint32_t offset = elfRead4Bytes(data);
|
||||||
data += 4;
|
data += 4;
|
||||||
|
|
||||||
u8 addrSize = *data++;
|
uint8_t addrSize = *data++;
|
||||||
|
|
||||||
if (version != 2) {
|
if (version != 2) {
|
||||||
fprintf(stderr, "Unsupported debugging information version %d\n", version);
|
fprintf(stderr, "Unsupported debugging information version %d\n", version);
|
||||||
|
@ -2387,7 +2387,7 @@ CompileUnit* elfParseCompUnit(u8* data, u8* abbrevData)
|
||||||
|
|
||||||
ELFAbbrev** abbrevs = elfReadAbbrevs(abbrevData, offset);
|
ELFAbbrev** abbrevs = elfReadAbbrevs(abbrevData, offset);
|
||||||
|
|
||||||
u32 abbrevNum = elfReadLEB128(data, &bytes);
|
uint32_t abbrevNum = elfReadLEB128(data, &bytes);
|
||||||
data += bytes;
|
data += bytes;
|
||||||
|
|
||||||
ELFAbbrev* abbrev = elfGetAbbrev(abbrevs, abbrevNum);
|
ELFAbbrev* abbrev = elfGetAbbrev(abbrevs, abbrevNum);
|
||||||
|
@ -2441,7 +2441,7 @@ CompileUnit* elfParseCompUnit(u8* data, u8* abbrevData)
|
||||||
return unit;
|
return unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void elfParseAranges(u8* data)
|
void elfParseAranges(uint8_t* data)
|
||||||
{
|
{
|
||||||
ELFSectionHeader* sh = elfGetSectionByName(".debug_aranges");
|
ELFSectionHeader* sh = elfGetSectionByName(".debug_aranges");
|
||||||
if (sh == NULL) {
|
if (sh == NULL) {
|
||||||
|
@ -2450,7 +2450,7 @@ void elfParseAranges(u8* data)
|
||||||
}
|
}
|
||||||
|
|
||||||
data = elfReadSection(data, sh);
|
data = elfReadSection(data, sh);
|
||||||
u8* end = data + READ32LE(&sh->size);
|
uint8_t* end = data + READ32LE(&sh->size);
|
||||||
|
|
||||||
int max = 4;
|
int max = 4;
|
||||||
ARanges* ranges = (ARanges*)calloc(sizeof(ARanges), 4);
|
ARanges* ranges = (ARanges*)calloc(sizeof(ARanges), 4);
|
||||||
|
@ -2458,14 +2458,14 @@ void elfParseAranges(u8* data)
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
while (data < end) {
|
while (data < end) {
|
||||||
u32 len = elfRead4Bytes(data);
|
uint32_t len = elfRead4Bytes(data);
|
||||||
data += 4;
|
data += 4;
|
||||||
// u16 version = elfRead2Bytes(data);
|
// uint16_t version = elfRead2Bytes(data);
|
||||||
data += 2;
|
data += 2;
|
||||||
u32 offset = elfRead4Bytes(data);
|
uint32_t offset = elfRead4Bytes(data);
|
||||||
data += 4;
|
data += 4;
|
||||||
// u8 addrSize = *data++;
|
// uint8_t addrSize = *data++;
|
||||||
// u8 segSize = *data++;
|
// uint8_t segSize = *data++;
|
||||||
data += 2; // remove if uncommenting above
|
data += 2; // remove if uncommenting above
|
||||||
data += 4;
|
data += 4;
|
||||||
ranges[index].count = (len - 20) / 8;
|
ranges[index].count = (len - 20) / 8;
|
||||||
|
@ -2473,9 +2473,9 @@ void elfParseAranges(u8* data)
|
||||||
ranges[index].ranges = (ARange*)calloc(sizeof(ARange), (len - 20) / 8);
|
ranges[index].ranges = (ARange*)calloc(sizeof(ARange), (len - 20) / 8);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
u32 addr = elfRead4Bytes(data);
|
uint32_t addr = elfRead4Bytes(data);
|
||||||
data += 4;
|
data += 4;
|
||||||
u32 len = elfRead4Bytes(data);
|
uint32_t len = elfRead4Bytes(data);
|
||||||
data += 4;
|
data += 4;
|
||||||
if (addr == 0 && len == 0)
|
if (addr == 0 && len == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -2493,7 +2493,7 @@ void elfParseAranges(u8* data)
|
||||||
elfDebugInfo->ranges = ranges;
|
elfDebugInfo->ranges = ranges;
|
||||||
}
|
}
|
||||||
|
|
||||||
void elfReadSymtab(u8* data)
|
void elfReadSymtab(uint8_t* data)
|
||||||
{
|
{
|
||||||
ELFSectionHeader* sh = elfGetSectionByName(".symtab");
|
ELFSectionHeader* sh = elfGetSectionByName(".symtab");
|
||||||
int table = READ32LE(&sh->link);
|
int table = READ32LE(&sh->link);
|
||||||
|
@ -2543,7 +2543,7 @@ void elfReadSymtab(u8* data)
|
||||||
// free(symtab);
|
// free(symtab);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool elfReadProgram(ELFHeader* eh, u8* data, int& size, bool parseDebug)
|
bool elfReadProgram(ELFHeader* eh, uint8_t* data, int& size, bool parseDebug)
|
||||||
{
|
{
|
||||||
int count = READ16LE(&eh->e_phnum);
|
int count = READ16LE(&eh->e_phnum);
|
||||||
int i;
|
int i;
|
||||||
|
@ -2552,7 +2552,7 @@ bool elfReadProgram(ELFHeader* eh, u8* data, int& size, bool parseDebug)
|
||||||
cpuIsMultiBoot = true;
|
cpuIsMultiBoot = true;
|
||||||
|
|
||||||
// read program headers... should probably move this code down
|
// read program headers... should probably move this code down
|
||||||
u8* p = data + READ32LE(&eh->e_phoff);
|
uint8_t* p = data + READ32LE(&eh->e_phoff);
|
||||||
size = 0;
|
size = 0;
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
ELFProgramHeader* ph = (ELFProgramHeader*)p;
|
ELFProgramHeader* ph = (ELFProgramHeader*)p;
|
||||||
|
@ -2645,7 +2645,7 @@ bool elfReadProgram(ELFHeader* eh, u8* data, int& size, bool parseDebug)
|
||||||
}
|
}
|
||||||
|
|
||||||
elfDebugInfo = (DebugInfo*)calloc(sizeof(DebugInfo), 1);
|
elfDebugInfo = (DebugInfo*)calloc(sizeof(DebugInfo), 1);
|
||||||
u8* abbrevdata = elfReadSection(data, h);
|
uint8_t* abbrevdata = elfReadSection(data, h);
|
||||||
|
|
||||||
h = elfGetSectionByName(".debug_str");
|
h = elfGetSectionByName(".debug_str");
|
||||||
|
|
||||||
|
@ -2654,21 +2654,21 @@ bool elfReadProgram(ELFHeader* eh, u8* data, int& size, bool parseDebug)
|
||||||
else
|
else
|
||||||
elfDebugStrings = (char*)elfReadSection(data, h);
|
elfDebugStrings = (char*)elfReadSection(data, h);
|
||||||
|
|
||||||
u8* debugdata = elfReadSection(data, dbgHeader);
|
uint8_t* debugdata = elfReadSection(data, dbgHeader);
|
||||||
|
|
||||||
elfDebugInfo->debugdata = data;
|
elfDebugInfo->debugdata = data;
|
||||||
elfDebugInfo->infodata = debugdata;
|
elfDebugInfo->infodata = debugdata;
|
||||||
|
|
||||||
u32 total = READ32LE(&dbgHeader->size);
|
uint32_t total = READ32LE(&dbgHeader->size);
|
||||||
u8* end = debugdata + total;
|
uint8_t* end = debugdata + total;
|
||||||
u8* ddata = debugdata;
|
uint8_t* ddata = debugdata;
|
||||||
|
|
||||||
CompileUnit* last = NULL;
|
CompileUnit* last = NULL;
|
||||||
CompileUnit* unit = NULL;
|
CompileUnit* unit = NULL;
|
||||||
|
|
||||||
while (ddata < end) {
|
while (ddata < end) {
|
||||||
unit = elfParseCompUnit(ddata, abbrevdata);
|
unit = elfParseCompUnit(ddata, abbrevdata);
|
||||||
unit->offset = (u32)(ddata - debugdata);
|
unit->offset = (uint32_t)(ddata - debugdata);
|
||||||
elfParseLineInfo(unit, data);
|
elfParseLineInfo(unit, data);
|
||||||
if (last == NULL)
|
if (last == NULL)
|
||||||
elfCompileUnits = unit;
|
elfCompileUnits = unit;
|
||||||
|
@ -2709,7 +2709,7 @@ bool elfRead(const char* name, int& siz, FILE* f)
|
||||||
{
|
{
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
long size = ftell(f);
|
long size = ftell(f);
|
||||||
elfFileData = (u8*)malloc(size);
|
elfFileData = (uint8_t*)malloc(size);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
int res = fread(elfFileData, 1, size, f);
|
int res = fread(elfFileData, 1, size, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
166
src/gba/elf.h
166
src/gba/elf.h
|
@ -11,79 +11,79 @@ enum LocationType { LOCATION_register,
|
||||||
#define DW_ATE_unsigned_char 0x08
|
#define DW_ATE_unsigned_char 0x08
|
||||||
|
|
||||||
struct ELFHeader {
|
struct ELFHeader {
|
||||||
u32 magic;
|
uint32_t magic;
|
||||||
u8 clazz;
|
uint8_t clazz;
|
||||||
u8 data;
|
uint8_t data;
|
||||||
u8 version;
|
uint8_t version;
|
||||||
u8 pad[9];
|
uint8_t pad[9];
|
||||||
u16 e_type;
|
uint16_t e_type;
|
||||||
u16 e_machine;
|
uint16_t e_machine;
|
||||||
u32 e_version;
|
uint32_t e_version;
|
||||||
u32 e_entry;
|
uint32_t e_entry;
|
||||||
u32 e_phoff;
|
uint32_t e_phoff;
|
||||||
u32 e_shoff;
|
uint32_t e_shoff;
|
||||||
u32 e_flags;
|
uint32_t e_flags;
|
||||||
u16 e_ehsize;
|
uint16_t e_ehsize;
|
||||||
u16 e_phentsize;
|
uint16_t e_phentsize;
|
||||||
u16 e_phnum;
|
uint16_t e_phnum;
|
||||||
u16 e_shentsize;
|
uint16_t e_shentsize;
|
||||||
u16 e_shnum;
|
uint16_t e_shnum;
|
||||||
u16 e_shstrndx;
|
uint16_t e_shstrndx;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ELFProgramHeader {
|
struct ELFProgramHeader {
|
||||||
u32 type;
|
uint32_t type;
|
||||||
u32 offset;
|
uint32_t offset;
|
||||||
u32 vaddr;
|
uint32_t vaddr;
|
||||||
u32 paddr;
|
uint32_t paddr;
|
||||||
u32 filesz;
|
uint32_t filesz;
|
||||||
u32 memsz;
|
uint32_t memsz;
|
||||||
u32 flags;
|
uint32_t flags;
|
||||||
u32 align;
|
uint32_t align;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ELFSectionHeader {
|
struct ELFSectionHeader {
|
||||||
u32 name;
|
uint32_t name;
|
||||||
u32 type;
|
uint32_t type;
|
||||||
u32 flags;
|
uint32_t flags;
|
||||||
u32 addr;
|
uint32_t addr;
|
||||||
u32 offset;
|
uint32_t offset;
|
||||||
u32 size;
|
uint32_t size;
|
||||||
u32 link;
|
uint32_t link;
|
||||||
u32 info;
|
uint32_t info;
|
||||||
u32 addralign;
|
uint32_t addralign;
|
||||||
u32 entsize;
|
uint32_t entsize;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ELFSymbol {
|
struct ELFSymbol {
|
||||||
u32 name;
|
uint32_t name;
|
||||||
u32 value;
|
uint32_t value;
|
||||||
u32 size;
|
uint32_t size;
|
||||||
u8 info;
|
uint8_t info;
|
||||||
u8 other;
|
uint8_t other;
|
||||||
u16 shndx;
|
uint16_t shndx;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ELFBlock {
|
struct ELFBlock {
|
||||||
int length;
|
int length;
|
||||||
u8* data;
|
uint8_t* data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ELFAttr {
|
struct ELFAttr {
|
||||||
u32 name;
|
uint32_t name;
|
||||||
u32 form;
|
uint32_t form;
|
||||||
union {
|
union {
|
||||||
u32 value;
|
uint32_t value;
|
||||||
char* string;
|
char* string;
|
||||||
u8* data;
|
uint8_t* data;
|
||||||
bool flag;
|
bool flag;
|
||||||
ELFBlock* block;
|
ELFBlock* block;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ELFAbbrev {
|
struct ELFAbbrev {
|
||||||
u32 number;
|
uint32_t number;
|
||||||
u32 tag;
|
uint32_t tag;
|
||||||
bool hasChildren;
|
bool hasChildren;
|
||||||
int numAttrs;
|
int numAttrs;
|
||||||
ELFAttr* attrs;
|
ELFAttr* attrs;
|
||||||
|
@ -132,7 +132,7 @@ struct Array {
|
||||||
|
|
||||||
struct EnumMember {
|
struct EnumMember {
|
||||||
char* name;
|
char* name;
|
||||||
u32 value;
|
uint32_t value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Enum {
|
struct Enum {
|
||||||
|
@ -141,7 +141,7 @@ struct Enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Type {
|
struct Type {
|
||||||
u32 offset;
|
uint32_t offset;
|
||||||
TypeEnum type;
|
TypeEnum type;
|
||||||
const char* name;
|
const char* name;
|
||||||
int encoding;
|
int encoding;
|
||||||
|
@ -164,15 +164,15 @@ struct Object {
|
||||||
bool external;
|
bool external;
|
||||||
Type* type;
|
Type* type;
|
||||||
ELFBlock* location;
|
ELFBlock* location;
|
||||||
u32 startScope;
|
uint32_t startScope;
|
||||||
u32 endScope;
|
uint32_t endScope;
|
||||||
Object* next;
|
Object* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Function {
|
struct Function {
|
||||||
char* name;
|
char* name;
|
||||||
u32 lowPC;
|
uint32_t lowPC;
|
||||||
u32 highPC;
|
uint32_t highPC;
|
||||||
int file;
|
int file;
|
||||||
int line;
|
int line;
|
||||||
bool external;
|
bool external;
|
||||||
|
@ -184,7 +184,7 @@ struct Function {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LineInfoItem {
|
struct LineInfoItem {
|
||||||
u32 address;
|
uint32_t address;
|
||||||
char* file;
|
char* file;
|
||||||
int line;
|
int line;
|
||||||
};
|
};
|
||||||
|
@ -197,28 +197,28 @@ struct LineInfo {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ARange {
|
struct ARange {
|
||||||
u32 lowPC;
|
uint32_t lowPC;
|
||||||
u32 highPC;
|
uint32_t highPC;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ARanges {
|
struct ARanges {
|
||||||
u32 offset;
|
uint32_t offset;
|
||||||
int count;
|
int count;
|
||||||
ARange* ranges;
|
ARange* ranges;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CompileUnit {
|
struct CompileUnit {
|
||||||
u32 length;
|
uint32_t length;
|
||||||
u8* top;
|
uint8_t* top;
|
||||||
u32 offset;
|
uint32_t offset;
|
||||||
ELFAbbrev** abbrevs;
|
ELFAbbrev** abbrevs;
|
||||||
ARanges* ranges;
|
ARanges* ranges;
|
||||||
char* name;
|
char* name;
|
||||||
char* compdir;
|
char* compdir;
|
||||||
u32 lowPC;
|
uint32_t lowPC;
|
||||||
u32 highPC;
|
uint32_t highPC;
|
||||||
bool hasLineInfo;
|
bool hasLineInfo;
|
||||||
u32 lineInfo;
|
uint32_t lineInfo;
|
||||||
LineInfo* lineInfoTable;
|
LineInfo* lineInfoTable;
|
||||||
Function* functions;
|
Function* functions;
|
||||||
Function* lastFunction;
|
Function* lastFunction;
|
||||||
|
@ -228,10 +228,10 @@ struct CompileUnit {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DebugInfo {
|
struct DebugInfo {
|
||||||
u8* debugfile;
|
uint8_t* debugfile;
|
||||||
u8* abbrevdata;
|
uint8_t* abbrevdata;
|
||||||
u8* debugdata;
|
uint8_t* debugdata;
|
||||||
u8* infodata;
|
uint8_t* infodata;
|
||||||
int numRanges;
|
int numRanges;
|
||||||
ARanges* ranges;
|
ARanges* ranges;
|
||||||
};
|
};
|
||||||
|
@ -240,24 +240,24 @@ struct Symbol {
|
||||||
const char* name;
|
const char* name;
|
||||||
int type;
|
int type;
|
||||||
int binding;
|
int binding;
|
||||||
u32 address;
|
uint32_t address;
|
||||||
u32 value;
|
uint32_t value;
|
||||||
u32 size;
|
uint32_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern u32 elfReadLEB128(u8*, int*);
|
extern uint32_t elfReadLEB128(uint8_t*, int*);
|
||||||
extern s32 elfReadSignedLEB128(u8*, int*);
|
extern int32_t elfReadSignedLEB128(uint8_t*, int*);
|
||||||
extern bool elfRead(const char*, int&, FILE* f);
|
extern bool elfRead(const char*, int&, FILE* f);
|
||||||
extern bool elfGetSymbolAddress(const char*, u32*, u32*, int*);
|
extern bool elfGetSymbolAddress(const char*, uint32_t*, uint32_t*, int*);
|
||||||
extern const char* elfGetAddressSymbol(u32);
|
extern const char* elfGetAddressSymbol(uint32_t);
|
||||||
extern const char* elfGetSymbol(int, u32*, u32*, int*);
|
extern const char* elfGetSymbol(int, uint32_t*, uint32_t*, int*);
|
||||||
extern void elfCleanUp();
|
extern void elfCleanUp();
|
||||||
extern bool elfGetCurrentFunction(u32, Function**, CompileUnit** c);
|
extern bool elfGetCurrentFunction(uint32_t, Function**, CompileUnit** c);
|
||||||
extern bool elfGetObject(const char*, Function*, CompileUnit*, Object**);
|
extern bool elfGetObject(const char*, Function*, CompileUnit*, Object**);
|
||||||
extern bool elfFindLineInUnit(u32*, CompileUnit*, int);
|
extern bool elfFindLineInUnit(uint32_t*, CompileUnit*, int);
|
||||||
extern bool elfFindLineInModule(u32*, const char*, int);
|
extern bool elfFindLineInModule(uint32_t*, const char*, int);
|
||||||
u32 elfDecodeLocation(Function*, ELFBlock*, LocationType*);
|
uint32_t elfDecodeLocation(Function*, ELFBlock*, LocationType*);
|
||||||
u32 elfDecodeLocation(Function*, ELFBlock*, LocationType*, u32);
|
uint32_t elfDecodeLocation(Function*, ELFBlock*, LocationType*, uint32_t);
|
||||||
int elfFindLine(CompileUnit* unit, Function* func, u32 addr, const char**);
|
int elfFindLine(CompileUnit* unit, Function* func, uint32_t addr, const char**);
|
||||||
|
|
||||||
#endif // ELF_H
|
#endif // ELF_H
|
||||||
|
|
|
@ -80,7 +80,7 @@ int dotcodepointer;
|
||||||
int dotcodeinterleave;
|
int dotcodeinterleave;
|
||||||
int decodestate;
|
int decodestate;
|
||||||
|
|
||||||
u32 GFpow;
|
uint32_t GFpow;
|
||||||
|
|
||||||
unsigned char* DotCodeData;
|
unsigned char* DotCodeData;
|
||||||
char filebuffer[2048];
|
char filebuffer[2048];
|
||||||
|
@ -108,9 +108,9 @@ int CheckEReaderRegion(void) //US = 1, JAP = 2, JAP+ = 3
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LoadDotCodeData(int size, u32* DCdata, unsigned long MEM1, unsigned long MEM2, int loadraw)
|
int LoadDotCodeData(int size, uint32_t* DCdata, unsigned long MEM1, unsigned long MEM2, int loadraw)
|
||||||
{
|
{
|
||||||
u32 temp1;
|
uint32_t temp1;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
unsigned char scanmap[28];
|
unsigned char scanmap[28];
|
||||||
|
@ -201,17 +201,17 @@ int LoadDotCodeData(int size, u32* DCdata, unsigned long MEM1, unsigned long MEM
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EReaderWriteMemory(u32 address, u32 value)
|
void EReaderWriteMemory(uint32_t address, uint32_t value)
|
||||||
{
|
{
|
||||||
switch (address >> 24) {
|
switch (address >> 24) {
|
||||||
case 2:
|
case 2:
|
||||||
WRITE32LE(((u32*)&workRAM[address & 0x3FFFF]), value);
|
WRITE32LE(((uint32_t*)&workRAM[address & 0x3FFFF]), value);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
WRITE32LE(((u32*)&internalRAM[address & 0x7FFF]), value);
|
WRITE32LE(((uint32_t*)&internalRAM[address & 0x7FFF]), value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
WRITE32LE(((u32*)&rom[address & 0x1FFFFFF]), value);
|
WRITE32LE(((uint32_t*)&rom[address & 0x1FFFFFF]), value);
|
||||||
//rom[address & 0x1FFFFFF] = data;
|
//rom[address & 0x1FFFFFF] = data;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -271,15 +271,15 @@ void BIOS_EReader_ScanCard(int swi_num)
|
||||||
|
|
||||||
switch (CheckEReaderRegion()) {
|
switch (CheckEReaderRegion()) {
|
||||||
case 1: //US
|
case 1: //US
|
||||||
LoadDotCodeData(i, (u32*)DotCodeData, 0x2032D14, 0x2028B28, 1);
|
LoadDotCodeData(i, (uint32_t*)DotCodeData, 0x2032D14, 0x2028B28, 1);
|
||||||
EReaderWriteMemory(0x80091BA, 0x46C0DFE2);
|
EReaderWriteMemory(0x80091BA, 0x46C0DFE2);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
LoadDotCodeData(i, (u32*)DotCodeData, 0x2006EC4, 0x2002478, 1);
|
LoadDotCodeData(i, (uint32_t*)DotCodeData, 0x2006EC4, 0x2002478, 1);
|
||||||
EReaderWriteMemory(0x8008B12, 0x46C0DFE2);
|
EReaderWriteMemory(0x8008B12, 0x46C0DFE2);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
LoadDotCodeData(i, (u32*)DotCodeData, 0x202F8A4, 0x2031034, 1);
|
LoadDotCodeData(i, (uint32_t*)DotCodeData, 0x202F8A4, 0x2031034, 1);
|
||||||
EReaderWriteMemory(0x800922E, 0x46C0DFE2);
|
EReaderWriteMemory(0x800922E, 0x46C0DFE2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -294,15 +294,15 @@ void BIOS_EReader_ScanCard(int swi_num)
|
||||||
|
|
||||||
switch (CheckEReaderRegion()) {
|
switch (CheckEReaderRegion()) {
|
||||||
case 1: //US
|
case 1: //US
|
||||||
LoadDotCodeData(dotcodesize, (u32*)NULL, 0x2032D14, 0x2028B28, 0);
|
LoadDotCodeData(dotcodesize, (uint32_t*)NULL, 0x2032D14, 0x2028B28, 0);
|
||||||
EReaderWriteMemory(0x80091BA, 0x46C0DFE1);
|
EReaderWriteMemory(0x80091BA, 0x46C0DFE1);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
LoadDotCodeData(dotcodesize, (u32*)NULL, 0x2006EC4, 0x2002478, 0);
|
LoadDotCodeData(dotcodesize, (uint32_t*)NULL, 0x2006EC4, 0x2002478, 0);
|
||||||
EReaderWriteMemory(0x8008B12, 0x46C0DFE1);
|
EReaderWriteMemory(0x8008B12, 0x46C0DFE1);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
LoadDotCodeData(dotcodesize, (u32*)NULL, 0x202F8A4, 0x2031034, 0);
|
LoadDotCodeData(dotcodesize, (uint32_t*)NULL, 0x202F8A4, 0x2031034, 0);
|
||||||
EReaderWriteMemory(0x800922E, 0x46C0DFE1);
|
EReaderWriteMemory(0x800922E, 0x46C0DFE1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ extern char filebuffer[];
|
||||||
|
|
||||||
int OpenDotCodeFile(void);
|
int OpenDotCodeFile(void);
|
||||||
int CheckEReaderRegion(void);
|
int CheckEReaderRegion(void);
|
||||||
int LoadDotCodeData(int size, u32* DCdata, unsigned long MEM1, unsigned long MEM2);
|
int LoadDotCodeData(int size, uint32_t* DCdata, unsigned long MEM1, unsigned long MEM2);
|
||||||
void EReaderWriteMemory(u32 address, u32 value);
|
void EReaderWriteMemory(uint32_t address, uint32_t value);
|
||||||
|
|
||||||
void BIOS_EReader_ScanCard(int swi_num);
|
void BIOS_EReader_ScanCard(int swi_num);
|
||||||
|
|
Loading…
Reference in New Issue