1 /* Return from signal handler in GNU C library for Hurd. Alpha version.
2 Copyright (C) 1994,95,97,98,2002 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
21 #include <hurd/signal.h>
22 #include <hurd/threadvar.h>
28 __sigreturn (struct sigcontext
*scp
)
30 struct hurd_sigstate
*ss
;
31 mach_port_t
*reply_port
;
33 if (scp
== NULL
|| (scp
->sc_mask
& _SIG_CANT_MASK
))
39 ss
= _hurd_self_sigstate ();
40 __spin_lock (&ss
->lock
);
42 /* Restore the set of blocked signals, and the intr_port slot. */
43 ss
->blocked
= scp
->sc_mask
;
44 ss
->intr_port
= scp
->sc_intr_port
;
46 /* Check for pending signals that were blocked by the old set. */
47 if (ss
->pending
& ~ss
->blocked
)
49 /* There are pending signals that just became unblocked. Wake up the
50 signal thread to deliver them. But first, squirrel away SCP where
51 the signal thread will notice it if it runs another handler, and
52 arrange to have us called over again in the new reality. */
54 /* Clear the intr_port slot, since we are not in fact doing
55 an interruptible RPC right now. If SS->intr_port is not null,
56 the SCP context is doing an interruptible RPC, but the signal
57 thread will examine us while we are blocked in the sig_post RPC. */
58 ss
->intr_port
= MACH_PORT_NULL
;
59 __spin_unlock (&ss
->lock
);
60 __msg_sig_post (_hurd_msgport
, 0, 0, __mach_task_self ());
61 /* If a pending signal was handled, sig_post never returned. */
62 __spin_lock (&ss
->lock
);
67 ss
->sigaltstack
.ss_flags
&= ~SS_ONSTACK
; /* XXX threadvars */
68 /* XXX cannot unlock until off sigstack */
72 __spin_unlock (&ss
->lock
);
74 /* Destroy the MiG reply port used by the signal handler, and restore the
75 reply port in use by the thread when interrupted. */
77 (mach_port_t
*) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY
);
79 __mach_port_destroy (__mach_task_self (), *reply_port
);
80 *reply_port
= scp
->sc_reply_port
;
84 /* Restore FPU state. */
86 /* Restore the floating-point control/status register.
87 We must do this first because the compiler will need
88 a temporary FP register for the load. */
89 asm volatile ("mt_fpcr %0" : : "f" (scp
->sc_fpcsr
));
91 /* Restore floating-point registers. */
92 #define restore_fpr(n) \
93 asm volatile ("ldt $f" #n ",%0" : : "m" (scp->sc_fpregs[n]))
127 /* Load all the registers from the sigcontext. */
128 #define restore_gpr(n) \
129 asm volatile ("ldq $" #n ",%0" : : "m" (scpreg->sc_regs[n]))
132 /* The `rei' PAL pseudo-instruction restores registers $2..$7, the PC
133 and processor status. So we can use these few registers for our
134 working variables. Unfortunately, it finds its data on the stack
135 and merely pops the SP ($30) over the words of state restored,
136 allowing no other option for the new SP value. So we must push the
137 registers and PSW it will to restore, onto the user's stack and let
138 it pop them from there. */
139 register const struct sigcontext
*const scpreg
asm ("$2") = scp
;
140 register integer_t
*usp
asm ("$3") = (integer_t
*) scpreg
->sc_regs
[30];
141 register integer_t usp_align
asm ("$4");
143 /* Push an 8-word "trap frame" onto the user stack for `rei':
144 registers $2..$7, the PC, and the PSW. */
146 register struct rei_frame
148 integer_t regs
[5], pc
, ps
;
149 } *rei_frame
asm ("$5");
152 /* `rei' demands that the stack be aligned to a 64 byte (8 word)
153 boundary; bits 61..56 of the PSW are OR'd back into the SP value
154 after popping the 8-word trap frame, so we store (sp % 64)
155 there and this restores the original user SP. */
156 usp_align
= (integer_t
) usp
& 63L;
157 rei_frame
= (void *) ((integer_t
) usp
& ~63L);
159 /* Copy the registers and PC from the sigcontext. */
160 memcpy (rei_frame
->regs
, &scpreg
->sc_regs
[2], sizeof rei_frame
->regs
);
161 rei_frame
->pc
= scpreg
->sc_pc
;
163 /* Compute the new PS value to be restored. `rei' adds the value at
164 bits 61..56 to the SP to compensate for the alignment above that
165 cleared the low 6 bits; bits 5..3 are the new mode/privilege level
166 (must be >= current mode; 3 == user mode); bits 2..0 are "software",
167 unused by the processor or kernel (XXX should trampoline save these?
168 How?); in user mode, `rei' demands that all other bits be zero. */
169 rei_frame
->ps
= (usp_align
<< 56) | (3 << 3); /* XXX low 3 bits??? */
171 /* Restore the other general registers: everything except $2..$7, which
172 are in the `rei' trap frame we set up above, and $30, which is the
173 SP which is popped by `rei'. */
198 /* Switch the stack pointer to the trap frame set up on
199 the user stack and do the magical `rei' PAL call. */
200 asm volatile ("mov %0, $30\n"
202 : : "r" (rei_frame
), "i" (63)); /* PAL_rti */
204 asm volatile ("halt");
211 weak_alias (__sigreturn
, sigreturn
)