]> gitweb.factorcode.org Git - factor.git/commitdiff
Update Win64 support
authorSlava Pestov <slava@factorcode.org>
Sun, 24 Jan 2010 13:17:18 +0000 (07:17 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 25 Jan 2010 02:39:34 +0000 (15:39 +1300)
19 files changed:
Nmakefile
basis/cpu/x86/64/64.factor
basis/cpu/x86/64/winnt/winnt.factor
vm/Config.windows.nt.x86.64
vm/bitwise_hacks.hpp
vm/code_blocks.cpp
vm/cpu-x86.hpp
vm/errors.cpp
vm/ffi_test.h
vm/full_collector.cpp
vm/instruction_operands.cpp
vm/instruction_operands.hpp
vm/master.hpp
vm/math.cpp
vm/os-windows-nt.64.hpp
vm/os-windows-nt.cpp
vm/run.cpp
vm/strings.cpp
vm/vm.hpp

index e964105d9f409bc59a06dd43579a652aea4a1370..07984e35c82bfdf6b4df6d0f501de862b388709b 100755 (executable)
--- a/Nmakefile
+++ b/Nmakefile
@@ -1,5 +1,10 @@
+!IF DEFINED(DEBUG)\r
+LINK_FLAGS = /nologo /DEBUG shell32.lib\r
+CL_FLAGS = /nologo /Zi /O2 /W3 /DFACTOR_DEBUG\r
+!ELSE\r
 LINK_FLAGS = /nologo shell32.lib\r
 CL_FLAGS = /nologo /O2 /W3\r
+!ENDIF\r
 \r
 EXE_OBJS = factor.dll.lib vm\main-windows-nt.obj vm\factor.res\r
 \r
@@ -50,11 +55,17 @@ DLL_OBJS = vm\os-windows-nt.obj \
 .cpp.obj:\r
        cl /EHsc $(CL_FLAGS) /Fo$@ /c $<\r
 \r
+.c.obj:\r
+       cl $(CL_FLAGS) /Fo$@ /c $<\r
+\r
 .rs.res:\r
        rc $<\r
 \r
 all: factor.com factor.exe\r
 \r
+libfactor-ffi-test.dll: vm/ffi_test.obj\r
+       link $(LINK_FLAGS) /out:libfactor-ffi-test.dll /dll vm/ffi_test.obj\r
+\r
 factor.dll.lib: $(DLL_OBJS)\r
        link $(LINK_FLAGS) /implib:factor.dll.lib /out:factor.dll /dll $(DLL_OBJS)\r
 \r
index d3196397c311a0d0c915477f1182e395407e6a38..5213030bdf0d7c075ddec8f91c4837d0342fee61 100644 (file)
@@ -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 -- )
index a398c6565c651d383b783171e313fcd909f81a34..c75bb5a1b93ba9e80a4499bda6d90bcf3c86af73 100644 (file)
@@ -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 ;
 
index 13ef665b1953a40a275fa4009cb6604ad0cd2f27..ddb61480e5cf8c340bf8a1708b0cda2fa259d5a4 100644 (file)
@@ -1,4 +1,3 @@
-#error "lol"
 DLL_PATH=http://factorcode.org/dlls/64
 CC=$(WIN64_PATH)-gcc.exe
 WINDRES=$(WIN64_PATH)-windres.exe
index 1927cd4736199909d2e5e439b7a2ca11959adbb9..162d9272c6ca9a93a2941fdfcaa7087082519478 100755 (executable)
@@ -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
index 89106499da7c2f201721c91e4e0f60ca4f8ca80b..f523dac3a051b2875a6d79064a6dd3139eab306e 100755 (executable)
@@ -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()
index c96291b0d72da9be33552f2386bb4dfedd21062c..97e5a203059a221ac973ebdc3c6327e80da3b7a9 100644 (file)
@@ -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)
index 2dcb773dd1c06b81ec9528708c9e2afb47191791..ae560012aa6f49902c5dbc123e437b4361e3b341 100755 (executable)
@@ -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);
 }
index af0c0b46a4b7051ee782965c8218be28a0f01802..661f3b64de5eb9c9ed1a482f67b39f9c587d0134 100644 (file)
@@ -1,4 +1,8 @@
-#include <stdbool.h>
+#ifdef _MSC_VER
+       #define WINDOWS
+#else
+       #include <stdbool.h>
+#endif
 
 #if defined(i386) || defined(__i386) || defined(__i386__) || defined(WIN32)
        #define F_STDCALL __attribute__((stdcall))
index 4de2814f1dfeb89646692226ff4d8d0fdf63208b..ec0972e952b709ea20eb8b8889bc0e9b37225023 100644 (file)
@@ -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;
        }
index db869d9d01574d03e1f0a66a5b7083fe549c6418..59dbf1ef8e3e702a47faa159ed665955538169ab 100644 (file)
@@ -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);
index d46b5cf3913c35a9a4c75f88c1774783218e4f08..dc8aa9d841d24a2f47b275a29aaa5b1ef61565f6 100644 (file)
@@ -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()
index f4c093447847c498160fd0862ee2c5f64cf2b854..70736c1bd9d127dbe26c29b5bf7b75a885dd848b 100755 (executable)
 /* 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
        #define WINDOWS
 #endif
 
-#ifndef _MSC_VER
-       #include <stdbool.h>
-#endif
-
 /* Forward-declare this since it comes up in function prototypes */
 namespace factor
 {
index a2c69c31f2a6af0514570b7c52469d944359e8aa..ef4a59933167b2a51cd06745361cc60bce91227c 100755 (executable)
@@ -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<bignum>(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<byte_array>(ctx->peek()));
+       unsigned int n_digits = (unsigned int)array_capacity(untag_check<byte_array>(ctx->peek()));
        bignum * result = digit_stream_to_bignum(n_digits,factor::bignum_producer,0x100,0);
        ctx->replace(tag<bignum>(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()
index b64bd607cbe86167abbc3ba39ad2a0d8d1ca07fa..aff662a4899428e9155bbbc9bdded9a613076ba6 100755 (executable)
@@ -4,7 +4,6 @@ namespace factor
 #define ESP Rsp
 #define EIP Rip
 
-#define X87SW(ctx) (ctx)->FloatSave.StatusWord
 #define MXCSR(ctx) (ctx)->MxCsr
 
 }
index 2fceb130f4e8eb29be189ff8d6515c5fe3be3d5f..cf5878e5bfb27eca79ebc97186259606610b6dbc 100755 (executable)
@@ -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;
index dfff8f2f2d30e4c662a590f62807de8e15eda8fa..6c8a8452e70d26c185ccb097901893ef20ae77c8 100755 (executable)
@@ -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()
index 67e4fb4508b909fe2af48a5b9ca6e74a24528183..5aad936a9eb3e378efad85517bb6ab314a16c7a1 100644 (file)
@@ -81,7 +81,7 @@ void factor_vm::fill_string(string *str_, cell start, cell capacity, cell fill)
        data_root<string> str(str_,this);
 
        if(fill <= 0x7f)
-               memset(&str->data()[start],fill,capacity - start);
+               memset(&str->data()[start],(int)fill,capacity - start);
        else
        {
                cell i;
index 6fb788d531a2364c516724cb5b1307778e7b56b3..6b12cc42c0f96c75aa7cdb153f3e9ab5167dc38d 100755 (executable)
--- 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
        }