summaryrefslogtreecommitdiff
path: root/sysdeps/mach/hurd/alpha
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/mach/hurd/alpha')
-rw-r--r--sysdeps/mach/hurd/alpha/exc2signal.c76
-rw-r--r--sysdeps/mach/hurd/alpha/longjmp-ctx.c38
-rw-r--r--sysdeps/mach/hurd/alpha/longjmp-ts.c41
-rw-r--r--sysdeps/mach/hurd/alpha/sigcontext.h65
-rw-r--r--sysdeps/mach/hurd/alpha/sigreturn.c212
-rw-r--r--sysdeps/mach/hurd/alpha/trampoline.c286
6 files changed, 718 insertions, 0 deletions
diff --git a/sysdeps/mach/hurd/alpha/exc2signal.c b/sysdeps/mach/hurd/alpha/exc2signal.c
new file mode 100644
index 0000000000..edac0aaa67
--- /dev/null
+++ b/sysdeps/mach/hurd/alpha/exc2signal.c
@@ -0,0 +1,76 @@
+/* Translate Mach exception codes into signal numbers. Alpha version.
+Copyright (C) 1994 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <hurd.h>
+#include <hurd/signal.h>
+#include <mach/exception.h>
+
+/* Translate the Mach exception codes, as received in an `exception_raise' RPC,
+ into a signal number and signal subcode. */
+
+void
+_hurd_exception2signal (int exception, int code, int subcode,
+ int *signo, long int *sigcode, int *error)
+{
+ *error = 0;
+
+ switch (exception)
+ {
+ default:
+ *signo = SIGIOT;
+ *sigcode = exception;
+ break;
+
+ case EXC_BAD_ACCESS:
+ if (code == KERN_PROTECTION_FAILURE)
+ *signo = SIGSEGV;
+ else
+ *signo = SIGBUS;
+ *sigcode = subcode;
+ *error = code;
+ break;
+
+ case EXC_BAD_INSTRUCTION:
+ *signo = SIGILL;
+ *sigcode = code;
+ break;
+
+ case EXC_ARITHMETIC:
+ *signo = SIGFPE;
+ *sigcode = code;
+ break;
+ break;
+
+ case EXC_EMULATION:
+ /* 3.0 doesn't give this one, why, I don't know. */
+ *signo = SIGEMT;
+ *sigcode = code;
+ break;
+
+ case EXC_SOFTWARE:
+ *signo = SIGEMT;
+ *sigcode = code;
+ break;
+
+ case EXC_BREAKPOINT:
+ *signo = SIGTRAP;
+ *sigcode = code;
+ break;
+ }
+}
diff --git a/sysdeps/mach/hurd/alpha/longjmp-ctx.c b/sysdeps/mach/hurd/alpha/longjmp-ctx.c
new file mode 100644
index 0000000000..dfc16fdfe4
--- /dev/null
+++ b/sysdeps/mach/hurd/alpha/longjmp-ctx.c
@@ -0,0 +1,38 @@
+/* Perform a `longjmp' on a `struct sigcontext'. Alpha version.
+Copyright (C) 1994 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <setjmp.h>
+#include <hurd/signal.h>
+#include <string.h>
+
+void
+_hurd_longjmp_sigcontext (struct sigcontext *scp, jmp_buf env, int retval)
+{
+ memset (scp, 0, sizeof (*scp));
+ scp->sc_regs[9] = env[0].__9;
+ scp->sc_regs[11] = env[0].__11;
+ scp->sc_regs[12] = env[0].__12;
+ scp->sc_regs[13] = env[0].__13;
+ scp->sc_regs[14] = env[0].__14;
+ scp->sc_regs[15] = (long int) env[0].__fp;
+ scp->sc_regs[30] = (long int) env[0].__sp;
+ scp->sc_pc = (long int) env[0].__pc;
+
+ memcpy (&scp->sc_fpregs[2], &env[0].__f2, sizeof (double));
+}
diff --git a/sysdeps/mach/hurd/alpha/longjmp-ts.c b/sysdeps/mach/hurd/alpha/longjmp-ts.c
new file mode 100644
index 0000000000..ad6f80cdb0
--- /dev/null
+++ b/sysdeps/mach/hurd/alpha/longjmp-ts.c
@@ -0,0 +1,41 @@
+/* Perform a `longjmp' on a Mach thread_state. Alpha version.
+Copyright (C) 1991, 1994 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <hurd/signal.h>
+#include <setjmp.h>
+#include <mach/thread_status.h>
+
+
+/* Set up STATE to do the equivalent of `longjmp (ENV, VAL);'. */
+
+void
+_hurd_longjmp_thread_state (void *state, jmp_buf env, int val)
+{
+ struct alpha_thread_state *ts = state;
+
+ ts->r9 = env[0].__jmpbuf[0].__9;
+ ts->r11 = env[0].__jmpbuf[0].__11;
+ ts->r12 = env[0].__jmpbuf[0].__12;
+ ts->r13 = env[0].__jmpbuf[0].__13;
+ ts->r14 = env[0].__jmpbuf[0].__14;
+ ts->r15 = (long int) env[0].__jmpbuf[0].__fp;
+ ts->r30 = (long int) env[0].__jmpbuf[0].__sp;
+ ts->pc = (long int) env[0].__jmpbuf[0].__pc;
+ ts->r0 = val ?: 1;
+}
diff --git a/sysdeps/mach/hurd/alpha/sigcontext.h b/sysdeps/mach/hurd/alpha/sigcontext.h
new file mode 100644
index 0000000000..32e0c94f98
--- /dev/null
+++ b/sysdeps/mach/hurd/alpha/sigcontext.h
@@ -0,0 +1,65 @@
+/* Machine-dependent signal context structure for GNU Hurd. Alpha version.
+Copyright (C) 1994 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+/* Signal handlers are actually called:
+ void handler (int sig, int code, struct sigcontext *scp); */
+
+/* State of this thread when the signal was taken. */
+struct sigcontext
+ {
+ /* These first members are machine-independent. */
+
+ long int sc_onstack; /* Nonzero if running on sigstack. */
+ __sigset_t sc_mask; /* Blocked signals to restore. */
+
+ /* MiG reply port this thread is using. */
+ unsigned long int sc_reply_port;
+
+ /* Port this thread is doing an interruptible RPC on. */
+ unsigned long int sc_intr_port;
+
+ /* Error code associated with this signal (interpreted as `error_t'). */
+ int sc_error;
+
+ /* All following members are machine-dependent. The rest of this
+ structure is written to be laid out identically to:
+ {
+ struct alpha_thread_state basic;
+ struct alpha_exc_state exc;
+ struct alpha_float_state fpu;
+ }
+ trampoline.c knows this, so it must be changed if this changes. */
+
+#define sc_alpha_thread_state sc_regs /* Beginning of correspondence. */
+ long int sc_regs[31]; /* General registers $0..$30. */
+ long int sc_pc; /* Program counter. */
+
+ /* struct alpha_exc_state */
+#define sc_alpha_exc_state sc_badvaddr
+ unsigned long int sc_badvaddr;
+ unsigned int sc_cause; /* Machine-level trap code. */
+#define SC_CAUSE_SET_SSTEP 1
+ int sc_used_fpa; /* Nonzero if FPU was used. */
+
+ /* struct alpha_float_state
+ This is only filled in if sc_used_fpa is nonzero. */
+#define sc_alpha_float_state sc_fpregs
+ double sc_fpregs[31]; /* Floating point registers $f0..$f30. */
+ long int sc_fpcsr; /* Floating point control/status register. */
+ };
diff --git a/sysdeps/mach/hurd/alpha/sigreturn.c b/sysdeps/mach/hurd/alpha/sigreturn.c
new file mode 100644
index 0000000000..e5dc383a3a
--- /dev/null
+++ b/sysdeps/mach/hurd/alpha/sigreturn.c
@@ -0,0 +1,212 @@
+/* Return from signal handler in GNU C library for Hurd. Alpha version.
+Copyright (C) 1994, 1995 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <hurd.h>
+#include <hurd/signal.h>
+#include <hurd/threadvar.h>
+#include <hurd/msg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mach/machine/alpha_instruction.h>
+
+int
+__sigreturn (struct sigcontext *scp)
+{
+ struct hurd_sigstate *ss;
+ mach_port_t *reply_port;
+
+ if (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ ss = _hurd_self_sigstate ();
+ __spin_lock (&ss->lock);
+
+ /* Restore the set of blocked signals, and the intr_port slot. */
+ ss->blocked = scp->sc_mask;
+ ss->intr_port = scp->sc_intr_port;
+
+ /* Check for pending signals that were blocked by the old set. */
+ if (ss->pending & ~ss->blocked)
+ {
+ /* There are pending signals that just became unblocked. Wake up the
+ signal thread to deliver them. But first, squirrel away SCP where
+ the signal thread will notice it if it runs another handler, and
+ arrange to have us called over again in the new reality. */
+ ss->context = scp;
+ /* Clear the intr_port slot, since we are not in fact doing
+ an interruptible RPC right now. If SS->intr_port is not null,
+ the SCP context is doing an interruptible RPC, but the signal
+ thread will examine us while we are blocked in the sig_post RPC. */
+ ss->intr_port = MACH_PORT_NULL;
+ __spin_unlock (&ss->lock);
+ __msg_sig_post (_hurd_msgport, 0, __mach_task_self ());
+ /* If a pending signal was handled, sig_post never returned. */
+ __spin_lock (&ss->lock);
+ }
+
+ if (scp->sc_onstack)
+ {
+ ss->sigaltstack.ss_flags &= ~SA_ONSTACK; /* XXX threadvars */
+ /* XXX cannot unlock until off sigstack */
+ abort ();
+ }
+ else
+ __spin_unlock (&ss->lock);
+
+ /* Destroy the MiG reply port used by the signal handler, and restore the
+ reply port in use by the thread when interrupted. */
+ reply_port =
+ (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY);
+ if (*reply_port)
+ __mach_port_destroy (__mach_task_self (), *reply_port);
+ *reply_port = scp->sc_reply_port;
+
+ if (scp->sc_used_fpa)
+ {
+ /* Restore FPU state. */
+
+ /* Restore the floating-point control/status register.
+ We must do this first because the compiler will need
+ a temporary FP register for the load. */
+ asm volatile ("mt_fpcr %0" : : "f" (scp->sc_fpcsr));
+
+ /* Restore floating-point registers. */
+#define restore_fpr(n) \
+ asm volatile ("ldt $f" #n ",%0" : : "m" (scp->sc_fpregs[n]))
+ restore_fpr (0);
+ restore_fpr (1);
+ restore_fpr (2);
+ restore_fpr (3);
+ restore_fpr (4);
+ restore_fpr (5);
+ restore_fpr (6);
+ restore_fpr (7);
+ restore_fpr (8);
+ restore_fpr (9);
+ restore_fpr (10);
+ restore_fpr (11);
+ restore_fpr (12);
+ restore_fpr (13);
+ restore_fpr (14);
+ restore_fpr (15);
+ restore_fpr (16);
+ restore_fpr (17);
+ restore_fpr (18);
+ restore_fpr (19);
+ restore_fpr (20);
+ restore_fpr (21);
+ restore_fpr (22);
+ restore_fpr (23);
+ restore_fpr (24);
+ restore_fpr (25);
+ restore_fpr (26);
+ restore_fpr (27);
+ restore_fpr (28);
+ restore_fpr (29);
+ restore_fpr (30);
+ }
+
+ /* Load all the registers from the sigcontext. */
+#define restore_gpr(n) \
+ asm volatile ("ldq $" #n ",%0" : : "m" (scpreg->sc_regs[n]))
+
+ {
+ /* The `rei' PAL pseudo-instruction restores registers $2..$7, the PC
+ and processor status. So we can use these few registers for our
+ working variables. Unfortunately, it finds its data on the stack
+ and merely pops the SP ($30) over the words of state restored,
+ allowing no other option for the new SP value. So we must push the
+ registers and PSW it will to restore, onto the user's stack and let
+ it pop them from there. */
+ register const struct sigcontext *const scpreg asm ("$2") = scp;
+ register integer_t *usp asm ("$3") = (integer_t *) scpreg->sc_regs[30];
+ register integer_t usp_align asm ("$4");
+
+ /* Push an 8-word "trap frame" onto the user stack for `rei':
+ registers $2..$7, the PC, and the PSW. */
+
+ register struct rei_frame
+ {
+ integer_t regs[5], pc, ps;
+ } *rei_frame asm ("$5");
+
+ usp -= 8;
+ /* `rei' demands that the stack be aligned to a 64 byte (8 word)
+ boundary; bits 61..56 of the PSW are OR'd back into the SP value
+ after popping the 8-word trap frame, so we store (sp % 64)
+ there and this restores the original user SP. */
+ usp_align = (integer_t) usp & 63L;
+ rei_frame = (void *) ((integer_t) usp & ~63L);
+
+ /* Copy the registers and PC from the sigcontext. */
+ memcpy (rei_frame->regs, &scpreg->sc_regs[2], sizeof rei_frame->regs);
+ rei_frame->pc = scpreg->sc_pc;
+
+ /* Compute the new PS value to be restored. `rei' adds the value at
+ bits 61..56 to the SP to compensate for the alignment above that
+ cleared the low 6 bits; bits 5..3 are the new mode/privilege level
+ (must be >= current mode; 3 == user mode); bits 2..0 are "software",
+ unused by the processor or kernel (XXX should trampoline save these?
+ How?); in user mode, `rei' demands that all other bits be zero. */
+ rei_frame->ps = (usp_align << 56) | (3 << 3); /* XXX low 3 bits??? */
+
+ /* Restore the other general registers: everything except $2..$7, which
+ are in the `rei' trap frame we set up above, and $30, which is the
+ SP which is popped by `rei'. */
+ restore_gpr (1);
+ restore_gpr (8);
+ restore_gpr (9);
+ restore_gpr (10);
+ restore_gpr (11);
+ restore_gpr (12);
+ restore_gpr (13);
+ restore_gpr (14);
+ restore_gpr (15);
+ restore_gpr (16);
+ restore_gpr (17);
+ restore_gpr (18);
+ restore_gpr (19);
+ restore_gpr (20);
+ restore_gpr (21);
+ restore_gpr (22);
+ restore_gpr (23);
+ restore_gpr (24);
+ restore_gpr (25);
+ restore_gpr (26);
+ restore_gpr (27);
+ restore_gpr (28);
+ restore_gpr (29);
+
+ /* Switch the stack pointer to the trap frame set up on
+ the user stack and do the magical `rei' PAL call. */
+ asm volatile ("mov %0, $30\n"
+ "call_pal %1"
+ : : "r" (rei_frame), "i" (op_rei));
+ /* Firewall. */
+ asm volatile ("call_pal %0" : : "i" (op_halt));
+ }
+
+ /* NOTREACHED */
+ return -1;
+}
+
+weak_alias (__sigreturn, sigreturn)
diff --git a/sysdeps/mach/hurd/alpha/trampoline.c b/sysdeps/mach/hurd/alpha/trampoline.c
new file mode 100644
index 0000000000..85f4964e14
--- /dev/null
+++ b/sysdeps/mach/hurd/alpha/trampoline.c
@@ -0,0 +1,286 @@
+/* Set thread_state for sighandler, and sigcontext to recover. Alpha version.
+Copyright (C) 1994 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <hurd/signal.h>
+#include "thread_state.h"
+#include <mach/machine/alpha_instruction.h>
+#include "hurdfault.h"
+#include <assert.h>
+
+struct mach_msg_trap_args
+ {
+ /* This is the order of arguments to mach_msg_trap. */
+ mach_msg_header_t *msg;
+ mach_msg_option_t option;
+ mach_msg_size_t send_size;
+ mach_msg_size_t rcv_size;
+ mach_port_t rcv_name;
+ mach_msg_timeout_t timeout;
+ mach_port_t notify;
+ };
+
+
+struct sigcontext *
+_hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler,
+ int signo, long int sigcode,
+ int rpc_wait,
+ struct machine_thread_all_state *state)
+{
+ __label__ trampoline, rpc_wait_trampoline;
+ void *sigsp;
+ struct sigcontext *scp;
+
+ if (ss->context)
+ {
+ /* We have a previous sigcontext that sigreturn was about
+ to restore when another signal arrived. We will just base
+ our setup on that. */
+ if (_hurdsig_catch_fault (SIGSEGV))
+ assert (_hurdsig_fault_sigcode >= (long int) ss->context &&
+ _hurdsig_fault_sigcode < (long int) (ss->context + 1));
+ else
+ {
+ memcpy (&state->basic, &ss->context->sc_alpha_thread_state,
+ sizeof (state->basic));
+ memcpy (&state->exc, &ss->context->sc_alpha_exc_state,
+ sizeof (state->exc));
+ state->set = (1 << ALPHA_THREAD_STATE) | (1 << ALPHA_EXC_STATE);
+ if (state->exc.used_fpa)
+ {
+ memcpy (&state->fpu, &ss->context->sc_alpha_float_state,
+ sizeof (state->fpu));
+ state->set |= (1 << ALPHA_FLOAT_STATE);
+ }
+ assert (! rpc_wait);
+ /* The intr_port slot was cleared before sigreturn sent us the
+ sig_post that made us notice this pending signal, so
+ _hurd_internal_post_signal wouldn't do interrupt_operation.
+ After we return, our caller will set SCP->sc_intr_port (in the
+ new context) from SS->intr_port and clear SS->intr_port. Now
+ that we are restoring this old context recorded by sigreturn,
+ we want to restore its intr_port too; so store it in
+ SS->intr_port now, so it will end up in SCP->sc_intr_port
+ later. */
+ ss->intr_port = ss->context->sc_intr_port;
+ }
+ /* If the sigreturn context was bogus, just ignore it. */
+ ss->context = NULL;
+ }
+ else if (! machine_get_basic_state (ss->thread, state))
+ return NULL;
+
+ if ((ss->actions[signo].sa_flags & SA_ONSTACK) &&
+ !(ss->sigaltstack.ss_flags & (SA_DISABLE|SA_ONSTACK)))
+ {
+ sigsp = ss->sigaltstack.ss_sp + ss->sigaltstack.ss_size;
+ ss->sigaltstack.ss_flags |= SA_ONSTACK;
+ /* XXX need to set up base of new stack for
+ per-thread variables, cthreads. */
+ }
+ else
+ sigsp = (char *) state->basic.SP;
+
+ /* Set up the sigcontext structure on the stack. This is all the stack
+ needs, since the args are passed in registers (below). */
+ sigsp -= sizeof (*scp);
+ scp = sigsp;
+
+ if (_hurdsig_catch_fault (SIGSEGV))
+ {
+ assert (_hurdsig_fault_sigcode >= (long int) scp &&
+ _hurdsig_fault_sigcode < (long int) (scp + 1));
+ /* We got a fault trying to write the stack frame.
+ We cannot set up the signal handler.
+ Returning NULL tells our caller, who will nuke us with a SIGILL. */
+ return NULL;
+ }
+ else
+ {
+ /* Set up the sigcontext from the current state of the thread. */
+
+ scp->sc_onstack = ss->sigaltstack.ss_flags & SA_ONSTACK ? 1 : 0;
+
+ /* struct sigcontext is laid out so that starting at sc_regs
+ mimics a struct alpha_thread_state. */
+ memcpy (&scp->sc_alpha_thread_state,
+ &state->basic, sizeof (state->basic));
+
+ /* struct sigcontext is laid out so that starting at sc_badvaddr
+ mimics a struct mips_exc_state. */
+ if (! machine_get_state (ss->thread, state, ALPHA_EXC_STATE,
+ &state->exc, &scp->sc_alpha_exc_state,
+ sizeof (state->exc)))
+ return NULL;
+
+ if (state->exc.used_fpa &&
+ /* struct sigcontext is laid out so that starting at sc_fpregs
+ mimics a struct alpha_float_state. This state
+ is only meaningful if the coprocessor was used. */
+ ! machine_get_state (ss->thread, state, ALPHA_FLOAT_STATE,
+ &state->fpu,
+ &scp->sc_alpha_float_state,
+ sizeof (state->fpu)))
+ return NULL;
+ }
+
+ /* Modify the thread state to call the trampoline code on the new stack. */
+ if (rpc_wait)
+ {
+ /* The signalee thread was blocked in a mach_msg_trap system call,
+ still waiting for a reply. We will have it run the special
+ trampoline code which retries the message receive before running
+ the signal handler.
+
+ To do this we change the OPTION argument in its registers to
+ enable only message reception, since the request message has
+ already been sent. */
+
+ /* The system call arguments are stored in consecutive registers
+ starting with a0 ($16). */
+ struct mach_msg_trap_args *args = (void *) &state->basic.r16;
+
+ assert (args->option & MACH_RCV_MSG);
+ /* Disable the message-send, since it has already completed. The
+ calls we retry need only wait to receive the reply message. */
+ args->option &= ~MACH_SEND_MSG;
+
+ state->basic.pc = (long int) &&rpc_wait_trampoline;
+ /* After doing the message receive, the trampoline code will need to
+ update the v0 ($0) value to be restored by sigreturn. To simplify
+ the assembly code, we pass the address of its slot in SCP to the
+ trampoline code in at ($28). */
+ state->basic.r28 = (long int) &scp->sc_regs[0];
+ /* We must preserve the mach_msg_trap args in a0..a5 and t0
+ ($16..$21, $1). Pass the handler args to the trampoline code in
+ t8..t10 ($22.$24). */
+ state->basic.r22 = signo;
+ state->basic.r23 = sigcode;
+ state->basic.r24 = (long int) scp;
+ }
+ else
+ {
+ state->basic.pc = (long int) &&trampoline;
+ state->basic.r16 = signo;
+ state->basic.r17 = sigcode;
+ state->basic.r18 = (long int) scp;
+ }
+
+ state->basic.r30 = (long int) sigsp; /* $30 is the stack pointer. */
+
+ /* We pass the handler function to the trampoline code in ra ($26). */
+ state->basic.r26 = (long int) handler;
+ /* In the callee-saved register t12/pv ($27), we store the
+ address of __sigreturn itself, for the trampoline code to use. */
+ state->basic.r27 = (long int) &__sigreturn;
+ /* In the callee-saved register t11/ai ($25), we save the SCP value to pass
+ to __sigreturn after the handler returns. */
+ state->basic.r25 = (long int) scp;
+
+ return scp;
+
+ /* The trampoline code follows. This is not actually executed as part of
+ this function, it is just convenient to write it that way. */
+
+ rpc_wait_trampoline:
+ /* This is the entry point when we have an RPC reply message to receive
+ before running the handler. The MACH_MSG_SEND bit has already been
+ cleared in the OPTION argument in our registers. For our convenience,
+ at ($28) points to the sc_regs[0] member of the sigcontext (saved v0
+ ($0)). */
+ asm volatile
+ (/* Retry the interrupted mach_msg system call. */
+ "lda $0, -25($31)\n" /* mach_msg_trap */
+ "call_pal %0\n" /* Magic system call instruction. */
+ /* When the sigcontext was saved, v0 was MACH_RCV_INTERRUPTED. But
+ now the message receive has completed and the original caller of
+ the RPC (i.e. the code running when the signal arrived) needs to
+ see the final return value of the message receive in v0. So
+ store the new v0 value into the sc_regs[0] member of the sigcontext
+ (whose address is in at to make this code simpler). */
+ "stq $0, 0($28)\n"
+ /* Since the argument registers needed to have the mach_msg_trap
+ arguments, we've stored the arguments to the handler function
+ in registers t8..t10 ($22..$24). */
+ "mov $22, $16\n"
+ "mov $23, $17\n"
+ "mov $24, $18\n"
+ : : "i" (op_chmk));
+
+ trampoline:
+ /* Entry point for running the handler normally. The arguments to the
+ handler function are already in the standard registers:
+
+ a0 SIGNO
+ a1 SIGCODE
+ a2 SCP
+
+ t12 also contains SCP; this value is callee-saved (and so should not get
+ clobbered by running the handler). We use this saved value to pass to
+ __sigreturn, so the handler can clobber the argument registers if it
+ likes. */
+ /* Call the handler function, saving return address in ra ($26). */
+ asm volatile ("jsr $26, ($26)");
+ /* Reset gp ($29) from the return address (here) in ra ($26). */
+ asm volatile ("ldgp $29, 0($26)");
+ asm volatile ("mov $25, $16"); /* Move saved SCP to argument register. */
+ /* Call __sigreturn (SCP); this cannot return. */
+ asm volatile ("jmp $31, ($27)");
+
+ /* NOTREACHED */
+ return NULL;
+}
+
+/* STATE describes a thread that had intr_port set (meaning it was inside
+ HURD_EINTR_RPC), after it has been thread_abort'd. If it looks to have
+ just completed a mach_msg_trap system call that returned
+ MACH_RCV_INTERRUPTED, return nonzero and set *PORT to the receive right
+ being waited on. */
+int
+_hurdsig_rcv_interrupted_p (struct machine_thread_all_state *state,
+ mach_port_t *port)
+{
+ if (state->basic.r0 == MACH_RCV_INTERRUPTED)
+ {
+ const unsigned int *pc = (void *) state->basic.pc;
+ struct mach_msg_trap_args *args = (void *) &state->basic.r16;
+
+ if (_hurdsig_catch_fault (SIGSEGV))
+ {
+ assert (_hurdsig_fault_sigcode == (long int) (pc - 1) ||
+ _hurdsig_fault_sigcode == (long int) &args->rcv_name);
+ /* We got a fault trying to read the PC or stack. */
+ return 0;
+ }
+ else
+ {
+ if (pc[-1] == ((alpha_instruction) { pal_format:
+ { opcode: op_pal,
+ function: op_chmk } }).bits)
+ {
+ /* We did just return from a mach_msg_trap system call
+ doing a message receive that was interrupted.
+ Examine the parameters to find the receive right. */
+ *port = args->rcv_name;
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}