diff --git a/makefile b/makefile index ae1ff9a240..34796f61f8 100755 --- a/makefile +++ b/makefile @@ -24,7 +24,6 @@ target-arch = $(arch) bootimage-platform = \ $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))) platform = $(bootimage-platform) -target-platform = $(platform) mode = fast process = compile @@ -165,6 +164,8 @@ ifneq ($(platform),darwin) endif endif +target-format = elf + cxx = $(build-cxx) $(mflag) cc = $(build-cc) $(mflag) @@ -211,7 +212,7 @@ build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \ converter-cflags = -D__STDC_CONSTANT_MACROS -Isrc/binaryToObject -Isrc/ \ -fno-rtti -fno-exceptions \ -DAVIAN_TARGET_ARCH=AVIAN_ARCH_UNKNOWN \ - -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_UNKNOWN \ + -DAVIAN_TARGET_FORMAT=AVIAN_FORMAT_UNKNOWN \ -Wall -Wextra -Werror -Wunused-parameter -Winit-self -Wno-non-virtual-dtor cflags = $(build-cflags) @@ -314,7 +315,6 @@ ifeq ($(build-platform),darwin) endif ifeq ($(platform),qnx) - target-platform = linux cflags = $(common-cflags) -fPIC -fvisibility=hidden -I$(src) lflags = $(common-lflags) -lsocket ifeq ($(build-platform),qnx) @@ -346,6 +346,7 @@ ifeq ($(platform),freebsd) endif ifeq ($(platform),darwin) + target-format = macho ifeq (${OSX_SDK_SYSROOT},) OSX_SDK_SYSROOT = 10.4u endif @@ -427,6 +428,8 @@ ifeq ($(platform),darwin) endif ifeq ($(platform),windows) + target-format = pe + inc = "$(win32)/include" lib = "$(win32)/lib" @@ -854,20 +857,16 @@ ifeq ($(target-arch),arm) cflags += -DAVIAN_TARGET_ARCH=AVIAN_ARCH_ARM endif -ifeq ($(target-platform),linux) - cflags += -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_LINUX +ifeq ($(target-format),elf) + cflags += -DAVIAN_TARGET_FORMAT=AVIAN_FORMAT_ELF endif -ifeq ($(target-platform),windows) - cflags += -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_WINDOWS +ifeq ($(target-format),pe) + cflags += -DAVIAN_TARGET_FORMAT=AVIAN_FORMAT_PE endif -ifeq ($(target-platform),darwin) - cflags += -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_DARWIN -endif - -ifeq ($(target-platform),freebsd) - cflags += -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_FREEBSD +ifeq ($(target-format),macho) + cflags += -DAVIAN_TARGET_FORMAT=AVIAN_FORMAT_MACHO endif class-name = $(patsubst $(1)/%.class,%,$(2)) @@ -1050,7 +1049,7 @@ $(build)/classpath.jar: $(classpath-dep) $(classpath-jar-dep) $(classpath-object): $(build)/classpath.jar $(converter) @echo "creating $(@)" $(converter) $(<) $(@) _binary_classpath_jar_start \ - _binary_classpath_jar_end $(target-platform) $(arch) + _binary_classpath_jar_end $(target-format) $(arch) $(build)/javahome.jar: @echo "creating $(@)" @@ -1061,7 +1060,7 @@ $(build)/javahome.jar: $(javahome-object): $(build)/javahome.jar $(converter) @echo "creating $(@)" $(converter) $(<) $(@) _binary_javahome_jar_start \ - _binary_javahome_jar_end $(target-platform) $(arch) + _binary_javahome_jar_end $(target-format) $(arch) define compile-generator-object @echo "compiling $(@)" @@ -1122,7 +1121,7 @@ $(bootimage-generator): $(bootimage-generator-objects) arch=$(build-arch) \ target-arch=$(arch) \ platform=$(bootimage-platform) \ - target-platform=$(target-platform) \ + target-format=$(target-format) \ openjdk=$(openjdk) \ openjdk-src=$(openjdk-src) \ bootimage-generator= \ diff --git a/src/arm.S b/src/arm.S index e67dcc0681..e62c0a60e0 100644 --- a/src/arm.S +++ b/src/arm.S @@ -1,4 +1,4 @@ -/* arm.S: JNI gluecode for ARM/Linux +/* arm.S: JNI gluecode for ARM Copyright (c) 2008-2011, Avian Contributors Permission to use, copy, modify, and/or distribute this software diff --git a/src/binaryToObject/elf.cpp b/src/binaryToObject/elf.cpp index f50e4b6eba..a2277c3488 100644 --- a/src/binaryToObject/elf.cpp +++ b/src/binaryToObject/elf.cpp @@ -197,8 +197,8 @@ public: const unsigned machine; - ElfPlatform(PlatformInfo::OperatingSystem os, PlatformInfo::Architecture arch): - Platform(PlatformInfo(os, arch)), + ElfPlatform(PlatformInfo::Architecture arch): + Platform(PlatformInfo(PlatformInfo::Elf, arch)), machine(getElfPlatform(arch)) {} class FileWriter { @@ -372,15 +372,9 @@ public: } }; -ElfPlatform elfLinuxX86Platform(PlatformInfo::Linux, PlatformInfo::x86); -ElfPlatform elfLinuxArmPlatform(PlatformInfo::Linux, PlatformInfo::Arm); -ElfPlatform elfLinuxPowerPCPlatform(PlatformInfo::Linux, PlatformInfo::PowerPC); -ElfPlatform elfLinuxX86_64Platform(PlatformInfo::Linux, PlatformInfo::x86_64); - -ElfPlatform elfFreeBSDx86Platform(PlatformInfo::FreeBSD, PlatformInfo::x86); -ElfPlatform elfFreeBSDArmPlatform(PlatformInfo::FreeBSD, PlatformInfo::Arm); -ElfPlatform elfFreeBSDPowerPCPlatform(PlatformInfo::FreeBSD, PlatformInfo::PowerPC); -ElfPlatform elfFreeBSDx86_64Platform(PlatformInfo::FreeBSD, PlatformInfo::x86_64); - +ElfPlatform elfX86Platform(PlatformInfo::x86); +ElfPlatform elfArmPlatform(PlatformInfo::Arm); +ElfPlatform elfPowerPCPlatform(PlatformInfo::PowerPC); +ElfPlatform elfX86_64Platform(PlatformInfo::x86_64); } // namespace diff --git a/src/binaryToObject/mach-o.cpp b/src/binaryToObject/mach-o.cpp index dd89ddb304..96dd63aafd 100644 --- a/src/binaryToObject/mach-o.cpp +++ b/src/binaryToObject/mach-o.cpp @@ -286,7 +286,7 @@ public: } MachOPlatform(PlatformInfo::Architecture arch): - Platform(PlatformInfo(PlatformInfo::Darwin, arch)) {} + Platform(PlatformInfo(PlatformInfo::MachO, arch)) {} }; diff --git a/src/binaryToObject/main.cpp b/src/binaryToObject/main.cpp index 851a805bec..fe389f3d29 100644 --- a/src/binaryToObject/main.cpp +++ b/src/binaryToObject/main.cpp @@ -41,14 +41,14 @@ using namespace avian::tools; bool writeObject(uint8_t* data, size_t size, OutputStream* out, const char* startName, - const char* endName, const char* os, + const char* endName, const char* format, const char* architecture, unsigned alignment, bool writable, bool executable) { - Platform* platform = Platform::getPlatform(PlatformInfo(PlatformInfo::osFromString(os), PlatformInfo::archFromString(architecture))); + Platform* platform = Platform::getPlatform(PlatformInfo(PlatformInfo::formatFromString(format), PlatformInfo::archFromString(architecture))); if(!platform) { - fprintf(stderr, "unsupported platform: %s/%s\n", os, architecture); + fprintf(stderr, "unsupported platform: %s/%s\n", format, architecture); return false; } diff --git a/src/binaryToObject/pe.cpp b/src/binaryToObject/pe.cpp index 69ca719bc1..8d5d5fc444 100644 --- a/src/binaryToObject/pe.cpp +++ b/src/binaryToObject/pe.cpp @@ -269,7 +269,7 @@ public: } WindowsPlatform(): - Platform(PlatformInfo(PlatformInfo::Windows, BytesPerWord == 4 ? PlatformInfo::x86 : PlatformInfo::x86_64)) {} + Platform(PlatformInfo(PlatformInfo::Pe, BytesPerWord == 4 ? PlatformInfo::x86 : PlatformInfo::x86_64)) {} }; WindowsPlatform<4> windows32Platform; diff --git a/src/binaryToObject/tools.cpp b/src/binaryToObject/tools.cpp index 89961a74c5..9cc9059b93 100644 --- a/src/binaryToObject/tools.cpp +++ b/src/binaryToObject/tools.cpp @@ -85,17 +85,23 @@ void FileOutputStream::write(uint8_t byte) { Platform* Platform::first = 0; -PlatformInfo::OperatingSystem PlatformInfo::osFromString(const char* os) { - if(strcmp(os, "linux") == 0) { - return Linux; - } else if(strcmp(os, "windows") == 0) { - return Windows; - } else if(strcmp(os, "darwin") == 0) { - return Darwin; - } else if(strcmp(os, "freebsd") == 0) { - return FreeBSD; +PlatformInfo::Format PlatformInfo::formatFromString(const char* format) { + if (strcmp(format, "elf") == 0 + or strcmp(format, "linux") == 0 + or strcmp(format, "freebsd") == 0 + or strcmp(format, "qnx") == 0) + { + return Elf; + } else if (strcmp(format, "pe") == 0 + or strcmp(format, "windows") == 0) + { + return Pe; + } else if (strcmp(format, "macho") == 0 + or strcmp(format, "darwin") == 0) + { + return MachO; } else { - return UnknownOS; + return UnknownFormat; } } diff --git a/src/binaryToObject/tools.h b/src/binaryToObject/tools.h index dde9140678..46bcd691e8 100644 --- a/src/binaryToObject/tools.h +++ b/src/binaryToObject/tools.h @@ -131,12 +131,11 @@ public: class PlatformInfo { public: - enum OperatingSystem { - Linux = AVIAN_PLATFORM_LINUX, - Windows = AVIAN_PLATFORM_WINDOWS, - Darwin = AVIAN_PLATFORM_DARWIN, - FreeBSD = AVIAN_PLATFORM_FREEBSD, - UnknownOS = AVIAN_PLATFORM_UNKNOWN + enum Format { + Elf = AVIAN_FORMAT_ELF, + Pe = AVIAN_FORMAT_PE, + MachO = AVIAN_FORMAT_MACHO, + UnknownFormat = AVIAN_FORMAT_UNKNOWN }; enum Architecture { @@ -147,18 +146,18 @@ public: UnknownArch = AVIAN_ARCH_UNKNOWN }; - const OperatingSystem os; + const Format format; const Architecture arch; - static OperatingSystem osFromString(const char* os); + static Format formatFromString(const char* format); static Architecture archFromString(const char* arch); - inline PlatformInfo(OperatingSystem os, Architecture arch): - os(os), + inline PlatformInfo(Format format, Architecture arch): + format(format), arch(arch) {} inline bool operator == (const PlatformInfo& other) { - return os == other.os && arch == other.arch; + return format == other.format && arch == other.arch; } inline bool isLittleEndian() { diff --git a/src/bootimage.cpp b/src/bootimage.cpp index bfcbe2220e..a4ac6331c6 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -1647,7 +1647,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp // fwrite(code, pad(image->codeSize, TargetBytesPerWord), 1, codeOutput); - Platform* platform = Platform::getPlatform(PlatformInfo((PlatformInfo::OperatingSystem)AVIAN_TARGET_PLATFORM, (PlatformInfo::Architecture)AVIAN_TARGET_ARCH)); + Platform* platform = Platform::getPlatform(PlatformInfo((PlatformInfo::Format)AVIAN_TARGET_FORMAT, (PlatformInfo::Architecture)AVIAN_TARGET_ARCH)); // if(!platform) { // fprintf(stderr, "unsupported platform: %s/%s\n", os, architecture); diff --git a/src/environment.h b/src/environment.h index 2d66407109..f24150cd0f 100644 --- a/src/environment.h +++ b/src/environment.h @@ -11,19 +11,18 @@ #ifndef AVIAN_ENVIRONMENT_H #define AVIAN_ENVIRONMENT_H -#ifndef AVIAN_TARGET_PLATFORM -#error build system should have defined AVIAN_TARGET_PLATFORM +#ifndef AVIAN_TARGET_FORMAT +#error build system should have defined AVIAN_TARGET_FORMAT #endif #ifndef AVIAN_TARGET_ARCH #error build system should have defined AVIAN_TARGET_ARCH #endif -#define AVIAN_PLATFORM_UNKNOWN 0 -#define AVIAN_PLATFORM_LINUX 1 -#define AVIAN_PLATFORM_WINDOWS 2 -#define AVIAN_PLATFORM_DARWIN 3 -#define AVIAN_PLATFORM_FREEBSD 4 +#define AVIAN_FORMAT_UNKNOWN 0 +#define AVIAN_FORMAT_ELF 1 +#define AVIAN_FORMAT_PE 2 +#define AVIAN_FORMAT_MACHO 3 #define AVIAN_ARCH_UNKNOWN 0 #define AVIAN_ARCH_X86 (1 << 8) diff --git a/src/x86.cpp b/src/x86.cpp index 2a6d39d0aa..47a7ab2ad6 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -2781,7 +2781,7 @@ class MyArchitecture: public Assembler::Architecture { } virtual unsigned frameFootprint(unsigned footprint) { -#if AVIAN_TARGET_PLATFORM == AVIAN_PLATFORM_WINDOWS +#if AVIAN_TARGET_FORMAT == AVIAN_FORMAT_PE return max(footprint, StackAlignmentInWords); #else return max(footprint > argumentRegisterCount() ? @@ -2803,7 +2803,7 @@ class MyArchitecture: public Assembler::Architecture { } virtual unsigned argumentRegisterCount() { -#if AVIAN_TARGET_PLATFORM == AVIAN_PLATFORM_WINDOWS +#if AVIAN_TARGET_FORMAT == AVIAN_FORMAT_PE if (TargetBytesPerWord == 8) return 4; else #else if (TargetBytesPerWord == 8) return 6; else @@ -2814,7 +2814,7 @@ class MyArchitecture: public Assembler::Architecture { virtual int argumentRegister(unsigned index) { assert(&c, TargetBytesPerWord == 8); switch (index) { -#if AVIAN_TARGET_PLATFORM == AVIAN_PLATFORM_WINDOWS +#if AVIAN_TARGET_FORMAT == AVIAN_FORMAT_PE case 0: return rcx; case 1: