1 ! Copyright (C) 2020 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: bootstrap.image.private compiler.codegen.relocation
4 compiler.constants compiler.units cpu.arm.assembler
5 cpu.arm.assembler.opcodes generic.single.private
6 kernel kernel.private layouts locals locals.backend
7 math math.private memory namespaces sequences slots.private
8 strings.private threads.private vocabs make ;
16 ! https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling?view=vs-2019
18 ! x0 Volatile Parameter/scratch register 1, result register
19 ! x1-x7 Volatile Parameter/scratch register 2-8
20 ! x8-x15 Volatile Scratch registers
21 ! x16-x17 Volatile Intra-procedure-call scratch registers
22 ! x18 Non-volatile Platform register: in kernel mode, points to KPCR for the current processor;
23 ! in user mode, points to TEB
24 ! x19-x28 Non-volatile Scratch registers
25 ! x29/fp Non-volatile Frame pointer
26 ! x30/lr Non-volatile Link registers
28 ! varargs https://developer.arm.com/documentation/ihi0055/d/?lang=en
29 : stack-frame-size ( -- n ) 8 bootstrap-cells ;
30 : volatile-regs ( -- seq ) { X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 } ;
31 ! windows arm - X18 is non-volatile https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-160
32 : nv-regs ( -- seq ) { X18 X19 X20 X21 X22 X23 X24 X25 X26 X27 X28 X29 X30 } ;
34 ! callee-save = non-volatile aka call-preserved
36 ! x30 is the link register (used to return from subroutines)
37 ! x29 is the frame register
38 ! x19 to x29 are callee-saved
39 ! x18 is the 'platform register', used for some operating-system-specific special purpose,
40 ! or an additional caller-saved register
41 ! x16 and x17 are the Intra-Procedure-call scratch register
42 ! x9 to x15: used to hold local variables (caller saved)
43 ! x8: used to hold indirect return value address
44 ! x0 to x7: used to hold argument values passed to a subroutine, and also hold
45 ! results returned from a subroutine
48 ! https://en.wikichip.org/wiki/arm/aarch64
49 ! Generally, X0 through X18 (volatile, can corrupt) while X19-X29 must be preserved (non-volatile)
50 ! Volatile registers' content may change over a subroutine call
51 ! non-volatile register is a type of register with contents that must be preserved over subroutine calls
52 ! Register Role Requirement
53 ! X0 - X7 Parameter/result registers Can Corrupt (volatile)
54 ! X8 Indirect result location register (volatile)
55 ! X9 - X15 Temporary registers (volatile)
56 ! X16 - X17 Intra-procedure call temporary (volatile)
57 ! x16 - syscall reg with SVC instructioin
58 ! X18 Platform register, otherwise temporary, DONT USE (volatile)
60 ! X19 - X29 Callee-saved register Must preserve (non-volatile)
61 ! X29 - frame pointer register, must always be valid
62 ! X30 Link Register LR Can Corrupt
63 ! X31 Stack Pointer SP
64 ! 16-byte stack alignment
66 ! stack walking - {fp, lr} pairs if compiled with frame pointers enabled
68 : arg1 ( -- reg ) X0 ;
69 : arg2 ( -- reg ) X1 ;
70 : arg3 ( -- reg ) X2 ;
71 : arg4 ( -- reg ) X3 ;
74 ! windows arm64: 16 bytes https://devblogs.microsoft.com/oldnewthing/20190111-00/?p=100685
75 ! windows arm32: 8 bytes
77 ! Apple arm64: 128 bytes https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms?language=objc
78 : red-zone-size ( -- n ) 16 ; ! 16 bytes on windows, or 128 bytes on linux? or 0?
80 ! no red zone on x86/x64 windows
83 ! https://github.com/MicrosoftDocs/cpp-docs/blob/master/docs/build/arm64-windows-abi-conventions.md
85 : shift-arg ( -- reg ) X1 ;
86 : div-arg ( -- reg ) X0 ;
87 : mod-arg ( -- reg ) X2 ;
89 ! caller-saved registers X9-X15
90 ! callee-saved registers X19-X29
91 : temp0 ( -- reg ) X9 ;
92 : temp1 ( -- reg ) X10 ;
93 : temp2 ( -- reg ) X11 ;
94 : temp3 ( -- reg ) X12 ;
97 ! : pic-tail-reg ( -- reg ) RBX ;
98 : return-reg ( -- reg ) X0 ;
99 : stack-reg ( -- reg ) SP ;
100 ! https://developer.arm.com/documentation/dui0801/a/Overview-of-AArch64-state/Link-registers
101 : link-reg ( -- reg ) X30 ; ! LR
102 : stack-frame-reg ( -- reg ) X29 ; ! FP
103 : vm-reg ( -- reg ) X28 ;
104 : ds-reg ( -- reg ) X27 ;
105 : rs-reg ( -- reg ) X26 ;
106 ! : ctx-reg ( -- reg ) R12 ;
107 ! : fixnum>slot@ ( -- ) temp0 1 SAR ;
108 ! : rex-length ( -- n ) 1 ;
110 ! rc-absolute-cell is just CONSTANT: 0
111 : jit-call ( name -- )
113 f rc-absolute-cell rel-dlsym
115 ! RAX 0 MOV f rc-absolute-cell rel-dlsym
118 :: jit-call-1arg ( arg1s name -- )
124 :: jit-call-2arg ( arg1s arg2s name -- )
133 ! pic-tail-reg 5 [RIP+] LEA
134 ! 0 JMP f rc-relative rel-word-pic-tail
135 ] JIT-WORD-JUMP jit-define
138 ! no-op on x86-64. in factor contexts vm-reg always contains the
142 : jit-load-context ( -- ) ;
143 ! ctx-reg vm-reg vm-context-offset [+] MOV ;
145 : jit-save-context ( -- ) ;
147 ! The reason for -8 I think is because we are anticipating a CALL
148 ! instruction. After the call instruction, the contexts frame_top
149 ! will point to the origin jump address.
151 ! ctx-reg context-callstack-top-offset [+] R11 MOV
152 ! ctx-reg context-datastack-offset [+] ds-reg MOV
153 ! ctx-reg context-retainstack-offset [+] rs-reg MOV ;
155 ! ctx-reg must already have been loaded
156 : jit-restore-context ( -- ) ;
157 ! ds-reg ctx-reg context-datastack-offset [+] MOV
158 ! rs-reg ctx-reg context-retainstack-offset [+] MOV ;
163 ! ! ctx-reg is preserved across the call because it is non-volatile
166 ! ! call the primitive
168 ! RAX 0 MOV f f rc-absolute-cell rel-dlsym
170 ! jit-restore-context
171 ] JIT-PRIMITIVE jit-define
174 : jit-jump-quot ( -- )
175 quot-entry-point-offset arg1 ADR
177 ! arg1 quot-entry-point-offset [+] JMP ;
179 : jit-call-quot ( -- )
180 quot-entry-point-offset arg1 ADR
182 ! arg1 quot-entry-point-offset [+] CALL ;
184 : signal-handler-save-regs ( -- regs ) { } ;
185 ! { RAX RCX RDX RBX RBP RSI RDI R8 R9 R10 R11 R12 R13 R14 R15 } ;
189 ! temp2 0 MOV f rc-absolute-cell rel-literal
191 ] PIC-CHECK-TUPLE jit-define
196 1 bootstrap-cells rs-reg rs-reg ADDi64
197 -1 bootstrap-cells ds-reg rs-reg LDR-post ;
200 1 bootstrap-cells ds-reg ds-reg ADDi64
201 -1 bootstrap-cells rs-reg ds-reg LDR-post ;
204 1 bootstrap-cells rs-reg rs-reg ADDi64
205 -1 bootstrap-cells ds-reg rs-reg LDR-post
206 1 bootstrap-cells rs-reg rs-reg ADDi64
207 -1 bootstrap-cells ds-reg rs-reg LDR-post ;
210 1 bootstrap-cells ds-reg ds-reg ADDi64
211 -1 bootstrap-cells rs-reg ds-reg LDR-post
212 1 bootstrap-cells ds-reg ds-reg ADDi64
213 -1 bootstrap-cells rs-reg ds-reg LDR-post ;
216 1 bootstrap-cells rs-reg rs-reg ADDi64
217 -1 bootstrap-cells ds-reg rs-reg LDR-post
218 1 bootstrap-cells rs-reg rs-reg ADDi64
219 -1 bootstrap-cells ds-reg rs-reg LDR-post
220 1 bootstrap-cells rs-reg rs-reg ADDi64
221 -1 bootstrap-cells ds-reg rs-reg LDR-post ;
224 1 bootstrap-cells ds-reg ds-reg ADDi64
225 -1 bootstrap-cells rs-reg ds-reg LDR-post
226 1 bootstrap-cells ds-reg ds-reg ADDi64
227 -1 bootstrap-cells rs-reg ds-reg LDR-post
228 1 bootstrap-cells ds-reg ds-reg ADDi64
229 -1 bootstrap-cells rs-reg ds-reg LDR-post ;
232 : jit-switch-context ( reg -- ) drop ;
233 ! ! Push a bogus return address so the GC can track this frame back
237 ! ! Make the new context the current one
239 ! vm-reg vm-context-offset [+] ctx-reg MOV
241 ! ! Load new stack pointer
242 ! RSP ctx-reg context-callstack-top-offset [+] MOV
244 ! ! Load new ds, rs registers
245 ! jit-restore-context
247 ! ctx-reg jit-update-tib ;
249 : jit-pop-context-and-param ( -- ) ;
251 ! arg1 arg1 alien-offset [+] MOV
252 ! arg2 ds-reg -8 [+] MOV
255 : jit-push-param ( -- ) ;
257 ! ds-reg [] arg2 MOV ;
259 : jit-set-context ( -- ) ;
260 ! jit-pop-context-and-param
262 ! arg1 jit-switch-context
266 : jit-pop-quot-and-param ( -- ) ;
268 ! arg2 ds-reg -8 [+] MOV
271 : jit-start-context ( -- ) ;
272 ! Create the new context in return-reg. Have to save context
273 ! twice, first before calling new_context() which may GC,
274 ! and again after popping the two parameters from the stack.
276 ! vm-reg "new_context" jit-call-1arg
278 ! jit-pop-quot-and-param
280 ! return-reg jit-switch-context
284 : jit-delete-current-context ( -- ) ;
285 ! vm-reg "delete_context" jit-call-1arg ;
289 ! 0 CALL f rc-relative rel-word
297 ! 0 [RIP+] EAX MOV rc-relative rel-safepoint
298 ] JIT-SAFEPOINT jit-define
300 ! # All arm.64 subprimitives
316 ! Rn Rd MOVr64 ! comment
318 vm-reg "begin_callback" jit-call-1arg
320 return-reg arg1 MOVr64 ! arg1 is return
323 vm-reg "end_callback" jit-call-1arg
325 } define-sub-primitives
330 ! { (set-context) [ jit-set-context ] }
331 ! { (set-context-and-delete) [
332 ! jit-delete-current-context
335 ! { (start-context) [ jit-start-context ] }
336 ! { (start-context-and-delete) [ jit-start-context-and-delete ] }
342 ! ! vm-reg "begin_callback" jit-call-1arg
344 ! ! ! call the quotation
345 ! ! arg1 return-reg MOV
348 ! ! vm-reg "end_callback" jit-call-1arg
367 ! ! vm-reg "begin_callback" jit-call-1arg
369 ! ! return-reg arg1 MOVr64 ! arg1 is return
372 ! ! vm-reg "end_callback" jit-call-1arg
377 ! { unwind-native-frames [ ] }
380 ! { fixnum+ [ [ ADD ] "overflow_fixnum_add" jit-overflow ] }
381 ! { fixnum- [ [ SUB ] "overflow_fixnum_subtract" jit-overflow ] }
386 ! RBX ds-reg 8 [+] MOV
387 ! RBX tag-bits get SAR
394 ! arg1 tag-bits get SAR
397 ! "overflow_fixnum_multiply" jit-call
412 ! RSP [] arg1 16-bit-version-of MOV
417 ! ! Load callstack object
419 ! ds-reg bootstrap-cell SUB
420 ! ! Get ctx->callstack_bottom
422 ! arg1 ctx-reg context-callstack-bottom-offset [+] MOV
423 ! ! Get top of callstack object -- 'src' for memcpy
424 ! arg2 arg4 callstack-top-offset [+] LEA
425 ! ! Get callstack length, in bytes --- 'len' for memcpy
426 ! arg3 arg4 callstack-length-offset [+] MOV
427 ! arg3 tag-bits get SHR
428 ! ! Compute new stack pointer -- 'dst' for memcpy
430 ! ! Install new stack pointer
432 ! ! Call memcpy; arguments are now in the correct registers
433 ! ! Create register shadow area for Win64
435 ! "factor_memcpy" jit-call
436 ! ! Tear down register shadow area
438 ! ! Return with new callstack
441 ! } define-sub-primitives
445 ! C to Factor entry point
448 ! ! Optimizing compiler's side of callback accesses
449 ! ! arguments that are on the stack via the frame pointer.
450 ! ! On x86-32 fastcall, and x86-64, some arguments are passed
451 ! ! in registers, and so the only registers that are safe for
452 ! ! use here are frame-reg, nv-reg and vm-reg.
454 ! frame-reg stack-reg MOV
456 ! ! Save all non-volatile registers
457 ! nv-regs [ PUSH ] each
461 ! ! Load VM into vm-reg
462 ! vm-reg 0 MOV 0 rc-absolute-cell rel-vm
465 ! nv-reg vm-reg vm-context-offset [+] MOV
468 ! ! Switch over to the spare context
469 ! nv-reg vm-reg vm-spare-context-offset [+] MOV
470 ! vm-reg vm-context-offset [+] nv-reg MOV
472 ! ! Save C callstack pointer
473 ! nv-reg context-callstack-save-offset [+] stack-reg MOV
475 ! ! Load Factor stack pointers
476 ! stack-reg nv-reg context-callstack-bottom-offset [+] MOV
477 ! nv-reg jit-update-tib
480 ! rs-reg nv-reg context-retainstack-offset [+] MOV
481 ! ds-reg nv-reg context-datastack-offset [+] MOV
483 ! ! Call into Factor code
484 ! link-reg 0 MOV f rc-absolute-cell rel-word
487 ! ! Load VM into vm-reg; only needed on x86-32, but doesn't
489 ! vm-reg 0 MOV 0 rc-absolute-cell rel-vm
491 ! ! Load C callstack pointer
492 ! nv-reg vm-reg vm-context-offset [+] MOV
493 ! stack-reg nv-reg context-callstack-save-offset [+] MOV
497 ! vm-reg vm-context-offset [+] nv-reg MOV
499 ! ! Restore non-volatile registers
502 ! nv-regs <reversed> [ POP ] each
506 ! ! Callbacks which return structs, or use stdcall/fastcall/thiscall,
507 ! ! need a parameter here.
509 ! ! See the comment for M\ x86.32 stack-cleanup in cpu.x86.32
510 ! 0xffff RET f rc-absolute-2 rel-untagged
511 ] CALLBACK-STUB jit-define
515 ! temp0 0 MOV f rc-absolute-cell rel-literal
516 ! ! increment datastack pointer
517 ! ds-reg bootstrap-cell ADD
518 ! ! store literal on datastack
519 ! ds-reg [] temp0 MOV
520 ] JIT-PUSH-LITERAL jit-define
523 ! 0 CALL f rc-relative rel-word-pic
524 ] JIT-WORD-CALL jit-define
526 ! The *-signal-handler subprimitives are special-cased in vm/quotations.cpp
527 ! not to trigger generation of a stack frame, so they can
528 ! peform their own prolog/epilog preserving registers.
530 ! It is important that the total is 192/64 and that it matches the
531 ! constants in vm/cpu-x86.*.hpp
532 : jit-signal-handler-prolog ( -- ) ;
533 ! ! Return address already on stack -> 8/4 bytes.
535 ! ! Push all registers. 15 regs/120 bytes on 64bit, 7 regs/28 bytes
536 ! ! on 32bit -> 128/32 bytes.
537 ! signal-handler-save-regs [ PUSH ] each
539 ! ! Push flags -> 136/36 bytes
542 ! ! Register parameter area 32 bytes, unused on platforms other than
543 ! ! windows 64 bit, but including it doesn't hurt. Plus
544 ! ! alignment. LEA used so we don't dirty flags -> 192/64 bytes.
545 ! stack-reg stack-reg 7 bootstrap-cells neg [+] LEA
549 : jit-signal-handler-epilog ( -- ) ;
550 ! stack-reg stack-reg 7 bootstrap-cells [+] LEA
552 ! signal-handler-save-regs reverse [ POP ] each ;
556 ! temp0 ds-reg [] MOV
558 ! ds-reg bootstrap-cell SUB
559 ! ! compare boolean with f
560 ! temp0 \ f type-number CMP
561 ! ! jump to true branch if not equal
562 ! 0 JNE f rc-relative rel-word
563 ! ! jump to false branch if equal
564 ! 0 JMP f rc-relative rel-word
570 ! 0 CALL f rc-relative rel-word
576 ! 0 CALL f rc-relative rel-word
578 ] JIT-2DIP jit-define
582 ! 0 CALL f rc-relative rel-word
584 ] JIT-3DIP jit-define
588 ! temp0 ds-reg [] MOV
590 ! ds-reg bootstrap-cell SUB
592 ! [ temp0 word-entry-point-offset [+] CALL ]
593 ! [ temp0 word-entry-point-offset [+] JMP ]
594 ! \ (execute) define-combinator-primitive
597 ! temp0 ds-reg [] MOV
598 ! ds-reg bootstrap-cell SUB
599 ! temp0 word-entry-point-offset [+] JMP
600 ] JIT-EXECUTE jit-define
603 ! https://elixir.bootlin.com/linux/latest/source/arch/arm64/kernel/stacktrace.c#L22
605 ! x64 ! stack-reg stack-frame-size bootstrap-cell - SUB
608 ! : link-reg ( -- reg ) X30 ; ! LR
609 ! : stack-frame-reg ( -- reg ) X29 ; ! FP
611 ! ! make room for LR plus magic number of callback, 16byte align
612 stack-frame-size bootstrap-cell 2 * + stack-reg stack-reg SUBi64
613 ! link-reg X29 stack-reg STP
614 0 SP link-reg X29 STP-pre
615 ] JIT-PROLOG jit-define
618 ! x64 ! stack-reg stack-frame-size bootstrap-cell - ADD
619 0 SP link-reg X29 LDP-pre
620 stack-frame-size bootstrap-cell 2 * + stack-reg stack-reg ADDi64
621 ] JIT-EPILOG jit-define
625 ] JIT-RETURN jit-define
627 ! ! ! Polymorphic inline caches
629 ! The PIC stubs are not permitted to touch pic-tail-reg.
631 ! Load a value from a stack position
633 ! temp1 ds-reg 0x7f [+] MOV f rc-absolute-1 rel-untagged
634 ] PIC-LOAD jit-define
637 ! temp1/32 tag-mask get AND
642 ! temp1/32 tag-mask get AND
643 ! temp1/32 tuple type-number CMP
645 ! [ temp1 temp0 tuple-class-offset [+] MOV ]
647 ] PIC-TUPLE jit-define
650 ! temp1/32 0x7f CMP f rc-absolute-1 rel-untagged
651 ] PIC-CHECK-TAG jit-define
654 ! 0 JE f rc-relative rel-word
657 ! ! ! Megamorphic caches
662 ! temp1/32 tag-mask get AND
663 ! temp1/32 tag-bits get SHL
664 ! temp1/32 tuple type-number tag-fixnum CMP
666 ! [ temp1 temp0 tuple-class-offset [+] MOV ]
669 ! temp0 0 MOV f rc-absolute-cell rel-literal
670 ! ! key = hashcode(class)
672 ! bootstrap-cell 4 = [ temp2 1 SHR ] when
673 ! ! key &= cache.length - 1
674 ! temp2 mega-cache-size get 1 - bootstrap-cell * AND
675 ! ! cache += array-start-offset
676 ! temp0 array-start-offset ADD
679 ! ! if(get(cache) == class)
683 ! ! megamorphic_cache_hits++
684 ! temp1 0 MOV rc-absolute-cell rel-megamorphic-cache-hits
686 ! ! goto get(cache + bootstrap-cell)
687 ! temp0 temp0 bootstrap-cell [+] MOV
688 ! temp0 word-entry-point-offset [+] JMP
689 ! ! fall-through on miss
691 ] MEGA-LOOKUP jit-define
694 : jit-compare ( insn -- ) drop ;
696 ! temp3 0 MOV t rc-absolute-cell rel-literal
698 ! temp1 \ f type-number MOV
700 ! temp0 ds-reg [] MOV
701 ! ! adjust stack pointer
702 ! ds-reg bootstrap-cell SUB
703 ! ! compare with second value
704 ! ds-reg [] temp0 CMP
706 ! [ temp1 temp3 ] dip execute( dst src -- )
708 ! ds-reg [] temp1 MOV ;
711 : jit-math ( insn -- ) drop ;
712 ! ! load second input
713 ! temp0 ds-reg [] MOV
715 ! ds-reg bootstrap-cell SUB
717 ! [ ds-reg [] temp0 ] dip execute( dst src -- ) ;
719 : jit-fixnum-/mod ( -- ) ;
720 ! ! load second parameter
721 ! temp1 ds-reg [] MOV
722 ! ! load first parameter
723 ! div-arg ds-reg bootstrap-cell neg [+] MOV
725 ! mod-arg div-arg MOV
727 ! mod-arg bootstrap-cell-bits 1 - SAR
731 ! # Rest of arm64 subprimitives
736 ! { fixnum+fast [ \ ADD jit-math ] }
739 ! { fixnum-bitand [ \ AND jit-math ] }
744 ! ds-reg [] tag-mask get XOR
746 ! { fixnum-bitor [ \ OR jit-math ] }
747 ! { fixnum-bitxor [ \ XOR jit-math ] }
748 ! { fixnum-shift-fast [
750 ! shift-arg ds-reg [] MOV
751 ! ! untag shift count
752 ! shift-arg tag-bits get SAR
753 ! ! adjust stack pointer
754 ! ds-reg bootstrap-cell SUB
756 ! temp3 ds-reg [] MOV
759 ! ! compute positive shift value in temp2
762 ! ! compute negative shift value in temp3
764 ! temp3 tag-mask get bitnot AND
766 ! ! if shift count was negative, move temp0 to temp2
769 ! ds-reg [] temp2 MOV
774 ! temp0 ds-reg [] MOV
775 ! ds-reg bootstrap-cell SUB
777 ! temp0 tag-mask get TEST
778 ! temp0 \ f type-number MOV
779 ! temp1 1 tag-fixnum MOV
781 ! ds-reg [] temp0 MOV
783 ! { eq? [ \ CMOVE jit-compare ] }
784 ! { fixnum> [ \ CMOVG jit-compare ] }
785 ! { fixnum>= [ \ CMOVGE jit-compare ] }
786 ! { fixnum< [ \ CMOVL jit-compare ] }
787 ! { fixnum<= [ \ CMOVLE jit-compare ] }
792 ! ! adjust stack pointer
793 ! ds-reg bootstrap-cell SUB
795 ! ds-reg [] mod-arg MOV
799 ! ! adjust stack pointer
800 ! ds-reg bootstrap-cell SUB
802 ! div-arg tag-bits get SHL
804 ! ds-reg [] div-arg MOV
806 ! { fixnum/mod-fast [
809 ! div-arg tag-bits get SHL
811 ! ds-reg [] mod-arg MOV
812 ! ds-reg bootstrap-cell neg [+] div-arg MOV
817 ! ! load second input
818 ! temp0 ds-reg [] MOV
820 ! ds-reg bootstrap-cell SUB
822 ! temp1 ds-reg [] MOV
823 ! ! untag second input
824 ! temp0 tag-bits get SAR
828 ! ds-reg [] temp0 MOV
832 ! { fixnum-fast [ \ SUB jit-math ] }
837 ! temp0 ds-reg [] MOV
838 ! ! adjust stack pointer
839 ! ds-reg bootstrap-cell SUB
840 ! ! turn local number into offset
842 ! ! decrement retain stack pointer
846 ! ! load local number
847 ! temp0 ds-reg [] MOV
848 ! ! turn local number into offset
851 ! temp0 rs-reg temp0 [+] MOV
853 ! ds-reg [] temp0 MOV
855 ! { load-local [ jit->r ] }
860 ! temp0 ds-reg [] MOV
861 ! ! adjust stack pointer
862 ! ds-reg bootstrap-cell SUB
864 ! temp1 ds-reg [] MOV
865 ! ! turn slot number into offset
868 ! temp1 tag-bits get SHR
869 ! temp1 tag-bits get SHL
871 ! temp0 temp1 temp0 [+] MOV
873 ! ds-reg [] temp0 MOV
875 ! { string-nth-fast [
876 ! ! load string index from stack
877 ! temp0 ds-reg bootstrap-cell neg [+] MOV
878 ! temp0 tag-bits get SHR
879 ! ! load string from stack
880 ! temp1 ds-reg [] MOV
882 ! temp0 8-bit-version-of temp0 temp1 string-offset [++] MOV
883 ! temp0 temp0 8-bit-version-of MOVZX
884 ! temp0 tag-bits get SHL
885 ! ! store character to stack
886 ! ds-reg bootstrap-cell SUB
887 ! ds-reg [] temp0 MOV
891 ! temp0 ds-reg [] MOV
893 ! temp0/32 tag-mask get AND
895 ! temp0/32 tag-bits get SHL
897 ! ds-reg [] temp0 MOV
903 ! { drop [ ds-reg bootstrap-cell SUB ] }
904 ! { 2drop [ ds-reg 2 bootstrap-cells SUB ] }
905 ! { 3drop [ ds-reg 3 bootstrap-cells SUB ] }
906 ! { 4drop [ ds-reg 4 bootstrap-cells SUB ] }
910 ! temp0 ds-reg [] MOV
911 ! ds-reg bootstrap-cell ADD
912 ! ds-reg [] temp0 MOV
915 ! temp0 ds-reg [] MOV
916 ! temp1 ds-reg bootstrap-cell neg [+] MOV
917 ! ds-reg 2 bootstrap-cells ADD
918 ! ds-reg [] temp0 MOV
919 ! ds-reg bootstrap-cell neg [+] temp1 MOV
922 ! temp0 ds-reg [] MOV
923 ! temp1 ds-reg -1 bootstrap-cells [+] MOV
924 ! temp3 ds-reg -2 bootstrap-cells [+] MOV
925 ! ds-reg 3 bootstrap-cells ADD
926 ! ds-reg [] temp0 MOV
927 ! ds-reg -1 bootstrap-cells [+] temp1 MOV
928 ! ds-reg -2 bootstrap-cells [+] temp3 MOV
931 ! temp0 ds-reg [] MOV
932 ! temp1 ds-reg -1 bootstrap-cells [+] MOV
933 ! temp2 ds-reg -2 bootstrap-cells [+] MOV
934 ! temp3 ds-reg -3 bootstrap-cells [+] MOV
935 ! ds-reg 4 bootstrap-cells ADD
936 ! ds-reg [] temp0 MOV
937 ! ds-reg -1 bootstrap-cells [+] temp1 MOV
938 ! ds-reg -2 bootstrap-cells [+] temp2 MOV
939 ! ds-reg -3 bootstrap-cells [+] temp3 MOV
942 ! temp0 ds-reg [] MOV
943 ! temp1 ds-reg -1 bootstrap-cells [+] MOV
944 ! ds-reg [] temp1 MOV
945 ! ds-reg bootstrap-cell ADD
946 ! ds-reg [] temp0 MOV
949 ! ! ### Misc shufflers
951 ! temp0 ds-reg -1 bootstrap-cells [+] MOV
952 ! ds-reg bootstrap-cell ADD
953 ! ds-reg [] temp0 MOV
956 ! temp0 ds-reg -2 bootstrap-cells [+] MOV
957 ! ds-reg bootstrap-cell ADD
958 ! ds-reg [] temp0 MOV
963 ! temp0 ds-reg [] MOV
964 ! ds-reg bootstrap-cell SUB
965 ! ds-reg [] temp0 MOV
968 ! temp0 ds-reg [] MOV
969 ! ds-reg 2 bootstrap-cells SUB
970 ! ds-reg [] temp0 MOV
975 ! temp0 ds-reg [] MOV
976 ! temp1 ds-reg -1 bootstrap-cells [+] MOV
977 ! temp3 ds-reg -2 bootstrap-cells [+] MOV
978 ! ds-reg -2 bootstrap-cells [+] temp0 MOV
979 ! ds-reg -1 bootstrap-cells [+] temp3 MOV
980 ! ds-reg [] temp1 MOV
983 ! temp0 ds-reg [] MOV
984 ! temp1 ds-reg -1 bootstrap-cells [+] MOV
985 ! temp3 ds-reg -2 bootstrap-cells [+] MOV
986 ! ds-reg -2 bootstrap-cells [+] temp1 MOV
987 ! ds-reg -1 bootstrap-cells [+] temp0 MOV
988 ! ds-reg [] temp3 MOV
991 ! temp0 ds-reg [] MOV
992 ! temp1 ds-reg bootstrap-cell neg [+] MOV
993 ! ds-reg bootstrap-cell neg [+] temp0 MOV
994 ! ds-reg [] temp1 MOV
997 ! temp0 ds-reg -1 bootstrap-cells [+] MOV
998 ! temp1 ds-reg -2 bootstrap-cells [+] MOV
999 ! ds-reg -2 bootstrap-cells [+] temp0 MOV
1000 ! ds-reg -1 bootstrap-cells [+] temp1 MOV
1003 ! ! ## Signal handling
1004 ! { leaf-signal-handler [
1005 ! jit-signal-handler-prolog
1007 ! temp0 vm-reg vm-signal-handler-addr-offset [+] MOV
1009 ! jit-signal-handler-epilog
1010 ! ! Pop the fake leaf frame along with our return address
1011 ! leaf-stack-frame-size bootstrap-cell - RET
1013 ! { signal-handler [
1014 ! jit-signal-handler-prolog
1016 ! temp0 vm-reg vm-signal-handler-addr-offset [+] MOV
1018 ! jit-signal-handler-epilog
1021 } define-sub-primitives
1023 [ "bootstrap.arm.64" forget-vocab ] with-compilation-unit