From f653f3d39ff6a0b50aad6c9f9ae59cb70f47daad Mon Sep 17 00:00:00 2001 From: Chris Double Date: Sat, 22 Sep 2007 12:24:53 +1200 Subject: [PATCH 01/24] Ignore factor build files on MacOS X --- .gitignore | 1 + Factor.app/Contents/MacOS/.dummy | 0 2 files changed, 1 insertion(+) create mode 100644 Factor.app/Contents/MacOS/.dummy diff --git a/.gitignore b/.gitignore index 5148db3022..a3f5d94252 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ Factor/factor *.lib *.image *.dylib +factor diff --git a/Factor.app/Contents/MacOS/.dummy b/Factor.app/Contents/MacOS/.dummy new file mode 100644 index 0000000000..e69de29bb2 From a00432b64e0435d6b8f88c4006a6e33c0d6de839 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 21 Sep 2007 22:32:32 -0400 Subject: [PATCH 02/24] HTTPD fix --- extra/http/server/responders/responders.factor | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/extra/http/server/responders/responders.factor b/extra/http/server/responders/responders.factor index b13239ac55..725cb515b0 100644 --- a/extra/http/server/responders/responders.factor +++ b/extra/http/server/responders/responders.factor @@ -126,13 +126,7 @@ SYMBOL: max-post-request #! Add a responder object to the list. "responder" over at responders get set-at ; -: add-simple-responder ( name quot -- ) - [ - [ drop ] swap append dup "get" set "post" set - "responder" set - ] H{ } make-assoc add-responder ; - -: make-responder ( quot -- responder ) +: make-responder ( quot -- ) #! quot has stack effect ( url -- ) [ [ @@ -151,6 +145,12 @@ SYMBOL: max-post-request call ] H{ } make-assoc add-responder ; +: add-simple-responder ( name quot -- ) + [ + [ drop ] swap append dup "get" set "post" set + "responder" set + ] make-responder ; + : vhost ( name -- vhost ) vhosts get at [ "default" vhost ] unless* ; @@ -175,7 +175,7 @@ SYMBOL: max-post-request "/" ?head drop ; : serve-explicit-responder ( method url -- ) - "/" split1 + "/" split1 "/responder/" pick "/" 3append "responder-url" set dup [ swap responder call-responder @@ -200,7 +200,7 @@ SYMBOL: max-post-request "404 No such responder" httpd-error ; ! create a responders hash if it doesn't already exist -global [ +global [ responders [ H{ } assoc-like ] change ! 404 error message pages are served by this guy From 7ff85dd33ec8d2a0158a9dbb95b626eecd199663 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 21 Sep 2007 22:56:01 -0400 Subject: [PATCH 03/24] Clean up x86 support code --- vm/cpu-x86.32.S | 45 +++++++++++++++++++++++++++++++++++++++++++++ vm/cpu-x86.32.h | 8 ++++++++ vm/cpu-x86.64.S | 41 +++++++++++++++++++++++++++++++++++++++++ vm/cpu-x86.64.h | 6 ++++++ 4 files changed, 100 insertions(+) create mode 100644 vm/cpu-x86.32.S create mode 100644 vm/cpu-x86.32.h create mode 100644 vm/cpu-x86.64.S create mode 100644 vm/cpu-x86.64.h diff --git a/vm/cpu-x86.32.S b/vm/cpu-x86.32.S new file mode 100644 index 0000000000..57f8656a75 --- /dev/null +++ b/vm/cpu-x86.32.S @@ -0,0 +1,45 @@ +#include "asm.h" + +/* Note that primitive word definitions are compiled with +__attribute__((regparm 2), so the pointer to the word object is passed in EAX, +and the callstack top is passed in EDX */ + +#define ARG0 %eax +#define ARG1 %edx +#define XT_REG %ecx +#define STACK_REG %esp +#define DS_REG %edi + +#define CELL_SIZE 4 + +#define PUSH_NONVOLATILE \ + push %ebx \ + push %ebp + +#define POP_NONVOLATILE \ + pop %ebp \ + pop %ebx + +#define QUOT_XT_OFFSET 5 +#define PROFILING_OFFSET 25 +#define WORD_DEF_OFFSET 13 +#define WORD_XT_OFFSET 29 + +/* We pass a function pointer to memcpy in 16(%esp) to work around a Mac OS X +ABI limitation which would otherwise require us to do a bizzaro PC-relative +trampoline to retrieve the function address */ +DEF(void,set_callstack,(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy)): + mov 4(%esp),%ebp /* to */ + mov 8(%esp),%edx /* from */ + mov 12(%esp),%ecx /* length */ + mov 16(%esp),%eax /* memcpy */ + sub %ecx,%ebp /* compute new stack pointer */ + mov %ebp,%esp + push %ecx /* pass length */ + push %edx /* pass src */ + push %ebp /* pass dst */ + call *%eax /* call memcpy */ + add $12,%esp /* pop args from the stack */ + ret /* return _with new stack_ */ + +#include "cpu-x86.S" diff --git a/vm/cpu-x86.32.h b/vm/cpu-x86.32.h new file mode 100644 index 0000000000..0129737685 --- /dev/null +++ b/vm/cpu-x86.32.h @@ -0,0 +1,8 @@ +#define FACTOR_CPU_STRING "x86.32" + +register CELL ds asm("esi"); +register CELL rs asm("edi"); + +#define FASTCALL __attribute__ ((regparm (2))) + +void set_callstack(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy); diff --git a/vm/cpu-x86.64.S b/vm/cpu-x86.64.S new file mode 100644 index 0000000000..12af25eec5 --- /dev/null +++ b/vm/cpu-x86.64.S @@ -0,0 +1,41 @@ +#include "asm.h" + +#define ARG0 %rdi +#define ARG1 %rsi +#define XT_REG %rcx +#define STACK_REG %rsp +#define DS_REG %r14 + +#define CELL_SIZE 8 + +#define PUSH_NONVOLATILE \ + push %rbx \ + push %rbp \ + push %r12 \ + push %r13 \ + push %r16 \ + push %rax /* Alignment */ + +#define POP_NONVOLATILE \ + pop %rax /* Alignment */ \ + pop %r16 \ + pop %r13 \ + pop %r12 \ + pop %rbp \ + pop %rbx + +#define QUOT_XT_OFFSET 13 +#define PROFILING_OFFSET 53 +#define WORD_DEF_OFFSET 29 +#define WORD_XT_OFFSET 61 + +/* We pass a function pointer to memcpy in 16(%esp) to work around a Mac OS X +ABI limitation which would otherwise require us to do a bizzaro PC-relative +trampoline to retrieve the function address */ +DEF(void,set_callstack,(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy)): + sub %rdx,%rdi /* compute new stack pointer */ + mov %rdi,%rsp + call *%rcx /* call memcpy */ + ret /* return _with new stack_ */ + +#include "cpu-x86.S" diff --git a/vm/cpu-x86.64.h b/vm/cpu-x86.64.h new file mode 100644 index 0000000000..0b3b5a2471 --- /dev/null +++ b/vm/cpu-x86.64.h @@ -0,0 +1,6 @@ +#define FACTOR_CPU_STRING "x86.64" + +register CELL ds asm("r14"); +register CELL rs asm("r15"); + +#define FASTCALL From e2c65cbc2d1221e92672b829cd5d4d37d49bd2d2 Mon Sep 17 00:00:00 2001 From: Slava Date: Fri, 21 Sep 2007 23:44:13 -0400 Subject: [PATCH 04/24] FreeBSD/x86 support --- vm/os-freebsd-x86.h | 1 + 1 file changed, 1 insertion(+) create mode 100644 vm/os-freebsd-x86.h diff --git a/vm/os-freebsd-x86.h b/vm/os-freebsd-x86.h new file mode 100644 index 0000000000..34299691bc --- /dev/null +++ b/vm/os-freebsd-x86.h @@ -0,0 +1 @@ +#define UAP_PROGRAM_COUNTER(ucontext) (((ucontext_t *)(ucontext))->uc_mcontext.mc_eip) From 63871229f64810ccb2060990a24a7f16e2d58ccb Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 21 Sep 2007 23:29:38 -0400 Subject: [PATCH 05/24] More x86 cleanups, working on AMD64 --- core/cpu/x86/bootstrap.factor | 102 ++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 core/cpu/x86/bootstrap.factor diff --git a/core/cpu/x86/bootstrap.factor b/core/cpu/x86/bootstrap.factor new file mode 100644 index 0000000000..21bcaf3aa3 --- /dev/null +++ b/core/cpu/x86/bootstrap.factor @@ -0,0 +1,102 @@ +! Copyright (C) 2007 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: bootstrap.image.private kernel namespaces system +cpu.x86.assembler layouts vocabs math ; +IN: bootstrap.x86 + +big-endian off + +1 jit-code-format set + +: scan-save stack-reg 3 bootstrap-cells [+] ; + +[ + arg0 arg0 quot-array@ [+] MOV ! load array + scan-reg arg0 scan@ [+] LEA ! initialize scan pointer +] { } make jit-setup set + +[ + xt-reg PUSH ! save XT + xt-reg stack-reg -44 [+] LEA ! compute forward chain pointer + xt-reg PUSH ! save forward chain pointer + arg0 PUSH ! save array + stack-reg 2 bootstrap-cells SUB ! reserve space for scan-save +] { } make jit-prolog set + +: advance-scan scan-reg bootstrap-cell ADD ; + +[ + advance-scan + ds-reg bootstrap-cell ADD ! increment datastack pointer + arg0 scan-reg [] MOV ! load literal + ds-reg [] arg0 MOV ! store literal on datastack +] { } make jit-push-literal set + +[ + advance-scan + ds-reg bootstrap-cell ADD ! increment datastack pointer + arg0 scan-reg [] MOV ! load wrapper + arg0 dup wrapper@ [+] MOV ! load wrapper-obj slot + ds-reg [] arg0 MOV ! store literal on datastack +] { } make jit-push-wrapper set + +[ + arg1 stack-reg MOV ! pass callstack pointer as arg 2 +] { } make jit-word-primitive-jump set + +[ + arg1 stack-reg bootstrap-cell neg [+] LEA ! pass callstack pointer as arg 2 +] { } make jit-word-primitive-call set + +[ + arg0 scan-reg bootstrap-cell [+] MOV ! load word + arg0 word-xt@ [+] JMP ! jump to word XT +] { } make jit-word-jump set + +[ + advance-scan + scan-save scan-reg MOV ! save scan pointer + arg0 scan-reg [] MOV ! load word + arg0 word-xt@ [+] CALL ! call word XT + scan-reg scan-save MOV ! restore scan pointer +] { } make jit-word-call set + +: load-branch + arg0 ds-reg [] MOV ! load boolean + ds-reg bootstrap-cell SUB ! pop boolean + arg0 \ f tag-number CMP ! compare it with f + arg0 scan-reg 2 bootstrap-cells [+] CMOVE ! load false branch if equal + arg0 scan-reg 1 bootstrap-cells [+] CMOVNE ! load true branch if not equal + scan-reg 3 bootstrap-cells ADD ! advance scan pointer + xt-reg arg0 quot-xt@ [+] MOV ! load quotation-xt + ; + +[ + load-branch + xt-reg JMP +] { } make jit-if-jump set + +[ + load-branch + stack-reg [] scan-reg MOV ! save scan pointer + xt-reg CALL ! call quotation + scan-reg stack-reg [] MOV ! restore scan pointer +] { } make jit-if-call set + +[ + arg0 ds-reg [] MOV ! load index + fixnum>slot@ ! turn it into an array offset + ds-reg bootstrap-cell SUB ! pop index + arg0 scan-reg bootstrap-cell [+] ADD ! compute quotation location + arg0 arg0 array-start [+] MOV ! load quotation + xt-reg arg0 quot-xt@ [+] MOV ! load quotation-xt + xt-reg JMP ! execute quotation +] { } make jit-dispatch set + +[ + stack-reg 7 cells ADD ! unwind stack frame +] { } make jit-epilog set + +[ 0 RET ] { } make jit-return set + +"bootstrap.x86" forget-vocab From 3a1d458b2945a1892266f36a5d442d822c531e1a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 21 Sep 2007 23:30:47 -0400 Subject: [PATCH 06/24] More changes --- core/cpu/x86/32/bootstrap.factor | 103 +++---------------------------- core/cpu/x86/64/64.factor | 4 +- core/cpu/x86/64/bootstrap.factor | 17 ++++- vm/cpu-x86.S | 92 ++++++++++----------------- vm/cpu-x86.h | 24 ++----- vm/os-macosx.m | 10 +-- vm/platform.h | 6 +- vm/run.h | 3 +- vm/stack.h | 2 +- 9 files changed, 73 insertions(+), 188 deletions(-) diff --git a/core/cpu/x86/32/bootstrap.factor b/core/cpu/x86/32/bootstrap.factor index f9504f50c7..32d07797e7 100644 --- a/core/cpu/x86/32/bootstrap.factor +++ b/core/cpu/x86/32/bootstrap.factor @@ -1,106 +1,17 @@ ! Copyright (C) 2007 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: bootstrap.image.private kernel namespaces system -cpu.x86.assembler layouts vocabs ; -IN: bootstrap.x86.32 +cpu.x86.assembler layouts vocabs parser ; +IN: bootstrap.x86 4 \ cell set -big-endian off - -1 jit-code-format set +: arg0 EAX ; +: arg1 EDX ; +: stack-reg ESP ; : ds-reg ESI ; : scan-reg EBX ; : xt-reg ECX ; -: scan-save ESP 12 [+] ; +: fixnum>slot@ arg0 1 SAR ; -[ - EAX EAX quot-array@ [+] MOV ! load array - scan-reg EAX 1 [+] LEA ! initialize scan pointer -] { } make jit-setup set - -[ - xt-reg PUSH ! save XT - xt-reg ESP -44 [+] LEA ! compute forward chain pointer - xt-reg PUSH ! save forward chain pointer - EAX PUSH ! save array - ESP 16 SUB ! reserve space for scan-save -] { } make jit-prolog set - -: advance-scan scan-reg 4 ADD ; - -[ - advance-scan - ds-reg 4 ADD ! increment datastack pointer - EAX scan-reg [] MOV ! load literal - ds-reg [] EAX MOV ! store literal on datastack -] { } make jit-push-literal set - -[ - advance-scan - ds-reg 4 ADD ! increment datastack pointer - EAX scan-reg [] MOV ! load wrapper - EAX dup wrapper@ [+] MOV ! load wrapper-obj slot - ds-reg [] EAX MOV ! store literal on datastack -] { } make jit-push-wrapper set - -[ - EDX ESP MOV ! pass callstack pointer as arg 2 -] { } make jit-word-primitive-jump set - -[ - EDX ESP -4 [+] LEA ! pass callstack pointer as arg 2 -] { } make jit-word-primitive-call set - -[ - EAX scan-reg 4 [+] MOV ! load word - EAX word-xt@ [+] JMP ! jump to word XT -] { } make jit-word-jump set - -[ - advance-scan - scan-save scan-reg MOV ! save scan pointer - EAX scan-reg [] MOV ! load word - EAX word-xt@ [+] CALL ! call word XT - scan-reg scan-save MOV ! restore scan pointer -] { } make jit-word-call set - -: load-branch - EAX ds-reg [] MOV ! load boolean - ds-reg 4 SUB ! pop boolean - EAX \ f tag-number CMP ! compare it with f - EAX scan-reg 8 [+] CMOVE ! load false branch if equal - EAX scan-reg 4 [+] CMOVNE ! load true branch if not equal - scan-reg 12 ADD ! advance scan pointer - xt-reg EAX quot-xt@ [+] MOV ! load quotation-xt - ; - -[ - load-branch - xt-reg JMP -] { } make jit-if-jump set - -[ - load-branch - ESP [] scan-reg MOV ! save scan pointer - xt-reg CALL ! call quotation - scan-reg ESP [] MOV ! restore scan pointer -] { } make jit-if-call set - -[ - EAX ds-reg [] MOV ! load index - EAX 1 SAR ! turn it into an array offset - ds-reg 4 SUB ! pop index - EAX scan-reg 4 [+] ADD ! compute quotation location - EAX EAX array-start [+] MOV ! load quotation - xt-reg EAX quot-xt@ [+] MOV ! load quotation-xt - xt-reg JMP ! execute quotation -] { } make jit-dispatch set - -[ - ESP 28 ADD ! unwind stack frame -] { } make jit-epilog set - -[ 0 RET ] { } make jit-return set - -"bootstrap.x86.32" forget-vocab +"resource:core/cpu/x86/bootstrap.factor" run-file diff --git a/core/cpu/x86/64/64.factor b/core/cpu/x86/64/64.factor index 1625a563f2..67c07608ab 100644 --- a/core/cpu/x86/64/64.factor +++ b/core/cpu/x86/64/64.factor @@ -14,10 +14,10 @@ M: amd64-backend ds-reg R14 ; M: amd64-backend rs-reg R15 ; M: amd64-backend stack-reg RSP ; -M: temp-reg v>operand drop R11 ; +M: temp-reg v>operand drop R16 ; M: int-regs return-reg drop RAX ; -M: int-regs vregs drop { RAX RCX RDX RSI RDI RBP R8 R9 R10 } ; +M: int-regs vregs drop { RAX RBX RCX RDX RBP RSI RDI R8 R9 R10 R11 R12 R13 } ; M: int-regs param-regs drop { RDI RSI RDX RCX R8 R9 } ; M: float-regs return-reg drop XMM0 ; diff --git a/core/cpu/x86/64/bootstrap.factor b/core/cpu/x86/64/bootstrap.factor index bccdcbd7f1..9d3fa8849f 100644 --- a/core/cpu/x86/64/bootstrap.factor +++ b/core/cpu/x86/64/bootstrap.factor @@ -1,4 +1,17 @@ -USING: bootstrap.image.private kernel namespaces system ; +! Copyright (C) 2007 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: bootstrap.image.private kernel namespaces system +cpu.x86.assembler layouts vocabs parser ; +IN: bootstrap.x86 8 \ cell set -big-endian off + +: arg0 RDI ; +: arg1 RSI ; +: stack-reg RSP ; +: ds-reg R14 ; +: scan-reg RBX ; +: xt-reg RCX ; +: fixnum>slot@ ; + +"resource:core/cpu/x86/bootstrap.factor" run-file diff --git a/vm/cpu-x86.S b/vm/cpu-x86.S index aa64002898..e8eeb403b7 100644 --- a/vm/cpu-x86.S +++ b/vm/cpu-x86.S @@ -1,83 +1,53 @@ -#include "asm.h" - -/* Note that primitive word definitions are compiled with -__attribute__((regparm 2), so the pointer to the word object is passed in EAX, -and the callstack top is passed in EDX */ - -/* When calling a quotation, we pass the XT in ECX */ #define JUMP_QUOT \ - mov 5(%eax),%ecx ; /* Load quot-xt */ \ - jmp *%ecx /* Jump to quot-xt */ + mov QUOT_XT_OFFSET(ARG0),XT_REG ; /* Load quot-xt */ \ + jmp *XT_REG /* Jump to quot-xt */ -DEF(void,c_to_factor,(CELL quot)): - push %ebp /* Save non-volatile registers */ - push %ebx +DEF(FASTCALL void,c_to_factor,(CELL quot)): + PUSH_NONVOLATILE + push ARG0 /* Save quot */ - lea -8(%esp),%eax /* Save stack pointer */ - push %eax /* This 16-byte aligns the stack */ + lea -CELL_SIZE(STACK_REG),ARG0 /* Save stack pointer */ call MANGLE(save_callstack_bottom) - mov 16(%esp),%eax /* Pass quot as arg 1 */ - mov 5(%eax),%ecx /* Pass quot-xt */ - call *%ecx /* Call quot-xt */ + mov (STACK_REG),ARG0 /* Pass quot as arg 1 */ + mov QUOT_XT_OFFSET(STACK_REG),XT_REG + call *XT_REG /* Call quot-xt */ - pop %eax /* Clobber */ - pop %ebx /* Restore non-volatile registers */ - pop %ebp + POP ARG0 + POP_NONVOLATILE ret -DEF(void,undefined,(CELL word)): - mov %esp,%ecx /* Save stack pointer before we mess with it */ - sub $12,%esp /* Alignment */ - mov %eax,4(%esp) /* Pass word as arg 1 (not fastcall) */ - mov %ecx,8(%esp) /* Pass callstack pointer as arg 2 (not fastcall) */ - jmp MANGLE(undefined_error) /* This throws an error */ +DEF(FASTCALL void,undefined,(CELL word)): + mov STACK_REG,ARG1 /* Pass callstack pointer as arg 2 (not fastcall) */ + jmp MANGLE(undefined_error) /* This throws an error */ -DEF(void,dosym,(CELL word)): - add $4,%esi /* Increment stack pointer */ - mov %eax,(%esi) /* Store word on stack */ +DEF(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(void,docol_profiling,(CELL word)): - add $8,25(%eax) /* Increment profile-count slot */ -DEF(void,docol,(CELL word)): - mov 13(%eax),%eax /* Load word-def slot */ +DEF(FASTCALL void,docol_profiling,(CELL word)): + add $CELL_SIZE,PROFILING_OFFSET(%eax) /* Increment profile-count slot */ +DEF(FASTCALL void,docol,(CELL word)): + mov WORD_XT_OFFSET(ARG0),ARG0 /* Load word-def slot */ JUMP_QUOT /* We must pass the XT to the quotation in ECX. */ -DEF(void,primitive_call,(void)): - mov (%esi),%eax /* Load quotation from data stack */ - sub $4,%esi /* Pop data stack */ +DEF(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(void,primitive_execute,(void)): - mov (%esi),%eax /* Load word from data stack */ - sub $4,%esi /* Pop data stack */ - mov 29(%eax),%ecx /* Load word-xt slot */ - jmp *%ecx /* Go */ +DEF(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 */ -/* We pass a function pointer to memcpy in 16(%esp) to work around a Mac OS X -ABI limitation which would otherwise require us to do a bizzaro PC-relative -trampoline to retrieve the function address */ -DEF(void,set_callstack,(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy)): - mov 4(%esp),%ebp /* to */ - mov 8(%esp),%edx /* from */ - mov 12(%esp),%ecx /* length */ - mov 16(%esp),%eax /* memcpy */ - sub %ecx,%ebp /* compute new stack pointer */ - mov %ebp,%esp - push %ecx /* pass length */ - push %edx /* pass src */ - push %ebp /* pass dst */ - call *%eax /* call memcpy */ - add $12,%esp /* pop args from the stack */ - ret /* return _with new stack_ */ - -DEF(void,throw_impl,(CELL quot, F_STACK_FRAME *rewind_to)): - mov 4(%esp),%eax /* quot */ - mov 8(%esp),%esp /* rewind_to */ +DEF(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 3fc111729e..e705432e70 100644 --- a/vm/cpu-x86.h +++ b/vm/cpu-x86.h @@ -1,10 +1,3 @@ -#define FACTOR_CPU_STRING "x86.32" - -register CELL ds asm("esi"); -register CELL rs asm("edi"); - -#define FASTCALL __attribute__ ((regparm (2))) - typedef struct _F_STACK_FRAME { /* In compiled quotation frames, position within the array. @@ -29,14 +22,9 @@ typedef struct _F_STACK_FRAME INLINE void flush_icache(CELL start, CELL len) {} -void c_to_factor(CELL quot); - -void set_callstack(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy); -void throw_impl(CELL quot, F_STACK_FRAME *rewind_to); - -/* Defined in cpu-x86.S and only called from Factor-compiled code. They all -use funny calling convention. */ -void undefined(CELL word); -void dosym(CELL word); -void docol_profiling(CELL word); -void docol(CELL word); +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); diff --git a/vm/os-macosx.m b/vm/os-macosx.m index e36d437cd6..07695b77fb 100644 --- a/vm/os-macosx.m +++ b/vm/os-macosx.m @@ -4,11 +4,11 @@ void c_to_factor_toplevel(CELL quot) { - /* for(;;) + for(;;) { -NS_DURING */ +NS_DURING c_to_factor(quot); - /* NS_VOIDRETURN; + NS_VOIDRETURN; NS_HANDLER dpush(allot_alien(F,(CELL)localException)); quot = userenv[COCOA_EXCEPTION_ENV]; @@ -16,11 +16,11 @@ NS_HANDLER { /* No Cocoa exception handler was registered, so extra/cocoa/ is not loaded. So we pass the exception - along. * + along. */ [localException raise]; } NS_ENDHANDLER - } */ + } } void early_init(void) diff --git a/vm/platform.h b/vm/platform.h index 602c7e6af5..e1da40a037 100644 --- a/vm/platform.h +++ b/vm/platform.h @@ -87,10 +87,12 @@ #if defined(FACTOR_X86) #include "cpu-x86.h" + #include "cpu-x86.32.h" +#elif defined(FACTOR_AMD64) + #include "cpu-x86.h" + #include "cpu-x86.64.h" #elif defined(FACTOR_PPC) #include "cpu-ppc.h" -#elif defined(FACTOR_AMD64) - #include "cpu-amd64.h" #elif defined(FACTOR_ARM) #include "cpu-arm.h" #else diff --git a/vm/run.h b/vm/run.h index 732880ce97..4d031350d3 100644 --- a/vm/run.h +++ b/vm/run.h @@ -196,7 +196,8 @@ void memory_protection_error(CELL addr, F_STACK_FRAME *native_stack); void signal_error(int signal, F_STACK_FRAME *native_stack); void type_error(CELL type, CELL tagged); void not_implemented_error(void); -void undefined_error(CELL word, F_STACK_FRAME *callstack_top); + +FASTCALL void undefined_error(CELL word, F_STACK_FRAME *callstack_top); DECLARE_PRIMITIVE(throw); diff --git a/vm/stack.h b/vm/stack.h index f07a1a76df..d2bec4fef1 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); -void save_callstack_bottom(F_STACK_FRAME *callstack_bottom); +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); From ae74818efa12a12483529d869838b27fc620dec8 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 21 Sep 2007 23:56:34 -0400 Subject: [PATCH 07/24] x86 fixes --- core/cpu/x86/bootstrap.factor | 2 +- vm/layouts.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/cpu/x86/bootstrap.factor b/core/cpu/x86/bootstrap.factor index 21bcaf3aa3..b234fe28b7 100644 --- a/core/cpu/x86/bootstrap.factor +++ b/core/cpu/x86/bootstrap.factor @@ -94,7 +94,7 @@ big-endian off ] { } make jit-dispatch set [ - stack-reg 7 cells ADD ! unwind stack frame + stack-reg 7 bootstrap-cells ADD ! unwind stack frame ] { } make jit-epilog set [ 0 RET ] { } make jit-return set diff --git a/vm/layouts.h b/vm/layouts.h index b924f61a81..e5419d1470 100644 --- a/vm/layouts.h +++ b/vm/layouts.h @@ -88,7 +88,7 @@ INLINE void *untag_object(CELL tagged) return (void *)UNTAG(tagged); } -typedef void (*XT)(CELL arg); +typedef void *XT; /* Assembly code makes assumptions about the layout of this struct */ typedef struct { From 7475278aeaf24f7436309c533ef4d3350d15cf55 Mon Sep 17 00:00:00 2001 From: Slava Date: Sat, 22 Sep 2007 00:41:17 -0400 Subject: [PATCH 08/24] Build system cleanup --- vm/Config.amd64 | 2 -- vm/{Config.freebsd.x86 => Config.freebsd.x86.32} | 0 vm/{Config.freebsd.amd64 => Config.freebsd.x86.64} | 0 vm/{Config.linux.x86 => Config.linux.x86.32} | 0 vm/{Config.linux.amd64 => Config.linux.x86.64} | 0 vm/{Config.macosx.x86 => Config.macosx.x86.32} | 0 vm/{Config.openbsd.x86 => Config.openbsd.x86.32} | 0 vm/{Config.openbsd.amd64 => Config.openbsd.x86.64} | 0 vm/{Config.solaris.x86 => Config.solaris.x86.32} | 0 vm/{Config.solaris.amd64 => Config.solaris.x86.64} | 0 vm/Config.windows.ce.x86 | 2 -- vm/{Config.windows.nt.x86 => Config.windows.nt.x86.32} | 0 vm/{Config.x86 => Config.x86.32} | 2 +- vm/Config.x86.64 | 2 ++ vm/{os-freebsd-x86.h => os-freebsd-x86.32.h} | 0 vm/{os-macosx-x86.h => os-macosx-x86.32.h} | 0 vm/{os-openbsd-x86.h => os-openbsd-x86.32.h} | 0 vm/{os-openbsd-amd64.h => os-openbsd-x86.64.h} | 0 18 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 vm/Config.amd64 rename vm/{Config.freebsd.x86 => Config.freebsd.x86.32} (100%) rename vm/{Config.freebsd.amd64 => Config.freebsd.x86.64} (100%) rename vm/{Config.linux.x86 => Config.linux.x86.32} (100%) rename vm/{Config.linux.amd64 => Config.linux.x86.64} (100%) rename vm/{Config.macosx.x86 => Config.macosx.x86.32} (100%) rename vm/{Config.openbsd.x86 => Config.openbsd.x86.32} (100%) rename vm/{Config.openbsd.amd64 => Config.openbsd.x86.64} (100%) rename vm/{Config.solaris.x86 => Config.solaris.x86.32} (100%) rename vm/{Config.solaris.amd64 => Config.solaris.x86.64} (100%) delete mode 100644 vm/Config.windows.ce.x86 rename vm/{Config.windows.nt.x86 => Config.windows.nt.x86.32} (100%) rename vm/{Config.x86 => Config.x86.32} (75%) create mode 100644 vm/Config.x86.64 rename vm/{os-freebsd-x86.h => os-freebsd-x86.32.h} (100%) rename vm/{os-macosx-x86.h => os-macosx-x86.32.h} (100%) rename vm/{os-openbsd-x86.h => os-openbsd-x86.32.h} (100%) rename vm/{os-openbsd-amd64.h => os-openbsd-x86.64.h} (100%) diff --git a/vm/Config.amd64 b/vm/Config.amd64 deleted file mode 100644 index d2c706cf14..0000000000 --- a/vm/Config.amd64 +++ /dev/null @@ -1,2 +0,0 @@ -BOOT_ARCH = amd64 -PLAF_DLL_OBJS += vm/cpu-amd64.o diff --git a/vm/Config.freebsd.x86 b/vm/Config.freebsd.x86.32 similarity index 100% rename from vm/Config.freebsd.x86 rename to vm/Config.freebsd.x86.32 diff --git a/vm/Config.freebsd.amd64 b/vm/Config.freebsd.x86.64 similarity index 100% rename from vm/Config.freebsd.amd64 rename to vm/Config.freebsd.x86.64 diff --git a/vm/Config.linux.x86 b/vm/Config.linux.x86.32 similarity index 100% rename from vm/Config.linux.x86 rename to vm/Config.linux.x86.32 diff --git a/vm/Config.linux.amd64 b/vm/Config.linux.x86.64 similarity index 100% rename from vm/Config.linux.amd64 rename to vm/Config.linux.x86.64 diff --git a/vm/Config.macosx.x86 b/vm/Config.macosx.x86.32 similarity index 100% rename from vm/Config.macosx.x86 rename to vm/Config.macosx.x86.32 diff --git a/vm/Config.openbsd.x86 b/vm/Config.openbsd.x86.32 similarity index 100% rename from vm/Config.openbsd.x86 rename to vm/Config.openbsd.x86.32 diff --git a/vm/Config.openbsd.amd64 b/vm/Config.openbsd.x86.64 similarity index 100% rename from vm/Config.openbsd.amd64 rename to vm/Config.openbsd.x86.64 diff --git a/vm/Config.solaris.x86 b/vm/Config.solaris.x86.32 similarity index 100% rename from vm/Config.solaris.x86 rename to vm/Config.solaris.x86.32 diff --git a/vm/Config.solaris.amd64 b/vm/Config.solaris.x86.64 similarity index 100% rename from vm/Config.solaris.amd64 rename to vm/Config.solaris.x86.64 diff --git a/vm/Config.windows.ce.x86 b/vm/Config.windows.ce.x86 deleted file mode 100644 index 0d1f776169..0000000000 --- a/vm/Config.windows.ce.x86 +++ /dev/null @@ -1,2 +0,0 @@ -#CC = x86-wince-mingw32ce-gcc -include vm/Config.windows.ce vm/Config.x86 diff --git a/vm/Config.windows.nt.x86 b/vm/Config.windows.nt.x86.32 similarity index 100% rename from vm/Config.windows.nt.x86 rename to vm/Config.windows.nt.x86.32 diff --git a/vm/Config.x86 b/vm/Config.x86.32 similarity index 75% rename from vm/Config.x86 rename to vm/Config.x86.32 index bd739d3a85..bbd26e8e11 100644 --- a/vm/Config.x86 +++ b/vm/Config.x86.32 @@ -1,5 +1,5 @@ BOOT_ARCH = x86 -PLAF_DLL_OBJS += vm/cpu-x86.o +PLAF_DLL_OBJS += vm/cpu-x86.32.o # gcc bug workaround CFLAGS += -fno-builtin-strlen -fno-builtin-strcat -mtune=pentium4 diff --git a/vm/Config.x86.64 b/vm/Config.x86.64 new file mode 100644 index 0000000000..9630e4a3ff --- /dev/null +++ b/vm/Config.x86.64 @@ -0,0 +1,2 @@ +BOOT_ARCH = amd64 +PLAF_DLL_OBJS += vm/cpu-x86.64.o diff --git a/vm/os-freebsd-x86.h b/vm/os-freebsd-x86.32.h similarity index 100% rename from vm/os-freebsd-x86.h rename to vm/os-freebsd-x86.32.h diff --git a/vm/os-macosx-x86.h b/vm/os-macosx-x86.32.h similarity index 100% rename from vm/os-macosx-x86.h rename to vm/os-macosx-x86.32.h diff --git a/vm/os-openbsd-x86.h b/vm/os-openbsd-x86.32.h similarity index 100% rename from vm/os-openbsd-x86.h rename to vm/os-openbsd-x86.32.h diff --git a/vm/os-openbsd-amd64.h b/vm/os-openbsd-x86.64.h similarity index 100% rename from vm/os-openbsd-amd64.h rename to vm/os-openbsd-x86.64.h From 6dc28869ce15cf6b3c7f9ffd1540044aa5e28294 Mon Sep 17 00:00:00 2001 From: Slava Date: Sat, 22 Sep 2007 00:44:27 -0400 Subject: [PATCH 09/24] More build system work --- Makefile | 64 +++++++++++++++++++++++------------------------- vm/Config.arm | 1 - vm/Config.ppc | 1 - vm/Config.x86.64 | 1 - vm/cpu-amd64.S | 8 ------ vm/cpu-amd64.h | 20 --------------- vm/cpu-x86.32.S | 6 ++--- vm/cpu-x86.32.h | 2 -- vm/cpu-x86.64.S | 20 +++++++-------- vm/cpu-x86.S | 6 ++--- vm/cpu-x86.h | 2 ++ vm/platform.h | 14 +++++------ vm/run.c | 2 +- vm/stack.c | 2 +- 14 files changed, 56 insertions(+), 93 deletions(-) delete mode 100644 vm/cpu-amd64.S delete mode 100644 vm/cpu-amd64.h diff --git a/Makefile b/Makefile index 73c7b2eb5e..c5db03896e 100644 --- a/Makefile +++ b/Makefile @@ -44,21 +44,20 @@ EXE_OBJS = $(PLAF_EXE_OBJS) default: @echo "Run 'make' with one of the following parameters:" @echo "" - @echo "freebsd-x86" - @echo "freebsd-amd64" - @echo "linux-x86" - @echo "linux-amd64" + @echo "freebsd-x86-32" + @echo "freebsd-x86-64" + @echo "linux-x86-32" + @echo "linux-x86-64" @echo "linux-ppc" @echo "linux-arm" - @echo "openbsd-x86" - @echo "openbsd-amd64" - @echo "macosx-x86" + @echo "openbsd-x86-32" + @echo "openbsd-x86-64" + @echo "macosx-x86-32" @echo "macosx-ppc" - @echo "solaris-x86" - @echo "solaris-amd64" + @echo "solaris-x86-32" + @echo "solaris-x86-64" @echo "windows-ce-arm" - @echo "windows-ce-x86" - @echo "windows-nt-x86" + @echo "windows-nt-x86-32" @echo "" @echo "Additional modifiers:" @echo "" @@ -67,17 +66,17 @@ default: @echo "NO_UI=1 don't link with X11 libraries (ignored on Mac OS X)" @echo "X11=1 force link with X11 libraries instead of Cocoa (only on Mac OS X)" -openbsd-x86: - $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.openbsd.x86 +openbsd-x86-32: + $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.openbsd.x86.32 -openbsd-amd64: - $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.openbsd.amd64 +openbsd-x86-64: + $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.openbsd.x86.64 -freebsd-x86: - $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.freebsd.x86 +freebsd-x86-32: + $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.freebsd.x86.32 -freebsd-amd64: - $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.freebsd.amd64 +freebsd-x86-64: + $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.freebsd.x86.64 macosx-freetype: ln -sf libfreetype.6.dylib \ @@ -86,14 +85,14 @@ macosx-freetype: macosx-ppc: macosx-freetype $(MAKE) $(EXECUTABLE) macosx.app CONFIG=vm/Config.macosx.ppc -macosx-x86: macosx-freetype - $(MAKE) $(EXECUTABLE) macosx.app CONFIG=vm/Config.macosx.x86 +macosx-x86-32: macosx-freetype + $(MAKE) $(EXECUTABLE) macosx.app CONFIG=vm/Config.macosx.x86.32 -linux-x86: - $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.linux.x86 +linux-x86-32: + $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.linux.x86.32 -linux-amd64: - $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.linux.amd64 +linux-x86-64: + $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.linux.x86.64 linux-ppc: $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.linux.ppc @@ -101,21 +100,18 @@ linux-ppc: linux-arm: $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.linux.arm -solaris-x86: - $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.solaris.x86 +solaris-x86-32: + $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.solaris.x86.32 -solaris-amd64: - $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.solaris.amd64 +solaris-x86-64: + $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.solaris.x86.64 -windows-nt-x86: - $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.nt.x86 +windows-nt-x86-32: + $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.nt.x86.32 windows-ce-arm: $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.ce.arm -windows-ce-x86: - $(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.ce.x86 - macosx.app: factor mkdir -p $(BUNDLE)/Contents/MacOS cp $(EXECUTABLE) $(BUNDLE)/Contents/MacOS/factor diff --git a/vm/Config.arm b/vm/Config.arm index fc41bb9c37..2273d61caf 100644 --- a/vm/Config.arm +++ b/vm/Config.arm @@ -1,2 +1 @@ -BOOT_ARCH = arm PLAF_DLL_OBJS += vm/cpu-arm.o diff --git a/vm/Config.ppc b/vm/Config.ppc index 3fa5fd8df1..1ded04dda1 100644 --- a/vm/Config.ppc +++ b/vm/Config.ppc @@ -1,2 +1 @@ -BOOT_ARCH = ppc PLAF_DLL_OBJS += vm/cpu-ppc.o diff --git a/vm/Config.x86.64 b/vm/Config.x86.64 index 9630e4a3ff..53a4d3c5e1 100644 --- a/vm/Config.x86.64 +++ b/vm/Config.x86.64 @@ -1,2 +1 @@ -BOOT_ARCH = amd64 PLAF_DLL_OBJS += vm/cpu-x86.64.o diff --git a/vm/cpu-amd64.S b/vm/cpu-amd64.S deleted file mode 100644 index 5df8bd0bf4..0000000000 --- a/vm/cpu-amd64.S +++ /dev/null @@ -1,8 +0,0 @@ -#include "asm.h" - -/* Callable from C as -void *native_stack_pointer(void) */ - .globl MANGLE(native_stack_pointer) -MANGLE(native_stack_pointer): - mov %rsp,%rax - ret diff --git a/vm/cpu-amd64.h b/vm/cpu-amd64.h deleted file mode 100644 index 64d2c3a14a..0000000000 --- a/vm/cpu-amd64.h +++ /dev/null @@ -1,20 +0,0 @@ -#define FACTOR_CPU_STRING "x86.64" - -register CELL ds asm("r14"); -register CELL rs asm("r15"); -void **primitives; - -INLINE void flush_icache(CELL start, CELL len) {} - -void *native_stack_pointer(void); - -typedef CELL F_COMPILED_FRAME; - -#define PREVIOUS_FRAME(frame) (frame + 1) -#define RETURN_ADDRESS(frame) (*(frame)) - -INLINE void execute(CELL word) -{ - F_WORD *untagged = untag_object(word); - untagged->xt(word); -} diff --git a/vm/cpu-x86.32.S b/vm/cpu-x86.32.S index 57f8656a75..93af51c968 100644 --- a/vm/cpu-x86.32.S +++ b/vm/cpu-x86.32.S @@ -8,16 +8,16 @@ and the callstack top is passed in EDX */ #define ARG1 %edx #define XT_REG %ecx #define STACK_REG %esp -#define DS_REG %edi +#define DS_REG %esi #define CELL_SIZE 4 #define PUSH_NONVOLATILE \ - push %ebx \ + push %ebx ; \ push %ebp #define POP_NONVOLATILE \ - pop %ebp \ + pop %ebp ; \ pop %ebx #define QUOT_XT_OFFSET 5 diff --git a/vm/cpu-x86.32.h b/vm/cpu-x86.32.h index 0129737685..4c4acb0ad3 100644 --- a/vm/cpu-x86.32.h +++ b/vm/cpu-x86.32.h @@ -4,5 +4,3 @@ register CELL ds asm("esi"); register CELL rs asm("edi"); #define FASTCALL __attribute__ ((regparm (2))) - -void set_callstack(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy); diff --git a/vm/cpu-x86.64.S b/vm/cpu-x86.64.S index 12af25eec5..ed502af89b 100644 --- a/vm/cpu-x86.64.S +++ b/vm/cpu-x86.64.S @@ -9,19 +9,19 @@ #define CELL_SIZE 8 #define PUSH_NONVOLATILE \ - push %rbx \ - push %rbp \ - push %r12 \ - push %r13 \ - push %r16 \ + push %rbx ; \ + push %rbp ; \ + push %r12 ; \ + push %r13 ; \ + push %r16 ; \ push %rax /* Alignment */ #define POP_NONVOLATILE \ - pop %rax /* Alignment */ \ - pop %r16 \ - pop %r13 \ - pop %r12 \ - pop %rbp \ + pop %rax ; /* Alignment */ \ + pop %r16 ; \ + pop %r13 ; \ + pop %r12 ; \ + pop %rbp ; \ pop %rbx #define QUOT_XT_OFFSET 13 diff --git a/vm/cpu-x86.S b/vm/cpu-x86.S index e8eeb403b7..a84ae6c480 100644 --- a/vm/cpu-x86.S +++ b/vm/cpu-x86.S @@ -10,7 +10,7 @@ DEF(FASTCALL void,c_to_factor,(CELL quot)): call MANGLE(save_callstack_bottom) mov (STACK_REG),ARG0 /* Pass quot as arg 1 */ - mov QUOT_XT_OFFSET(STACK_REG),XT_REG + mov QUOT_XT_OFFSET(ARG0),XT_REG call *XT_REG /* Call quot-xt */ POP ARG0 @@ -18,7 +18,7 @@ DEF(FASTCALL void,c_to_factor,(CELL quot)): ret DEF(FASTCALL void,undefined,(CELL word)): - mov STACK_REG,ARG1 /* Pass callstack pointer as arg 2 (not fastcall) */ + mov STACK_REG,ARG1 /* Pass callstack pointer */ jmp MANGLE(undefined_error) /* This throws an error */ DEF(FASTCALL void,dosym,(CELL word)): @@ -31,7 +31,7 @@ enabled */ DEF(FASTCALL void,docol_profiling,(CELL word)): add $CELL_SIZE,PROFILING_OFFSET(%eax) /* Increment profile-count slot */ DEF(FASTCALL void,docol,(CELL word)): - mov WORD_XT_OFFSET(ARG0),ARG0 /* Load word-def slot */ + mov WORD_DEF_OFFSET(ARG0),ARG0 /* Load word-def slot */ JUMP_QUOT /* We must pass the XT to the quotation in ECX. */ diff --git a/vm/cpu-x86.h b/vm/cpu-x86.h index e705432e70..a535038eef 100644 --- a/vm/cpu-x86.h +++ b/vm/cpu-x86.h @@ -28,3 +28,5 @@ FASTCALL void undefined(CELL word); FASTCALL void dosym(CELL word); FASTCALL void docol_profiling(CELL word); FASTCALL void docol(CELL word); + +void set_callstack(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy); diff --git a/vm/platform.h b/vm/platform.h index e1da40a037..d5e5d6902a 100644 --- a/vm/platform.h +++ b/vm/platform.h @@ -13,10 +13,8 @@ #if defined(WINDOWS) #if defined(WINCE) #include "os-windows-ce.h" - #elif defined (__i386) - #include "os-windows-nt.h" #else - #error "Unsupported Windows flavor" + #include "os-windows-nt.h" #endif #include "os-windows.h" @@ -44,7 +42,7 @@ #include "os-unix-ucontext.h" #if defined(FACTOR_X86) - #include "os-freebsd-x86.h" + #include "os-freebsd-x86.32.h" #else #error "Unsupported FreeBSD flavor" #endif @@ -53,9 +51,9 @@ #include "os-openbsd.h" #if defined(FACTOR_X86) - #include "os-openbsd-x86.h" + #include "os-openbsd-x86.32.h" #elif defined(FACTOR_AMD64) - #include "os-openbsd-amd64.h" + #include "os-openbsd-x86.64.h" #else #error "Unsupported OpenBSD flavor" #endif @@ -86,11 +84,11 @@ #endif #if defined(FACTOR_X86) - #include "cpu-x86.h" #include "cpu-x86.32.h" -#elif defined(FACTOR_AMD64) #include "cpu-x86.h" +#elif defined(FACTOR_AMD64) #include "cpu-x86.64.h" + #include "cpu-x86.h" #elif defined(FACTOR_PPC) #include "cpu-ppc.h" #elif defined(FACTOR_ARM) diff --git a/vm/run.c b/vm/run.c index 2ed7bae7f4..2b946b0722 100644 --- a/vm/run.c +++ b/vm/run.c @@ -199,7 +199,7 @@ void not_implemented_error(void) } /* This function is called from the undefined function in cpu_*.S */ -void undefined_error(CELL word, F_STACK_FRAME *callstack_top) +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); diff --git a/vm/stack.c b/vm/stack.c index 9c36389b40..e50575219c 100644 --- a/vm/stack.c +++ b/vm/stack.c @@ -19,7 +19,7 @@ void fix_stacks(void) } /* called before entry into Factor code. */ -void save_callstack_bottom(F_STACK_FRAME *callstack_bottom) +FASTCALL void save_callstack_bottom(F_STACK_FRAME *callstack_bottom) { stack_chain->callstack_bottom = callstack_bottom; } From 5d01a369e44055b22b99983c73817b0b268d8056 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 22 Sep 2007 00:03:47 -0400 Subject: [PATCH 10/24] Update Config.* fixes (???) --- vm/Config.freebsd.x86.32 | 2 +- vm/Config.freebsd.x86.64 | 2 +- vm/Config.linux.x86.32 | 2 +- vm/Config.linux.x86.64 | 2 +- vm/Config.macosx.x86.32 | 2 +- vm/Config.openbsd.x86.32 | 2 +- vm/Config.openbsd.x86.64 | 2 +- vm/Config.solaris.x86.32 | 2 +- vm/Config.solaris.x86.64 | 2 +- vm/Config.windows.nt.x86.32 | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/vm/Config.freebsd.x86.32 b/vm/Config.freebsd.x86.32 index 1273130dc7..969ba1cea6 100644 --- a/vm/Config.freebsd.x86.32 +++ b/vm/Config.freebsd.x86.32 @@ -1,2 +1,2 @@ include vm/Config.freebsd -include vm/Config.x86 +include vm/Config.x86.32 diff --git a/vm/Config.freebsd.x86.64 b/vm/Config.freebsd.x86.64 index db6f9f3c1e..0f9667e48d 100644 --- a/vm/Config.freebsd.x86.64 +++ b/vm/Config.freebsd.x86.64 @@ -1,2 +1,2 @@ include vm/Config.freebsd -include vm/Config.amd64 +include vm/Config.x86.64 diff --git a/vm/Config.linux.x86.32 b/vm/Config.linux.x86.32 index 313b999133..7f4f3b4bfe 100644 --- a/vm/Config.linux.x86.32 +++ b/vm/Config.linux.x86.32 @@ -1,2 +1,2 @@ include vm/Config.linux -include vm/Config.x86 +include vm/Config.x86.32 diff --git a/vm/Config.linux.x86.64 b/vm/Config.linux.x86.64 index d7ae032e6a..bfd1222496 100644 --- a/vm/Config.linux.x86.64 +++ b/vm/Config.linux.x86.64 @@ -1,3 +1,3 @@ include vm/Config.linux -include vm/Config.amd64 +include vm/Config.x86.64 LIBPATH = -L/usr/X11R6/lib64 -L/usr/X11R6/lib diff --git a/vm/Config.macosx.x86.32 b/vm/Config.macosx.x86.32 index 27c47fcb63..5c0d4e0ede 100644 --- a/vm/Config.macosx.x86.32 +++ b/vm/Config.macosx.x86.32 @@ -1,2 +1,2 @@ include vm/Config.macosx -include vm/Config.x86 +include vm/Config.x86.32 diff --git a/vm/Config.openbsd.x86.32 b/vm/Config.openbsd.x86.32 index 99cf991032..407083d38e 100644 --- a/vm/Config.openbsd.x86.32 +++ b/vm/Config.openbsd.x86.32 @@ -1,2 +1,2 @@ include vm/Config.openbsd -include vm/Config.x86 +include vm/Config.x86.32 diff --git a/vm/Config.openbsd.x86.64 b/vm/Config.openbsd.x86.64 index e895d34307..d254e61bf8 100644 --- a/vm/Config.openbsd.x86.64 +++ b/vm/Config.openbsd.x86.64 @@ -1,2 +1,2 @@ include vm/Config.openbsd -include vm/Config.amd64 +include vm/Config.x86.64 diff --git a/vm/Config.solaris.x86.32 b/vm/Config.solaris.x86.32 index d839047c77..ffe59be468 100644 --- a/vm/Config.solaris.x86.32 +++ b/vm/Config.solaris.x86.32 @@ -1,2 +1,2 @@ include vm/Config.solaris -include vm/Config.x86 +include vm/Config.x86.32 diff --git a/vm/Config.solaris.x86.64 b/vm/Config.solaris.x86.64 index 58bd2b2f4d..116725daed 100644 --- a/vm/Config.solaris.x86.64 +++ b/vm/Config.solaris.x86.64 @@ -1,2 +1,2 @@ include vm/Config.solaris -include vm/Config.amd64 +include vm/Config.x86.64 diff --git a/vm/Config.windows.nt.x86.32 b/vm/Config.windows.nt.x86.32 index 8834332442..adc69b1e27 100644 --- a/vm/Config.windows.nt.x86.32 +++ b/vm/Config.windows.nt.x86.32 @@ -4,4 +4,4 @@ DLL_SUFFIX=-nt PLAF_DLL_OBJS += vm/os-windows-nt.o PLAF_EXE_OBJS += vm/resources.o PLAF_EXE_OBJS += vm/main-windows-nt.o -include vm/Config.x86 vm/Config.windows +include vm/Config.x86.32 vm/Config.windows From 51c5f0b267903ce4a5fc8c290147bfae7fb4f49e Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 22 Sep 2007 00:10:57 -0400 Subject: [PATCH 11/24] x86 bootstrap typo --- core/cpu/x86/bootstrap.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/cpu/x86/bootstrap.factor b/core/cpu/x86/bootstrap.factor index b234fe28b7..84d0b152b8 100644 --- a/core/cpu/x86/bootstrap.factor +++ b/core/cpu/x86/bootstrap.factor @@ -20,7 +20,7 @@ big-endian off xt-reg stack-reg -44 [+] LEA ! compute forward chain pointer xt-reg PUSH ! save forward chain pointer arg0 PUSH ! save array - stack-reg 2 bootstrap-cells SUB ! reserve space for scan-save + stack-reg 4 bootstrap-cells SUB ! reserve space for scan-save ] { } make jit-prolog set : advance-scan scan-reg bootstrap-cell ADD ; From 88cdd6ca9c3d7dff5d94667fcc2d19f15ce93adc Mon Sep 17 00:00:00 2001 From: Slava Date: Sat, 22 Sep 2007 00:13:01 -0400 Subject: [PATCH 12/24] Mac Intel compile fix --- vm/platform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/platform.h b/vm/platform.h index d5e5d6902a..23c241336b 100644 --- a/vm/platform.h +++ b/vm/platform.h @@ -27,7 +27,7 @@ #include "mach_signal.h" #ifdef FACTOR_X86 - #include "os-macosx-x86.h" + #include "os-macosx-x86.32.h" #elif defined(FACTOR_PPC) #include "os-macosx-ppc.h" #else From 7b45efc69d6944f7970697e3b721fa793da8e715 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 22 Sep 2007 00:28:55 -0400 Subject: [PATCH 13/24] VM fixes for Linux/x86-64 --- core/cpu/x86/64/64.factor | 4 ++-- vm/cpu-x86.64.S | 6 +----- vm/platform.h | 2 ++ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/core/cpu/x86/64/64.factor b/core/cpu/x86/64/64.factor index 67c07608ab..b91ab169de 100644 --- a/core/cpu/x86/64/64.factor +++ b/core/cpu/x86/64/64.factor @@ -14,10 +14,10 @@ M: amd64-backend ds-reg R14 ; M: amd64-backend rs-reg R15 ; M: amd64-backend stack-reg RSP ; -M: temp-reg v>operand drop R16 ; +M: temp-reg v>operand drop R13 ; M: int-regs return-reg drop RAX ; -M: int-regs vregs drop { RAX RBX RCX RDX RBP RSI RDI R8 R9 R10 R11 R12 R13 } ; +M: int-regs vregs drop { RAX RBX RCX RDX RBP RSI RDI R8 R9 R10 R11 R12 } ; M: int-regs param-regs drop { RDI RSI RDX RCX R8 R9 } ; M: float-regs return-reg drop XMM0 ; diff --git a/vm/cpu-x86.64.S b/vm/cpu-x86.64.S index ed502af89b..8aef5f9d61 100644 --- a/vm/cpu-x86.64.S +++ b/vm/cpu-x86.64.S @@ -12,13 +12,9 @@ push %rbx ; \ push %rbp ; \ push %r12 ; \ - push %r13 ; \ - push %r16 ; \ - push %rax /* Alignment */ + push %r13 ; #define POP_NONVOLATILE \ - pop %rax ; /* Alignment */ \ - pop %r16 ; \ pop %r13 ; \ pop %r12 ; \ pop %rbp ; \ diff --git a/vm/platform.h b/vm/platform.h index 23c241336b..f181c93e2c 100644 --- a/vm/platform.h +++ b/vm/platform.h @@ -63,6 +63,7 @@ #if defined(FACTOR_X86) #include "os-unix-ucontext.h" + #include "os-linux-x86-32.h" #elif defined(FACTOR_PPC) #include "os-unix-ucontext.h" #include "os-linux-ppc.h" @@ -70,6 +71,7 @@ #include "os-linux-arm.h" #elif defined(FACTOR_AMD64) #include "os-unix-ucontext.h" + #include "os-linux-x86-64.h" #else #error "Unsupported Linux flavor" #endif From 931b5322fc2b95c6e646aa0fd4a9e32e8d5b9504 Mon Sep 17 00:00:00 2001 From: slava Date: Sat, 22 Sep 2007 02:22:38 -0400 Subject: [PATCH 14/24] Factory load fixes --- extra/factory/.factory-menus.swp | Bin 0 -> 20480 bytes extra/factory/factory-menus | 3 ++- extra/factory/factory-rc | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 extra/factory/.factory-menus.swp diff --git a/extra/factory/.factory-menus.swp b/extra/factory/.factory-menus.swp new file mode 100644 index 0000000000000000000000000000000000000000..241afbf9d743d8df82d29f4298157ebb10de6d4e GIT binary patch literal 20480 zcmeI4YiJ!=9l(!Co8&f4u55L6h1HY0VAJX(?N;rYZ9^m5m)%xqwxJMKoy?uwJKlL* zXXfT6?Y4dp5yS_ILYGxPi4RbGASfuV_(4CYsH}*(=qFJT1y{uf3i>-|=04KQP17YG zRL+H8Zsxqt|2*dW|L32q99cSlQ68T;BKW*eh~}67a;EaGN5s_qLL|PuW~=Z!e5&q> zXNPx4MD$Hv;OwgHq)|NUuBWk`KWucqt-uXi$(@TbDU1Y+1nx!xt#s9TXhIx0`rt7+ zRe9i^16S@Qw@GUxU?gB9U?gB9U?gB9U?gB9U?lK=Ac1BohQ+^iM~3*h7haIFhi?}~ z^5ehkmR zr{FqV04c=&e*tm(Z-E032r>R^Al-NbuY;GteM0Q}A^ZTIhHt?8;JrYd`^rL;z74dq zbX173U%_{Pu(2EP1O(v2NjL%b2r>E#_&Ct!QR*1^DSREi1~I%H=>N!D;MMRd%p{b( z_eVh8d)MG9+z(?y>_KLGJ_}F5Yk>X?e-1tX?}yXy2s{Y1bBO*A{S%PE&?n#~EW>el zEl|eLOWjeR8lU> zI1B8hx@fOw`Ig)`^&H!;kSfRnt+hN*r@yWm*Gb>2yf3{@c3UUIC?!Scwyk!c`z`1D zr9hT;-NnmA3%x&PH|2gqW+fL3UWsv8R-CGwO`OQO6kXPhXQt45BcW>8kpLHWvxOg0$NKvv_Z z*%N=SxQci_&G3C$Pt)eyZ0_mfL{)btifcQq*Y~q}WkK`qRw(VdohA&ld_wwelBiD8 zC+1An$xignJ32^ck1-ftX#0{?+BZ(S(36>5jM9o*;Yr_P#6majb|jw<(`mYKs3P=w z$b!_O*>3)H%Pr_qzFzXFIdHjTYo}nf=!o52EP?I$gO&>8xzTDhJhcJP>4r+nhLNUq zw>{JLe1vu?upPAu2G9Dawc@*umReSTQ;)r5rmDkFWnYvq6J8rwh8x$iJ*e9Vven4s zyMY~^s;PEu+X(G7x2YF8+A;a?o>dSPO{Bh=$rpKspETYnCh)^nl)r)(zGI`M{KRecHkZwyc?dy zNimnsmcnYp?XZ|LEw;66dTuEuup6$mN`kC0YRH%_)omK}s2$hTTam1rw?ly?I9U!gqH{+0Ev5GiovA z1$oAc-PLG4AH`;aeMPQjVMSfkuNj^3s@tq@#44W}uqcFvMXI*j`uD*}8?jrnInU~;Zg-vrroV78-)Q?@QUzVo z3+Z&Wg!0kXv%aWY(Kl}kR#7*0^CId7@8%ksyG?bF(^9JtQn`6Ej`EO9+ICaU&u762 zZ`ZJ4wPV5_7J}@30n>fCs;#CxVM){g$4Znoae~6o8Pu=(;Hq=?ALgf3b-LO^@ox4mjwR}Gkw=Ul(Z!KzIJiqF(tD_DA^$^2Bmq2BXq7f-qY zeq>jvDNnY}!K7Mq(`2R{%;?5$3TcG_!{k=8tvB17#FfSKm(I?~h8u^jFI%CvF4ych zkwFx*@yf(UJ+vK%gKiY-E?9>&sHxa}$+w84Y=>5?z!z8vvE3`{|5BZlc`Uzy&OZ zx_$JdYfvdFeBJRQM_H6eSjirWOgY(1$W4qo?KZYWZ6nebfPGD-?WzVnG6i;}T>lr` zOAn#XYyBUef35$c*O&hUp8<6K@{@22mViGVF25AGm!A9?D7ygn+mnNzc z;P>z>;L|XI55mYNLEZg73e>&#Id}$c!8_q39E5wh>;F8^pFPvC4@%tee-oYty@CBfZp%1|a;T)U=+V Date: Sat, 22 Sep 2007 02:27:28 -0400 Subject: [PATCH 15/24] JSON writer fix --- extra/json/writer/writer.factor | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extra/json/writer/writer.factor b/extra/json/writer/writer.factor index fc11904890..4370a38411 100644 --- a/extra/json/writer/writer.factor +++ b/extra/json/writer/writer.factor @@ -21,6 +21,11 @@ M: string json-print ( obj -- ) M: number json-print ( num -- ) number>string write ; +! sequence and number overlap, we provide an explicit +! disambiguation method +M: integer json-print ( num -- ) + number>string write ; + M: sequence json-print ( array -- string ) CHAR: [ write1 [ >json ] map "," join write CHAR: ] write1 ; From 2589c69c04d02063bc44036163eae5bae04d95ff Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 22 Sep 2007 02:27:53 -0400 Subject: [PATCH 16/24] Unix launcher: use execvp instead of execve --- extra/io/unix/launcher/launcher.factor | 7 +++---- extra/unix/unix.factor | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extra/io/unix/launcher/launcher.factor b/extra/io/unix/launcher/launcher.factor index c3fe6d0a05..7b286feae1 100644 --- a/extra/io/unix/launcher/launcher.factor +++ b/extra/io/unix/launcher/launcher.factor @@ -9,16 +9,15 @@ USE: unix : with-fork ( quot -- pid ) fork [ zero? -rot if ] keep ; inline -: prepare-execve ( args -- cmd args envp ) +: prepare-execvp ( args -- cmd args ) #! Doesn't free any memory, so we only call this word #! after forking. [ malloc-char-string ] map [ first ] keep - f add >c-void*-array - f ; + f add >c-void*-array ; : (spawn-process) ( args -- ) - [ prepare-execve execve ] catch 1 exit ; + [ prepare-execvp execvp ] catch 1 exit ; : spawn-process ( args -- pid ) [ (spawn-process) ] [ drop ] with-fork ; diff --git a/extra/unix/unix.factor b/extra/unix/unix.factor index 8eb940352f..ca4b569587 100644 --- a/extra/unix/unix.factor +++ b/extra/unix/unix.factor @@ -107,6 +107,7 @@ FUNCTION: void close ( int fd ) ; FUNCTION: int connect ( int s, void* name, socklen_t namelen ) ; FUNCTION: int dup2 ( int oldd, int newd ) ; ! FUNCTION: int dup ( int oldd ) ; +FUNCTION: int execvp ( char* path, char** argv ) ; FUNCTION: int execve ( char* path, char** argv, char** envp ) ; FUNCTION: int fchdir ( int fd ) ; FUNCTION: int fchmod ( int fd, mode_t mode ) ; From 136e249f6d018707701a8b7152f940f863529ceb Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 22 Sep 2007 02:28:49 -0400 Subject: [PATCH 17/24] x86-64 fixes --- core/bootstrap/image/image.factor | 2 +- core/cpu/x86/32/bootstrap.factor | 1 + core/cpu/x86/64/64.factor | 2 ++ core/cpu/x86/64/bootstrap.factor | 1 + core/cpu/x86/bootstrap.factor | 2 +- vm/cpu-x86.32.S | 2 +- vm/cpu-x86.64.S | 2 +- 7 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/bootstrap/image/image.factor b/core/bootstrap/image/image.factor index 36d2f7f1de..0f61eb4c83 100644 --- a/core/bootstrap/image/image.factor +++ b/core/bootstrap/image/image.factor @@ -32,7 +32,7 @@ IN: bootstrap.image : -1-offset 9 ; inline : array-start 2 bootstrap-cells object tag-number - ; -: scan@ array-start 4 - ; +: scan@ array-start bootstrap-cell - ; : wrapper@ bootstrap-cell object tag-number - ; : word-xt@ 8 bootstrap-cells object tag-number - ; : quot-array@ bootstrap-cell object tag-number - ; diff --git a/core/cpu/x86/32/bootstrap.factor b/core/cpu/x86/32/bootstrap.factor index 32d07797e7..289ae0c213 100644 --- a/core/cpu/x86/32/bootstrap.factor +++ b/core/cpu/x86/32/bootstrap.factor @@ -13,5 +13,6 @@ IN: bootstrap.x86 : scan-reg EBX ; : xt-reg ECX ; : fixnum>slot@ arg0 1 SAR ; +: next-frame@ -44 ; "resource:core/cpu/x86/bootstrap.factor" run-file diff --git a/core/cpu/x86/64/64.factor b/core/cpu/x86/64/64.factor index b91ab169de..94da29eb6d 100644 --- a/core/cpu/x86/64/64.factor +++ b/core/cpu/x86/64/64.factor @@ -13,6 +13,8 @@ PREDICATE: x86-backend amd64-backend M: amd64-backend ds-reg R14 ; M: amd64-backend rs-reg R15 ; M: amd64-backend stack-reg RSP ; +M: x86-backend xt-reg RCX ; +M: x86-backend stack-save-reg RSI ; M: temp-reg v>operand drop R13 ; diff --git a/core/cpu/x86/64/bootstrap.factor b/core/cpu/x86/64/bootstrap.factor index 9d3fa8849f..00db1ac119 100644 --- a/core/cpu/x86/64/bootstrap.factor +++ b/core/cpu/x86/64/bootstrap.factor @@ -13,5 +13,6 @@ IN: bootstrap.x86 : scan-reg RBX ; : xt-reg RCX ; : fixnum>slot@ ; +: next-frame@ -88 ; "resource:core/cpu/x86/bootstrap.factor" run-file diff --git a/core/cpu/x86/bootstrap.factor b/core/cpu/x86/bootstrap.factor index 84d0b152b8..67156d8300 100644 --- a/core/cpu/x86/bootstrap.factor +++ b/core/cpu/x86/bootstrap.factor @@ -17,7 +17,7 @@ big-endian off [ xt-reg PUSH ! save XT - xt-reg stack-reg -44 [+] LEA ! compute forward chain pointer + xt-reg stack-reg next-frame@ [+] LEA ! compute forward chain pointer xt-reg PUSH ! save forward chain pointer arg0 PUSH ! save array stack-reg 4 bootstrap-cells SUB ! reserve space for scan-save diff --git a/vm/cpu-x86.32.S b/vm/cpu-x86.32.S index 93af51c968..19a735ec88 100644 --- a/vm/cpu-x86.32.S +++ b/vm/cpu-x86.32.S @@ -25,7 +25,7 @@ and the callstack top is passed in EDX */ #define WORD_DEF_OFFSET 13 #define WORD_XT_OFFSET 29 -/* We pass a function pointer to memcpy in 16(%esp) to work around a Mac OS X +/* We pass a function pointer to memcpy to work around a Mac OS X ABI limitation which would otherwise require us to do a bizzaro PC-relative trampoline to retrieve the function address */ DEF(void,set_callstack,(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy)): diff --git a/vm/cpu-x86.64.S b/vm/cpu-x86.64.S index 8aef5f9d61..1725c0cbd5 100644 --- a/vm/cpu-x86.64.S +++ b/vm/cpu-x86.64.S @@ -25,7 +25,7 @@ #define WORD_DEF_OFFSET 29 #define WORD_XT_OFFSET 61 -/* We pass a function pointer to memcpy in 16(%esp) to work around a Mac OS X +/* We pass a function pointer to memcpy to work around a Mac OS X ABI limitation which would otherwise require us to do a bizzaro PC-relative trampoline to retrieve the function address */ DEF(void,set_callstack,(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy)): From dacab19574f7d5126b474e1074773bc010fa3cd3 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 22 Sep 2007 03:09:18 -0400 Subject: [PATCH 18/24] AMD64 fixes --- core/cpu/x86/32/32.factor | 4 ++-- core/cpu/x86/64/64.factor | 10 +++++----- core/cpu/x86/architecture/architecture.factor | 2 +- vm/cpu-x86.S | 2 +- vm/factor.c | 1 + vm/os-linux-x86-64.h | 2 ++ 6 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 vm/os-linux-x86-64.h diff --git a/core/cpu/x86/32/32.factor b/core/cpu/x86/32/32.factor index 998e87c7a0..4ef7777dd4 100644 --- a/core/cpu/x86/32/32.factor +++ b/core/cpu/x86/32/32.factor @@ -206,10 +206,10 @@ M: x86-backend %box-small-struct ( size -- ) M: x86-backend %prepare-alien-indirect ( -- ) "unbox_alien" f %alien-invoke - ESP cell temp@ [+] EAX MOV ; + cell temp@ EAX MOV ; M: x86-backend %alien-indirect ( -- ) - ESP cell temp@ [+] CALL ; + cell temp@ CALL ; M: x86-backend %alien-callback ( quot -- ) 4 [ diff --git a/core/cpu/x86/64/64.factor b/core/cpu/x86/64/64.factor index 94da29eb6d..708c75e0bd 100644 --- a/core/cpu/x86/64/64.factor +++ b/core/cpu/x86/64/64.factor @@ -16,10 +16,10 @@ M: amd64-backend stack-reg RSP ; M: x86-backend xt-reg RCX ; M: x86-backend stack-save-reg RSI ; -M: temp-reg v>operand drop R13 ; +M: temp-reg v>operand drop RBX ; M: int-regs return-reg drop RAX ; -M: int-regs vregs drop { RAX RBX RCX RDX RBP RSI RDI R8 R9 R10 R11 R12 } ; +M: int-regs vregs drop { RAX RCX RDX RBP RSI RDI R8 R9 R10 R11 R12 R13 } ; M: int-regs param-regs drop { RDI RSI RDX RCX R8 R9 } ; M: float-regs return-reg drop XMM0 ; @@ -146,17 +146,17 @@ M: amd64-backend %alien-indirect ( -- ) cell temp@ CALL ; M: amd64-backend %alien-callback ( quot -- ) - RDI load-indirect "run_callback" f compile-c-call ; + RDI load-indirect "c_to_factor" f compile-c-call ; M: amd64-backend %callback-value ( ctype -- ) ! Save top of data stack %prepare-unbox ! Put former top of data stack in RDI - temp@ RDI MOV + cell temp@ RDI MOV ! Restore data/call/retain stacks "unnest_stacks" f %alien-invoke ! Put former top of data stack in RDI - RDI temp@ MOV + RDI cell temp@ MOV ! Unbox former top of data stack to return registers unbox-return ; diff --git a/core/cpu/x86/architecture/architecture.factor b/core/cpu/x86/architecture/architecture.factor index 6879e23051..4acd4d8c46 100644 --- a/core/cpu/x86/architecture/architecture.factor +++ b/core/cpu/x86/architecture/architecture.factor @@ -150,7 +150,7 @@ M: x86-backend small-enough? ( n -- ? ) : %tag-fixnum ( reg -- ) tag-bits get SHL ; -: temp@ \ stack-frame get swap - ; +: temp@ stack-reg \ stack-frame get rot - [+] ; : struct-return@ ( size n -- n ) [ diff --git a/vm/cpu-x86.S b/vm/cpu-x86.S index a84ae6c480..3e2a97dd5c 100644 --- a/vm/cpu-x86.S +++ b/vm/cpu-x86.S @@ -29,7 +29,7 @@ DEF(FASTCALL void,dosym,(CELL word)): /* Here we have two entry points. The first one is taken when profiling is enabled */ DEF(FASTCALL void,docol_profiling,(CELL word)): - add $CELL_SIZE,PROFILING_OFFSET(%eax) /* Increment profile-count slot */ + add $CELL_SIZE,PROFILING_OFFSET(ARG0) /* Increment profile-count slot */ DEF(FASTCALL void,docol,(CELL word)): mov WORD_DEF_OFFSET(ARG0),ARG0 /* Load word-def slot */ JUMP_QUOT diff --git a/vm/factor.c b/vm/factor.c index e74662a8a4..6a6dc8f154 100644 --- a/vm/factor.c +++ b/vm/factor.c @@ -135,6 +135,7 @@ void init_factor_from_args(F_CHAR *image, int argc, F_CHAR **argv, bool embedded } nest_stacks(); + printf("%lx\n",untag_quotation(userenv[BOOT_ENV])->xt); c_to_factor_toplevel(userenv[BOOT_ENV]); unnest_stacks(); diff --git a/vm/os-linux-x86-64.h b/vm/os-linux-x86-64.h new file mode 100644 index 0000000000..2bbae86f6e --- /dev/null +++ b/vm/os-linux-x86-64.h @@ -0,0 +1,2 @@ +#define UAP_PROGRAM_COUNTER(ucontext) \ + (((ucontext_t *)(ucontext))->uc_mcontext.gregs[16]) From 34465cf837252e350e3f20b50934997318ee9215 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 22 Sep 2007 03:26:09 -0400 Subject: [PATCH 19/24] Remove debug message --- vm/factor.c | 1 - 1 file changed, 1 deletion(-) diff --git a/vm/factor.c b/vm/factor.c index 6a6dc8f154..e74662a8a4 100644 --- a/vm/factor.c +++ b/vm/factor.c @@ -135,7 +135,6 @@ void init_factor_from_args(F_CHAR *image, int argc, F_CHAR **argv, bool embedded } nest_stacks(); - printf("%lx\n",untag_quotation(userenv[BOOT_ENV])->xt); c_to_factor_toplevel(userenv[BOOT_ENV]); unnest_stacks(); From 77d8a844f3763be44dc86cad2d6d1188b95429c4 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 22 Sep 2007 04:00:22 -0400 Subject: [PATCH 20/24] Untested Linux/x86 support --- vm/os-linux-x86-32.h | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 vm/os-linux-x86-32.h diff --git a/vm/os-linux-x86-32.h b/vm/os-linux-x86-32.h new file mode 100644 index 0000000000..e12133966d --- /dev/null +++ b/vm/os-linux-x86-32.h @@ -0,0 +1,2 @@ +#define UAP_PROGRAM_COUNTER(ucontext) \ + (((ucontext_t *)(ucontext))->uc_mcontext.gregs[14]) From 05e66a0659db86c90721344ea8c6b7e468598408 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 22 Sep 2007 17:17:37 -0400 Subject: [PATCH 21/24] Remove dead code; code_fixup stack frame return addrs --- vm/image.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/vm/image.c b/vm/image.c index 0d1b22adee..2d3318472d 100644 --- a/vm/image.c +++ b/vm/image.c @@ -81,19 +81,6 @@ void load_image(F_PARAMETERS *p) userenv[IMAGE_ENV] = tag_object(from_native_string(p->image)); } -/* Compute total sum of sizes of free blocks */ -void save_code_heap(FILE *file) -{ - F_BLOCK *scan = first_block(&code_heap); - - while(scan) - { - if(scan->status == B_ALLOCATED) - fwrite(scan,scan->size,1,file); - scan = next_block(&code_heap,scan); - } -} - /* Save the current image to disk */ bool save_image(const F_CHAR *filename) { @@ -132,7 +119,6 @@ bool save_image(const F_CHAR *filename) fwrite(&h,sizeof(F_HEADER),1,file); fwrite((void*)tenured->start,h.data_size,1,file); - /* save_code_heap(file); */ fwrite(first_block(&code_heap),h.code_size,1,file); fclose(file); @@ -198,7 +184,12 @@ void fixup_stack_frame(F_STACK_FRAME *frame) frame->scan = scan + frame->array; } - /* code_fixup(&frame->return_address); */ +#ifdef CALLSTACK_UP_P + printf("%x %x\n",frame->xt,*(CELL *)(frame->next + 1)); + code_fixup((CELL *)(frame->next + 1)); +#else + code_fixup(&frame->return_address); +#endif } /* Initialize an object in a newly-loaded image */ From 64e3e0c0d69ee8fe4ac211fa491d2994a4959643 Mon Sep 17 00:00:00 2001 From: Slava Date: Sat, 22 Sep 2007 18:56:27 -0400 Subject: [PATCH 22/24] Fix callstack relocation --- extra/factory/.factory-menus.swp | Bin 20480 -> 0 bytes vm/image.c | 19 ++++++++++++++----- vm/stack.c | 4 ++-- vm/stack.h | 2 ++ 4 files changed, 18 insertions(+), 7 deletions(-) delete mode 100644 extra/factory/.factory-menus.swp diff --git a/extra/factory/.factory-menus.swp b/extra/factory/.factory-menus.swp deleted file mode 100644 index 241afbf9d743d8df82d29f4298157ebb10de6d4e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI4YiJ!=9l(!Co8&f4u55L6h1HY0VAJX(?N;rYZ9^m5m)%xqwxJMKoy?uwJKlL* zXXfT6?Y4dp5yS_ILYGxPi4RbGASfuV_(4CYsH}*(=qFJT1y{uf3i>-|=04KQP17YG zRL+H8Zsxqt|2*dW|L32q99cSlQ68T;BKW*eh~}67a;EaGN5s_qLL|PuW~=Z!e5&q> zXNPx4MD$Hv;OwgHq)|NUuBWk`KWucqt-uXi$(@TbDU1Y+1nx!xt#s9TXhIx0`rt7+ zRe9i^16S@Qw@GUxU?gB9U?gB9U?gB9U?gB9U?lK=Ac1BohQ+^iM~3*h7haIFhi?}~ z^5ehkmR zr{FqV04c=&e*tm(Z-E032r>R^Al-NbuY;GteM0Q}A^ZTIhHt?8;JrYd`^rL;z74dq zbX173U%_{Pu(2EP1O(v2NjL%b2r>E#_&Ct!QR*1^DSREi1~I%H=>N!D;MMRd%p{b( z_eVh8d)MG9+z(?y>_KLGJ_}F5Yk>X?e-1tX?}yXy2s{Y1bBO*A{S%PE&?n#~EW>el zEl|eLOWjeR8lU> zI1B8hx@fOw`Ig)`^&H!;kSfRnt+hN*r@yWm*Gb>2yf3{@c3UUIC?!Scwyk!c`z`1D zr9hT;-NnmA3%x&PH|2gqW+fL3UWsv8R-CGwO`OQO6kXPhXQt45BcW>8kpLHWvxOg0$NKvv_Z z*%N=SxQci_&G3C$Pt)eyZ0_mfL{)btifcQq*Y~q}WkK`qRw(VdohA&ld_wwelBiD8 zC+1An$xignJ32^ck1-ftX#0{?+BZ(S(36>5jM9o*;Yr_P#6majb|jw<(`mYKs3P=w z$b!_O*>3)H%Pr_qzFzXFIdHjTYo}nf=!o52EP?I$gO&>8xzTDhJhcJP>4r+nhLNUq zw>{JLe1vu?upPAu2G9Dawc@*umReSTQ;)r5rmDkFWnYvq6J8rwh8x$iJ*e9Vven4s zyMY~^s;PEu+X(G7x2YF8+A;a?o>dSPO{Bh=$rpKspETYnCh)^nl)r)(zGI`M{KRecHkZwyc?dy zNimnsmcnYp?XZ|LEw;66dTuEuup6$mN`kC0YRH%_)omK}s2$hTTam1rw?ly?I9U!gqH{+0Ev5GiovA z1$oAc-PLG4AH`;aeMPQjVMSfkuNj^3s@tq@#44W}uqcFvMXI*j`uD*}8?jrnInU~;Zg-vrroV78-)Q?@QUzVo z3+Z&Wg!0kXv%aWY(Kl}kR#7*0^CId7@8%ksyG?bF(^9JtQn`6Ej`EO9+ICaU&u762 zZ`ZJ4wPV5_7J}@30n>fCs;#CxVM){g$4Znoae~6o8Pu=(;Hq=?ALgf3b-LO^@ox4mjwR}Gkw=Ul(Z!KzIJiqF(tD_DA^$^2Bmq2BXq7f-qY zeq>jvDNnY}!K7Mq(`2R{%;?5$3TcG_!{k=8tvB17#FfSKm(I?~h8u^jFI%CvF4ych zkwFx*@yf(UJ+vK%gKiY-E?9>&sHxa}$+w84Y=>5?z!z8vvE3`{|5BZlc`Uzy&OZ zx_$JdYfvdFeBJRQM_H6eSjirWOgY(1$W4qo?KZYWZ6nebfPGD-?WzVnG6i;}T>lr` zOAn#XYyBUef35$c*O&hUp8<6K@{@22mViGVF25AGm!A9?D7ygn+mnNzc z;P>z>;L|XI55mYNLEZg73e>&#Id}$c!8_q39E5wh>;F8^pFPvC4@%tee-oYty@CBfZp%1|a;T)U=+Vexpired = T; } +F_FIXNUM delta; + void fixup_stack_frame(F_STACK_FRAME *frame) { code_fixup(&frame->xt); @@ -185,13 +187,22 @@ void fixup_stack_frame(F_STACK_FRAME *frame) } #ifdef CALLSTACK_UP_P - printf("%x %x\n",frame->xt,*(CELL *)(frame->next + 1)); - code_fixup((CELL *)(frame->next + 1)); + F_STACK_FRAME *next = REBASE_FRAME_SUCCESSOR(frame,delta); + code_fixup((XT *)(next + 1)); #else code_fixup(&frame->return_address); #endif } +void fixup_callstack_object(F_CALLSTACK *stack) +{ + CELL top = (CELL)(stack + 1); + CELL bottom = top + untag_fixnum_fast(stack->length); + delta = (bottom - stack->bottom); + + iterate_callstack_object(stack,fixup_stack_frame); +} + /* Initialize an object in a newly-loaded image */ void relocate_object(CELL relocating) { @@ -212,9 +223,7 @@ void relocate_object(CELL relocating) fixup_alien((F_ALIEN *)relocating); break; case CALLSTACK_TYPE: - iterate_callstack_object( - (F_CALLSTACK *)relocating, - fixup_stack_frame); + fixup_callstack_object((F_CALLSTACK *)relocating); break; } } diff --git a/vm/stack.c b/vm/stack.c index e50575219c..cf3c1df00a 100644 --- a/vm/stack.c +++ b/vm/stack.c @@ -111,7 +111,7 @@ void iterate_callstack(CELL top, CELL bottom, CELL base, CALLSTACK_ITER iterator while(ITERATING_P) { - F_STACK_FRAME *next = (F_STACK_FRAME *)((CELL)FRAME_SUCCESSOR(frame) + delta); + F_STACK_FRAME *next = REBASE_FRAME_SUCCESSOR(frame,delta); iterator(frame); frame = next; } @@ -344,7 +344,7 @@ static F_FIXNUM delta; void adjust_stack_frame(F_STACK_FRAME *frame) { - FRAME_SUCCESSOR(frame) = (F_STACK_FRAME *)((CELL)FRAME_SUCCESSOR(frame) + delta); + FRAME_SUCCESSOR(frame) = REBASE_FRAME_SUCCESSOR(frame,delta); } void adjust_callstack(F_CALLSTACK *stack, CELL bottom) diff --git a/vm/stack.h b/vm/stack.h index d2bec4fef1..62ee1d9ba2 100644 --- a/vm/stack.h +++ b/vm/stack.h @@ -56,6 +56,8 @@ void init_stacks(CELL ds_size, CELL rs_size); #define FIRST_STACK_FRAME(stack) (F_STACK_FRAME *)((stack) + 1) +#define REBASE_FRAME_SUCCESSOR(frame,delta) (F_STACK_FRAME *)((CELL)FRAME_SUCCESSOR(frame) + delta) + typedef void (*CALLSTACK_ITER)(F_STACK_FRAME *frame); void iterate_callstack(CELL top, CELL bottom, CELL base, CALLSTACK_ITER iterator); From b0f931d038df45ddf75524835f6616a9a148b0a9 Mon Sep 17 00:00:00 2001 From: Slava Date: Sat, 22 Sep 2007 19:31:28 -0400 Subject: [PATCH 23/24] x86 alien fix and new slot intrinsics --- core/cpu/x86/architecture/architecture.factor | 2 +- core/cpu/x86/intrinsics/intrinsics.factor | 67 +++++++++---------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/core/cpu/x86/architecture/architecture.factor b/core/cpu/x86/architecture/architecture.factor index 4acd4d8c46..91e8bf1460 100644 --- a/core/cpu/x86/architecture/architecture.factor +++ b/core/cpu/x86/architecture/architecture.factor @@ -156,7 +156,7 @@ M: x86-backend small-enough? ( n -- ? ) [ stack-frame* cell + + ] [ - temp@ + \ stack-frame get swap - ] ?if ; HOOK: %unbox-struct-1 compiler-backend ( -- ) diff --git a/core/cpu/x86/intrinsics/intrinsics.factor b/core/cpu/x86/intrinsics/intrinsics.factor index fc4d7388bf..1ee6efecfc 100644 --- a/core/cpu/x86/intrinsics/intrinsics.factor +++ b/core/cpu/x86/intrinsics/intrinsics.factor @@ -71,29 +71,38 @@ IN: cpu.x86.intrinsics } define-intrinsic ! Slots +: %slot-literal-known-tag + "obj" operand + "n" get cells + "obj" operand-tag - [+] ; + +: %slot-literal-any-tag + "obj" operand %untag + "obj" operand "n" get cells [+] ; + +: %slot-any + "obj" operand %untag + "n" operand fixnum>slot@ + "obj" operand "n" operand [+] ; \ slot { + ! Slot number is literal and the tag is known + { + [ "obj" operand %slot-literal-known-tag MOV ] H{ + { +input+ { { f "obj" known-tag } { [ small-slot? ] "n" } } } + { +output+ { "obj" } } + } + } ! Slot number is literal { - [ - "obj" operand %untag - ! load slot value - "obj" operand dup "n" get cells [+] MOV - ] H{ + [ "obj" operand %slot-literal-any-tag MOV ] H{ { +input+ { { f "obj" } { [ small-slot? ] "n" } } } { +output+ { "obj" } } } } ! Slot number in a register { - [ - "obj" operand %untag - ! turn tagged fixnum slot # into an offset, - ! multiple of 4 - "n" operand fixnum>slot@ - ! load slot value - "obj" operand dup "n" operand [+] MOV - ] H{ + [ "obj" operand %slot-any MOV ] H{ { +input+ { { f "obj" } { f "n" } } } { +output+ { "obj" } } { +clobber+ { "n" } } @@ -105,38 +114,28 @@ IN: cpu.x86.intrinsics #! Mark the card pointed to by vreg. "val" operand-immediate? "obj" get fresh-object? or [ "obj" operand card-bits SHR - "scratch" operand HEX: ffffffff MOV - "cards_offset" f rc-absolute-cell rel-dlsym - "scratch" operand dup [] MOV - "scratch" operand "obj" operand [+] card-mark OR + "cards_offset" f %alien-global + temp-reg v>operand "obj" operand [+] card-mark OR ] unless ; \ set-slot { + ! Slot number is literal and the tag is known + { + [ %slot-literal-known-tag "val" operand MOV ] H{ + { +input+ { { f "val" } { f "obj" known-tag } { [ small-slot? ] "n" } } } + { +clobber+ { "obj" } } + } + } ! Slot number is literal { - [ - "obj" operand %untag - ! store new slot value - "obj" operand "n" get cells [+] "val" operand MOV - generate-write-barrier - ] H{ + [ %slot-literal-any-tag "val" operand MOV generate-write-barrier ] H{ { +input+ { { f "val" } { f "obj" } { [ small-slot? ] "n" } } } - { +scratch+ { { f "scratch" } } } { +clobber+ { "obj" } } } } ! Slot number in a register { - [ - ! turn tagged fixnum slot # into an offset - "n" operand fixnum>slot@ - "obj" operand %untag - ! store new slot value - "obj" operand "n" operand [+] "val" operand MOV - ! reuse register - "n" get "scratch" set - generate-write-barrier - ] H{ + [ %slot-any "val" operand MOV generate-write-barrier ] H{ { +input+ { { f "val" } { f "obj" } { f "n" } } } { +clobber+ { "obj" "n" } } } From 94bfbbde2fd87468c77cc0fdd928e7929018b29f Mon Sep 17 00:00:00 2001 From: Slava Date: Sun, 23 Sep 2007 15:26:15 -0400 Subject: [PATCH 24/24] Fix set-slot intrinsic for x86 --- core/cpu/x86/intrinsics/intrinsics.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/cpu/x86/intrinsics/intrinsics.factor b/core/cpu/x86/intrinsics/intrinsics.factor index 1ee6efecfc..0228848a33 100644 --- a/core/cpu/x86/intrinsics/intrinsics.factor +++ b/core/cpu/x86/intrinsics/intrinsics.factor @@ -121,7 +121,7 @@ IN: cpu.x86.intrinsics \ set-slot { ! Slot number is literal and the tag is known { - [ %slot-literal-known-tag "val" operand MOV ] H{ + [ %slot-literal-known-tag "val" operand MOV generate-write-barrier ] H{ { +input+ { { f "val" } { f "obj" known-tag } { [ small-slot? ] "n" } } } { +clobber+ { "obj" } } }