1 /* Return from signal handler in GNU C library for Hurd. Alpha version.
2 Copyright (C) 1994, 1995 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
21 #include <hurd/signal.h>
22 #include <hurd/threadvar.h>
26 #include <mach/machine/alpha_instruction.h>
29 __sigreturn (struct sigcontext
*scp
)
31 struct hurd_sigstate
*ss
;
32 mach_port_t
*reply_port
;
34 if (scp
== NULL
|| (scp
->sc_mask
& _SIG_CANT_MASK
))
40 ss
= _hurd_self_sigstate ();
41 __spin_lock (&ss
->lock
);
43 /* Restore the set of blocked signals, and the intr_port slot. */
44 ss
->blocked
= scp
->sc_mask
;
45 ss
->intr_port
= scp
->sc_intr_port
;
47 /* Check for pending signals that were blocked by the old set. */
48 if (ss
->pending
& ~ss
->blocked
)
50 /* There are pending signals that just became unblocked. Wake up the
51 signal thread to deliver them. But first, squirrel away SCP where
52 the signal thread will notice it if it runs another handler, and
53 arrange to have us called over again in the new reality. */
55 /* Clear the intr_port slot, since we are not in fact doing
56 an interruptible RPC right now. If SS->intr_port is not null,
57 the SCP context is doing an interruptible RPC, but the signal
58 thread will examine us while we are blocked in the sig_post RPC. */
59 ss
->intr_port
= MACH_PORT_NULL
;
60 __spin_unlock (&ss
->lock
);
61 __msg_sig_post (_hurd_msgport
, 0, __mach_task_self ());
62 /* If a pending signal was handled, sig_post never returned. */
63 __spin_lock (&ss
->lock
);
68 ss
->sigaltstack
.ss_flags
&= ~SA_ONSTACK
; /* XXX threadvars */
69 /* XXX cannot unlock until off sigstack */
73 __spin_unlock (&ss
->lock
);
75 /* Destroy the MiG reply port used by the signal handler, and restore the
76 reply port in use by the thread when interrupted. */
78 (mach_port_t
*) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY
);
80 __mach_port_destroy (__mach_task_self (), *reply_port
);
81 *reply_port
= scp
->sc_reply_port
;
85 /* Restore FPU state. */
87 /* Restore the floating-point control/status register.
88 We must do this first because the compiler will need
89 a temporary FP register for the load. */
90 asm volatile ("mt_fpcr %0" : : "f" (scp
->sc_fpcsr
));
92 /* Restore floating-point registers. */
93 #define restore_fpr(n) \
94 asm volatile ("ldt $f" #n ",%0" : : "m" (scp->sc_fpregs[n]))
128 /* Load all the registers from the sigcontext. */
129 #define restore_gpr(n) \
130 asm volatile ("ldq $" #n ",%0" : : "m" (scpreg->sc_regs[n]))
133 /* The `rei' PAL pseudo-instruction restores registers $2..$7, the PC
134 and processor status. So we can use these few registers for our
135 working variables. Unfortunately, it finds its data on the stack
136 and merely pops the SP ($30) over the words of state restored,
137 allowing no other option for the new SP value. So we must push the
138 registers and PSW it will to restore, onto the user's stack and let
139 it pop them from there. */
140 register const struct sigcontext
*const scpreg
asm ("$2") = scp
;
141 register integer_t
*usp
asm ("$3") = (integer_t
*) scpreg
->sc_regs
[30];
142 register integer_t usp_align
asm ("$4");
144 /* Push an 8-word "trap frame" onto the user stack for `rei':
145 registers $2..$7, the PC, and the PSW. */
147 register struct rei_frame
149 integer_t regs
[5], pc
, ps
;
150 } *rei_frame
asm ("$5");
153 /* `rei' demands that the stack be aligned to a 64 byte (8 word)
154 boundary; bits 61..56 of the PSW are OR'd back into the SP value
155 after popping the 8-word trap frame, so we store (sp % 64)
156 there and this restores the original user SP. */
157 usp_align
= (integer_t
) usp
& 63L;
158 rei_frame
= (void *) ((integer_t
) usp
& ~63L);
160 /* Copy the registers and PC from the sigcontext. */
161 memcpy (rei_frame
->regs
, &scpreg
->sc_regs
[2], sizeof rei_frame
->regs
);
162 rei_frame
->pc
= scpreg
->sc_pc
;
164 /* Compute the new PS value to be restored. `rei' adds the value at
165 bits 61..56 to the SP to compensate for the alignment above that
166 cleared the low 6 bits; bits 5..3 are the new mode/privilege level
167 (must be >= current mode; 3 == user mode); bits 2..0 are "software",
168 unused by the processor or kernel (XXX should trampoline save these?
169 How?); in user mode, `rei' demands that all other bits be zero. */
170 rei_frame
->ps
= (usp_align
<< 56) | (3 << 3); /* XXX low 3 bits??? */
172 /* Restore the other general registers: everything except $2..$7, which
173 are in the `rei' trap frame we set up above, and $30, which is the
174 SP which is popped by `rei'. */
199 /* Switch the stack pointer to the trap frame set up on
200 the user stack and do the magical `rei' PAL call. */
201 asm volatile ("mov %0, $30\n"
203 : : "r" (rei_frame
), "i" (op_rei
));
205 asm volatile ("call_pal %0" : : "i" (op_halt
));
212 weak_alias (__sigreturn
, sigreturn
)