More changes

release
Slava Pestov 2007-09-21 23:30:47 -04:00
parent 63871229f6
commit 3a1d458b29
9 changed files with 73 additions and 188 deletions

View File

@ -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

View File

@ -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 ;

View File

@ -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

View File

@ -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) */
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

View File

@ -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);

View File

@ -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)

View File

@ -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

View File

@ -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);

View File

@ -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);