diff --git a/Makefile b/Makefile index 6c52f71..dd22cf8 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,7 @@ dist: $(PACKAGE)-$(VERSION)/src/arch/sparc.c \ $(PACKAGE)-$(VERSION)/src/arch/sparc64.c \ $(PACKAGE)-$(VERSION)/src/arch/yasep.c \ + $(PACKAGE)-$(VERSION)/src/arch/yasep16.c \ $(PACKAGE)-$(VERSION)/src/arch/Makefile \ $(PACKAGE)-$(VERSION)/src/arch/amd64.ins \ $(PACKAGE)-$(VERSION)/src/arch/amd64.reg \ @@ -121,6 +122,7 @@ dist: $(PACKAGE)-$(VERSION)/test/sparc.S \ $(PACKAGE)-$(VERSION)/test/sparc64.S \ $(PACKAGE)-$(VERSION)/test/yasep.S \ + $(PACKAGE)-$(VERSION)/test/yasep16.S \ $(PACKAGE)-$(VERSION)/test/Makefile \ $(PACKAGE)-$(VERSION)/test/project.conf \ $(PACKAGE)-$(VERSION)/Makefile \ diff --git a/src/arch/Makefile b/src/arch/Makefile index de2e65c..e660014 100644 --- a/src/arch/Makefile +++ b/src/arch/Makefile @@ -1,4 +1,4 @@ -TARGETS = amd64.so arm.so armeb.so armel.so dalvik.so i386.so i386_real.so i486.so i586.so i686.so java.so mips.so mipseb.so mipsel.so sparc.so sparc64.so yasep.so +TARGETS = amd64.so arm.so armeb.so armel.so dalvik.so i386.so i386_real.so i486.so i586.so i686.so java.so mips.so mipseb.so mipsel.so sparc.so sparc64.so yasep.so yasep16.so PREFIX = /usr/local DESTDIR = LIBDIR = $(PREFIX)/lib @@ -137,6 +137,13 @@ yasep_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) yasep.so: $(yasep_OBJS) $(CCSHARED) -o yasep.so $(yasep_OBJS) $(yasep_LDFLAGS) +yasep16_OBJS = yasep16.o +yasep16_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) +yasep16_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) + +yasep16.so: $(yasep16_OBJS) + $(CCSHARED) -o yasep16.so $(yasep16_OBJS) $(yasep16_LDFLAGS) + amd64.o: amd64.c amd64.ins amd64.reg common.ins null.ins i386.h i386.ins i386.reg i486.ins i686.ins i686.reg $(CC) $(amd64_CFLAGS) -c amd64.c @@ -188,8 +195,11 @@ sparc64.o: sparc64.c common.ins null.ins sparc.h sparc.ins sparc.reg yasep.o: yasep.c common.ins null.ins yasep.ins yasep.reg $(CC) $(yasep_CFLAGS) -c yasep.c +yasep16.o: yasep16.c common.ins null.ins yasep.ins yasep.reg + $(CC) $(yasep16_CFLAGS) -c yasep16.c + clean: - $(RM) -- $(amd64_OBJS) $(arm_OBJS) $(armeb_OBJS) $(armel_OBJS) $(dalvik_OBJS) $(i386_OBJS) $(i386_real_OBJS) $(i486_OBJS) $(i586_OBJS) $(i686_OBJS) $(java_OBJS) $(mips_OBJS) $(mipseb_OBJS) $(mipsel_OBJS) $(sparc_OBJS) $(sparc64_OBJS) $(yasep_OBJS) + $(RM) -- $(amd64_OBJS) $(arm_OBJS) $(armeb_OBJS) $(armel_OBJS) $(dalvik_OBJS) $(i386_OBJS) $(i386_real_OBJS) $(i486_OBJS) $(i586_OBJS) $(i686_OBJS) $(java_OBJS) $(mips_OBJS) $(mipseb_OBJS) $(mipsel_OBJS) $(sparc_OBJS) $(sparc64_OBJS) $(yasep_OBJS) $(yasep16_OBJS) distclean: clean $(RM) -- $(TARGETS) @@ -229,6 +239,8 @@ install: $(TARGETS) $(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 + $(MKDIR) $(DESTDIR)$(LIBDIR)/asm/arch + $(INSTALL) -m 0644 -- yasep16.so $(DESTDIR)$(LIBDIR)/asm/arch/yasep16.so uninstall: $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/amd64.so @@ -248,5 +260,6 @@ uninstall: $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/sparc.so $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/sparc64.so $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/yasep.so + $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/yasep16.so .PHONY: all clean distclean install uninstall diff --git a/src/arch/project.conf b/src/arch/project.conf index 6a13f47..c02b7b1 100644 --- a/src/arch/project.conf +++ b/src/arch/project.conf @@ -1,4 +1,4 @@ -targets=amd64,arm,armeb,armel,dalvik,i386,i386_real,i486,i586,i686,java,mips,mipseb,mipsel,sparc,sparc64,yasep +targets=amd64,arm,armeb,armel,dalvik,i386,i386_real,i486,i586,i686,java,mips,mipseb,mipsel,sparc,sparc64,yasep,yasep16 cppflags_force=-I ../../include cflags_force=-W `pkg-config --cflags libSystem` cflags=-Wall -g -O2 -fPIC -pedantic @@ -139,3 +139,11 @@ install=$(LIBDIR)/asm/arch [yasep.c] depends=common.ins,null.ins,yasep.ins,yasep.reg + +[yasep16] +type=plugin +sources=yasep16.c +install=$(LIBDIR)/asm/arch + +[yasep16.c] +depends=common.ins,null.ins,yasep.ins,yasep.reg diff --git a/src/arch/yasep.c b/src/arch/yasep.c index 6eac656..37622b2 100644 --- a/src/arch/yasep.c +++ b/src/arch/yasep.c @@ -17,13 +17,22 @@ #include #include "Asm.h" -#define ARCH_yasep32 +#ifndef ARCH_yasep +# define ARCH_yasep 32 +# define ARCH_yasep32 +# define _yasep_name "yasep" +#endif /* yasep */ /* private */ /* variables */ /* plug-in */ +static ArchDescription _yasep_description = +{ + "flat", ARCH_ENDIAN_LITTLE, 32, 16, 0 +}; + #define REG(name, size, id) { "" # name, size, id }, static ArchRegister _yasep_registers[] = { @@ -47,13 +56,13 @@ static int _yasep_encode(ArchPlugin * plugin, ArchInstruction * instruction, static int _yasep_decode(ArchPlugin * plugin, ArchInstructionCall * call); -/* protected */ +/* public */ /* variables */ ArchPlugin arch_plugin = { NULL, - "yasep", - NULL, + _yasep_name, + &_yasep_description, _yasep_registers, _yasep_instructions, NULL, diff --git a/src/arch/yasep.ins b/src/arch/yasep.ins index b71bfe0..9dd1eac 100644 --- a/src/arch/yasep.ins +++ b/src/arch/yasep.ins @@ -1,5 +1,6 @@ /* $Id$ */ /* Copyright (c) 2011 Pierre Pronchery */ +/* Copyright (c) 2011 Yann Guidon */ /* This file is part of DeforaOS Devel asm */ /* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/arch/yasep16.c b/src/arch/yasep16.c new file mode 100644 index 0000000..3f1330d --- /dev/null +++ b/src/arch/yasep16.c @@ -0,0 +1,21 @@ +/* $Id$ */ +/* Copyright (c) 2011 Pierre Pronchery */ +/* This file is part of DeforaOS Devel asm */ +/* This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + + + +#define ARCH_yasep 16 +#define ARCH_yasep16 +#define _yasep_name "yasep16" +#include "yasep.c" diff --git a/src/parser.c b/src/parser.c index 72dd6ac..48d7d65 100644 --- a/src/parser.c +++ b/src/parser.c @@ -40,12 +40,12 @@ typedef struct _State /* prototypes */ -static int _parser_scan(State * state); static int _parser_check(State * state, TokenCode code); +static int _parser_defines(State * state, AsmPrefs * ap); +static int _parser_error(State * state, char const * format, ...); static int _parser_is_code(State * state, TokenCode code); static int _parser_in_set(State * state, TokenSet set); - -static int _parser_error(State * state, char const * format, ...); +static int _parser_scan(State * state); static int _parser_warning(State * state, char const * format, ...); /* grammar */ @@ -132,6 +132,31 @@ static int _parser_check(State * state, TokenCode code) } +/* parser_defines */ +static int _parser_defines(State * state, AsmPrefs * ap) +{ + int ret = 0; + char const * p; + char * q; + size_t len; + size_t i; + + if((p = asmcode_get_arch(state->code)) != NULL + && (len = strlen(p)) > 0) + { + if((q = malloc(len + 5)) == NULL) + return -error_set_code(1, "%s", strerror(errno)); + snprintf(q, len + 5, "__%s__", p); + ret |= cpp_define_add(state->cpp, q, NULL); + free(q); + } + if(ret == 0 && ap != NULL) + for(i = 0; i < ap->defines_cnt; i++) + ret |= cpp_define_add(state->cpp, ap->defines[i], NULL); + return ret; +} + + /* parser_is_code */ static int _parser_is_code(State * state, TokenCode code) { @@ -193,7 +218,6 @@ int parser(AsmPrefs * ap, AsmCode * code, char const * infile) { CppPrefs prefs; State state; - size_t i; memset(&prefs, 0, sizeof(prefs)); prefs.filename = infile; @@ -202,12 +226,16 @@ int parser(AsmPrefs * ap, AsmCode * code, char const * infile) state.code = code; if((state.cpp = cpp_new(&prefs)) == NULL) return -1; - if(ap != NULL) - for(i = 0; i < ap->defines_cnt; i++) - /* FIXME check errors */ - cpp_define_add(state.cpp, ap->defines[i], NULL); + if(_parser_defines(&state, ap) != 0) + { + cpp_delete(state.cpp); + return -1; + } if(_parser_scan(&state) != 0) + { + cpp_delete(state.cpp); return _parser_error(&state, "%s", error_get()); + } if(_program(&state) != 0) error_set_code(1, "%s%s%u%s%u%s", infile, ": Compilation failed with ", state.error_cnt, diff --git a/test/Makefile b/test/Makefile index 9d9a31b..f48b778 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,4 +1,4 @@ -TARGETS = amd64.o arm.o armeb.o armel.o dalvik.o i386.o i386_real.o i486.o i586.o i686.o mips.o mipseb.o mipsel.o java.o sparc.o sparc64.o yasep.o +TARGETS = amd64.o arm.o armeb.o armel.o dalvik.o i386.o i386_real.o i486.o i586.o i686.o mips.o mipseb.o mipsel.o java.o sparc.o sparc64.o yasep.o yasep16.o PREFIX = /usr/local DESTDIR = BINDIR = $(PREFIX)/bin @@ -63,6 +63,9 @@ sparc64.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a sparc64 yasep.o_OBJS = yasep.o yasep.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a yasep -f flat +yasep16.o_OBJS = yasep16.o +yasep16.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a yasep16 -f flat + amd64.o: amd64.S ../src/asm $(AS) $(amd64.o_ASFLAGS) -o amd64.o amd64.S @@ -114,8 +117,11 @@ sparc64.o: sparc64.S ../src/asm yasep.o: yasep.S ../src/asm $(AS) $(yasep.o_ASFLAGS) -o yasep.o yasep.S +yasep16.o: yasep16.S ../src/asm yasep.S + $(AS) $(yasep16.o_ASFLAGS) -o yasep16.o yasep16.S + clean: - $(RM) -- $(amd64.o_OBJS) $(arm.o_OBJS) $(armeb.o_OBJS) $(armel.o_OBJS) $(dalvik.o_OBJS) $(i386.o_OBJS) $(i386_real.o_OBJS) $(i486.o_OBJS) $(i586.o_OBJS) $(i686.o_OBJS) $(mips.o_OBJS) $(mipseb.o_OBJS) $(mipsel.o_OBJS) $(java.o_OBJS) $(sparc.o_OBJS) $(sparc64.o_OBJS) $(yasep.o_OBJS) + $(RM) -- $(amd64.o_OBJS) $(arm.o_OBJS) $(armeb.o_OBJS) $(armel.o_OBJS) $(dalvik.o_OBJS) $(i386.o_OBJS) $(i386_real.o_OBJS) $(i486.o_OBJS) $(i586.o_OBJS) $(i686.o_OBJS) $(mips.o_OBJS) $(mipseb.o_OBJS) $(mipsel.o_OBJS) $(java.o_OBJS) $(sparc.o_OBJS) $(sparc64.o_OBJS) $(yasep.o_OBJS) $(yasep16.o_OBJS) distclean: clean $(RM) -- $(TARGETS) diff --git a/test/project.conf b/test/project.conf index 9facf7a..a099ea2 100644 --- a/test/project.conf +++ b/test/project.conf @@ -1,4 +1,4 @@ -targets=amd64.o,arm.o,armeb.o,armel.o,dalvik.o,i386.o,i386_real.o,i486.o,i586.o,i686.o,mips.o,mipseb.o,mipsel.o,java.o,sparc.o,sparc64.o,yasep.o +targets=amd64.o,arm.o,armeb.o,armel.o,dalvik.o,i386.o,i386_real.o,i486.o,i586.o,i686.o,mips.o,mipseb.o,mipsel.o,java.o,sparc.o,sparc64.o,yasep.o,yasep16.o as=../src/asm-static dist=Makefile @@ -137,3 +137,11 @@ sources=yasep.S [yasep.S] asflags=-a yasep -f flat depends=../src/asm + +[yasep16.o] +type=object +sources=yasep16.S + +[yasep16.S] +asflags=-a yasep16 -f flat +depends=../src/asm,yasep.S diff --git a/test/yasep.S b/test/yasep.S index 3b04af7..bba791a 100644 --- a/test/yasep.S +++ b/test/yasep.S @@ -13,9 +13,13 @@ get $0x09, %r1 get %r10, %r11 lsb %r12, %r13 +#ifdef __yasep__ lsh %r14, %r15 +#endif lzb %npc, %d5 +#ifdef __yasep__ lzh %a5, %d4 +#endif mov $0x04, %a4 mov %d3, %a3 mul8h $0x03, %d2 @@ -41,10 +45,12 @@ sar %r0, %r1 sb $0x08, %r1 sb %r0, %r1 +#ifdef __yasep__ sh $0x09, %r1 sh %r0, %r1 shh $0x0a, %r1 shh %r0, %r1 +#endif shl $0x0b, %r1 shl %r0, %r1 shr $0x0c, %r1 diff --git a/test/yasep16.S b/test/yasep16.S new file mode 100644 index 0000000..985453f --- /dev/null +++ b/test/yasep16.S @@ -0,0 +1,2 @@ +/* $Id$ */ +#include "yasep.S"