* [Patch 5/6] MIPS: Scheduler support for HARDWARE_WATCHPOINTS.
2008-08-28 21:38 [Patch 0/6] MIPS: Hardware watch register support for gdb (version 3) David Daney
@ 2008-08-28 22:11 ` David Daney
0 siblings, 0 replies; 11+ messages in thread
From: David Daney @ 2008-08-28 22:11 UTC (permalink / raw)
To: linux-mips; +Cc: linux-kernel
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.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Patch 5/6] MIPS: Scheduler support for HARDWARE_WATCHPOINTS.
2008-09-11 5:34 [Patch 0/6] MIPS: Hardware watch register support for gdb (version 4) David Daney
@ 2008-09-11 6:01 ` David Daney
0 siblings, 0 replies; 11+ messages in thread
From: David Daney @ 2008-09-11 6:01 UTC (permalink / raw)
To: linux-mips; +Cc: linux-kernel
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.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Patch 0/6] MIPS: Hardware watch register support for gdb (version 5).
@ 2008-09-23 7:02 David Daney
2008-09-23 7:04 ` [Patch 1/6] MIPS: Add HARDWARE_WATCHPOINTS configure option David Daney
` (6 more replies)
0 siblings, 7 replies; 11+ messages in thread
From: David Daney @ 2008-09-23 7:02 UTC (permalink / raw)
To: linux-mips
Esteemed kernel hackers,
To follow is my fifth pass at MIPS watch register support.
The differences from the previous version:
http://www.linux-mips.org/cgi-bin/mesg.cgi?a=linux-mips&i=48C8ADEF.9020305%40avtrex.com
* Respun against linux-queue.
* Clear the WP bit in cause register on watch exception.
The corresponding GDB patch is here:
http://sourceware.org/ml/gdb-patches/2008-09/msg00230.html
Six patches to follow.
Thanks
David Daney
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Patch 1/6] MIPS: Add HARDWARE_WATCHPOINTS configure option.
2008-09-23 7:02 Patch 0/6] MIPS: Hardware watch register support for gdb (version 5) David Daney
@ 2008-09-23 7:04 ` David Daney
2008-09-23 7:05 ` [Patch 2/6] MIPS: Add HARDWARE_WATCHPOINTS definitions and support code David Daney
` (5 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: David Daney @ 2008-09-23 7:04 UTC (permalink / raw)
To: linux-mips
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 ccf2b0e..2d27ab8 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -1267,6 +1267,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.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Patch 2/6] MIPS: Add HARDWARE_WATCHPOINTS definitions and support code.
2008-09-23 7:02 Patch 0/6] MIPS: Hardware watch register support for gdb (version 5) David Daney
2008-09-23 7:04 ` [Patch 1/6] MIPS: Add HARDWARE_WATCHPOINTS configure option David Daney
@ 2008-09-23 7:05 ` David Daney
2008-09-23 7:07 ` [Patch 3/6] MIPS: Probe watch registers and report configuration David Daney
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: David Daney @ 2008-09-23 7:05 UTC (permalink / raw)
To: linux-mips
This is the main support code for the patch. Here we just add the
code, the following patches hook it up.
Signed-off-by: David Daney <ddaney@avtrex.com>
---
arch/mips/include/asm/cpu-info.h | 6 +
arch/mips/include/asm/processor.h | 20 ++++
arch/mips/include/asm/thread_info.h | 2 +
arch/mips/include/asm/watch.h | 32 ++++++
arch/mips/kernel/Makefile | 2 +-
arch/mips/kernel/watch.c | 188 +++++++++++++++++++++++++++++++++++
6 files changed, 249 insertions(+), 1 deletions(-)
create mode 100644 arch/mips/include/asm/watch.h
create mode 100644 arch/mips/kernel/watch.c
diff --git a/arch/mips/include/asm/cpu-info.h b/arch/mips/include/asm/cpu-info.h
index 2de73db..744cd8f 100644
--- a/arch/mips/include/asm/cpu-info.h
+++ b/arch/mips/include/asm/cpu-info.h
@@ -12,6 +12,8 @@
#ifndef __ASM_CPU_INFO_H
#define __ASM_CPU_INFO_H
+#include <linux/types.h>
+
#include <asm/cache.h>
/*
@@ -69,6 +71,10 @@ struct cpuinfo_mips {
int tc_id; /* Thread Context number */
#endif
void *data; /* Additional data */
+ unsigned int watch_reg_count; /* Number that exist */
+ unsigned int watch_reg_use_cnt; /* Usable by ptrace */
+#define NUM_WATCH_REGS 4
+ u16 watch_reg_masks[NUM_WATCH_REGS];
} __attribute__((aligned(SMP_CACHE_BYTES)));
extern struct cpuinfo_mips cpu_data[];
diff --git a/arch/mips/include/asm/processor.h b/arch/mips/include/asm/processor.h
index a1e4453..18ee58e 100644
--- a/arch/mips/include/asm/processor.h
+++ b/arch/mips/include/asm/processor.h
@@ -105,6 +105,19 @@ struct mips_dsp_state {
{0,} \
}
+struct mips3264_watch_reg_state {
+ /* The width of watchlo is 32 in a 32 bit kernel and 64 in a
+ 64 bit kernel. We use unsigned long as it has the same
+ property. */
+ unsigned long watchlo[NUM_WATCH_REGS];
+ /* Only the mask and IRW bits from watchhi. */
+ u16 watchhi[NUM_WATCH_REGS];
+};
+
+union mips_watch_reg_state {
+ struct mips3264_watch_reg_state mips3264;
+};
+
typedef struct {
unsigned long seg;
} mm_segment_t;
@@ -137,6 +150,9 @@ struct thread_struct {
/* Saved state of the DSP ASE, if available. */
struct mips_dsp_state dsp;
+ /* Saved watch register state, if available. */
+ union mips_watch_reg_state watch;
+
/* Other stuff associated with the thread. */
unsigned long cp0_badvaddr; /* Last user fault */
unsigned long cp0_baduaddr; /* Last kernel fault accessing USEG */
@@ -193,6 +209,10 @@ struct thread_struct {
.dspcontrol = 0, \
}, \
/* \
+ * saved watch register stuff \
+ */ \
+ .watch = {{{0,},},}, \
+ /* \
* Other stuff associated with the process \
*/ \
.cp0_badvaddr = 0, \
diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
index bb30606..3f76de7 100644
--- a/arch/mips/include/asm/thread_info.h
+++ b/arch/mips/include/asm/thread_info.h
@@ -124,6 +124,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)
@@ -140,6 +141,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/arch/mips/include/asm/watch.h b/arch/mips/include/asm/watch.h
new file mode 100644
index 0000000..20126ec
--- /dev/null
+++ b/arch/mips/include/asm/watch.h
@@ -0,0 +1,32 @@
+/*
+ * 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 <linux/bitops.h>
+
+#include <asm/mipsregs.h>
+
+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);
+
+#ifdef CONFIG_HARDWARE_WATCHPOINTS
+#define __restore_watch() do { \
+ if (unlikely(test_bit(TIF_LOAD_WATCH, \
+ ¤t_thread_info()->flags))) { \
+ mips_install_watch_registers(); \
+ } \
+} while (0)
+
+#else
+#define __restore_watch() do {} while (0)
+#endif
+
+#endif /* _ASM_WATCH_H */
diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
index 706f939..2504f15 100644
--- a/arch/mips/kernel/Makefile
+++ b/arch/mips/kernel/Makefile
@@ -6,7 +6,7 @@ extra-y := head.o init_task.o vmlinux.lds
obj-y += cpu-probe.o branch.o entry.o genex.o irq.o process.o \
ptrace.o reset.o setup.o signal.o syscall.o \
- time.o topology.o traps.o unaligned.o
+ time.o topology.o traps.o unaligned.o watch.o
obj-$(CONFIG_CEVT_BCM1480) += cevt-bcm1480.o
obj-$(CONFIG_CEVT_R4K) += cevt-r4k.o
diff --git a/arch/mips/kernel/watch.c b/arch/mips/kernel/watch.c
new file mode 100644
index 0000000..e9c4f5d
--- /dev/null
+++ b/arch/mips/kernel/watch.c
@@ -0,0 +1,188 @@
+/*
+ * 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/processor.h>
+#include <asm/watch.h>
+
+/*
+ * Install the watch registers for the current thread. A maximum of
+ * four registers are installed although the machine may have more.
+ */
+void mips_install_watch_registers(void)
+{
+ struct mips3264_watch_reg_state *watches =
+ ¤t->thread.watch.mips3264;
+ switch (current_cpu_data.watch_reg_use_cnt) {
+ default:
+ BUG();
+ case 4:
+ write_c0_watchlo3(watches->watchlo[3]);
+ /* Write 1 to the I, R, and W bits to clear them, and
+ 1 to G so all ASIDs are trapped. */
+ write_c0_watchhi3(0x40000007 | watches->watchhi[3]);
+ case 3:
+ write_c0_watchlo2(watches->watchlo[2]);
+ write_c0_watchhi2(0x40000007 | watches->watchhi[2]);
+ case 2:
+ write_c0_watchlo1(watches->watchlo[1]);
+ write_c0_watchhi1(0x40000007 | watches->watchhi[1]);
+ case 1:
+ write_c0_watchlo0(watches->watchlo[0]);
+ write_c0_watchhi0(0x40000007 | watches->watchhi[0]);
+ }
+}
+
+/*
+ * Read back the watchhi registers so the user space debugger has
+ * access to the I, R, and W bits. A maximum of four registers are
+ * read although the machine may have more.
+ */
+void mips_read_watch_registers(void)
+{
+ struct mips3264_watch_reg_state *watches =
+ ¤t->thread.watch.mips3264;
+ switch (current_cpu_data.watch_reg_use_cnt) {
+ default:
+ BUG();
+ case 4:
+ watches->watchhi[3] = (read_c0_watchhi3() & 0x0fff);
+ case 3:
+ watches->watchhi[2] = (read_c0_watchhi2() & 0x0fff);
+ case 2:
+ watches->watchhi[1] = (read_c0_watchhi1() & 0x0fff);
+ case 1:
+ watches->watchhi[0] = (read_c0_watchhi0() & 0x0fff);
+ }
+ if (current_cpu_data.watch_reg_use_cnt == 1 &&
+ (watches->watchhi[0] & 7) == 0) {
+ /* Pathological case of release 1 architecture that
+ * doesn't set the condition bits. We assume that
+ * since we got here, the watch condition was met and
+ * signal that the conditions requested in watchlo
+ * were met. */
+ watches->watchhi[0] |= (watches->watchlo[0] & 7);
+ }
+ }
+
+/*
+ * Disable all watch registers. Although only four registers are
+ * installed, all are cleared to eliminate the possibility of endless
+ * looping in the watch handler.
+ */
+void mips_clear_watch_registers(void)
+{
+ 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_masks[0] = t & 7;
+
+ /* Write the mask bits and read them back to determine which
+ * can be used. */
+ c->watch_reg_count = 1;
+ c->watch_reg_use_cnt = 1;
+ t = read_c0_watchhi0();
+ write_c0_watchhi0(t | 0xff8);
+ t = read_c0_watchhi0();
+ c->watch_reg_masks[0] |= (t & 0xff8);
+ if ((t & 0x80000000) == 0)
+ return;
+
+ write_c0_watchlo1(7);
+ t = read_c0_watchlo1();
+ write_c0_watchlo1(0);
+ c->watch_reg_masks[1] = t & 7;
+
+ c->watch_reg_count = 2;
+ c->watch_reg_use_cnt = 2;
+ t = read_c0_watchhi1();
+ write_c0_watchhi1(t | 0xff8);
+ t = read_c0_watchhi1();
+ c->watch_reg_masks[1] |= (t & 0xff8);
+ if ((t & 0x80000000) == 0)
+ return;
+
+ write_c0_watchlo2(7);
+ t = read_c0_watchlo2();
+ write_c0_watchlo2(0);
+ c->watch_reg_masks[2] = t & 7;
+
+ c->watch_reg_count = 3;
+ c->watch_reg_use_cnt = 3;
+ t = read_c0_watchhi2();
+ write_c0_watchhi2(t | 0xff8);
+ t = read_c0_watchhi2();
+ c->watch_reg_masks[2] |= (t & 0xff8);
+ if ((t & 0x80000000) == 0)
+ return;
+
+ write_c0_watchlo3(7);
+ t = read_c0_watchlo3();
+ write_c0_watchlo3(0);
+ c->watch_reg_masks[3] = t & 7;
+
+ c->watch_reg_count = 4;
+ c->watch_reg_use_cnt = 4;
+ t = read_c0_watchhi3();
+ write_c0_watchhi3(t | 0xff8);
+ t = read_c0_watchhi3();
+ c->watch_reg_masks[3] |= (t & 0xff8);
+ if ((t & 0x80000000) == 0)
+ return;
+
+ /* We use at most 4, but probe and report up to 8. */
+ c->watch_reg_count = 5;
+ t = read_c0_watchhi4();
+ if ((t & 0x80000000) == 0)
+ return;
+
+ c->watch_reg_count = 6;
+ t = read_c0_watchhi5();
+ if ((t & 0x80000000) == 0)
+ return;
+
+ c->watch_reg_count = 7;
+ t = read_c0_watchhi6();
+ if ((t & 0x80000000) == 0)
+ return;
+
+ c->watch_reg_count = 8;
+}
--
1.5.5.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Patch 3/6] MIPS: Probe watch registers and report configuration.
2008-09-23 7:02 Patch 0/6] MIPS: Hardware watch register support for gdb (version 5) David Daney
2008-09-23 7:04 ` [Patch 1/6] MIPS: Add HARDWARE_WATCHPOINTS configure option David Daney
2008-09-23 7:05 ` [Patch 2/6] MIPS: Add HARDWARE_WATCHPOINTS definitions and support code David Daney
@ 2008-09-23 7:07 ` David Daney
2008-09-23 7:08 ` [Patch 4/6] MIPS: Watch exception handling for HARDWARE_WATCHPOINTS David Daney
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: David Daney @ 2008-09-23 7:07 UTC (permalink / raw)
To: linux-mips
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 | 2 ++
arch/mips/kernel/proc.c | 9 +++++++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index 335a6ae..d0d07b8 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,
@@ -685,6 +686,7 @@ static inline void spram_config(void) {}
static inline void cpu_probe_mips(struct cpuinfo_mips *c)
{
decode_configs(c);
+ mips_probe_watch_registers(c);
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..9d60679 100644
--- a/arch/mips/kernel/proc.c
+++ b/arch/mips/kernel/proc.c
@@ -50,8 +50,13 @@ 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");
- seq_printf(m, "hardware watchpoint\t: %s\n",
- cpu_has_watch ? "yes" : "no");
+ seq_printf(m, "hardware watchpoint\t: %s",
+ cpu_has_watch ? "yes, " : "no\n");
+ if (cpu_has_watch)
+ seq_printf(m,
+ "count: %d, address/irw mask: 0x%04x\n",
+ cpu_data[n].watch_reg_count,
+ cpu_data[n].watch_reg_masks[0]);
seq_printf(m, "ASEs implemented\t:%s%s%s%s%s%s\n",
cpu_has_mips16 ? " mips16" : "",
cpu_has_mdmx ? " mdmx" : "",
--
1.5.5.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Patch 4/6] MIPS: Watch exception handling for HARDWARE_WATCHPOINTS.
2008-09-23 7:02 Patch 0/6] MIPS: Hardware watch register support for gdb (version 5) David Daney
` (2 preceding siblings ...)
2008-09-23 7:07 ` [Patch 3/6] MIPS: Probe watch registers and report configuration David Daney
@ 2008-09-23 7:08 ` David Daney
2008-09-23 7:09 ` [Patch 5/6] MIPS: Scheduler support " David Daney
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: David Daney @ 2008-09-23 7:08 UTC (permalink / raw)
To: linux-mips
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 | 24 +++++++++++++++++++-----
2 files changed, 23 insertions(+), 5 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 6bee290..3b1ef59 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -42,6 +42,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>
@@ -907,13 +908,26 @@ asmlinkage void do_mdmx(struct pt_regs *regs)
asmlinkage void do_watch(struct pt_regs *regs)
{
+ u32 cause;
+
/*
- * We use the watch exception where available to detect stack
- * overflows.
+ * Clear WP (bit 22) bit of cause register so we don't loop
+ * forever.
*/
- dump_tlb_all();
- show_regs(regs);
- panic("Caught WATCH exception - probably caused by stack overflow.");
+ cause = read_c0_cause();
+ cause &= ~(1 << 22);
+ write_c0_cause(cause);
+
+ /*
+ * 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();
}
asmlinkage void do_mcheck(struct pt_regs *regs)
--
1.5.5.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Patch 5/6] MIPS: Scheduler support for HARDWARE_WATCHPOINTS.
2008-09-23 7:02 Patch 0/6] MIPS: Hardware watch register support for gdb (version 5) David Daney
` (3 preceding siblings ...)
2008-09-23 7:08 ` [Patch 4/6] MIPS: Watch exception handling for HARDWARE_WATCHPOINTS David Daney
@ 2008-09-23 7:09 ` David Daney
2008-09-23 7:11 ` [Patch 6/6] MIPS: Ptrace " David Daney
2008-09-23 18:49 ` Patch 0/6] MIPS: Hardware watch register support for gdb (version 5) David VomLehn
6 siblings, 0 replies; 11+ messages in thread
From: David Daney @ 2008-09-23 7:09 UTC (permalink / raw)
To: linux-mips
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>
---
arch/mips/include/asm/system.h | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
index a944eda..cd30f83 100644
--- a/arch/mips/include/asm/system.h
+++ b/arch/mips/include/asm/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.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Patch 6/6] MIPS: Ptrace support for HARDWARE_WATCHPOINTS
2008-09-23 7:02 Patch 0/6] MIPS: Hardware watch register support for gdb (version 5) David Daney
` (4 preceding siblings ...)
2008-09-23 7:09 ` [Patch 5/6] MIPS: Scheduler support " David Daney
@ 2008-09-23 7:11 ` David Daney
2008-09-23 18:49 ` Patch 0/6] MIPS: Hardware watch register support for gdb (version 5) David VomLehn
6 siblings, 0 replies; 11+ messages in thread
From: David Daney @ 2008-09-23 7:11 UTC (permalink / raw)
To: linux-mips
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/include/asm/ptrace.h | 38 +++++++++++++++
arch/mips/kernel/ptrace.c | 100 +++++++++++++++++++++++++++++++++++++++-
arch/mips/kernel/ptrace32.c | 15 ++++++
3 files changed, 152 insertions(+), 1 deletions(-)
diff --git a/arch/mips/include/asm/ptrace.h b/arch/mips/include/asm/ptrace.h
index c00cca2..dfccd3c 100644
--- a/arch/mips/include/asm/ptrace.h
+++ b/arch/mips/include/asm/ptrace.h
@@ -74,6 +74,44 @@ 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 {
+ uint32_t watchlo[8];
+ /* Lower 16 bits of watchhi. */
+ uint16_t watchhi[8];
+ /* Valid mask and I R W bits.
+ * bit 0 -- 1 if W bit is usable.
+ * bit 1 -- 1 if R bit is usable.
+ * bit 2 -- 1 if I bit is usable.
+ * bits 3 - 11 -- Valid watchhi mask bits.
+ */
+ uint16_t watch_masks[8];
+ /* The number of valid watch register pairs. */
+ uint32_t num_valid;
+} __attribute__ ((aligned (8)));
+
+struct mips64_watch_regs {
+ uint64_t watchlo[8];
+ uint16_t watchhi[8];
+ uint16_t watch_masks[8];
+ uint32_t num_valid;
+} __attribute__ ((aligned (8)));
+
+struct pt_watch_regs {
+ enum pt_watch_style style;
+ union {
+ struct mips32_watch_regs mips32;
+ struct mips32_watch_regs mips64;
+ };
+};
+
+#define PTRACE_GET_WATCH_REGS 0xd0
+#define PTRACE_SET_WATCH_REGS 0xd1
+
#ifdef __KERNEL__
#include <linux/linkage.h>
diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index 35234b9..ee41f8a 100644
--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -46,7 +46,8 @@
*/
void ptrace_disable(struct task_struct *child)
{
- /* Nothing to do.. */
+ /* Don't load the watchpoint registers for the ex-child. */
+ clear_tsk_thread_flag(child, TIF_LOAD_WATCH);
}
/*
@@ -167,6 +168,93 @@ int ptrace_setfpregs(struct task_struct *child, __u32 __user *data)
return 0;
}
+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 || current_cpu_data.watch_reg_use_cnt == 0)
+ 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_use_cnt,
+ &addr->WATCH_STYLE.num_valid);
+ for (i = 0; i < current_cpu_data.watch_reg_use_cnt; 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]);
+ __put_user(current_cpu_data.watch_reg_masks[i],
+ &addr->WATCH_STYLE.watch_masks[i]);
+ }
+ for (; i < 8; i++) {
+ __put_user(0, &addr->WATCH_STYLE.watchlo[i]);
+ __put_user(0, &addr->WATCH_STYLE.watchhi[i]);
+ __put_user(0, &addr->WATCH_STYLE.watch_masks[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];
+ u16 ht[NUM_WATCH_REGS];
+
+ if (!cpu_has_watch || current_cpu_data.watch_reg_use_cnt == 0)
+ return -EIO;
+ if (!access_ok(VERIFY_READ, addr, sizeof(struct pt_watch_regs)))
+ return -EIO;
+ /* Check the values. */
+ for (i = 0; i < current_cpu_data.watch_reg_use_cnt; i++) {
+ __get_user(lt[i], &addr->WATCH_STYLE.watchlo[i]);
+#ifdef CONFIG_32BIT
+ if (lt[i] & __UA_LIMIT)
+ return -EINVAL;
+#else
+ if (test_tsk_thread_flag(child, TIF_32BIT_ADDR)) {
+ if (lt[i] & 0xffffffff80000000UL)
+ return -EINVAL;
+ } else {
+ if (lt[i] & __UA_LIMIT)
+ return -EINVAL;
+ }
+#endif
+ __get_user(ht[i], &addr->WATCH_STYLE.watchhi[i]);
+ if (ht[i] & ~0xff8)
+ return -EINVAL;
+ }
+ /* Install them. */
+ for (i = 0; i < current_cpu_data.watch_reg_use_cnt; i++) {
+ if (lt[i] & 7)
+ watch_active = 1;
+ child->thread.watch.mips3264.watchlo[i] = lt[i];
+ /* Set the G bit. */
+ child->thread.watch.mips3264.watchhi[i] = ht[i];
+ }
+
+ if (watch_active)
+ set_tsk_thread_flag(child, TIF_LOAD_WATCH);
+ else
+ clear_tsk_thread_flag(child, TIF_LOAD_WATCH);
+
+ return 0;
+}
+
long arch_ptrace(struct task_struct *child, long request, long addr, long data)
{
int ret;
@@ -440,6 +528,16 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
(unsigned long __user *) data);
break;
+ 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;
+
default:
ret = ptrace_request(child, request, addr, data);
break;
diff --git a/arch/mips/kernel/ptrace32.c b/arch/mips/kernel/ptrace32.c
index cac56a8..8df1625 100644
--- a/arch/mips/kernel/ptrace32.c
+++ b/arch/mips/kernel/ptrace32.c
@@ -43,6 +43,11 @@ int ptrace_setregs(struct task_struct *child, __s64 __user *data);
int ptrace_getfpregs(struct task_struct *child, __u32 __user *data);
int ptrace_setfpregs(struct task_struct *child, __u32 __user *data);
+int ptrace_get_watch_regs(struct task_struct *child,
+ struct pt_watch_regs __user *addr);
+int ptrace_set_watch_regs(struct task_struct *child,
+ struct pt_watch_regs __user *addr);
+
/*
* Tracing a 32-bit process with a 64-bit strace and vice versa will not
* work. I don't know how to fix this.
@@ -387,6 +392,16 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
(unsigned long __user *) (unsigned long) data);
break;
+ case PTRACE_GET_WATCH_REGS:
+ ret = ptrace_get_watch_regs(child,
+ (struct pt_watch_regs __user *) (unsigned long) addr);
+ break;
+
+ case PTRACE_SET_WATCH_REGS:
+ ret = ptrace_set_watch_regs(child,
+ (struct pt_watch_regs __user *) (unsigned long) addr);
+ break;
+
default:
ret = ptrace_request(child, request, addr, data);
break;
--
1.5.5.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: Patch 0/6] MIPS: Hardware watch register support for gdb (version 5).
2008-09-23 7:02 Patch 0/6] MIPS: Hardware watch register support for gdb (version 5) David Daney
` (5 preceding siblings ...)
2008-09-23 7:11 ` [Patch 6/6] MIPS: Ptrace " David Daney
@ 2008-09-23 18:49 ` David VomLehn
2008-09-23 19:02 ` David Daney
6 siblings, 1 reply; 11+ messages in thread
From: David VomLehn @ 2008-09-23 18:49 UTC (permalink / raw)
To: David Daney; +Cc: linux-mips
David Daney wrote:
> To follow is my fifth pass at MIPS watch register support.
I'd like to add a feature request, understanding fully that the response may very
well be, "interesting idea, now show us a patch"--can we have an interface that
would allow kernel-space allocation of watchpoint registers?
The rationale is that we have found it quite useful to have kernel and driver
code set watchpoints for debugging purposes. I would not expect that kernel space
code could grab watchpoint registers already in use by ptrace, and that ptrace
would be free to allocate all watchpoint registers not in use for kernel space
purposes, i.e. there would be no watchpoint registers permanently allocated for
kernel space usage.
- - - - - Cisco - - - - -
This e-mail and any attachments may contain information which is confidential,
proprietary, privileged or otherwise protected by law. The information is solely
intended for the named addressee (or a person responsible for delivering it to
the addressee). If you are not the intended recipient of this message, you are
not authorized to read, print, retain, copy or disseminate this message or any
part of it. If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete it from your computer.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Patch 0/6] MIPS: Hardware watch register support for gdb (version 5).
2008-09-23 18:49 ` Patch 0/6] MIPS: Hardware watch register support for gdb (version 5) David VomLehn
@ 2008-09-23 19:02 ` David Daney
0 siblings, 0 replies; 11+ messages in thread
From: David Daney @ 2008-09-23 19:02 UTC (permalink / raw)
To: David VomLehn; +Cc: linux-mips
David VomLehn wrote:
> David Daney wrote:
>
>> To follow is my fifth pass at MIPS watch register support.
>
> I'd like to add a feature request, understanding fully that the response
> may very well be, "interesting idea, now show us a patch"--can we have
> an interface that would allow kernel-space allocation of watchpoint
> registers?
>
> The rationale is that we have found it quite useful to have kernel and
> driver code set watchpoints for debugging purposes. I would not expect
> that kernel space code could grab watchpoint registers already in use by
> ptrace, and that ptrace would be free to allocate all watchpoint
> registers not in use for kernel space purposes, i.e. there would be no
> watchpoint registers permanently allocated for kernel space usage.
>
The current patch has an artificial limit of 4 registers that it would use.
I think adding this feature would be possible, but would rather make it
part of a follow-on patch.
You would limit the number of registers available to ptrace and then
handle the others specially in the do_watch handler.
David Daney
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-09-23 19:03 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-23 7:02 Patch 0/6] MIPS: Hardware watch register support for gdb (version 5) David Daney
2008-09-23 7:04 ` [Patch 1/6] MIPS: Add HARDWARE_WATCHPOINTS configure option David Daney
2008-09-23 7:05 ` [Patch 2/6] MIPS: Add HARDWARE_WATCHPOINTS definitions and support code David Daney
2008-09-23 7:07 ` [Patch 3/6] MIPS: Probe watch registers and report configuration David Daney
2008-09-23 7:08 ` [Patch 4/6] MIPS: Watch exception handling for HARDWARE_WATCHPOINTS David Daney
2008-09-23 7:09 ` [Patch 5/6] MIPS: Scheduler support " David Daney
2008-09-23 7:11 ` [Patch 6/6] MIPS: Ptrace " David Daney
2008-09-23 18:49 ` Patch 0/6] MIPS: Hardware watch register support for gdb (version 5) David VomLehn
2008-09-23 19:02 ` David Daney
-- strict thread matches above, loose matches on Subject: below --
2008-09-11 5:34 [Patch 0/6] MIPS: Hardware watch register support for gdb (version 4) David Daney
2008-09-11 6:01 ` [Patch 5/6] MIPS: Scheduler support for HARDWARE_WATCHPOINTS David Daney
2008-08-28 21:38 [Patch 0/6] MIPS: Hardware watch register support for gdb (version 3) David Daney
2008-08-28 22:11 ` [Patch 5/6] MIPS: Scheduler support for HARDWARE_WATCHPOINTS David Daney
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.