2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
26 * NeXT 386 setjmp/longjmp
28 * Written by Bruce Martin, NeXT Inc. 4/9/92
32 * C library -- setjmp, longjmp
35 * will generate a "return(v)" from
38 * by restoring registers from the stack,
39 * The previous value of the signal mask is
44 #include <architecture/i386/asm_help.h>
65 #define JB_SAVEMASK 72 // sigsetjmp/siglongjmp only
68 movl 4(%esp), %eax // sigjmp_buf * jmpbuf;
69 movl 8(%esp), %ecx // int savemask;
70 movl %ecx, JB_SAVEMASK(%eax) // jmpbuf[_JBLEN] = savemask;
71 cmpl $0, %ecx // if savemask != 0
72 jne _setjmp // setjmp(jmpbuf);
73 BRANCH_EXTERN(__setjmp) // else
77 movl 4(%esp), %ecx // jmp_buf (struct sigcontext *)
78 pushl %ecx // save ecx
80 // call sigstack to get the current signal stack
81 subl $12, %esp // space for return structure
84 CALL_EXTERN(_sigaltstack)
85 movl 12(%esp), %eax // save stack pointer
86 movl %eax, JB_ONSTACK(%ecx)
89 // call sigblock to get signal mask
91 CALL_EXTERN(_sigblock)
93 popl %ecx // restore ecx
94 movl %eax, JB_MASK(%ecx)
96 // now build sigcontext
97 movl %ebx, JB_EBX(%ecx)
98 movl %edi, JB_EDI(%ecx)
99 movl %esi, JB_ESI(%ecx)
100 movl %ebp, JB_EBP(%ecx)
102 // EIP is set to the frame return address value
104 movl %eax, JB_EIP(%ecx)
105 // ESP is set to the frame return address plus 4
108 movl %eax, JB_ESP(%ecx)
124 // save eflags - you can't use movl
127 movl %eax, JB_EFLAGS(%ecx)
134 movl 4(%esp), %eax // sigjmp_buf * jmpbuf;
135 cmpl $0, JB_SAVEMASK(%eax) // if jmpbuf[_JBLEN] != 0
136 jne _longjmp // longjmp(jmpbuf, var);
137 BRANCH_EXTERN(__longjmp) // else
138 // _longjmp(jmpbuf, var);
142 fnstcw (%esp) // save FP control word
143 fninit // reset FP coprocessor
144 fldcw (%esp) // restore FP control word
146 movl 4(%esp), %eax // address of jmp_buf (saved context)
147 movl 8(%esp), %edx // return value
148 movl %edx, JB_EAX(%eax) // return value into saved context
149 movl $SYS_sigreturn, %eax // sigreturn system call
152 CALL_EXTERN(_longjmperror)