]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/cpu/x86/32/winnt/bootstrap.factor
Store stack bounds in TIB on win64 to make C++ exceptions work
[factor.git] / basis / cpu / x86 / 32 / winnt / bootstrap.factor
index b8ee1dacafb65f5d066ddd025f8046e0bcdc4164..5628632e6cf03427bb69d621322055845df159cc 100644 (file)
@@ -5,50 +5,32 @@ cpu.x86.assembler cpu.x86.assembler.operands kernel layouts
 locals parser sequences ;
 IN: bootstrap.x86
 
-: tib-exception-list-offset ( -- n ) 0 bootstrap-cells ;
-: tib-stack-base-offset ( -- n ) 1 bootstrap-cells ;
-: tib-stack-limit-offset ( -- n ) 2 bootstrap-cells ;
+: tib-segment ( -- ) FS ;
+: tib-temp ( -- reg ) EAX ;
 
-: jit-save-tib ( -- )
-    tib-exception-list-offset [] FS PUSH
-    tib-stack-base-offset [] FS PUSH
-    tib-stack-limit-offset [] FS PUSH ;
-
-: jit-restore-tib ( -- )
-    tib-stack-limit-offset [] FS POP
-    tib-stack-base-offset [] FS POP
-    tib-exception-list-offset [] FS POP ;
-
-:: jit-update-tib ( ctx-reg -- )
-    ! There's a redundant load here because we're not allowed
-    ! to clobber ctx-reg. Clobbers EAX.
-    ! Save callstack base in TIB
-    EAX ctx-reg context-callstack-seg-offset [+] MOV
-    EAX EAX segment-end-offset [+] MOV
-    tib-stack-base-offset [] EAX FS MOV
-    ! Save callstack limit in TIB
-    EAX ctx-reg context-callstack-seg-offset [+] MOV
-    EAX EAX segment-start-offset [+] MOV
-    tib-stack-limit-offset [] EAX FS MOV ;
+<< "vocab:cpu/x86/winnt/bootstrap.factor" parse-file suffix! >> call
 
 : jit-install-seh ( -- )
     ! Create a new exception record and store it in the TIB.
+    ! Clobbers tib-temp.
     ! Align stack
     ESP 3 bootstrap-cells ADD
     ! Exception handler address filled in by callback.cpp
-    0 PUSH rc-absolute-cell rt-exception-handler jit-rel
+    tib-temp 0 MOV rc-absolute-cell rt-exception-handler jit-rel
+    tib-temp PUSH
     ! No next handler
     0 PUSH
     ! This is the new exception handler
-    tib-exception-list-offset [] ESP FS MOV ;
+    tib-exception-list-offset [] ESP tib-segment MOV ;
 
 :: jit-update-seh ( ctx-reg -- )
     ! Load exception record structure that jit-install-seh
-    ! created from the bottom of the callstack. Clobbers EAX.
-    EAX ctx-reg context-callstack-bottom-offset [+] MOV
-    EAX bootstrap-cell ADD
+    ! created from the bottom of the callstack.
+    ! Clobbers tib-temp.
+    tib-temp ctx-reg context-callstack-bottom-offset [+] MOV
+    tib-temp bootstrap-cell ADD
     ! Store exception record in TIB.
-    tib-exception-list-offset [] EAX FS MOV ;
+    tib-exception-list-offset [] tib-temp tib-segment MOV ;
 
-<< "vocab:cpu/x86/32/bootstrap.factor" parse-file suffix! >>
-call
+<< "vocab:cpu/x86/32/bootstrap.factor" parse-file suffix! >> call
+<< "vocab:cpu/x86/bootstrap.factor" parse-file suffix! >> call