]> git.saurik.com Git - apple/libc.git/blame - i386/sys/setjmp.s
Libc-583.tar.gz
[apple/libc.git] / i386 / sys / setjmp.s
CommitLineData
e9ce8d39
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
734aad71
A
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
e9ce8d39
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
734aad71
A
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.
e9ce8d39
A
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>
e9ce8d39 46
8e029c65
A
47// The FP control word is actually two bytes, but there's no harm in
48// using four bytes for it and keeping the struct aligned.
49#define JB_FPCW 0
e9ce8d39 50#define JB_MASK 4
8e029c65 51#define JB_MXCSR 8
e9ce8d39 52#define JB_EBX 12
224c7076 53#define JB_ONSTACK 16
e9ce8d39
A
54#define JB_EDX 20
55#define JB_EDI 24
56#define JB_ESI 28
57#define JB_EBP 32
58#define JB_ESP 36
59#define JB_SS 40
60#define JB_EFLAGS 44
61#define JB_EIP 48
62#define JB_CS 52
63#define JB_DS 56
64#define JB_ES 60
65#define JB_FS 64
66#define JB_GS 68
67#define JB_SAVEMASK 72 // sigsetjmp/siglongjmp only
68
69LEAF(_sigsetjmp, 0)
70 movl 4(%esp), %eax // sigjmp_buf * jmpbuf;
71 movl 8(%esp), %ecx // int savemask;
72 movl %ecx, JB_SAVEMASK(%eax) // jmpbuf[_JBLEN] = savemask;
73 cmpl $0, %ecx // if savemask != 0
74 jne _setjmp // setjmp(jmpbuf);
eb1cde05 75 jmp L_do__setjmp // else _setjmp(jmpbuf);
e9ce8d39
A
76
77LEAF(_setjmp, 0)
224c7076
A
78 subl $16, %esp // make space for return from sigprocmask
79 // + 12 to align stack
eb1cde05
A
80 pushl %esp // oset
81 pushl $0 // set = NULL
82 pushl $1 // how = SIG_BLOCK
83 CALL_EXTERN(_sigprocmask)
84 movl 12(%esp),%eax // save the mask
224c7076 85 addl $28, %esp // restore original esp
e9ce8d39 86 movl 4(%esp), %ecx // jmp_buf (struct sigcontext *)
e9ce8d39 87 movl %eax, JB_MASK(%ecx)
224c7076
A
88
89 subl $20, %esp // temporary struct sigaltstack + 8 to
90 // align stack
91 pushl %esp // oss
92 pushl $0 // ss == NULL
93 CALL_EXTERN(_sigaltstack) // get alternate signal stack info
94 movl 16(%esp), %eax // oss->ss_flags
95 addl $28, %esp // Restore %esp
96 movl %eax, JB_ONSTACK(%ecx)
97
eb1cde05
A
98L_do__setjmp:
99 BRANCH_EXTERN(__setjmp)
e9ce8d39
A
100
101LEAF(_siglongjmp, 0)
102 movl 4(%esp), %eax // sigjmp_buf * jmpbuf;
103 cmpl $0, JB_SAVEMASK(%eax) // if jmpbuf[_JBLEN] != 0
104 jne _longjmp // longjmp(jmpbuf, var);
eb1cde05 105 jmp L_do__longjmp // else _longjmp(jmpbuf, var);
e9ce8d39
A
106
107LEAF(_longjmp, 0)
eb1cde05
A
108 movl 4(%esp), %ecx // address of jmp_buf (saved context)
109 movl JB_MASK(%ecx),%eax // get the mask
224c7076
A
110 subl $12, %esp // Make sure the stack is 16-byte
111 // aligned when we call sigprocmask
eb1cde05
A
112 pushl %eax // store the mask
113 movl %esp, %edx // save the address where we stored the mask
114 pushl $0 // oset = NULL
115 pushl %edx // set
116 pushl $3 // how = SIG_SETMASK
117 CALL_EXTERN_AGAIN(_sigprocmask)
224c7076
A
118 addl $28, %esp // restore original esp
119
120 movl 4(%esp), %ecx // address of jmp_buf
121 movl JB_ONSTACK(%ecx), %eax // ss_flags
122 subl $8, %esp
123 pushl %eax
124 CALL_EXTERN(__sigunaltstack)
125 addl $12, %esp
126
eb1cde05
A
127L_do__longjmp:
128 BRANCH_EXTERN(__longjmp) // else
e9ce8d39 129END(_longjmp)