2
* arch/arm/kernel/kgdb.c
6
* Copyright (c) 2002-2004 MontaVista Software, Inc
7
* Copyright (c) 2008 Wind River Systems, Inc.
9
* Authors: George Davis <davis_g@mvista.com>
10
* Deepak Saxena <dsaxena@plexity.net>
12
#include <linux/irq.h>
13
#include <linux/kdebug.h>
14
#include <linux/kgdb.h>
15
#include <asm/traps.h>
17
struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] =
19
{ "r0", 4, offsetof(struct pt_regs, ARM_r0)},
20
{ "r1", 4, offsetof(struct pt_regs, ARM_r1)},
21
{ "r2", 4, offsetof(struct pt_regs, ARM_r2)},
22
{ "r3", 4, offsetof(struct pt_regs, ARM_r3)},
23
{ "r4", 4, offsetof(struct pt_regs, ARM_r4)},
24
{ "r5", 4, offsetof(struct pt_regs, ARM_r5)},
25
{ "r6", 4, offsetof(struct pt_regs, ARM_r6)},
26
{ "r7", 4, offsetof(struct pt_regs, ARM_r7)},
27
{ "r8", 4, offsetof(struct pt_regs, ARM_r8)},
28
{ "r9", 4, offsetof(struct pt_regs, ARM_r9)},
29
{ "r10", 4, offsetof(struct pt_regs, ARM_r10)},
30
{ "fp", 4, offsetof(struct pt_regs, ARM_fp)},
31
{ "ip", 4, offsetof(struct pt_regs, ARM_ip)},
32
{ "sp", 4, offsetof(struct pt_regs, ARM_sp)},
33
{ "lr", 4, offsetof(struct pt_regs, ARM_lr)},
34
{ "pc", 4, offsetof(struct pt_regs, ARM_pc)},
44
{ "cpsr", 4, offsetof(struct pt_regs, ARM_cpsr)},
47
char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
49
if (regno >= DBG_MAX_REG_NUM || regno < 0)
52
if (dbg_reg_def[regno].offset != -1)
53
memcpy(mem, (void *)regs + dbg_reg_def[regno].offset,
54
dbg_reg_def[regno].size);
56
memset(mem, 0, dbg_reg_def[regno].size);
57
return dbg_reg_def[regno].name;
60
int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
62
if (regno >= DBG_MAX_REG_NUM || regno < 0)
65
if (dbg_reg_def[regno].offset != -1)
66
memcpy((void *)regs + dbg_reg_def[regno].offset, mem,
67
dbg_reg_def[regno].size);
72
sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task)
74
struct pt_regs *thread_regs;
77
/* Just making sure... */
81
/* Initialize to zero */
82
for (regno = 0; regno < GDB_MAX_REGS; regno++)
85
/* Otherwise, we have only some registers from switch_to() */
86
thread_regs = task_pt_regs(task);
87
gdb_regs[_R0] = thread_regs->ARM_r0;
88
gdb_regs[_R1] = thread_regs->ARM_r1;
89
gdb_regs[_R2] = thread_regs->ARM_r2;
90
gdb_regs[_R3] = thread_regs->ARM_r3;
91
gdb_regs[_R4] = thread_regs->ARM_r4;
92
gdb_regs[_R5] = thread_regs->ARM_r5;
93
gdb_regs[_R6] = thread_regs->ARM_r6;
94
gdb_regs[_R7] = thread_regs->ARM_r7;
95
gdb_regs[_R8] = thread_regs->ARM_r8;
96
gdb_regs[_R9] = thread_regs->ARM_r9;
97
gdb_regs[_R10] = thread_regs->ARM_r10;
98
gdb_regs[_FP] = thread_regs->ARM_fp;
99
gdb_regs[_IP] = thread_regs->ARM_ip;
100
gdb_regs[_SPT] = thread_regs->ARM_sp;
101
gdb_regs[_LR] = thread_regs->ARM_lr;
102
gdb_regs[_PC] = thread_regs->ARM_pc;
103
gdb_regs[_CPSR] = thread_regs->ARM_cpsr;
106
void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
111
static int compiled_break;
113
int kgdb_arch_handle_exception(int exception_vector, int signo,
114
int err_code, char *remcom_in_buffer,
115
char *remcom_out_buffer,
116
struct pt_regs *linux_regs)
121
switch (remcom_in_buffer[0]) {
126
* Try to read optional parameter, pc unchanged if no parm.
127
* If this was a compiled breakpoint, we need to move
128
* to the next instruction or we will just breakpoint
129
* over and over again.
131
ptr = &remcom_in_buffer[1];
132
if (kgdb_hex2long(&ptr, &addr))
133
linux_regs->ARM_pc = addr;
134
else if (compiled_break == 1)
135
linux_regs->ARM_pc += 4;
145
static int kgdb_brk_fn(struct pt_regs *regs, unsigned int instr)
147
kgdb_handle_exception(1, SIGTRAP, 0, regs);
152
static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int instr)
155
kgdb_handle_exception(1, SIGTRAP, 0, regs);
160
static struct undef_hook kgdb_brkpt_hook = {
161
.instr_mask = 0xffffffff,
162
.instr_val = KGDB_BREAKINST,
166
static struct undef_hook kgdb_compiled_brkpt_hook = {
167
.instr_mask = 0xffffffff,
168
.instr_val = KGDB_COMPILED_BREAK,
169
.fn = kgdb_compiled_brk_fn
172
static void kgdb_call_nmi_hook(void *ignored)
174
kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
177
void kgdb_roundup_cpus(unsigned long flags)
180
smp_call_function(kgdb_call_nmi_hook, NULL, 0);
184
static int __kgdb_notify(struct die_args *args, unsigned long cmd)
186
struct pt_regs *regs = args->regs;
188
if (kgdb_handle_exception(1, args->signr, cmd, regs))
193
kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)
198
local_irq_save(flags);
199
ret = __kgdb_notify(ptr, cmd);
200
local_irq_restore(flags);
205
static struct notifier_block kgdb_notifier = {
206
.notifier_call = kgdb_notify,
207
.priority = -INT_MAX,
212
* kgdb_arch_init - Perform any architecture specific initalization.
214
* This function will handle the initalization of any architecture
215
* specific callbacks.
217
int kgdb_arch_init(void)
219
int ret = register_die_notifier(&kgdb_notifier);
224
register_undef_hook(&kgdb_brkpt_hook);
225
register_undef_hook(&kgdb_compiled_brkpt_hook);
231
* kgdb_arch_exit - Perform any architecture specific uninitalization.
233
* This function will handle the uninitalization of any architecture
234
* specific callbacks, for dynamic registration and unregistration.
236
void kgdb_arch_exit(void)
238
unregister_undef_hook(&kgdb_brkpt_hook);
239
unregister_undef_hook(&kgdb_compiled_brkpt_hook);
240
unregister_die_notifier(&kgdb_notifier);
244
* Register our undef instruction hooks with ARM undef core.
245
* We regsiter a hook specifically looking for the KGB break inst
246
* and we handle the normal undef case within the do_undefinstr
249
struct kgdb_arch arch_kgdb_ops = {
251
.gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
252
#else /* ! __ARMEB__ */
253
.gdb_bpt_instr = {0xe7, 0xff, 0xde, 0xfe}