]> git.saurik.com Git - apple/libc.git/blob - sys.subproj/ppc.subproj/_setjmp.s
Libc-186.tar.gz
[apple/libc.git] / sys.subproj / ppc.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 /* int _setjmp(jmp_buf env); */
24 /*
25 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
26 *
27 * File: sys/ppc/_setjmp.s
28 *
29 * Implements _setjmp()
30 *
31 * History:
32 * 8 September 1998 Matt Watson (mwatson@apple.com)
33 * Created. Derived from setjmp.s
34 */
35
36
37 #include <architecture/ppc/asm_help.h>
38 #include "_setjmp.h"
39
40 #define VRSave 256
41
42 /* special flag bit definitions copied from /osfmk/ppc/thread_act.h */
43
44 #define floatUsedbit 1
45 #define vectorUsedbit 2
46
47 #define FlagsFastTrap 0x7FF3
48
49
50 LEAF(__setjmp)
51 stw r31, JMP_r31(r3)
52 /* r1, r2, r13-r30 */
53 stw r1, JMP_r1(r3)
54 stw r2, JMP_r2(r3)
55 stw r13, JMP_r13(r3)
56 stw r14, JMP_r14(r3)
57 stw r15, JMP_r15(r3)
58 stw r16, JMP_r16(r3)
59 stw r17, JMP_r17(r3)
60 stw r18, JMP_r18(r3)
61 stw r19, JMP_r19(r3)
62 stw r20, JMP_r20(r3)
63 stw r21, JMP_r21(r3)
64 stw r22, JMP_r22(r3)
65 mfcr r0
66 stw r23, JMP_r23(r3)
67 stw r24, JMP_r24(r3)
68 mflr r5
69 stw r25, JMP_r25(r3)
70 stw r26, JMP_r26(r3)
71 mfctr r6 ; XXX ctr is volatile
72 stw r27, JMP_r27(r3)
73 stw r28, JMP_r28(r3)
74 mfxer r7 ; XXX xer is volatile
75 stw r29, JMP_r29(r3)
76 stw r30, JMP_r30(r3)
77 stw r0, JMP_cr(r3)
78 stw r5, JMP_lr(r3)
79 stw r6, JMP_ctr(r3)
80 stw r7, JMP_xer(r3)
81
82 mr r31,r3 ; save jmp_buf ptr
83 li r0,FlagsFastTrap
84 sc ; get FPR-inuse and VR-inuse flags from kernel
85 rlwinm r4,r3,0,floatUsedbit,floatUsedbit
86 rlwinm. r5,r3,0,vectorUsedbit,vectorUsedbit
87 cmpwi cr1,r4,0 ; set CR1 bne iff FPRs in use
88 stw r3,JMP_flags(r31)
89 stw r31,JMP_addr_at_setjmp(r31)
90 mr r3,r31 ; restore jmp_buf ptr
91 lwz r31,JMP_r31(r31)
92 beq LSaveFPRsIfNecessary ; skip if vectorUsedbit was 0
93
94 ; must save VRs and VRSAVE
95
96 mfspr r4,VRSave
97 andi. r0,r4,0xFFF ; we only care about v20-v31
98 stw r0,JMP_vrsave(r3) ; set up effective VRSAVE
99 beq LSaveFPRsIfNecessary ; no live non-volatile VRs
100 addi r6,r3,JMP_vr_base_addr
101 stvx v20,0,r6
102 li r4,16*1
103 stvx v21,r4,r6
104 li r4,16*2
105 stvx v22,r4,r6
106 li r4,16*3
107 stvx v23,r4,r6
108 li r4,16*4
109 stvx v24,r4,r6
110 li r4,16*5
111 stvx v25,r4,r6
112 li r4,16*6
113 stvx v26,r4,r6
114 li r4,16*7
115 stvx v27,r4,r6
116 li r4,16*8
117 stvx v28,r4,r6
118 li r4,16*9
119 stvx v29,r4,r6
120 li r4,16*10
121 stvx v30,r4,r6
122 li r4,16*11
123 stvx v31,r4,r6
124
125 ; must save FPRs if they are live in this thread
126 ; CR1 = bne iff FPRs are in use
127
128 LSaveFPRsIfNecessary:
129 beq cr1,LExit ; FPRs not in use
130 addi r6,r3,JMP_fp_base_addr
131 rlwinm r6,r6,0,0,27 ; mask off low 4 bits to qw align
132 stfd f14,0*8(r6)
133 stfd f15,1*8(r6)
134 stfd f16,2*8(r6)
135 stfd f17,3*8(r6)
136 stfd f18,4*8(r6)
137 stfd f19,5*8(r6)
138 stfd f20,6*8(r6)
139 stfd f21,7*8(r6)
140 stfd f22,8*8(r6)
141 stfd f23,9*8(r6)
142 stfd f24,10*8(r6)
143 stfd f25,11*8(r6)
144 stfd f26,12*8(r6)
145 stfd f27,13*8(r6)
146 stfd f28,14*8(r6)
147 stfd f29,15*8(r6)
148 stfd f30,16*8(r6)
149 stfd f31,17*8(r6)
150
151 LExit:
152 li r3, 0
153 blr
154