Created
February 21, 2011 03:34
-
-
Save SaitoAtsushi/836626 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/sysdep.h | |
=================================================================== | |
--- src/sysdep.h (リビジョン 506) | |
+++ src/sysdep.h (作業コピー) | |
@@ -114,6 +114,7 @@ | |
#define VALUE_NAN std::numeric_limits<double>::quiet_NaN() | |
#define VALUE_INF std::numeric_limits<double>::infinity() | |
+ #ifndef __MINGW32__ | |
#define INT8_MIN _I8_MIN | |
#define INT8_MAX _I8_MAX | |
#define INT16_MIN _I16_MIN | |
@@ -134,6 +135,7 @@ | |
#define UINT64_MAX _UI64_MAX | |
#define UINTPTR_MIN _UI32_MIN | |
#define UINTPTR_MAX _UI32_MAX | |
+ #endif | |
typedef signed char int8_t; | |
typedef short int16_t; | |
@@ -143,7 +145,13 @@ | |
typedef unsigned short uint16_t; | |
typedef unsigned int uint32_t; | |
typedef unsigned long long uint64_t; | |
+ | |
+ #ifndef _SSIZE_T_ | |
+ #ifndef _NO_OLDNAMES | |
typedef int ssize_t; | |
+ #endif | |
+ #endif | |
+ | |
typedef int64_t off64_t; | |
typedef HANDLE fd_t; | |
@@ -175,8 +183,11 @@ | |
#define HOST_NAME_MAX 255 | |
#endif | |
+ #ifndef __MINGW32__ | |
inline int isnan(double x) { return _isnan(x); } | |
inline int isinf(double x) { return (!_finite(x) && !_isnan(x)); } | |
+ #endif | |
+ | |
inline double round(double x) { return (x >= 0.0) ? floor(x + 0.5) : ceil(x - 0.5); } | |
inline double trunc(double x) { return (x >= 0.0) ? floor(x) : ceil(x); } | |
@@ -225,15 +236,19 @@ | |
return VirtualFree(adrs, size, MEM_DECOMMIT); | |
} | |
+ #ifdef __MINGW32__ | |
+ extern __thread VM* s_current_vm; | |
+ #else | |
+ extern __declspec(thread) VM* s_current_vm; | |
+ #endif | |
+ | |
inline VM* current_vm() | |
{ | |
- extern __declspec(thread) VM* s_current_vm; | |
return s_current_vm; | |
} | |
inline void set_current_vm(VM* vm) | |
{ | |
- extern __declspec(thread) VM* s_current_vm; | |
s_current_vm = vm; | |
} | |
@@ -263,6 +278,10 @@ | |
Sleep(0); | |
} | |
+ #ifdef __MINGW32__ | |
+ #define gmtime_s(tm,time) (*tm=*gmtime(time)) | |
+ #define localtime_s(tm,time) (*tm=*localtime(time)) | |
+ #endif | |
#else | |
#include <sys/time.h> | |
Index: src/file.cpp | |
=================================================================== | |
--- src/file.cpp (リビジョン 506) | |
+++ src/file.cpp (作業コピー) | |
@@ -455,7 +455,7 @@ | |
scm_string_t string = (scm_string_t)proc; | |
name = string->name; | |
} | |
- return GetProcAddress((HMODULE)hdl, name); | |
+ return reinterpret_cast<void*>(GetProcAddress((HMODULE)hdl, name)); | |
} | |
const char* | |
Index: src/ffi_stub_mingw.s | |
=================================================================== | |
--- src/ffi_stub_mingw.s (リビジョン 0) | |
+++ src/ffi_stub_mingw.s (リビジョン 0) | |
@@ -0,0 +1,87 @@ | |
+ | |
+ .file "ffi_stub_mingw.s" | |
+ | |
+ .text | |
+ | |
+ .align 4,0x90 | |
+ | |
+ .globl _c_func_stub_intptr | |
+ .globl _c_func_stub_int64 | |
+ .globl _c_func_stub_double | |
+ .globl _c_callback_stub_intptr | |
+ .globl _c_callback_stub_int64 | |
+ .globl _c_callback_stub_double | |
+ | |
+_c_func_stub_intptr: | |
+_c_func_stub_int64: | |
+_c_func_stub_double: | |
+ | |
+ pushl %ebp | |
+ movl %esp, %ebp | |
+ | |
+ subl $8, %esp | |
+ movl %edi, -8(%ebp) | |
+ movl %esi, -4(%ebp) | |
+ | |
+ movl 8(%ebp), %eax # adrs | |
+ movl 12(%ebp), %ecx # argc | |
+ movl 16(%ebp), %esi # argv | |
+ | |
+ leal 15(,%ecx,4), %ecx # align to 16 byte | |
+ andl $-16, %ecx | |
+ | |
+ movl %esp, %edx | |
+ subl %ecx, %esp | |
+ movl %esp, %edi | |
+ rep movsb | |
+ | |
+ call *%eax | |
+ | |
+ movl -8(%ebp), %edi | |
+ movl -4(%ebp), %esi | |
+ movl %ebp, %esp | |
+ popl %ebp | |
+ ret | |
+ | |
+ .align 4,0x90 | |
+ | |
+_c_callback_stub_double: | |
+ movl $_c_callback_double, %edx | |
+ jmp callback_stub_common | |
+ | |
+ .align 4,0x90 | |
+ | |
+_c_callback_stub_int64: | |
+ movl $_c_callback_int64, %edx | |
+ jmp callback_stub_common | |
+ | |
+ .align 4,0x90 | |
+ | |
+_c_callback_stub_intptr: | |
+ movl $_c_callback_intptr, %edx | |
+ jmp callback_stub_common | |
+ | |
+ .align 4,0x90 | |
+ | |
+callback_stub_common: | |
+ | |
+ pushl %ebp | |
+ movl %esp, %ebp | |
+ | |
+ subl $24, %esp # 16 + 8 | |
+ | |
+ movl (%ecx), %eax # uid | |
+ movl %eax, (%esp) | |
+ | |
+ movl 4(%ecx), %eax # argc | |
+ movl %eax, 4(%esp) | |
+ | |
+ leal 8(%ebp), %eax # base | |
+ movl %eax, 8(%esp) | |
+ | |
+ call *%edx | |
+ | |
+ movl %ebp, %esp | |
+ popl %ebp | |
+ ret | |
+ | |
Index: src/subr_ffi.cpp | |
=================================================================== | |
--- src/subr_ffi.cpp (リビジョン 506) | |
+++ src/subr_ffi.cpp (作業コピー) | |
@@ -214,7 +214,7 @@ | |
call_c_intptr(VM* vm, void* func, c_stack_frame_t& stack) | |
{ | |
synchronize_errno sync(vm); | |
-#if ARCH_IA32 | |
+#if defined(ARCH_IA32) || defined(__MINGW32__) | |
return c_func_stub_intptr(func, stack.count(), stack.frame()); | |
#elif ARCH_X64 | |
return c_func_stub_intptr_x64(func, stack.count(), stack.sse_use(), stack.frame()); | |
@@ -231,7 +231,7 @@ | |
call_c_int64(VM* vm, void* func, c_stack_frame_t& stack) | |
{ | |
synchronize_errno sync(vm); | |
-#if ARCH_IA32 | |
+#if defined(ARCH_IA32) || defined(__MINGW32__) | |
return c_func_stub_int64(func, stack.count(), stack.frame()); | |
#elif ARCH_X64 | |
return (int64_t)c_func_stub_intptr_x64(func, stack.count(), stack.sse_use(), stack.frame()); | |
@@ -249,7 +249,7 @@ | |
call_c_float(VM* vm, void* func, c_stack_frame_t& stack) | |
{ | |
synchronize_errno sync(vm); | |
-#if ARCH_IA32 | |
+#if defined(ARCH_IA32) || defined(__MINGW32__) | |
return c_func_stub_double(func, stack.count(), stack.frame()); | |
#elif ARCH_X64 | |
return c_func_stub_float_x64(func, stack.count(), stack.sse_use(), stack.frame()); | |
@@ -266,7 +266,7 @@ | |
call_c_double(VM* vm, void* func, c_stack_frame_t& stack) | |
{ | |
synchronize_errno sync(vm); | |
-#if ARCH_IA32 | |
+#if defined(ARCH_IA32) || defined(__MINGW32__) | |
return c_func_stub_double(func, stack.count(), stack.frame()); | |
#elif ARCH_X64 | |
return c_func_stub_double_x64(func, stack.count(), stack.sse_use(), stack.frame()); | |
Index: src/object.h | |
=================================================================== | |
--- src/object.h (リビジョン 506) | |
+++ src/object.h (作業コピー) | |
@@ -213,8 +213,17 @@ | |
typedef uint32_t (*hash_proc_t)(scm_obj_t obj, uint32_t bound); | |
typedef bool (*equiv_proc_t)(scm_obj_t obj1, scm_obj_t obj2); | |
+#ifdef __MINGW32__ | |
+#define OBJECT_ALIGNED(x) struct x | |
+#else | |
#define OBJECT_ALIGNED(x) struct DECLSPEC(align(OBJECT_DATUM_ALIGN)) x | |
+#endif | |
+ | |
+#ifdef __MINGW32__ | |
+#define END __attribute__((aligned(OBJECT_DATUM_ALIGN))) | |
+#else | |
#define END ATTRIBUTE(aligned(OBJECT_DATUM_ALIGN)) | |
+#endif | |
OBJECT_ALIGNED(scm_pair_rec_t) { | |
scm_obj_t car; | |
Index: src/main.cpp | |
=================================================================== | |
--- src/main.cpp (リビジョン 506) | |
+++ src/main.cpp (作業コピー) | |
@@ -11,7 +11,7 @@ | |
int main_command_line_argc; | |
char* const* main_command_line_argv; | |
-#if _MSC_VER | |
+#if defined(_MSC_VER) && !defined(__MINGW32__) | |
__declspec(thread) VM* s_current_vm; | |
#else | |
#if defined(NO_TLS) | |
Index: src/ffi.cpp | |
=================================================================== | |
--- src/ffi.cpp (リビジョン 506) | |
+++ src/ffi.cpp (作業コピー) | |
@@ -12,7 +12,7 @@ | |
#define C_STACK_COERCE_ARGUMENTS 1 | |
-#if ARCH_IA32 | |
+#if defined(ARCH_IA32) || defined(__MINGW32__) | |
const char* | |
c_stack_frame_t::push(scm_obj_t obj, int signature) | |
{ | |
@@ -1020,7 +1020,7 @@ | |
#endif | |
-#if _MSC_VER | |
+#if defined(_MSC_VER) && !defined(__MINGW32__) | |
intptr_t | |
c_func_stub_intptr(void* adrs, intptr_t argc, intptr_t argv[]) | |
@@ -1413,7 +1413,7 @@ | |
assert(uid < FIXNUM_MAX); | |
return uintptr_to_integer(vm->m_heap, (uintptr_t)thunk); | |
} | |
-#elif ARCH_IA32 | |
+#elif defined(ARCH_IA32) || defined(__MINGW32__) | |
struct trampoline_t { | |
uint8_t mov_ecx_imm32; // B9 : mov ecx, imm16/32 | |
uint32_t imm32_uid; // 00 00 00 00 | |
@@ -1443,7 +1443,13 @@ | |
} | |
assert(size < s_pool_alloc_size); | |
if (s_pool + size > s_pool_limit) { | |
+ #ifdef __MINGW32__ | |
+ s_pool = (uint8_t*)VirtualAlloc(NULL, s_pool_alloc_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); | |
+ errno = GetLastError(); | |
+ #define MAP_FAILED NULL | |
+ #else | |
s_pool = (uint8_t*)mmap(NULL, s_pool_alloc_size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); | |
+ #endif | |
if (s_pool == (uint8_t*)MAP_FAILED) fatal("%s:%u mmap failed %d", __FILE__, __LINE__, errno); | |
s_pool_limit = s_pool + s_pool_alloc_size; | |
} | |
Index: Makefile | |
=================================================================== | |
--- Makefile (リビジョン 506) | |
+++ Makefile (作業コピー) | |
@@ -240,6 +240,13 @@ | |
endif | |
endif | |
+ifneq (,$(findstring MINGW32, $(UNAME))) | |
+ CXXFLAGS += -msse2 -D_MSC_VER -msse -D_WIN32_WINNT=0x0501 -march=i686 -DUNICODE -D_MT -mthreads -flto | |
+ LDFLAGS += -flto -Wl,--allow-multiple-definition | |
+ LDLIBS = -lws2_32 -lShlwapi $(WINDIR)/system32/msvcr100.dll -mthreads | |
+ SRCS += ffi_stub_mingw.s | |
+endif | |
+ | |
OBJS = $(patsubst %.cpp, %.o, $(filter %.cpp, $(SRCS))) $(patsubst %.s, %.o, $(filter %.s, $(SRCS))) | |
DEPS = $(patsubst %.cpp, %.d, $(filter %.cpp, $(SRCS))) | |
@@ -249,7 +256,7 @@ | |
@mkdir -p -m755 $(HOME)/.ypsilon | |
$(PROG): $(OBJS) | |
- $(CXX) $(LDFLAGS) $(LDLIBS) -o $@ $^ | |
+ $(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS) | |
vm1.s: vm1.cpp | |
$(CXX) $(CXXFLAGS) $(CPPFLAGS) \ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment