]>
Commit | Line | Data |
---|---|---|
e9ce8d39 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved | |
24 | */ | |
25 | /* | |
26 | * NeXT 386 setjmp/longjmp | |
27 | * | |
28 | * Written by Bruce Martin, NeXT Inc. 4/9/92 | |
29 | */ | |
30 | ||
31 | /* | |
32 | * C library -- setjmp, longjmp | |
33 | * | |
34 | * longjmp(a,v) | |
35 | * will generate a "return(v)" from | |
36 | * the last call to | |
37 | * setjmp(a) | |
38 | * by restoring registers from the stack, | |
39 | * The previous value of the signal mask is | |
40 | * restored. | |
41 | * | |
42 | */ | |
43 | ||
44 | #include <architecture/i386/asm_help.h> | |
45 | #include "SYS.h" | |
46 | ||
47 | #define JB_ONSTACK 0 | |
48 | #define JB_MASK 4 | |
49 | #define JB_EAX 8 | |
50 | #define JB_EBX 12 | |
51 | #define JB_ECX 16 | |
52 | #define JB_EDX 20 | |
53 | #define JB_EDI 24 | |
54 | #define JB_ESI 28 | |
55 | #define JB_EBP 32 | |
56 | #define JB_ESP 36 | |
57 | #define JB_SS 40 | |
58 | #define JB_EFLAGS 44 | |
59 | #define JB_EIP 48 | |
60 | #define JB_CS 52 | |
61 | #define JB_DS 56 | |
62 | #define JB_ES 60 | |
63 | #define JB_FS 64 | |
64 | #define JB_GS 68 | |
65 | #define JB_SAVEMASK 72 // sigsetjmp/siglongjmp only | |
66 | ||
67 | LEAF(_sigsetjmp, 0) | |
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 | |
74 | // _setjmp(jmpbuf); | |
75 | ||
76 | LEAF(_setjmp, 0) | |
77 | movl 4(%esp), %ecx // jmp_buf (struct sigcontext *) | |
78 | pushl %ecx // save ecx | |
79 | ||
80 | // call sigstack to get the current signal stack | |
81 | subl $12, %esp // space for return structure | |
82 | pushl %esp | |
83 | pushl $0 | |
84 | CALL_EXTERN(_sigaltstack) | |
85 | movl 12(%esp), %eax // save stack pointer | |
86 | movl %eax, JB_ONSTACK(%ecx) | |
87 | addl $20, %esp | |
88 | ||
89 | // call sigblock to get signal mask | |
90 | pushl $0 | |
91 | CALL_EXTERN(_sigblock) | |
92 | addl $4, %esp | |
93 | popl %ecx // restore ecx | |
94 | movl %eax, JB_MASK(%ecx) | |
95 | ||
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) | |
101 | ||
102 | // EIP is set to the frame return address value | |
103 | movl (%esp), %eax | |
104 | movl %eax, JB_EIP(%ecx) | |
105 | // ESP is set to the frame return address plus 4 | |
106 | movl %esp, %eax | |
107 | addl $4, %eax | |
108 | movl %eax, JB_ESP(%ecx) | |
109 | ||
110 | // segment registers | |
111 | movl $0, JB_SS(%ecx) | |
112 | mov %ss, JB_SS(%ecx) | |
113 | movl $0, JB_CS(%ecx) | |
114 | mov %cs, JB_CS(%ecx) | |
115 | movl $0, JB_DS(%ecx) | |
116 | mov %ds, JB_DS(%ecx) | |
117 | movl $0, JB_ES(%ecx) | |
118 | mov %es, JB_ES(%ecx) | |
119 | movl $0, JB_FS(%ecx) | |
120 | mov %fs, JB_FS(%ecx) | |
121 | movl $0, JB_GS(%ecx) | |
122 | mov %gs, JB_GS(%ecx) | |
123 | ||
124 | // save eflags - you can't use movl | |
125 | pushf | |
126 | popl %eax | |
127 | movl %eax, JB_EFLAGS(%ecx) | |
128 | ||
129 | // return 0 | |
130 | xorl %eax, %eax | |
131 | ret | |
132 | ||
133 | LEAF(_siglongjmp, 0) | |
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); | |
139 | ||
140 | LEAF(_longjmp, 0) | |
141 | subl $2,%esp | |
142 | fnstcw (%esp) // save FP control word | |
143 | fninit // reset FP coprocessor | |
144 | fldcw (%esp) // restore FP control word | |
145 | addl $2,%esp | |
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 | |
150 | UNIX_SYSCALL_TRAP | |
151 | addl $8, %esp | |
152 | CALL_EXTERN(_longjmperror) | |
153 | CALL_EXTERN(_abort) | |
154 | END(_longjmp) |