]> gitweb.factorcode.org Git - factor.git/commitdiff
Store stack bounds in TIB on win64 to make C++ exceptions work
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 5 Apr 2010 23:06:51 +0000 (19:06 -0400)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 5 Apr 2010 23:07:10 +0000 (19:07 -0400)
Nmakefile
basis/cpu/x86/32/bootstrap.factor
basis/cpu/x86/32/unix/bootstrap.factor
basis/cpu/x86/32/winnt/bootstrap.factor
basis/cpu/x86/64/bootstrap.factor
basis/cpu/x86/64/unix/bootstrap.factor
basis/cpu/x86/64/winnt/bootstrap.factor
basis/cpu/x86/unix/bootstrap.factor [new file with mode: 0644]
basis/cpu/x86/winnt/bootstrap.factor [new file with mode: 0644]

index dc28e1884cdec4b1f44782fd91f614e0ba8d62f6..02d2b5f1ed413405a1a6eef81b4f616cace367c5 100755 (executable)
--- a/Nmakefile
+++ b/Nmakefile
@@ -1,5 +1,5 @@
 !IF DEFINED(DEBUG)
-LINK_FLAGS = /nologo /DEBUG shell32.lib
+LINK_FLAGS = /nologo /safeseh /DEBUG shell32.lib
 CL_FLAGS = /nologo /Zi /O2 /W3 /DFACTOR_DEBUG
 !ELSE
 LINK_FLAGS = /nologo /safeseh shell32.lib
index 9b1a1de23dc6de804065ebc9dbee4909cd071473..b2cd241df1de6d47ab014faa1f4e14999e7d8591 100644 (file)
@@ -330,6 +330,3 @@ IN: bootstrap.x86
     jit-delete-current-context
     jit-start-context
 ] \ (start-context-and-delete) define-sub-primitive
-
-<< "vocab:cpu/x86/bootstrap.factor" parse-file suffix! >>
-call
index 1e3bee4961a18dd6b6c7aba387e1d883a38202cf..56d18511e43892a5f841271ab53df17896ca5ad3 100644 (file)
@@ -1,14 +1,8 @@
 ! Copyright (C) 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: cpu.x86.assembler cpu.x86.assembler.operands kernel
-layouts parser sequences ;
+USING: kernel parser sequences ;
 IN: bootstrap.x86
 
-: jit-save-tib ( -- ) ;
-: jit-restore-tib ( -- ) ;
-: jit-update-tib ( ctx-reg -- ) drop ;
-: jit-install-seh ( -- ) ESP bootstrap-cell ADD ;
-: jit-update-seh ( ctx-reg -- ) drop ;
-
-<< "vocab:cpu/x86/32/bootstrap.factor" parse-file suffix! >>
-call
+<< "vocab:cpu/x86/unix/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
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
index 69734df225140c3ebc6e82728b043eab245d103f..68c3d8b7025dc7a89322ca62262f8d4091729d52 100644 (file)
@@ -26,11 +26,6 @@ IN: bootstrap.x86
 : fixnum>slot@ ( -- ) temp0 1 SAR ;
 : rex-length ( -- n ) 1 ;
 
-: jit-save-tib ( -- ) ;
-: jit-restore-tib ( -- ) ;
-: jit-update-tib ( ctx-reg -- ) drop ;
-: jit-install-seh ( -- ) stack-reg bootstrap-cell ADD ;
-
 : jit-call ( name -- )
     RAX 0 MOV rc-absolute-cell jit-dlsym
     RAX CALL ;
@@ -238,7 +233,9 @@ IN: bootstrap.x86
     RSP ctx-reg context-callstack-top-offset [+] MOV
 
     ! Load new ds, rs registers
-    jit-restore-context ;
+    jit-restore-context
+
+    ctx-reg jit-update-tib ;
 
 : jit-pop-context-and-param ( -- )
     arg1 ds-reg [] MOV
@@ -293,6 +290,3 @@ IN: bootstrap.x86
     jit-delete-current-context
     jit-start-context
 ] \ (start-context-and-delete) define-sub-primitive
-
-<< "vocab:cpu/x86/bootstrap.factor" parse-file suffix! >>
-call
index d19b5306a0ea8bf2514609148fec95b72b821653..cffb12902c3088ae05dbbd0461d25bb9c3d18379 100644 (file)
@@ -12,5 +12,6 @@ IN: bootstrap.x86
 : arg3 ( -- reg ) RDX ;
 : arg4 ( -- reg ) RCX ;
 
-<< "vocab:cpu/x86/64/bootstrap.factor" parse-file suffix! >>
-call
+<< "vocab:cpu/x86/unix/bootstrap.factor" parse-file suffix! >> call
+<< "vocab:cpu/x86/64/bootstrap.factor" parse-file suffix! >> call
+<< "vocab:cpu/x86/bootstrap.factor" parse-file suffix! >> call
index 113a13918f1f84bd04c4cfda4e6372624acf8768..f816980e57121fa207fd91a92bb9a6b2f78a10b9 100644 (file)
@@ -5,6 +5,8 @@ vocabs sequences cpu.x86.assembler parser
 cpu.x86.assembler.operands ;
 IN: bootstrap.x86
 
+DEFER: stack-reg
+
 : stack-frame-size ( -- n ) 8 bootstrap-cells ;
 : nv-regs ( -- seq ) { RBX RSI RDI R12 R13 R14 R15 } ;
 : arg1 ( -- reg ) RCX ;
@@ -12,5 +14,12 @@ IN: bootstrap.x86
 : arg3 ( -- reg ) R8 ;
 : arg4 ( -- reg ) R9 ;
 
-<< "vocab:cpu/x86/64/bootstrap.factor" parse-file suffix! >>
-call
+: tib-segment ( -- ) GS ;
+: tib-temp ( -- reg ) R11 ;
+
+: jit-install-seh ( -- ) stack-reg bootstrap-cell ADD ;
+: jit-update-seh ( ctx-reg -- ) drop ;
+
+<< "vocab:cpu/x86/winnt/bootstrap.factor" parse-file suffix! >> call
+<< "vocab:cpu/x86/64/bootstrap.factor" parse-file suffix! >> call
+<< "vocab:cpu/x86/bootstrap.factor" parse-file suffix! >> call
diff --git a/basis/cpu/x86/unix/bootstrap.factor b/basis/cpu/x86/unix/bootstrap.factor
new file mode 100644 (file)
index 0000000..20dd738
--- /dev/null
@@ -0,0 +1,13 @@
+! Copyright (C) 2010 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: cpu.x86.assembler cpu.x86.assembler.operands kernel
+layouts ;
+IN: bootstrap.x86
+
+DEFER: stack-reg
+
+: jit-save-tib ( -- ) ;
+: jit-restore-tib ( -- ) ;
+: jit-update-tib ( ctx-reg -- ) drop ;
+: jit-install-seh ( -- ) stack-reg bootstrap-cell ADD ;
+: jit-update-seh ( ctx-reg -- ) drop ;
diff --git a/basis/cpu/x86/winnt/bootstrap.factor b/basis/cpu/x86/winnt/bootstrap.factor
new file mode 100644 (file)
index 0000000..b81c1eb
--- /dev/null
@@ -0,0 +1,32 @@
+! Copyright (C) 2010 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: bootstrap.image.private compiler.constants
+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 ;
+
+: jit-save-tib ( -- )
+    tib-exception-list-offset [] tib-segment PUSH
+    tib-stack-base-offset [] tib-segment PUSH
+    tib-stack-limit-offset [] tib-segment PUSH ;
+
+: jit-restore-tib ( -- )
+    tib-stack-limit-offset [] tib-segment POP
+    tib-stack-base-offset [] tib-segment POP
+    tib-exception-list-offset [] tib-segment POP ;
+
+:: jit-update-tib ( ctx-reg -- )
+    ! There's a redundant load here because we're not allowed
+    ! to clobber ctx-reg. Clobbers tib-temp.
+    ! Save callstack base in TIB
+    tib-temp ctx-reg context-callstack-seg-offset [+] MOV
+    tib-temp tib-temp segment-end-offset [+] MOV
+    tib-stack-base-offset [] tib-temp tib-segment MOV
+    ! Save callstack limit in TIB
+    tib-temp ctx-reg context-callstack-seg-offset [+] MOV
+    tib-temp tib-temp segment-start-offset [+] MOV
+    tib-stack-limit-offset [] tib-temp tib-segment MOV ;