diff options
author | David S. Miller <davem@davemloft.net> | 2008-04-29 05:38:50 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-04-29 05:38:50 -0400 |
commit | e2fdd7fd99dd68b77caaf2a2272b75b5da890de7 (patch) | |
tree | d2b6d3a9b50e4d2ced793430d2b1414f790666a3 /arch/sparc64/kernel | |
parent | 4d7ffa49909a830f5f926a3280731d01e29f31fb (diff) |
sparc: Add kgdb support.
Current limitations:
1) On SMP single stepping has some fundamental issues,
shared with other sw single-step architectures such
as mips and arm.
2) On 32-bit sparc we don't support SMP kgdb yet. That
requires some reworking of the IPI mechanisms and
infrastructure on that platform.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/sparc64/kernel')
-rw-r--r-- | arch/sparc64/kernel/Makefile | 1 | ||||
-rw-r--r-- | arch/sparc64/kernel/kgdb.c | 186 | ||||
-rw-r--r-- | arch/sparc64/kernel/misctrap.S | 10 | ||||
-rw-r--r-- | arch/sparc64/kernel/smp.c | 10 | ||||
-rw-r--r-- | arch/sparc64/kernel/ttable.S | 2 |
5 files changed, 208 insertions, 1 deletions
diff --git a/arch/sparc64/kernel/Makefile b/arch/sparc64/kernel/Makefile index 2bd0340b743d..ec4f5ebb1ca6 100644 --- a/arch/sparc64/kernel/Makefile +++ b/arch/sparc64/kernel/Makefile | |||
@@ -29,3 +29,4 @@ obj-$(CONFIG_SUN_LDOMS) += ldc.o vio.o viohs.o ds.o | |||
29 | obj-$(CONFIG_AUDIT) += audit.o | 29 | obj-$(CONFIG_AUDIT) += audit.o |
30 | obj-$(CONFIG_AUDIT)$(CONFIG_COMPAT) += compat_audit.o | 30 | obj-$(CONFIG_AUDIT)$(CONFIG_COMPAT) += compat_audit.o |
31 | obj-y += $(obj-yy) | 31 | obj-y += $(obj-yy) |
32 | obj-$(CONFIG_KGDB) += kgdb.o | ||
diff --git a/arch/sparc64/kernel/kgdb.c b/arch/sparc64/kernel/kgdb.c new file mode 100644 index 000000000000..fefbe6dc51be --- /dev/null +++ b/arch/sparc64/kernel/kgdb.c | |||
@@ -0,0 +1,186 @@ | |||
1 | /* kgdb.c: KGDB support for 64-bit sparc. | ||
2 | * | ||
3 | * Copyright (C) 2008 David S. Miller <davem@davemloft.net> | ||
4 | */ | ||
5 | |||
6 | #include <linux/kgdb.h> | ||
7 | #include <linux/kdebug.h> | ||
8 | |||
9 | #include <asm/kdebug.h> | ||
10 | #include <asm/ptrace.h> | ||
11 | #include <asm/irq.h> | ||
12 | |||
13 | void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs) | ||
14 | { | ||
15 | struct reg_window *win; | ||
16 | int i; | ||
17 | |||
18 | gdb_regs[GDB_G0] = 0; | ||
19 | for (i = 0; i < 15; i++) | ||
20 | gdb_regs[GDB_G1 + i] = regs->u_regs[UREG_G1 + i]; | ||
21 | |||
22 | win = (struct reg_window *) (regs->u_regs[UREG_FP] + STACK_BIAS); | ||
23 | for (i = 0; i < 8; i++) | ||
24 | gdb_regs[GDB_L0 + i] = win->locals[i]; | ||
25 | for (i = 0; i < 8; i++) | ||
26 | gdb_regs[GDB_I0 + i] = win->ins[i]; | ||
27 | |||
28 | for (i = GDB_F0; i <= GDB_F62; i++) | ||
29 | gdb_regs[i] = 0; | ||
30 | |||
31 | gdb_regs[GDB_PC] = regs->tpc; | ||
32 | gdb_regs[GDB_NPC] = regs->tnpc; | ||
33 | gdb_regs[GDB_STATE] = regs->tstate; | ||
34 | gdb_regs[GDB_FSR] = 0; | ||
35 | gdb_regs[GDB_FPRS] = 0; | ||
36 | gdb_regs[GDB_Y] = regs->y; | ||
37 | } | ||
38 | |||
39 | void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p) | ||
40 | { | ||
41 | struct thread_info *t = task_thread_info(p); | ||
42 | extern unsigned int switch_to_pc; | ||
43 | extern unsigned int ret_from_syscall; | ||
44 | struct reg_window *win; | ||
45 | unsigned long pc, cwp; | ||
46 | int i; | ||
47 | |||
48 | for (i = GDB_G0; i < GDB_G6; i++) | ||
49 | gdb_regs[i] = 0; | ||
50 | gdb_regs[GDB_G6] = (unsigned long) t; | ||
51 | gdb_regs[GDB_G7] = (unsigned long) p; | ||
52 | for (i = GDB_O0; i < GDB_SP; i++) | ||
53 | gdb_regs[i] = 0; | ||
54 | gdb_regs[GDB_SP] = t->ksp; | ||
55 | gdb_regs[GDB_O7] = 0; | ||
56 | |||
57 | win = (struct reg_window *) (t->ksp + STACK_BIAS); | ||
58 | for (i = 0; i < 8; i++) | ||
59 | gdb_regs[GDB_L0 + i] = win->locals[i]; | ||
60 | for (i = 0; i < 8; i++) | ||
61 | gdb_regs[GDB_I0 + i] = win->ins[i]; | ||
62 | |||
63 | for (i = GDB_F0; i <= GDB_F62; i++) | ||
64 | gdb_regs[i] = 0; | ||
65 | |||
66 | if (t->new_child) | ||
67 | pc = (unsigned long) &ret_from_syscall; | ||
68 | else | ||
69 | pc = (unsigned long) &switch_to_pc; | ||
70 | |||
71 | gdb_regs[GDB_PC] = pc; | ||
72 | gdb_regs[GDB_NPC] = pc + 4; | ||
73 | |||
74 | cwp = __thread_flag_byte_ptr(t)[TI_FLAG_BYTE_CWP]; | ||
75 | |||
76 | gdb_regs[GDB_STATE] = (TSTATE_PRIV | TSTATE_IE | cwp); | ||
77 | gdb_regs[GDB_FSR] = 0; | ||
78 | gdb_regs[GDB_FPRS] = 0; | ||
79 | gdb_regs[GDB_Y] = 0; | ||
80 | } | ||
81 | |||
82 | void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs) | ||
83 | { | ||
84 | struct reg_window *win; | ||
85 | int i; | ||
86 | |||
87 | for (i = 0; i < 15; i++) | ||
88 | regs->u_regs[UREG_G1 + i] = gdb_regs[GDB_G1 + i]; | ||
89 | |||
90 | /* If the TSTATE register is changing, we have to preserve | ||
91 | * the CWP field, otherwise window save/restore explodes. | ||
92 | */ | ||
93 | if (regs->tstate != gdb_regs[GDB_STATE]) { | ||
94 | unsigned long cwp = regs->tstate & TSTATE_CWP; | ||
95 | |||
96 | regs->tstate = (gdb_regs[GDB_STATE] & ~TSTATE_CWP) | cwp; | ||
97 | } | ||
98 | |||
99 | regs->tpc = gdb_regs[GDB_PC]; | ||
100 | regs->tnpc = gdb_regs[GDB_NPC]; | ||
101 | regs->y = gdb_regs[GDB_Y]; | ||
102 | |||
103 | win = (struct reg_window *) (regs->u_regs[UREG_FP] + STACK_BIAS); | ||
104 | for (i = 0; i < 8; i++) | ||
105 | win->locals[i] = gdb_regs[GDB_L0 + i]; | ||
106 | for (i = 0; i < 8; i++) | ||
107 | win->ins[i] = gdb_regs[GDB_I0 + i]; | ||
108 | } | ||
109 | |||
110 | #ifdef CONFIG_SMP | ||
111 | void smp_kgdb_capture_client(struct pt_regs *regs) | ||
112 | { | ||
113 | unsigned long flags; | ||
114 | |||
115 | __asm__ __volatile__("rdpr %%pstate, %0\n\t" | ||
116 | "wrpr %0, %1, %%pstate" | ||
117 | : "=r" (flags) | ||
118 | : "i" (PSTATE_IE)); | ||
119 | |||
120 | flushw_all(); | ||
121 | |||
122 | if (atomic_read(&kgdb_active) != -1) | ||
123 | kgdb_nmicallback(raw_smp_processor_id(), regs); | ||
124 | |||
125 | __asm__ __volatile__("wrpr %0, 0, %%pstate" | ||
126 | : : "r" (flags)); | ||
127 | } | ||
128 | #endif | ||
129 | |||
130 | int kgdb_arch_handle_exception(int e_vector, int signo, int err_code, | ||
131 | char *remcomInBuffer, char *remcomOutBuffer, | ||
132 | struct pt_regs *linux_regs) | ||
133 | { | ||
134 | unsigned long addr; | ||
135 | char *ptr; | ||
136 | |||
137 | switch (remcomInBuffer[0]) { | ||
138 | case 'c': | ||
139 | /* try to read optional parameter, pc unchanged if no parm */ | ||
140 | ptr = &remcomInBuffer[1]; | ||
141 | if (kgdb_hex2long(&ptr, &addr)) { | ||
142 | linux_regs->tpc = addr; | ||
143 | linux_regs->tnpc = addr + 4; | ||
144 | } | ||
145 | /* fallthru */ | ||
146 | |||
147 | case 'D': | ||
148 | case 'k': | ||
149 | if (linux_regs->tpc == (unsigned long) arch_kgdb_breakpoint) { | ||
150 | linux_regs->tpc = linux_regs->tnpc; | ||
151 | linux_regs->tnpc += 4; | ||
152 | } | ||
153 | return 0; | ||
154 | } | ||
155 | return -1; | ||
156 | } | ||
157 | |||
158 | asmlinkage void kgdb_trap(unsigned long trap_level, struct pt_regs *regs) | ||
159 | { | ||
160 | unsigned long flags; | ||
161 | |||
162 | if (user_mode(regs)) { | ||
163 | bad_trap(regs, trap_level); | ||
164 | return; | ||
165 | } | ||
166 | |||
167 | flushw_all(); | ||
168 | |||
169 | local_irq_save(flags); | ||
170 | kgdb_handle_exception(0x172, SIGTRAP, 0, regs); | ||
171 | local_irq_restore(flags); | ||
172 | } | ||
173 | |||
174 | int kgdb_arch_init(void) | ||
175 | { | ||
176 | return 0; | ||
177 | } | ||
178 | |||
179 | void kgdb_arch_exit(void) | ||
180 | { | ||
181 | } | ||
182 | |||
183 | struct kgdb_arch arch_kgdb_ops = { | ||
184 | /* Breakpoint instruction: ta 0x72 */ | ||
185 | .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 }, | ||
186 | }; | ||
diff --git a/arch/sparc64/kernel/misctrap.S b/arch/sparc64/kernel/misctrap.S index b257497ddde1..753b4f031bfb 100644 --- a/arch/sparc64/kernel/misctrap.S +++ b/arch/sparc64/kernel/misctrap.S | |||
@@ -1,3 +1,13 @@ | |||
1 | #ifdef CONFIG_KGDB | ||
2 | .globl arch_kgdb_breakpoint | ||
3 | .type arch_kgdb_breakpoint,#function | ||
4 | arch_kgdb_breakpoint: | ||
5 | ta 0x72 | ||
6 | retl | ||
7 | nop | ||
8 | .size arch_kgdb_breakpoint,.-arch_kgdb_breakpoint | ||
9 | #endif | ||
10 | |||
1 | .type __do_privact,#function | 11 | .type __do_privact,#function |
2 | __do_privact: | 12 | __do_privact: |
3 | mov TLB_SFSR, %g3 | 13 | mov TLB_SFSR, %g3 |
diff --git a/arch/sparc64/kernel/smp.c b/arch/sparc64/kernel/smp.c index 409dd71f2738..8face0c49fef 100644 --- a/arch/sparc64/kernel/smp.c +++ b/arch/sparc64/kernel/smp.c | |||
@@ -910,6 +910,9 @@ extern unsigned long xcall_flush_tlb_kernel_range; | |||
910 | extern unsigned long xcall_report_regs; | 910 | extern unsigned long xcall_report_regs; |
911 | extern unsigned long xcall_receive_signal; | 911 | extern unsigned long xcall_receive_signal; |
912 | extern unsigned long xcall_new_mmu_context_version; | 912 | extern unsigned long xcall_new_mmu_context_version; |
913 | #ifdef CONFIG_KGDB | ||
914 | extern unsigned long xcall_kgdb_capture; | ||
915 | #endif | ||
913 | 916 | ||
914 | #ifdef DCACHE_ALIASING_POSSIBLE | 917 | #ifdef DCACHE_ALIASING_POSSIBLE |
915 | extern unsigned long xcall_flush_dcache_page_cheetah; | 918 | extern unsigned long xcall_flush_dcache_page_cheetah; |
@@ -1079,6 +1082,13 @@ void smp_new_mmu_context_version(void) | |||
1079 | smp_cross_call(&xcall_new_mmu_context_version, 0, 0, 0); | 1082 | smp_cross_call(&xcall_new_mmu_context_version, 0, 0, 0); |
1080 | } | 1083 | } |
1081 | 1084 | ||
1085 | #ifdef CONFIG_KGDB | ||
1086 | void kgdb_roundup_cpus(unsigned long flags) | ||
1087 | { | ||
1088 | smp_cross_call(&xcall_kgdb_capture, 0, 0, 0); | ||
1089 | } | ||
1090 | #endif | ||
1091 | |||
1082 | void smp_report_regs(void) | 1092 | void smp_report_regs(void) |
1083 | { | 1093 | { |
1084 | smp_cross_call(&xcall_report_regs, 0, 0, 0); | 1094 | smp_cross_call(&xcall_report_regs, 0, 0, 0); |
diff --git a/arch/sparc64/kernel/ttable.S b/arch/sparc64/kernel/ttable.S index b0de4c00b11a..450053af039e 100644 --- a/arch/sparc64/kernel/ttable.S +++ b/arch/sparc64/kernel/ttable.S | |||
@@ -153,7 +153,7 @@ tl0_resv164: BTRAP(0x164) BTRAP(0x165) BTRAP(0x166) BTRAP(0x167) BTRAP(0x168) | |||
153 | tl0_resv169: BTRAP(0x169) BTRAP(0x16a) BTRAP(0x16b) BTRAP(0x16c) | 153 | tl0_resv169: BTRAP(0x169) BTRAP(0x16a) BTRAP(0x16b) BTRAP(0x16c) |
154 | tl0_linux64: LINUX_64BIT_SYSCALL_TRAP | 154 | tl0_linux64: LINUX_64BIT_SYSCALL_TRAP |
155 | tl0_gsctx: TRAP(sparc64_get_context) TRAP(sparc64_set_context) | 155 | tl0_gsctx: TRAP(sparc64_get_context) TRAP(sparc64_set_context) |
156 | tl0_resv170: KPROBES_TRAP(0x170) KPROBES_TRAP(0x171) BTRAP(0x172) | 156 | tl0_resv170: KPROBES_TRAP(0x170) KPROBES_TRAP(0x171) KGDB_TRAP(0x172) |
157 | tl0_resv173: BTRAP(0x173) BTRAP(0x174) BTRAP(0x175) BTRAP(0x176) BTRAP(0x177) | 157 | tl0_resv173: BTRAP(0x173) BTRAP(0x174) BTRAP(0x175) BTRAP(0x176) BTRAP(0x177) |
158 | tl0_resv178: BTRAP(0x178) BTRAP(0x179) BTRAP(0x17a) BTRAP(0x17b) BTRAP(0x17c) | 158 | tl0_resv178: BTRAP(0x178) BTRAP(0x179) BTRAP(0x17a) BTRAP(0x17b) BTRAP(0x17c) |
159 | tl0_resv17d: BTRAP(0x17d) BTRAP(0x17e) BTRAP(0x17f) | 159 | tl0_resv17d: BTRAP(0x17d) BTRAP(0x17e) BTRAP(0x17f) |