2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 /* void _longjmp(jmp_buf env, int val); */
25 /* int _longjmp(jmp_buf env); */
27 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
29 * File: sys/ppc/_longjmp.s
31 * Implements _longjmp()
34 * 8 September 1998 Matt Watson (mwatson@apple.com)
35 * Created. Derived from longjmp.s
38 #include <architecture/ppc/asm_help.h>
43 /* special flag bit definitions copied from /osfmk/ppc/thread_act.h */
45 #define floatUsedbit 1
46 #define vectorUsedbit 2
49 #if defined(__DYNAMIC__)
51 .non_lazy_symbol_pointer
53 L_memmove$non_lazy_ptr:
54 .indirect_symbol _memmove
56 .non_lazy_symbol_pointer
58 L__cpu_has_altivec$non_lazy_ptr:
59 .indirect_symbol __cpu_has_altivec
66 ; need to restore FPRs or VRs?
69 lwz r6,JMP_addr_at_setjmp(r3)
70 rlwinm r7,r5,0,vectorUsedbit,vectorUsedbit
71 rlwinm r8,r5,0,floatUsedbit,floatUsedbit
72 cmpw cr1,r3,r6 ; jmp_buf still at same address?
73 cmpwi cr3,r7,0 ; set cr3 iff VRs in use (non-volatile CR)
74 cmpwi cr4,r8,0 ; set cr4 iff FPRs in use (non-volatile CR)
77 ; jmp_buf was moved since setjmp (or is uninitialized.)
78 ; We must move VRs and FPRs to be quadword aligned at present address.
80 stw r3,JMP_addr_at_setjmp(r3) ; update, in case we longjmp to this again
81 mr r31,r4 ; save "val" arg across memmove
82 mr r30,r3 ; and jmp_buf ptr
83 addi r3,r3,JMP_vr_base_addr
84 addi r4,r6,JMP_vr_base_addr
85 rlwinm r3,r3,0,0,27 ; r3 <- QW aligned addr where they should be
86 rlwinm r4,r4,0,0,27 ; r4 <- QW aligned addr where they originally were
87 sub r7,r4,r6 ; r7 <- offset of VRs/FPRs within jmp_buf
88 add r4,r30,r7 ; r4 <- where they are now
89 li r5,(JMP_buf_end - JMP_vr_base_addr)
90 #if defined(__DYNAMIC__)
91 bcl 20,31,1f ; Get pic-base
93 addis r12, r12, ha16(L_memmove$non_lazy_ptr - 1b)
94 lwz r12, lo16(L_memmove$non_lazy_ptr - 1b)(r12)
95 mtctr r12 ; Get address left by dyld
103 ; Restore VRs iff any
108 beq+ cr3,LZeroVRSave ; no VRs
109 lwz r0,JMP_vrsave(r3)
110 addi r6,r3,JMP_vr_base_addr
111 cmpwi r0,0 ; any live VRs?
137 b LRestoreFPRs ; skip zeroing VRSave
139 ; Zero VRSave iff Altivec is supported, but VRs were not in use
140 ; at setjmp time. This covers the case where VRs are first used after
141 ; the setjmp but before the longjmp, and where VRSave is nonzero at
142 ; the longjmp. We need to zero it now, or it will always remain
143 ; nonzero since they are sticky bits.
146 #if defined(__DYNAMIC__)
148 1: mflr r9 ; get our address
149 addis r6,r9,ha16(L__cpu_has_altivec$non_lazy_ptr - 1b)
150 lwz r7,lo16(L__cpu_has_altivec$non_lazy_ptr - 1b)(r6)
151 lwz r7,0(r7) ; load the flag
153 lis r7, ha16(__cpu_has_altivec)
154 lwz r7, lo16(__cpu_has_altivec)(r7)
158 beq LRestoreFPRs ; no Altivec, so skip
161 ; Restore FPRs if any
165 beq cr4,LRestoreGPRs ; FPRs not in use at setjmp
166 addi r6,r3,JMP_fp_base_addr
167 rlwinm r6,r6,0,0,27 ; mask off low 4 bits to qw align
216 lwz r0, JMP_ctr(r3) ; XXX ctr is volatile
218 lwz r0, JMP_xer(r3) ; XXX xer is volatile