]> git.saurik.com Git - apple/xnu.git/blob - libsa/ppc/setjmp.s
xnu-792.12.6.tar.gz
[apple/xnu.git] / libsa / ppc / setjmp.s
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33
34 /*
35 * C library -- _setjmp, _longjmp
36 *
37 * _longjmp(a,v)
38 * will generate a "return(v)" from
39 * the last call to
40 * _setjmp(a)
41 * by restoring registers from the stack,
42 * The previous signal state is NOT restored.
43 *
44 * NOTE : MUST BE KEPT CONSISTENT WITH gdb/config/powerpc/tm-ppc-eabi.h
45 * (which needs to know where to find the destination address)
46 */
47
48 #include <mach/machine/asm.h>
49
50 .private_extern _longjmp
51 .private_extern _setjmp
52
53 /*
54 * setjmp : ARG0 (r3) contains the address of
55 * the structure where we are to
56 * store the context
57 * Uses r0 as scratch register
58 *
59 * NOTE : MUST BE KEPT CONSISTENT WITH gdb/config/powerpc/tm-ppc-eabi.h
60 * (which needs to know where to find the destination address)
61 */
62
63 ENTRY(setjmp,TAG_NO_FRAME_USED)
64 /* first entry is used for r1 - stack ptr */
65 stw r13, 4(ARG0) /* GPR context. We avoid multiple-word */
66 stw r14, 8(ARG0) /* instructions as they're slower (?) */
67 stw r15, 12(ARG0)
68 stw r16, 16(ARG0)
69 stw r17, 20(ARG0)
70 stw r18, 24(ARG0)
71 stw r19, 28(ARG0)
72 stw r20, 32(ARG0)
73 stw r21, 36(ARG0)
74 stw r22, 40(ARG0)
75 stw r23, 44(ARG0)
76 stw r24, 48(ARG0)
77 stw r25, 52(ARG0)
78 stw r26, 56(ARG0)
79 stw r27, 60(ARG0)
80 stw r28, 64(ARG0)
81 stw r29, 68(ARG0)
82 stw r30, 72(ARG0)
83 stw r31, 76(ARG0)
84
85 mfcr r0
86 stw r0, 80(ARG0) /* Condition register */
87
88 mflr r0
89 stw r0, 84(ARG0) /* Link register */
90
91 mfxer r0
92 stw r0, 88(ARG0) /* Fixed point exception register */
93
94 #if FLOATING_POINT_SUPPORT /* TODO NMGS probably not needed for kern */
95 mffs f0 /* get FPSCR in low 32 bits of f0 */
96 stfiwx f0, 92(ARG0) /* Floating point status register */
97
98 stfd f14, 96(ARG0) /* Floating point context - 8 byte aligned */
99 stfd f15, 104(ARG0)
100 stfd f16, 112(ARG0)
101 stfd f17, 120(ARG0)
102 stfd f18, 138(ARG0)
103 stfd f19, 146(ARG0)
104 stfd f20, 144(ARG0)
105 stfd f21, 152(ARG0)
106 stfd f22, 160(ARG0)
107 stfd f23, 178(ARG0)
108 stfd f24, 186(ARG0)
109 stfd f25, 184(ARG0)
110 stfd f26, 192(ARG0)
111 stfd f27, 200(ARG0)
112 stfd f28, 218(ARG0)
113 stfd f29, 226(ARG0)
114 stfd f30, 224(ARG0)
115 stfd f31, 232(ARG0)
116
117 #endif
118
119 stw r1, 0(ARG0) /* finally, save the stack pointer */
120 li ARG0, 0 /* setjmp must return zero */
121 blr
122
123 /*
124 * longjmp : ARG0 (r3) contains the address of
125 * the structure from where we are to
126 * restore the context.
127 * ARG1 (r4) contains the non-zero
128 * value that we must return to
129 * that context.
130 * Uses r0 as scratch register
131 *
132 * NOTE : MUST BE KEPT CONSISTENT WITH gdb/config/powerpc/tm-ppc-eabi.h
133 * (which needs to know where to find the destination address)
134 */
135
136 ENTRY(longjmp, TAG_NO_FRAME_USED) /* TODO NMGS - need correct tag */
137 lwz r13, 4(ARG0) /* GPR context. We avoid multiple-word */
138 lwz r14, 8(ARG0) /* instructions as they're slower (?) */
139 lwz r15, 12(ARG0)
140 lwz r16, 16(ARG0)
141 lwz r17, 20(ARG0)
142 lwz r18, 24(ARG0)
143 lwz r19, 28(ARG0)
144 lwz r20, 32(ARG0)
145 lwz r21, 36(ARG0)
146 lwz r22, 40(ARG0)
147 lwz r23, 44(ARG0)
148 lwz r24, 48(ARG0)
149 lwz r25, 52(ARG0)
150 lwz r26, 56(ARG0)
151 lwz r27, 60(ARG0)
152 lwz r28, 64(ARG0)
153 lwz r29, 68(ARG0)
154 lwz r30, 72(ARG0)
155 lwz r31, 76(ARG0)
156
157 lwz r0, 80(ARG0) /* Condition register */
158 mtcr r0 /* Use r5 as scratch register */
159
160 lwz r0, 84(ARG0) /* Link register */
161 mtlr r0
162
163 lwz r0, 88(ARG0) /* Fixed point exception register */
164 mtxer r0
165
166 #ifdef FLOATING_POINT_SUPPORT
167 lfd f0, 92-4(ARG0) /* get Floating point status register in low 32 bits of f0 */
168 mtfsf 0xFF,f0 /* restore FPSCR */
169
170 lfd f14, 96(ARG0) /* Floating point context - 8 byte aligned */
171 lfd f15, 104(ARG0)
172 lfd f16, 112(ARG0)
173 lfd f17, 120(ARG0)
174 lfd f18, 128(ARG0)
175 lfd f19, 136(ARG0)
176 lfd f20, 144(ARG0)
177 lfd f21, 152(ARG0)
178 lfd f22, 160(ARG0)
179 lfd f23, 168(ARG0)
180 lfd f24, 176(ARG0)
181 lfd f25, 184(ARG0)
182 lfd f26, 192(ARG0)
183 lfd f27, 200(ARG0)
184 lfd f28, 208(ARG0)
185 lfd f29, 216(ARG0)
186 lfd f30, 224(ARG0)
187 lfd f31, 232(ARG0)
188
189 #endif /* FLOATING_POINT_SUPPORT */
190
191
192 lwz r1, 0(ARG0) /* finally, restore the stack pointer */
193
194 mr. ARG0, ARG1 /* set the return value */
195 bnelr /* return if non-zero */
196
197 li ARG0, 1
198 blr /* never return 0, return 1 instead */
199