* [Patch 1/6] Add HARDWARE_WATCHPOINTS configure option.
2008-04-21 23:20 [Patch 0/6] MIPS Hardware watchpoint support for gdb David Daney
@ 2008-04-22 0:01 ` David Daney
2008-04-22 0:10 ` [Patch 2/6] Add HARDWARE_WATCHPOINTS definitions and support code David Daney
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: David Daney @ 2008-04-22 0:01 UTC (permalink / raw)
To: linux-mips; +Cc: linux-kernel
This first patch just adds the HARDWARE_WATCHPOINTS option to the
'Kernel type' menu. If N, the watch register support is disabled.
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..98f46f6 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -1622,6 +1622,13 @@ config CPU_HAS_SMARTMIPS
you don't know you probably don't have SmartMIPS and should say N
here.
+config HARDWARE_WATCHPOINTS
+ bool "Debugger support for hardware watchpoints"
+ depends on (CPU_MIPS32 || CPU_MIPS64)
+ help
+ Saying yes here allows you to utilize the hardware watchpoint
+ registers. Most people should say Y here.
+
config CPU_HAS_WB
bool
--
1.5.5
^ permalink raw reply related [flat|nested] 9+ messages in thread* [Patch 2/6] Add HARDWARE_WATCHPOINTS definitions and support code.
2008-04-21 23:20 [Patch 0/6] MIPS Hardware watchpoint support for gdb David Daney
2008-04-22 0:01 ` [Patch 1/6] Add HARDWARE_WATCHPOINTS configure option David Daney
@ 2008-04-22 0:10 ` David Daney
2008-04-22 0:15 ` [Patch 3/6] Probe watch registers and report configuration David Daney
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: David Daney @ 2008-04-22 0:10 UTC (permalink / raw)
To: linux-mips; +Cc: linux-kernel
This patch adds arch/mips/kernel/watch.c which contains support code for
manipulating the watch registers. It also adds the needed fields to the
thread_struct and thread_info. The cpu_info structure is augmented to
contain the characteristics of the watch registers.
Signed-off-by: David Daney <ddaney@avtrex.com>
---
arch/mips/kernel/Makefile | 1 +
arch/mips/kernel/watch.c | 177 ++++++++++++++++++++++++++++++++++++++++
include/asm-mips/cpu-info.h | 5 +
include/asm-mips/processor.h | 29 +++++++
include/asm-mips/thread_info.h | 2 +
include/asm-mips/watch.h | 29 +++++++
6 files changed, 243 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 938be3a..5b1e017 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..6217682
--- /dev/null
+++ b/arch/mips/kernel/watch.c
@@ -0,0 +1,177 @@
+/*
+ * 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()
+{
+ struct mips32_watch_reg_state *watches = ¤t->thread.watch.mips32;
+ 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 5:
+ write_c0_watchlo4(watches->watchlo[4]);
+ write_c0_watchhi4(watches->watchhi[4] | 7);
+ case 4:
+ write_c0_watchlo3(watches->watchlo[3]);
+ write_c0_watchhi3(watches->watchhi[3] | 7);
+ case 3:
+ write_c0_watchlo2(watches->watchlo[2]);
+ write_c0_watchhi2(watches->watchhi[2] | 7);
+ case 2:
+ write_c0_watchlo1(watches->watchlo[1]);
+ write_c0_watchhi1(watches->watchhi[1] | 7);
+ case 1:
+ write_c0_watchlo0(watches->watchlo[0]);
+ write_c0_watchhi0(watches->watchhi[0] | 7);
+ }
+}
+
+/*
+ * Read back the watchhi registers so the user space debugger has
+ * access to the I, R, and W bits.
+ */
+void mips_read_watch_registers()
+{
+ struct mips32_watch_reg_state *watches = ¤t->thread.watch.mips32;
+ switch (current_cpu_data.watch_reg_count) {
+ default:
+ BUG();
+ case 8:
+ watches->watchhi[7] = read_c0_watchhi7();
+ case 7:
+ watches->watchhi[6] = read_c0_watchhi6();
+ case 6:
+ watches->watchhi[5] = read_c0_watchhi5();
+ case 5:
+ watches->watchhi[4] = read_c0_watchhi4();
+ case 4:
+ watches->watchhi[3] = read_c0_watchhi3();
+ case 3:
+ watches->watchhi[2] = read_c0_watchhi2();
+ case 2:
+ watches->watchhi[1] = read_c0_watchhi1();
+ case 1:
+ watches->watchhi[0] = read_c0_watchhi0();
+ }
+}
+
+void mips_clear_watch_registers()
+{
+ switch (current_cpu_data.watch_reg_count) {
+ default:
+ BUG();
+ case 8:
+ write_c0_watchlo7(0);
+ case 7:
+ write_c0_watchlo6(0);
+ case 6:
+ write_c0_watchlo5(0);
+ case 5:
+ write_c0_watchlo4(0);
+ case 4:
+ write_c0_watchlo3(0);
+ case 3:
+ write_c0_watchlo2(0);
+ case 2:
+ write_c0_watchlo1(0);
+ case 1:
+ write_c0_watchlo0(0);
+ }
+}
+
+__init void mips_probe_watch_registers(struct cpuinfo_mips *c)
+{
+ unsigned int t;
+
+ if ((c->options & MIPS_CPU_WATCH) == 0)
+ return;
+ /*
+ * Check which of the I,R and W bits are supported, then
+ * disable the register.
+ */
+ write_c0_watchlo0(7);
+ t = read_c0_watchlo0();
+ write_c0_watchlo0(0);
+ c->watch_reg_irw = t & 7;
+
+ t = read_c0_watchhi0();
+ write_c0_watchhi0(t | 0xff8);
+ t = read_c0_watchhi0();
+ c->watch_reg_count = 1;
+ c->watch_reg_mask = t & 0xff8;
+ if ((t & 0x80000000) == 0)
+ return;
+
+ t = read_c0_watchhi1();
+ write_c0_watchhi1(t | 0xff8);
+ t = read_c0_watchhi1();
+ c->watch_reg_count = 2;
+ /* Calculate the smallest common mask. */
+ c->watch_reg_mask &= t;
+ if ((t & 0x80000000) == 0)
+ return;
+
+ t = read_c0_watchhi2();
+ write_c0_watchhi2(t | 0xff8);
+ t = read_c0_watchhi2();
+ c->watch_reg_count = 3;
+ c->watch_reg_mask &= t;
+ if ((t & 0x80000000) == 0)
+ return;
+
+ t = read_c0_watchhi3();
+ write_c0_watchhi3(t | 0xff8);
+ t = read_c0_watchhi3();
+ c->watch_reg_count = 4;
+ c->watch_reg_mask &= t;
+ if ((t & 0x80000000) == 0)
+ return;
+
+ t = read_c0_watchhi4();
+ write_c0_watchhi4(t | 0xff8);
+ t = read_c0_watchhi4();
+ c->watch_reg_count = 5;
+ c->watch_reg_mask &= t;
+ if ((t & 0x80000000) == 0)
+ return;
+
+ t = read_c0_watchhi5();
+ write_c0_watchhi5(t | 0xff8);
+ t = read_c0_watchhi5();
+ c->watch_reg_count = 6;
+ c->watch_reg_mask &= t;
+ if ((t & 0x80000000) == 0)
+ return;
+
+ t = read_c0_watchhi6();
+ write_c0_watchhi6(t | 0xff8);
+ t = read_c0_watchhi6();
+ c->watch_reg_count = 7;
+ c->watch_reg_mask &= t;
+ if ((t & 0x80000000) == 0)
+ return;
+
+ t = read_c0_watchhi7();
+ write_c0_watchhi7(t | 0xff8);
+ t = read_c0_watchhi7();
+ c->watch_reg_count = 8;
+ c->watch_reg_mask &= t;
+}
diff --git a/include/asm-mips/cpu-info.h b/include/asm-mips/cpu-info.h
index 0c5a358..7d3a093 100644
--- a/include/asm-mips/cpu-info.h
+++ b/include/asm-mips/cpu-info.h
@@ -49,6 +49,11 @@ struct cpuinfo_mips {
unsigned int fpu_id;
unsigned int cputype;
int isa_level;
+#if defined(CONFIG_HARDWARE_WATCHPOINTS)
+ unsigned int watch_reg_count;
+ unsigned int watch_reg_mask;
+ unsigned int watch_reg_irw;
+#endif
int tlbsize;
struct cache_desc icache; /* Primary I-cache */
struct cache_desc dcache; /* Primary D or combined I/D cache */
diff --git a/include/asm-mips/processor.h b/include/asm-mips/processor.h
index 58cbac5..423e04d 100644
--- a/include/asm-mips/processor.h
+++ b/include/asm-mips/processor.h
@@ -105,6 +105,26 @@ struct mips_dsp_state {
{0,} \
}
+#ifdef CONFIG_HARDWARE_WATCHPOINTS
+
+#define NUM_WATCH_REGS 8
+
+struct mips32_watch_reg_state {
+ __u32 watchlo[NUM_WATCH_REGS];
+ __u32 watchhi[NUM_WATCH_REGS];
+};
+
+union mips_watch_reg_state {
+ struct mips32_watch_reg_state mips32;
+};
+
+#define INIT_WATCH .watch = {{{0,},},}
+
+#define OPTIONAL_INIT_WATCH INIT_WATCH,
+#else
+#define OPTIONAL_INIT_WATCH
+#endif
+
typedef struct {
unsigned long seg;
} mm_segment_t;
@@ -137,6 +157,11 @@ struct thread_struct {
/* Saved state of the DSP ASE, if available. */
struct mips_dsp_state dsp;
+#ifdef CONFIG_HARDWARE_WATCHPOINTS
+ /* Saved watch register state, if available. */
+ union mips_watch_reg_state watch;
+#endif
+
/* Other stuff associated with the thread. */
unsigned long cp0_badvaddr; /* Last user fault */
unsigned long cp0_baduaddr; /* Last kernel fault accessing USEG */
@@ -193,6 +218,10 @@ struct thread_struct {
.dspcontrol = 0, \
}, \
/* \
+ * saved watch register stuff \
+ */ \
+ OPTIONAL_INIT_WATCH \
+ /* \
* Other stuff associated with the process \
*/ \
.cp0_badvaddr = 0, \
diff --git a/include/asm-mips/thread_info.h b/include/asm-mips/thread_info.h
index b2772df..e31de4b 100644
--- a/include/asm-mips/thread_info.h
+++ b/include/asm-mips/thread_info.h
@@ -122,6 +122,7 @@ register struct thread_info *__current_thread_info __asm__("$28");
#define TIF_32BIT_REGS 22 /* also implies 16/32 fprs */
#define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
#define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
+#define TIF_LOAD_WATCH 25 /* If set, load watch registers */
#define TIF_SYSCALL_TRACE 31 /* syscall trace active */
#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
@@ -138,6 +139,7 @@ register struct thread_info *__current_thread_info __asm__("$28");
#define _TIF_32BIT_REGS (1<<TIF_32BIT_REGS)
#define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
#define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
+#define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
/* work to do on interrupt/exception return */
#define _TIF_WORK_MASK (0x0000ffef & ~_TIF_SECCOMP)
diff --git a/include/asm-mips/watch.h b/include/asm-mips/watch.h
new file mode 100644
index 0000000..72607be
--- /dev/null
+++ b/include/asm-mips/watch.h
@@ -0,0 +1,29 @@
+/*
+ * 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
+ */
+#ifndef _ASM_WATCH_H
+#define _ASM_WATCH_H
+
+#include <asm/mipsregs.h>
+
+#ifdef CONFIG_HARDWARE_WATCHPOINTS
+void mips_install_watch_registers(void);
+void mips_read_watch_registers(void);
+void mips_clear_watch_registers(void);
+void mips_probe_watch_registers(struct cpuinfo_mips *c);
+
+#define __restore_watch() do { \
+ if (unlikely(current_thread_info()->flags & _TIF_LOAD_WATCH)) { \
+ mips_install_watch_registers(); \
+ } \
+} while (0)
+
+#else
+#define __restore_watch() do {} while (0)
+#endif
+
+#endif /* _ASM_WATCH_H */
--
1.5.5
^ permalink raw reply related [flat|nested] 9+ messages in thread* [Patch 3/6] Probe watch registers and report configuration.
2008-04-21 23:20 [Patch 0/6] MIPS Hardware watchpoint support for gdb David Daney
2008-04-22 0:01 ` [Patch 1/6] Add HARDWARE_WATCHPOINTS configure option David Daney
2008-04-22 0:10 ` [Patch 2/6] Add HARDWARE_WATCHPOINTS definitions and support code David Daney
@ 2008-04-22 0:15 ` David Daney
2008-04-22 0:21 ` [Patch 4/6] Watch trap handling for HARDWARE_WATCHPOINTS David Daney
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: David Daney @ 2008-04-22 0:15 UTC (permalink / raw)
To: linux-mips; +Cc: linux-kernel
This portion of the patch add probing for the watch registers. The probing
code is in watch.c, here we add a call to that code.
Also /proc/cpu info is modified to print out the watch register information.
Signed-off-by: David Daney <ddaney@avtrex.com>
---
arch/mips/kernel/cpu-probe.c | 3 +++
arch/mips/kernel/proc.c | 10 ++++++++++
2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index 89c3304..c3308d3 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -678,6 +678,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
^ permalink raw reply related [flat|nested] 9+ messages in thread* [Patch 4/6] Watch trap handling for HARDWARE_WATCHPOINTS.
2008-04-21 23:20 [Patch 0/6] MIPS Hardware watchpoint support for gdb David Daney
` (2 preceding siblings ...)
2008-04-22 0:15 ` [Patch 3/6] Probe watch registers and report configuration David Daney
@ 2008-04-22 0:21 ` David Daney
2008-04-22 0:33 ` [Patch 5/6] Scheduler support " David Daney
2008-04-22 0:40 ` [Patch 6/6] Ptrace " David Daney
5 siblings, 0 replies; 9+ messages in thread
From: David Daney @ 2008-04-22 0:21 UTC (permalink / raw)
To: linux-mips; +Cc: linux-kernel
In this portion of the patch we hook up the watch trap handler. When the
trap occurs, we copy the register contents into the thread_struct and
send SIGTRAP. If the current thread was not expecting the trap, the
watch register values must have been left over from a different context and
we just clear the registers and return.
Also I turn off the message the prints on each trap, as these traps are now
expected.
Signed-off-by: David Daney <ddaney@avtrex.com>
---
arch/mips/kernel/genex.S | 4 ++++
arch/mips/kernel/traps.c | 13 +++++++++++++
2 files changed, 17 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 984c0d0..6a5f3f0 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -887,6 +887,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;
@@ -899,6 +911,7 @@ asmlinkage void do_watch(struct pt_regs *regs)
dump_tlb_all();
show_regs(regs);
panic("Caught WATCH exception - probably caused by stack overflow.");
+#endif
}
asmlinkage void do_mcheck(struct pt_regs *regs)
--
1.5.5
^ permalink raw reply related [flat|nested] 9+ messages in thread* [Patch 5/6] Scheduler support for HARDWARE_WATCHPOINTS.
2008-04-21 23:20 [Patch 0/6] MIPS Hardware watchpoint support for gdb David Daney
` (3 preceding siblings ...)
2008-04-22 0:21 ` [Patch 4/6] Watch trap handling for HARDWARE_WATCHPOINTS David Daney
@ 2008-04-22 0:33 ` David Daney
2008-04-22 0:40 ` [Patch 6/6] Ptrace " David Daney
5 siblings, 0 replies; 9+ messages in thread
From: David Daney @ 2008-04-22 0:33 UTC (permalink / raw)
To: linux-mips; +Cc: linux-kernel
This is the meat of the patch. Here we install the watch register values when we
schedule a new thread.
The implemtation of __restore_watch() is in asm/watch.h. In the case where there
are no watch registers to install (the normal case) the overhead is 5 machine
instructions with gcc-3.4.3.
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
^ permalink raw reply related [flat|nested] 9+ messages in thread* [Patch 6/6] Ptrace support for HARDWARE_WATCHPOINTS.
2008-04-21 23:20 [Patch 0/6] MIPS Hardware watchpoint support for gdb David Daney
` (4 preceding siblings ...)
2008-04-22 0:33 ` [Patch 5/6] Scheduler support " David Daney
@ 2008-04-22 0:40 ` David Daney
2008-04-22 16:23 ` Daniel Jacobowitz
5 siblings, 1 reply; 9+ messages in thread
From: David Daney @ 2008-04-22 0:40 UTC (permalink / raw)
To: linux-mips; +Cc: linux-kernel
This is the final part of the patch. Here we add ptrace support so that
gdb can read and set the watch register values.
We add two new ptrace requests PTRACE_GET_WATCH_REGS, and
PTRACE_SET_WATCH_REGS to access the watch registers. Since MIPS has more
than one format for watch registers, the data structure is a union, the
first structure member is an enum that tells us which layout is in use.
For this first cut at the patch, I only support mips32 style registers.
Signed-off-by: David Daney <ddaney@avtrex.com>
---
arch/mips/kernel/ptrace.c | 81 +++++++++++++++++++++++++++++++++++++++++++++
include/asm-mips/ptrace.h | 23 +++++++++++++
2 files changed, 104 insertions(+), 0 deletions(-)
diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index 35234b9..d6dece8 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,72 @@ int ptrace_setfpregs(struct task_struct *child, __u32 __user *data)
return 0;
}
+#ifdef CONFIG_HARDWARE_WATCHPOINTS
+int ptrace_get_watch_regs(struct task_struct *child,
+ struct pt_watch_regs __user *addr)
+{
+ int i;
+
+ if (!cpu_has_watch)
+ return -EIO;
+ if (!access_ok(VERIFY_WRITE, addr, sizeof(struct pt_watch_regs)))
+ return -EIO;
+
+ __put_user (pt_watch_style_mips32, &addr->style);
+ __put_user (current_cpu_data.watch_reg_count, &addr->mips32.num_valid);
+ __put_user (current_cpu_data.watch_reg_mask, &addr->mips32.reg_mask);
+ __put_user (current_cpu_data.watch_reg_irw, &addr->mips32.irw_mask);
+ for (i = 0; i < current_cpu_data.watch_reg_count; i++) {
+ __put_user (child->thread.watch.mips32.watchlo[i],
+ &addr->mips32.watchlo[i]);
+ __put_user (child->thread.watch.mips32.watchhi[i] & 0xfff,
+ &addr->mips32.watchhi[i]);
+ }
+
+ return 0;
+}
+
+int ptrace_set_watch_regs(struct task_struct *child,
+ struct pt_watch_regs __user *addr)
+{
+ int i;
+ int watch_active = 0;
+ unsigned long lt[NUM_WATCH_REGS];
+ unsigned int ht[NUM_WATCH_REGS];
+
+ if (!cpu_has_watch)
+ return -EIO;
+ if (!access_ok(VERIFY_READ, addr, sizeof(struct pt_watch_regs)))
+ return -EIO;
+ /* Check the values. */
+ for (i = 0; i < NUM_WATCH_REGS; i++) {
+ __get_user(lt[i], &addr->mips32.watchlo[i]);
+ if (lt[i] & __UA_LIMIT)
+ return -EINVAL;
+
+ __get_user(ht[i], &addr->mips32.watchhi[i]);
+ if (ht[i] & ~0xff8)
+ return -EINVAL;
+ }
+ /* Install them. */
+ for (i = 0; i < NUM_WATCH_REGS; i++) {
+ if (lt[i] & 7)
+ watch_active = 1;
+ child->thread.watch.mips32.watchlo[i] = lt[i];
+ /* Set the G bit. */
+ child->thread.watch.mips32.watchhi[i] = ht[i] | 0x40000000;
+ }
+
+ if (watch_active)
+ set_tsk_thread_flag(child, TIF_LOAD_WATCH);
+ else
+ clear_tsk_thread_flag(child, TIF_LOAD_WATCH);
+
+ return 0;
+}
+
+#endif
+
long arch_ptrace(struct task_struct *child, long request, long addr, long data)
{
int ret;
@@ -439,7 +510,17 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
ret = put_user(task_thread_info(child)->tp_value,
(unsigned long __user *) data);
break;
+#ifdef CONFIG_HARDWARE_WATCHPOINTS
+ case PTRACE_GET_WATCH_REGS:
+ ret = ptrace_get_watch_regs(child,
+ (struct pt_watch_regs __user *) addr);
+ break;
+ case PTRACE_SET_WATCH_REGS:
+ ret = ptrace_set_watch_regs(child,
+ (struct pt_watch_regs __user *) addr);
+ break;
+#endif
default:
ret = ptrace_request(child, request, addr, data);
break;
diff --git a/include/asm-mips/ptrace.h b/include/asm-mips/ptrace.h
index 786f7e3..8fb1bcc 100644
--- a/include/asm-mips/ptrace.h
+++ b/include/asm-mips/ptrace.h
@@ -71,6 +71,29 @@ struct pt_regs {
#define PTRACE_POKEDATA_3264 0xc3
#define PTRACE_GET_THREAD_AREA_3264 0xc4
+/* Read and write watchpoint registers. */
+enum pt_watch_style {
+ pt_watch_style_mips32,
+ pt_watch_style_mips64
+};
+struct mips32_watch_regs {
+ unsigned int num_valid;
+ unsigned int reg_mask;
+ unsigned int irw_mask;
+ unsigned long watchlo[8];
+ unsigned int watchhi[8];
+};
+
+struct pt_watch_regs {
+ enum pt_watch_style style;
+ union {
+ struct mips32_watch_regs mips32;
+ };
+};
+
+#define PTRACE_GET_WATCH_REGS 0xd0
+#define PTRACE_SET_WATCH_REGS 0xd1
+
#ifdef __KERNEL__
#include <linux/linkage.h>
--
1.5.5
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [Patch 6/6] Ptrace support for HARDWARE_WATCHPOINTS.
2008-04-22 0:40 ` [Patch 6/6] Ptrace " David Daney
@ 2008-04-22 16:23 ` Daniel Jacobowitz
2008-04-22 18:26 ` Maciej W. Rozycki
0 siblings, 1 reply; 9+ messages in thread
From: Daniel Jacobowitz @ 2008-04-22 16:23 UTC (permalink / raw)
To: David Daney; +Cc: linux-mips, linux-kernel
On Mon, Apr 21, 2008 at 05:40:11PM -0700, David Daney wrote:
> +struct mips32_watch_regs {
> + unsigned int num_valid;
> + unsigned int reg_mask;
> + unsigned int irw_mask;
> + unsigned long watchlo[8];
> + unsigned int watchhi[8];
> +};
Please do not use long in new ptrace interfaces. Use either
uint32_t or uint64_t as appropriate so that it doesn't depend
on how the kernel or debugger was built.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [Patch 6/6] Ptrace support for HARDWARE_WATCHPOINTS.
2008-04-22 16:23 ` Daniel Jacobowitz
@ 2008-04-22 18:26 ` Maciej W. Rozycki
0 siblings, 0 replies; 9+ messages in thread
From: Maciej W. Rozycki @ 2008-04-22 18:26 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: David Daney, linux-mips, linux-kernel
On Tue, 22 Apr 2008, Daniel Jacobowitz wrote:
> On Mon, Apr 21, 2008 at 05:40:11PM -0700, David Daney wrote:
> > +struct mips32_watch_regs {
> > + unsigned int num_valid;
> > + unsigned int reg_mask;
> > + unsigned int irw_mask;
> > + unsigned long watchlo[8];
> > + unsigned int watchhi[8];
> > +};
>
> Please do not use long in new ptrace interfaces. Use either
> uint32_t or uint64_t as appropriate so that it doesn't depend
> on how the kernel or debugger was built.
A minor nit from my side too -- since it is a new API it may be wise to
move wider structure members to the beginning not to waste gaps in memory
due to alignment.
Maciej
^ permalink raw reply [flat|nested] 9+ messages in thread