1 /* Copyright (C) 1991, 1992, 1994, 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
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 /* Clear the intr_port slot, since we are not in fact doing
52 an interruptible RPC right now. If SS->intr_port is not null,
53 the SCP context is doing an interruptible RPC, but the signal
54 thread will examine us while we are blocked in the sig_post RPC. */
55 ss
->intr_port
= MACH_PORT_NULL
;
56 __spin_unlock (&ss
->lock
);
57 __msg_sig_post (_hurd_msgport
, 0, __mach_task_self ());
58 /* If a pending signal was handled, sig_post never returned. */
59 __spin_lock (&ss
->lock
);
64 ss
->sigaltstack
.ss_flags
&= ~SA_ONSTACK
; /* XXX threadvars */
65 /* XXX cannot unlock until off sigstack */
69 __spin_unlock (&ss
->lock
);
71 /* Destroy the MiG reply port used by the signal handler, and restore the
72 reply port in use by the thread when interrupted. */
74 (mach_port_t
*) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY
);
76 __mach_port_destroy (__mach_task_self (), *reply_port
);
77 *reply_port
= scp
->sc_reply_port
;
79 if (scp
->sc_coproc_used
& SC_COPROC_USE_FPU
)
81 /* Restore FPU state. */
82 #define restore_fpr(n) \
83 asm volatile ("l.d $f" #n ",%0" : : "m" (scp->sc_fpr[n]))
85 /* Restore floating-point registers. */
103 /* Restore the floating-point control/status register ($f31). */
104 asm volatile ("ctc1 %0,$f31" : : "r" (scp
->sc_fpcsr
));
107 /* Load all the registers from the sigcontext. */
108 #define restore_gpr(n) \
109 asm volatile ("lw $" #n ",%0" : : "m" (scpreg->sc_gpr[n - 1]))
112 register const struct sigcontext
*const scpreg
asm ("$1") = scp
;
113 register int *at
asm ("$1");
115 /* First restore the multiplication result registers. The compiler
116 will use some temporary registers, so we do this before restoring
117 the general registers. */
118 asm volatile ("mtlo %0" : : "r" (scpreg
->sc_mdlo
));
119 asm volatile ("mthi %0" : : "r" (scpreg
->sc_mdhi
));
121 /* In the word after the saved PC, store the saved $1 value. */
122 (&scpreg
->sc_pc
)[1] = scpreg
->sc_gpr
[0];
124 asm volatile (".set noreorder; .set noat;");
126 /* Restore the normal registers. */
151 /* Registers 26-27 are kernel-only. */
153 restore_gpr (29); /* Stack pointer. */
154 restore_gpr (30); /* Frame pointer. */
155 restore_gpr (31); /* Return address. */
158 /* This is an emulated instruction that will find at the address in $1
159 two words: the PC value to restore, and the $1 value to restore. */
160 asm volatile (".word op_sigreturn");
162 asm volatile (".set reorder; .set at;");
169 weak_alias (__sigreturn
, sigreturn
)