2 * arch/hexagon/kernel/kgdb.c - Hexagon KGDB Support
4 * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and
8 * only version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include <linux/irq.h>
22 #include <linux/sched.h>
23 #include <linux/kdebug.h>
24 #include <linux/kgdb.h>
26 /* All registers are 4 bytes, for now */
27 #define GDB_SIZEOF_REG 4
29 /* The register names are used during printing of the regs;
30 * Keep these at three letters to pretty-print. */
31 struct dbg_reg_def_t dbg_reg_def
[DBG_MAX_REG_NUM
] = {
32 { " r0", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r00
)},
33 { " r1", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r01
)},
34 { " r2", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r02
)},
35 { " r3", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r03
)},
36 { " r4", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r04
)},
37 { " r5", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r05
)},
38 { " r6", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r06
)},
39 { " r7", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r07
)},
40 { " r8", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r08
)},
41 { " r9", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r09
)},
42 { "r10", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r10
)},
43 { "r11", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r11
)},
44 { "r12", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r12
)},
45 { "r13", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r13
)},
46 { "r14", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r14
)},
47 { "r15", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r15
)},
48 { "r16", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r16
)},
49 { "r17", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r17
)},
50 { "r18", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r18
)},
51 { "r19", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r19
)},
52 { "r20", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r20
)},
53 { "r21", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r21
)},
54 { "r22", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r22
)},
55 { "r23", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r23
)},
56 { "r24", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r24
)},
57 { "r25", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r25
)},
58 { "r26", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r26
)},
59 { "r27", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r27
)},
60 { "r28", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r28
)},
61 { "r29", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r29
)},
62 { "r30", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r30
)},
63 { "r31", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, r31
)},
65 { "usr", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, usr
)},
66 { "preds", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, preds
)},
67 { " m0", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, m0
)},
68 { " m1", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, m1
)},
69 { "sa0", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, sa0
)},
70 { "sa1", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, sa1
)},
71 { "lc0", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, lc0
)},
72 { "lc1", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, lc1
)},
73 { " gp", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, gp
)},
74 { "ugp", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, ugp
)},
75 { "cs0", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, cs0
)},
76 { "cs1", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, cs1
)},
77 { "psp", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, hvmer
.vmpsp
)},
78 { "elr", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, hvmer
.vmel
)},
79 { "est", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, hvmer
.vmest
)},
80 { "badva", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, hvmer
.vmbadva
)},
81 { "restart_r0", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, restart_r0
)},
82 { "syscall_nr", GDB_SIZEOF_REG
, offsetof(struct pt_regs
, syscall_nr
)},
85 struct kgdb_arch arch_kgdb_ops
= {
86 /* trap0(#0xDB) 0x0cdb0054 */
87 .gdb_bpt_instr
= {0x54, 0x00, 0xdb, 0x0c},
90 char *dbg_get_reg(int regno
, void *mem
, struct pt_regs
*regs
)
92 if (regno
>= DBG_MAX_REG_NUM
|| regno
< 0)
95 *((unsigned long *) mem
) = *((unsigned long *) ((void *)regs
+
96 dbg_reg_def
[regno
].offset
));
98 return dbg_reg_def
[regno
].name
;
101 int dbg_set_reg(int regno
, void *mem
, struct pt_regs
*regs
)
103 if (regno
>= DBG_MAX_REG_NUM
|| regno
< 0)
106 *((unsigned long *) ((void *)regs
+ dbg_reg_def
[regno
].offset
)) =
107 *((unsigned long *) mem
);
112 void kgdb_arch_set_pc(struct pt_regs
*regs
, unsigned long pc
)
114 instruction_pointer(regs
) = pc
;
120 * kgdb_roundup_cpus - Get other CPUs into a holding pattern
121 * @flags: Current IRQ state
123 * On SMP systems, we need to get the attention of the other CPUs
124 * and get them be in a known state. This should do what is needed
125 * to get the other CPUs to call kgdb_wait(). Note that on some arches,
126 * the NMI approach is not used for rounding up all the CPUs. For example,
127 * in case of MIPS, smp_call_function() is used to roundup CPUs. In
128 * this case, we have to make sure that interrupts are enabled before
129 * calling smp_call_function(). The argument to this function is
130 * the flags that will be used when restoring the interrupts. There is
131 * local_irq_save() call before kgdb_roundup_cpus().
133 * On non-SMP systems, this is not called.
136 static void hexagon_kgdb_nmi_hook(void *ignored
)
138 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
141 void kgdb_roundup_cpus(unsigned long flags
)
144 smp_call_function(hexagon_kgdb_nmi_hook
, NULL
, 0);
150 /* Not yet working */
151 void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs
,
152 struct task_struct
*task
)
154 struct pt_regs
*thread_regs
;
159 /* Initialize to zero */
160 memset(gdb_regs
, 0, NUMREGBYTES
);
162 /* Otherwise, we have only some registers from switch_to() */
163 thread_regs
= task_pt_regs(task
);
164 gdb_regs
[0] = thread_regs
->r00
;
168 * kgdb_arch_handle_exception - Handle architecture specific GDB packets.
169 * @vector: The error vector of the exception that happened.
170 * @signo: The signal number of the exception that happened.
171 * @err_code: The error code of the exception that happened.
172 * @remcom_in_buffer: The buffer of the packet we have read.
173 * @remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
174 * @regs: The &struct pt_regs of the current process.
176 * This function MUST handle the 'c' and 's' command packets,
177 * as well packets to set / remove a hardware breakpoint, if used.
178 * If there are additional packets which the hardware needs to handle,
179 * they are handled here. The code should return -1 if it wants to
180 * process more packets, and a %0 or %1 if it wants to exit from the
185 int kgdb_arch_handle_exception(int vector
, int signo
, int err_code
,
186 char *remcom_in_buffer
, char *remcom_out_buffer
,
187 struct pt_regs
*linux_regs
)
189 switch (remcom_in_buffer
[0]) {
194 /* Stay in the debugger. */
198 static int __kgdb_notify(struct die_args
*args
, unsigned long cmd
)
201 if (atomic_read(&kgdb_active
) != -1) {
202 kgdb_nmicallback(smp_processor_id(), args
->regs
);
206 if (user_mode(args
->regs
))
209 if (kgdb_handle_exception(args
->trapnr
& 0xff, args
->signr
, args
->err
,
217 kgdb_notify(struct notifier_block
*self
, unsigned long cmd
, void *ptr
)
222 local_irq_save(flags
);
223 ret
= __kgdb_notify(ptr
, cmd
);
224 local_irq_restore(flags
);
229 static struct notifier_block kgdb_notifier
= {
230 .notifier_call
= kgdb_notify
,
233 * Lowest-prio notifier priority, we want to be notified last:
235 .priority
= -INT_MAX
,
239 * kgdb_arch_init - Perform any architecture specific initalization.
241 * This function will handle the initalization of any architecture
242 * specific callbacks.
244 int kgdb_arch_init(void)
246 return register_die_notifier(&kgdb_notifier
);
250 * kgdb_arch_exit - Perform any architecture specific uninitalization.
252 * This function will handle the uninitalization of any architecture
253 * specific callbacks, for dynamic registration and unregistration.
255 void kgdb_arch_exit(void)
257 unregister_die_notifier(&kgdb_notifier
);