2.9
[glibc/nacl-glibc.git] / sysdeps / mach / hurd / powerpc / sigreturn.c
blob18e37a3d4185833552775218dac8a0edfaa0f2e3
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <hurd.h>
21 #include <hurd/signal.h>
22 #include <hurd/threadvar.h>
23 #include <stdlib.h>
25 int
26 __sigreturn (struct sigcontext *scp)
28 struct hurd_sigstate *ss;
29 mach_port_t *reply_port;
31 if (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK))
33 errno = EINVAL;
34 return -1;
37 ss = _hurd_self_sigstate ();
38 __spin_lock (&ss->lock);
40 /* Restore the set of blocked signals, and the intr_port slot. */
41 ss->blocked = scp->sc_mask;
42 ss->intr_port = scp->sc_intr_port;
44 /* Check for pending signals that were blocked by the old set. */
45 if (ss->pending & ~ss->blocked)
47 /* There are pending signals that just became unblocked. Wake up the
48 signal thread to deliver them. But first, squirrel away SCP where
49 the signal thread will notice it if it runs another handler, and
50 arrange to have us called over again in the new reality. */
51 ss->context = scp;
52 __spin_unlock (&ss->lock);
53 __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
54 /* If a pending signal was handled, sig_post never returned. */
55 __spin_lock (&ss->lock);
56 ss->context = NULL;
59 if (scp->sc_onstack)
61 ss->sigaltstack.ss_flags &= ~SS_ONSTACK; /* XXX threadvars */
62 /* XXX cannot unlock until off sigstack */
63 abort ();
65 else
66 __spin_unlock (&ss->lock);
68 /* Destroy the MiG reply port used by the signal handler, and restore the
69 reply port in use by the thread when interrupted. */
70 reply_port =
71 (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY);
72 if (*reply_port)
74 mach_port_t port = *reply_port;
76 /* Assigning MACH_PORT_DEAD here tells libc's mig_get_reply_port not to
77 get another reply port, but avoids mig_dealloc_reply_port trying to
78 deallocate it after the receive fails (which it will, because the
79 reply port will be bogus, whether we do this or not). */
80 *reply_port = MACH_PORT_DEAD;
82 __mach_port_destroy (__mach_task_self (), port);
84 *reply_port = scp->sc_reply_port;
86 /* Restore FPU state. */
87 #define restore_fpr(n) \
88 asm volatile ("lfd " #n ",%0(31)" : : "i" (n * 4))
90 asm volatile ("mr 31,%0" : : "r" (scp->sc_fprs));
92 /* Restore the floating-point control/status register. */
93 asm volatile ("lfd 0,256(31)");
94 asm volatile ("mtfsf 0xff,0");
96 /* Restore floating-point registers. */
97 restore_fpr (0);
98 restore_fpr (1);
99 restore_fpr (2);
100 restore_fpr (3);
101 restore_fpr (4);
102 restore_fpr (5);
103 restore_fpr (6);
104 restore_fpr (7);
105 restore_fpr (8);
106 restore_fpr (9);
107 restore_fpr (10);
108 restore_fpr (11);
109 restore_fpr (12);
110 restore_fpr (13);
111 restore_fpr (14);
112 restore_fpr (15);
113 restore_fpr (16);
114 restore_fpr (17);
115 restore_fpr (18);
116 restore_fpr (19);
117 restore_fpr (20);
118 restore_fpr (21);
119 restore_fpr (22);
120 restore_fpr (23);
121 restore_fpr (24);
122 restore_fpr (25);
123 restore_fpr (26);
124 restore_fpr (27);
125 restore_fpr (28);
126 restore_fpr (29);
127 restore_fpr (30);
128 restore_fpr (31);
130 /* Load all the registers from the sigcontext. */
131 #define restore_gpr(n) \
132 asm volatile ("lwz " #n ",%0(31)" : : "i" (n * 4))
134 asm volatile ("addi 31,31,-188"); /* r31 = scp->gprs */
136 /* Restore the special purpose registers. */
137 asm volatile ("lwz 0,128(31); mtcr 0");
138 asm volatile ("lwz 0,132(31); mtxer 0");
139 asm volatile ("lwz 0,136(31); mtlr 0");
140 asm volatile ("lwz 0,-8(31); mtctr 0"); /* XXX this is the PC */
141 #if 0
142 asm volatile ("lwz 0,144(31); mtmq %0"); /* PPC601 only */
143 #endif
145 /* Restore the normal registers. */
146 restore_gpr (0);
147 restore_gpr (1);
148 restore_gpr (2);
149 restore_gpr (3);
150 restore_gpr (4);
151 restore_gpr (5);
152 restore_gpr (6);
153 restore_gpr (7);
154 restore_gpr (8);
155 restore_gpr (9);
156 restore_gpr (10);
157 restore_gpr (11);
158 restore_gpr (12);
159 restore_gpr (13);
160 restore_gpr (14);
161 restore_gpr (15);
162 restore_gpr (16);
163 restore_gpr (17);
164 restore_gpr (18);
165 restore_gpr (19);
166 restore_gpr (20);
167 restore_gpr (21);
168 restore_gpr (22);
169 restore_gpr (23);
170 restore_gpr (24);
171 restore_gpr (25);
172 restore_gpr (26);
173 restore_gpr (27);
174 restore_gpr (28);
175 restore_gpr (29);
176 restore_gpr (30);
177 restore_gpr (31);
179 /* Return. */
180 asm volatile ("bctr"); /* XXX CTR is not restored! */
182 /* NOTREACHED */
183 return -1;
186 weak_alias (__sigreturn, sigreturn)