Move ARM disassembler out of libacc and into the acc command-line tool.
This commit is contained in:
parent
d62ae8f12f
commit
d5315573d7
8 changed files with 76 additions and 90 deletions
|
@ -77,6 +77,12 @@ void accGetScriptLabel(ACCscript* script, const ACCchar * name,
|
|||
void accGetPragmas(ACCscript* script, ACCsizei* actualStringCount,
|
||||
ACCsizei maxStringCount, ACCchar** strings);
|
||||
|
||||
/* Used to implement disassembly */
|
||||
|
||||
void accGetProgramBinary(ACCscript* script,
|
||||
ACCvoid** base,
|
||||
ACCsizei* length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -7,10 +7,6 @@ include $(CLEAR_VARS)
|
|||
LOCAL_MODULE:= libacc
|
||||
LOCAL_SRC_FILES := acc.cpp
|
||||
|
||||
ifeq ($(TARGET_ARCH),arm)
|
||||
LOCAL_SRC_FILES += disassem.cpp
|
||||
endif
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := libdl libcutils
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
@ -24,10 +20,6 @@ LOCAL_SRC_FILES := acc.cpp
|
|||
|
||||
LOCAL_CFLAGS := -O0 -g
|
||||
|
||||
ifeq ($(TARGET_ARCH),arm)
|
||||
LOCAL_SRC_FILES += disassem.cpp
|
||||
endif
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := libcutils
|
||||
LOCAL_LDLIBS := -ldl
|
||||
|
||||
|
|
|
@ -39,10 +39,6 @@
|
|||
#define PROVIDE_X64_CODEGEN
|
||||
#endif
|
||||
|
||||
#ifdef PROVIDE_ARM_CODEGEN
|
||||
#include "disassem.h"
|
||||
#endif
|
||||
|
||||
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
|
||||
#define ARM_USE_VFP
|
||||
#endif
|
||||
|
@ -55,7 +51,6 @@
|
|||
#define LOG_STACK(...) do {} while(0)
|
||||
// #define LOG_STACK(...) fprintf (stderr, __VA_ARGS__)
|
||||
|
||||
#define ENABLE_ARM_DISASSEMBLY
|
||||
// #define PROVIDE_TRACE_CODEGEN
|
||||
|
||||
// Uncomment to save input to a text file in DEBUG_DUMP_PATTERN
|
||||
|
@ -484,11 +479,6 @@ class Compiler : public ErrorSink {
|
|||
*/
|
||||
virtual void adjustStackAfterCall(Type* pDecl, int l, bool isIndirect) = 0;
|
||||
|
||||
/* Print a disassembly of the assembled code to out. Return
|
||||
* non-zero if there is an error.
|
||||
*/
|
||||
virtual int disassemble(FILE* out) = 0;
|
||||
|
||||
/* Generate a symbol at the current PC. t is the head of a
|
||||
* linked list of addresses to patch.
|
||||
*/
|
||||
|
@ -695,9 +685,9 @@ class Compiler : public ErrorSink {
|
|||
public:
|
||||
ARMCodeGenerator() {
|
||||
#ifdef ARM_USE_VFP
|
||||
LOGD("Using ARM VFP hardware floating point.");
|
||||
// LOGD("Using ARM VFP hardware floating point.");
|
||||
#else
|
||||
LOGD("Using ARM soft floating point.");
|
||||
// LOGD("Using ARM soft floating point.");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1764,24 +1754,6 @@ class Compiler : public ErrorSink {
|
|||
#endif
|
||||
}
|
||||
|
||||
virtual int disassemble(FILE* out) {
|
||||
#ifdef ENABLE_ARM_DISASSEMBLY
|
||||
disasmOut = out;
|
||||
disasm_interface_t di;
|
||||
di.di_readword = disassemble_readword;
|
||||
di.di_printaddr = disassemble_printaddr;
|
||||
di.di_printf = disassemble_printf;
|
||||
|
||||
int base = getBase();
|
||||
int pc = getPC();
|
||||
for(int i = base; i < pc; i += 4) {
|
||||
fprintf(out, "%08x: %08x ", i, *(int*) i);
|
||||
::disasm(&di, i, 0);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* alignment (in bytes) for this type of data
|
||||
*/
|
||||
|
@ -1833,27 +1805,6 @@ class Compiler : public ErrorSink {
|
|||
}
|
||||
|
||||
private:
|
||||
static FILE* disasmOut;
|
||||
|
||||
static u_int
|
||||
disassemble_readword(u_int address)
|
||||
{
|
||||
return(*((u_int *)address));
|
||||
}
|
||||
|
||||
static void
|
||||
disassemble_printaddr(u_int address)
|
||||
{
|
||||
fprintf(disasmOut, "0x%08x", address);
|
||||
}
|
||||
|
||||
static void
|
||||
disassemble_printf(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vfprintf(disasmOut, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
static const int BRANCH_REL_ADDRESS_MASK = 0x00ffffff;
|
||||
|
||||
|
@ -2783,10 +2734,6 @@ class Compiler : public ErrorSink {
|
|||
return 5;
|
||||
}
|
||||
|
||||
virtual int disassemble(FILE* out) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* output a symbol and patch all calls to it */
|
||||
virtual void gsym(int t) {
|
||||
int n;
|
||||
|
@ -3114,10 +3061,6 @@ class Compiler : public ErrorSink {
|
|||
return mpBase->jumpOffset();
|
||||
}
|
||||
|
||||
virtual int disassemble(FILE* out) {
|
||||
return mpBase->disassemble(out);
|
||||
}
|
||||
|
||||
/* output a symbol and patch all calls to it */
|
||||
virtual void gsym(int t) {
|
||||
fprintf(stderr, "gsym(%d)\n", t);
|
||||
|
@ -5755,15 +5698,6 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
int dump(FILE* out) {
|
||||
fwrite(codeBuf.getBase(), 1, codeBuf.getSize(), out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int disassemble(FILE* out) {
|
||||
return pGen->disassemble(out);
|
||||
}
|
||||
|
||||
/* Look through the symbol table to find a symbol.
|
||||
* If found, return its value.
|
||||
*/
|
||||
|
@ -5796,10 +5730,14 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void getProgramBinary(ACCvoid** base, ACCsizei* length) {
|
||||
*base = codeBuf.getBase();
|
||||
*length = (ACCsizei) codeBuf.getSize();
|
||||
}
|
||||
|
||||
char* getErrorMessage() {
|
||||
return mErrorBuf.getUnwrapped();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const char* Compiler::operatorChars =
|
||||
|
@ -5813,10 +5751,6 @@ const char Compiler::operatorLevel[] =
|
|||
2, 2 /* ~ ! */
|
||||
};
|
||||
|
||||
#ifdef PROVIDE_ARM_CODEGEN
|
||||
FILE* Compiler::ARMCodeGenerator::disasmOut;
|
||||
#endif
|
||||
|
||||
#ifdef PROVIDE_X86_CODEGEN
|
||||
const int Compiler::X86CodeGenerator::operatorHelper[] = {
|
||||
0x1, // ++
|
||||
|
@ -6014,8 +5948,9 @@ void accGetPragmas(ACCscript* script, ACCsizei* actualStringCount,
|
|||
}
|
||||
|
||||
extern "C"
|
||||
void accDisassemble(ACCscript* script) {
|
||||
script->compiler.disassemble(stderr);
|
||||
void accGetProgramBinary(ACCscript* script,
|
||||
ACCvoid** base, ACCsizei* length) {
|
||||
script->compiler.getProgramBinary(base, length);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ include $(CLEAR_VARS)
|
|||
LOCAL_MODULE:= acc
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
main.cpp
|
||||
main.cpp \
|
||||
disassem.cpp
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libacc
|
||||
|
|
|
@ -20,6 +20,14 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if defined(__arm__)
|
||||
#define PROVIDE_ARM_DISASSEMBLY
|
||||
#endif
|
||||
|
||||
#ifdef PROVIDE_ARM_DISASSEMBLY
|
||||
#include "disassem.h"
|
||||
#endif
|
||||
|
||||
#include <acc/acc.h>
|
||||
|
||||
|
||||
|
@ -29,15 +37,57 @@ int run(MainPtr mainFunc, int argc, char** argv) {
|
|||
return mainFunc(argc, argv);
|
||||
}
|
||||
|
||||
// Private API for development:
|
||||
|
||||
extern "C"
|
||||
void accDisassemble(ACCscript* script);
|
||||
|
||||
ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name) {
|
||||
return (ACCvoid*) dlsym(RTLD_DEFAULT, name);
|
||||
}
|
||||
|
||||
#ifdef PROVIDE_ARM_DISASSEMBLY
|
||||
|
||||
static FILE* disasmOut;
|
||||
|
||||
static u_int
|
||||
disassemble_readword(u_int address)
|
||||
{
|
||||
return(*((u_int *)address));
|
||||
}
|
||||
|
||||
static void
|
||||
disassemble_printaddr(u_int address)
|
||||
{
|
||||
fprintf(disasmOut, "0x%08x", address);
|
||||
}
|
||||
|
||||
static void
|
||||
disassemble_printf(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vfprintf(disasmOut, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
static int disassemble(ACCscript* script, FILE* out) {
|
||||
disasmOut = out;
|
||||
disasm_interface_t di;
|
||||
di.di_readword = disassemble_readword;
|
||||
di.di_printaddr = disassemble_printaddr;
|
||||
di.di_printf = disassemble_printf;
|
||||
|
||||
ACCvoid* base;
|
||||
ACCsizei length;
|
||||
|
||||
accGetProgramBinary(script, &base, &length);
|
||||
unsigned long* pBase = (unsigned long*) base;
|
||||
unsigned long* pEnd = (unsigned long*) (((unsigned char*) base) + length);
|
||||
|
||||
for(unsigned long* pInstruction = pBase; pInstruction < pEnd; pInstruction++) {
|
||||
fprintf(out, "%08x: %08x ", (int) pInstruction, *pInstruction);
|
||||
::disasm(&di, (uint) pInstruction, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // PROVIDE_ARM_DISASSEMBLY
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
const char* inFile = NULL;
|
||||
bool printListing;
|
||||
|
@ -121,7 +171,9 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
|
||||
if (printListing) {
|
||||
accDisassemble(script);
|
||||
#ifdef PROVIDE_ARM_DISASSEMBLY
|
||||
disassemble(script, stderr);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (runResults) {
|
||||
|
|
Loading…
Reference in a new issue