]> gitweb.factorcode.org Git - factor.git/commitdiff
arm64: moving things around
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 18 Feb 2021 20:51:06 +0000 (14:51 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 26 Mar 2021 23:11:03 +0000 (18:11 -0500)
basis/bootstrap/assembler/arm.64.factor
basis/bootstrap/assembler/arm.64.unix.factor

index 754f5c90347bc39e9ebbaaf84af5e184978de501..6ce07538092ccbfbe618967eb972ec63a928042f 100644 (file)
@@ -12,6 +12,55 @@ IN: bootstrap.arm
 
 big-endian off
 
+! Stack frame
+! https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling?view=vs-2019
+
+! x0   Volatile        Parameter/scratch register 1, result register
+! x1-x7        Volatile        Parameter/scratch register 2-8
+! x8-x15       Volatile        Scratch registers
+! x16-x17      Volatile        Intra-procedure-call scratch registers
+! x18  Non-volatile    Platform register: in kernel mode, points to KPCR for the current processor;
+!   in user mode, points to TEB
+! x19-x28      Non-volatile    Scratch registers
+! x29/fp       Non-volatile    Frame pointer
+! x30/lr       Non-volatile    Link registers
+
+: stack-frame-size ( -- n ) 4 bootstrap-cells ;
+: volatile-regs ( -- seq ) { X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 } ;
+: nv-regs ( -- seq ) { X18 X19 X20 X21 X22 X23 X24 X25 X26 X27 X28 X29 X30 } ;
+
+! callee-save = non-volatile aka call-preserved
+
+! x30 is the link register (used to return from subroutines)
+! x29 is the frame register
+! x19 to x29 are callee-saved
+! x18 is the 'platform register', used for some operating-system-specific special purpose,
+!   or an additional caller-saved register
+! x16 and x17 are the Intra-Procedure-call scratch register
+! x9 to x15: used to hold local variables (caller saved)
+! x8: used to hold indirect return value address
+! x0 to x7: used to hold argument values passed to a subroutine, and also hold
+!   results returned from a subroutine
+
+
+! https://en.wikichip.org/wiki/arm/aarch64
+! Generally, X0 through X18 can corrupt while X19-X29 must be preserved
+! Register   Role    Requirement
+! X0 -  X7   Parameter/result registers   Can Corrupt
+! X8         Indirect result location register
+! X9 -  X15  Temporary registers
+! X16 - X17  Intra-procedure call temporary
+! X18        Platform register, otherwise temporary
+
+! X19 - X29    Callee-saved register    Must preserve
+! X30    Link Register    Can Corrupt
+
+: arg1 ( -- reg ) X0 ;
+: arg2 ( -- reg ) X1 ;
+: arg3 ( -- reg ) X2 ;
+: arg4 ( -- reg ) X3 ;
+: red-zone-size ( -- n ) 16 ;
+
 : shift-arg ( -- reg ) X1 ;
 : div-arg ( -- reg ) X0 ;
 : mod-arg ( -- reg ) X2 ;
@@ -38,15 +87,24 @@ big-endian off
 ! : fixnum>slot@ ( -- ) temp0 1 SAR ;
 ! : rex-length ( -- n ) 1 ;
 
-: jit-call ( name -- ) drop ;
+! rc-absolute-cell is just CONSTANT: 0
+: jit-call ( name -- )
+    ! 0 X0 MOVwi64
+    f rc-absolute-cell rel-dlsym
+    X0 BR ;
     ! RAX 0 MOV f rc-absolute-cell rel-dlsym
     ! RAX CALL ;
 
-:: jit-call-1arg ( arg1s name -- ) 2drop ;
-    ! arg1 arg1s MOV
+:: jit-call-1arg ( arg1s name -- )
+    arg1s arg1 MOVr64
+    name jit-call ;
+    ! arg1 arg1s MOVr64
     ! name jit-call ;
 
 :: jit-call-2arg ( arg1s arg2s name -- ) 3drop ;
+    arg1s arg1 MOVr64
+    arg2s arg2 MOVr64
+    name jit-call ;
     ! arg1 arg1s MOV
     ! arg2 arg2s MOV
     ! name jit-call ;
@@ -227,8 +285,20 @@ big-endian off
     ! { (start-context-and-delete) [ jit-start-context-and-delete ] }
 
     ! ## Entry points
-    { c-to-factor [    ] }
-    { unwind-native-frames [ ] }
+    { c-to-factor [
+        ! arg2 arg1 MOV
+        ! vm-reg "begin_callback" jit-call-1arg
+
+        ! ! call the quotation
+        ! arg1 return-reg MOV
+        ! jit-call-quot
+
+        ! vm-reg "end_callback" jit-call-1arg
+
+        BL
+
+    ] }
+    ! { unwind-native-frames [ ] }
 
     ! ## Math
     ! { fixnum+ [ [ ADD ] "overflow_fixnum_add" jit-overflow ] }
index 635d942b658b905b57a9be527a6649fd0bdc5c80..0e4504d1523f079d5d4116564f8fd0b69fb74dee 100644 (file)
@@ -4,57 +4,6 @@ USING: cpu.arm.assembler cpu.arm.assembler.opcodes kernel layouts
 parser sequences ;
 IN: bootstrap.arm
 
-! Stack frame
-! https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling?view=vs-2019
-
-
-! x0   Volatile        Parameter/scratch register 1, result register
-! x1-x7        Volatile        Parameter/scratch register 2-8
-! x8-x15       Volatile        Scratch registers
-! x16-x17      Volatile        Intra-procedure-call scratch registers
-! x18  Non-volatile    Platform register: in kernel mode, points to KPCR for the current processor;
-!   in user mode, points to TEB
-! x19-x28      Non-volatile    Scratch registers
-! x29/fp       Non-volatile    Frame pointer
-! x30/lr       Non-volatile    Link registers
-
-
-: stack-frame-size ( -- n ) 4 bootstrap-cells ;
-: volatile-regs ( -- seq ) { X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 } ;
-: nv-regs ( -- seq ) { X18 X19 X20 X21 X22 X23 X24 X25 X26 X27 X28 X29 X30 } ;
-
-
-! callee-save = non-volatile aka call-preserved
-
-! x30 is the link register (used to return from subroutines)
-! x29 is the frame register
-! x19 to x29 are callee-saved
-! x18 is the 'platform register', used for some operating-system-specific special purpose,
-!   or an additional caller-saved register
-! x16 and x17 are the Intra-Procedure-call scratch register
-! x9 to x15: used to hold local variables (caller saved)
-! x8: used to hold indirect return value address
-! x0 to x7: used to hold argument values passed to a subroutine, and also hold
-!   results returned from a subroutine
-
-
-! https://en.wikichip.org/wiki/arm/aarch64
-! Generally, X0 through X18 can corrupt while X19-X29 must be preserved
-! Register   Role    Requirement
-! X0 -  X7   Parameter/result registers   Can Corrupt
-! X8         Indirect result location register
-! X9 -  X15  Temporary registers
-! X16 - X17  Intra-procedure call temporary
-! X18        Platform register, otherwise temporary
-
-! X19 - X29    Callee-saved register    Must preserve
-! X30    Link Register    Can Corrupt
-
-: arg1 ( -- reg ) X0 ;
-: arg2 ( -- reg ) X1 ;
-: arg3 ( -- reg ) X2 ;
-: arg4 ( -- reg ) X3 ;
-: red-zone-size ( -- n ) 16 ;
 
 << "vocab:bootstrap/assembler/arm.unix.factor" parse-file suffix! >> call
 << "vocab:bootstrap/assembler/arm.64.factor" parse-file suffix! >> call