Module Name:    src
Committed By:   matt
Date:           Sat May 15 20:27:48 UTC 2010

Modified Files:
        src/sys/arch/mips/include [matt-nb5-mips64]: mips_opcode.h proc.h
            sysarch.h
        src/sys/arch/mips/mips [matt-nb5-mips64]: mips_emul.c sys_machdep.c

Log Message:
Add kernel support for MIPS TLS.  Use rdhwr rt, $29 as defined by the MIPS
TLS spec so that Linux MIPS binaries will work.  Use sysarch(MIPS_TINFOSET, v)
to set the pointer.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.12.96.1 src/sys/arch/mips/include/mips_opcode.h
cvs rdiff -u -r1.21.36.7 -r1.21.36.8 src/sys/arch/mips/include/proc.h
cvs rdiff -u -r1.8 -r1.8.96.1 src/sys/arch/mips/include/sysarch.h
cvs rdiff -u -r1.14.78.9 -r1.14.78.10 src/sys/arch/mips/mips/mips_emul.c
cvs rdiff -u -r1.33 -r1.33.28.1 src/sys/arch/mips/mips/sys_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/mips/include/mips_opcode.h
diff -u src/sys/arch/mips/include/mips_opcode.h:1.12 src/sys/arch/mips/include/mips_opcode.h:1.12.96.1
--- src/sys/arch/mips/include/mips_opcode.h:1.12	Sun Dec 11 12:18:09 2005
+++ src/sys/arch/mips/include/mips_opcode.h	Sat May 15 20:27:48 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: mips_opcode.h,v 1.12 2005/12/11 12:18:09 christos Exp $	*/
+/*	$NetBSD: mips_opcode.h,v 1.12.96.1 2010/05/15 20:27:48 matt Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -117,7 +117,7 @@
 #define OP_SPECIAL	000
 #define OP_BCOND	001
 #define OP_J		002
-#define	OP_JAL		003
+#define OP_JAL		003
 #define OP_BEQ		004
 #define OP_BNE		005
 #define OP_BLEZ		006
@@ -147,6 +147,7 @@
 #define OP_LDR		033		/* MIPS-II, for r4000 port */
 
 #define OP_SPECIAL2	034		/* QED opcodes */
+#define OP_SPECIAL3	037		/* QED opcodes */
 
 #define OP_LB		040
 #define OP_LH		041
@@ -255,6 +256,18 @@
 #define OP_MAD		000		/* QED */
 #define OP_MADU		001		/* QED */
 #define OP_MUL		002		/* QED */
+#define OP_MSUB		004		/* MIPS32/64 */
+#define OP_MSUBU	005		/* MIPS32/64 */
+#define OP_CLZ		040		/* MIPS32/64 */
+#define OP_CLO		041		/* MIPS32/64 */
+#define OP_DCLZ		044		/* MIPS32/64 */
+#define OP_DCLO		045		/* MIPS32/64 */
+
+/*
+ * Values for the 'func' field when 'op' == OP_SPECIAL3.
+ */
+#define OP_RDHWR	073		/* MIPS32/64 r2 */
+
 
 /*
  * Values for the 'func' field when 'op' == OP_BCOND.

Index: src/sys/arch/mips/include/proc.h
diff -u src/sys/arch/mips/include/proc.h:1.21.36.7 src/sys/arch/mips/include/proc.h:1.21.36.8
--- src/sys/arch/mips/include/proc.h:1.21.36.7	Thu Mar 11 08:12:37 2010
+++ src/sys/arch/mips/include/proc.h	Sat May 15 20:27:48 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: proc.h,v 1.21.36.7 2010/03/11 08:12:37 matt Exp $	*/
+/*	$NetBSD: proc.h,v 1.21.36.8 2010/05/15 20:27:48 matt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -57,6 +57,7 @@
 	vaddr_t	md_ss_addr;		/* single step address for ptrace */
 	int	md_ss_instr;		/* single step instruction for ptrace */
 	volatile u_int md_astpending;	/* AST pending on return to userland */
+	register_t md_tinfo;		/* thread info (TLS) */
 };
 
 struct mdproc {

Index: src/sys/arch/mips/include/sysarch.h
diff -u src/sys/arch/mips/include/sysarch.h:1.8 src/sys/arch/mips/include/sysarch.h:1.8.96.1
--- src/sys/arch/mips/include/sysarch.h:1.8	Sun Dec 11 12:18:09 2005
+++ src/sys/arch/mips/include/sysarch.h	Sat May 15 20:27:48 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysarch.h,v 1.8 2005/12/11 12:18:09 christos Exp $ */
+/*	$NetBSD: sysarch.h,v 1.8.96.1 2010/05/15 20:27:48 matt Exp $ */
 
 #ifndef _MIPS_SYSARCH_H_
 #define _MIPS_SYSARCH_H_
@@ -8,6 +8,7 @@
  */
 #define MIPS_CACHEFLUSH	0
 #define MIPS_CACHECTL	1
+#define MIPS_TINFOSET	2
 
 struct mips_cacheflush_args {
 	vaddr_t va;

Index: src/sys/arch/mips/mips/mips_emul.c
diff -u src/sys/arch/mips/mips/mips_emul.c:1.14.78.9 src/sys/arch/mips/mips/mips_emul.c:1.14.78.10
--- src/sys/arch/mips/mips/mips_emul.c:1.14.78.9	Mon Feb  1 04:16:19 2010
+++ src/sys/arch/mips/mips/mips_emul.c	Sat May 15 20:27:48 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: mips_emul.c,v 1.14.78.9 2010/02/01 04:16:19 matt Exp $ */
+/*	$NetBSD: mips_emul.c,v 1.14.78.10 2010/05/15 20:27:48 matt Exp $ */
 
 /*
  * Copyright (c) 1999 Shuichiro URATA.  All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mips_emul.c,v 1.14.78.9 2010/02/01 04:16:19 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mips_emul.c,v 1.14.78.10 2010/05/15 20:27:48 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -57,6 +57,7 @@
 void	MachEmulateLWC0(uint32_t, struct trapframe *, uint32_t);
 void	MachEmulateSWC0(uint32_t, struct trapframe *, uint32_t);
 void	MachEmulateSpecial(uint32_t, struct trapframe *, uint32_t);
+void	MachEmulateSpecial3(uint32_t, struct trapframe *, uint32_t);
 void	MachEmulateLWC1(uint32_t, struct trapframe *, uint32_t);
 void	MachEmulateLDC1(uint32_t, struct trapframe *, uint32_t);
 void	MachEmulateSWC1(uint32_t, struct trapframe *, uint32_t);
@@ -243,6 +244,9 @@
 	case OP_SPECIAL:
 		MachEmulateSpecial(inst, tf, cause);
 		break;
+	case OP_SPECIAL3:
+		MachEmulateSpecial3(inst, tf, cause);
+		break;
 	case OP_COP1:
 #if defined(FPEMUL)
 		MachEmulateFP(inst, &tf->tf_registers, cause);
@@ -414,9 +418,37 @@
 		tf->tf_regs[_R_CAUSE] = cause;
 		tf->tf_regs[_R_BADVADDR] = tf->tf_regs[_R_PC];
 		KSI_INIT_TRAP(&ksi);
-		ksi.ksi_signo = SIGSEGV;
+		ksi.ksi_signo = SIGILL;
+		ksi.ksi_trap = cause;
+		ksi.ksi_code = ILL_ILLOPC;
+		ksi.ksi_addr = (void *)(intptr_t)tf->tf_regs[_R_PC];
+		(*curproc->p_emul->e_trapsignal)(curlwp, &ksi);
+		break;
+	}
+
+	update_pc(tf, cause);
+}
+
+void
+MachEmulateSpecial3(uint32_t inst, struct trapframe *tf, uint32_t cause)
+{
+	ksiginfo_t ksi;
+	switch (((InstFmt)inst).RType.func) {
+	case OP_RDHWR:
+		switch (((InstFmt)inst).RType.rd) {
+		case 29:
+			tf->tf_regs[((InstFmt)inst).RType.rt] =
+			    curlwp->l_md.md_tinfo;
+			break;
+		}
+		/* FALLTHROUGH */
+	default:
+		tf->tf_regs[_R_CAUSE] = cause;
+		tf->tf_regs[_R_BADVADDR] = tf->tf_regs[_R_PC];
+		KSI_INIT_TRAP(&ksi);
+		ksi.ksi_signo = SIGILL;
 		ksi.ksi_trap = cause;
-		ksi.ksi_code = SEGV_MAPERR;
+		ksi.ksi_code = ILL_ILLOPC;
 		ksi.ksi_addr = (void *)(intptr_t)tf->tf_regs[_R_PC];
 		(*curproc->p_emul->e_trapsignal)(curlwp, &ksi);
 		break;

Index: src/sys/arch/mips/mips/sys_machdep.c
diff -u src/sys/arch/mips/mips/sys_machdep.c:1.33 src/sys/arch/mips/mips/sys_machdep.c:1.33.28.1
--- src/sys/arch/mips/mips/sys_machdep.c:1.33	Thu Dec 20 23:02:41 2007
+++ src/sys/arch/mips/mips/sys_machdep.c	Sat May 15 20:27:48 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_machdep.c,v 1.33 2007/12/20 23:02:41 dsl Exp $	*/
+/*	$NetBSD: sys_machdep.c,v 1.33.28.1 2010/05/15 20:27:48 matt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.33 2007/12/20 23:02:41 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.33.28.1 2010/05/15 20:27:48 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -86,6 +86,10 @@
 		error = mips_user_cachectl(p, ccua.va, ccua.nbytes, ccua.ctl);
 		break;
 	}
+	case MIPS_TINFOSET: {
+		curlwp->l_md.md_tinfo = (intptr_t)SCARG(uap, parms);
+		break;
+	}
 	default:
 		error = ENOSYS;
 		break;

Reply via email to