This is my second take at MIPS watch register support. Changes from the previous version include: * Change layout of structures used by ptrace to eliminate holes. * Use [set|clear]_tsk_thread_flag() and friends instead of racy direct access. * mips64 support (untested). * Fix sparse warnings. For this version of the patch you will need the corresponding gdb patch which can be found here: http://sourceware.org/ml/gdb-patches/2008-04/msg00642.html David Daney --
Add HARDWARE_WATCHPOINTS configure option. This is automatically set for all MIPS32 and MIPS64 processors. Signed-off-by: David Daney <ddaney@avtrex.com> --- arch/mips/Kconfig | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 8724ed3..a52d3a8 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -1344,6 +1344,13 @@ config CPU_SUPPORTS_32BIT_KERNEL config CPU_SUPPORTS_64BIT_KERNEL bool +# +# Set to y for ptrace access to watch registers. +# +config HARDWARE_WATCHPOINTS + bool + default y if CPU_MIPS32 || CPU_MIPS64 + menu "Kernel type" choice -- 1.5.5 --
Add HARDWARE_WATCHPOINTS definitions and support code.
Signed-off-by: David Daney <ddaney@avtrex.com>
---
arch/mips/kernel/Makefile | 1 +
arch/mips/kernel/watch.c | 158 ++++++++++++++++++++++++++++++++++++++++
include/asm-mips/cpu-info.h | 5 +
include/asm-mips/processor.h | 32 ++++++++
include/asm-mips/thread_info.h | 2 +
include/asm-mips/watch.h | 32 ++++++++
6 files changed, 230 insertions(+), 0 deletions(-)
create mode 100644 arch/mips/kernel/watch.c
create mode 100644 include/asm-mips/watch.h
diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
index ed3d160..fdd59cd 100644
--- a/arch/mips/kernel/Makefile
+++ b/arch/mips/kernel/Makefile
@@ -72,6 +72,7 @@ obj-$(CONFIG_MIPS32_O32) += binfmt_elfo32.o scall64-o32.o
obj-$(CONFIG_KGDB) += gdb-low.o gdb-stub.o
obj-$(CONFIG_PROC_FS) += proc.o
+obj-$(CONFIG_HARDWARE_WATCHPOINTS) += watch.o
obj-$(CONFIG_64BIT) += cpu-bugs64.o
diff --git a/arch/mips/kernel/watch.c b/arch/mips/kernel/watch.c
new file mode 100644
index 0000000..9eb7c4f
--- /dev/null
+++ b/arch/mips/kernel/watch.c
@@ -0,0 +1,158 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2008 David Daney
+ */
+
+#include <linux/sched.h>
+
+#include <asm/watch.h>
+
+void mips_install_watch_registers(void)
+{
+ struct mips3264_watch_reg_state *watches =
+ &current->thread.watch.mips3264;
+ switch (current_cpu_data.watch_reg_count) {
+ default:
+ BUG();
+ case 8:
+ write_c0_watchlo7(watches->watchlo[7]);
+ /* Write 1 to the I, R, and W bits to clear them. */
+ write_c0_watchhi7(watches->watchhi[7] | 7);
+ case 7:
+ write_c0_watchlo6(watches->watchlo[6]);
+ write_c0_watchhi6(watches->watchhi[6] | 7);
+ case 6:
+ write_c0_watchlo5(watches->watchlo[5]);
+ write_c0_watchhi5(watches->watchhi[5] | 7);
+ case ...Probe watch registers and report configuration.
Probe for watch register characteristics, and report them in /proc/cpuinfo.
Signed-off-by: David Daney <ddaney@avtrex.com>
---
arch/mips/kernel/cpu-probe.c | 4 ++++
arch/mips/kernel/proc.c | 10 ++++++++++
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index 89c3304..1563049 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -21,6 +21,7 @@
#include <asm/fpu.h>
#include <asm/mipsregs.h>
#include <asm/system.h>
+#include <asm/watch.h>
/*
* Not all of the MIPS CPUs have the "wait" instruction available. Moreover,
@@ -678,6 +679,9 @@ static void __cpuinit decode_configs(struct cpuinfo_mips *c)
static inline void cpu_probe_mips(struct cpuinfo_mips *c)
{
decode_configs(c);
+#if defined(CONFIG_HARDWARE_WATCHPOINTS)
+ mips_probe_watch_registers(c);
+#endif
switch (c->processor_id & 0xff00) {
case PRID_IMP_4KC:
c->cputype = CPU_4KC;
diff --git a/arch/mips/kernel/proc.c b/arch/mips/kernel/proc.c
index 36f0653..e2f716c 100644
--- a/arch/mips/kernel/proc.c
+++ b/arch/mips/kernel/proc.c
@@ -50,8 +50,18 @@ static int show_cpuinfo(struct seq_file *m, void *v)
seq_printf(m, "tlb_entries\t\t: %d\n", cpu_data[n].tlbsize);
seq_printf(m, "extra interrupt vector\t: %s\n",
cpu_has_divec ? "yes" : "no");
+#ifdef CONFIG_HARDWARE_WATCHPOINTS
+ seq_printf(m, "hardware watchpoint\t: %s",
+ cpu_has_watch ? "yes" : "no\n");
+ if (cpu_has_watch)
+ seq_printf(m, ", count: %d, address mask: 0x%04x, irw mask 0x%02x\n",
+ cpu_data[n].watch_reg_count,
+ cpu_data[n].watch_reg_mask,
+ cpu_data[n].watch_reg_irw);
+#else
seq_printf(m, "hardware watchpoint\t: %s\n",
cpu_has_watch ? "yes" : "no");
+#endif
seq_printf(m, "ASEs implemented\t:%s%s%s%s%s%s\n",
cpu_has_mips16 ? " mips16" : "",
cpu_has_mdmx ? " mdmx" : "",
--
1.5.5
--
Watch exception handling for HARDWARE_WATCHPOINTS.
Here we hook up the watch exception handler so that it sends SIGTRAP when
the hardware watch registers are triggered.
Signed-off-by: David Daney <ddaney@avtrex.com>
---
arch/mips/kernel/genex.S | 4 ++++
arch/mips/kernel/traps.c | 14 ++++++++++++++
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/arch/mips/kernel/genex.S b/arch/mips/kernel/genex.S
index c6ada98..15a9bde 100644
--- a/arch/mips/kernel/genex.S
+++ b/arch/mips/kernel/genex.S
@@ -416,7 +416,11 @@ NESTED(nmi_handler, PT_SIZE, sp)
BUILD_HANDLER tr tr sti silent /* #13 */
BUILD_HANDLER fpe fpe fpe silent /* #15 */
BUILD_HANDLER mdmx mdmx sti silent /* #22 */
+#ifdef CONFIG_HARDWARE_WATCHPOINTS
+ BUILD_HANDLER watch watch sti silent /* #23 */
+#else
BUILD_HANDLER watch watch sti verbose /* #23 */
+#endif
BUILD_HANDLER mcheck mcheck cli verbose /* #24 */
BUILD_HANDLER mt mt sti silent /* #25 */
BUILD_HANDLER dsp dsp sti silent /* #26 */
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index 824b187..22bb053 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -39,6 +39,7 @@
#include <asm/tlbdebug.h>
#include <asm/traps.h>
#include <asm/uaccess.h>
+#include <asm/watch.h>
#include <asm/mmu_context.h>
#include <asm/types.h>
#include <asm/stacktrace.h>
@@ -871,6 +872,18 @@ asmlinkage void do_mdmx(struct pt_regs *regs)
asmlinkage void do_watch(struct pt_regs *regs)
{
+#ifdef CONFIG_HARDWARE_WATCHPOINTS
+ /*
+ * If the current thread has the watch registers loaded, save
+ * their values and send SIGTRAP. Otherwise another thread
+ * left the registers set, clear them and continue.
+ */
+ if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) {
+ mips_read_watch_registers();
+ force_sig(SIGTRAP, current);
+ } else
+ mips_clear_watch_registers();
+#else
if (board_watchpoint_handler) {
(*board_watchpoint_handler)(regs);
return;
@@ -883,6 +896,7 @@ ...Scheduler support for HARDWARE_WATCHPOINTS.
Here we hook up the scheduler. Whenever we switch to a new process,
we check to see if the watch registers should be installed, and do it
if needed.
Signed-off-by: David Daney <ddaney@avtrex.com>
---
include/asm-mips/system.h | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/include/asm-mips/system.h b/include/asm-mips/system.h
index a944eda..cd30f83 100644
--- a/include/asm-mips/system.h
+++ b/include/asm-mips/system.h
@@ -20,6 +20,7 @@
#include <asm/cmpxchg.h>
#include <asm/cpu-features.h>
#include <asm/dsp.h>
+#include <asm/watch.h>
#include <asm/war.h>
@@ -76,6 +77,7 @@ do { \
__restore_dsp(current); \
if (cpu_has_userlocal) \
write_c0_userlocal(current_thread_info()->tp_value); \
+ __restore_watch(); \
} while (0)
static inline unsigned long __xchg_u32(volatile int * m, unsigned int val)
--
1.5.5
--
Ptrace support for HARDWARE_WATCHPOINTS
This is the final part of the watch register patch. Here we hook up
ptrace so that the user space debugger (gdb), can set and read the
registers.
Signed-off-by: David Daney <ddaney@avtrex.com>
---
arch/mips/kernel/ptrace.c | 93 +++++++++++++++++++++++++++++++++++++++++++++
include/asm-mips/ptrace.h | 31 +++++++++++++++
2 files changed, 124 insertions(+), 0 deletions(-)
diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index 35234b9..8e86134 100644
--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -46,7 +46,12 @@
*/
void ptrace_disable(struct task_struct *child)
{
+#ifdef CONFIG_HARDWARE_WATCHPOINTS
+ /* Don't load the watchpoint registers for the ex-child. */
+ clear_tsk_thread_flag(child, TIF_LOAD_WATCH);
+#else
/* Nothing to do.. */
+#endif
}
/*
@@ -167,6 +172,84 @@ int ptrace_setfpregs(struct task_struct *child, __u32 __user *data)
return 0;
}
+#ifdef CONFIG_HARDWARE_WATCHPOINTS
+static int ptrace_get_watch_regs(struct task_struct *child,
+ struct pt_watch_regs __user *addr)
+{
+ enum pt_watch_style style;
+ int i;
+
+ if (!cpu_has_watch)
+ return -EIO;
+ if (!access_ok(VERIFY_WRITE, addr, sizeof(struct pt_watch_regs)))
+ return -EIO;
+
+#ifdef CONFIG_32BIT
+ style = pt_watch_style_mips32;
+#define WATCH_STYLE mips32
+#else
+ style = pt_watch_style_mips64;
+#define WATCH_STYLE mips64
+#endif
+
+ __put_user(style, &addr->style);
+ __put_user(current_cpu_data.watch_reg_count,
+ &addr->WATCH_STYLE.num_valid);
+ __put_user(current_cpu_data.watch_reg_mask,
+ &addr->WATCH_STYLE.reg_mask);
+ __put_user(current_cpu_data.watch_reg_irw,
+ &addr->WATCH_STYLE.irw_mask);
+ for (i = 0; i < current_cpu_data.watch_reg_count; i++) {
+ __put_user(child->thread.watch.mips3264.watchlo[i],
+ &addr->WATCH_STYLE.watchlo[i]);
+ __put_user(child->thread.watch.mips3264.watchhi[i] & 0xfff,
+ &addr->WATCH_STYLE.watchhi[i]);
+ }
+
+ return ...