aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2012-04-17 03:22:04 -0400
committerPaul Mundt <lethal@linux-sh.org>2012-04-17 03:22:04 -0400
commit9d773d378d9b7272c6cefad5cb41b5e57c96b7a0 (patch)
treee4f51b9b1d018c10204f35ae89eb955935d67aba
parent856cb4bb337ee50427e2b8daaf3a8d61de8a4f44 (diff)
parent21cb20d758254e68a369ba83c721f8ce083e6659 (diff)
Merge branch 'sh/kgdb' into sh-latest
-rw-r--r--arch/sh/include/asm/kgdb.h30
-rw-r--r--arch/sh/kernel/kgdb.c105
2 files changed, 96 insertions, 39 deletions
diff --git a/arch/sh/include/asm/kgdb.h b/arch/sh/include/asm/kgdb.h
index f3613952d1ae..9e7d2d1b03e0 100644
--- a/arch/sh/include/asm/kgdb.h
+++ b/arch/sh/include/asm/kgdb.h
@@ -4,18 +4,6 @@
4#include <asm/cacheflush.h> 4#include <asm/cacheflush.h>
5#include <asm/ptrace.h> 5#include <asm/ptrace.h>
6 6
7/* Same as pt_regs but has vbr in place of syscall_nr */
8struct kgdb_regs {
9 unsigned long regs[16];
10 unsigned long pc;
11 unsigned long pr;
12 unsigned long sr;
13 unsigned long gbr;
14 unsigned long mach;
15 unsigned long macl;
16 unsigned long vbr;
17};
18
19enum regnames { 7enum regnames {
20 GDB_R0, GDB_R1, GDB_R2, GDB_R3, GDB_R4, GDB_R5, GDB_R6, GDB_R7, 8 GDB_R0, GDB_R1, GDB_R2, GDB_R3, GDB_R4, GDB_R5, GDB_R6, GDB_R7,
21 GDB_R8, GDB_R9, GDB_R10, GDB_R11, GDB_R12, GDB_R13, GDB_R14, GDB_R15, 9 GDB_R8, GDB_R9, GDB_R10, GDB_R11, GDB_R12, GDB_R13, GDB_R14, GDB_R15,
@@ -23,17 +11,27 @@ enum regnames {
23 GDB_PC, GDB_PR, GDB_SR, GDB_GBR, GDB_MACH, GDB_MACL, GDB_VBR, 11 GDB_PC, GDB_PR, GDB_SR, GDB_GBR, GDB_MACH, GDB_MACL, GDB_VBR,
24}; 12};
25 13
26#define NUMREGBYTES ((GDB_VBR + 1) * 4) 14#define _GP_REGS 16
15#define _EXTRA_REGS 7
16#define GDB_SIZEOF_REG sizeof(u32)
17
18#define DBG_MAX_REG_NUM (_GP_REGS + _EXTRA_REGS)
19#define NUMREGBYTES (DBG_MAX_REG_NUM * sizeof(GDB_SIZEOF_REG))
27 20
28static inline void arch_kgdb_breakpoint(void) 21static inline void arch_kgdb_breakpoint(void)
29{ 22{
30 __asm__ __volatile__ ("trapa #0x3c\n"); 23 __asm__ __volatile__ ("trapa #0x3c\n");
31} 24}
32 25
33#define BUFMAX 2048
34
35#define CACHE_FLUSH_IS_SAFE 1
36#define BREAK_INSTR_SIZE 2 26#define BREAK_INSTR_SIZE 2
27#define BUFMAX 2048
28
29#ifdef CONFIG_SMP
30# define CACHE_FLUSH_IS_SAFE 0
31#else
32# define CACHE_FLUSH_IS_SAFE 1
33#endif
34
37#define GDB_ADJUSTS_BREAK_OFFSET 35#define GDB_ADJUSTS_BREAK_OFFSET
38 36
39#endif /* __ASM_SH_KGDB_H */ 37#endif /* __ASM_SH_KGDB_H */
diff --git a/arch/sh/kernel/kgdb.c b/arch/sh/kernel/kgdb.c
index b117781bfea2..38b313909ac9 100644
--- a/arch/sh/kernel/kgdb.c
+++ b/arch/sh/kernel/kgdb.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * SuperH KGDB support 2 * SuperH KGDB support
3 * 3 *
4 * Copyright (C) 2008 - 2009 Paul Mundt 4 * Copyright (C) 2008 - 2012 Paul Mundt
5 * 5 *
6 * Single stepping taken from the old stub by Henry Bell and Jeremy Siegel. 6 * Single stepping taken from the old stub by Henry Bell and Jeremy Siegel.
7 * 7 *
@@ -164,42 +164,89 @@ static void undo_single_step(struct pt_regs *linux_regs)
164 stepped_opcode = 0; 164 stepped_opcode = 0;
165} 165}
166 166
167void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs) 167struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = {
168{ 168 { "r0", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[0]) },
169 int i; 169 { "r1", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[1]) },
170 { "r2", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[2]) },
171 { "r3", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[3]) },
172 { "r4", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[4]) },
173 { "r5", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[5]) },
174 { "r6", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[6]) },
175 { "r7", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[7]) },
176 { "r8", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[8]) },
177 { "r9", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[9]) },
178 { "r10", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[10]) },
179 { "r11", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[11]) },
180 { "r12", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[12]) },
181 { "r13", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[13]) },
182 { "r14", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[14]) },
183 { "r15", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[15]) },
184 { "pc", GDB_SIZEOF_REG, offsetof(struct pt_regs, pc) },
185 { "pr", GDB_SIZEOF_REG, offsetof(struct pt_regs, pr) },
186 { "sr", GDB_SIZEOF_REG, offsetof(struct pt_regs, sr) },
187 { "gbr", GDB_SIZEOF_REG, offsetof(struct pt_regs, gbr) },
188 { "mach", GDB_SIZEOF_REG, offsetof(struct pt_regs, mach) },
189 { "macl", GDB_SIZEOF_REG, offsetof(struct pt_regs, macl) },
190 { "vbr", GDB_SIZEOF_REG, -1 },
191};
170 192
171 for (i = 0; i < 16; i++) 193int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
172 gdb_regs[GDB_R0 + i] = regs->regs[i]; 194{
195 if (regno < 0 || regno >= DBG_MAX_REG_NUM)
196 return -EINVAL;
173 197
174 gdb_regs[GDB_PC] = regs->pc; 198 if (dbg_reg_def[regno].offset != -1)
175 gdb_regs[GDB_PR] = regs->pr; 199 memcpy((void *)regs + dbg_reg_def[regno].offset, mem,
176 gdb_regs[GDB_SR] = regs->sr; 200 dbg_reg_def[regno].size);
177 gdb_regs[GDB_GBR] = regs->gbr;
178 gdb_regs[GDB_MACH] = regs->mach;
179 gdb_regs[GDB_MACL] = regs->macl;
180 201
181 __asm__ __volatile__ ("stc vbr, %0" : "=r" (gdb_regs[GDB_VBR])); 202 return 0;
182} 203}
183 204
184void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs) 205char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
185{ 206{
186 int i; 207 if (regno >= DBG_MAX_REG_NUM || regno < 0)
208 return NULL;
187 209
188 for (i = 0; i < 16; i++) 210 if (dbg_reg_def[regno].size != -1)
189 regs->regs[GDB_R0 + i] = gdb_regs[GDB_R0 + i]; 211 memcpy(mem, (void *)regs + dbg_reg_def[regno].offset,
212 dbg_reg_def[regno].size);
213
214 switch (regno) {
215 case GDB_VBR:
216 __asm__ __volatile__ ("stc vbr, %0" : "=r" (mem));
217 break;
218 }
190 219
191 regs->pc = gdb_regs[GDB_PC]; 220 return dbg_reg_def[regno].name;
192 regs->pr = gdb_regs[GDB_PR];
193 regs->sr = gdb_regs[GDB_SR];
194 regs->gbr = gdb_regs[GDB_GBR];
195 regs->mach = gdb_regs[GDB_MACH];
196 regs->macl = gdb_regs[GDB_MACL];
197} 221}
198 222
199void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p) 223void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
200{ 224{
225 struct pt_regs *thread_regs = task_pt_regs(p);
226 int reg;
227
228 /* Initialize to zero */
229 for (reg = 0; reg < DBG_MAX_REG_NUM; reg++)
230 gdb_regs[reg] = 0;
231
232 /*
233 * Copy out GP regs 8 to 14.
234 *
235 * switch_to() relies on SR.RB toggling, so regs 0->7 are banked
236 * and need privileged instructions to get to. The r15 value we
237 * fetch from the thread info directly.
238 */
239 for (reg = GDB_R8; reg < GDB_R15; reg++)
240 gdb_regs[reg] = thread_regs->regs[reg];
241
201 gdb_regs[GDB_R15] = p->thread.sp; 242 gdb_regs[GDB_R15] = p->thread.sp;
202 gdb_regs[GDB_PC] = p->thread.pc; 243 gdb_regs[GDB_PC] = p->thread.pc;
244
245 /*
246 * Additional registers we have context for
247 */
248 gdb_regs[GDB_PR] = thread_regs->pr;
249 gdb_regs[GDB_GBR] = thread_regs->gbr;
203} 250}
204 251
205int kgdb_arch_handle_exception(int e_vector, int signo, int err_code, 252int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
@@ -264,6 +311,18 @@ BUILD_TRAP_HANDLER(singlestep)
264 local_irq_restore(flags); 311 local_irq_restore(flags);
265} 312}
266 313
314static void kgdb_call_nmi_hook(void *ignored)
315{
316 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
317}
318
319void kgdb_roundup_cpus(unsigned long flags)
320{
321 local_irq_enable();
322 smp_call_function(kgdb_call_nmi_hook, NULL, 0);
323 local_irq_disable();
324}
325
267static int __kgdb_notify(struct die_args *args, unsigned long cmd) 326static int __kgdb_notify(struct die_args *args, unsigned long cmd)
268{ 327{
269 int ret; 328 int ret;