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@
26 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
34 * sigvec registers _sigtramp as the handler for any signal requiring
35 * user-mode intervention. All _sigtramp does is find the real handler,
36 * calls it, then sigreturn's.
38 * Note that the kernel saves/restores all of our register state.
40 #if defined(__DYNAMIC__)
41 int __in_sigtramp
= 0;
44 /* These defn should match the kernel one */
46 #if defined(__ppc__) || defined(__ppc64__)
48 #define UC_TRAD64_VEC 25
50 #define UC_FLAVOR_VEC 35
51 #define UC_FLAVOR64 40
52 #define UC_FLAVOR64_VEC 45
54 #define UC_DUAL_VEC 55
56 /* The following are valid mcontext sizes */
57 #define UC_FLAVOR_SIZE ((PPC_THREAD_STATE_COUNT + PPC_EXCEPTION_STATE_COUNT + PPC_FLOAT_STATE_COUNT) * sizeof(int))
59 #define UC_FLAVOR_VEC_SIZE ((PPC_THREAD_STATE_COUNT + PPC_EXCEPTION_STATE_COUNT + PPC_FLOAT_STATE_COUNT + PPC_VECTOR_STATE_COUNT) * sizeof(int))
61 #define UC_FLAVOR64_SIZE ((PPC_THREAD_STATE64_COUNT + PPC_EXCEPTION_STATE64_COUNT + PPC_FLOAT_STATE_COUNT) * sizeof(int))
63 #define UC_FLAVOR64_VEC_SIZE ((PPC_THREAD_STATE64_COUNT + PPC_EXCEPTION_STATE64_COUNT + PPC_FLOAT_STATE_COUNT + PPC_VECTOR_STATE_COUNT) * sizeof(int))
66 #if defined(__ppc__) || defined(__ppc64__)
67 /* This routine will be replaced by an assembly soon */
69 restore64_state(mcontext_t mctx
, mcontext64_t mctx64
)
71 if (mctx
->ss
.srr0
!= (unsigned int)mctx64
->ss
.srr0
)
73 if (mctx
->ss
.srr1
!= (unsigned int)mctx64
->ss
.srr1
)
75 if (mctx
->ss
.r0
!= (unsigned int)mctx64
->ss
.r0
)
77 if (mctx
->ss
.r1
!= (unsigned int)mctx
->ss
.r1
)
79 if (mctx
->ss
.r2
!= (unsigned int)mctx
->ss
.r2
)
81 if (mctx
->ss
.r3
!= (unsigned int)mctx
->ss
.r3
)
83 if (mctx
->ss
.r4
!= (unsigned int)mctx
->ss
.r4
)
85 if (mctx
->ss
.r5
!= (unsigned int)mctx
->ss
.r5
)
87 if (mctx
->ss
.r6
!= (unsigned int)mctx
->ss
.r6
)
89 if (mctx
->ss
.r7
!= (unsigned int)mctx
->ss
.r7
)
91 if (mctx
->ss
.r8
!= (unsigned int)mctx
->ss
.r8
)
93 if (mctx
->ss
.r9
!= (unsigned int)mctx
->ss
.r9
)
95 if (mctx
->ss
.r10
!= (unsigned int)mctx
->ss
.r10
)
97 if (mctx
->ss
.r11
!= (unsigned int)mctx
->ss
.r11
)
99 if (mctx
->ss
.r12
!= (unsigned int)mctx
->ss
.r12
)
101 if (mctx
->ss
.r13
!= (unsigned int)mctx
->ss
.r13
)
103 if (mctx
->ss
.r14
!= (unsigned int)mctx
->ss
.r14
)
105 if (mctx
->ss
.r15
!= (unsigned int)mctx
->ss
.r15
)
107 if (mctx
->ss
.r16
!= (unsigned int)mctx
->ss
.r16
)
109 if (mctx
->ss
.r17
!= (unsigned int)mctx
->ss
.r17
)
111 if (mctx
->ss
.r18
!= (unsigned int)mctx
->ss
.r18
)
113 if (mctx
->ss
.r19
!= (unsigned int)mctx
->ss
.r19
)
115 if (mctx
->ss
.r20
!= (unsigned int)mctx
->ss
.r20
)
117 if (mctx
->ss
.r21
!= (unsigned int)mctx
->ss
.r21
)
119 if (mctx
->ss
.r22
!= (unsigned int)mctx64
->ss
.r22
)
121 if (mctx
->ss
.r23
!= (unsigned int)mctx64
->ss
.r23
)
123 if (mctx
->ss
.r24
!= (unsigned int)mctx64
->ss
.r24
)
125 if (mctx
->ss
.r25
!= (unsigned int)mctx64
->ss
.r25
)
127 if (mctx
->ss
.r26
!= (unsigned int)mctx64
->ss
.r26
)
129 if (mctx
->ss
.r27
!= (unsigned int)mctx64
->ss
.r27
)
131 if (mctx
->ss
.r28
!= (unsigned int)mctx64
->ss
.r28
)
133 if (mctx
->ss
.r29
!= (unsigned int)mctx64
->ss
.r29
)
135 if (mctx
->ss
.r30
!= (unsigned int)mctx64
->ss
.r30
)
137 if (mctx
->ss
.r31
!= (unsigned int)mctx64
->ss
.r31
)
140 if (mctx
->ss
.cr
!= mctx64
->ss
.cr
)
142 if (mctx
->ss
.xer
!= (unsigned int)mctx64
->ss
.xer
)
144 if (mctx
->ss
.lr
!= (unsigned int)mctx64
->ss
.lr
)
146 if (mctx
->ss
.ctr
!= (unsigned int)mctx64
->ss
.ctr
)
157 union __sigaction_u __sigaction_u
,
161 struct ucontext
*uctx
163 #if defined(__ppc__) || defined(__ppc64__)
164 int ctxstyle
= UC_FLAVOR
;
169 #if defined(__DYNAMIC__)
173 if (sigstyle
== UC_TRAD
)
175 #elif defined(__ppc__) || defined(__ppc64__)
176 if ((sigstyle
== UC_TRAD
) || (sigstyle
== UC_TRAD64
) || (sigstyle
== UC_TRAD64_VEC
))
180 sa_sigaction(sig
, sinfo
, uctx
);
182 if ((sigstyle
== UC_DUAL
) || (sigstyle
== UC_DUAL_VEC
)) {
183 mctx
= uctx
->uc_mcontext
;
184 mctx64
= (mcontext64_t
)((char *)(uctx
->uc_mcontext
) + sizeof(struct mcontext
));
185 /* restore 64bit state ? */
186 if (restore64_state(mctx
, mctx64
)) {
187 uctx
->uc_mcontext
= (void *)mctx64
;
188 if (sigstyle
== UC_DUAL
) {
189 uctx
->uc_mcsize
= UC_FLAVOR64_SIZE
;
190 ctxstyle
= UC_FLAVOR64
;
192 uctx
->uc_mcsize
= UC_FLAVOR64_VEC_SIZE
;
193 ctxstyle
= UC_FLAVOR64_VEC
;
196 if (sigstyle
== UC_DUAL
)
197 ctxstyle
= UC_FLAVOR
;
199 ctxstyle
= UC_FLAVOR_VEC
;
203 #endif /* __ppc__ || __ppc64__ */
205 #if defined(__DYNAMIC__)
208 #if defined(__ppc__) || defined(__ppc64__)
210 /* sigreturn(uctx, ctxstyle); */
211 /* syscall (SYS_SIGRETURN, uctx, ctxstyle); */
212 syscall (184, uctx
, ctxstyle
);
216 #endif /* __ppc__ || __ppc64__ */