From: Slava Pestov Date: Sun, 24 Jan 2010 13:17:18 +0000 (-0600) Subject: Update Win64 support X-Git-Tag: 0.97~5019 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=942f6e0943cb953b2e6c4e7b7deaf0c32e3336a7 Update Win64 support --- diff --git a/Nmakefile b/Nmakefile index e964105d9f..07984e35c8 100755 --- a/Nmakefile +++ b/Nmakefile @@ -1,5 +1,10 @@ +!IF DEFINED(DEBUG) +LINK_FLAGS = /nologo /DEBUG shell32.lib +CL_FLAGS = /nologo /Zi /O2 /W3 /DFACTOR_DEBUG +!ELSE LINK_FLAGS = /nologo shell32.lib CL_FLAGS = /nologo /O2 /W3 +!ENDIF EXE_OBJS = factor.dll.lib vm\main-windows-nt.obj vm\factor.res @@ -50,11 +55,17 @@ DLL_OBJS = vm\os-windows-nt.obj \ .cpp.obj: cl /EHsc $(CL_FLAGS) /Fo$@ /c $< +.c.obj: + cl $(CL_FLAGS) /Fo$@ /c $< + .rs.res: rc $< all: factor.com factor.exe +libfactor-ffi-test.dll: vm/ffi_test.obj + link $(LINK_FLAGS) /out:libfactor-ffi-test.dll /dll vm/ffi_test.obj + factor.dll.lib: $(DLL_OBJS) link $(LINK_FLAGS) /implib:factor.dll.lib /out:factor.dll /dll $(DLL_OBJS) diff --git a/basis/cpu/x86/64/64.factor b/basis/cpu/x86/64/64.factor index d3196397c3..5213030bdf 100644 --- a/basis/cpu/x86/64/64.factor +++ b/basis/cpu/x86/64/64.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2005, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays kernel math namespaces make sequences -system layouts alien alien.c-types alien.accessors slots -splitting assocs combinators locals compiler.constants +system layouts alien alien.c-types alien.accessors alien.libraries +slots splitting assocs combinators locals compiler.constants compiler.codegen compiler.codegen.fixup compiler.cfg.instructions compiler.cfg.builder compiler.cfg.intrinsics compiler.cfg.stack-frame @@ -118,9 +118,6 @@ M:: x86.64 %unbox ( n rep func -- ) ! this is the end of alien-callback n [ n rep reg-class-of return-reg rep %save-param-reg ] when ; -M: x86.64 %unbox-long-long ( n func -- ) - [ int-rep ] dip %unbox ; - : %unbox-struct-field ( c-type i -- ) ! Alien must be in param-reg-0. R11 swap cells [+] swap rep>> reg-class-of { @@ -163,12 +160,11 @@ M:: x86.64 %box ( n rep func -- ) ] [ rep load-return-value ] if - rep int-rep? [ param-reg-1 ] [ param-reg-0 ] if %mov-vm-ptr + rep int-rep? + cpu x86.64? os windows? and or + param-reg-1 param-reg-0 ? %mov-vm-ptr func f %alien-invoke ; -M: x86.64 %box-long-long ( n func -- ) - [ int-rep ] dip %box ; - : box-struct-field@ ( i -- operand ) 1 + cells param@ ; : %box-struct-field ( c-type i -- ) @@ -258,7 +254,7 @@ M: x86.64 %callback-value ( ctype -- ) M:: x86.64 %unary-float-function ( dst src func -- ) 0 src float-function-param - func f %alien-invoke + func "libm" load-library %alien-invoke dst float-function-return ; M:: x86.64 %binary-float-function ( dst src1 src2 func -- ) @@ -266,7 +262,7 @@ M:: x86.64 %binary-float-function ( dst src1 src2 func -- ) ! src2 is always a spill slot 0 src1 float-function-param 1 src2 float-function-param - func f %alien-invoke + func "libm" load-library %alien-invoke dst float-function-return ; M:: x86.64 %call-gc ( gc-root-count temp -- ) diff --git a/basis/cpu/x86/64/winnt/winnt.factor b/basis/cpu/x86/64/winnt/winnt.factor index a398c6565c..c75bb5a1b9 100644 --- a/basis/cpu/x86/64/winnt/winnt.factor +++ b/basis/cpu/x86/64/winnt/winnt.factor @@ -22,5 +22,5 @@ M: x86.64 dummy-int-params? t ; M: x86.64 dummy-fp-params? t ; -M: x86.64 temp-reg RAX ; +M: x86.64 temp-reg R11 ; diff --git a/vm/Config.windows.nt.x86.64 b/vm/Config.windows.nt.x86.64 index 13ef665b19..ddb61480e5 100644 --- a/vm/Config.windows.nt.x86.64 +++ b/vm/Config.windows.nt.x86.64 @@ -1,4 +1,3 @@ -#error "lol" DLL_PATH=http://factorcode.org/dlls/64 CC=$(WIN64_PATH)-gcc.exe WINDRES=$(WIN64_PATH)-windres.exe diff --git a/vm/bitwise_hacks.hpp b/vm/bitwise_hacks.hpp index 1927cd4736..162d9272c6 100755 --- a/vm/bitwise_hacks.hpp +++ b/vm/bitwise_hacks.hpp @@ -12,7 +12,8 @@ inline cell log2(cell x) #endif #elif defined(FACTOR_AMD64) #if defined(_MSC_VER) - _BitScanReverse64(&n,x); + n = 0; + _BitScanReverse64((DWORD *)&n,x); #else asm ("bsr %1, %0;":"=r"(n):"r"(x)); #endif diff --git a/vm/code_blocks.cpp b/vm/code_blocks.cpp index 89106499da..f523dac3a0 100755 --- a/vm/code_blocks.cpp +++ b/vm/code_blocks.cpp @@ -129,13 +129,6 @@ void factor_vm::update_word_references(code_block *compiled) } } -void factor_vm::check_code_address(cell address) -{ -#ifdef FACTOR_DEBUG - assert(address >= code->seg->start && address < code->seg->end); -#endif -} - /* References to undefined symbols are patched up to call this function on image load */ void factor_vm::undefined_symbol() diff --git a/vm/cpu-x86.hpp b/vm/cpu-x86.hpp index c96291b0d7..97e5a20305 100644 --- a/vm/cpu-x86.hpp +++ b/vm/cpu-x86.hpp @@ -42,7 +42,7 @@ inline static void *get_call_target(cell return_address) inline static void set_call_target(cell return_address, void *target) { check_call_site(return_address); - *(int *)(return_address - 4) = ((cell)target - return_address); + *(int *)(return_address - 4) = (u32)((cell)target - return_address); } inline static bool tail_call_site_p(cell return_address) diff --git a/vm/errors.cpp b/vm/errors.cpp index 2dcb773dd1..ae560012aa 100755 --- a/vm/errors.cpp +++ b/vm/errors.cpp @@ -113,7 +113,7 @@ void factor_vm::memory_protection_error(cell addr, stack_frame *native_stack) general_error(ERROR_MEMORY,allot_cell(addr),false_object,native_stack); } -void factor_vm::signal_error(int signal, stack_frame *native_stack) +void factor_vm::signal_error(cell signal, stack_frame *native_stack) { general_error(ERROR_SIGNAL,allot_cell(signal),false_object,native_stack); } diff --git a/vm/ffi_test.h b/vm/ffi_test.h index af0c0b46a4..661f3b64de 100644 --- a/vm/ffi_test.h +++ b/vm/ffi_test.h @@ -1,4 +1,8 @@ -#include +#ifdef _MSC_VER + #define WINDOWS +#else + #include +#endif #if defined(i386) || defined(__i386) || defined(__i386__) || defined(WIN32) #define F_STDCALL __attribute__((stdcall)) diff --git a/vm/full_collector.cpp b/vm/full_collector.cpp index 4de2814f1d..ec0972e952 100644 --- a/vm/full_collector.cpp +++ b/vm/full_collector.cpp @@ -51,7 +51,7 @@ void factor_vm::update_code_roots_for_sweep() for(; iter < end; iter++) { code_root *root = *iter; - code_block *block = (code_block *)(root->value & -data_alignment); + code_block *block = (code_block *)(root->value & (~data_alignment - 1)); if(root->valid && !state->marked_p(block)) root->valid = false; } diff --git a/vm/instruction_operands.cpp b/vm/instruction_operands.cpp index db869d9d01..59dbf1ef8e 100644 --- a/vm/instruction_operands.cpp +++ b/vm/instruction_operands.cpp @@ -82,7 +82,7 @@ void instruction_operand::store_value_2_2(fixnum value) void instruction_operand::store_value_masked(fixnum value, cell mask, cell shift) { u32 *ptr = (u32 *)(pointer - sizeof(u32)); - *ptr = ((*ptr & ~mask) | ((value >> shift) & mask)); + *ptr = (u32)((*ptr & ~mask) | ((value >> shift) & mask)); } void instruction_operand::store_value(fixnum absolute_value) @@ -95,10 +95,10 @@ void instruction_operand::store_value(fixnum absolute_value) *(cell *)(pointer - sizeof(cell)) = absolute_value; break; case RC_ABSOLUTE: - *(u32 *)(pointer - sizeof(u32)) = absolute_value; + *(u32 *)(pointer - sizeof(u32)) = (u32)absolute_value; break; case RC_RELATIVE: - *(s32 *)(pointer - sizeof(s32)) = relative_value; + *(s32 *)(pointer - sizeof(s32)) = (s32)relative_value; break; case RC_ABSOLUTE_PPC_2_2: store_value_2_2(absolute_value); diff --git a/vm/instruction_operands.hpp b/vm/instruction_operands.hpp index d46b5cf391..dc8aa9d841 100644 --- a/vm/instruction_operands.hpp +++ b/vm/instruction_operands.hpp @@ -69,7 +69,7 @@ struct relocation_entry { relocation_class rel_class, cell offset) { - value = (rel_type << 28) | (rel_class << 24) | offset; + value = (u32)((rel_type << 28) | (rel_class << 24) | offset); } relocation_type rel_type() diff --git a/vm/master.hpp b/vm/master.hpp index f4c0934478..70736c1bd9 100755 --- a/vm/master.hpp +++ b/vm/master.hpp @@ -32,10 +32,10 @@ /* Detect target CPU type */ #if defined(__arm__) #define FACTOR_ARM -#elif defined(__amd64__) || defined(__x86_64__) +#elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64) #define FACTOR_AMD64 #define FACTOR_64 -#elif defined(i386) || defined(__i386) || defined(__i386__) || defined(WIN32) || defined(_MSC_VER) +#elif defined(i386) || defined(__i386) || defined(__i386__) || defined(_M_IX86) #define FACTOR_X86 #elif defined(__POWERPC__) || defined(__ppc__) || defined(_ARCH_PPC) #define FACTOR_PPC @@ -50,10 +50,6 @@ #define WINDOWS #endif -#ifndef _MSC_VER - #include -#endif - /* Forward-declare this since it comes up in function prototypes */ namespace factor { diff --git a/vm/math.cpp b/vm/math.cpp index a2c69c31f2..ef4a599331 100755 --- a/vm/math.cpp +++ b/vm/math.cpp @@ -203,7 +203,7 @@ void factor_vm::primitive_bignum_not() void factor_vm::primitive_bignum_bitp() { - fixnum bit = to_fixnum(ctx->pop()); + int bit = (int)to_fixnum(ctx->pop()); bignum *x = untag(ctx->pop()); ctx->push(tag_boolean(bignum_logbitp(bit,x))); } @@ -226,7 +226,7 @@ unsigned int bignum_producer(unsigned int digit, factor_vm *parent) void factor_vm::primitive_byte_array_to_bignum() { - cell n_digits = array_capacity(untag_check(ctx->peek())); + unsigned int n_digits = (unsigned int)array_capacity(untag_check(ctx->peek())); bignum * result = digit_stream_to_bignum(n_digits,factor::bignum_producer,0x100,0); ctx->replace(tag(result)); } @@ -352,7 +352,7 @@ void factor_vm::primitive_float_bits() void factor_vm::primitive_bits_float() { - ctx->push(allot_float(bits_float(to_cell(ctx->pop())))); + ctx->push(allot_float(bits_float((u32)to_cell(ctx->pop())))); } void factor_vm::primitive_double_bits() diff --git a/vm/os-windows-nt.64.hpp b/vm/os-windows-nt.64.hpp index b64bd607cb..aff662a489 100755 --- a/vm/os-windows-nt.64.hpp +++ b/vm/os-windows-nt.64.hpp @@ -4,7 +4,6 @@ namespace factor #define ESP Rsp #define EIP Rip -#define X87SW(ctx) (ctx)->FloatSave.StatusWord #define MXCSR(ctx) (ctx)->MxCsr } diff --git a/vm/os-windows-nt.cpp b/vm/os-windows-nt.cpp index 2fceb130f4..cf5878e5bf 100755 --- a/vm/os-windows-nt.cpp +++ b/vm/os-windows-nt.cpp @@ -91,8 +91,12 @@ LONG factor_vm::exception_handler(PEXCEPTION_POINTERS pe) case STATUS_FLOAT_UNDERFLOW: case STATUS_FLOAT_MULTIPLE_FAULTS: case STATUS_FLOAT_MULTIPLE_TRAPS: +#ifdef FACTOR_AMD64 + signal_fpu_status = fpu_status(MXCSR(c)); +#else signal_fpu_status = fpu_status(X87SW(c) | MXCSR(c)); X87SW(c) = 0; +#endif MXCSR(c) &= 0xffffffc0; c->EIP = (cell)factor::fp_signal_handler_impl; break; diff --git a/vm/run.cpp b/vm/run.cpp index dfff8f2f2d..6c8a8452e7 100755 --- a/vm/run.cpp +++ b/vm/run.cpp @@ -5,7 +5,7 @@ namespace factor void factor_vm::primitive_exit() { - exit(to_fixnum(ctx->pop())); + exit((int)to_fixnum(ctx->pop())); } void factor_vm::primitive_system_micros() diff --git a/vm/strings.cpp b/vm/strings.cpp index 67e4fb4508..5aad936a9e 100644 --- a/vm/strings.cpp +++ b/vm/strings.cpp @@ -81,7 +81,7 @@ void factor_vm::fill_string(string *str_, cell start, cell capacity, cell fill) data_root str(str_,this); if(fill <= 0x7f) - memset(&str->data()[start],fill,capacity - start); + memset(&str->data()[start],(int)fill,capacity - start); else { cell i; diff --git a/vm/vm.hpp b/vm/vm.hpp index 6fb788d531..6b12cc42c0 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -149,7 +149,7 @@ struct factor_vm void not_implemented_error(); bool in_page(cell fault, cell area, cell area_size, int offset); void memory_protection_error(cell addr, stack_frame *native_stack); - void signal_error(int signal, stack_frame *native_stack); + void signal_error(cell signal, stack_frame *native_stack); void divide_by_zero_error(); void fp_trap_error(unsigned int fpu_status, stack_frame *signal_callstack_top); void primitive_call_clear(); @@ -509,7 +509,6 @@ struct factor_vm cell compute_entry_point_pic_tail_address(cell w_); cell code_block_owner(code_block *compiled); void update_word_references(code_block *compiled); - void check_code_address(cell address); void undefined_symbol(); cell compute_dlsym_address(array *literals, cell index); cell compute_vm_address(cell arg); @@ -524,7 +523,7 @@ struct factor_vm inline void check_code_pointer(cell ptr) { #ifdef FACTOR_DEBUG - assert(in_code_heap_p(ptr)); + //assert(in_code_heap_p(ptr)); #endif }