From 72cf6186e3ce2504634b786f4cde8da5cc22a19d Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 28 Sep 2011 12:23:46 +0000 Subject: [PATCH] Assembling the first yasep instructions --- Makefile | 1 + src/arch/Makefile | 3 +++ src/arch/project.conf | 5 ++-- src/arch/yasep.c | 61 ++++++++++++++++++++++++++++++++++++++++--- src/arch/yasep.reg | 16 ++++++++++++ test/Makefile | 10 +++++-- test/project.conf | 10 ++++++- test/yasep.S | 3 +++ 8 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 src/arch/yasep.reg create mode 100644 test/yasep.S diff --git a/Makefile b/Makefile index e98eddb..0e439d0 100644 --- a/Makefile +++ b/Makefile @@ -106,6 +106,7 @@ dist: $(PACKAGE)-$(VERSION)/test/java.S \ $(PACKAGE)-$(VERSION)/test/sparc.S \ $(PACKAGE)-$(VERSION)/test/sparc64.S \ + $(PACKAGE)-$(VERSION)/test/yasep.S \ $(PACKAGE)-$(VERSION)/test/Makefile \ $(PACKAGE)-$(VERSION)/test/project.conf \ $(PACKAGE)-$(VERSION)/Makefile \ diff --git a/src/arch/Makefile b/src/arch/Makefile index 78089bb..ebce8d8 100644 --- a/src/arch/Makefile +++ b/src/arch/Makefile @@ -179,6 +179,8 @@ install: $(TARGETS) $(INSTALL) -m 0644 -- sparc.so $(DESTDIR)$(LIBDIR)/asm/arch/sparc.so $(MKDIR) $(DESTDIR)$(LIBDIR)/asm/arch $(INSTALL) -m 0644 -- sparc64.so $(DESTDIR)$(LIBDIR)/asm/arch/sparc64.so + $(MKDIR) $(DESTDIR)$(LIBDIR)/asm/arch + $(INSTALL) -m 0644 -- yasep.so $(DESTDIR)$(LIBDIR)/asm/arch/yasep.so uninstall: $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/amd64.so @@ -193,5 +195,6 @@ uninstall: $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/mips.so $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/sparc.so $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/sparc64.so + $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/yasep.so .PHONY: all clean distclean install uninstall diff --git a/src/arch/project.conf b/src/arch/project.conf index 3ffd5ef..f3c11dd 100644 --- a/src/arch/project.conf +++ b/src/arch/project.conf @@ -2,7 +2,7 @@ targets=amd64,arm,dalvik,i386,i386_real,i486,i586,i686,java,mips,sparc,sparc64,y cppflags_force=-I ../../include cflags_force=-W `pkg-config --cflags libSystem` cflags=-Wall -g -O2 -fPIC -pedantic -dist=Makefile,amd64.ins,amd64.reg,arm.h,arm.ins,arm.reg,common.ins,dalvik.ins,dalvik.reg,i386.h,i386.ins,i386.reg,i486.ins,i586.ins,i686.ins,i686.reg,mips.h,mips.ins,mips.reg,null.ins,sparc.h,sparc.ins,sparc.reg,yasep.ins +dist=Makefile,amd64.ins,amd64.reg,arm.h,arm.ins,arm.reg,common.ins,dalvik.ins,dalvik.reg,i386.h,i386.ins,i386.reg,i486.ins,i586.ins,i686.ins,i686.reg,mips.h,mips.ins,mips.reg,null.ins,sparc.h,sparc.ins,sparc.reg,yasep.ins,yasep.reg [amd64] type=plugin @@ -103,6 +103,7 @@ depends=common.ins,null.ins,sparc.h,sparc.ins,sparc.reg [yasep] type=plugin sources=yasep.c +install=$(LIBDIR)/asm/arch [yasep.c] -depends=common.ins,null.ins,yasep.ins +depends=common.ins,null.ins,yasep.ins,yasep.reg diff --git a/src/arch/yasep.c b/src/arch/yasep.c index 8bd97d1..0ea6999 100644 --- a/src/arch/yasep.c +++ b/src/arch/yasep.c @@ -22,6 +22,15 @@ /* yasep */ /* private */ /* variables */ +/* plug-in */ +#define REG(name, size, id) { "" # name, size, id }, +static ArchRegister _yasep_registers[] = +{ +#include "yasep.reg" + { NULL, 0, 0 } +}; +#undef REG + static ArchInstruction _yasep_instructions[] = { #include "yasep.ins" @@ -30,8 +39,10 @@ static ArchInstruction _yasep_instructions[] = }; -/* functions */ +/* prototypes */ /* plug-in */ +static int _yasep_write(ArchPlugin * plugin, ArchInstruction * instruction, + ArchInstructionCall * call); /* protected */ @@ -41,10 +52,54 @@ ArchPlugin arch_plugin = NULL, "yasep", NULL, - NULL, + _yasep_registers, _yasep_instructions, NULL, NULL, - NULL, + _yasep_write, NULL }; + + +/* private */ +/* functions */ +/* plug-in */ +/* yasep_write */ +static int _write_16(ArchPlugin * plugin, ArchInstruction * instruction, + ArchInstructionCall * call); +static int _write_32(ArchPlugin * plugin, ArchInstruction * instruction, + ArchInstructionCall * call); + +static int _yasep_write(ArchPlugin * plugin, ArchInstruction * instruction, + ArchInstructionCall * call) +{ + return (instruction->opcode & 0x1) + ? _write_32(plugin, instruction, call) + : _write_16(plugin, instruction, call); +} + +static int _write_16(ArchPlugin * plugin, ArchInstruction * instruction, + ArchInstructionCall * call) +{ + ArchPluginHelper * helper = plugin->helper; + uint16_t opcode = instruction->opcode; + + opcode = _htob16(opcode); + if(helper->write(helper->arch, &opcode, sizeof(opcode)) + != sizeof(opcode)) + return -1; + return 0; +} + +static int _write_32(ArchPlugin * plugin, ArchInstruction * instruction, + ArchInstructionCall * call) +{ + ArchPluginHelper * helper = plugin->helper; + uint32_t opcode = instruction->opcode; + + opcode = _htob32(opcode); + if(helper->write(helper->arch, &opcode, sizeof(opcode)) + != sizeof(opcode)) + return -1; + return 0; +} diff --git a/src/arch/yasep.reg b/src/arch/yasep.reg new file mode 100644 index 0000000..3db9272 --- /dev/null +++ b/src/arch/yasep.reg @@ -0,0 +1,16 @@ +REG(r0, 32, 0x00) +REG(r1, 32, 0x01) +REG(r2, 32, 0x02) +REG(r3, 32, 0x03) +REG(r4, 32, 0x04) +REG(r5, 32, 0x05) +REG(r6, 32, 0x06) +REG(r7, 32, 0x07) +REG(r8, 32, 0x08) +REG(r9, 32, 0x09) +REG(r10, 32, 0x0a) +REG(r11, 32, 0x0b) +REG(r12, 32, 0x0c) +REG(r13, 32, 0x0d) +REG(r14, 32, 0x0e) +REG(r15, 32, 0x0f) diff --git a/test/Makefile b/test/Makefile index 52d5a31..e312ef9 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,4 +1,4 @@ -TARGETS = amd64.o arm.o dalvik.o i386.o i386_real.o i486.o i586.o i686.o mips.o java.o sparc.o sparc64.o +TARGETS = amd64.o arm.o dalvik.o i386.o i386_real.o i486.o i586.o i686.o mips.o java.o sparc.o sparc64.o yasep.o PREFIX = /usr/local DESTDIR = BINDIR = $(PREFIX)/bin @@ -48,6 +48,9 @@ sparc.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a sparc sparc64.o_OBJS = sparc64.o sparc64.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a sparc64 +yasep.o_OBJS = yasep.o +yasep.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a yasep -f flat + amd64.o: amd64.S ../src/asm $(AS) $(amd64.o_ASFLAGS) -o amd64.o amd64.S @@ -84,8 +87,11 @@ sparc.o: sparc.S ../src/asm sparc64.o: sparc64.S ../src/asm $(AS) $(sparc64.o_ASFLAGS) -o sparc64.o sparc64.S +yasep.o: yasep.S ../src/asm + $(AS) $(yasep.o_ASFLAGS) -o yasep.o yasep.S + clean: - $(RM) -- $(amd64.o_OBJS) $(arm.o_OBJS) $(dalvik.o_OBJS) $(i386.o_OBJS) $(i386_real.o_OBJS) $(i486.o_OBJS) $(i586.o_OBJS) $(i686.o_OBJS) $(mips.o_OBJS) $(java.o_OBJS) $(sparc.o_OBJS) $(sparc64.o_OBJS) + $(RM) -- $(amd64.o_OBJS) $(arm.o_OBJS) $(dalvik.o_OBJS) $(i386.o_OBJS) $(i386_real.o_OBJS) $(i486.o_OBJS) $(i586.o_OBJS) $(i686.o_OBJS) $(mips.o_OBJS) $(java.o_OBJS) $(sparc.o_OBJS) $(sparc64.o_OBJS) $(yasep.o_OBJS) distclean: clean $(RM) -- $(TARGETS) diff --git a/test/project.conf b/test/project.conf index 9a63b9d..4f70251 100644 --- a/test/project.conf +++ b/test/project.conf @@ -1,4 +1,4 @@ -targets=amd64.o,arm.o,dalvik.o,i386.o,i386_real.o,i486.o,i586.o,i686.o,mips.o,java.o,sparc.o,sparc64.o +targets=amd64.o,arm.o,dalvik.o,i386.o,i386_real.o,i486.o,i586.o,i686.o,mips.o,java.o,sparc.o,sparc64.o,yasep.o as=../src/asm-static dist=Makefile @@ -97,3 +97,11 @@ sources=sparc64.S [sparc64.S] asflags=-a sparc64 depends=../src/asm + +[yasep.o] +type=object +sources=yasep.S + +[yasep.S] +asflags=-a yasep -f flat +depends=../src/asm diff --git a/test/yasep.S b/test/yasep.S new file mode 100644 index 0000000..9b44926 --- /dev/null +++ b/test/yasep.S @@ -0,0 +1,3 @@ +/* $Id$ */ +.text + add %r0, %r1