1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/libc/x64/setjmp.S
2016-06-13 13:04:54 +02:00

97 lines
2.4 KiB
ArmAsm

/*
* Copyright (c) 2013, 2014 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* x64/setjmp.S
* Implement the assembly part of setjmp.
*/
#define SIG_SETMASK 2
/*
* sigjmp_buf[0] = %rbx
* sigjmp_buf[1] = %rsp
* sigjmp_buf[2] = %rbp
* sigjmp_buf[3] = %r12
* sigjmp_buf[4] = %r13
* sigjmp_buf[5] = %r14
* sigjmp_buf[6] = %r15
* sigjmp_buf[7] = <return-address>
* sigjmp_buf[8] = <non-zero if sigmask saved>
* sigjmp_buf[9...] = <saved sigmask if sigjmp_buf[8] != 0>
*/
.global setjmp
.type setjmp, @function
setjmp:
movl $1, %esi # setjmp saves the signal mask on Sortix
jmp 1f
.size setjmp, . - setjmp
.global sigsetjmp
.type sigsetjmp, @function
sigsetjmp:
mov %esi, %esi # clear upper 32-bit bits
testl %esi, %esi
jz 2f
1: push %rdi
push %rsi
lea (9 * 8)(%rdi), %rdx # oldset
xor %esi, %esi # set
xor %edi, %edi # how (ignored because set is NULL)
mov $sigprocmask, %rax # assumes sigprocmask is per-thread on Sortix
int $0x90
pop %rsi
pop %rdi
2: mov %rbx, (0 * 8)(%rdi)
mov %rsp, %rdx
add $8, %rdx
mov %rdx, (1 * 8)(%rdi)
mov %rbp, (2 * 8)(%rdi)
mov %r12, (3 * 8)(%rdi)
mov %r13, (4 * 8)(%rdi)
mov %r14, (5 * 8)(%rdi)
mov %r15, (6 * 8)(%rdi)
mov %rsi, (8 * 8)(%rdi)
int $0x94
xorl %eax, %eax
int $0x91
.size sigsetjmp, . - sigsetjmp
.global longjmp
.type longjmp, @function
longjmp:
jmp siglongjmp
.size longjmp, . - longjmp
.global siglongjmp
.type siglongjmp, @function
siglongjmp:
testl %esi, %esi
jnz 1f
movl $1, %esi
1: movq (8 * 8)(%rdi), %rdx
testq %rdx, %rdx
jz 2f
pushq %rdi
pushq %rsi
leaq (9 * 8)(%rdi), %rsi # set
movl $SIG_SETMASK, %edi # how
xorl %edx, %edx # oldset
mov $sigprocmask, %rax
int $0x90
popq %rsi
popq %rdi
2: int $0x95
.size siglongjmp, . - siglongjmp