From fe28af3bed4a2542513070641605621ee61c3b34 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 8 Jun 2011 01:13:47 +0000 Subject: [PATCH] Added stubs for mips support --- Makefile | 5 ++++ src/arch/Makefile | 17 ++++++++++-- src/arch/mips.c | 59 +++++++++++++++++++++++++++++++++++++++ src/arch/mips.h | 44 +++++++++++++++++++++++++++++ src/arch/mips.ins | 26 ++++++++++++++++++ src/arch/mips.reg | 64 +++++++++++++++++++++++++++++++++++++++++++ src/arch/project.conf | 12 ++++++-- src/format/elf.c | 1 + test/Makefile | 10 +++++-- test/mips.S | 2 ++ test/project.conf | 10 ++++++- 11 files changed, 243 insertions(+), 7 deletions(-) create mode 100644 src/arch/mips.c create mode 100644 src/arch/mips.h create mode 100644 src/arch/mips.ins create mode 100644 src/arch/mips.reg create mode 100644 test/mips.S diff --git a/Makefile b/Makefile index a4c9abf..c4a1938 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,7 @@ dist: $(PACKAGE)-$(VERSION)/src/arch/i586.c \ $(PACKAGE)-$(VERSION)/src/arch/i686.c \ $(PACKAGE)-$(VERSION)/src/arch/java.c \ + $(PACKAGE)-$(VERSION)/src/arch/mips.c \ $(PACKAGE)-$(VERSION)/src/arch/sparc.c \ $(PACKAGE)-$(VERSION)/src/arch/sparc64.c \ $(PACKAGE)-$(VERSION)/src/arch/Makefile \ @@ -72,6 +73,9 @@ dist: $(PACKAGE)-$(VERSION)/src/arch/i586.ins \ $(PACKAGE)-$(VERSION)/src/arch/i686.ins \ $(PACKAGE)-$(VERSION)/src/arch/i686.reg \ + $(PACKAGE)-$(VERSION)/src/arch/mips.h \ + $(PACKAGE)-$(VERSION)/src/arch/mips.ins \ + $(PACKAGE)-$(VERSION)/src/arch/mips.reg \ $(PACKAGE)-$(VERSION)/src/arch/null.ins \ $(PACKAGE)-$(VERSION)/src/arch/sparc.h \ $(PACKAGE)-$(VERSION)/src/arch/sparc.ins \ @@ -91,6 +95,7 @@ dist: $(PACKAGE)-$(VERSION)/test/i486.S \ $(PACKAGE)-$(VERSION)/test/i586.S \ $(PACKAGE)-$(VERSION)/test/i686.S \ + $(PACKAGE)-$(VERSION)/test/mips.S \ $(PACKAGE)-$(VERSION)/test/java.S \ $(PACKAGE)-$(VERSION)/test/sparc.S \ $(PACKAGE)-$(VERSION)/test/sparc64.S \ diff --git a/src/arch/Makefile b/src/arch/Makefile index eec1156..a7c7de4 100644 --- a/src/arch/Makefile +++ b/src/arch/Makefile @@ -1,4 +1,4 @@ -TARGETS = amd64.so dalvik.so i386.so i386_real.so i486.so i586.so i686.so java.so sparc.so sparc64.so +TARGETS = amd64.so dalvik.so i386.so i386_real.so i486.so i586.so i686.so java.so mips.so sparc.so sparc64.so PREFIX = /usr/local DESTDIR = LIBDIR = $(PREFIX)/lib @@ -74,6 +74,13 @@ java_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) java.so: $(java_OBJS) $(LD) -o java.so $(java_OBJS) $(java_LDFLAGS) +mips_OBJS = mips.o +mips_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) +mips_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) + +mips.so: $(mips_OBJS) + $(LD) -o mips.so $(mips_OBJS) $(mips_LDFLAGS) + sparc_OBJS = sparc.o sparc_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) sparc_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) @@ -112,6 +119,9 @@ i686.o: i686.c common.ins null.ins i386.h i386.ins i386.reg i486.ins i686.ins i6 java.o: java.c common.ins null.ins $(CC) $(java_CFLAGS) -c java.c +mips.o: mips.c common.ins null.ins mips.h mips.ins mips.reg + $(CC) $(mips_CFLAGS) -c mips.c + sparc.o: sparc.c common.ins null.ins sparc.h sparc.ins sparc.reg $(CC) $(sparc_CFLAGS) -c sparc.c @@ -119,7 +129,7 @@ sparc64.o: sparc64.c common.ins null.ins sparc.h sparc.ins sparc.reg $(CC) $(sparc64_CFLAGS) -c sparc64.c clean: - $(RM) -- $(amd64_OBJS) $(dalvik_OBJS) $(i386_OBJS) $(i386_real_OBJS) $(i486_OBJS) $(i586_OBJS) $(i686_OBJS) $(java_OBJS) $(sparc_OBJS) $(sparc64_OBJS) + $(RM) -- $(amd64_OBJS) $(dalvik_OBJS) $(i386_OBJS) $(i386_real_OBJS) $(i486_OBJS) $(i586_OBJS) $(i686_OBJS) $(java_OBJS) $(mips_OBJS) $(sparc_OBJS) $(sparc64_OBJS) distclean: clean $(RM) -- $(TARGETS) @@ -142,6 +152,8 @@ install: $(TARGETS) $(MKDIR) $(DESTDIR)$(LIBDIR)/asm/arch $(INSTALL) -m 0644 -- java.so $(DESTDIR)$(LIBDIR)/asm/arch/java.so $(MKDIR) $(DESTDIR)$(LIBDIR)/asm/arch + $(INSTALL) -m 0644 -- mips.so $(DESTDIR)$(LIBDIR)/asm/arch/mips.so + $(MKDIR) $(DESTDIR)$(LIBDIR)/asm/arch $(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 @@ -155,6 +167,7 @@ uninstall: $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/i586.so $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/i686.so $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/java.so + $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/mips.so $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/sparc.so $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/sparc64.so diff --git a/src/arch/mips.c b/src/arch/mips.c new file mode 100644 index 0000000..7d26b8f --- /dev/null +++ b/src/arch/mips.c @@ -0,0 +1,59 @@ +/* $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 . */ + + + +#include +#include "Asm.h" + + +/* mips */ +/* private */ +/* variables */ +static ArchDescription _mips_description = { "elf", ARCH_ENDIAN_BIG, 32, 32 }; + +#define REG(name, size, id) { "" # name, size, id }, +static ArchRegister _mips_registers[] = +{ +#include "mips.reg" + { NULL, 0, 0 } +}; +#undef REG + +static ArchInstruction _mips_instructions[] = +{ +#include "mips.ins" +#include "common.ins" +#include "null.ins" +}; + + +/* functions */ +/* plug-in */ +#include "mips.h" + + +/* protected */ +/* variables */ +ArchPlugin arch_plugin = +{ + NULL, + "mips", + &_mips_description, + _mips_registers, + _mips_instructions, + _mips_write, + NULL +}; diff --git a/src/arch/mips.h b/src/arch/mips.h new file mode 100644 index 0000000..acce2c7 --- /dev/null +++ b/src/arch/mips.h @@ -0,0 +1,44 @@ +/* $Id$ */ +/* Copyright (c) 2011 Pierre Pronchery */ +/* This file is part of DeforaOS Devel as */ +/* 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 . */ + + + +#include + + +/* mips */ +/* private */ +/* prototypes */ +/* plug-in */ +static int _mips_write(ArchPlugin * plugin, ArchInstruction * instruction, + ArchInstructionCall * call); + + +/* functions */ +/* plug-in */ +/* mips_write */ +static int _mips_write(ArchPlugin * plugin, ArchInstruction * instruction, + ArchInstructionCall * call) +{ + ArchPluginHelper * helper = plugin->helper; + uint32_t opcode = instruction->opcode; + + /* FIXME really implement */ + opcode = _htob32(opcode); + if(helper->write(helper->arch, &opcode, sizeof(opcode)) + != sizeof(opcode)) + return -1; + return 0; +} diff --git a/src/arch/mips.ins b/src/arch/mips.ins new file mode 100644 index 0000000..b4a1636 --- /dev/null +++ b/src/arch/mips.ins @@ -0,0 +1,26 @@ +/* $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 . */ + + + +/* generic */ +/* registers */ + +/* opcodes */ +#define OPNOP AO_IMMEDIATE(0, 32, 0) + + +/* instructions */ +{ "nop", 0x00000000, OPNOP, AOT_NONE, AOT_NONE, AOT_NONE }, diff --git a/src/arch/mips.reg b/src/arch/mips.reg new file mode 100644 index 0000000..232ea03 --- /dev/null +++ b/src/arch/mips.reg @@ -0,0 +1,64 @@ +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) +REG(r16, 32, 0x10) +REG(r17, 32, 0x11) +REG(r18, 32, 0x12) +REG(r19, 32, 0x13) +REG(r20, 32, 0x14) +REG(r21, 32, 0x15) +REG(r22, 32, 0x16) +REG(r23, 32, 0x17) +REG(r24, 32, 0x18) +REG(r25, 32, 0x19) +REG(r26, 32, 0x1a) +REG(r27, 32, 0x1b) +REG(r28, 32, 0x1c) +REG(r29, 32, 0x1d) +REG(r30, 32, 0x1e) +REG(r31, 32, 0x1f) +REG(f0, 32, 0x31) +REG(f1, 32, 0x32) +REG(f2, 32, 0x33) +REG(f3, 32, 0x34) +REG(f4, 32, 0x35) +REG(f5, 32, 0x36) +REG(f6, 32, 0x37) +REG(f7, 32, 0x38) +REG(f8, 32, 0x39) +REG(f9, 32, 0x3a) +REG(f10, 32, 0x3b) +REG(f11, 32, 0x3c) +REG(f12, 32, 0x3d) +REG(f13, 32, 0x3e) +REG(f14, 32, 0x3f) +REG(f15, 32, 0x40) +REG(f16, 32, 0x41) +REG(f17, 32, 0x42) +REG(f18, 32, 0x43) +REG(f19, 32, 0x44) +REG(f20, 32, 0x45) +REG(f21, 32, 0x46) +REG(f22, 32, 0x47) +REG(f23, 32, 0x48) +REG(f24, 32, 0x49) +REG(f25, 32, 0x4a) +REG(f26, 32, 0x4b) +REG(f27, 32, 0x4c) +REG(f28, 32, 0x4d) +REG(f29, 32, 0x4e) +REG(f30, 32, 0x4f) +REG(f31, 32, 0x50) diff --git a/src/arch/project.conf b/src/arch/project.conf index 59a0e0b..a602e55 100644 --- a/src/arch/project.conf +++ b/src/arch/project.conf @@ -1,8 +1,8 @@ -targets=amd64,dalvik,i386,i386_real,i486,i586,i686,java,sparc,sparc64 +targets=amd64,dalvik,i386,i386_real,i486,i586,i686,java,mips,sparc,sparc64 cppflags_force=-I ../../include cflags_force=-W `pkg-config --cflags libSystem` cflags=-Wall -g -O2 -fPIC -pedantic -dist=Makefile,amd64.ins,amd64.reg,common.ins,dalvik.ins,dalvik.reg,i386.h,i386.ins,i386.reg,i486.ins,i586.ins,i686.ins,i686.reg,null.ins,sparc.h,sparc.ins,sparc.reg +dist=Makefile,amd64.ins,amd64.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 [amd64] type=plugin @@ -68,6 +68,14 @@ install=$(LIBDIR)/asm/arch [java.c] depends=common.ins,null.ins +[mips] +type=plugin +sources=mips.c +install=$(LIBDIR)/asm/arch + +[mips.c] +depends=common.ins,null.ins,mips.h,mips.ins,mips.reg + [sparc] type=plugin sources=sparc.c diff --git a/src/format/elf.c b/src/format/elf.c index 57d2841..6b2256c 100644 --- a/src/format/elf.c +++ b/src/format/elf.c @@ -100,6 +100,7 @@ static ElfArch elf_arch[] = { "i486", EM_386, ELFCLASS32, ELFDATA2LSB }, { "i586", EM_386, ELFCLASS32, ELFDATA2LSB }, { "i686", EM_386, ELFCLASS32, ELFDATA2LSB }, + { "mips", EM_MIPS, ELFCLASS32, ELFDATA2MSB }, { "sparc", EM_SPARC, ELFCLASS32, ELFDATA2MSB }, { "sparc64", EM_SPARCV9, ELFCLASS64, ELFDATA2MSB }, { NULL, '\0', '\0', '\0' } diff --git a/test/Makefile b/test/Makefile index 4e42d6c..4728441 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,4 +1,4 @@ -TARGETS = amd64.o dalvik.o i386.o i386_real.o i486.o i586.o i686.o java.o sparc.o sparc64.o +TARGETS = amd64.o dalvik.o i386.o i386_real.o i486.o i586.o i686.o mips.o java.o sparc.o sparc64.o PREFIX = /usr/local DESTDIR = BINDIR = $(PREFIX)/bin @@ -33,6 +33,9 @@ i586.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a i586 i686.o_OBJS = i686.o i686.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a i686 +mips.o_OBJS = mips.o +mips.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a mips + java.o_OBJS = java.o java.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a java -f flat @@ -63,6 +66,9 @@ i586.o: i586.S ../src/asm i686.o: i686.S ../src/asm $(AS) $(i686.o_ASFLAGS) -o i686.o i686.S +mips.o: mips.S ../src/asm + $(AS) $(mips.o_ASFLAGS) -o mips.o mips.S + java.o: java.S ../src/asm $(AS) $(java.o_ASFLAGS) -o java.o java.S @@ -73,7 +79,7 @@ sparc64.o: sparc64.S ../src/asm $(AS) $(sparc64.o_ASFLAGS) -o sparc64.o sparc64.S clean: - $(RM) -- $(amd64.o_OBJS) $(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) + $(RM) -- $(amd64.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) distclean: clean $(RM) -- $(TARGETS) diff --git a/test/mips.S b/test/mips.S new file mode 100644 index 0000000..d1836f2 --- /dev/null +++ b/test/mips.S @@ -0,0 +1,2 @@ +.text + nop diff --git a/test/project.conf b/test/project.conf index 542c1ce..4608bd6 100644 --- a/test/project.conf +++ b/test/project.conf @@ -1,4 +1,4 @@ -targets=amd64.o,dalvik.o,i386.o,i386_real.o,i486.o,i586.o,i686.o,java.o,sparc.o,sparc64.o +targets=amd64.o,dalvik.o,i386.o,i386_real.o,i486.o,i586.o,i686.o,mips.o,java.o,sparc.o,sparc64.o as=../src/asm-static dist=Makefile @@ -66,6 +66,14 @@ sources=java.S asflags=-a java -f flat depends=../src/asm +[mips.o] +type=object +sources=mips.S + +[mips.S] +asflags=-a mips +depends=../src/asm + [sparc.o] type=object sources=sparc.S