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 /* Make a local copy of the registers passed into the handler (bletch) */
17 void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *kernel_regs)
21 /* Initialize all to zero. */
22 for (regno = 0; regno < GDB_MAX_REGS; regno++)
25 gdb_regs[_R0] = kernel_regs->ARM_r0;
26 gdb_regs[_R1] = kernel_regs->ARM_r1;
27 gdb_regs[_R2] = kernel_regs->ARM_r2;
28 gdb_regs[_R3] = kernel_regs->ARM_r3;
29 gdb_regs[_R4] = kernel_regs->ARM_r4;
30 gdb_regs[_R5] = kernel_regs->ARM_r5;
31 gdb_regs[_R6] = kernel_regs->ARM_r6;
32 gdb_regs[_R7] = kernel_regs->ARM_r7;
33 gdb_regs[_R8] = kernel_regs->ARM_r8;
34 gdb_regs[_R9] = kernel_regs->ARM_r9;
35 gdb_regs[_R10] = kernel_regs->ARM_r10;
36 gdb_regs[_FP] = kernel_regs->ARM_fp;
37 gdb_regs[_IP] = kernel_regs->ARM_ip;
38 gdb_regs[_SPT] = kernel_regs->ARM_sp;
39 gdb_regs[_LR] = kernel_regs->ARM_lr;
40 gdb_regs[_PC] = kernel_regs->ARM_pc;
41 gdb_regs[_CPSR] = kernel_regs->ARM_cpsr;
44 /* Copy local gdb registers back to kgdb regs, for later copy to kernel */
45 void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *kernel_regs)
47 kernel_regs->ARM_r0 = gdb_regs[_R0];
48 kernel_regs->ARM_r1 = gdb_regs[_R1];
49 kernel_regs->ARM_r2 = gdb_regs[_R2];
50 kernel_regs->ARM_r3 = gdb_regs[_R3];
51 kernel_regs->ARM_r4 = gdb_regs[_R4];
52 kernel_regs->ARM_r5 = gdb_regs[_R5];
53 kernel_regs->ARM_r6 = gdb_regs[_R6];
54 kernel_regs->ARM_r7 = gdb_regs[_R7];
55 kernel_regs->ARM_r8 = gdb_regs[_R8];
56 kernel_regs->ARM_r9 = gdb_regs[_R9];
57 kernel_regs->ARM_r10 = gdb_regs[_R10];
58 kernel_regs->ARM_fp = gdb_regs[_FP];
59 kernel_regs->ARM_ip = gdb_regs[_IP];
60 kernel_regs->ARM_sp = gdb_regs[_SPT];
61 kernel_regs->ARM_lr = gdb_regs[_LR];
62 kernel_regs->ARM_pc = gdb_regs[_PC];
63 kernel_regs->ARM_cpsr = gdb_regs[_CPSR];
67 sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task)
69 struct pt_regs *thread_regs;
72 /* Just making sure... */
76 /* Initialize to zero */
77 for (regno = 0; regno < GDB_MAX_REGS; regno++)
80 /* Otherwise, we have only some registers from switch_to() */
81 thread_regs = task_pt_regs(task);
82 gdb_regs[_R0] = thread_regs->ARM_r0;
83 gdb_regs[_R1] = thread_regs->ARM_r1;
84 gdb_regs[_R2] = thread_regs->ARM_r2;
85 gdb_regs[_R3] = thread_regs->ARM_r3;
86 gdb_regs[_R4] = thread_regs->ARM_r4;
87 gdb_regs[_R5] = thread_regs->ARM_r5;
88 gdb_regs[_R6] = thread_regs->ARM_r6;
89 gdb_regs[_R7] = thread_regs->ARM_r7;
90 gdb_regs[_R8] = thread_regs->ARM_r8;
91 gdb_regs[_R9] = thread_regs->ARM_r9;
92 gdb_regs[_R10] = thread_regs->ARM_r10;
93 gdb_regs[_FP] = thread_regs->ARM_fp;
94 gdb_regs[_IP] = thread_regs->ARM_ip;
95 gdb_regs[_SPT] = thread_regs->ARM_sp;
96 gdb_regs[_LR] = thread_regs->ARM_lr;
97 gdb_regs[_PC] = thread_regs->ARM_pc;
98 gdb_regs[_CPSR] = thread_regs->ARM_cpsr;
101 static int compiled_break;
103 int kgdb_arch_handle_exception(int exception_vector, int signo,
104 int err_code, char *remcom_in_buffer,
105 char *remcom_out_buffer,
106 struct pt_regs *linux_regs)
111 switch (remcom_in_buffer[0]) {
116 * Try to read optional parameter, pc unchanged if no parm.
117 * If this was a compiled breakpoint, we need to move
118 * to the next instruction or we will just breakpoint
119 * over and over again.
121 ptr = &remcom_in_buffer[1];
122 if (kgdb_hex2long(&ptr, &addr))
123 linux_regs->ARM_pc = addr;
124 else if (compiled_break == 1)
125 linux_regs->ARM_pc += 4;
135 static int kgdb_brk_fn(struct pt_regs *regs, unsigned int instr)
137 kgdb_handle_exception(1, SIGTRAP, 0, regs);
142 static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int instr)
145 kgdb_handle_exception(1, SIGTRAP, 0, regs);
150 static struct undef_hook kgdb_brkpt_hook = {
151 .instr_mask = 0xffffffff,
152 .instr_val = KGDB_BREAKINST,
156 static struct undef_hook kgdb_compiled_brkpt_hook = {
157 .instr_mask = 0xffffffff,
158 .instr_val = KGDB_COMPILED_BREAK,
159 .fn = kgdb_compiled_brk_fn
162 static void kgdb_call_nmi_hook(void *ignored)
164 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
167 void kgdb_roundup_cpus(unsigned long flags)
170 smp_call_function(kgdb_call_nmi_hook, NULL, 0);
175 * kgdb_arch_init - Perform any architecture specific initalization.
177 * This function will handle the initalization of any architecture
178 * specific callbacks.
180 int kgdb_arch_init(void)
182 register_undef_hook(&kgdb_brkpt_hook);
183 register_undef_hook(&kgdb_compiled_brkpt_hook);
189 * kgdb_arch_exit - Perform any architecture specific uninitalization.
191 * This function will handle the uninitalization of any architecture
192 * specific callbacks, for dynamic registration and unregistration.
194 void kgdb_arch_exit(void)
196 unregister_undef_hook(&kgdb_brkpt_hook);
197 unregister_undef_hook(&kgdb_compiled_brkpt_hook);
201 * Register our undef instruction hooks with ARM undef core.
202 * We regsiter a hook specifically looking for the KGB break inst
203 * and we handle the normal undef case within the do_undefinstr
206 struct kgdb_arch arch_kgdb_ops = {
208 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
209 #else /* ! __ARMEB__ */
210 .gdb_bpt_instr = {0xe7, 0xff, 0xde, 0xfe}