factor/core/cpu/x86/bootstrap.factor

72 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 vocabs math generator.fixup ;
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
[
arg0 0 [] MOV ! load quotation
arg1 arg0 quot-xt@ [+] MOV ! load XT
stack-frame-size PUSH ! save stack frame size
arg1 PUSH ! save XT
2007-12-26 20:02:41 -05:00
arg1 PUSH ! alignment
] rc-absolute-cell rt-literal 2 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
] rc-relative rt-primitive 3 jit-word-primitive-jump jit-define
[
2007-09-21 23:29:38 -04:00
arg1 stack-reg bootstrap-cell neg [+] LEA ! pass callstack pointer as arg 2
(CALL) drop ! go
2007-12-26 20:02:41 -05:00
] rc-relative rt-primitive 5 jit-word-primitive-call 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