]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/mach/hurd/mips/sigreturn.c
initial import
[thirdparty/glibc.git] / sysdeps / mach / hurd / mips / sigreturn.c
1 /* Copyright (C) 1991, 1992, 1994, 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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. */
18
19 #include <hurd.h>
20 #include <hurd/signal.h>
21 #include <hurd/threadvar.h>
22 #include <stdlib.h>
23
24 int
25 __sigreturn (struct sigcontext *scp)
26 {
27 struct hurd_sigstate *ss;
28 mach_port_t *reply_port;
29
30 if (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK))
31 {
32 errno = EINVAL;
33 return -1;
34 }
35
36 ss = _hurd_self_sigstate ();
37 __spin_lock (&ss->lock);
38
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;
42
43 /* Check for pending signals that were blocked by the old set. */
44 if (ss->pending & ~ss->blocked)
45 {
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. */
50 ss->context = scp;
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);
60 }
61
62 if (scp->sc_onstack)
63 {
64 ss->sigaltstack.ss_flags &= ~SA_ONSTACK; /* XXX threadvars */
65 /* XXX cannot unlock until off sigstack */
66 abort ();
67 }
68 else
69 __spin_unlock (&ss->lock);
70
71 /* Destroy the MiG reply port used by the signal handler, and restore the
72 reply port in use by the thread when interrupted. */
73 reply_port =
74 (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY);
75 if (*reply_port)
76 __mach_port_destroy (__mach_task_self (), *reply_port);
77 *reply_port = scp->sc_reply_port;
78
79 if (scp->sc_coproc_used & SC_COPROC_USE_FPU)
80 {
81 /* Restore FPU state. */
82 #define restore_fpr(n) \
83 asm volatile ("l.d $f" #n ",%0" : : "m" (scp->sc_fpr[n]))
84
85 /* Restore floating-point registers. */
86 restore_fpr (0);
87 restore_fpr (2);
88 restore_fpr (4);
89 restore_fpr (6);
90 restore_fpr (8);
91 restore_fpr (10);
92 restore_fpr (12);
93 restore_fpr (14);
94 restore_fpr (16);
95 restore_fpr (18);
96 restore_fpr (20);
97 restore_fpr (22);
98 restore_fpr (24);
99 restore_fpr (26);
100 restore_fpr (28);
101 restore_fpr (30);
102
103 /* Restore the floating-point control/status register ($f31). */
104 asm volatile ("ctc1 %0,$f31" : : "r" (scp->sc_fpcsr));
105 }
106
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]))
110
111 {
112 register const struct sigcontext *const scpreg asm ("$1") = scp;
113 register int *at asm ("$1");
114
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));
120
121 /* In the word after the saved PC, store the saved $1 value. */
122 (&scpreg->sc_pc)[1] = scpreg->sc_gpr[0];
123
124 asm volatile (".set noreorder; .set noat;");
125
126 /* Restore the normal registers. */
127 restore_gpr (2);
128 restore_gpr (3);
129 restore_gpr (4);
130 restore_gpr (5);
131 restore_gpr (6);
132 restore_gpr (7);
133 restore_gpr (8);
134 restore_gpr (9);
135 restore_gpr (10);
136 restore_gpr (11);
137 restore_gpr (12);
138 restore_gpr (13);
139 restore_gpr (14);
140 restore_gpr (15);
141 restore_gpr (16);
142 restore_gpr (17);
143 restore_gpr (18);
144 restore_gpr (19);
145 restore_gpr (20);
146 restore_gpr (21);
147 restore_gpr (22);
148 restore_gpr (23);
149 restore_gpr (24);
150 restore_gpr (25);
151 /* Registers 26-27 are kernel-only. */
152 restore_gpr (28);
153 restore_gpr (29); /* Stack pointer. */
154 restore_gpr (30); /* Frame pointer. */
155 restore_gpr (31); /* Return address. */
156
157 at = &scpreg->sc_pc;
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");
161
162 asm volatile (".set reorder; .set at;");
163 }
164
165 /* NOTREACHED */
166 return -1;
167 }
168
169 weak_alias (__sigreturn, sigreturn)