]> git.saurik.com Git - apple/libc.git/blob - i386/sys/_setjmp.s
Libc-339.tar.gz
[apple/libc.git] / i386 / sys / _setjmp.s
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
27 *
28 * HISTORY
29 * 20-Apr-92 Bruce Martin (bmartin@next.com)
30 * Created from M68K sources.
31 */
32
33 /*
34 * C library -- _setjmp, _longjmp
35 *
36 * _longjmp(a,v)
37 * will generate a "return(v)" from
38 * the last call to
39 * _setjmp(a)
40 * by restoring registers from the stack,
41 * The previous signal state is NOT restored.
42 *
43 */
44
45 #include <architecture/i386/asm_help.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
66
67 LEAF(__setjmp, 0)
68 movl 4(%esp), %ecx // jmp_buf (struct sigcontext *)
69
70 // now build sigcontext
71 movl %ebx, JB_EBX(%ecx)
72 movl %edi, JB_EDI(%ecx)
73 movl %esi, JB_ESI(%ecx)
74 movl %ebp, JB_EBP(%ecx)
75
76 // EIP is set to the frame return address value
77 movl (%esp), %eax
78 movl %eax, JB_EIP(%ecx)
79 // ESP is set to the frame return address plus 4
80 movl %esp, %eax
81 addl $4, %eax
82 movl %eax, JB_ESP(%ecx)
83
84 #if SAVE_SEG_REGS
85 // segment registers
86 mov %ss, JB_SS(%ecx)
87 mov %cs, JB_CS(%ecx)
88 mov %ds, JB_DS(%ecx)
89 mov %es, JB_ES(%ecx)
90 mov %fs, JB_FS(%ecx)
91 mov %gs, JB_GS(%ecx)
92 #endif
93
94 // save eflags - you can't use movl
95 pushf
96 popl %eax
97 movl %eax, JB_EFLAGS(%ecx)
98
99 // return 0
100 xorl %eax, %eax
101 ret
102
103
104 LEAF(__longjmp, 0)
105 subl $2,%esp
106 fnstcw (%esp) // save FP control word
107 fninit // reset FP coprocessor
108 fldcw (%esp) // restore FP control word
109 addl $2,%esp
110
111 movl 4(%esp), %ecx // jmp_buf (struct sigcontext *)
112 movl 8(%esp), %eax // return value
113 testl %eax, %eax
114 jnz 1f
115 incl %eax
116
117 // general registers
118 1: movl JB_EBX(%ecx), %ebx
119 movl JB_ESI(%ecx), %esi
120 movl JB_EDI(%ecx), %edi
121 movl JB_EBP(%ecx), %ebp
122 movl JB_ESP(%ecx), %esp
123
124 #if SAVE_SEG_REGS
125 // segment registers
126 mov JB_SS(%ecx), %ss
127 mov JB_CS(%ecx), %cs
128 mov JB_DS(%ecx), %ds
129 mov JB_ES(%ecx), %es
130 mov JB_FS(%ecx), %fs
131 mov JB_GS(%ecx), %gs
132 #endif
133
134 // eflags
135 pushl JB_EFLAGS(%ecx)
136 popf
137
138 jmp *JB_EIP(%ecx)