From f375f6e85cbb9ea4d8d33534b3ec194bf5647e70 Mon Sep 17 00:00:00 2001 From: dicej Date: Wed, 4 Jun 2008 17:09:09 -0600 Subject: [PATCH] enable powerpc build for process=interpret (won't run yet, though) --- makefile | 2 +- src/binaryToMacho.cpp | 28 +++++++++++++++++++++------- src/powerpc.S | 9 +++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/makefile b/makefile index 7446b356e2..553125d966 100644 --- a/makefile +++ b/makefile @@ -346,7 +346,7 @@ $(binaryToMacho): $(src)/binaryToMacho.cpp $(classpath-object): $(build)/classpath.jar $(binaryToMacho) @echo "creating $(@)" ifeq ($(platform),darwin) - $(binaryToMacho) $(build)/classpath.jar \ + $(binaryToMacho) $(asm) $(build)/classpath.jar \ __binary_classpath_jar_start __binary_classpath_jar_end > $(@) else (wd=$$(pwd); \ diff --git a/src/binaryToMacho.cpp b/src/binaryToMacho.cpp index 013b9bfc7f..8f04202e21 100644 --- a/src/binaryToMacho.cpp +++ b/src/binaryToMacho.cpp @@ -20,6 +20,8 @@ #include "mach-o/loader.h" #include "mach-o/nlist.h" + + namespace { inline unsigned @@ -29,16 +31,27 @@ pad(unsigned n) } void -writeObject(FILE* out, const uint8_t* data, unsigned size, +writeObject(const char* architecture, + FILE* out, const uint8_t* data, unsigned size, const char* startName, const char* endName) { unsigned startNameLength = strlen(startName) + 1; unsigned endNameLength = strlen(endName) + 1; + cpu_type_t cpuType; + cpu_subtype_t cpuSubtype; + if (strcmp(architecture, "x86") == 0) { + cpuType = CPU_TYPE_I386; + cpuSubtype = CPU_SUBTYPE_I386_ALL; + } else if (strcmp(architecture, "powerpc") == 0) { + cpuType = CPU_TYPE_POWERPC; + cpuSubtype = CPU_SUBTYPE_POWERPC_ALL; + } + mach_header header = { MH_MAGIC, // magic - CPU_TYPE_I386, // cputype - CPU_SUBTYPE_I386_ALL, // cpusubtype + cpuType, + cpuSubtype, MH_OBJECT, // filetype, 2, // ncmds sizeof(segment_command) @@ -136,16 +149,17 @@ writeObject(FILE* out, const uint8_t* data, unsigned size, int main(int argc, const char** argv) { - if (argc != 4) { + if (argc != 5) { fprintf(stderr, - "usage: %s \n", + "usage: %s " + "\n", argv[0]); return -1; } uint8_t* data = 0; unsigned size; - int fd = open(argv[1], O_RDONLY); + int fd = open(argv[2], O_RDONLY); if (fd != -1) { struct stat s; int r = fstat(fd, &s); @@ -158,7 +172,7 @@ main(int argc, const char** argv) } if (data) { - writeObject(stdout, data, size, argv[2], argv[3]); + writeObject(argv[1], stdout, data, size, argv[3], argv[4]); munmap(data, size); return 0; } else { diff --git a/src/powerpc.S b/src/powerpc.S index 367c352e0d..b5ebd688f3 100644 --- a/src/powerpc.S +++ b/src/powerpc.S @@ -29,3 +29,12 @@ vmNativeCall: ;; mtlr r0 ; into the link register ;; addi r1,r1,spaceToSaveAligned ; restore stack pointer blr ; and branch to the return address + +#ifdef __APPLE__ +.globl _vmJump +_vmJump: +#else +.globl vmJump +vmJump: +#endif + blr