From 9a0ac0e97558e58ffb717e28fb8ed26d9e82edde Mon Sep 17 00:00:00 2001 From: "U-C4\\Administrator" Date: Thu, 27 Sep 2007 15:10:37 -0500 Subject: [PATCH] Attempt to merge in changes F_FASTCALL --- core/compiler/test/intrinsics.factor | 22 +++++++++++++--------- vm/cpu-ppc.h | 2 +- vm/cpu-x86.32.h | 3 ++- vm/cpu-x86.64.h | 2 +- vm/cpu-x86.S | 16 ++++++++-------- vm/cpu-x86.h | 14 +++++++------- vm/jit.c | 2 +- vm/jit.h | 2 +- vm/os-unix.c | 10 ---------- vm/os-windows-nt.c | 18 ++---------------- vm/os-windows-nt.h | 2 ++ vm/primitives.h | 12 ++++++------ vm/run.c | 17 ++++++++++++++++- vm/run.h | 2 +- vm/stack.c | 2 +- vm/stack.h | 2 +- 16 files changed, 63 insertions(+), 65 deletions(-) diff --git a/core/compiler/test/intrinsics.factor b/core/compiler/test/intrinsics.factor index 23e94a7974..3a18f0ebe4 100644 --- a/core/compiler/test/intrinsics.factor +++ b/core/compiler/test/intrinsics.factor @@ -361,19 +361,23 @@ cell 8 = [ [ ] [ B{ 1 2 3 4 5 } malloc-byte-array "b" set ] unit-test -[ 3 ] [ "b" get 2 [ alien-unsigned-1 ] compile-1 ] unit-test -[ 3 ] [ "b" get [ { simple-alien } declare 2 alien-unsigned-1 ] compile-1 ] unit-test -[ 3 ] [ "b" get 2 [ { simple-alien fixnum } declare alien-unsigned-1 ] compile-1 ] unit-test -[ 3 ] [ "b" get 2 [ { simple-c-ptr fixnum } declare alien-unsigned-1 ] compile-1 ] unit-test +"b" get [ + [ 3 ] [ "b" get 2 [ alien-unsigned-1 ] compile-1 ] unit-test + [ 3 ] [ "b" get [ { simple-alien } declare 2 alien-unsigned-1 ] compile-1 ] unit-test + [ 3 ] [ "b" get 2 [ { simple-alien fixnum } declare alien-unsigned-1 ] compile-1 ] unit-test + [ 3 ] [ "b" get 2 [ { simple-c-ptr fixnum } declare alien-unsigned-1 ] compile-1 ] unit-test -[ ] [ "b" get free ] unit-test + [ ] [ "b" get free ] unit-test +] when -[ ] [ "hello world" malloc-char-string "s" set ] unit-test +[ t ] [ "hello world" malloc-char-string "s" set ] unit-test -[ "hello world" ] [ "s" get [ { byte-array } declare *void* ] compile-1 alien>char-string ] unit-test -[ "hello world" ] [ "s" get [ { simple-c-ptr } declare *void* ] compile-1 alien>char-string ] unit-test +"s" get [ + [ "hello world" ] [ "s" get [ { byte-array } declare *void* ] compile-1 alien>char-string ] unit-test + [ "hello world" ] [ "s" get [ { simple-c-ptr } declare *void* ] compile-1 alien>char-string ] unit-test -[ ] [ "s" get free ] unit-test + [ ] [ "s" get free ] unit-test +] when [ ALIEN: 1234 ] [ ALIEN: 1234 [ { simple-alien } declare ] compile-1 *void* ] unit-test [ ALIEN: 1234 ] [ ALIEN: 1234 [ { simple-c-ptr } declare ] compile-1 *void* ] unit-test diff --git a/vm/cpu-ppc.h b/vm/cpu-ppc.h index c74e13e68b..ac4a0a92ee 100644 --- a/vm/cpu-ppc.h +++ b/vm/cpu-ppc.h @@ -1,5 +1,5 @@ #define FACTOR_CPU_STRING "ppc" -#define FASTCALL +#define F_FASTCALL register CELL ds asm("r14"); register CELL rs asm("r15"); diff --git a/vm/cpu-x86.32.h b/vm/cpu-x86.32.h index 4c4acb0ad3..a81c9987c4 100644 --- a/vm/cpu-x86.32.h +++ b/vm/cpu-x86.32.h @@ -3,4 +3,5 @@ register CELL ds asm("esi"); register CELL rs asm("edi"); -#define FASTCALL __attribute__ ((regparm (2))) +#define F_FASTCALL __attribute__ ((regparm (2))) + diff --git a/vm/cpu-x86.64.h b/vm/cpu-x86.64.h index 0b3b5a2471..6412355129 100644 --- a/vm/cpu-x86.64.h +++ b/vm/cpu-x86.64.h @@ -3,4 +3,4 @@ register CELL ds asm("r14"); register CELL rs asm("r15"); -#define FASTCALL +#define F_FASTCALL diff --git a/vm/cpu-x86.S b/vm/cpu-x86.S index ec5d09291e..7032b77e18 100644 --- a/vm/cpu-x86.S +++ b/vm/cpu-x86.S @@ -2,7 +2,7 @@ mov QUOT_XT_OFFSET(ARG0),XT_REG ; /* Load quot-xt */ \ jmp *XT_REG /* Jump to quot-xt */ -DEF(FASTCALL void,c_to_factor,(CELL quot)): +DEF(F_FASTCALL void,c_to_factor,(CELL quot)): PUSH_NONVOLATILE push ARG0 /* Save quot */ @@ -17,38 +17,38 @@ DEF(FASTCALL void,c_to_factor,(CELL quot)): POP_NONVOLATILE ret -DEF(FASTCALL void,undefined,(CELL word)): +DEF(F_FASTCALL void,undefined,(CELL word)): mov STACK_REG,ARG1 /* Pass callstack pointer */ jmp MANGLE(undefined_error) /* This throws an error */ -DEF(FASTCALL void,dosym,(CELL word)): +DEF(F_FASTCALL void,dosym,(CELL word)): add $CELL_SIZE,DS_REG /* Increment stack pointer */ mov ARG0,(DS_REG) /* Store word on stack */ ret /* Here we have two entry points. The first one is taken when profiling is enabled */ -DEF(FASTCALL void,docol_profiling,(CELL word)): +DEF(F_FASTCALL void,docol_profiling,(CELL word)): add $CELL_SIZE,PROFILING_OFFSET(ARG0) /* Increment profile-count slot */ -DEF(FASTCALL void,docol,(CELL word)): +DEF(F_FASTCALL void,docol,(CELL word)): mov WORD_DEF_OFFSET(ARG0),ARG0 /* Load word-def slot */ JUMP_QUOT /* We must pass the XT to the quotation in ECX. */ -DEF(FASTCALL void,primitive_call,(void)): +DEF(F_FASTCALL void,primitive_call,(void)): mov (DS_REG),ARG0 /* Load quotation from data stack */ sub $CELL_SIZE,DS_REG /* Pop data stack */ JUMP_QUOT /* We pass the word in EAX and the XT in ECX. Don't mess up EDX, it's the callstack top parameter to primitives. */ -DEF(FASTCALL void,primitive_execute,(void)): +DEF(F_FASTCALL void,primitive_execute,(void)): mov (DS_REG),ARG0 /* Load word from data stack */ sub $CELL_SIZE,DS_REG /* Pop data stack */ mov WORD_XT_OFFSET(ARG0),XT_REG /* Load word-xt slot */ jmp *XT_REG /* Go */ -DEF(FASTCALL void,throw_impl,(CELL quot, F_STACK_FRAME *rewind_to)): +DEF(F_FASTCALL void,throw_impl,(CELL quot, F_STACK_FRAME *rewind_to)): mov ARG1,STACK_REG /* rewind_to */ JUMP_QUOT diff --git a/vm/cpu-x86.h b/vm/cpu-x86.h index 63bf2b08e1..91f1f8236a 100644 --- a/vm/cpu-x86.h +++ b/vm/cpu-x86.h @@ -22,12 +22,12 @@ typedef struct _F_STACK_FRAME INLINE void flush_icache(CELL start, CELL len) {} -FASTCALL void c_to_factor(CELL quot); -FASTCALL void throw_impl(CELL quot, F_STACK_FRAME *rewind_to); -FASTCALL void undefined(CELL word); -FASTCALL void dosym(CELL word); -FASTCALL void docol_profiling(CELL word); -FASTCALL void docol(CELL word); -FASTCALL void lazy_jit_compile(CELL quot); +F_FASTCALL void c_to_factor(CELL quot); +F_FASTCALL void throw_impl(CELL quot, F_STACK_FRAME *rewind_to); +F_FASTCALL void undefined(CELL word); +F_FASTCALL void dosym(CELL word); +F_FASTCALL void docol_profiling(CELL word); +F_FASTCALL void docol(CELL word); +F_FASTCALL void lazy_jit_compile(CELL quot); void set_callstack(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy); diff --git a/vm/jit.c b/vm/jit.c index 6faf0a6a17..51fa06ef86 100644 --- a/vm/jit.c +++ b/vm/jit.c @@ -34,7 +34,7 @@ bool jit_stack_frame_p(F_ARRAY *array) return false; } -FASTCALL CELL jit_compile(CELL tagged, F_STACK_FRAME *stack) +F_FASTCALL CELL jit_compile(CELL tagged, F_STACK_FRAME *stack) { stack_chain->callstack_top = stack; diff --git a/vm/jit.h b/vm/jit.h index a9f1399472..d1c91b631b 100644 --- a/vm/jit.h +++ b/vm/jit.h @@ -1,2 +1,2 @@ -DLLEXPORT FASTCALL CELL jit_compile(CELL tagged, F_STACK_FRAME *stack); +DLLEXPORT F_FASTCALL CELL jit_compile(CELL tagged, F_STACK_FRAME *stack); XT quot_offset_to_pc(F_QUOTATION *quot, F_FIXNUM offset); diff --git a/vm/os-unix.c b/vm/os-unix.c index 2d9ba02ca5..65ae79550c 100644 --- a/vm/os-unix.c +++ b/vm/os-unix.c @@ -179,11 +179,6 @@ INLINE F_STACK_FRAME *uap_stack_pointer(void *uap) return NULL; } -void memory_signal_handler_impl(void) -{ - memory_protection_error(signal_fault_addr,signal_callstack_top); -} - void memory_signal_handler(int signal, siginfo_t *siginfo, void *uap) { signal_fault_addr = (CELL)siginfo->si_addr; @@ -191,11 +186,6 @@ void memory_signal_handler(int signal, siginfo_t *siginfo, void *uap) UAP_PROGRAM_COUNTER(uap) = (CELL)memory_signal_handler_impl; } -void misc_signal_handler_impl(void) -{ - signal_error(signal_number,signal_callstack_top); -} - void misc_signal_handler(int signal, siginfo_t *siginfo, void *uap) { signal_number = signal; diff --git a/vm/os-windows-nt.c b/vm/os-windows-nt.c index cf40745cdd..8f7513a32a 100644 --- a/vm/os-windows-nt.c +++ b/vm/os-windows-nt.c @@ -27,10 +27,11 @@ long exception_handler(PEXCEPTION_POINTERS pe) { PEXCEPTION_RECORD e = (PEXCEPTION_RECORD)pe->ExceptionRecord; CONTEXT *c = (CONTEXT*)pe->ContextRecord; - void *signal_callstack_top = NULL; if(in_code_heap_p(c->Eip)) signal_callstack_top = (void*)c->Esp; + else + signal_callstack_top = NULL; if(e->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { @@ -58,18 +59,3 @@ void c_to_factor_toplevel(CELL quot) c_to_factor(quot); RemoveVectoredExceptionHandler((void*)exception_handler); } - -void memory_signal_handler_impl(void) -{ - memory_protection_error(signal_fault_addr,signal_callstack_top); -} - -void divide_by_zero_signal_handler_impl(void) -{ - general_error(ERROR_DIVIDE_BY_ZERO,F,F,signal_callstack_top); -} - -void misc_signal_handler_impl(void) -{ - signal_error(signal_number,signal_callstack_top); -} diff --git a/vm/os-windows-nt.h b/vm/os-windows-nt.h index 4dc87d0f83..f3017b0cbe 100644 --- a/vm/os-windows-nt.h +++ b/vm/os-windows-nt.h @@ -14,6 +14,8 @@ typedef char F_SYMBOL; #define FACTOR_DLL L"factor-nt.dll" #define FACTOR_DLL_NAME "factor-nt.dll" +void c_to_factor_toplevel(CELL quot); + CELL signal_number; CELL signal_fault_addr; void *signal_callstack_top; diff --git a/vm/primitives.h b/vm/primitives.h index ce22cff528..2c0040f13f 100644 --- a/vm/primitives.h +++ b/vm/primitives.h @@ -14,19 +14,19 @@ DEFINE_PRIMITIVE(name) Becomes -FASTCALL void primitive_name(CELL word, F_STACK_FRAME *callstack_top) +F_FASTCALL void primitive_name(CELL word, F_STACK_FRAME *callstack_top) { stack_chain->callstack_top = callstack_top; ... CODE ... } -On x86, FASTCALL expands into a GCC declaration which forces the two parameters -to be passed in registers. This simplifies the quotation compiler and support -code in cpu-x86.S. */ +On x86, F_FASTCALL expands into a GCC declaration which forces the two +parameters to be passed in registers. This simplifies the quotation compiler +and support code in cpu-x86.S. */ #define DEFINE_PRIMITIVE(name) \ INLINE void primitive_##name##_impl(void); \ \ - FASTCALL void primitive_##name(CELL word, F_STACK_FRAME *callstack_top) \ + F_FASTCALL void primitive_##name(CELL word, F_STACK_FRAME *callstack_top) \ { \ stack_chain->callstack_top = callstack_top; \ primitive_##name##_impl(); \ @@ -36,4 +36,4 @@ code in cpu-x86.S. */ /* Prototype for header files */ #define DECLARE_PRIMITIVE(name) \ - FASTCALL void primitive_##name(CELL word, F_STACK_FRAME *callstack_top) + F_FASTCALL void primitive_##name(CELL word, F_STACK_FRAME *callstack_top) diff --git a/vm/run.c b/vm/run.c index 255be845d3..d4f95a47f2 100644 --- a/vm/run.c +++ b/vm/run.c @@ -197,7 +197,7 @@ void not_implemented_error(void) } /* This function is called from the undefined function in cpu_*.S */ -FASTCALL void undefined_error(CELL word, F_STACK_FRAME *callstack_top) +F_FASTCALL void undefined_error(CELL word, F_STACK_FRAME *callstack_top) { stack_chain->callstack_top = callstack_top; general_error(ERROR_UNDEFINED_WORD,word,F,NULL); @@ -244,6 +244,21 @@ void divide_by_zero_error(F_STACK_FRAME *native_stack) general_error(ERROR_DIVIDE_BY_ZERO,F,F,native_stack); } +void memory_signal_handler_impl(void) +{ + memory_protection_error(signal_fault_addr,signal_callstack_top); +} + +void divide_by_zero_signal_handler_impl(void) +{ + divide_by_zero_error(signal_callstack_top); +} + +void misc_signal_handler_impl(void) +{ + signal_error(signal_number,signal_callstack_top); +} + DEFINE_PRIMITIVE(throw) { uncurry(dpop()); diff --git a/vm/run.h b/vm/run.h index 72ee7eea17..73454989ce 100644 --- a/vm/run.h +++ b/vm/run.h @@ -197,7 +197,7 @@ void signal_error(int signal, F_STACK_FRAME *native_stack); void type_error(CELL type, CELL tagged); void not_implemented_error(void); -FASTCALL void undefined_error(CELL word, F_STACK_FRAME *callstack_top); +F_FASTCALL void undefined_error(CELL word, F_STACK_FRAME *callstack_top); DECLARE_PRIMITIVE(throw); diff --git a/vm/stack.c b/vm/stack.c index b2a05b9181..9ba4e35bf5 100644 --- a/vm/stack.c +++ b/vm/stack.c @@ -19,7 +19,7 @@ void fix_stacks(void) } /* called before entry into Factor code. */ -FASTCALL void save_callstack_bottom(F_STACK_FRAME *callstack_bottom) +F_FASTCALL void save_callstack_bottom(F_STACK_FRAME *callstack_bottom) { stack_chain->callstack_bottom = callstack_bottom; } diff --git a/vm/stack.h b/vm/stack.h index 62ee1d9ba2..58be5ae52f 100644 --- a/vm/stack.h +++ b/vm/stack.h @@ -48,7 +48,7 @@ CELL ds_size, rs_size; void reset_datastack(void); void reset_retainstack(void); void fix_stacks(void); -FASTCALL void save_callstack_bottom(F_STACK_FRAME *callstack_bottom); +F_FASTCALL void save_callstack_bottom(F_STACK_FRAME *callstack_bottom); DLLEXPORT void save_stacks(void); DLLEXPORT void nest_stacks(void); DLLEXPORT void unnest_stacks(void);