]> git.saurik.com Git - apple/libc.git/blob - sys.subproj/i386.subproj/_setjmp.s
bbec3f80f53b341768bbb52170886837caf18a54
[apple/libc.git] / sys.subproj / i386.subproj / _setjmp.s
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 * HISTORY
26 * 20-Apr-92 Bruce Martin (bmartin@next.com)
27 * Created from M68K sources.
28 */
29
30 /*
31 * C library -- _setjmp, _longjmp
32 *
33 * _longjmp(a,v)
34 * will generate a "return(v)" from
35 * the last call to
36 * _setjmp(a)
37 * by restoring registers from the stack,
38 * The previous signal state is NOT restored.
39 *
40 */
41
42 #include <architecture/i386/asm_help.h>
43
44 #define JB_ONSTACK 0
45 #define JB_MASK 4
46 #define JB_EAX 8
47 #define JB_EBX 12
48 #define JB_ECX 16
49 #define JB_EDX 20
50 #define JB_EDI 24
51 #define JB_ESI 28
52 #define JB_EBP 32
53 #define JB_ESP 36
54 #define JB_SS 40
55 #define JB_EFLAGS 44
56 #define JB_EIP 48
57 #define JB_CS 52
58 #define JB_DS 56
59 #define JB_ES 60
60 #define JB_FS 64
61 #define JB_GS 68
62
63
64 LEAF(__setjmp, 0)
65 movl 4(%esp), %ecx // jmp_buf (struct sigcontext *)
66
67 // now build sigcontext
68 movl %ebx, JB_EBX(%ecx)
69 movl %edi, JB_EDI(%ecx)
70 movl %esi, JB_ESI(%ecx)
71 movl %ebp, JB_EBP(%ecx)
72
73 // EIP is set to the frame return address value
74 movl (%esp), %eax
75 movl %eax, JB_EIP(%ecx)
76 // ESP is set to the frame return address plus 4
77 movl %esp, %eax
78 addl $4, %eax
79 movl %eax, JB_ESP(%ecx)
80
81 #if SAVE_SEG_REGS
82 // segment registers
83 mov %ss, JB_SS(%ecx)
84 mov %cs, JB_CS(%ecx)
85 mov %ds, JB_DS(%ecx)
86 mov %es, JB_ES(%ecx)
87 mov %fs, JB_FS(%ecx)
88 mov %gs, JB_GS(%ecx)
89 #endif
90
91 // save eflags - you can't use movl
92 pushf
93 popl %eax
94 movl %eax, JB_EFLAGS(%ecx)
95
96 // return 0
97 xorl %eax, %eax
98 ret
99
100
101 LEAF(__longjmp, 0)
102 subl $2,%esp
103 fnstcw (%esp) // save FP control word
104 fninit // reset FP coprocessor
105 fldcw (%esp) // restore FP control word
106 addl $2,%esp
107
108 movl 4(%esp), %ecx // jmp_buf (struct sigcontext *)
109 movl 8(%esp), %eax // return value
110 testl %eax, %eax
111 jnz 1f
112 incl %eax
113
114 // general registers
115 1: movl JB_EBX(%ecx), %ebx
116 movl JB_ESI(%ecx), %esi
117 movl JB_EDI(%ecx), %edi
118 movl JB_EBP(%ecx), %ebp
119 movl JB_ESP(%ecx), %esp
120
121 #if SAVE_SEG_REGS
122 // segment registers
123 mov JB_SS(%ecx), %ss
124 mov JB_CS(%ecx), %cs
125 mov JB_DS(%ecx), %ds
126 mov JB_ES(%ecx), %es
127 mov JB_FS(%ecx), %fs
128 mov JB_GS(%ecx), %gs
129 #endif
130
131 // eflags
132 pushl JB_EFLAGS(%ecx)
133 popf
134
135 jmp *JB_EIP(%ecx)