]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/cpu/x86/32/bootstrap.factor
use radix literals
[factor.git] / basis / cpu / x86 / 32 / bootstrap.factor
index 184c0e6b3346798bd89343521929a5bebbb7e9f7..a3edd70ffb43f9df3ebcc8536655c9d8191bb8d7 100755 (executable)
@@ -4,7 +4,7 @@ USING: bootstrap.image.private kernel kernel.private namespaces
 system cpu.x86.assembler cpu.x86.assembler.operands layouts
 vocabs parser compiler.constants compiler.codegen.relocation
 sequences math math.private generic.single.private
-threads.private ;
+threads.private locals ;
 IN: bootstrap.x86
 
 4 \ cell set
@@ -23,23 +23,25 @@ IN: bootstrap.x86
 : vm-reg ( -- reg ) EBX ;
 : ctx-reg ( -- reg ) EBP ;
 : nv-regs ( -- seq ) { ESI EDI EBX } ;
+: volatile-regs ( -- seq ) { EAX ECX EDX } ;
 : nv-reg ( -- reg ) ESI ;
 : ds-reg ( -- reg ) ESI ;
 : rs-reg ( -- reg ) EDI ;
 : link-reg ( -- reg ) EBX ;
 : fixnum>slot@ ( -- ) temp0 2 SAR ;
 : rex-length ( -- n ) 0 ;
+: red-zone-size ( -- n ) 0 ;
 
 : jit-call ( name -- )
     0 CALL f rc-relative rel-dlsym ;
 
 [
-    ! save stack frame size
-    stack-frame-size PUSH
-    ! push entry point
-    0 PUSH rc-absolute-cell rel-this
     ! alignment
-    ESP stack-frame-size 3 bootstrap-cells - SUB
+    ESP stack-frame-size bootstrap-cell - SUB
+    ! store entry point
+    ESP stack-frame-size 3 bootstrap-cells - [+] 0 MOV rc-absolute-cell rel-this
+    ! store stack frame size
+    ESP stack-frame-size 2 bootstrap-cells - [+] stack-frame-size MOV
 ] jit-prolog jit-define
 
 [
@@ -96,6 +98,40 @@ IN: bootstrap.x86
     "end_callback" jit-call
 ] \ c-to-factor define-sub-primitive
 
+! The signal-handler and leaf-signal-handler subprimitives are special-cased
+! in vm/quotations.cpp not to trigger generation of a stack frame, so they can
+! peform their own prolog/epilog preserving registers.
+
+:: jit-signal-handler-prolog ( -- frame-size )
+    stack-frame-size 8 bootstrap-cells + :> frame-size
+    ! minus a cell each for flags and return address
+    ! use LEA so we don't dirty flags
+    ESP ESP frame-size 2 bootstrap-cells - neg [+] LEA
+    ESP []                    EAX MOV
+    ESP 1 bootstrap-cells [+] ECX MOV
+    ESP 2 bootstrap-cells [+] EDX MOV
+    ESP 3 bootstrap-cells [+] EBX MOV
+    ESP 4 bootstrap-cells [+] EBP MOV
+    ESP 5 bootstrap-cells [+] ESI MOV
+    ESP 6 bootstrap-cells [+] EDI MOV
+    PUSHF
+    ESP frame-size 3 bootstrap-cells - [+] 0 MOV rc-absolute-cell rel-this
+    ESP frame-size 2 bootstrap-cells - [+] frame-size MOV
+    ! subprimitive definition assumes vm's been loaded
+    jit-load-vm
+    frame-size ;
+
+:: jit-signal-handler-epilog ( frame-size -- )
+    POPF
+    EAX ESP []                    MOV
+    ECX ESP 1 bootstrap-cells [+] MOV
+    EDX ESP 2 bootstrap-cells [+] MOV
+    EBX ESP 3 bootstrap-cells [+] MOV
+    EBP ESP 4 bootstrap-cells [+] MOV
+    ESI ESP 5 bootstrap-cells [+] MOV
+    EDI ESP 6 bootstrap-cells [+] MOV
+    ESP ESP frame-size 2 bootstrap-cells - [+] LEA ;
+
 [
     EAX ds-reg [] MOV
     ds-reg bootstrap-cell SUB
@@ -110,6 +146,9 @@ IN: bootstrap.x86
     jit-load-context
     jit-restore-context
 
+    ! clear the fault flag
+    vm-reg vm-fault-flag-offset [+] 0 MOV
+
     ! Windows-specific setup
     ctx-reg jit-update-seh
 
@@ -178,7 +217,7 @@ IN: bootstrap.x86
 \ lazy-jit-compile define-combinator-primitive
 
 [
-    temp1 HEX: ffffffff CMP f rc-absolute-cell rel-literal
+    temp1 0xffffffff CMP f rc-absolute-cell rel-literal
 ] pic-check-tuple jit-define
 
 ! Inline cache miss entry points
@@ -359,8 +398,9 @@ IN: bootstrap.x86
     EAX EDX [] MOV
     jit-jump-quot ;
 
-: jit-safepoint ( -- )
-    0 EAX MOVABS rc-absolute rel-safepoint ;
+[
+    0 EAX MOVABS rc-absolute rel-safepoint
+] \ jit-safepoint jit-define
 
 [
     jit-start-context-and-delete