From 74130f88fe8a7e41eff66fd41784a9da31107409 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Thu, 9 Jun 2011 18:05:05 +0000 Subject: [PATCH] Added stub files for ARM support as well --- Makefile | 5 ++++ src/arch/Makefile | 17 ++++++++++-- src/arch/arm.c | 59 +++++++++++++++++++++++++++++++++++++++ src/arch/arm.h | 44 +++++++++++++++++++++++++++++ src/arch/arm.ins | 27 ++++++++++++++++++ src/arch/arm.reg | 64 +++++++++++++++++++++++++++++++++++++++++++ src/arch/project.conf | 12 ++++++-- src/format/elf.c | 1 + test/Makefile | 10 +++++-- test/arm.S | 2 ++ test/project.conf | 10 ++++++- 11 files changed, 244 insertions(+), 7 deletions(-) create mode 100644 src/arch/arm.c create mode 100644 src/arch/arm.h create mode 100644 src/arch/arm.ins create mode 100644 src/arch/arm.reg create mode 100644 test/arm.S diff --git a/Makefile b/Makefile index c4a1938..7544ca0 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,7 @@ dist: $(PACKAGE)-$(VERSION)/src/token.h \ $(PACKAGE)-$(VERSION)/src/project.conf \ $(PACKAGE)-$(VERSION)/src/arch/amd64.c \ + $(PACKAGE)-$(VERSION)/src/arch/arm.c \ $(PACKAGE)-$(VERSION)/src/arch/dalvik.c \ $(PACKAGE)-$(VERSION)/src/arch/i386.c \ $(PACKAGE)-$(VERSION)/src/arch/i386_real.c \ @@ -63,6 +64,9 @@ dist: $(PACKAGE)-$(VERSION)/src/arch/Makefile \ $(PACKAGE)-$(VERSION)/src/arch/amd64.ins \ $(PACKAGE)-$(VERSION)/src/arch/amd64.reg \ + $(PACKAGE)-$(VERSION)/src/arch/arm.h \ + $(PACKAGE)-$(VERSION)/src/arch/arm.ins \ + $(PACKAGE)-$(VERSION)/src/arch/arm.reg \ $(PACKAGE)-$(VERSION)/src/arch/common.ins \ $(PACKAGE)-$(VERSION)/src/arch/dalvik.ins \ $(PACKAGE)-$(VERSION)/src/arch/dalvik.reg \ @@ -89,6 +93,7 @@ dist: $(PACKAGE)-$(VERSION)/src/format/Makefile \ $(PACKAGE)-$(VERSION)/src/format/project.conf \ $(PACKAGE)-$(VERSION)/test/amd64.S \ + $(PACKAGE)-$(VERSION)/test/arm.S \ $(PACKAGE)-$(VERSION)/test/dalvik.S \ $(PACKAGE)-$(VERSION)/test/i386.S \ $(PACKAGE)-$(VERSION)/test/i386_real.S \ diff --git a/src/arch/Makefile b/src/arch/Makefile index a7c7de4..b99f909 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 mips.so sparc.so sparc64.so +TARGETS = amd64.so arm.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 @@ -25,6 +25,13 @@ amd64_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) amd64.so: $(amd64_OBJS) $(LD) -o amd64.so $(amd64_OBJS) $(amd64_LDFLAGS) +arm_OBJS = arm.o +arm_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) +arm_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) + +arm.so: $(arm_OBJS) + $(LD) -o arm.so $(arm_OBJS) $(arm_LDFLAGS) + dalvik_OBJS = dalvik.o dalvik_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) dalvik_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) @@ -98,6 +105,9 @@ sparc64.so: $(sparc64_OBJS) 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 +arm.o: arm.c arm.h arm.ins arm.reg common.ins null.ins + $(CC) $(arm_CFLAGS) -c arm.c + dalvik.o: dalvik.c common.ins null.ins dalvik.ins dalvik.reg $(CC) $(dalvik_CFLAGS) -c dalvik.c @@ -129,7 +139,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) $(mips_OBJS) $(sparc_OBJS) $(sparc64_OBJS) + $(RM) -- $(amd64_OBJS) $(arm_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) @@ -138,6 +148,8 @@ install: $(TARGETS) $(MKDIR) $(DESTDIR)$(LIBDIR)/asm/arch $(INSTALL) -m 0644 -- amd64.so $(DESTDIR)$(LIBDIR)/asm/arch/amd64.so $(MKDIR) $(DESTDIR)$(LIBDIR)/asm/arch + $(INSTALL) -m 0644 -- arm.so $(DESTDIR)$(LIBDIR)/asm/arch/arm.so + $(MKDIR) $(DESTDIR)$(LIBDIR)/asm/arch $(INSTALL) -m 0644 -- dalvik.so $(DESTDIR)$(LIBDIR)/asm/arch/dalvik.so $(MKDIR) $(DESTDIR)$(LIBDIR)/asm/arch $(INSTALL) -m 0644 -- i386.so $(DESTDIR)$(LIBDIR)/asm/arch/i386.so @@ -160,6 +172,7 @@ install: $(TARGETS) uninstall: $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/amd64.so + $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/arm.so $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/dalvik.so $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/i386.so $(RM) -- $(DESTDIR)$(LIBDIR)/asm/arch/i386_real.so diff --git a/src/arch/arm.c b/src/arch/arm.c new file mode 100644 index 0000000..614ae0f --- /dev/null +++ b/src/arch/arm.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" + + +/* arm */ +/* private */ +/* variables */ +static ArchDescription _arm_description = { "elf", ARCH_ENDIAN_BIG, 32, 32 }; + +#define REG(name, size, id) { "" # name, size, id }, +static ArchRegister _arm_registers[] = +{ +#include "arm.reg" + { NULL, 0, 0 } +}; +#undef REG + +static ArchInstruction _arm_instructions[] = +{ +#include "arm.ins" +#include "common.ins" +#include "null.ins" +}; + + +/* functions */ +/* plug-in */ +#include "arm.h" + + +/* protected */ +/* variables */ +ArchPlugin arch_plugin = +{ + NULL, + "arm", + &_arm_description, + _arm_registers, + _arm_instructions, + _arm_write, + NULL +}; diff --git a/src/arch/arm.h b/src/arch/arm.h new file mode 100644 index 0000000..2b82c5a --- /dev/null +++ b/src/arch/arm.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 + + +/* arm */ +/* private */ +/* prototypes */ +/* plug-in */ +static int _arm_write(ArchPlugin * plugin, ArchInstruction * instruction, + ArchInstructionCall * call); + + +/* functions */ +/* plug-in */ +/* arm_write */ +static int _arm_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/arm.ins b/src/arch/arm.ins new file mode 100644 index 0000000..97dffd1 --- /dev/null +++ b/src/arch/arm.ins @@ -0,0 +1,27 @@ +/* $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 */ +/* FIXME verify */ +{ "nop", 0x00000000, OPNOP, AOT_NONE, AOT_NONE, AOT_NONE }, diff --git a/src/arch/arm.reg b/src/arch/arm.reg new file mode 100644 index 0000000..232ea03 --- /dev/null +++ b/src/arch/arm.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 a602e55..44a072e 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,mips,sparc,sparc64 +targets=amd64,arm,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,mips.h,mips.ins,mips.reg,null.ins,sparc.h,sparc.ins,sparc.reg +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 [amd64] type=plugin @@ -12,6 +12,14 @@ install=$(LIBDIR)/asm/arch [amd64.c] depends=amd64.ins,amd64.reg,common.ins,null.ins,i386.h,i386.ins,i386.reg,i486.ins,i686.ins,i686.reg +[arm] +type=plugin +sources=arm.c +install=$(LIBDIR)/asm/arch + +[arm.c] +depends=arm.h,arm.ins,arm.reg,common.ins,null.ins + [dalvik] type=plugin sources=dalvik.c diff --git a/src/format/elf.c b/src/format/elf.c index 6b2256c..fff8441 100644 --- a/src/format/elf.c +++ b/src/format/elf.c @@ -96,6 +96,7 @@ static int _elfstrtab_set(FormatPlugin * format, ElfStrtab * strtab, static ElfArch elf_arch[] = { { "amd64", EM_X86_64, ELFCLASS64, ELFDATA2LSB }, + { "arm", EM_ARM, ELFCLASS32, ELFDATA2MSB }, { "i386", EM_386, ELFCLASS32, ELFDATA2LSB }, { "i486", EM_386, ELFCLASS32, ELFDATA2LSB }, { "i586", EM_386, ELFCLASS32, ELFDATA2LSB }, diff --git a/test/Makefile b/test/Makefile index 4728441..6b51be4 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 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 PREFIX = /usr/local DESTDIR = BINDIR = $(PREFIX)/bin @@ -15,6 +15,9 @@ all: $(TARGETS) amd64.o_OBJS = amd64.o amd64.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a amd64 +arm.o_OBJS = arm.o +arm.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a arm + dalvik.o_OBJS = dalvik.o dalvik.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a dalvik -f flat @@ -48,6 +51,9 @@ sparc64.o_ASFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(ASFLAGS) -a sparc64 amd64.o: amd64.S ../src/asm $(AS) $(amd64.o_ASFLAGS) -o amd64.o amd64.S +arm.o: arm.S ../src/asm + $(AS) $(arm.o_ASFLAGS) -o arm.o arm.S + dalvik.o: dalvik.S ../src/asm $(AS) $(dalvik.o_ASFLAGS) -o dalvik.o dalvik.S @@ -79,7 +85,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) $(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) distclean: clean $(RM) -- $(TARGETS) diff --git a/test/arm.S b/test/arm.S new file mode 100644 index 0000000..d1836f2 --- /dev/null +++ b/test/arm.S @@ -0,0 +1,2 @@ +.text + nop diff --git a/test/project.conf b/test/project.conf index 4608bd6..9a63b9d 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,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 as=../src/asm-static dist=Makefile @@ -10,6 +10,14 @@ sources=amd64.S asflags=-a amd64 depends=../src/asm +[arm.o] +type=object +sources=arm.S + +[arm.S] +asflags=-a arm +depends=../src/asm + [dalvik.o] type=object sources=dalvik.S