From 32da9a3eb347d79f38f4a8dcfa7ac98d3f52f204 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sat, 1 Dec 2012 02:50:13 +0100 Subject: [PATCH] Supporting even more architectures in standalone libasm --- Makefile | 7 ++++++ tools/Makefile | 23 ++++++++++++++++- tools/arch.c | 63 ++++++++++++++++++---------------------------- tools/arch/arm.c | 19 ++++++++++++++ tools/arch/armeb.c | 19 ++++++++++++++ tools/arch/armel.c | 19 ++++++++++++++ tools/arch/i386.c | 19 ++++++++++++++ tools/arch/i486.c | 19 ++++++++++++++ tools/arch/i586.c | 19 ++++++++++++++ tools/arch/i686.c | 19 ++++++++++++++ tools/project.conf | 2 +- 11 files changed, 187 insertions(+), 41 deletions(-) create mode 100644 tools/arch/arm.c create mode 100644 tools/arch/armeb.c create mode 100644 tools/arch/armel.c create mode 100644 tools/arch/i386.c create mode 100644 tools/arch/i486.c create mode 100644 tools/arch/i586.c create mode 100644 tools/arch/i686.c diff --git a/Makefile b/Makefile index 6f1267c..546e2ba 100644 --- a/Makefile +++ b/Makefile @@ -142,6 +142,13 @@ dist: $(PACKAGE)-$(VERSION)/tests/tests.sh \ $(PACKAGE)-$(VERSION)/tests/project.conf \ $(PACKAGE)-$(VERSION)/tools/arch.c \ + $(PACKAGE)-$(VERSION)/tools/arch/arm.c \ + $(PACKAGE)-$(VERSION)/tools/arch/armeb.c \ + $(PACKAGE)-$(VERSION)/tools/arch/armel.c \ + $(PACKAGE)-$(VERSION)/tools/arch/i386.c \ + $(PACKAGE)-$(VERSION)/tools/arch/i486.c \ + $(PACKAGE)-$(VERSION)/tools/arch/i586.c \ + $(PACKAGE)-$(VERSION)/tools/arch/i686.c \ $(PACKAGE)-$(VERSION)/tools/format.c \ $(PACKAGE)-$(VERSION)/tools/Makefile \ $(PACKAGE)-$(VERSION)/tools/project.conf \ diff --git a/tools/Makefile b/tools/Makefile index f92ca5e..5f7b47e 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -18,7 +18,7 @@ INSTALL ?= install all: $(TARGETS) -libasm_OBJS = arch.o format.o +libasm_OBJS = arch.o arch/arm.o arch/armeb.o arch/armel.o arch/i386.o arch/i486.o arch/i586.o arch/i686.o format.o libasm_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) libasm_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) ../src/asm.o ../src/code.o ../src/parser.o ../src/token.o `pkg-config --libs cpp` @@ -34,6 +34,27 @@ libasm.so.0.0 libasm.so.0 libasm.so: $(libasm_OBJS) arch.o: arch.c ../src/arch.c $(CC) $(libasm_CFLAGS) -c arch.c +arch/arm.o: arch/arm.c + $(CC) $(libasm_CFLAGS) -o arch/arm.o -c arch/arm.c + +arch/armeb.o: arch/armeb.c + $(CC) $(libasm_CFLAGS) -o arch/armeb.o -c arch/armeb.c + +arch/armel.o: arch/armel.c + $(CC) $(libasm_CFLAGS) -o arch/armel.o -c arch/armel.c + +arch/i386.o: arch/i386.c + $(CC) $(libasm_CFLAGS) -o arch/i386.o -c arch/i386.c + +arch/i486.o: arch/i486.c + $(CC) $(libasm_CFLAGS) -o arch/i486.o -c arch/i486.c + +arch/i586.o: arch/i586.c + $(CC) $(libasm_CFLAGS) -o arch/i586.o -c arch/i586.c + +arch/i686.o: arch/i686.c + $(CC) $(libasm_CFLAGS) -o arch/i686.o -c arch/i686.c + format.o: format.c ../src/format.c $(CC) $(libasm_CFLAGS) -c format.c diff --git a/tools/arch.c b/tools/arch.c index 94ab90a..ad8318e 100644 --- a/tools/arch.c +++ b/tools/arch.c @@ -19,48 +19,10 @@ #include "../src/arch/amd64.c" #undef arch_plugin -#if 0 -#define arch_plugin arch_plugin_arm -#include "../src/arch/arm.c" -#undef arch_plugin -#endif - -#if 0 -#define arch_plugin arch_plugin_armeb -#include "../src/arch/armeb.c" -#undef arch_plugin - -#define arch_plugin arch_plugin_armel -#include "../src/arch/armel.c" -#undef arch_plugin -#endif - #define arch_plugin arch_plugin_dalvik #include "../src/arch/dalvik.c" #undef arch_plugin -#if 0 -#define arch_plugin arch_plugin_i386 -#include "../src/arch/i386.c" -#undef arch_plugin - -#define arch_plugin arch_plugin_i386_real -#include "../src/arch/i386_real.c" -#undef arch_plugin - -#define arch_plugin arch_plugin_i486 -#include "../src/arch/i486.c" -#undef arch_plugin - -#define arch_plugin arch_plugin_i586 -#include "../src/arch/i586.c" -#undef arch_plugin - -#define arch_plugin arch_plugin_i686 -#include "../src/arch/i686.c" -#undef arch_plugin -#endif - #define arch_plugin arch_plugin_java #include "../src/arch/java.c" #undef arch_plugin @@ -107,14 +69,29 @@ /* AsmArch */ /* private */ /* constants */ -static const struct +extern AsmArchPlugin arch_plugin_arm; +extern AsmArchPlugin arch_plugin_armeb; +extern AsmArchPlugin arch_plugin_armel; +extern AsmArchPlugin arch_plugin_i386; +extern AsmArchPlugin arch_plugin_i486; +extern AsmArchPlugin arch_plugin_i586; +extern AsmArchPlugin arch_plugin_i686; + +static struct { char const * name; AsmArchPlugin * plugin; } _arch[] = { { "amd64", &arch_plugin_amd64 }, + { "arm", NULL }, + { "armeb", NULL }, + { "armel", NULL }, { "dalvik", &arch_plugin_dalvik }, + { "i386", NULL }, + { "i486", NULL }, + { "i586", NULL }, + { "i686", NULL }, { "java", &arch_plugin_java }, { "mips", &arch_plugin_mips }, { "sparc", &arch_plugin_sparc }, @@ -135,6 +112,14 @@ AsmArch * arch_new(char const * name) #ifdef DEBUG fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, name); #endif + /* XXX */ + _arch[1].plugin = &arch_plugin_arm; + _arch[2].plugin = &arch_plugin_armeb; + _arch[3].plugin = &arch_plugin_armel; + _arch[5].plugin = &arch_plugin_i386; + _arch[6].plugin = &arch_plugin_i486; + _arch[7].plugin = &arch_plugin_i586; + _arch[8].plugin = &arch_plugin_i686; for(i = 0; i < sizeof(_arch) / sizeof(*_arch); i++) if(strcmp(_arch[i].name, name) == 0) { diff --git a/tools/arch/arm.c b/tools/arch/arm.c new file mode 100644 index 0000000..3c38b7d --- /dev/null +++ b/tools/arch/arm.c @@ -0,0 +1,19 @@ +/* $Id$ */ +/* Copyright (c) 2012 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 Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ + + + +#define arch_plugin arch_plugin_arm +#include "../src/arch/arm.c" diff --git a/tools/arch/armeb.c b/tools/arch/armeb.c new file mode 100644 index 0000000..0126197 --- /dev/null +++ b/tools/arch/armeb.c @@ -0,0 +1,19 @@ +/* $Id$ */ +/* Copyright (c) 2012 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 Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ + + + +#define arch_plugin arch_plugin_armeb +#include "../src/arch/armeb.c" diff --git a/tools/arch/armel.c b/tools/arch/armel.c new file mode 100644 index 0000000..c9fefff --- /dev/null +++ b/tools/arch/armel.c @@ -0,0 +1,19 @@ +/* $Id$ */ +/* Copyright (c) 2012 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 Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ + + + +#define arch_plugin arch_plugin_armel +#include "../src/arch/armel.c" diff --git a/tools/arch/i386.c b/tools/arch/i386.c new file mode 100644 index 0000000..9df5881 --- /dev/null +++ b/tools/arch/i386.c @@ -0,0 +1,19 @@ +/* $Id$ */ +/* Copyright (c) 2012 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 Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ + + + +#define arch_plugin arch_plugin_i386 +#include "../src/arch/i386.c" diff --git a/tools/arch/i486.c b/tools/arch/i486.c new file mode 100644 index 0000000..7385840 --- /dev/null +++ b/tools/arch/i486.c @@ -0,0 +1,19 @@ +/* $Id$ */ +/* Copyright (c) 2012 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 Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ + + + +#define arch_plugin arch_plugin_i486 +#include "../src/arch/i486.c" diff --git a/tools/arch/i586.c b/tools/arch/i586.c new file mode 100644 index 0000000..84b7e5f --- /dev/null +++ b/tools/arch/i586.c @@ -0,0 +1,19 @@ +/* $Id$ */ +/* Copyright (c) 2012 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 Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ + + + +#define arch_plugin arch_plugin_i586 +#include "../src/arch/i586.c" diff --git a/tools/arch/i686.c b/tools/arch/i686.c new file mode 100644 index 0000000..3483f3d --- /dev/null +++ b/tools/arch/i686.c @@ -0,0 +1,19 @@ +/* $Id$ */ +/* Copyright (c) 2012 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 Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ + + + +#define arch_plugin arch_plugin_i686 +#include "../src/arch/i686.c" diff --git a/tools/project.conf b/tools/project.conf index 79b540b..3cfa6f6 100644 --- a/tools/project.conf +++ b/tools/project.conf @@ -6,7 +6,7 @@ dist=Makefile [libasm] type=library -sources=arch.c,format.c +sources=arch.c,arch/arm.c,arch/armeb.c,arch/armel.c,arch/i386.c,arch/i486.c,arch/i586.c,arch/i686.c,format.c ldflags=../src/asm.o ../src/code.o ../src/parser.o ../src/token.o `pkg-config --libs cpp` [arch.c]