]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/cpu/x86/64/bootstrap.factor
use radix literals
[factor.git] / basis / cpu / x86 / 64 / bootstrap.factor
index 5191f3993c8084e014da830c77ded5da3ab9285b..8ed80af2c694c530c681f019333adc5143b899c5 100755 (executable)
@@ -4,7 +4,7 @@ USING: bootstrap.image.private kernel kernel.private namespaces
 system layouts vocabs parser compiler.constants
 compiler.codegen.relocation math math.private cpu.x86.assembler
 cpu.x86.assembler.operands sequences generic.single.private
-threads.private ;
+threads.private locals ;
 IN: bootstrap.x86
 
 8 \ cell set
@@ -36,12 +36,12 @@ IN: bootstrap.x86
 [
     ! load entry point
     RAX 0 MOV rc-absolute-cell rel-this
-    ! save stack frame size
-    stack-frame-size PUSH
-    ! push entry point
-    RAX PUSH
     ! alignment
-    RSP stack-frame-size 3 bootstrap-cells - SUB
+    RSP stack-frame-size bootstrap-cell - SUB
+    ! store entry point
+    RSP stack-frame-size 3 bootstrap-cells - [+] RAX MOV
+    ! store stack frame size
+    RSP stack-frame-size 2 bootstrap-cells - [+] stack-frame-size MOV
 ] jit-prolog jit-define
 
 [
@@ -91,6 +91,29 @@ IN: bootstrap.x86
     "end_callback" jit-call
 ] \ c-to-factor define-sub-primitive
 
+: signal-handler-save-regs ( -- regs )
+    { RAX RCX RDX RBX RBP RSI RDI R8 R9 R10 R11 R12 R13 R14 R15 } ;
+
+:: jit-signal-handler-prolog ( -- frame-size )
+    signal-handler-save-regs :> save-regs
+    save-regs length 1 + bootstrap-cells 16 align stack-frame-size + :> frame-size
+    ! minus a cell each for flags, return address
+    ! use LEA so we don't dirty flags
+    RSP RSP frame-size 2 bootstrap-cells - neg [+] LEA
+    save-regs [| r i | RSP i bootstrap-cells [+] r MOV ] each-index
+    PUSHF
+    ! Now that the registers are saved, we can make the stack frame
+    RAX 0 MOV rc-absolute-cell rel-this
+    RSP frame-size 3 bootstrap-cells - [+] RAX MOV
+    RSP frame-size 2 bootstrap-cells - [+] frame-size MOV
+    frame-size ;
+
+:: jit-signal-handler-epilog ( frame-size -- )
+    POPF
+    signal-handler-save-regs
+    [| r i | r RSP i bootstrap-cells [+] MOV ] each-index
+    RSP RSP frame-size 2 bootstrap-cells - [+] LEA ;
+
 [
     arg1 ds-reg [] MOV
     ds-reg bootstrap-cell SUB
@@ -111,6 +134,9 @@ IN: bootstrap.x86
     jit-load-context
     jit-restore-context
 
+    ! Clear the fault flag
+    vm-reg vm-fault-flag-offset [+] 0 MOV
+
     ! Call quotation
     jit-jump-quot
 ] \ unwind-native-frames define-sub-primitive
@@ -167,7 +193,7 @@ IN: bootstrap.x86
 \ lazy-jit-compile define-combinator-primitive
 
 [
-    temp2 HEX: ffffffff MOV f rc-absolute-cell rel-literal
+    temp2 0xffffffff MOV f rc-absolute-cell rel-literal
     temp1 temp2 CMP
 ] pic-check-tuple jit-define
 
@@ -313,8 +339,9 @@ IN: bootstrap.x86
     jit-push-param
     jit-jump-quot ;
 
-: jit-safepoint ( -- )
-    0 [RIP+] EAX MOV rc-relative rel-safepoint ;
+[
+    0 [RIP+] EAX MOV rc-relative rel-safepoint
+] \ jit-safepoint jit-define
 
 [
     jit-start-context-and-delete