]> git.saurik.com Git - apple/libc.git/blame - x86_64/sys/setjmp.s
Libc-391.5.22.tar.gz
[apple/libc.git] / x86_64 / sys / setjmp.s
CommitLineData
8e029c65
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
25 */
26/*
27 * NeXT 386 setjmp/longjmp
28 *
29 * Written by Bruce Martin, NeXT Inc. 4/9/92
30 */
31
32/*
33 * C library -- setjmp, longjmp
34 *
35 * longjmp(a,v)
36 * will generate a "return(v)" from
37 * the last call to
38 * setjmp(a)
39 * by restoring registers from the stack,
40 * The previous value of the signal mask is
41 * restored.
42 *
43 */
44
45#include <architecture/i386/asm_help.h>
46#include <SYS.h>
47
48#define JB_RBX 0
49#define JB_RBP 8
50#define JB_RSP 16
51#define JB_R12 24
52#define JB_R13 32
53#define JB_R14 40
54#define JB_R15 48
55#define JB_RIP 56
56#define JB_RFLAGS 64
57#define JB_MXCSR 72
58#define JB_FPCONTROL 76
59#define JB_MASK 80
60#define JB_SAVEMASK 84 // sigsetjmp/siglongjmp only
61
62
63LEAF(_sigsetjmp, 0)
64 // %rdi is sigjmp_buf * jmpbuf;
65 // %esi is int savemask
66 movl %esi, JB_SAVEMASK(%rdi) // jmpbuf[_JBLEN] = savemask;
67 cmpl $0, %esi // if savemask != 0
68 jne _setjmp // setjmp(jmpbuf);
69 jmp L_do__setjmp // else _setjmp(jmpbuf);
70
71LEAF(_setjmp, 0)
72 pushq %rdi // Preserve the jmp_buf across the call
73 movl $1, %edi // how = SIG_BLOCK
74 xorq %rsi, %rsi // set = NULL
75 subq $8, %rsp // Allocate space for the return from sigprocmask
76 movq %rsp, %rdx
77 CALL_EXTERN(_sigprocmask)
78 popq %rax // Save the mask
79 popq %rdi // jmp_buf (struct sigcontext *)
80 movq %rax, JB_MASK(%rdi)
81L_do__setjmp:
82 BRANCH_EXTERN(__setjmp)
83
84LEAF(_siglongjmp, 0)
85 // %rdi is sigjmp_buf * jmpbuf;
86 cmpl $0, JB_SAVEMASK(%rdi) // if jmpbuf[_JBLEN] != 0
87 jne _longjmp // longjmp(jmpbuf, var);
88 jmp L_do__longjmp // else _longjmp(jmpbuf, var);
89
90LEAF(_longjmp, 0)
91 // %rdi is address of jmp_buf (saved context)
92 pushq %rdi // Preserve the jmp_buf across the call
93 pushq %rsi // Preserve the value across the call
94 pushq JB_MASK(%rdi) // Put the mask on the stack
95 movq $3, %rdi // how = SIG_SETMASK
96 movq %rsp, %rsi // set = address where we stored the mask
97 xorq %rdx, %rdx // oset = NULL
98 CALL_EXTERN_AGAIN(_sigprocmask)
99 addq $8, %rsp
100 popq %rsi // Restore the value
101 popq %rdi // Restore the jmp_buf
102L_do__longjmp:
103 BRANCH_EXTERN(__longjmp) // else
104END(_longjmp)