diff --git a/basis/cpu/x86/32/bootstrap.factor b/basis/cpu/x86/32/bootstrap.factor index 1f78c47740..2bb9eac877 100755 --- a/basis/cpu/x86/32/bootstrap.factor +++ b/basis/cpu/x86/32/bootstrap.factor @@ -91,39 +91,8 @@ 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 ) - signal-handler-stack-frame-size :> 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 ; +: signal-handler-save-regs ( -- regs ) + { EAX ECX EDX EBX EBP ESI EDI } ; [ EAX ds-reg [] MOV diff --git a/basis/cpu/x86/64/bootstrap.factor b/basis/cpu/x86/64/bootstrap.factor index b5de844f47..5fef6382a5 100755 --- a/basis/cpu/x86/64/bootstrap.factor +++ b/basis/cpu/x86/64/bootstrap.factor @@ -83,22 +83,6 @@ IN: bootstrap.x86 : 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 - signal-handler-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 - 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 diff --git a/basis/cpu/x86/64/unix/bootstrap.factor b/basis/cpu/x86/64/unix/bootstrap.factor index cf9415441a..c4abe962cf 100644 --- a/basis/cpu/x86/64/unix/bootstrap.factor +++ b/basis/cpu/x86/64/unix/bootstrap.factor @@ -6,7 +6,7 @@ sequences system vocabs ; IN: bootstrap.x86 : leaf-stack-frame-size ( -- n ) 2 bootstrap-cells ; -: signal-handler-stack-frame-size ( -- n ) 18 bootstrap-cells ; +: signal-handler-stack-frame-size ( -- n ) 20 bootstrap-cells ; : stack-frame-size ( -- n ) 4 bootstrap-cells ; : nv-regs ( -- seq ) { RBX R12 R13 R14 R15 } ; : volatile-regs ( -- seq ) { RAX RCX RDX RSI RDI R8 R9 R10 R11 } ; diff --git a/basis/cpu/x86/64/windows/bootstrap.factor b/basis/cpu/x86/64/windows/bootstrap.factor index a881225103..d622161f32 100644 --- a/basis/cpu/x86/64/windows/bootstrap.factor +++ b/basis/cpu/x86/64/windows/bootstrap.factor @@ -8,7 +8,7 @@ IN: bootstrap.x86 DEFER: stack-reg : leaf-stack-frame-size ( -- n ) 2 bootstrap-cells ; -: signal-handler-stack-frame-size ( -- n ) 22 bootstrap-cells ; +: signal-handler-stack-frame-size ( -- n ) 24 bootstrap-cells ; : stack-frame-size ( -- n ) 8 bootstrap-cells ; : nv-regs ( -- seq ) { RBX RSI RDI R12 R13 R14 R15 } ; : volatile-regs ( -- seq ) { RAX RCX RDX R8 R9 R10 R11 } ; diff --git a/basis/cpu/x86/bootstrap.factor b/basis/cpu/x86/bootstrap.factor index d09657f33c..42ea87a5be 100644 --- a/basis/cpu/x86/bootstrap.factor +++ b/basis/cpu/x86/bootstrap.factor @@ -93,38 +93,58 @@ big-endian off ! not to trigger generation of a stack frame, so they can ! peform their own prolog/epilog preserving registers. +: jit-signal-handler-prolog ( -- ) + ! minus a cell each for flags, return address + ! use LEA so we don't dirty flags + stack-reg stack-reg signal-handler-stack-frame-size + 2 bootstrap-cells - neg [+] LEA + + signal-handler-save-regs + [| r i | stack-reg i bootstrap-cells [+] r MOV ] each-index + + PUSHF ; + +: jit-signal-handler-epilog ( -- ) + POPF + + signal-handler-save-regs + [| r i | r stack-reg i bootstrap-cells [+] MOV ] each-index + + stack-reg stack-reg signal-handler-stack-frame-size + 2 bootstrap-cells - [+] LEA ; + [| | - jit-signal-handler-prolog :> frame-size + jit-signal-handler-prolog jit-save-context temp0 vm-reg vm-signal-handler-addr-offset [+] MOV temp0 CALL - frame-size jit-signal-handler-epilog + jit-signal-handler-epilog 0 RET ] \ signal-handler define-sub-primitive [| | - jit-signal-handler-prolog :> frame-size + jit-signal-handler-prolog jit-save-context temp0 vm-reg vm-signal-handler-addr-offset [+] MOV temp0 CALL - frame-size jit-signal-handler-epilog + jit-signal-handler-epilog ! Pop the fake leaf frame along with our return address leaf-stack-frame-size bootstrap-cell - RET ] \ leaf-signal-handler define-sub-primitive [| | - jit-signal-handler-prolog :> frame-size + jit-signal-handler-prolog temp0 vm-reg vm-signal-handler-addr-offset [+] MOV temp0 CALL - frame-size jit-signal-handler-epilog + jit-signal-handler-epilog red-zone-size RET ] \ ffi-signal-handler define-sub-primitive [| | - jit-signal-handler-prolog :> frame-size + jit-signal-handler-prolog temp0 vm-reg vm-signal-handler-addr-offset [+] MOV temp0 CALL - frame-size jit-signal-handler-epilog + jit-signal-handler-epilog red-zone-size 16 bootstrap-cell - + RET ] \ ffi-leaf-signal-handler define-sub-primitive diff --git a/vm/os-linux-x86.64.hpp b/vm/os-linux-x86.64.hpp index 022636012b..f0b1786071 100644 --- a/vm/os-linux-x86.64.hpp +++ b/vm/os-linux-x86.64.hpp @@ -31,7 +31,7 @@ inline static void uap_clear_fpu_status(void *uap) /* Must match the leaf-stack-frame-size, signal-handler-stack-frame-size, and stack-frame-size constants in basis/cpu/x86/64/unix/bootstrap.factor */ static const unsigned LEAF_FRAME_SIZE = 16; -static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 144; +static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 160; static const unsigned JIT_FRAME_SIZE = 32; } diff --git a/vm/os-macosx-x86.64.hpp b/vm/os-macosx-x86.64.hpp index 023dfec867..9a339881e6 100644 --- a/vm/os-macosx-x86.64.hpp +++ b/vm/os-macosx-x86.64.hpp @@ -76,7 +76,7 @@ inline static void uap_clear_fpu_status(void *uap) /* Must match the leaf-stack-frame-size, signal-handler-stack-frame-size, and stack-frame-size constants in basis/cpu/x86/64/unix/bootstrap.factor */ static const unsigned LEAF_FRAME_SIZE = 16; -static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 144; +static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 160; static const unsigned JIT_FRAME_SIZE = 32; } diff --git a/vm/os-windows.64.hpp b/vm/os-windows.64.hpp index d5171b089e..7dad29c6d2 100644 --- a/vm/os-windows.64.hpp +++ b/vm/os-windows.64.hpp @@ -12,6 +12,6 @@ namespace factor and stack-frame-size constants in basis/cpu/x86/64/windows/bootstrap.factor */ static const unsigned LEAF_FRAME_SIZE = 16; -static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 176; +static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 192; static const unsigned JIT_FRAME_SIZE = 64; }