Assembling the first yasep instructions

This commit is contained in:
Pierre Pronchery 2011-09-28 12:23:46 +00:00
parent fa4614af23
commit 72cf6186e3
8 changed files with 101 additions and 8 deletions

View File

@ -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 \

View File

@ -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

View File

@ -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

View File

@ -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;
}

16
src/arch/yasep.reg Normal file
View File

@ -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)

View File

@ -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)

View File

@ -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

3
test/yasep.S Normal file
View File

@ -0,0 +1,3 @@
/* $Id$ */
.text
add %r0, %r1