factor/core/cpu/ppc/bootstrap.factor

93 lines
3.2 KiB
Factor
Raw Normal View History

2008-01-08 16:04:45 -05:00
! Copyright (C) 2007, 2008 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: bootstrap.image.private kernel namespaces system
cpu.ppc.assembler math layouts words vocabs ;
2007-09-20 18:09:08 -04:00
IN: bootstrap.ppc
4 \ cell set
big-endian on
4 jit-code-format set
: ds-reg 14 ;
: temp-reg 6 ;
2008-01-08 16:04:45 -05:00
: aux-reg 7 ;
2007-09-20 18:09:08 -04:00
: factor-area-size 4 bootstrap-cells ;
2007-09-20 18:09:08 -04:00
: stack-frame
factor-area-size c-area-size + 4 bootstrap-cells align ;
: next-save stack-frame bootstrap-cell - ;
: xt-save stack-frame 2 bootstrap-cells - ;
2007-09-20 18:09:08 -04:00
2008-01-08 16:04:45 -05:00
! jit-profiling
2007-09-20 18:09:08 -04:00
[
2008-01-08 16:04:45 -05:00
0 temp-reg LOAD32 ! load XT
0 MFLR ! load return address
1 1 stack-frame neg ADDI ! create stack frame
temp-reg 1 xt-save STW ! save XT
stack-frame temp-reg LI ! load frame size
temp-reg 1 next-save STW ! save frame size
0 1 lr-save stack-frame + STW ! save return address
2008-01-08 16:04:45 -05:00
] rc-absolute-ppc-2/2 rt-label 0 jit-prolog jit-define
2007-09-20 18:09:08 -04:00
[
2008-01-08 16:04:45 -05:00
0 temp-reg LOAD32 ! load literal
temp-reg dup 0 LWZ ! indirection
temp-reg ds-reg 4 STWU ! push literal
2008-01-08 16:04:45 -05:00
] rc-absolute-ppc-2/2 rt-literal 0 jit-push-literal jit-define
2007-09-20 18:09:08 -04:00
[
4 1 MR ! pass stack pointer to primitive
2008-01-08 16:04:45 -05:00
0 temp-reg LOAD32 ! load primitive address
temp-reg MTCTR ! jump to primitive
BCTR
] rc-absolute-ppc-2/2 rt-primitive 1 jit-word-primitive jit-define
2007-09-20 18:09:08 -04:00
[
2008-01-08 16:04:45 -05:00
0 BL
] rc-relative-ppc-3 rt-xt 0 jit-word-call jit-define
2007-09-20 18:09:08 -04:00
2008-01-08 16:04:45 -05:00
[
0 B
] rc-relative-ppc-3 rt-xt 0 jit-word-jump jit-define
2007-09-20 18:09:08 -04:00
2008-01-08 16:04:45 -05:00
: jit-call-quot ( -- )
temp-reg temp-reg quot-xt@ LWZ ! load quotation-xt
temp-reg MTCTR ! jump to quotation-xt
BCTR ;
2007-09-20 18:09:08 -04:00
2008-01-08 16:04:45 -05:00
[
0 temp-reg LOAD32 ! point quot-reg at false branch
aux-reg ds-reg 0 LWZ ! load boolean
0 aux-reg \ f tag-number CMPI ! compare it with f
2 BNE ! skip next insn if its not f
2008-01-08 16:04:45 -05:00
temp-reg dup 4 ADDI ! point quot-reg at true branch
temp-reg dup 0 LWZ ! load the branch
ds-reg dup 4 SUBI ! pop boolean
2008-01-08 16:04:45 -05:00
jit-call-quot
] rc-absolute-ppc-2/2 rt-literal 0 jit-if-jump jit-define
2007-09-20 18:09:08 -04:00
[
2008-01-08 16:04:45 -05:00
0 temp-reg LOAD32 ! load dispatch array
temp-reg dup 0 LWZ ! indirection
aux-reg ds-reg 0 LWZ ! load index
aux-reg dup 1 SRAWI ! turn it into an array offset
temp-reg dup aux-reg ADD ! compute quotation location
temp-reg dup array-start LWZ ! load quotation
ds-reg dup 4 SUBI ! pop index
2008-01-08 16:04:45 -05:00
jit-call-quot
] rc-absolute-ppc-2/2 rt-literal 0 jit-dispatch jit-define
2007-09-20 18:09:08 -04:00
[
0 1 lr-save stack-frame + LWZ ! load return address
1 1 stack-frame ADDI ! pop stack frame
0 MTLR ! get ready to return
2008-01-08 16:04:45 -05:00
] f f f jit-epilog jit-define
2007-09-20 18:09:08 -04:00
2008-01-08 16:04:45 -05:00
[ BLR ] f f f jit-return jit-define
2007-09-20 18:09:08 -04:00
"bootstrap.ppc" forget-vocab