Beginning to encode and test Dalvik instructions again

This commit is contained in:
Pierre Pronchery 2011-04-23 01:12:37 +00:00
parent c4aef2db4f
commit 438ef5939a
5 changed files with 63 additions and 4 deletions

View File

@ -81,6 +81,7 @@ dist:
$(PACKAGE)-$(VERSION)/src/format/pe.c \
$(PACKAGE)-$(VERSION)/src/format/Makefile \
$(PACKAGE)-$(VERSION)/src/format/project.conf \
$(PACKAGE)-$(VERSION)/test/dalvik.S \
$(PACKAGE)-$(VERSION)/test/i386.S \
$(PACKAGE)-$(VERSION)/test/i386_real.S \
$(PACKAGE)-$(VERSION)/test/i486.S \

View File

@ -63,6 +63,12 @@ static ArchInstruction _dalvik_instructions[] =
};
/* prototypes */
/* plug-in */
static int _dalvik_write(ArchPlugin * plugin, ArchInstruction * instruction,
ArchInstructionCall * call);
/* public */
/* variables */
ArchPlugin arch_plugin =
@ -72,6 +78,42 @@ ArchPlugin arch_plugin =
&_dalvik_description,
_dalvik_registers,
_dalvik_instructions,
NULL,
_dalvik_write,
NULL
};
/* private */
/* functions */
/* dalvik_write */
static int _dalvik_write(ArchPlugin * plugin, ArchInstruction * instruction,
ArchInstructionCall * call)
{
ArchPluginHelper * helper = plugin->helper;
uint8_t u8;
uint16_t u16;
unsigned char const * buf;
size_t size;
/* FIXME really implement */
switch(AO_GET_SIZE(instruction->flags))
{
case 8:
u8 = instruction->opcode;
buf = &u8;
size = sizeof(u8);
break;
case 16:
u16 = _htol16(instruction->opcode);
buf = &u16;
size = sizeof(u16);
break;
default:
/* FIXME should not happen */
return -error_set_code(1, "%s: %s", helper->filename,
"Invalid size for opcode");
}
if(fwrite(buf, size, 1, helper->fp) != 1)
return -1; /* XXX report error */
return 0;
}

View File

@ -1,4 +1,4 @@
TARGETS = i386.o i386_real.o i486.o i586.o i686.o java.o sparc.o sparc64.o
TARGETS = dalvik.o i386.o i386_real.o i486.o i586.o i686.o java.o sparc.o sparc64.o
PREFIX = /usr/local
DESTDIR =
BINDIR = $(PREFIX)/bin
@ -12,6 +12,9 @@ INSTALL = install
all: $(TARGETS)
dalvik.o_OBJS = dalvik.o
dalvik.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a dalvik -f flat
i386.o_OBJS = i386.o
i386.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a i386
@ -36,6 +39,9 @@ sparc.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a sparc
sparc64.o_OBJS = sparc64.o
sparc64.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a sparc64
dalvik.o: dalvik.S ../src/asm
$(AS) $(dalvik.o_ASFLAGS) -o dalvik.o dalvik.S
i386.o: i386.S ../src/asm
$(AS) $(i386.o_ASFLAGS) -o i386.o i386.S
@ -61,7 +67,7 @@ sparc64.o: sparc64.S ../src/asm
$(AS) $(sparc64.o_ASFLAGS) -o sparc64.o sparc64.S
clean:
$(RM) -- $(i386.o_OBJS) $(i386_real.o_OBJS) $(i486.o_OBJS) $(i586.o_OBJS) $(i686.o_OBJS) $(java.o_OBJS) $(sparc.o_OBJS) $(sparc64.o_OBJS)
$(RM) -- $(dalvik.o_OBJS) $(i386.o_OBJS) $(i386_real.o_OBJS) $(i486.o_OBJS) $(i586.o_OBJS) $(i686.o_OBJS) $(java.o_OBJS) $(sparc.o_OBJS) $(sparc64.o_OBJS)
distclean: clean
$(RM) -- $(TARGETS)

2
test/dalvik.S Normal file
View File

@ -0,0 +1,2 @@
.text
nop

View File

@ -1,7 +1,15 @@
targets=i386.o,i386_real.o,i486.o,i586.o,i686.o,java.o,sparc.o,sparc64.o
targets=dalvik.o,i386.o,i386_real.o,i486.o,i586.o,i686.o,java.o,sparc.o,sparc64.o
as=../src/asm
dist=Makefile
[dalvik.o]
type=object
sources=dalvik.S
[dalvik.S]
asflags=-a dalvik -f flat
depends=../src/asm
[i386.o]
type=object
sources=i386.S