Module Name: src
Committed By: uwe
Date: Fri Jan 28 21:06:09 UTC 2011
Modified Files:
src/sys/arch/sh3/include: ptrace.h userret.h
src/sys/arch/sh3/sh3: db_interface.c exception.c exception_vector.S
process_machdep.c sh3_machdep.c
Log Message:
Implement PT_STEP.
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/sh3/include/ptrace.h
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/sh3/include/userret.h
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/sh3/sh3/db_interface.c \
src/sys/arch/sh3/sh3/exception.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/sh3/sh3/exception_vector.S
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/sh3/sh3/process_machdep.c
cvs rdiff -u -r1.89 -r1.90 src/sys/arch/sh3/sh3/sh3_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/sh3/include/ptrace.h
diff -u src/sys/arch/sh3/include/ptrace.h:1.8 src/sys/arch/sh3/include/ptrace.h:1.9
--- src/sys/arch/sh3/include/ptrace.h:1.8 Mon Oct 27 23:50:12 2008
+++ src/sys/arch/sh3/include/ptrace.h Fri Jan 28 21:06:07 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: ptrace.h,v 1.8 2008/10/27 23:50:12 uwe Exp $ */
+/* $NetBSD: ptrace.h,v 1.9 2011/01/28 21:06:07 uwe Exp $ */
/*
* Copyright (c) 1993 Christopher G. Demetriou
@@ -37,6 +37,8 @@
* sh3-dependent ptrace definitions
*/
+#define PT_STEP (PT_FIRSTMACH + 0)
+
/* old struct reg (now struct __reg40) that was missing r_gbr */
#define PT___GETREGS40 (PT_FIRSTMACH + 1)
#define PT___SETREGS40 (PT_FIRSTMACH + 2)
@@ -45,7 +47,7 @@
#define PT_SETREGS (PT_FIRSTMACH + 4)
#define PT_MACHDEP_STRINGS \
- "(unused)", \
+ "PT_STEP", \
"PT___GETREGS40", \
"PT___SETREGS40", \
"PT_GETREGS", \
Index: src/sys/arch/sh3/include/userret.h
diff -u src/sys/arch/sh3/include/userret.h:1.10 src/sys/arch/sh3/include/userret.h:1.11
--- src/sys/arch/sh3/include/userret.h:1.10 Mon Nov 5 20:37:48 2007
+++ src/sys/arch/sh3/include/userret.h Fri Jan 28 21:06:07 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: userret.h,v 1.10 2007/11/05 20:37:48 ad Exp $ */
+/* $NetBSD: userret.h,v 1.11 2011/01/28 21:06:07 uwe Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -81,12 +81,39 @@
#include <sys/userret.h>
+#include <sh3/ubcreg.h>
+#include "opt_ptrace.h"
+
+
static __inline void
userret(struct lwp *l)
{
/* Invoke MI userret code */
mi_userret(l);
+
+#ifdef PTRACE
+ /* Check if lwp is being PT_STEP'ed */
+ if (l->l_md.md_flags & MDP_SSTEP) {
+ struct trapframe *tf = l->l_md.md_regs;
+
+ /*
+ * Channel A is set up for single stepping in sh_cpu_init().
+ * Before RTE we write tf_ubc to BBRA and tf_spc to BARA.
+ */
+#ifdef SH3
+ if (CPU_IS_SH3) {
+ tf->tf_ubc = UBC_CYCLE_INSN | UBC_CYCLE_READ
+ | SH3_UBC_CYCLE_CPU;
+ }
+#endif
+#ifdef SH4
+ if (CPU_IS_SH4) {
+ tf->tf_ubc = UBC_CYCLE_INSN | UBC_CYCLE_READ;
+ }
+#endif
+ }
+#endif /* PTRACE */
}
#endif /* !_SH3_USERRET_H_ */
Index: src/sys/arch/sh3/sh3/db_interface.c
diff -u src/sys/arch/sh3/sh3/db_interface.c:1.60 src/sys/arch/sh3/sh3/db_interface.c:1.61
--- src/sys/arch/sh3/sh3/db_interface.c:1.60 Wed Jan 26 18:43:30 2011
+++ src/sys/arch/sh3/sh3/db_interface.c Fri Jan 28 21:06:07 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: db_interface.c,v 1.60 2011/01/26 18:43:30 uwe Exp $ */
+/* $NetBSD: db_interface.c,v 1.61 2011/01/28 21:06:07 uwe Exp $ */
/*-
* Copyright (C) 2002 UCHIYAMA Yasushi. All rights reserved.
@@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.60 2011/01/26 18:43:30 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.61 2011/01/28 21:06:07 uwe Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@@ -227,35 +227,21 @@
db_set_single_step(db_regs_t *regs)
{
- _reg_write_2(SH_(BBRA), 0); /* disable break */
-
+ /*
+ * Channel A is set up for single stepping in sh_cpu_init().
+ * Before RTE we write tf_ubc to BBRA and tf_spc to BARA.
+ */
#ifdef SH3
if (CPU_IS_SH3) {
- /* A: compare all address bits */
- _reg_write_4(SH3_BAMRA, 0x00000000);
-
- /* A: break after execution, ignore ASID */
- _reg_write_4(SH3_BRCR, (UBC_CTL_A_AFTER_INSN
- | SH3_UBC_CTL_A_MASK_ASID));
-
- /* will be written to BBRA before RTE */
regs->tf_ubc = UBC_CYCLE_INSN | UBC_CYCLE_READ
| SH3_UBC_CYCLE_CPU;
}
-#endif /* SH3 */
-
+#endif
#ifdef SH4
if (CPU_IS_SH4) {
- /* A: compare all address bits, ignore ASID */
- _reg_write_1(SH4_BAMRA, SH4_UBC_MASK_NONE | SH4_UBC_MASK_ASID);
-
- /* A: break after execution */
- _reg_write_2(SH4_BRCR, UBC_CTL_A_AFTER_INSN);
-
- /* will be written to BBRA before RTE */
regs->tf_ubc = UBC_CYCLE_INSN | UBC_CYCLE_READ;
}
-#endif /* SH4 */
+#endif
}
void
Index: src/sys/arch/sh3/sh3/exception.c
diff -u src/sys/arch/sh3/sh3/exception.c:1.60 src/sys/arch/sh3/sh3/exception.c:1.61
--- src/sys/arch/sh3/sh3/exception.c:1.60 Thu Jan 27 01:01:55 2011
+++ src/sys/arch/sh3/sh3/exception.c Fri Jan 28 21:06:08 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: exception.c,v 1.60 2011/01/27 01:01:55 uwe Exp $ */
+/* $NetBSD: exception.c,v 1.61 2011/01/28 21:06:08 uwe Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc. All rights reserved.
@@ -79,7 +79,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exception.c,v 1.60 2011/01/27 01:01:55 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exception.c,v 1.61 2011/01/28 21:06:08 uwe Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@@ -185,6 +185,7 @@
break;
case EXPEVT_BREAK | EXP_USER:
+ l->l_md.md_flags &= ~MDP_SSTEP;
KSI_INIT_TRAP(&ksi);
ksi.ksi_signo = SIGTRAP;
ksi.ksi_code = TRAP_TRACE;
Index: src/sys/arch/sh3/sh3/exception_vector.S
diff -u src/sys/arch/sh3/sh3/exception_vector.S:1.46 src/sys/arch/sh3/sh3/exception_vector.S:1.47
--- src/sys/arch/sh3/sh3/exception_vector.S:1.46 Mon Dec 20 00:25:43 2010
+++ src/sys/arch/sh3/sh3/exception_vector.S Fri Jan 28 21:06:08 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: exception_vector.S,v 1.46 2010/12/20 00:25:43 matt Exp $ */
+/* $NetBSD: exception_vector.S,v 1.47 2011/01/28 21:06:08 uwe Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -28,6 +28,8 @@
#include "opt_cputype.h"
#include "opt_ddb.h"
+#include "opt_ptrace.h"
+
#include "assym.h"
#include <sh3/param.h>
@@ -46,7 +48,7 @@
#define _ALIGN_TEXT .align 5
#include <sh3/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: exception_vector.S,v 1.46 2010/12/20 00:25:43 matt Exp $")
+__KERNEL_RCSID(0, "$NetBSD: exception_vector.S,v 1.47 2011/01/28 21:06:08 uwe Exp $")
/*
@@ -97,12 +99,12 @@
/* general_exception(curlwp, tf, TEA); */
1: mov r4, r8
-#ifdef DDB
+#if defined(PTRACE) || defined(DDB)
mov #0, r2
MOV (BBRA, r1)
- mov.w r2, @r1 /* disable UBC */
mov.l r2, @(TF_UBC, r14) /* clear tf->tf_ubc */
-#endif /* DDB */
+ mov.w r2, @r1 /* disable UBC channel A */
+#endif
__EXCEPTION_UNBLOCK(r0, r1)
mov.l .Lg_general_exception, r0
jsr @r0
@@ -114,9 +116,9 @@
jsr @r0
mov r14, r5
-#ifdef DDB
+#if defined(PTRACE) || defined(DDB)
mov.l @(TF_UBC, r14), r2
- tst r2, r2 ! ddb single-step == 0?
+ tst r2, r2 ! single-step == 0?
bt .Lg_return_from_exception
!! We are returning from DDB to do single step. Channel A in
@@ -127,7 +129,7 @@
mov.l @(TF_SPC, r14), r4
mov.l r4, @r5 ! BARA = tf->tf_spc
mov.w r2, @r3 ! BBRA = tf->tf_ubc
-#endif /* DDB */
+#endif /* PTRACE || DDB */
.Lg_return_from_exception:
__EXCEPTION_RETURN
Index: src/sys/arch/sh3/sh3/process_machdep.c
diff -u src/sys/arch/sh3/sh3/process_machdep.c:1.18 src/sys/arch/sh3/sh3/process_machdep.c:1.19
--- src/sys/arch/sh3/sh3/process_machdep.c:1.18 Sat Nov 21 17:40:28 2009
+++ src/sys/arch/sh3/sh3/process_machdep.c Fri Jan 28 21:06:08 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: process_machdep.c,v 1.18 2009/11/21 17:40:28 rmind Exp $ */
+/* $NetBSD: process_machdep.c,v 1.19 2011/01/28 21:06:08 uwe Exp $ */
/*
* Copyright (c) 1993 The Regents of the University of California.
@@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.18 2009/11/21 17:40:28 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.19 2011/01/28 21:06:08 uwe Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -343,9 +343,11 @@
{
if (sstep)
- return (EINVAL);
+ l->l_md.md_flags |= MDP_SSTEP;
+ else
+ l->l_md.md_flags &= ~MDP_SSTEP;
- return (0);
+ return 0;
}
int
Index: src/sys/arch/sh3/sh3/sh3_machdep.c
diff -u src/sys/arch/sh3/sh3/sh3_machdep.c:1.89 src/sys/arch/sh3/sh3/sh3_machdep.c:1.90
--- src/sys/arch/sh3/sh3/sh3_machdep.c:1.89 Wed Jan 26 23:29:16 2011
+++ src/sys/arch/sh3/sh3/sh3_machdep.c Fri Jan 28 21:06:08 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: sh3_machdep.c,v 1.89 2011/01/26 23:29:16 uwe Exp $ */
+/* $NetBSD: sh3_machdep.c,v 1.90 2011/01/28 21:06:08 uwe Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2002 The NetBSD Foundation, Inc.
@@ -65,11 +65,13 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sh3_machdep.c,v 1.89 2011/01/26 23:29:16 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sh3_machdep.c,v 1.90 2011/01/28 21:06:08 uwe Exp $");
+#include "opt_ddb.h"
#include "opt_kgdb.h"
#include "opt_memsize.h"
#include "opt_kstack_debug.h"
+#include "opt_ptrace.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -104,6 +106,7 @@
#include <sh3/mmu.h>
#include <sh3/pcb.h>
#include <sh3/intr.h>
+#include <sh3/ubcreg.h>
/* Our exported CPU info; we can have only one. */
struct cpu_info cpu_info_store;
@@ -190,6 +193,33 @@
/* Set page size (4KB) */
uvm_setpagesize();
+
+ /* setup UBC channel A for single-stepping */
+#if defined(PTRACE) || defined(DDB)
+ _reg_write_2(SH_(BBRA), 0); /* disable channel A */
+ _reg_write_2(SH_(BBRB), 0); /* disable channel B */
+
+#ifdef SH3
+ if (CPU_IS_SH3) {
+ /* A: break after execution, ignore ASID */
+ _reg_write_4(SH3_BRCR, (UBC_CTL_A_AFTER_INSN
+ | SH3_UBC_CTL_A_MASK_ASID));
+
+ /* A: compare all address bits */
+ _reg_write_4(SH3_BAMRA, 0x00000000);
+ }
+#endif /* SH3 */
+
+#ifdef SH4
+ if (CPU_IS_SH4) {
+ /* A: break after execution */
+ _reg_write_2(SH4_BRCR, UBC_CTL_A_AFTER_INSN);
+
+ /* A: compare all address bits, ignore ASID */
+ _reg_write_1(SH4_BAMRA, SH4_UBC_MASK_NONE | SH4_UBC_MASK_ASID);
+ }
+#endif /* SH4 */
+#endif
}