2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
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 /* We use mode-independent "g" opcodes such as "lg", and/or
39 * mode-independent macros such as MI_CALL_EXTERNAL. These expand
40 * into word operations when targeting __ppc__, and into doubleword
41 * operations when targeting __ppc64__.
43 #include <architecture/ppc/mode_independent_asm.h>
47 #define __APPLE_API_PRIVATE
48 #include <machine/cpu_capabilities.h>
49 #undef __APPLE_API_PRIVATE
54 /* int _longjmp(jmp_buf env, int val); */
56 MI_ENTRY_POINT(__longjmp)
57 lg r6,JMP_addr_at_setjmp(r3)
58 lbz r7, _COMM_PAGE_ALTIVEC(0)
59 cmpg cr1,r3,r6 ; jmpbuf still at same address?
60 cmpwi cr2,r7,0 ; Altivec available? (using non-volatile cr)
61 beq++ cr1,LRestoreVRs ; jmpbuf has not moved
63 ; jmp_buf was moved since setjmp (or is uninitialized.)
64 ; We must move VRs and FPRs to be quadword aligned at present address.
66 stg r3,JMP_addr_at_setjmp(r3) ; update, in case we longjmp to this again
67 mr r31,r4 ; save "val" arg across memmove
68 mr r30,r3 ; and jmp_buf ptr
69 addi r3,r3,JMP_vr_base_addr
70 addi r4,r6,JMP_vr_base_addr
71 clrrgi r3,r3,4 ; r3 <- QW aligned addr where they should be
72 clrrgi r4,r4,4 ; r4 <- QW aligned addr where they originally were
73 sub r7,r4,r6 ; r7 <- offset of VRs/FPRs within jmp_buf
74 add r4,r30,r7 ; r4 <- where they are now
75 li r5,(JMP_buf_end - JMP_vr_base_addr)
77 MI_CALL_EXTERNAL(_memmove)
79 mr r3,r30 ; restore parameters
83 ; cr2 - beq if AltiVec not available
86 lg r0,JMP_vrsave(r3) ; get VRSAVE at setjmp()
87 addi r6,r3,JMP_vr_base_addr
88 beq-- cr2,LRestoreFPRs ; AltiVec not available so skip
89 cmpwi r0,0 ; any live VRs?
90 mtspr VRSave,r0 ; update VRSAVE whether 0 or not
91 beq++ LRestoreFPRs ; VRSAVE is 0 so no VRs to reload
119 addi r6,r3,JMP_fp_base_addr
120 lfd f0,JMP_fpscr(r3) ; get FPSCR from non-sliding section of jmpbuf
121 clrrgi r6,r6,4 ; mask off low 4 bits to qw align
140 mtfsf 0xFF,f0 ; restore entire FPSCR
144 lg r5, JMP_cr(r3) ; r5 <- CR
145 lg r6, JMP_lr(r3) ; r6 <- LR (ie, return addres)
146 cmplgi r4,0 ; is return value 0? (not permitted)
154 mtcrf 0x20,r5 ; restore cr2 (we only restore non-volatile CRs)
159 mtctr r6 ; set up return address, avoiding LR since it will mispredict
164 mtcrf 0x10,r5 ; restore cr3
169 mtcrf 0x08,r5 ; restore cr4
172 mr r3,r4 ; move return code into position (cr0 is set on r4)
173 bnectr++ ; return code was not 0
174 li r3, 1 ; cannot return zero from longjmp(), so return 1 instead