@@ -380,21 +380,23 @@ EOF
380380 .seh_proc _sigfe_maybe
381381_sigfe_maybe: # stack is aligned on entry!
382382 .seh_endprologue
383+ ldr x10, [x18, #0x8]
3833840: ret
384385 .seh_endproc
385386
386387 .seh_proc _sigfe
387388_sigfe: # stack is aligned on entry!
388389 .seh_endprologue
389- ldr x9 , [sp], #0x10
390- br x9
390+ ldr x10 , [sp], #0x10
391+ br x10
391392 .seh_endproc
392393
393394 .global _sigbe
394395 .seh_proc _sigbe
395396_sigbe: # return here after cygwin syscall
396397 # stack is aligned on entry!
397398 .seh_endprologue
399+ ret
398400 .seh_endproc
399401
400402 .global sigdelayed
@@ -442,10 +444,10 @@ _ZN7_cygtls6lockedEv:
442444 .seh_proc stabilize_sig_stack
443445stabilize_sig_stack:
444446 // prologue
445- stp fp, lr, [sp, #-0x10]! // save registers
446- .seh_save_fplr_x 0x10
447- sub sp, sp, #0x20 // allocate 32 bytes on stack
448- .seh_stackalloc 0x20
447+ stp fp, lr, [sp, #-0x10]! // save FP and LR registers
448+ stp x9, x10, [sp, #- 0x10]! // save x9 and x10 registers used next
449+ stp x11, x12, [ sp, #-0x10]! // save x11 and x12 registers used next
450+ stp x13, x14, [sp, #-0x10]! // save x13 register used next and x14 just to keep stack orientation and alignment
449451 .seh_endprologue
450452
451453 ldr x10, [x18, #0x8] // get thread local storage pointer
@@ -499,10 +501,13 @@ stabilize_sig_stack:
499501 sub w9, w9, #1 // decrement incyg counter
500502 str w9, [x11]
501503
504+ mov x0, x10 // return TLS address in x0 (return value)
505+
502506 // epilogue
503- add sp, sp, #0x20 // restore stack
504- mov x1, x10 // return TLS address in x0 (return value)
505- ldp fp, lr, [sp], #0x10 // restore saved registers
507+ ldp x13, x14, [sp], #0x10
508+ ldp x11, x12, [sp], #0x10
509+ ldp x9, x10, [sp], #0x10
510+ ldp fp, lr, [sp], #0x10
506511 ret
507512 .seh_endproc
508513EOF
@@ -651,15 +656,23 @@ EOF
651656 .seh_proc sigsetjmp
652657sigsetjmp:
653658 // prologue
659+ stp fp, lr, [sp, #-0x10]! // save FP and LR registers
660+ mov fp, sp // set FP to current SP
661+ sub sp, sp, #0x20 // allocate 32 bytes on stack
654662 .seh_endprologue
655663
656- mov x0, 0
664+ bl setjmp
665+
666+ // epilogue
667+ ldp fp, lr, [sp], #0x10 // restore saved FP and LR registers
657668 ret
658669 .seh_endproc
659670
660671 .globl setjmp
661672 .seh_proc setjmp
662673setjmp:
674+ // prologue
675+ stp fp, lr, [sp, #-0x10]! // save FP and LR registers
663676 .seh_endprologue
664677
665678 // save callee-saved registers from jump buffer
@@ -668,8 +681,7 @@ setjmp:
668681 stp x23, x24, [x0, #0x28] // save x23 and x24
669682 stp x25, x26, [x0, #0x38] // save x25 and x26
670683 stp x27, x28, [x0, #0x48] // save x27 and x28
671- str x29, [x0, #0x58] // save x29 (frame pointer)
672- str x30, [x0, #0x60] // save x30 (link register)
684+ stp x29, x30, [x0, #0x58] // save x29 (frame pointer) and x30 (link register)
673685 mov x1, sp // get the current stack pointer
674686 str x1, [x0, #0x68] // save SP
675687 mrs x1, fpsr // get floating-point status register
@@ -683,93 +695,103 @@ setjmp:
683695 stp q4, q5, [x0, #0xC0]
684696 stp q6, q7, [x0, #0xE0]
685697
686- bl stabilize_sig_stack // call stabilize_sig_stack (returns TLS in x1 )
698+ bl stabilize_sig_stack // call stabilize_sig_stack (returns TLS in x0 )
687699
688700 // store the stack pointer to ...
689701 ldr x2, =_cygtls.stackptr
690- add x2, x1 , x2
691- ldr x2 , [x2]
702+ add x2, x0 , x2
703+ ldr x3 , [x2]
692704 // TODO: Save the value somewhere.
693705
694706 // decrement the stack lock
695707 ldr x2, =_cygtls.stacklock
696- add x2, x1 , x2
697- ldr w2 , [x2]
698- sub w2, w2 , #1
699- str w2 , [x2]
708+ add x2, x0 , x2
709+ ldr w3 , [x2]
710+ sub w3, w3 , #1
711+ str w3 , [x2]
700712
701713 mov w0, #0 // return 0
702714
703715 // epilogue
716+ ldp fp, lr, [sp], #0x10 // restore saved FP and LR registers
704717 ret
705718 .seh_endproc
706719
707720 .globl siglongjmp
708721 .seh_proc siglongjmp
709722siglongjmp:
723+ // prologue
724+ stp fp, lr, [sp, #-0x10]! // save FP and LR registers
725+ mov fp, sp // set FP to current SP
726+ sub sp, sp, #32 // allocate 32 bytes on stack
710727 .seh_endprologue
728+
729+ bl longjmp
730+
731+ // epilogue
732+ ldp fp, lr, [sp], #0x10 // restore saved FP and LR registers
711733 ret
712734 .seh_endproc
713735
714736 .globl longjmp
715737 .seh_proc longjmp
716738longjmp:
717739 // prologue
718- stp fp, lr, [sp, #-0x20]! // save FP and LR registers
719- mov fp, sp // set FP to current SP
720- sub sp, sp, #0x20 // allocate 32 bytes on stack
721- .seh_stackalloc 0x20
740+ stp fp, lr, [sp, #-0x20]! // save FP and LR registers, allocate additional 16 bytes for function arguments
741+ stp x0, x1, [sp, #0x10] // save function arguments (jump buffer and return value)
742+ mov fp, sp // establishing frame chain
722743 .seh_endprologue
723-
724- mov w19, w1 // save the return value
7257441:
726- bl stabilize_sig_stack // call stabilize_sig_stack which returns TLS pointer in x1
727- mov w0, w19 // restore return value to w0 (ARM64 return register)
728- ldr x10, [x0 ] // get old signal stack from jump buffer
745+ bl stabilize_sig_stack // call stabilize_sig_stack which returns TLS pointer in x0
746+ ldr x2, [sp, #0x10] // get jump buffer pointer from stack
747+ ldr x10, [x2 ] // get old signal stack from jump buffer
729748
730749 // restore stack pointer in TLS
731750 ldr x11, =_cygtls.stackptr
732- add x11, x1 , x11
751+ add x11, x0 , x11
733752 str x10, [x11]
734753
735754 // release lock by decrementing counter
736755 ldr x11, =_cygtls.stacklock
737- add x11, x1 , x11
756+ add x11, x0 , x11
738757 ldr w12, [x11]
739758 sub w12, w12, #1
740759 str w12, [x11]
741760
742761 // we're not in cygwin anymore, clear "in cygwin" flag
743762 ldr x11, =_cygtls.incyg
744- add x11, x1 , x11
763+ add x11, x0 , x11
745764 mov w12, #0
746765 str w12, [x11]
747766
767+ // get saved return value before SP is restored
768+ ldr x0, [sp, #0x10]
769+
748770 // restore callee-saved registers from jump buffer
749- ldp x19, x20, [x0, #0x08] // restore x19, x20
750- ldp x21, x22, [x0, #0x18] // restore x21, x22
751- ldp x23, x24, [x0, #0x28] // restore x23, x24
752- ldp x25, x26, [x0, #0x38] // restore x25, x26
753- ldp x27, x28, [x0, #0x48] // restore x27, x28
754- ldp x29, x30, [x0, #0x58] // restore x29 (frame pointer) and x30 (link register)
755- ldr x9, [x0, #0x68] // get saved stack pointer
756- ldr x10, [x0, #0x70] // load floating-point status register
771+ ldp x19, x20, [x2, #0x08] // restore x19, x20
772+ ldp x21, x22, [x2, #0x18] // restore x21, x22
773+ ldp x23, x24, [x2, #0x28] // restore x23, x24
774+ ldp x25, x26, [x2, #0x38] // restore x25, x26
775+ ldp x27, x28, [x2, #0x48] // restore x27, x28
776+ ldp x29, x30, [x2, #0x58] // restore x29 (frame pointer) and x30 (link register)
777+ ldr x10, [x2, #0x68] // get saved stack pointer
778+ mov sp, x10 // restore stack pointer
779+ ldr x10, [x2, #0x70] // load floating-point status register
757780 msr fpsr, x10 // restore FPSR
758- ldr x10, [x0 , #0x78] // load floating-point control register
781+ ldr x10, [x2 , #0x78] // load floating-point control register
759782 msr fpcr, x10 // restore FPCR
760783
761784 // restore SIMD registers
762- ldp q0, q1, [x0 , #0x80]
763- ldp q2, q3, [x0 , #0xA0]
764- ldp q4, q5, [x0 , #0xC0]
765- ldp q6, q7, [x0 , #0xE0]
785+ ldp q0, q1, [x2 , #0x80]
786+ ldp q2, q3, [x2 , #0xA0]
787+ ldp q4, q5, [x2 , #0xC0]
788+ ldp q6, q7, [x2 , #0xE0]
766789
767790 // ensure return value is non-zero (C standard requirement)
768- cbnz w0 , 0f
769- mov w0 , #1
791+ cbnz x0 , 0f
792+ mov x0 , #1
7707930:
771- // epilogue
772- ldp fp, lr, [sp], #0x10 // restore saved FP and LR registers
794+ // epilogue is empty as FP and LR are already restored
773795 ret
774796 .seh_endproc
775797EOF
0 commit comments