Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Implement siginfo for sh3.
details: https://anonhg.NetBSD.org/src/rev/407e4c7d5331
branches: trunk
changeset: 555635:407e4c7d5331
user: uwe <uwe%NetBSD.org@localhost>
date: Sun Nov 23 23:13:11 2003 +0000
description:
Implement siginfo for sh3.
diffstat:
lib/libc/arch/sh3/Makefile.inc | 6 +-
lib/libc/arch/sh3/sys/__sigaction14_sigtramp.c | 25 +++-
lib/libc/arch/sh3/sys/__sigtramp2.S | 59 +++++++++
sys/arch/sh3/include/frame.h | 34 ++++-
sys/arch/sh3/include/signal.h | 9 +-
sys/arch/sh3/sh3/exception.c | 61 ++++++++-
sys/arch/sh3/sh3/sh3_machdep.c | 154 ++++++++++++++++++++----
7 files changed, 293 insertions(+), 55 deletions(-)
diffs (truncated from 586 to 300 lines):
diff -r d71ff202f943 -r 407e4c7d5331 lib/libc/arch/sh3/Makefile.inc
--- a/lib/libc/arch/sh3/Makefile.inc Sun Nov 23 19:20:25 2003 +0000
+++ b/lib/libc/arch/sh3/Makefile.inc Sun Nov 23 23:13:11 2003 +0000
@@ -1,11 +1,11 @@
-# $NetBSD: Makefile.inc,v 1.3 2002/07/10 04:29:08 thorpej Exp $
+# $NetBSD: Makefile.inc,v 1.4 2003/11/23 23:13:11 uwe Exp $
KMINCLUDES= arch/sh3/SYS.h
-CPPFLAGS+= -DSOFTFLOAT
+CPPFLAGS+= -DSOFTFLOAT # -DSOFTFLOAT_NEED_FIXUNS
.include <softfloat/Makefile.inc>
#KMSRCS= bcmp.S bzero.S ffs.S strcat.S strcmp.S strcpy.S strlen.S \
# htonl.S htons.S ntohl.S ntohs.S
-SRCS+= __sigaction14_sigtramp.c __sigtramp1.S
+SRCS+= __sigaction14_sigtramp.c __sigtramp1.S __sigtramp2.S
diff -r d71ff202f943 -r 407e4c7d5331 lib/libc/arch/sh3/sys/__sigaction14_sigtramp.c
--- a/lib/libc/arch/sh3/sys/__sigaction14_sigtramp.c Sun Nov 23 19:20:25 2003 +0000
+++ b/lib/libc/arch/sh3/sys/__sigaction14_sigtramp.c Sun Nov 23 23:13:11 2003 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: __sigaction14_sigtramp.c,v 1.2 2003/01/18 11:14:02 thorpej Exp $ */
+/* $NetBSD: __sigaction14_sigtramp.c,v 1.3 2003/11/23 23:13:11 uwe Exp $ */
/*-
- * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -40,6 +40,7 @@
#include <sys/types.h>
#include <signal.h>
+#include <errno.h>
#include "extern.h"
@@ -49,12 +50,24 @@
__libc_sigaction14(int sig, const struct sigaction *act, struct sigaction *oact)
{
extern int __sigtramp_sigcontext_1[];
+ extern int __sigtramp_siginfo_2[];
+ int rv;
/*
- * Right here we should select the SA_SIGINFO trampoline
- * if SA_SIGINFO is set in the sigaction.
+ * We select the compatibility SIGCONTEXT trampoline if SA_SIGINFO
+ * is not set in the sigaction.
*/
+ if (act && (act->sa_flags & SA_SIGINFO) == 0) {
+ rv = __sigaction_sigtramp(sig, act, oact,
+ __sigtramp_sigcontext_1, 1);
+ /*
+ * EINVAL might indicate that trampoline version 1 is
+ * not supported by the kernel; fall back on native
+ * SIGINFO trampoline.
+ */
+ if (rv >= 0 || errno != EINVAL)
+ return rv;
+ }
- return (__sigaction_sigtramp(sig, act, oact,
- __sigtramp_sigcontext_1, 1));
+ return __sigaction_sigtramp(sig, act, oact, __sigtramp_siginfo_2, 2);
}
diff -r d71ff202f943 -r 407e4c7d5331 lib/libc/arch/sh3/sys/__sigtramp2.S
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/arch/sh3/sys/__sigtramp2.S Sun Nov 23 23:13:11 2003 +0000
@@ -0,0 +1,59 @@
+/* $NetBSD: __sigtramp2.S,v 1.1 2003/11/23 23:13:11 uwe Exp $ */
+
+/*-
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "SYS.h"
+
+/*
+ * The SH signal trampoline is invoked only to return from
+ * the signal; the kernel calls the signal handler directly.
+ *
+ * On entry, stack looks like:
+ *
+ * siginfo structure
+ * sp-> ucontext structure
+ *
+ * NB: This order is different from what other ports use (siginfo at
+ * the top of the stack), because we want to avoid wasting two
+ * instructions to skip to the ucontext. Not that this order really
+ * matters, but I think this inconsistency deserves an explanation.
+ */
+NENTRY(__sigtramp_siginfo_2)
+ mov r15, r4 /* get pointer to ucontext */
+ SYSTRAP(setcontext) /* and call setcontext() */
+ mov r0, r4 /* exit with errno */
+ SYSTRAP(exit) /* if sigreturn fails */
diff -r d71ff202f943 -r 407e4c7d5331 sys/arch/sh3/include/frame.h
--- a/sys/arch/sh3/include/frame.h Sun Nov 23 19:20:25 2003 +0000
+++ b/sys/arch/sh3/include/frame.h Sun Nov 23 23:13:11 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: frame.h,v 1.11 2003/08/07 16:29:28 agc Exp $ */
+/* $NetBSD: frame.h,v 1.12 2003/11/23 23:13:11 uwe Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -128,12 +128,38 @@
};
/*
- * Signal frame
+ * Signal frame.
+ *
+ * NB: The order of sf_uc and sf_si is different from what other ports
+ * use (siginfo at the top of the stack), because we want to avoid
+ * wasting two instructions in __sigtramp_siginfo_2 to skip to the
+ * ucontext. Not that this order really matters, but I think this
+ * inconsistency deserves an explanation.
*/
-struct sigframe {
- struct sigcontext sf_sc;
+struct sigframe_siginfo {
+#if 0 /* in registers on entry to signal trampoline */
+ int sf_signum; /* r4 - "signum" argument for handler */
+ siginfo_t *sf_sip; /* r5 - "sip" argument for handler */
+ ucontext_t *sf_ucp; /* r6 - "ucp" argument for handler */
+#endif
+ ucontext_t sf_uc; /* actual saved ucontext */
+ siginfo_t sf_si; /* actual saved siginfo */
};
+#if defined(COMPAT_16) && defined(_KERNEL)
+/*
+ * Old signal frame format.
+ */
+struct sigframe_sigcontext {
+#if 0 /* in registers on entry to signal trampoline */
+ int sf_signum; /* r4 - "signum" argument for handler */
+ int sf_code; /* r5 - "code" argument for handler */
+ struct sigcontext *sf_scp; /* r6 - "scp" argument for handler */
+#endif
+ struct sigcontext sf_sc; /* actual saved context */
+};
+#endif
+
/*
* Scheduler activations upcall frame
*/
diff -r d71ff202f943 -r 407e4c7d5331 sys/arch/sh3/include/signal.h
--- a/sys/arch/sh3/include/signal.h Sun Nov 23 19:20:25 2003 +0000
+++ b/sys/arch/sh3/include/signal.h Sun Nov 23 23:13:11 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: signal.h,v 1.7 2003/08/07 16:29:29 agc Exp $ */
+/* $NetBSD: signal.h,v 1.8 2003/11/23 23:13:11 uwe Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
@@ -38,6 +38,13 @@
typedef int sig_atomic_t;
+#define __HAVE_SIGINFO
+#ifdef COMPAT_16
+#define SIGTRAMP_VALID(vers) ((unsigned)(vers) <= 2)
+#else
+#define SIGTRAMP_VALID(vers) ((vers) == 2)
+#endif
+
#if defined(_NETBSD_SOURCE)
/*
diff -r d71ff202f943 -r 407e4c7d5331 sys/arch/sh3/sh3/exception.c
--- a/sys/arch/sh3/sh3/exception.c Sun Nov 23 19:20:25 2003 +0000
+++ b/sys/arch/sh3/sh3/exception.c Sun Nov 23 23:13:11 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exception.c,v 1.15 2003/10/31 03:28:13 simonb Exp $ */
+/* $NetBSD: exception.c,v 1.16 2003/11/23 23:13:11 uwe Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -79,7 +79,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exception.c,v 1.15 2003/10/31 03:28:13 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exception.c,v 1.16 2003/11/23 23:13:11 uwe Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@@ -153,6 +153,7 @@
{
int expevt = tf->tf_expevt;
boolean_t usermode = !KERNELMODE(tf->tf_ssr);
+ ksiginfo_t ksi;
uvmexp.traps++;
@@ -169,12 +170,17 @@
/* Check for debugger break */
if (_reg_read_4(SH_(TRA)) == (_SH_TRA_BREAK << 2)) {
tf->tf_spc -= 2; /* back to the breakpoint address */
- trapsignal(l, SIGTRAP, tf->tf_expevt);
+ KSI_INIT_TRAP(&ksi);
+ ksi.ksi_signo = SIGTRAP;
+ ksi.ksi_code = TRAP_BRKPT;
+ ksi.ksi_addr = (void *)tf->tf_spc;
+ goto trapsignal;
} else {
syscall(l, tf);
return;
}
break;
+
case EXPEVT_ADDR_ERR_LD:
/*FALLTHROUGH*/
case EXPEVT_ADDR_ERR_ST:
@@ -187,18 +193,29 @@
case EXPEVT_ADDR_ERR_LD | EXP_USER:
/*FALLTHROUGH*/
case EXPEVT_ADDR_ERR_ST | EXP_USER:
- trapsignal(l, SIGSEGV, tf->tf_expevt);
- break;
+ KSI_INIT_TRAP(&ksi);
+ /* XXX: for kernel access attempt this should be a SIGSEGV */
+ ksi.ksi_signo = SIGBUS;
+ ksi.ksi_code = BUS_ADRALN;
+ ksi.ksi_addr = (void *)tf->tf_spc; /* XXX: use TEA */
+ goto trapsignal;
case EXPEVT_RES_INST | EXP_USER:
/*FALLTHROUGH*/
case EXPEVT_SLOT_INST | EXP_USER:
- trapsignal(l, SIGILL, tf->tf_expevt);
- break;
+ KSI_INIT_TRAP(&ksi);
+ ksi.ksi_signo = SIGILL;
+ ksi.ksi_code = ILL_ILLOPC; /* XXX: could be ILL_PRVOPC */
+ ksi.ksi_addr = (void *)tf->tf_spc;
+ goto trapsignal;
case EXPEVT_BREAK | EXP_USER:
- trapsignal(l, SIGTRAP, tf->tf_expevt);
- break;
+ KSI_INIT_TRAP(&ksi);
+ ksi.ksi_signo = SIGTRAP;
+ ksi.ksi_code = TRAP_BRKPT; /* XXX: ??? */
+ ksi.ksi_addr = (void *)tf->tf_spc;
+ goto trapsignal;
+
default:
goto do_panic;
}
@@ -207,6 +224,14 @@
userret(l);
return;
+ trapsignal:
+ ksi.ksi_trap = tf->tf_expevt;
+ KERNEL_PROC_LOCK(l);
+ trapsignal(l, &ksi);
+ KERNEL_PROC_UNLOCK(l);
+ userret(l);
+ return;
+
do_panic:
#ifdef DDB
Home |
Main Index |
Thread Index |
Old Index