factor/core/cpu/x86/bootstrap.factor

79 lines
2.7 KiB
Factor
Raw Normal View History

2007-09-21 23:29:38 -04:00
! 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 compiler.units math generator.fixup
2008-01-02 19:36:36 -05:00
compiler.constants ;
2007-09-21 23:29:38 -04:00
IN: bootstrap.x86
big-endian off
1 jit-code-format set
2007-12-26 20:02:41 -05:00
: stack-frame-size 4 bootstrap-cells ;
2007-10-06 18:54:46 -04:00
2007-09-21 23:29:38 -04:00
[
2008-01-02 19:36:36 -05:00
! Load word
2008-01-02 22:07:25 -05:00
temp-reg 0 [] MOV
2008-01-02 19:36:36 -05:00
! Bump profiling counter
2008-01-02 22:07:25 -05:00
temp-reg profile-count-offset [+] 1 tag-fixnum ADD
2008-01-02 19:36:36 -05:00
! Load word->code
2008-01-02 22:07:25 -05:00
temp-reg temp-reg word-code-offset [+] MOV
2008-01-02 19:36:36 -05:00
! Compute word XT
2008-01-02 22:07:25 -05:00
temp-reg compiled-header-size ADD
2008-01-02 19:36:36 -05:00
! Jump to XT
2008-01-02 22:07:25 -05:00
temp-reg JMP
2008-01-02 19:36:36 -05:00
] rc-absolute-cell rt-literal 2 jit-profiling jit-define
[
stack-frame-size PUSH ! save stack frame size
2008-01-02 19:36:36 -05:00
0 PUSH ! push XT
2007-12-26 20:02:41 -05:00
arg1 PUSH ! alignment
] rc-absolute-cell rt-label 6 jit-prolog jit-define
[
arg0 0 [] MOV ! load literal
2007-09-21 23:29:38 -04:00
ds-reg bootstrap-cell ADD ! increment datastack pointer
ds-reg [] arg0 MOV ! store literal on datastack
] rc-absolute-cell rt-literal 2 jit-push-literal jit-define
[
2007-09-21 23:29:38 -04:00
arg1 stack-reg MOV ! pass callstack pointer as arg 2
(JMP) drop ! go
2008-01-02 19:36:36 -05:00
] rc-relative rt-primitive 3 jit-primitive jit-define
[
2007-12-26 02:33:49 -05:00
(JMP) drop
] rc-relative rt-xt 1 jit-word-jump jit-define
[
2007-12-26 02:33:49 -05:00
(CALL) drop
2007-12-26 20:02:41 -05:00
] rc-relative rt-xt 1 jit-word-call jit-define
[
arg1 0 MOV ! load addr of true quotation
2007-09-21 23:29:38 -04:00
arg0 ds-reg [] MOV ! load boolean
ds-reg bootstrap-cell SUB ! pop boolean
arg0 \ f tag-number CMP ! compare it with f
arg0 arg1 [] CMOVNE ! load true branch if not equal
arg0 arg1 bootstrap-cell [+] CMOVE ! load false branch if equal
arg0 quot-xt@ [+] JMP ! jump to quotation-xt
] rc-absolute-cell rt-literal 1 jit-if-jump jit-define
2007-09-21 23:29:38 -04:00
[
arg1 0 [] MOV ! load dispatch table
2007-09-21 23:29:38 -04:00
arg0 ds-reg [] MOV ! load index
fixnum>slot@ ! turn it into an array offset
ds-reg bootstrap-cell SUB ! pop index
arg0 arg1 ADD ! compute quotation location
2007-09-21 23:29:38 -04:00
arg0 arg0 array-start [+] MOV ! load quotation
arg0 quot-xt@ [+] JMP ! execute branch
] rc-absolute-cell rt-literal 2 jit-dispatch jit-define
2007-09-21 23:29:38 -04:00
[
2007-10-05 17:30:10 -04:00
stack-reg stack-frame-size bootstrap-cell - ADD ! unwind stack frame
] f f f jit-epilog jit-define
2007-09-21 23:29:38 -04:00
[ 0 RET ] f f f jit-return jit-define
2007-09-21 23:29:38 -04:00
[ "bootstrap.x86" forget-vocab ] with-compilation-unit