diff options
-rw-r--r-- | arch/sh/Kconfig | 1 | ||||
-rw-r--r-- | arch/sh/Kconfig.debug | 69 | ||||
-rw-r--r-- | arch/sh/include/asm/kgdb.h | 66 | ||||
-rw-r--r-- | arch/sh/include/asm/system.h | 2 | ||||
-rw-r--r-- | arch/sh/kernel/Makefile_32 | 2 | ||||
-rw-r--r-- | arch/sh/kernel/cpu/sh3/entry.S | 10 | ||||
-rw-r--r-- | arch/sh/kernel/cpu/sh3/ex.S | 2 | ||||
-rw-r--r-- | arch/sh/kernel/debugtraps.S | 13 | ||||
-rw-r--r-- | arch/sh/kernel/entry-common.S | 10 | ||||
-rw-r--r-- | arch/sh/kernel/kgdb.c | 285 | ||||
-rw-r--r-- | arch/sh/kernel/kgdb_jmp.S | 33 | ||||
-rw-r--r-- | arch/sh/kernel/kgdb_stub.c | 1052 | ||||
-rw-r--r-- | arch/sh/kernel/time_32.c | 7 | ||||
-rw-r--r-- | arch/sh/kernel/traps_32.c | 14 | ||||
-rw-r--r-- | arch/sh/mm/fault_32.c | 6 |
15 files changed, 328 insertions, 1244 deletions
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index ff7a1f358a36..ff3c137deac3 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig | |||
@@ -27,6 +27,7 @@ config SUPERH32 | |||
27 | select HAVE_FUNCTION_TRACER | 27 | select HAVE_FUNCTION_TRACER |
28 | select HAVE_FTRACE_MCOUNT_RECORD | 28 | select HAVE_FTRACE_MCOUNT_RECORD |
29 | select HAVE_DYNAMIC_FTRACE | 29 | select HAVE_DYNAMIC_FTRACE |
30 | select HAVE_ARCH_KGDB | ||
30 | 31 | ||
31 | config SUPERH64 | 32 | config SUPERH64 |
32 | def_bool y if CPU_SH5 | 33 | def_bool y if CPU_SH5 |
diff --git a/arch/sh/Kconfig.debug b/arch/sh/Kconfig.debug index 8f0c1fbd51a6..834a2d24342b 100644 --- a/arch/sh/Kconfig.debug +++ b/arch/sh/Kconfig.debug | |||
@@ -98,19 +98,6 @@ config IRQSTACKS | |||
98 | for handling hard and soft interrupts. This can help avoid | 98 | for handling hard and soft interrupts. This can help avoid |
99 | overflowing the process kernel stacks. | 99 | overflowing the process kernel stacks. |
100 | 100 | ||
101 | config SH_KGDB | ||
102 | bool "Include KGDB kernel debugger" | ||
103 | select FRAME_POINTER | ||
104 | select DEBUG_INFO | ||
105 | depends on CPU_SH3 || CPU_SH4 | ||
106 | help | ||
107 | Include in-kernel hooks for kgdb, the Linux kernel source level | ||
108 | debugger. See <http://kgdb.sourceforge.net/> for more information. | ||
109 | Unless you are intending to debug the kernel, say N here. | ||
110 | |||
111 | menu "KGDB configuration options" | ||
112 | depends on SH_KGDB | ||
113 | |||
114 | config MORE_COMPILE_OPTIONS | 101 | config MORE_COMPILE_OPTIONS |
115 | bool "Add any additional compile options" | 102 | bool "Add any additional compile options" |
116 | help | 103 | help |
@@ -122,62 +109,6 @@ config COMPILE_OPTIONS | |||
122 | string "Additional compile arguments" | 109 | string "Additional compile arguments" |
123 | depends on MORE_COMPILE_OPTIONS | 110 | depends on MORE_COMPILE_OPTIONS |
124 | 111 | ||
125 | config KGDB_NMI | ||
126 | def_bool n | ||
127 | prompt "Enter KGDB on NMI" | ||
128 | |||
129 | config SH_KGDB_CONSOLE | ||
130 | def_bool n | ||
131 | prompt "Console messages through GDB" | ||
132 | depends on !SERIAL_SH_SCI_CONSOLE && SERIAL_SH_SCI=y | ||
133 | select SERIAL_CORE_CONSOLE | ||
134 | |||
135 | config KGDB_SYSRQ | ||
136 | def_bool y | ||
137 | prompt "Allow SysRq 'G' to enter KGDB" | ||
138 | depends on MAGIC_SYSRQ | ||
139 | |||
140 | comment "Serial port setup" | ||
141 | |||
142 | config KGDB_DEFPORT | ||
143 | int "Port number (ttySCn)" | ||
144 | default "1" | ||
145 | |||
146 | config KGDB_DEFBAUD | ||
147 | int "Baud rate" | ||
148 | default "115200" | ||
149 | |||
150 | choice | ||
151 | prompt "Parity" | ||
152 | depends on SH_KGDB | ||
153 | default KGDB_DEFPARITY_N | ||
154 | |||
155 | config KGDB_DEFPARITY_N | ||
156 | bool "None" | ||
157 | |||
158 | config KGDB_DEFPARITY_E | ||
159 | bool "Even" | ||
160 | |||
161 | config KGDB_DEFPARITY_O | ||
162 | bool "Odd" | ||
163 | |||
164 | endchoice | ||
165 | |||
166 | choice | ||
167 | prompt "Data bits" | ||
168 | depends on SH_KGDB | ||
169 | default KGDB_DEFBITS_8 | ||
170 | |||
171 | config KGDB_DEFBITS_8 | ||
172 | bool "8" | ||
173 | |||
174 | config KGDB_DEFBITS_7 | ||
175 | bool "7" | ||
176 | |||
177 | endchoice | ||
178 | |||
179 | endmenu | ||
180 | |||
181 | if SUPERH64 | 112 | if SUPERH64 |
182 | 113 | ||
183 | config SH64_SR_WATCH | 114 | config SH64_SR_WATCH |
diff --git a/arch/sh/include/asm/kgdb.h b/arch/sh/include/asm/kgdb.h index 24e42078f36f..72704ed725e5 100644 --- a/arch/sh/include/asm/kgdb.h +++ b/arch/sh/include/asm/kgdb.h | |||
@@ -1,21 +1,7 @@ | |||
1 | /* | 1 | #ifndef __ASM_SH_KGDB_H |
2 | * May be copied or modified under the terms of the GNU General Public | 2 | #define __ASM_SH_KGDB_H |
3 | * License. See linux/COPYING for more information. | ||
4 | * | ||
5 | * Based on original code by Glenn Engel, Jim Kingdon, | ||
6 | * David Grothe <dave@gcom.com>, Tigran Aivazian, <tigran@sco.com> and | ||
7 | * Amit S. Kale <akale@veritas.com> | ||
8 | * | ||
9 | * Super-H port based on sh-stub.c (Ben Lee and Steve Chamberlain) by | ||
10 | * Henry Bell <henry.bell@st.com> | ||
11 | * | ||
12 | * Header file for low-level support for remote debug using GDB. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #ifndef __KGDB_H | ||
17 | #define __KGDB_H | ||
18 | 3 | ||
4 | #include <asm/cacheflush.h> | ||
19 | #include <asm/ptrace.h> | 5 | #include <asm/ptrace.h> |
20 | 6 | ||
21 | /* Same as pt_regs but has vbr in place of syscall_nr */ | 7 | /* Same as pt_regs but has vbr in place of syscall_nr */ |
@@ -30,40 +16,26 @@ struct kgdb_regs { | |||
30 | unsigned long vbr; | 16 | unsigned long vbr; |
31 | }; | 17 | }; |
32 | 18 | ||
33 | /* State info */ | 19 | enum regnames { |
34 | extern char kgdb_in_gdb_mode; | 20 | GDB_R0, GDB_R1, GDB_R2, GDB_R3, GDB_R4, GDB_R5, GDB_R6, GDB_R7, |
35 | extern int kgdb_nofault; /* Ignore bus errors (in gdb mem access) */ | 21 | GDB_R8, GDB_R9, GDB_R10, GDB_R11, GDB_R12, GDB_R13, GDB_R14, GDB_R15, |
36 | extern char in_nmi; /* Debounce flag to prevent NMI reentry*/ | ||
37 | 22 | ||
38 | /* SCI */ | 23 | GDB_PC, GDB_PR, GDB_SR, GDB_GBR, GDB_MACH, GDB_MACL, GDB_VBR, |
39 | extern int kgdb_portnum; | 24 | }; |
40 | extern int kgdb_baud; | ||
41 | extern char kgdb_parity; | ||
42 | extern char kgdb_bits; | ||
43 | 25 | ||
44 | /* Init and interface stuff */ | 26 | #define NUMREGBYTES ((GDB_VBR + 1) * 4) |
45 | extern int kgdb_init(void); | ||
46 | extern int (*kgdb_getchar)(void); | ||
47 | extern void (*kgdb_putchar)(int); | ||
48 | 27 | ||
49 | /* Trap functions */ | 28 | static inline void arch_kgdb_breakpoint(void) |
50 | typedef void (kgdb_debug_hook_t)(struct pt_regs *regs); | 29 | { |
51 | typedef void (kgdb_bus_error_hook_t)(void); | 30 | __asm__ __volatile__ ("trapa #0x3c\n"); |
52 | extern kgdb_debug_hook_t *kgdb_debug_hook; | 31 | } |
53 | extern kgdb_bus_error_hook_t *kgdb_bus_err_hook; | ||
54 | 32 | ||
55 | /* Console */ | 33 | /* State info */ |
56 | struct console; | 34 | extern char in_nmi; /* Debounce flag to prevent NMI reentry*/ |
57 | void kgdb_console_write(struct console *co, const char *s, unsigned count); | ||
58 | extern int kgdb_console_setup(struct console *, char *); | ||
59 | 35 | ||
60 | /* Prototypes for jmp fns */ | 36 | #define BUFMAX 2048 |
61 | #define _JBLEN 9 | ||
62 | typedef int jmp_buf[_JBLEN]; | ||
63 | extern void longjmp(jmp_buf __jmpb, int __retval); | ||
64 | extern int setjmp(jmp_buf __jmpb); | ||
65 | 37 | ||
66 | /* Forced breakpoint */ | 38 | #define CACHE_FLUSH_IS_SAFE 1 |
67 | #define breakpoint() __asm__ __volatile__("trapa #0x3c") | 39 | #define BREAK_INSTR_SIZE 2 |
68 | 40 | ||
69 | #endif | 41 | #endif /* __ASM_SH_KGDB_H */ |
diff --git a/arch/sh/include/asm/system.h b/arch/sh/include/asm/system.h index 6160fe445161..c9ec6af8e745 100644 --- a/arch/sh/include/asm/system.h +++ b/arch/sh/include/asm/system.h | |||
@@ -175,6 +175,8 @@ asmlinkage void name##_trap_handler(unsigned int vec, struct pt_regs *regs) | |||
175 | BUILD_TRAP_HANDLER(address_error); | 175 | BUILD_TRAP_HANDLER(address_error); |
176 | BUILD_TRAP_HANDLER(debug); | 176 | BUILD_TRAP_HANDLER(debug); |
177 | BUILD_TRAP_HANDLER(bug); | 177 | BUILD_TRAP_HANDLER(bug); |
178 | BUILD_TRAP_HANDLER(breakpoint); | ||
179 | BUILD_TRAP_HANDLER(singlestep); | ||
178 | BUILD_TRAP_HANDLER(fpu_error); | 180 | BUILD_TRAP_HANDLER(fpu_error); |
179 | BUILD_TRAP_HANDLER(fpu_state_restore); | 181 | BUILD_TRAP_HANDLER(fpu_state_restore); |
180 | 182 | ||
diff --git a/arch/sh/kernel/Makefile_32 b/arch/sh/kernel/Makefile_32 index 10a34c3ae647..df25304ad780 100644 --- a/arch/sh/kernel/Makefile_32 +++ b/arch/sh/kernel/Makefile_32 | |||
@@ -19,7 +19,7 @@ obj-$(CONFIG_VSYSCALL) += vsyscall/ | |||
19 | obj-$(CONFIG_SMP) += smp.o | 19 | obj-$(CONFIG_SMP) += smp.o |
20 | obj-$(CONFIG_CF_ENABLER) += cf-enabler.o | 20 | obj-$(CONFIG_CF_ENABLER) += cf-enabler.o |
21 | obj-$(CONFIG_SH_STANDARD_BIOS) += sh_bios.o | 21 | obj-$(CONFIG_SH_STANDARD_BIOS) += sh_bios.o |
22 | obj-$(CONFIG_SH_KGDB) += kgdb_stub.o kgdb_jmp.o | 22 | obj-$(CONFIG_KGDB) += kgdb.o |
23 | obj-$(CONFIG_SH_CPU_FREQ) += cpufreq.o | 23 | obj-$(CONFIG_SH_CPU_FREQ) += cpufreq.o |
24 | obj-$(CONFIG_MODULES) += sh_ksyms_32.o module.o | 24 | obj-$(CONFIG_MODULES) += sh_ksyms_32.o module.o |
25 | obj-$(CONFIG_EARLY_PRINTK) += early_printk.o | 25 | obj-$(CONFIG_EARLY_PRINTK) += early_printk.o |
diff --git a/arch/sh/kernel/cpu/sh3/entry.S b/arch/sh/kernel/cpu/sh3/entry.S index f112faa219c3..b4106d0c68ec 100644 --- a/arch/sh/kernel/cpu/sh3/entry.S +++ b/arch/sh/kernel/cpu/sh3/entry.S | |||
@@ -52,7 +52,7 @@ | |||
52 | * syscall # | 52 | * syscall # |
53 | * | 53 | * |
54 | */ | 54 | */ |
55 | #if defined(CONFIG_KGDB_NMI) | 55 | #if defined(CONFIG_KGDB) |
56 | NMI_VEC = 0x1c0 ! Must catch early for debounce | 56 | NMI_VEC = 0x1c0 ! Must catch early for debounce |
57 | #endif | 57 | #endif |
58 | 58 | ||
@@ -307,7 +307,7 @@ skip_restore: | |||
307 | 6: or k0, k2 ! Set the IMASK-bits | 307 | 6: or k0, k2 ! Set the IMASK-bits |
308 | ldc k2, ssr | 308 | ldc k2, ssr |
309 | ! | 309 | ! |
310 | #if defined(CONFIG_KGDB_NMI) | 310 | #if defined(CONFIG_KGDB) |
311 | ! Clear in_nmi | 311 | ! Clear in_nmi |
312 | mov.l 6f, k0 | 312 | mov.l 6f, k0 |
313 | mov #0, k1 | 313 | mov #0, k1 |
@@ -320,7 +320,7 @@ skip_restore: | |||
320 | 320 | ||
321 | .align 2 | 321 | .align 2 |
322 | 5: .long 0x00001000 ! DSP | 322 | 5: .long 0x00001000 ! DSP |
323 | #ifdef CONFIG_KGDB_NMI | 323 | #ifdef CONFIG_KGDB |
324 | 6: .long in_nmi | 324 | 6: .long in_nmi |
325 | #endif | 325 | #endif |
326 | 7: .long 0x30000000 | 326 | 7: .long 0x30000000 |
@@ -377,7 +377,7 @@ tlb_miss: | |||
377 | .balign 512,0,512 | 377 | .balign 512,0,512 |
378 | interrupt: | 378 | interrupt: |
379 | mov.l 3f, k3 | 379 | mov.l 3f, k3 |
380 | #if defined(CONFIG_KGDB_NMI) | 380 | #if defined(CONFIG_KGDB) |
381 | mov.l 2f, k2 | 381 | mov.l 2f, k2 |
382 | ! Debounce (filter nested NMI) | 382 | ! Debounce (filter nested NMI) |
383 | mov.l @k2, k0 | 383 | mov.l @k2, k0 |
@@ -394,7 +394,7 @@ interrupt: | |||
394 | 5: .long NMI_VEC | 394 | 5: .long NMI_VEC |
395 | 6: .long in_nmi | 395 | 6: .long in_nmi |
396 | 0: | 396 | 0: |
397 | #endif /* defined(CONFIG_KGDB_NMI) */ | 397 | #endif /* defined(CONFIG_KGDB) */ |
398 | bra handle_exception | 398 | bra handle_exception |
399 | mov #-1, k2 ! interrupt exception marker | 399 | mov #-1, k2 ! interrupt exception marker |
400 | 400 | ||
diff --git a/arch/sh/kernel/cpu/sh3/ex.S b/arch/sh/kernel/cpu/sh3/ex.S index dac429726899..e5a0de39a2db 100644 --- a/arch/sh/kernel/cpu/sh3/ex.S +++ b/arch/sh/kernel/cpu/sh3/ex.S | |||
@@ -26,7 +26,7 @@ | |||
26 | #define fpu_error_trap_handler exception_error | 26 | #define fpu_error_trap_handler exception_error |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | #if !defined(CONFIG_KGDB_NMI) | 29 | #if !defined(CONFIG_KGDB) |
30 | #define kgdb_handle_exception exception_error | 30 | #define kgdb_handle_exception exception_error |
31 | #endif | 31 | #endif |
32 | 32 | ||
diff --git a/arch/sh/kernel/debugtraps.S b/arch/sh/kernel/debugtraps.S index 13b66746410a..591741383ee6 100644 --- a/arch/sh/kernel/debugtraps.S +++ b/arch/sh/kernel/debugtraps.S | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Debug trap jump tables for SuperH | 4 | * Debug trap jump tables for SuperH |
5 | * | 5 | * |
6 | * Copyright (C) 2006 Paul Mundt | 6 | * Copyright (C) 2006 - 2008 Paul Mundt |
7 | * | 7 | * |
8 | * This file is subject to the terms and conditions of the GNU General Public | 8 | * This file is subject to the terms and conditions of the GNU General Public |
9 | * License. See the file "COPYING" in the main directory of this archive | 9 | * License. See the file "COPYING" in the main directory of this archive |
@@ -12,12 +12,13 @@ | |||
12 | #include <linux/sys.h> | 12 | #include <linux/sys.h> |
13 | #include <linux/linkage.h> | 13 | #include <linux/linkage.h> |
14 | 14 | ||
15 | #if !defined(CONFIG_SH_KGDB) | 15 | #if !defined(CONFIG_KGDB) |
16 | #define kgdb_handle_exception debug_trap_handler | 16 | #define breakpoint_trap_handler debug_trap_handler |
17 | #define singlestep_trap_handler debug_trap_handler | ||
17 | #endif | 18 | #endif |
18 | 19 | ||
19 | #if !defined(CONFIG_SH_STANDARD_BIOS) | 20 | #if !defined(CONFIG_SH_STANDARD_BIOS) |
20 | #define sh_bios_handler debug_trap_handler | 21 | #define sh_bios_handler debug_trap_handler |
21 | #endif | 22 | #endif |
22 | 23 | ||
23 | .data | 24 | .data |
@@ -35,7 +36,7 @@ ENTRY(debug_trap_table) | |||
35 | .long debug_trap_handler /* 0x39 */ | 36 | .long debug_trap_handler /* 0x39 */ |
36 | .long debug_trap_handler /* 0x3a */ | 37 | .long debug_trap_handler /* 0x3a */ |
37 | .long debug_trap_handler /* 0x3b */ | 38 | .long debug_trap_handler /* 0x3b */ |
38 | .long kgdb_handle_exception /* 0x3c */ | 39 | .long breakpoint_trap_handler /* 0x3c */ |
39 | .long debug_trap_handler /* 0x3d */ | 40 | .long singlestep_trap_handler /* 0x3d */ |
40 | .long bug_trap_handler /* 0x3e */ | 41 | .long bug_trap_handler /* 0x3e */ |
41 | .long sh_bios_handler /* 0x3f */ | 42 | .long sh_bios_handler /* 0x3f */ |
diff --git a/arch/sh/kernel/entry-common.S b/arch/sh/kernel/entry-common.S index efbb4268875e..d62359cfbbe2 100644 --- a/arch/sh/kernel/entry-common.S +++ b/arch/sh/kernel/entry-common.S | |||
@@ -308,15 +308,19 @@ ENTRY(system_call) | |||
308 | mov.l 1f, r9 | 308 | mov.l 1f, r9 |
309 | mov.l @r9, r8 ! Read from TRA (Trap Address) Register | 309 | mov.l @r9, r8 ! Read from TRA (Trap Address) Register |
310 | #endif | 310 | #endif |
311 | |||
312 | mov #OFF_TRA, r10 | ||
313 | add r15, r10 | ||
314 | mov.l r8, @r10 ! set TRA value to tra | ||
315 | |||
311 | /* | 316 | /* |
312 | * Check the trap type | 317 | * Check the trap type |
313 | */ | 318 | */ |
314 | mov #((0x20 << 2) - 1), r9 | 319 | mov #((0x20 << 2) - 1), r9 |
315 | cmp/hi r9, r8 | 320 | cmp/hi r9, r8 |
316 | bt/s debug_trap ! it's a debug trap.. | 321 | bt/s debug_trap ! it's a debug trap.. |
317 | mov #OFF_TRA, r9 | 322 | nop |
318 | add r15, r9 | 323 | |
319 | mov.l r8, @r9 ! set TRA value to tra | ||
320 | #ifdef CONFIG_TRACE_IRQFLAGS | 324 | #ifdef CONFIG_TRACE_IRQFLAGS |
321 | mov.l 5f, r10 | 325 | mov.l 5f, r10 |
322 | jsr @r10 | 326 | jsr @r10 |
diff --git a/arch/sh/kernel/kgdb.c b/arch/sh/kernel/kgdb.c new file mode 100644 index 000000000000..7c747e7d71b8 --- /dev/null +++ b/arch/sh/kernel/kgdb.c | |||
@@ -0,0 +1,285 @@ | |||
1 | /* | ||
2 | * SuperH KGDB support | ||
3 | * | ||
4 | * Copyright (C) 2008 Paul Mundt | ||
5 | * | ||
6 | * Single stepping taken from the old stub by Henry Bell and Jeremy Siegel. | ||
7 | * | ||
8 | * This file is subject to the terms and conditions of the GNU General Public | ||
9 | * License. See the file "COPYING" in the main directory of this archive | ||
10 | * for more details. | ||
11 | */ | ||
12 | #include <linux/kgdb.h> | ||
13 | #include <linux/kdebug.h> | ||
14 | #include <linux/irq.h> | ||
15 | #include <linux/io.h> | ||
16 | #include <asm/cacheflush.h> | ||
17 | |||
18 | char in_nmi = 0; /* Set during NMI to prevent re-entry */ | ||
19 | |||
20 | /* Macros for single step instruction identification */ | ||
21 | #define OPCODE_BT(op) (((op) & 0xff00) == 0x8900) | ||
22 | #define OPCODE_BF(op) (((op) & 0xff00) == 0x8b00) | ||
23 | #define OPCODE_BTF_DISP(op) (((op) & 0x80) ? (((op) | 0xffffff80) << 1) : \ | ||
24 | (((op) & 0x7f ) << 1)) | ||
25 | #define OPCODE_BFS(op) (((op) & 0xff00) == 0x8f00) | ||
26 | #define OPCODE_BTS(op) (((op) & 0xff00) == 0x8d00) | ||
27 | #define OPCODE_BRA(op) (((op) & 0xf000) == 0xa000) | ||
28 | #define OPCODE_BRA_DISP(op) (((op) & 0x800) ? (((op) | 0xfffff800) << 1) : \ | ||
29 | (((op) & 0x7ff) << 1)) | ||
30 | #define OPCODE_BRAF(op) (((op) & 0xf0ff) == 0x0023) | ||
31 | #define OPCODE_BRAF_REG(op) (((op) & 0x0f00) >> 8) | ||
32 | #define OPCODE_BSR(op) (((op) & 0xf000) == 0xb000) | ||
33 | #define OPCODE_BSR_DISP(op) (((op) & 0x800) ? (((op) | 0xfffff800) << 1) : \ | ||
34 | (((op) & 0x7ff) << 1)) | ||
35 | #define OPCODE_BSRF(op) (((op) & 0xf0ff) == 0x0003) | ||
36 | #define OPCODE_BSRF_REG(op) (((op) >> 8) & 0xf) | ||
37 | #define OPCODE_JMP(op) (((op) & 0xf0ff) == 0x402b) | ||
38 | #define OPCODE_JMP_REG(op) (((op) >> 8) & 0xf) | ||
39 | #define OPCODE_JSR(op) (((op) & 0xf0ff) == 0x400b) | ||
40 | #define OPCODE_JSR_REG(op) (((op) >> 8) & 0xf) | ||
41 | #define OPCODE_RTS(op) ((op) == 0xb) | ||
42 | #define OPCODE_RTE(op) ((op) == 0x2b) | ||
43 | |||
44 | #define SR_T_BIT_MASK 0x1 | ||
45 | #define STEP_OPCODE 0xc33d | ||
46 | |||
47 | /* Calculate the new address for after a step */ | ||
48 | static short *get_step_address(struct pt_regs *linux_regs) | ||
49 | { | ||
50 | opcode_t op = __raw_readw(linux_regs->pc); | ||
51 | long addr; | ||
52 | |||
53 | /* BT */ | ||
54 | if (OPCODE_BT(op)) { | ||
55 | if (linux_regs->sr & SR_T_BIT_MASK) | ||
56 | addr = linux_regs->pc + 4 + OPCODE_BTF_DISP(op); | ||
57 | else | ||
58 | addr = linux_regs->pc + 2; | ||
59 | } | ||
60 | |||
61 | /* BTS */ | ||
62 | else if (OPCODE_BTS(op)) { | ||
63 | if (linux_regs->sr & SR_T_BIT_MASK) | ||
64 | addr = linux_regs->pc + 4 + OPCODE_BTF_DISP(op); | ||
65 | else | ||
66 | addr = linux_regs->pc + 4; /* Not in delay slot */ | ||
67 | } | ||
68 | |||
69 | /* BF */ | ||
70 | else if (OPCODE_BF(op)) { | ||
71 | if (!(linux_regs->sr & SR_T_BIT_MASK)) | ||
72 | addr = linux_regs->pc + 4 + OPCODE_BTF_DISP(op); | ||
73 | else | ||
74 | addr = linux_regs->pc + 2; | ||
75 | } | ||
76 | |||
77 | /* BFS */ | ||
78 | else if (OPCODE_BFS(op)) { | ||
79 | if (!(linux_regs->sr & SR_T_BIT_MASK)) | ||
80 | addr = linux_regs->pc + 4 + OPCODE_BTF_DISP(op); | ||
81 | else | ||
82 | addr = linux_regs->pc + 4; /* Not in delay slot */ | ||
83 | } | ||
84 | |||
85 | /* BRA */ | ||
86 | else if (OPCODE_BRA(op)) | ||
87 | addr = linux_regs->pc + 4 + OPCODE_BRA_DISP(op); | ||
88 | |||
89 | /* BRAF */ | ||
90 | else if (OPCODE_BRAF(op)) | ||
91 | addr = linux_regs->pc + 4 | ||
92 | + linux_regs->regs[OPCODE_BRAF_REG(op)]; | ||
93 | |||
94 | /* BSR */ | ||
95 | else if (OPCODE_BSR(op)) | ||
96 | addr = linux_regs->pc + 4 + OPCODE_BSR_DISP(op); | ||
97 | |||
98 | /* BSRF */ | ||
99 | else if (OPCODE_BSRF(op)) | ||
100 | addr = linux_regs->pc + 4 | ||
101 | + linux_regs->regs[OPCODE_BSRF_REG(op)]; | ||
102 | |||
103 | /* JMP */ | ||
104 | else if (OPCODE_JMP(op)) | ||
105 | addr = linux_regs->regs[OPCODE_JMP_REG(op)]; | ||
106 | |||
107 | /* JSR */ | ||
108 | else if (OPCODE_JSR(op)) | ||
109 | addr = linux_regs->regs[OPCODE_JSR_REG(op)]; | ||
110 | |||
111 | /* RTS */ | ||
112 | else if (OPCODE_RTS(op)) | ||
113 | addr = linux_regs->pr; | ||
114 | |||
115 | /* RTE */ | ||
116 | else if (OPCODE_RTE(op)) | ||
117 | addr = linux_regs->regs[15]; | ||
118 | |||
119 | /* Other */ | ||
120 | else | ||
121 | addr = linux_regs->pc + instruction_size(op); | ||
122 | |||
123 | flush_icache_range(addr, addr + instruction_size(op)); | ||
124 | return (short *)addr; | ||
125 | } | ||
126 | |||
127 | /* | ||
128 | * Replace the instruction immediately after the current instruction | ||
129 | * (i.e. next in the expected flow of control) with a trap instruction, | ||
130 | * so that returning will cause only a single instruction to be executed. | ||
131 | * Note that this model is slightly broken for instructions with delay | ||
132 | * slots (e.g. B[TF]S, BSR, BRA etc), where both the branch and the | ||
133 | * instruction in the delay slot will be executed. | ||
134 | */ | ||
135 | |||
136 | static unsigned long stepped_address; | ||
137 | static opcode_t stepped_opcode; | ||
138 | |||
139 | static void do_single_step(struct pt_regs *linux_regs) | ||
140 | { | ||
141 | /* Determine where the target instruction will send us to */ | ||
142 | unsigned short *addr = get_step_address(linux_regs); | ||
143 | |||
144 | stepped_address = (int)addr; | ||
145 | |||
146 | /* Replace it */ | ||
147 | stepped_opcode = __raw_readw((long)addr); | ||
148 | *addr = STEP_OPCODE; | ||
149 | |||
150 | /* Flush and return */ | ||
151 | flush_icache_range((long)addr, (long)addr + | ||
152 | instruction_size(stepped_opcode)); | ||
153 | } | ||
154 | |||
155 | /* Undo a single step */ | ||
156 | static void undo_single_step(struct pt_regs *linux_regs) | ||
157 | { | ||
158 | /* If we have stepped, put back the old instruction */ | ||
159 | /* Use stepped_address in case we stopped elsewhere */ | ||
160 | if (stepped_opcode != 0) { | ||
161 | __raw_writew(stepped_opcode, stepped_address); | ||
162 | flush_icache_range(stepped_address, stepped_address + 2); | ||
163 | } | ||
164 | |||
165 | stepped_opcode = 0; | ||
166 | } | ||
167 | |||
168 | void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs) | ||
169 | { | ||
170 | int i; | ||
171 | |||
172 | for (i = 0; i < 16; i++) | ||
173 | gdb_regs[GDB_R0 + i] = regs->regs[i]; | ||
174 | |||
175 | gdb_regs[GDB_PC] = regs->pc; | ||
176 | gdb_regs[GDB_PR] = regs->pr; | ||
177 | gdb_regs[GDB_SR] = regs->sr; | ||
178 | gdb_regs[GDB_GBR] = regs->gbr; | ||
179 | gdb_regs[GDB_MACH] = regs->mach; | ||
180 | gdb_regs[GDB_MACL] = regs->macl; | ||
181 | |||
182 | __asm__ __volatile__ ("stc vbr, %0" : "=r" (gdb_regs[GDB_VBR])); | ||
183 | } | ||
184 | |||
185 | void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs) | ||
186 | { | ||
187 | int i; | ||
188 | |||
189 | for (i = 0; i < 16; i++) | ||
190 | regs->regs[GDB_R0 + i] = gdb_regs[GDB_R0 + i]; | ||
191 | |||
192 | regs->pc = gdb_regs[GDB_PC]; | ||
193 | regs->pr = gdb_regs[GDB_PR]; | ||
194 | regs->sr = gdb_regs[GDB_SR]; | ||
195 | regs->gbr = gdb_regs[GDB_GBR]; | ||
196 | regs->mach = gdb_regs[GDB_MACH]; | ||
197 | regs->macl = gdb_regs[GDB_MACL]; | ||
198 | |||
199 | __asm__ __volatile__ ("ldc %0, vbr" : : "r" (gdb_regs[GDB_VBR])); | ||
200 | } | ||
201 | |||
202 | void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p) | ||
203 | { | ||
204 | gdb_regs[GDB_R15] = p->thread.sp; | ||
205 | gdb_regs[GDB_PC] = p->thread.pc; | ||
206 | } | ||
207 | |||
208 | int kgdb_arch_handle_exception(int e_vector, int signo, int err_code, | ||
209 | char *remcomInBuffer, char *remcomOutBuffer, | ||
210 | struct pt_regs *linux_regs) | ||
211 | { | ||
212 | unsigned long addr; | ||
213 | char *ptr; | ||
214 | |||
215 | /* Undo any stepping we may have done */ | ||
216 | undo_single_step(linux_regs); | ||
217 | |||
218 | switch (remcomInBuffer[0]) { | ||
219 | case 'c': | ||
220 | case 's': | ||
221 | /* try to read optional parameter, pc unchanged if no parm */ | ||
222 | ptr = &remcomInBuffer[1]; | ||
223 | if (kgdb_hex2long(&ptr, &addr)) | ||
224 | linux_regs->pc = addr; | ||
225 | case 'D': | ||
226 | case 'k': | ||
227 | atomic_set(&kgdb_cpu_doing_single_step, -1); | ||
228 | |||
229 | if (remcomInBuffer[0] == 's') { | ||
230 | do_single_step(linux_regs); | ||
231 | kgdb_single_step = 1; | ||
232 | |||
233 | atomic_set(&kgdb_cpu_doing_single_step, | ||
234 | raw_smp_processor_id()); | ||
235 | } | ||
236 | |||
237 | return 0; | ||
238 | } | ||
239 | |||
240 | /* this means that we do not want to exit from the handler: */ | ||
241 | return -1; | ||
242 | } | ||
243 | |||
244 | /* | ||
245 | * The primary entry points for the kgdb debug trap table entries. | ||
246 | */ | ||
247 | BUILD_TRAP_HANDLER(singlestep) | ||
248 | { | ||
249 | unsigned long flags; | ||
250 | TRAP_HANDLER_DECL; | ||
251 | |||
252 | local_irq_save(flags); | ||
253 | regs->pc -= instruction_size(__raw_readw(regs->pc - 4)); | ||
254 | kgdb_handle_exception(vec >> 2, SIGTRAP, 0, regs); | ||
255 | local_irq_restore(flags); | ||
256 | } | ||
257 | |||
258 | |||
259 | BUILD_TRAP_HANDLER(breakpoint) | ||
260 | { | ||
261 | unsigned long flags; | ||
262 | TRAP_HANDLER_DECL; | ||
263 | |||
264 | local_irq_save(flags); | ||
265 | kgdb_handle_exception(vec >> 2, SIGTRAP, 0, regs); | ||
266 | local_irq_restore(flags); | ||
267 | } | ||
268 | |||
269 | int kgdb_arch_init(void) | ||
270 | { | ||
271 | return 0; | ||
272 | } | ||
273 | |||
274 | void kgdb_arch_exit(void) | ||
275 | { | ||
276 | } | ||
277 | |||
278 | struct kgdb_arch arch_kgdb_ops = { | ||
279 | /* Breakpoint instruction: trapa #0x3c */ | ||
280 | #ifdef CONFIG_CPU_LITTLE_ENDIAN | ||
281 | .gdb_bpt_instr = { 0x3c, 0xc3 }, | ||
282 | #else | ||
283 | .gdb_bpt_instr = { 0xc3, 0x3c }, | ||
284 | #endif | ||
285 | }; | ||
diff --git a/arch/sh/kernel/kgdb_jmp.S b/arch/sh/kernel/kgdb_jmp.S deleted file mode 100644 index 339bb1d7ff0b..000000000000 --- a/arch/sh/kernel/kgdb_jmp.S +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | #include <linux/linkage.h> | ||
2 | |||
3 | ENTRY(setjmp) | ||
4 | add #(9*4), r4 | ||
5 | sts.l pr, @-r4 | ||
6 | mov.l r15, @-r4 | ||
7 | mov.l r14, @-r4 | ||
8 | mov.l r13, @-r4 | ||
9 | mov.l r12, @-r4 | ||
10 | mov.l r11, @-r4 | ||
11 | mov.l r10, @-r4 | ||
12 | mov.l r9, @-r4 | ||
13 | mov.l r8, @-r4 | ||
14 | rts | ||
15 | mov #0, r0 | ||
16 | |||
17 | ENTRY(longjmp) | ||
18 | mov.l @r4+, r8 | ||
19 | mov.l @r4+, r9 | ||
20 | mov.l @r4+, r10 | ||
21 | mov.l @r4+, r11 | ||
22 | mov.l @r4+, r12 | ||
23 | mov.l @r4+, r13 | ||
24 | mov.l @r4+, r14 | ||
25 | mov.l @r4+, r15 | ||
26 | lds.l @r4+, pr | ||
27 | mov r5, r0 | ||
28 | tst r0, r0 | ||
29 | bf 1f | ||
30 | mov #1, r0 ! in case val==0 | ||
31 | 1: rts | ||
32 | nop | ||
33 | |||
diff --git a/arch/sh/kernel/kgdb_stub.c b/arch/sh/kernel/kgdb_stub.c deleted file mode 100644 index bf8ac4c71640..000000000000 --- a/arch/sh/kernel/kgdb_stub.c +++ /dev/null | |||
@@ -1,1052 +0,0 @@ | |||
1 | /* | ||
2 | * May be copied or modified under the terms of the GNU General Public | ||
3 | * License. See linux/COPYING for more information. | ||
4 | * | ||
5 | * Contains extracts from code by Glenn Engel, Jim Kingdon, | ||
6 | * David Grothe <dave@gcom.com>, Tigran Aivazian <tigran@sco.com>, | ||
7 | * Amit S. Kale <akale@veritas.com>, William Gatliff <bgat@open-widgets.com>, | ||
8 | * Ben Lee, Steve Chamberlain and Benoit Miller <fulg@iname.com>. | ||
9 | * | ||
10 | * This version by Henry Bell <henry.bell@st.com> | ||
11 | * Minor modifications by Jeremy Siegel <jsiegel@mvista.com> | ||
12 | * | ||
13 | * Contains low-level support for remote debug using GDB. | ||
14 | * | ||
15 | * To enable debugger support, two things need to happen. A call to | ||
16 | * set_debug_traps() is necessary in order to allow any breakpoints | ||
17 | * or error conditions to be properly intercepted and reported to gdb. | ||
18 | * A breakpoint also needs to be generated to begin communication. This | ||
19 | * is most easily accomplished by a call to breakpoint() which does | ||
20 | * a trapa if the initialisation phase has been successfully completed. | ||
21 | * | ||
22 | * In this case, set_debug_traps() is not used to "take over" exceptions; | ||
23 | * other kernel code is modified instead to enter the kgdb functions here | ||
24 | * when appropriate (see entry.S for breakpoint traps and NMI interrupts, | ||
25 | * see traps.c for kernel error exceptions). | ||
26 | * | ||
27 | * The following gdb commands are supported: | ||
28 | * | ||
29 | * Command Function Return value | ||
30 | * | ||
31 | * g return the value of the CPU registers hex data or ENN | ||
32 | * G set the value of the CPU registers OK or ENN | ||
33 | * | ||
34 | * mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN | ||
35 | * MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN | ||
36 | * XAA..AA,LLLL: Same, but data is binary (not hex) OK or ENN | ||
37 | * | ||
38 | * c Resume at current address SNN ( signal NN) | ||
39 | * cAA..AA Continue at address AA..AA SNN | ||
40 | * CNN; Resume at current address with signal SNN | ||
41 | * CNN;AA..AA Resume at address AA..AA with signal SNN | ||
42 | * | ||
43 | * s Step one instruction SNN | ||
44 | * sAA..AA Step one instruction from AA..AA SNN | ||
45 | * SNN; Step one instruction with signal SNN | ||
46 | * SNNAA..AA Step one instruction from AA..AA w/NN SNN | ||
47 | * | ||
48 | * k kill (Detach GDB) | ||
49 | * | ||
50 | * d Toggle debug flag | ||
51 | * D Detach GDB | ||
52 | * | ||
53 | * Hct Set thread t for operations, OK or ENN | ||
54 | * c = 'c' (step, cont), c = 'g' (other | ||
55 | * operations) | ||
56 | * | ||
57 | * qC Query current thread ID QCpid | ||
58 | * qfThreadInfo Get list of current threads (first) m<id> | ||
59 | * qsThreadInfo " " " " " (subsequent) | ||
60 | * qOffsets Get section offsets Text=x;Data=y;Bss=z | ||
61 | * | ||
62 | * TXX Find if thread XX is alive OK or ENN | ||
63 | * ? What was the last sigval ? SNN (signal NN) | ||
64 | * O Output to GDB console | ||
65 | * | ||
66 | * Remote communication protocol. | ||
67 | * | ||
68 | * A debug packet whose contents are <data> is encapsulated for | ||
69 | * transmission in the form: | ||
70 | * | ||
71 | * $ <data> # CSUM1 CSUM2 | ||
72 | * | ||
73 | * <data> must be ASCII alphanumeric and cannot include characters | ||
74 | * '$' or '#'. If <data> starts with two characters followed by | ||
75 | * ':', then the existing stubs interpret this as a sequence number. | ||
76 | * | ||
77 | * CSUM1 and CSUM2 are ascii hex representation of an 8-bit | ||
78 | * checksum of <data>, the most significant nibble is sent first. | ||
79 | * the hex digits 0-9,a-f are used. | ||
80 | * | ||
81 | * Receiver responds with: | ||
82 | * | ||
83 | * + - if CSUM is correct and ready for next packet | ||
84 | * - - if CSUM is incorrect | ||
85 | * | ||
86 | * Responses can be run-length encoded to save space. A '*' means that | ||
87 | * the next character is an ASCII encoding giving a repeat count which | ||
88 | * stands for that many repetitions of the character preceding the '*'. | ||
89 | * The encoding is n+29, yielding a printable character where n >=3 | ||
90 | * (which is where RLE starts to win). Don't use an n > 126. | ||
91 | * | ||
92 | * So "0* " means the same as "0000". | ||
93 | */ | ||
94 | |||
95 | #include <linux/string.h> | ||
96 | #include <linux/kernel.h> | ||
97 | #include <linux/sched.h> | ||
98 | #include <linux/smp.h> | ||
99 | #include <linux/spinlock.h> | ||
100 | #include <linux/delay.h> | ||
101 | #include <linux/linkage.h> | ||
102 | #include <linux/init.h> | ||
103 | #include <linux/console.h> | ||
104 | #include <linux/sysrq.h> | ||
105 | #include <linux/module.h> | ||
106 | #include <asm/system.h> | ||
107 | #include <asm/cacheflush.h> | ||
108 | #include <asm/current.h> | ||
109 | #include <asm/signal.h> | ||
110 | #include <asm/pgtable.h> | ||
111 | #include <asm/ptrace.h> | ||
112 | #include <asm/kgdb.h> | ||
113 | #include <asm/io.h> | ||
114 | |||
115 | /* Function pointers for linkage */ | ||
116 | kgdb_debug_hook_t *kgdb_debug_hook; | ||
117 | kgdb_bus_error_hook_t *kgdb_bus_err_hook; | ||
118 | |||
119 | int (*kgdb_getchar)(void); | ||
120 | EXPORT_SYMBOL_GPL(kgdb_getchar); | ||
121 | void (*kgdb_putchar)(int); | ||
122 | EXPORT_SYMBOL_GPL(kgdb_putchar); | ||
123 | |||
124 | static void put_debug_char(int c) | ||
125 | { | ||
126 | if (!kgdb_putchar) | ||
127 | return; | ||
128 | (*kgdb_putchar)(c); | ||
129 | } | ||
130 | static int get_debug_char(void) | ||
131 | { | ||
132 | if (!kgdb_getchar) | ||
133 | return -1; | ||
134 | return (*kgdb_getchar)(); | ||
135 | } | ||
136 | |||
137 | /* Num chars in in/out bound buffers, register packets need NUMREGBYTES * 2 */ | ||
138 | #define BUFMAX 1024 | ||
139 | #define NUMREGBYTES (MAXREG*4) | ||
140 | #define OUTBUFMAX (NUMREGBYTES*2+512) | ||
141 | |||
142 | enum { | ||
143 | R0 = 0, R1, R2, R3, R4, R5, R6, R7, | ||
144 | R8, R9, R10, R11, R12, R13, R14, R15, | ||
145 | PC, PR, GBR, VBR, MACH, MACL, SR, | ||
146 | /* */ | ||
147 | MAXREG | ||
148 | }; | ||
149 | |||
150 | static unsigned int registers[MAXREG]; | ||
151 | struct kgdb_regs trap_registers; | ||
152 | |||
153 | char kgdb_in_gdb_mode; | ||
154 | char in_nmi; /* Set during NMI to prevent reentry */ | ||
155 | int kgdb_nofault; /* Boolean to ignore bus errs (i.e. in GDB) */ | ||
156 | |||
157 | /* Default values for SCI (can override via kernel args in setup.c) */ | ||
158 | #ifndef CONFIG_KGDB_DEFPORT | ||
159 | #define CONFIG_KGDB_DEFPORT 1 | ||
160 | #endif | ||
161 | |||
162 | #ifndef CONFIG_KGDB_DEFBAUD | ||
163 | #define CONFIG_KGDB_DEFBAUD 115200 | ||
164 | #endif | ||
165 | |||
166 | #if defined(CONFIG_KGDB_DEFPARITY_E) | ||
167 | #define CONFIG_KGDB_DEFPARITY 'E' | ||
168 | #elif defined(CONFIG_KGDB_DEFPARITY_O) | ||
169 | #define CONFIG_KGDB_DEFPARITY 'O' | ||
170 | #else /* CONFIG_KGDB_DEFPARITY_N */ | ||
171 | #define CONFIG_KGDB_DEFPARITY 'N' | ||
172 | #endif | ||
173 | |||
174 | #ifdef CONFIG_KGDB_DEFBITS_7 | ||
175 | #define CONFIG_KGDB_DEFBITS '7' | ||
176 | #else /* CONFIG_KGDB_DEFBITS_8 */ | ||
177 | #define CONFIG_KGDB_DEFBITS '8' | ||
178 | #endif | ||
179 | |||
180 | /* SCI/UART settings, used in kgdb_console_setup() */ | ||
181 | int kgdb_portnum = CONFIG_KGDB_DEFPORT; | ||
182 | EXPORT_SYMBOL_GPL(kgdb_portnum); | ||
183 | int kgdb_baud = CONFIG_KGDB_DEFBAUD; | ||
184 | EXPORT_SYMBOL_GPL(kgdb_baud); | ||
185 | char kgdb_parity = CONFIG_KGDB_DEFPARITY; | ||
186 | EXPORT_SYMBOL_GPL(kgdb_parity); | ||
187 | char kgdb_bits = CONFIG_KGDB_DEFBITS; | ||
188 | EXPORT_SYMBOL_GPL(kgdb_bits); | ||
189 | |||
190 | /* Jump buffer for setjmp/longjmp */ | ||
191 | static jmp_buf rem_com_env; | ||
192 | |||
193 | /* TRA differs sh3/4 */ | ||
194 | #if defined(CONFIG_CPU_SH3) | ||
195 | #define TRA 0xffffffd0 | ||
196 | #elif defined(CONFIG_CPU_SH4) | ||
197 | #define TRA 0xff000020 | ||
198 | #endif | ||
199 | |||
200 | /* Macros for single step instruction identification */ | ||
201 | #define OPCODE_BT(op) (((op) & 0xff00) == 0x8900) | ||
202 | #define OPCODE_BF(op) (((op) & 0xff00) == 0x8b00) | ||
203 | #define OPCODE_BTF_DISP(op) (((op) & 0x80) ? (((op) | 0xffffff80) << 1) : \ | ||
204 | (((op) & 0x7f ) << 1)) | ||
205 | #define OPCODE_BFS(op) (((op) & 0xff00) == 0x8f00) | ||
206 | #define OPCODE_BTS(op) (((op) & 0xff00) == 0x8d00) | ||
207 | #define OPCODE_BRA(op) (((op) & 0xf000) == 0xa000) | ||
208 | #define OPCODE_BRA_DISP(op) (((op) & 0x800) ? (((op) | 0xfffff800) << 1) : \ | ||
209 | (((op) & 0x7ff) << 1)) | ||
210 | #define OPCODE_BRAF(op) (((op) & 0xf0ff) == 0x0023) | ||
211 | #define OPCODE_BRAF_REG(op) (((op) & 0x0f00) >> 8) | ||
212 | #define OPCODE_BSR(op) (((op) & 0xf000) == 0xb000) | ||
213 | #define OPCODE_BSR_DISP(op) (((op) & 0x800) ? (((op) | 0xfffff800) << 1) : \ | ||
214 | (((op) & 0x7ff) << 1)) | ||
215 | #define OPCODE_BSRF(op) (((op) & 0xf0ff) == 0x0003) | ||
216 | #define OPCODE_BSRF_REG(op) (((op) >> 8) & 0xf) | ||
217 | #define OPCODE_JMP(op) (((op) & 0xf0ff) == 0x402b) | ||
218 | #define OPCODE_JMP_REG(op) (((op) >> 8) & 0xf) | ||
219 | #define OPCODE_JSR(op) (((op) & 0xf0ff) == 0x400b) | ||
220 | #define OPCODE_JSR_REG(op) (((op) >> 8) & 0xf) | ||
221 | #define OPCODE_RTS(op) ((op) == 0xb) | ||
222 | #define OPCODE_RTE(op) ((op) == 0x2b) | ||
223 | |||
224 | #define SR_T_BIT_MASK 0x1 | ||
225 | #define STEP_OPCODE 0xc320 | ||
226 | #define BIOS_CALL_TRAP 0x3f | ||
227 | |||
228 | /* Exception codes as per SH-4 core manual */ | ||
229 | #define ADDRESS_ERROR_LOAD_VEC 7 | ||
230 | #define ADDRESS_ERROR_STORE_VEC 8 | ||
231 | #define TRAP_VEC 11 | ||
232 | #define INVALID_INSN_VEC 12 | ||
233 | #define INVALID_SLOT_VEC 13 | ||
234 | #define NMI_VEC 14 | ||
235 | #define USER_BREAK_VEC 15 | ||
236 | #define SERIAL_BREAK_VEC 58 | ||
237 | |||
238 | /* Misc static */ | ||
239 | static int stepped_address; | ||
240 | static short stepped_opcode; | ||
241 | static char in_buffer[BUFMAX]; | ||
242 | static char out_buffer[OUTBUFMAX]; | ||
243 | |||
244 | static void kgdb_to_gdb(const char *s); | ||
245 | |||
246 | /* Convert ch to hex */ | ||
247 | static int hex(const char ch) | ||
248 | { | ||
249 | if ((ch >= 'a') && (ch <= 'f')) | ||
250 | return (ch - 'a' + 10); | ||
251 | if ((ch >= '0') && (ch <= '9')) | ||
252 | return (ch - '0'); | ||
253 | if ((ch >= 'A') && (ch <= 'F')) | ||
254 | return (ch - 'A' + 10); | ||
255 | return (-1); | ||
256 | } | ||
257 | |||
258 | /* Convert the memory pointed to by mem into hex, placing result in buf. | ||
259 | Returns a pointer to the last char put in buf (null) */ | ||
260 | static char *mem_to_hex(const char *mem, char *buf, const int count) | ||
261 | { | ||
262 | int i; | ||
263 | int ch; | ||
264 | unsigned short s_val; | ||
265 | unsigned long l_val; | ||
266 | |||
267 | /* Check for 16 or 32 */ | ||
268 | if (count == 2 && ((long) mem & 1) == 0) { | ||
269 | s_val = *(unsigned short *) mem; | ||
270 | mem = (char *) &s_val; | ||
271 | } else if (count == 4 && ((long) mem & 3) == 0) { | ||
272 | l_val = *(unsigned long *) mem; | ||
273 | mem = (char *) &l_val; | ||
274 | } | ||
275 | for (i = 0; i < count; i++) { | ||
276 | ch = *mem++; | ||
277 | buf = pack_hex_byte(buf, ch); | ||
278 | } | ||
279 | *buf = 0; | ||
280 | return (buf); | ||
281 | } | ||
282 | |||
283 | /* Convert the hex array pointed to by buf into binary, to be placed in mem. | ||
284 | Return a pointer to the character after the last byte written */ | ||
285 | static char *hex_to_mem(const char *buf, char *mem, const int count) | ||
286 | { | ||
287 | int i; | ||
288 | unsigned char ch; | ||
289 | |||
290 | for (i = 0; i < count; i++) { | ||
291 | ch = hex(*buf++) << 4; | ||
292 | ch = ch + hex(*buf++); | ||
293 | *mem++ = ch; | ||
294 | } | ||
295 | return (mem); | ||
296 | } | ||
297 | |||
298 | /* While finding valid hex chars, convert to an integer, then return it */ | ||
299 | static int hex_to_int(char **ptr, int *int_value) | ||
300 | { | ||
301 | int num_chars = 0; | ||
302 | int hex_value; | ||
303 | |||
304 | *int_value = 0; | ||
305 | |||
306 | while (**ptr) { | ||
307 | hex_value = hex(**ptr); | ||
308 | if (hex_value >= 0) { | ||
309 | *int_value = (*int_value << 4) | hex_value; | ||
310 | num_chars++; | ||
311 | } else | ||
312 | break; | ||
313 | (*ptr)++; | ||
314 | } | ||
315 | return num_chars; | ||
316 | } | ||
317 | |||
318 | /* Copy the binary array pointed to by buf into mem. Fix $, #, | ||
319 | and 0x7d escaped with 0x7d. Return a pointer to the character | ||
320 | after the last byte written. */ | ||
321 | static char *ebin_to_mem(const char *buf, char *mem, int count) | ||
322 | { | ||
323 | for (; count > 0; count--, buf++) { | ||
324 | if (*buf == 0x7d) | ||
325 | *mem++ = *(++buf) ^ 0x20; | ||
326 | else | ||
327 | *mem++ = *buf; | ||
328 | } | ||
329 | return mem; | ||
330 | } | ||
331 | |||
332 | /* Scan for the start char '$', read the packet and check the checksum */ | ||
333 | static void get_packet(char *buffer, int buflen) | ||
334 | { | ||
335 | unsigned char checksum; | ||
336 | unsigned char xmitcsum; | ||
337 | int i; | ||
338 | int count; | ||
339 | char ch; | ||
340 | |||
341 | do { | ||
342 | /* Ignore everything until the start character */ | ||
343 | while ((ch = get_debug_char()) != '$'); | ||
344 | |||
345 | checksum = 0; | ||
346 | xmitcsum = -1; | ||
347 | count = 0; | ||
348 | |||
349 | /* Now, read until a # or end of buffer is found */ | ||
350 | while (count < (buflen - 1)) { | ||
351 | ch = get_debug_char(); | ||
352 | |||
353 | if (ch == '#') | ||
354 | break; | ||
355 | |||
356 | checksum = checksum + ch; | ||
357 | buffer[count] = ch; | ||
358 | count = count + 1; | ||
359 | } | ||
360 | |||
361 | buffer[count] = 0; | ||
362 | |||
363 | /* Continue to read checksum following # */ | ||
364 | if (ch == '#') { | ||
365 | xmitcsum = hex(get_debug_char()) << 4; | ||
366 | xmitcsum += hex(get_debug_char()); | ||
367 | |||
368 | /* Checksum */ | ||
369 | if (checksum != xmitcsum) | ||
370 | put_debug_char('-'); /* Failed checksum */ | ||
371 | else { | ||
372 | /* Ack successful transfer */ | ||
373 | put_debug_char('+'); | ||
374 | |||
375 | /* If a sequence char is present, reply | ||
376 | the sequence ID */ | ||
377 | if (buffer[2] == ':') { | ||
378 | put_debug_char(buffer[0]); | ||
379 | put_debug_char(buffer[1]); | ||
380 | |||
381 | /* Remove sequence chars from buffer */ | ||
382 | count = strlen(buffer); | ||
383 | for (i = 3; i <= count; i++) | ||
384 | buffer[i - 3] = buffer[i]; | ||
385 | } | ||
386 | } | ||
387 | } | ||
388 | } | ||
389 | while (checksum != xmitcsum); /* Keep trying while we fail */ | ||
390 | } | ||
391 | |||
392 | /* Send the packet in the buffer with run-length encoding */ | ||
393 | static void put_packet(char *buffer) | ||
394 | { | ||
395 | int checksum; | ||
396 | char *src; | ||
397 | int runlen; | ||
398 | int encode; | ||
399 | |||
400 | do { | ||
401 | src = buffer; | ||
402 | put_debug_char('$'); | ||
403 | checksum = 0; | ||
404 | |||
405 | /* Continue while we still have chars left */ | ||
406 | while (*src) { | ||
407 | /* Check for runs up to 99 chars long */ | ||
408 | for (runlen = 1; runlen < 99; runlen++) { | ||
409 | if (src[0] != src[runlen]) | ||
410 | break; | ||
411 | } | ||
412 | |||
413 | if (runlen > 3) { | ||
414 | /* Got a useful amount, send encoding */ | ||
415 | encode = runlen + ' ' - 4; | ||
416 | put_debug_char(*src); checksum += *src; | ||
417 | put_debug_char('*'); checksum += '*'; | ||
418 | put_debug_char(encode); checksum += encode; | ||
419 | src += runlen; | ||
420 | } else { | ||
421 | /* Otherwise just send the current char */ | ||
422 | put_debug_char(*src); checksum += *src; | ||
423 | src += 1; | ||
424 | } | ||
425 | } | ||
426 | |||
427 | /* '#' Separator, put high and low components of checksum */ | ||
428 | put_debug_char('#'); | ||
429 | put_debug_char(hex_asc_hi(checksum)); | ||
430 | put_debug_char(hex_asc_lo(checksum)); | ||
431 | } | ||
432 | while ((get_debug_char()) != '+'); /* While no ack */ | ||
433 | } | ||
434 | |||
435 | /* A bus error has occurred - perform a longjmp to return execution and | ||
436 | allow handling of the error */ | ||
437 | static void kgdb_handle_bus_error(void) | ||
438 | { | ||
439 | longjmp(rem_com_env, 1); | ||
440 | } | ||
441 | |||
442 | /* Translate SH-3/4 exception numbers to unix-like signal values */ | ||
443 | static int compute_signal(const int excep_code) | ||
444 | { | ||
445 | int sigval; | ||
446 | |||
447 | switch (excep_code) { | ||
448 | |||
449 | case INVALID_INSN_VEC: | ||
450 | case INVALID_SLOT_VEC: | ||
451 | sigval = SIGILL; | ||
452 | break; | ||
453 | case ADDRESS_ERROR_LOAD_VEC: | ||
454 | case ADDRESS_ERROR_STORE_VEC: | ||
455 | sigval = SIGSEGV; | ||
456 | break; | ||
457 | |||
458 | case SERIAL_BREAK_VEC: | ||
459 | case NMI_VEC: | ||
460 | sigval = SIGINT; | ||
461 | break; | ||
462 | |||
463 | case USER_BREAK_VEC: | ||
464 | case TRAP_VEC: | ||
465 | sigval = SIGTRAP; | ||
466 | break; | ||
467 | |||
468 | default: | ||
469 | sigval = SIGBUS; /* "software generated" */ | ||
470 | break; | ||
471 | } | ||
472 | |||
473 | return (sigval); | ||
474 | } | ||
475 | |||
476 | /* Make a local copy of the registers passed into the handler (bletch) */ | ||
477 | static void kgdb_regs_to_gdb_regs(const struct kgdb_regs *regs, | ||
478 | int *gdb_regs) | ||
479 | { | ||
480 | gdb_regs[R0] = regs->regs[R0]; | ||
481 | gdb_regs[R1] = regs->regs[R1]; | ||
482 | gdb_regs[R2] = regs->regs[R2]; | ||
483 | gdb_regs[R3] = regs->regs[R3]; | ||
484 | gdb_regs[R4] = regs->regs[R4]; | ||
485 | gdb_regs[R5] = regs->regs[R5]; | ||
486 | gdb_regs[R6] = regs->regs[R6]; | ||
487 | gdb_regs[R7] = regs->regs[R7]; | ||
488 | gdb_regs[R8] = regs->regs[R8]; | ||
489 | gdb_regs[R9] = regs->regs[R9]; | ||
490 | gdb_regs[R10] = regs->regs[R10]; | ||
491 | gdb_regs[R11] = regs->regs[R11]; | ||
492 | gdb_regs[R12] = regs->regs[R12]; | ||
493 | gdb_regs[R13] = regs->regs[R13]; | ||
494 | gdb_regs[R14] = regs->regs[R14]; | ||
495 | gdb_regs[R15] = regs->regs[R15]; | ||
496 | gdb_regs[PC] = regs->pc; | ||
497 | gdb_regs[PR] = regs->pr; | ||
498 | gdb_regs[GBR] = regs->gbr; | ||
499 | gdb_regs[MACH] = regs->mach; | ||
500 | gdb_regs[MACL] = regs->macl; | ||
501 | gdb_regs[SR] = regs->sr; | ||
502 | gdb_regs[VBR] = regs->vbr; | ||
503 | } | ||
504 | |||
505 | /* Copy local gdb registers back to kgdb regs, for later copy to kernel */ | ||
506 | static void gdb_regs_to_kgdb_regs(const int *gdb_regs, | ||
507 | struct kgdb_regs *regs) | ||
508 | { | ||
509 | regs->regs[R0] = gdb_regs[R0]; | ||
510 | regs->regs[R1] = gdb_regs[R1]; | ||
511 | regs->regs[R2] = gdb_regs[R2]; | ||
512 | regs->regs[R3] = gdb_regs[R3]; | ||
513 | regs->regs[R4] = gdb_regs[R4]; | ||
514 | regs->regs[R5] = gdb_regs[R5]; | ||
515 | regs->regs[R6] = gdb_regs[R6]; | ||
516 | regs->regs[R7] = gdb_regs[R7]; | ||
517 | regs->regs[R8] = gdb_regs[R8]; | ||
518 | regs->regs[R9] = gdb_regs[R9]; | ||
519 | regs->regs[R10] = gdb_regs[R10]; | ||
520 | regs->regs[R11] = gdb_regs[R11]; | ||
521 | regs->regs[R12] = gdb_regs[R12]; | ||
522 | regs->regs[R13] = gdb_regs[R13]; | ||
523 | regs->regs[R14] = gdb_regs[R14]; | ||
524 | regs->regs[R15] = gdb_regs[R15]; | ||
525 | regs->pc = gdb_regs[PC]; | ||
526 | regs->pr = gdb_regs[PR]; | ||
527 | regs->gbr = gdb_regs[GBR]; | ||
528 | regs->mach = gdb_regs[MACH]; | ||
529 | regs->macl = gdb_regs[MACL]; | ||
530 | regs->sr = gdb_regs[SR]; | ||
531 | regs->vbr = gdb_regs[VBR]; | ||
532 | } | ||
533 | |||
534 | /* Calculate the new address for after a step */ | ||
535 | static short *get_step_address(void) | ||
536 | { | ||
537 | short op = *(short *) trap_registers.pc; | ||
538 | long addr; | ||
539 | |||
540 | /* BT */ | ||
541 | if (OPCODE_BT(op)) { | ||
542 | if (trap_registers.sr & SR_T_BIT_MASK) | ||
543 | addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op); | ||
544 | else | ||
545 | addr = trap_registers.pc + 2; | ||
546 | } | ||
547 | |||
548 | /* BTS */ | ||
549 | else if (OPCODE_BTS(op)) { | ||
550 | if (trap_registers.sr & SR_T_BIT_MASK) | ||
551 | addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op); | ||
552 | else | ||
553 | addr = trap_registers.pc + 4; /* Not in delay slot */ | ||
554 | } | ||
555 | |||
556 | /* BF */ | ||
557 | else if (OPCODE_BF(op)) { | ||
558 | if (!(trap_registers.sr & SR_T_BIT_MASK)) | ||
559 | addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op); | ||
560 | else | ||
561 | addr = trap_registers.pc + 2; | ||
562 | } | ||
563 | |||
564 | /* BFS */ | ||
565 | else if (OPCODE_BFS(op)) { | ||
566 | if (!(trap_registers.sr & SR_T_BIT_MASK)) | ||
567 | addr = trap_registers.pc + 4 + OPCODE_BTF_DISP(op); | ||
568 | else | ||
569 | addr = trap_registers.pc + 4; /* Not in delay slot */ | ||
570 | } | ||
571 | |||
572 | /* BRA */ | ||
573 | else if (OPCODE_BRA(op)) | ||
574 | addr = trap_registers.pc + 4 + OPCODE_BRA_DISP(op); | ||
575 | |||
576 | /* BRAF */ | ||
577 | else if (OPCODE_BRAF(op)) | ||
578 | addr = trap_registers.pc + 4 | ||
579 | + trap_registers.regs[OPCODE_BRAF_REG(op)]; | ||
580 | |||
581 | /* BSR */ | ||
582 | else if (OPCODE_BSR(op)) | ||
583 | addr = trap_registers.pc + 4 + OPCODE_BSR_DISP(op); | ||
584 | |||
585 | /* BSRF */ | ||
586 | else if (OPCODE_BSRF(op)) | ||
587 | addr = trap_registers.pc + 4 | ||
588 | + trap_registers.regs[OPCODE_BSRF_REG(op)]; | ||
589 | |||
590 | /* JMP */ | ||
591 | else if (OPCODE_JMP(op)) | ||
592 | addr = trap_registers.regs[OPCODE_JMP_REG(op)]; | ||
593 | |||
594 | /* JSR */ | ||
595 | else if (OPCODE_JSR(op)) | ||
596 | addr = trap_registers.regs[OPCODE_JSR_REG(op)]; | ||
597 | |||
598 | /* RTS */ | ||
599 | else if (OPCODE_RTS(op)) | ||
600 | addr = trap_registers.pr; | ||
601 | |||
602 | /* RTE */ | ||
603 | else if (OPCODE_RTE(op)) | ||
604 | addr = trap_registers.regs[15]; | ||
605 | |||
606 | /* Other */ | ||
607 | else | ||
608 | addr = trap_registers.pc + 2; | ||
609 | |||
610 | flush_icache_range(addr, addr + 2); | ||
611 | return (short *) addr; | ||
612 | } | ||
613 | |||
614 | /* Set up a single-step. Replace the instruction immediately after the | ||
615 | current instruction (i.e. next in the expected flow of control) with a | ||
616 | trap instruction, so that returning will cause only a single instruction | ||
617 | to be executed. Note that this model is slightly broken for instructions | ||
618 | with delay slots (e.g. B[TF]S, BSR, BRA etc), where both the branch | ||
619 | and the instruction in the delay slot will be executed. */ | ||
620 | static void do_single_step(void) | ||
621 | { | ||
622 | unsigned short *addr = 0; | ||
623 | |||
624 | /* Determine where the target instruction will send us to */ | ||
625 | addr = get_step_address(); | ||
626 | stepped_address = (int)addr; | ||
627 | |||
628 | /* Replace it */ | ||
629 | stepped_opcode = *(short *)addr; | ||
630 | *addr = STEP_OPCODE; | ||
631 | |||
632 | /* Flush and return */ | ||
633 | flush_icache_range((long) addr, (long) addr + 2); | ||
634 | } | ||
635 | |||
636 | /* Undo a single step */ | ||
637 | static void undo_single_step(void) | ||
638 | { | ||
639 | /* If we have stepped, put back the old instruction */ | ||
640 | /* Use stepped_address in case we stopped elsewhere */ | ||
641 | if (stepped_opcode != 0) { | ||
642 | *(short*)stepped_address = stepped_opcode; | ||
643 | flush_icache_range(stepped_address, stepped_address + 2); | ||
644 | } | ||
645 | stepped_opcode = 0; | ||
646 | } | ||
647 | |||
648 | /* Send a signal message */ | ||
649 | static void send_signal_msg(const int signum) | ||
650 | { | ||
651 | out_buffer[0] = 'S'; | ||
652 | out_buffer[1] = hex_asc_hi(signum); | ||
653 | out_buffer[2] = hex_asc_lo(signum); | ||
654 | out_buffer[3] = 0; | ||
655 | put_packet(out_buffer); | ||
656 | } | ||
657 | |||
658 | /* Reply that all was well */ | ||
659 | static void send_ok_msg(void) | ||
660 | { | ||
661 | strcpy(out_buffer, "OK"); | ||
662 | put_packet(out_buffer); | ||
663 | } | ||
664 | |||
665 | /* Reply that an error occurred */ | ||
666 | static void send_err_msg(void) | ||
667 | { | ||
668 | strcpy(out_buffer, "E01"); | ||
669 | put_packet(out_buffer); | ||
670 | } | ||
671 | |||
672 | /* Empty message indicates unrecognised command */ | ||
673 | static void send_empty_msg(void) | ||
674 | { | ||
675 | put_packet(""); | ||
676 | } | ||
677 | |||
678 | /* Read memory due to 'm' message */ | ||
679 | static void read_mem_msg(void) | ||
680 | { | ||
681 | char *ptr; | ||
682 | int addr; | ||
683 | int length; | ||
684 | |||
685 | /* Jmp, disable bus error handler */ | ||
686 | if (setjmp(rem_com_env) == 0) { | ||
687 | |||
688 | kgdb_nofault = 1; | ||
689 | |||
690 | /* Walk through, have m<addr>,<length> */ | ||
691 | ptr = &in_buffer[1]; | ||
692 | if (hex_to_int(&ptr, &addr) && (*ptr++ == ',')) | ||
693 | if (hex_to_int(&ptr, &length)) { | ||
694 | ptr = 0; | ||
695 | if (length * 2 > OUTBUFMAX) | ||
696 | length = OUTBUFMAX / 2; | ||
697 | mem_to_hex((char *) addr, out_buffer, length); | ||
698 | } | ||
699 | if (ptr) | ||
700 | send_err_msg(); | ||
701 | else | ||
702 | put_packet(out_buffer); | ||
703 | } else | ||
704 | send_err_msg(); | ||
705 | |||
706 | /* Restore bus error handler */ | ||
707 | kgdb_nofault = 0; | ||
708 | } | ||
709 | |||
710 | /* Write memory due to 'M' or 'X' message */ | ||
711 | static void write_mem_msg(int binary) | ||
712 | { | ||
713 | char *ptr; | ||
714 | int addr; | ||
715 | int length; | ||
716 | |||
717 | if (setjmp(rem_com_env) == 0) { | ||
718 | |||
719 | kgdb_nofault = 1; | ||
720 | |||
721 | /* Walk through, have M<addr>,<length>:<data> */ | ||
722 | ptr = &in_buffer[1]; | ||
723 | if (hex_to_int(&ptr, &addr) && (*ptr++ == ',')) | ||
724 | if (hex_to_int(&ptr, &length) && (*ptr++ == ':')) { | ||
725 | if (binary) | ||
726 | ebin_to_mem(ptr, (char*)addr, length); | ||
727 | else | ||
728 | hex_to_mem(ptr, (char*)addr, length); | ||
729 | flush_icache_range(addr, addr + length); | ||
730 | ptr = 0; | ||
731 | send_ok_msg(); | ||
732 | } | ||
733 | if (ptr) | ||
734 | send_err_msg(); | ||
735 | } else | ||
736 | send_err_msg(); | ||
737 | |||
738 | /* Restore bus error handler */ | ||
739 | kgdb_nofault = 0; | ||
740 | } | ||
741 | |||
742 | /* Continue message */ | ||
743 | static void continue_msg(void) | ||
744 | { | ||
745 | /* Try to read optional parameter, PC unchanged if none */ | ||
746 | char *ptr = &in_buffer[1]; | ||
747 | int addr; | ||
748 | |||
749 | if (hex_to_int(&ptr, &addr)) | ||
750 | trap_registers.pc = addr; | ||
751 | } | ||
752 | |||
753 | /* Continue message with signal */ | ||
754 | static void continue_with_sig_msg(void) | ||
755 | { | ||
756 | int signal; | ||
757 | char *ptr = &in_buffer[1]; | ||
758 | int addr; | ||
759 | |||
760 | /* Report limitation */ | ||
761 | kgdb_to_gdb("Cannot force signal in kgdb, continuing anyway.\n"); | ||
762 | |||
763 | /* Signal */ | ||
764 | hex_to_int(&ptr, &signal); | ||
765 | if (*ptr == ';') | ||
766 | ptr++; | ||
767 | |||
768 | /* Optional address */ | ||
769 | if (hex_to_int(&ptr, &addr)) | ||
770 | trap_registers.pc = addr; | ||
771 | } | ||
772 | |||
773 | /* Step message */ | ||
774 | static void step_msg(void) | ||
775 | { | ||
776 | continue_msg(); | ||
777 | do_single_step(); | ||
778 | } | ||
779 | |||
780 | /* Step message with signal */ | ||
781 | static void step_with_sig_msg(void) | ||
782 | { | ||
783 | continue_with_sig_msg(); | ||
784 | do_single_step(); | ||
785 | } | ||
786 | |||
787 | /* Send register contents */ | ||
788 | static void send_regs_msg(void) | ||
789 | { | ||
790 | kgdb_regs_to_gdb_regs(&trap_registers, registers); | ||
791 | mem_to_hex((char *) registers, out_buffer, NUMREGBYTES); | ||
792 | put_packet(out_buffer); | ||
793 | } | ||
794 | |||
795 | /* Set register contents - currently can't set other thread's registers */ | ||
796 | static void set_regs_msg(void) | ||
797 | { | ||
798 | kgdb_regs_to_gdb_regs(&trap_registers, registers); | ||
799 | hex_to_mem(&in_buffer[1], (char *) registers, NUMREGBYTES); | ||
800 | gdb_regs_to_kgdb_regs(registers, &trap_registers); | ||
801 | send_ok_msg(); | ||
802 | } | ||
803 | |||
804 | #ifdef CONFIG_SH_KGDB_CONSOLE | ||
805 | /* | ||
806 | * Bring up the ports.. | ||
807 | */ | ||
808 | static int __init kgdb_serial_setup(void) | ||
809 | { | ||
810 | struct console dummy; | ||
811 | return kgdb_console_setup(&dummy, 0); | ||
812 | } | ||
813 | #else | ||
814 | #define kgdb_serial_setup() 0 | ||
815 | #endif | ||
816 | |||
817 | /* The command loop, read and act on requests */ | ||
818 | static void kgdb_command_loop(const int excep_code, const int trapa_value) | ||
819 | { | ||
820 | int sigval; | ||
821 | |||
822 | /* Enter GDB mode (e.g. after detach) */ | ||
823 | if (!kgdb_in_gdb_mode) { | ||
824 | /* Do serial setup, notify user, issue preemptive ack */ | ||
825 | printk(KERN_NOTICE "KGDB: Waiting for GDB\n"); | ||
826 | kgdb_in_gdb_mode = 1; | ||
827 | put_debug_char('+'); | ||
828 | } | ||
829 | |||
830 | /* Reply to host that an exception has occurred */ | ||
831 | sigval = compute_signal(excep_code); | ||
832 | send_signal_msg(sigval); | ||
833 | |||
834 | /* TRAP_VEC exception indicates a software trap inserted in place of | ||
835 | code by GDB so back up PC by one instruction, as this instruction | ||
836 | will later be replaced by its original one. Do NOT do this for | ||
837 | trap 0xff, since that indicates a compiled-in breakpoint which | ||
838 | will not be replaced (and we would retake the trap forever) */ | ||
839 | if ((excep_code == TRAP_VEC) && (trapa_value != (0x3c << 2))) | ||
840 | trap_registers.pc -= 2; | ||
841 | |||
842 | /* Undo any stepping we may have done */ | ||
843 | undo_single_step(); | ||
844 | |||
845 | while (1) { | ||
846 | out_buffer[0] = 0; | ||
847 | get_packet(in_buffer, BUFMAX); | ||
848 | |||
849 | /* Examine first char of buffer to see what we need to do */ | ||
850 | switch (in_buffer[0]) { | ||
851 | case '?': /* Send which signal we've received */ | ||
852 | send_signal_msg(sigval); | ||
853 | break; | ||
854 | |||
855 | case 'g': /* Return the values of the CPU registers */ | ||
856 | send_regs_msg(); | ||
857 | break; | ||
858 | |||
859 | case 'G': /* Set the value of the CPU registers */ | ||
860 | set_regs_msg(); | ||
861 | break; | ||
862 | |||
863 | case 'm': /* Read LLLL bytes address AA..AA */ | ||
864 | read_mem_msg(); | ||
865 | break; | ||
866 | |||
867 | case 'M': /* Write LLLL bytes address AA..AA, ret OK */ | ||
868 | write_mem_msg(0); /* 0 = data in hex */ | ||
869 | break; | ||
870 | |||
871 | case 'X': /* Write LLLL bytes esc bin address AA..AA */ | ||
872 | if (kgdb_bits == '8') | ||
873 | write_mem_msg(1); /* 1 = data in binary */ | ||
874 | else | ||
875 | send_empty_msg(); | ||
876 | break; | ||
877 | |||
878 | case 'C': /* Continue, signum included, we ignore it */ | ||
879 | continue_with_sig_msg(); | ||
880 | return; | ||
881 | |||
882 | case 'c': /* Continue at address AA..AA (optional) */ | ||
883 | continue_msg(); | ||
884 | return; | ||
885 | |||
886 | case 'S': /* Step, signum included, we ignore it */ | ||
887 | step_with_sig_msg(); | ||
888 | return; | ||
889 | |||
890 | case 's': /* Step one instruction from AA..AA */ | ||
891 | step_msg(); | ||
892 | return; | ||
893 | |||
894 | case 'k': /* 'Kill the program' with a kernel ? */ | ||
895 | break; | ||
896 | |||
897 | case 'D': /* Detach from program, send reply OK */ | ||
898 | kgdb_in_gdb_mode = 0; | ||
899 | send_ok_msg(); | ||
900 | get_debug_char(); | ||
901 | return; | ||
902 | |||
903 | default: | ||
904 | send_empty_msg(); | ||
905 | break; | ||
906 | } | ||
907 | } | ||
908 | } | ||
909 | |||
910 | /* There has been an exception, most likely a breakpoint. */ | ||
911 | static void handle_exception(struct pt_regs *regs) | ||
912 | { | ||
913 | int excep_code, vbr_val; | ||
914 | int count; | ||
915 | int trapa_value = ctrl_inl(TRA); | ||
916 | |||
917 | /* Copy kernel regs (from stack) */ | ||
918 | for (count = 0; count < 16; count++) | ||
919 | trap_registers.regs[count] = regs->regs[count]; | ||
920 | trap_registers.pc = regs->pc; | ||
921 | trap_registers.pr = regs->pr; | ||
922 | trap_registers.sr = regs->sr; | ||
923 | trap_registers.gbr = regs->gbr; | ||
924 | trap_registers.mach = regs->mach; | ||
925 | trap_registers.macl = regs->macl; | ||
926 | |||
927 | asm("stc vbr, %0":"=r"(vbr_val)); | ||
928 | trap_registers.vbr = vbr_val; | ||
929 | |||
930 | /* Get excode for command loop call, user access */ | ||
931 | asm("stc r2_bank, %0":"=r"(excep_code)); | ||
932 | |||
933 | /* Act on the exception */ | ||
934 | kgdb_command_loop(excep_code, trapa_value); | ||
935 | |||
936 | /* Copy back the (maybe modified) registers */ | ||
937 | for (count = 0; count < 16; count++) | ||
938 | regs->regs[count] = trap_registers.regs[count]; | ||
939 | regs->pc = trap_registers.pc; | ||
940 | regs->pr = trap_registers.pr; | ||
941 | regs->sr = trap_registers.sr; | ||
942 | regs->gbr = trap_registers.gbr; | ||
943 | regs->mach = trap_registers.mach; | ||
944 | regs->macl = trap_registers.macl; | ||
945 | |||
946 | vbr_val = trap_registers.vbr; | ||
947 | asm("ldc %0, vbr": :"r"(vbr_val)); | ||
948 | } | ||
949 | |||
950 | asmlinkage void kgdb_handle_exception(unsigned long r4, unsigned long r5, | ||
951 | unsigned long r6, unsigned long r7, | ||
952 | struct pt_regs __regs) | ||
953 | { | ||
954 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); | ||
955 | handle_exception(regs); | ||
956 | } | ||
957 | |||
958 | /* Initialise the KGDB data structures and serial configuration */ | ||
959 | int __init kgdb_init(void) | ||
960 | { | ||
961 | in_nmi = 0; | ||
962 | kgdb_nofault = 0; | ||
963 | stepped_opcode = 0; | ||
964 | kgdb_in_gdb_mode = 0; | ||
965 | |||
966 | if (kgdb_serial_setup() != 0) { | ||
967 | printk(KERN_NOTICE "KGDB: serial setup error\n"); | ||
968 | return -1; | ||
969 | } | ||
970 | |||
971 | /* Init ptr to exception handler */ | ||
972 | kgdb_debug_hook = handle_exception; | ||
973 | kgdb_bus_err_hook = kgdb_handle_bus_error; | ||
974 | |||
975 | /* Enter kgdb now if requested, or just report init done */ | ||
976 | printk(KERN_NOTICE "KGDB: stub is initialized.\n"); | ||
977 | |||
978 | return 0; | ||
979 | } | ||
980 | |||
981 | /* Make function available for "user messages"; console will use it too. */ | ||
982 | |||
983 | char gdbmsgbuf[BUFMAX]; | ||
984 | #define MAXOUT ((BUFMAX-2)/2) | ||
985 | |||
986 | static void kgdb_msg_write(const char *s, unsigned count) | ||
987 | { | ||
988 | int i; | ||
989 | int wcount; | ||
990 | char *bufptr; | ||
991 | |||
992 | /* 'O'utput */ | ||
993 | gdbmsgbuf[0] = 'O'; | ||
994 | |||
995 | /* Fill and send buffers... */ | ||
996 | while (count > 0) { | ||
997 | bufptr = gdbmsgbuf + 1; | ||
998 | |||
999 | /* Calculate how many this time */ | ||
1000 | wcount = (count > MAXOUT) ? MAXOUT : count; | ||
1001 | |||
1002 | /* Pack in hex chars */ | ||
1003 | for (i = 0; i < wcount; i++) | ||
1004 | bufptr = pack_hex_byte(bufptr, s[i]); | ||
1005 | *bufptr = '\0'; | ||
1006 | |||
1007 | /* Move up */ | ||
1008 | s += wcount; | ||
1009 | count -= wcount; | ||
1010 | |||
1011 | /* Write packet */ | ||
1012 | put_packet(gdbmsgbuf); | ||
1013 | } | ||
1014 | } | ||
1015 | |||
1016 | static void kgdb_to_gdb(const char *s) | ||
1017 | { | ||
1018 | kgdb_msg_write(s, strlen(s)); | ||
1019 | } | ||
1020 | |||
1021 | #ifdef CONFIG_SH_KGDB_CONSOLE | ||
1022 | void kgdb_console_write(struct console *co, const char *s, unsigned count) | ||
1023 | { | ||
1024 | /* Bail if we're not talking to GDB */ | ||
1025 | if (!kgdb_in_gdb_mode) | ||
1026 | return; | ||
1027 | |||
1028 | kgdb_msg_write(s, count); | ||
1029 | } | ||
1030 | #endif | ||
1031 | |||
1032 | #ifdef CONFIG_KGDB_SYSRQ | ||
1033 | static void sysrq_handle_gdb(int key, struct tty_struct *tty) | ||
1034 | { | ||
1035 | printk("Entering GDB stub\n"); | ||
1036 | breakpoint(); | ||
1037 | } | ||
1038 | |||
1039 | static struct sysrq_key_op sysrq_gdb_op = { | ||
1040 | .handler = sysrq_handle_gdb, | ||
1041 | .help_msg = "Gdb", | ||
1042 | .action_msg = "GDB", | ||
1043 | }; | ||
1044 | |||
1045 | static int gdb_register_sysrq(void) | ||
1046 | { | ||
1047 | printk("Registering GDB sysrq handler\n"); | ||
1048 | register_sysrq_key('g', &sysrq_gdb_op); | ||
1049 | return 0; | ||
1050 | } | ||
1051 | module_init(gdb_register_sysrq); | ||
1052 | #endif | ||
diff --git a/arch/sh/kernel/time_32.c b/arch/sh/kernel/time_32.c index 23ca711c27d2..1336f275326c 100644 --- a/arch/sh/kernel/time_32.c +++ b/arch/sh/kernel/time_32.c | |||
@@ -277,11 +277,4 @@ void __init time_init(void) | |||
277 | ((sh_hpt_frequency + 500) / 1000) / 1000, | 277 | ((sh_hpt_frequency + 500) / 1000) / 1000, |
278 | ((sh_hpt_frequency + 500) / 1000) % 1000); | 278 | ((sh_hpt_frequency + 500) / 1000) % 1000); |
279 | 279 | ||
280 | #if defined(CONFIG_SH_KGDB) | ||
281 | /* | ||
282 | * Set up kgdb as requested. We do it here because the serial | ||
283 | * init uses the timer vars we just set up for figuring baud. | ||
284 | */ | ||
285 | kgdb_init(); | ||
286 | #endif | ||
287 | } | 280 | } |
diff --git a/arch/sh/kernel/traps_32.c b/arch/sh/kernel/traps_32.c index 6094fc13beea..88807a2aacc3 100644 --- a/arch/sh/kernel/traps_32.c +++ b/arch/sh/kernel/traps_32.c | |||
@@ -28,17 +28,6 @@ | |||
28 | #include <asm/fpu.h> | 28 | #include <asm/fpu.h> |
29 | #include <asm/kprobes.h> | 29 | #include <asm/kprobes.h> |
30 | 30 | ||
31 | #ifdef CONFIG_SH_KGDB | ||
32 | #include <asm/kgdb.h> | ||
33 | #define CHK_REMOTE_DEBUG(regs) \ | ||
34 | { \ | ||
35 | if (kgdb_debug_hook && !user_mode(regs))\ | ||
36 | (*kgdb_debug_hook)(regs); \ | ||
37 | } | ||
38 | #else | ||
39 | #define CHK_REMOTE_DEBUG(regs) | ||
40 | #endif | ||
41 | |||
42 | #ifdef CONFIG_CPU_SH2 | 31 | #ifdef CONFIG_CPU_SH2 |
43 | # define TRAP_RESERVED_INST 4 | 32 | # define TRAP_RESERVED_INST 4 |
44 | # define TRAP_ILLEGAL_SLOT_INST 6 | 33 | # define TRAP_ILLEGAL_SLOT_INST 6 |
@@ -94,7 +83,6 @@ void die(const char * str, struct pt_regs * regs, long err) | |||
94 | 83 | ||
95 | printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter); | 84 | printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter); |
96 | 85 | ||
97 | CHK_REMOTE_DEBUG(regs); | ||
98 | print_modules(); | 86 | print_modules(); |
99 | show_regs(regs); | 87 | show_regs(regs); |
100 | 88 | ||
@@ -683,7 +671,6 @@ asmlinkage void do_reserved_inst(unsigned long r4, unsigned long r5, | |||
683 | error_code = lookup_exception_vector(); | 671 | error_code = lookup_exception_vector(); |
684 | 672 | ||
685 | local_irq_enable(); | 673 | local_irq_enable(); |
686 | CHK_REMOTE_DEBUG(regs); | ||
687 | force_sig(SIGILL, tsk); | 674 | force_sig(SIGILL, tsk); |
688 | die_if_no_fixup("reserved instruction", regs, error_code); | 675 | die_if_no_fixup("reserved instruction", regs, error_code); |
689 | } | 676 | } |
@@ -761,7 +748,6 @@ asmlinkage void do_illegal_slot_inst(unsigned long r4, unsigned long r5, | |||
761 | inst = lookup_exception_vector(); | 748 | inst = lookup_exception_vector(); |
762 | 749 | ||
763 | local_irq_enable(); | 750 | local_irq_enable(); |
764 | CHK_REMOTE_DEBUG(regs); | ||
765 | force_sig(SIGILL, tsk); | 751 | force_sig(SIGILL, tsk); |
766 | die_if_no_fixup("illegal slot instruction", regs, inst); | 752 | die_if_no_fixup("illegal slot instruction", regs, inst); |
767 | } | 753 | } |
diff --git a/arch/sh/mm/fault_32.c b/arch/sh/mm/fault_32.c index e58726892b5f..31a33ebdef6f 100644 --- a/arch/sh/mm/fault_32.c +++ b/arch/sh/mm/fault_32.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <asm/system.h> | 20 | #include <asm/system.h> |
21 | #include <asm/mmu_context.h> | 21 | #include <asm/mmu_context.h> |
22 | #include <asm/tlbflush.h> | 22 | #include <asm/tlbflush.h> |
23 | #include <asm/kgdb.h> | ||
24 | 23 | ||
25 | /* | 24 | /* |
26 | * This routine handles page faults. It determines the address, | 25 | * This routine handles page faults. It determines the address, |
@@ -282,11 +281,6 @@ asmlinkage int __kprobes __do_page_fault(struct pt_regs *regs, | |||
282 | if (notify_page_fault(regs, lookup_exception_vector())) | 281 | if (notify_page_fault(regs, lookup_exception_vector())) |
283 | goto out; | 282 | goto out; |
284 | 283 | ||
285 | #ifdef CONFIG_SH_KGDB | ||
286 | if (kgdb_nofault && kgdb_bus_err_hook) | ||
287 | kgdb_bus_err_hook(); | ||
288 | #endif | ||
289 | |||
290 | ret = 1; | 284 | ret = 1; |
291 | 285 | ||
292 | /* | 286 | /* |