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/kgdb.h>
14 #include <asm/traps.h>
16 struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] =
18 { "r0", 4, offsetof(struct pt_regs, ARM_r0)},
19 { "r1", 4, offsetof(struct pt_regs, ARM_r1)},
20 { "r2", 4, offsetof(struct pt_regs, ARM_r2)},
21 { "r3", 4, offsetof(struct pt_regs, ARM_r3)},
22 { "r4", 4, offsetof(struct pt_regs, ARM_r4)},
23 { "r5", 4, offsetof(struct pt_regs, ARM_r5)},
24 { "r6", 4, offsetof(struct pt_regs, ARM_r6)},
25 { "r7", 4, offsetof(struct pt_regs, ARM_r7)},
26 { "r8", 4, offsetof(struct pt_regs, ARM_r8)},
27 { "r9", 4, offsetof(struct pt_regs, ARM_r9)},
28 { "r10", 4, offsetof(struct pt_regs, ARM_r10)},
29 { "fp", 4, offsetof(struct pt_regs, ARM_fp)},
30 { "ip", 4, offsetof(struct pt_regs, ARM_ip)},
31 { "sp", 4, offsetof(struct pt_regs, ARM_sp)},
32 { "lr", 4, offsetof(struct pt_regs, ARM_lr)},
33 { "pc", 4, offsetof(struct pt_regs, ARM_pc)},
43 { "cpsr", 4, offsetof(struct pt_regs, ARM_cpsr)},
46 char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
48 if (regno >= DBG_MAX_REG_NUM || regno < 0)
51 if (dbg_reg_def[regno].offset != -1)
52 memcpy(mem, (void *)regs + dbg_reg_def[regno].offset,
53 dbg_reg_def[regno].size);
55 memset(mem, 0, dbg_reg_def[regno].size);
56 return dbg_reg_def[regno].name;
59 int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
61 if (regno >= DBG_MAX_REG_NUM || regno < 0)
64 if (dbg_reg_def[regno].offset != -1)
65 memcpy((void *)regs + dbg_reg_def[regno].offset, mem,
66 dbg_reg_def[regno].size);
71 sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task)
73 struct pt_regs *thread_regs;
76 /* Just making sure... */
80 /* Initialize to zero */
81 for (regno = 0; regno < GDB_MAX_REGS; regno++)
84 /* Otherwise, we have only some registers from switch_to() */
85 thread_regs = task_pt_regs(task);
86 gdb_regs[_R0] = thread_regs->ARM_r0;
87 gdb_regs[_R1] = thread_regs->ARM_r1;
88 gdb_regs[_R2] = thread_regs->ARM_r2;
89 gdb_regs[_R3] = thread_regs->ARM_r3;
90 gdb_regs[_R4] = thread_regs->ARM_r4;
91 gdb_regs[_R5] = thread_regs->ARM_r5;
92 gdb_regs[_R6] = thread_regs->ARM_r6;
93 gdb_regs[_R7] = thread_regs->ARM_r7;
94 gdb_regs[_R8] = thread_regs->ARM_r8;
95 gdb_regs[_R9] = thread_regs->ARM_r9;
96 gdb_regs[_R10] = thread_regs->ARM_r10;
97 gdb_regs[_FP] = thread_regs->ARM_fp;
98 gdb_regs[_IP] = thread_regs->ARM_ip;
99 gdb_regs[_SPT] = thread_regs->ARM_sp;
100 gdb_regs[_LR] = thread_regs->ARM_lr;
101 gdb_regs[_PC] = thread_regs->ARM_pc;
102 gdb_regs[_CPSR] = thread_regs->ARM_cpsr;
105 void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
110 static int compiled_break;
112 int kgdb_arch_handle_exception(int exception_vector, int signo,
113 int err_code, char *remcom_in_buffer,
114 char *remcom_out_buffer,
115 struct pt_regs *linux_regs)
120 switch (remcom_in_buffer[0]) {
125 * Try to read optional parameter, pc unchanged if no parm.
126 * If this was a compiled breakpoint, we need to move
127 * to the next instruction or we will just breakpoint
128 * over and over again.
130 ptr = &remcom_in_buffer[1];
131 if (kgdb_hex2long(&ptr, &addr))
132 linux_regs->ARM_pc = addr;
133 else if (compiled_break == 1)
134 linux_regs->ARM_pc += 4;
144 static int kgdb_brk_fn(struct pt_regs *regs, unsigned int instr)
146 kgdb_handle_exception(1, SIGTRAP, 0, regs);
151 static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int instr)
154 kgdb_handle_exception(1, SIGTRAP, 0, regs);
159 static struct undef_hook kgdb_brkpt_hook = {
160 .instr_mask = 0xffffffff,
161 .instr_val = KGDB_BREAKINST,
165 static struct undef_hook kgdb_compiled_brkpt_hook = {
166 .instr_mask = 0xffffffff,
167 .instr_val = KGDB_COMPILED_BREAK,
168 .fn = kgdb_compiled_brk_fn
171 static void kgdb_call_nmi_hook(void *ignored)
173 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
176 void kgdb_roundup_cpus(unsigned long flags)
179 smp_call_function(kgdb_call_nmi_hook, NULL, 0);
184 * kgdb_arch_init - Perform any architecture specific initalization.
186 * This function will handle the initalization of any architecture
187 * specific callbacks.
189 int kgdb_arch_init(void)
191 register_undef_hook(&kgdb_brkpt_hook);
192 register_undef_hook(&kgdb_compiled_brkpt_hook);
198 * kgdb_arch_exit - Perform any architecture specific uninitalization.
200 * This function will handle the uninitalization of any architecture
201 * specific callbacks, for dynamic registration and unregistration.
203 void kgdb_arch_exit(void)
205 unregister_undef_hook(&kgdb_brkpt_hook);
206 unregister_undef_hook(&kgdb_compiled_brkpt_hook);
210 * Register our undef instruction hooks with ARM undef core.
211 * We regsiter a hook specifically looking for the KGB break inst
212 * and we handle the normal undef case within the do_undefinstr
215 struct kgdb_arch arch_kgdb_ops = {
217 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
218 #else /* ! __ARMEB__ */
219 .gdb_bpt_instr = {0xe7, 0xff, 0xde, 0xfe}