]> gitweb.factorcode.org Git - factor.git/blob - vm/cpu-arm.32.S
xmode.marker: caching match group regexps for performance
[factor.git] / vm / cpu-arm.32.S
1 #include "asm.h"
2
3 /* Note that the XT is passed to the quotation in r12 */
4 #define CALL_QUOT \
5         ldr r12,[r0, #9]     /* load quotation-xt slot */ ; \
6        mov lr,pc ; \
7         mov pc,r12
8
9 #define JUMP_QUOT \
10         ldr r12,[r0, #9]     /* load quotation-xt slot */ ; \
11        mov pc,r12
12
13 #define SAVED_REGS_SIZE 32
14
15 #define FRAME (RESERVED_SIZE + SAVED_REGS_SIZE + 8)
16
17 #define LR_SAVE [sp, #-4]
18 #define RESERVED_SIZE 8
19
20 #define SAVE_LR str lr,LR_SAVE
21
22 #define LOAD_LR ldr lr,LR_SAVE
23
24 #define SAVE_AT(offset) (RESERVED_SIZE + 4 * offset)
25
26 #define SAVE(register,offset) str register,[sp, #SAVE_AT(offset)]
27
28 #define RESTORE(register,offset) ldr register,[sp, #SAVE_AT(offset)]
29
30 #define PROLOGUE \
31        SAVE_LR ; \
32        sub sp,sp,#FRAME
33
34 #define EPILOGUE \
35        add sp,sp,#FRAME ; \
36        LOAD_LR
37
38 DEF(void,c_to_factor,(CELL quot)):
39         PROLOGUE
40
41        SAVE(r4,0)           /* save GPRs */
42                              /* don't save ds pointer */
43                              /* don't save rs pointer */
44         SAVE(r7,3)
45         SAVE(r8,4)
46         SAVE(r9,5)
47         SAVE(r10,6)
48         SAVE(r11,7)
49        SAVE(r0,8)           /* save quotation since we're about to mangle it */
50
51         sub r0,sp,#4         /* pass call stack pointer as an argument */
52        bl MANGLE(save_callstack_bottom)
53
54        RESTORE(r0,8)        /* restore quotation */
55         CALL_QUOT
56
57         RESTORE(r11,7)       /* restore GPRs */
58         RESTORE(r10,6)
59         RESTORE(r9,5)
60         RESTORE(r8,4)
61         RESTORE(r7,3)
62                              /* don't restore rs pointer */
63                              /* don't restore ds pointer */
64         RESTORE(r4,0)
65
66         EPILOGUE
67         mov pc,lr
68
69 /* The JIT compiles an 'mov r1',sp in front of every primitive call, since a
70 word which was defined as a primitive will not change its definition for the
71 lifetime of the image -- adding new primitives requires a bootstrap. However,
72 an undefined word can certainly become defined,
73
74 DEFER: foo
75 ...
76 : foo ... ;
77
78 And calls to non-primitives do not have this one-instruction prologue, so we
79 set the XT of undefined words to this symbol. */
80 DEF(void,undefined,(CELL word)):
81        sub r1,sp,#4
82        b MANGLE(undefined_error)
83
84 /* Here we have two entry points. The first one is taken when profiling is
85 enabled */
86 DEF(void,docol_profiling,(CELL word)):
87         ldr r1,[r0, #25]     /* load profile-count slot */
88         add r1,r1,#8         /* increment count */
89         str r1,[r0, #25]     /* store profile-count slot */
90 DEF(void,docol,(CELL word)):
91         ldr r0,[r0, #13]     /* load word-def slot */
92         JUMP_QUOT
93
94 /* We must pass the XT to the quotation in r12. */
95 DEF(void,primitive_call,(void)):
96         ldr r0,[r5], #-4     /* load quotation from data stack */
97         JUMP_QUOT
98
99 /* We must preserve r1 here in case we're calling a primitive */
100 DEF(void,primitive_execute,(void)):
101         ldr r0,[r5], #-4     /* load word from data stack */
102         ldr pc,[r0, #29]     /* jump to word-xt */
103
104 @ DEF(void,set_callstack,(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length)):
105 @         sub sp,r0,r2         /* compute new stack pointer */
106 @         mov r0,sp            /* start of destination of memcpy() */
107 @        sub sp,sp,#12        /* alignment */
108 @         bl MANGLE(memcpy)    /* go */
109 @        add sp,sp,#16        /* point SP at innermost frame */
110 @         ldr pc,LR_SAVE       /* return */
111
112 DEF(void,throw_impl,(CELL quot, F_STACK_FRAME *rewind_to)):
113        add sp,r1,#4         /* compute new stack pointer */
114        ldr lr,LR_SAVE       /* we have rewound the stack; load return address */
115        JUMP_QUOT            /* call the quotation */
116
117 DEF(void,lazy_jit_compile,(CELL quot)):
118        mov r1,sp            /* save stack pointer */
119        PROLOGUE
120        bl MANGLE(lazy_jit_compile_impl)
121        EPILOGUE
122         JUMP_QUOT            /* call the quotation */
123
124 #ifdef WINCE
125        .section .drectve
126        .ascii " -export:c_to_factor"
127 #endif