1 /* Return from signal handler for Hurd. PowerPC version.
2 Copyright (C) 1996,97,98,2001 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 #include <hurd/signal.h>
21 #include <hurd/threadvar.h>
25 __sigreturn (struct sigcontext
*scp
)
27 struct hurd_sigstate
*ss
;
28 mach_port_t
*reply_port
;
30 if (scp
== NULL
|| (scp
->sc_mask
& _SIG_CANT_MASK
))
36 ss
= _hurd_self_sigstate ();
37 __spin_lock (&ss
->lock
);
39 /* Restore the set of blocked signals, and the intr_port slot. */
40 ss
->blocked
= scp
->sc_mask
;
41 ss
->intr_port
= scp
->sc_intr_port
;
43 /* Check for pending signals that were blocked by the old set. */
44 if (ss
->pending
& ~ss
->blocked
)
46 /* There are pending signals that just became unblocked. Wake up the
47 signal thread to deliver them. But first, squirrel away SCP where
48 the signal thread will notice it if it runs another handler, and
49 arrange to have us called over again in the new reality. */
51 __spin_unlock (&ss
->lock
);
52 __msg_sig_post (_hurd_msgport
, 0, 0, __mach_task_self ());
53 /* If a pending signal was handled, sig_post never returned. */
54 __spin_lock (&ss
->lock
);
60 ss
->sigaltstack
.ss_flags
&= ~SS_ONSTACK
; /* XXX threadvars */
61 /* XXX cannot unlock until off sigstack */
65 __spin_unlock (&ss
->lock
);
67 /* Destroy the MiG reply port used by the signal handler, and restore the
68 reply port in use by the thread when interrupted. */
70 (mach_port_t
*) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY
);
73 mach_port_t port
= *reply_port
;
75 /* Assigning MACH_PORT_DEAD here tells libc's mig_get_reply_port not to
76 get another reply port, but avoids mig_dealloc_reply_port trying to
77 deallocate it after the receive fails (which it will, because the
78 reply port will be bogus, whether we do this or not). */
79 *reply_port
= MACH_PORT_DEAD
;
81 __mach_port_destroy (__mach_task_self (), port
);
83 *reply_port
= scp
->sc_reply_port
;
85 /* Restore FPU state. */
86 #define restore_fpr(n) \
87 asm volatile ("lfd " #n ",%0(31)" : : "i" (n * 4))
89 asm volatile ("mr 31,%0" : : "r" (scp
->sc_fprs
));
91 /* Restore the floating-point control/status register. */
92 asm volatile ("lfd 0,256(31)");
93 asm volatile ("mtfsf 0xff,0");
95 /* Restore floating-point registers. */
129 /* Load all the registers from the sigcontext. */
130 #define restore_gpr(n) \
131 asm volatile ("lwz " #n ",%0(31)" : : "i" (n * 4))
133 asm volatile ("addi 31,31,-188"); /* r31 = scp->gprs */
135 /* Restore the special purpose registers. */
136 asm volatile ("lwz 0,128(31); mtcr 0");
137 asm volatile ("lwz 0,132(31); mtxer 0");
138 asm volatile ("lwz 0,136(31); mtlr 0");
139 asm volatile ("lwz 0,-8(31); mtctr 0"); /* XXX this is the PC */
141 asm volatile ("lwz 0,144(31); mtmq %0"); /* PPC601 only */
144 /* Restore the normal registers. */
179 asm volatile ("bctr"); /* XXX CTR is not restored! */
185 weak_alias (__sigreturn
, sigreturn
)