]> Git Repo - linux.git/blame - arch/blackfin/kernel/kgdb.c
bug[220] kgdb: change the smp cross core function entry
[linux.git] / arch / blackfin / kernel / kgdb.c
CommitLineData
474f1a66 1/*
a5ac0129 2 * arch/blackfin/kernel/kgdb.c - Blackfin kgdb pieces
474f1a66 3 *
a5ac0129 4 * Copyright 2005-2008 Analog Devices Inc.
474f1a66 5 *
a5ac0129 6 * Licensed under the GPL-2 or later.
474f1a66
SZ
7 */
8
474f1a66
SZ
9#include <linux/ptrace.h> /* for linux pt_regs struct */
10#include <linux/kgdb.h>
a5ac0129 11#include <linux/uaccess.h>
259c9b17 12#include <asm/irq_regs.h>
474f1a66 13
a5ac0129 14void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
474f1a66
SZ
15{
16 gdb_regs[BFIN_R0] = regs->r0;
17 gdb_regs[BFIN_R1] = regs->r1;
18 gdb_regs[BFIN_R2] = regs->r2;
19 gdb_regs[BFIN_R3] = regs->r3;
20 gdb_regs[BFIN_R4] = regs->r4;
21 gdb_regs[BFIN_R5] = regs->r5;
22 gdb_regs[BFIN_R6] = regs->r6;
23 gdb_regs[BFIN_R7] = regs->r7;
24 gdb_regs[BFIN_P0] = regs->p0;
25 gdb_regs[BFIN_P1] = regs->p1;
26 gdb_regs[BFIN_P2] = regs->p2;
27 gdb_regs[BFIN_P3] = regs->p3;
28 gdb_regs[BFIN_P4] = regs->p4;
29 gdb_regs[BFIN_P5] = regs->p5;
30 gdb_regs[BFIN_SP] = regs->reserved;
31 gdb_regs[BFIN_FP] = regs->fp;
32 gdb_regs[BFIN_I0] = regs->i0;
33 gdb_regs[BFIN_I1] = regs->i1;
34 gdb_regs[BFIN_I2] = regs->i2;
35 gdb_regs[BFIN_I3] = regs->i3;
36 gdb_regs[BFIN_M0] = regs->m0;
37 gdb_regs[BFIN_M1] = regs->m1;
38 gdb_regs[BFIN_M2] = regs->m2;
39 gdb_regs[BFIN_M3] = regs->m3;
40 gdb_regs[BFIN_B0] = regs->b0;
41 gdb_regs[BFIN_B1] = regs->b1;
42 gdb_regs[BFIN_B2] = regs->b2;
43 gdb_regs[BFIN_B3] = regs->b3;
44 gdb_regs[BFIN_L0] = regs->l0;
45 gdb_regs[BFIN_L1] = regs->l1;
46 gdb_regs[BFIN_L2] = regs->l2;
47 gdb_regs[BFIN_L3] = regs->l3;
48 gdb_regs[BFIN_A0_DOT_X] = regs->a0x;
49 gdb_regs[BFIN_A0_DOT_W] = regs->a0w;
50 gdb_regs[BFIN_A1_DOT_X] = regs->a1x;
51 gdb_regs[BFIN_A1_DOT_W] = regs->a1w;
52 gdb_regs[BFIN_ASTAT] = regs->astat;
53 gdb_regs[BFIN_RETS] = regs->rets;
54 gdb_regs[BFIN_LC0] = regs->lc0;
55 gdb_regs[BFIN_LT0] = regs->lt0;
56 gdb_regs[BFIN_LB0] = regs->lb0;
57 gdb_regs[BFIN_LC1] = regs->lc1;
58 gdb_regs[BFIN_LT1] = regs->lt1;
59 gdb_regs[BFIN_LB1] = regs->lb1;
60 gdb_regs[BFIN_CYCLES] = 0;
61 gdb_regs[BFIN_CYCLES2] = 0;
62 gdb_regs[BFIN_USP] = regs->usp;
63 gdb_regs[BFIN_SEQSTAT] = regs->seqstat;
64 gdb_regs[BFIN_SYSCFG] = regs->syscfg;
65 gdb_regs[BFIN_RETI] = regs->pc;
66 gdb_regs[BFIN_RETX] = regs->retx;
67 gdb_regs[BFIN_RETN] = regs->retn;
68 gdb_regs[BFIN_RETE] = regs->rete;
69 gdb_regs[BFIN_PC] = regs->pc;
d2db97bf 70 gdb_regs[BFIN_CC] = (regs->astat >> 5) & 1;
474f1a66
SZ
71 gdb_regs[BFIN_EXTRA1] = 0;
72 gdb_regs[BFIN_EXTRA2] = 0;
73 gdb_regs[BFIN_EXTRA3] = 0;
74 gdb_regs[BFIN_IPEND] = regs->ipend;
75}
76
77/*
78 * Extracts ebp, esp and eip values understandable by gdb from the values
79 * saved by switch_to.
80 * thread.esp points to ebp. flags and ebp are pushed in switch_to hence esp
025dfdaf 81 * prior to entering switch_to is 8 greater than the value that is saved.
474f1a66
SZ
82 * If switch_to changes, change following code appropriately.
83 */
84void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
85{
86 gdb_regs[BFIN_SP] = p->thread.ksp;
87 gdb_regs[BFIN_PC] = p->thread.pc;
88 gdb_regs[BFIN_SEQSTAT] = p->thread.seqstat;
89}
90
a5ac0129 91void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)
474f1a66
SZ
92{
93 regs->r0 = gdb_regs[BFIN_R0];
94 regs->r1 = gdb_regs[BFIN_R1];
95 regs->r2 = gdb_regs[BFIN_R2];
96 regs->r3 = gdb_regs[BFIN_R3];
97 regs->r4 = gdb_regs[BFIN_R4];
98 regs->r5 = gdb_regs[BFIN_R5];
99 regs->r6 = gdb_regs[BFIN_R6];
100 regs->r7 = gdb_regs[BFIN_R7];
101 regs->p0 = gdb_regs[BFIN_P0];
102 regs->p1 = gdb_regs[BFIN_P1];
103 regs->p2 = gdb_regs[BFIN_P2];
104 regs->p3 = gdb_regs[BFIN_P3];
105 regs->p4 = gdb_regs[BFIN_P4];
106 regs->p5 = gdb_regs[BFIN_P5];
107 regs->fp = gdb_regs[BFIN_FP];
108 regs->i0 = gdb_regs[BFIN_I0];
109 regs->i1 = gdb_regs[BFIN_I1];
110 regs->i2 = gdb_regs[BFIN_I2];
111 regs->i3 = gdb_regs[BFIN_I3];
112 regs->m0 = gdb_regs[BFIN_M0];
113 regs->m1 = gdb_regs[BFIN_M1];
114 regs->m2 = gdb_regs[BFIN_M2];
115 regs->m3 = gdb_regs[BFIN_M3];
116 regs->b0 = gdb_regs[BFIN_B0];
117 regs->b1 = gdb_regs[BFIN_B1];
118 regs->b2 = gdb_regs[BFIN_B2];
119 regs->b3 = gdb_regs[BFIN_B3];
120 regs->l0 = gdb_regs[BFIN_L0];
121 regs->l1 = gdb_regs[BFIN_L1];
122 regs->l2 = gdb_regs[BFIN_L2];
123 regs->l3 = gdb_regs[BFIN_L3];
124 regs->a0x = gdb_regs[BFIN_A0_DOT_X];
125 regs->a0w = gdb_regs[BFIN_A0_DOT_W];
126 regs->a1x = gdb_regs[BFIN_A1_DOT_X];
127 regs->a1w = gdb_regs[BFIN_A1_DOT_W];
128 regs->rets = gdb_regs[BFIN_RETS];
129 regs->lc0 = gdb_regs[BFIN_LC0];
130 regs->lt0 = gdb_regs[BFIN_LT0];
131 regs->lb0 = gdb_regs[BFIN_LB0];
132 regs->lc1 = gdb_regs[BFIN_LC1];
133 regs->lt1 = gdb_regs[BFIN_LT1];
134 regs->lb1 = gdb_regs[BFIN_LB1];
135 regs->usp = gdb_regs[BFIN_USP];
136 regs->syscfg = gdb_regs[BFIN_SYSCFG];
7fe1a912 137 regs->retx = gdb_regs[BFIN_RETX];
474f1a66
SZ
138 regs->retn = gdb_regs[BFIN_RETN];
139 regs->rete = gdb_regs[BFIN_RETE];
140 regs->pc = gdb_regs[BFIN_PC];
141
142#if 0 /* can't change these */
143 regs->astat = gdb_regs[BFIN_ASTAT];
144 regs->seqstat = gdb_regs[BFIN_SEQSTAT];
145 regs->ipend = gdb_regs[BFIN_IPEND];
146#endif
147}
148
8d0177db 149static struct hw_breakpoint {
474f1a66
SZ
150 unsigned int occupied:1;
151 unsigned int skip:1;
152 unsigned int enabled:1;
153 unsigned int type:1;
154 unsigned int dataacc:2;
155 unsigned short count;
156 unsigned int addr;
a5ac0129 157} breakinfo[HW_WATCHPOINT_NUM];
474f1a66 158
8d0177db 159static int bfin_set_hw_break(unsigned long addr, int len, enum kgdb_bptype type)
474f1a66
SZ
160{
161 int breakno;
a5ac0129
SZ
162 int bfin_type;
163 int dataacc = 0;
164
165 switch (type) {
166 case BP_HARDWARE_BREAKPOINT:
167 bfin_type = TYPE_INST_WATCHPOINT;
168 break;
169 case BP_WRITE_WATCHPOINT:
170 dataacc = 1;
171 bfin_type = TYPE_DATA_WATCHPOINT;
172 break;
173 case BP_READ_WATCHPOINT:
174 dataacc = 2;
175 bfin_type = TYPE_DATA_WATCHPOINT;
176 break;
177 case BP_ACCESS_WATCHPOINT:
178 dataacc = 3;
179 bfin_type = TYPE_DATA_WATCHPOINT;
180 break;
181 default:
182 return -ENOSPC;
183 }
184
25985edc 185 /* Because hardware data watchpoint impelemented in current
a5ac0129
SZ
186 * Blackfin can not trigger an exception event as the hardware
187 * instrction watchpoint does, we ignaore all data watch point here.
188 * They can be turned on easily after future blackfin design
189 * supports this feature.
190 */
191 for (breakno = 0; breakno < HW_INST_WATCHPOINT_NUM; breakno++)
192 if (bfin_type == breakinfo[breakno].type
193 && !breakinfo[breakno].occupied) {
474f1a66 194 breakinfo[breakno].occupied = 1;
8a0e9acf 195 breakinfo[breakno].skip = 0;
474f1a66 196 breakinfo[breakno].enabled = 1;
474f1a66 197 breakinfo[breakno].addr = addr;
a5ac0129
SZ
198 breakinfo[breakno].dataacc = dataacc;
199 breakinfo[breakno].count = 0;
474f1a66
SZ
200 return 0;
201 }
202
203 return -ENOSPC;
204}
205
8d0177db 206static int bfin_remove_hw_break(unsigned long addr, int len, enum kgdb_bptype type)
474f1a66
SZ
207{
208 int breakno;
a5ac0129
SZ
209 int bfin_type;
210
211 switch (type) {
212 case BP_HARDWARE_BREAKPOINT:
213 bfin_type = TYPE_INST_WATCHPOINT;
214 break;
215 case BP_WRITE_WATCHPOINT:
216 case BP_READ_WATCHPOINT:
217 case BP_ACCESS_WATCHPOINT:
218 bfin_type = TYPE_DATA_WATCHPOINT;
219 break;
220 default:
221 return 0;
222 }
223 for (breakno = 0; breakno < HW_WATCHPOINT_NUM; breakno++)
224 if (bfin_type == breakinfo[breakno].type
225 && breakinfo[breakno].occupied
226 && breakinfo[breakno].addr == addr) {
227 breakinfo[breakno].occupied = 0;
228 breakinfo[breakno].enabled = 0;
229 }
474f1a66
SZ
230
231 return 0;
232}
233
8d0177db 234static void bfin_remove_all_hw_break(void)
474f1a66 235{
a5ac0129 236 int breakno;
474f1a66 237
a5ac0129
SZ
238 memset(breakinfo, 0, sizeof(struct hw_breakpoint)*HW_WATCHPOINT_NUM);
239
240 for (breakno = 0; breakno < HW_INST_WATCHPOINT_NUM; breakno++)
241 breakinfo[breakno].type = TYPE_INST_WATCHPOINT;
242 for (; breakno < HW_WATCHPOINT_NUM; breakno++)
243 breakinfo[breakno].type = TYPE_DATA_WATCHPOINT;
474f1a66 244}
474f1a66 245
8d0177db 246static void bfin_correct_hw_break(void)
474f1a66
SZ
247{
248 int breakno;
a5ac0129
SZ
249 unsigned int wpiactl = 0;
250 unsigned int wpdactl = 0;
251 int enable_wp = 0;
252
253 for (breakno = 0; breakno < HW_WATCHPOINT_NUM; breakno++)
254 if (breakinfo[breakno].enabled) {
255 enable_wp = 1;
474f1a66 256
474f1a66
SZ
257 switch (breakno) {
258 case 0:
a5ac0129
SZ
259 wpiactl |= WPIAEN0|WPICNTEN0;
260 bfin_write_WPIA0(breakinfo[breakno].addr);
261 bfin_write_WPIACNT0(breakinfo[breakno].count
262 + breakinfo->skip);
474f1a66 263 break;
474f1a66 264 case 1:
a5ac0129
SZ
265 wpiactl |= WPIAEN1|WPICNTEN1;
266 bfin_write_WPIA1(breakinfo[breakno].addr);
267 bfin_write_WPIACNT1(breakinfo[breakno].count
268 + breakinfo->skip);
474f1a66 269 break;
474f1a66 270 case 2:
a5ac0129
SZ
271 wpiactl |= WPIAEN2|WPICNTEN2;
272 bfin_write_WPIA2(breakinfo[breakno].addr);
273 bfin_write_WPIACNT2(breakinfo[breakno].count
274 + breakinfo->skip);
474f1a66 275 break;
474f1a66 276 case 3:
a5ac0129
SZ
277 wpiactl |= WPIAEN3|WPICNTEN3;
278 bfin_write_WPIA3(breakinfo[breakno].addr);
279 bfin_write_WPIACNT3(breakinfo[breakno].count
280 + breakinfo->skip);
474f1a66
SZ
281 break;
282 case 4:
a5ac0129
SZ
283 wpiactl |= WPIAEN4|WPICNTEN4;
284 bfin_write_WPIA4(breakinfo[breakno].addr);
285 bfin_write_WPIACNT4(breakinfo[breakno].count
286 + breakinfo->skip);
474f1a66
SZ
287 break;
288 case 5:
a5ac0129
SZ
289 wpiactl |= WPIAEN5|WPICNTEN5;
290 bfin_write_WPIA5(breakinfo[breakno].addr);
291 bfin_write_WPIACNT5(breakinfo[breakno].count
292 + breakinfo->skip);
293 break;
294 case 6:
295 wpdactl |= WPDAEN0|WPDCNTEN0|WPDSRC0;
296 wpdactl |= breakinfo[breakno].dataacc
297 << WPDACC0_OFFSET;
298 bfin_write_WPDA0(breakinfo[breakno].addr);
299 bfin_write_WPDACNT0(breakinfo[breakno].count
300 + breakinfo->skip);
301 break;
302 case 7:
303 wpdactl |= WPDAEN1|WPDCNTEN1|WPDSRC1;
304 wpdactl |= breakinfo[breakno].dataacc
305 << WPDACC1_OFFSET;
306 bfin_write_WPDA1(breakinfo[breakno].addr);
307 bfin_write_WPDACNT1(breakinfo[breakno].count
308 + breakinfo->skip);
474f1a66
SZ
309 break;
310 }
311 }
a5ac0129
SZ
312
313 /* Should enable WPPWR bit first before set any other
314 * WPIACTL and WPDACTL bits */
315 if (enable_wp) {
316 bfin_write_WPIACTL(WPPWR);
317 CSYNC();
318 bfin_write_WPIACTL(wpiactl|WPPWR);
474f1a66
SZ
319 bfin_write_WPDACTL(wpdactl);
320 CSYNC();
474f1a66
SZ
321 }
322}
323
d7ba979d 324static void bfin_disable_hw_debug(struct pt_regs *regs)
474f1a66
SZ
325{
326 /* Disable hardware debugging while we are in kgdb */
a5ac0129
SZ
327 bfin_write_WPIACTL(0);
328 bfin_write_WPDACTL(0);
474f1a66
SZ
329 CSYNC();
330}
331
a5ac0129
SZ
332#ifdef CONFIG_SMP
333void kgdb_passive_cpu_callback(void *info)
334{
335 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
336}
337
338void kgdb_roundup_cpus(unsigned long flags)
339{
1439d030
SZ
340 unsigned int cpu;
341
342 for (cpu = cpumask_first(cpu_online_mask); cpu < nr_cpu_ids;
a0f4207d
SZ
343 cpu = cpumask_next(cpu, cpu_online_mask))
344 smp_call_function_single(cpu, kgdb_passive_cpu_callback,
345 NULL, 0);
a5ac0129
SZ
346}
347
348void kgdb_roundup_cpu(int cpu, unsigned long flags)
349{
a0f4207d 350 smp_call_function_single(cpu, kgdb_passive_cpu_callback, NULL, 0);
a5ac0129
SZ
351}
352#endif
353
900de051
SZ
354#ifdef CONFIG_IPIPE
355static unsigned long kgdb_arch_imask;
b68233e7 356#endif
900de051
SZ
357
358void kgdb_post_primary_code(struct pt_regs *regs, int e_vector, int err_code)
359{
b68233e7
SZ
360 if (kgdb_single_step)
361 preempt_enable();
362
363#ifdef CONFIG_IPIPE
900de051
SZ
364 if (kgdb_arch_imask) {
365 cpu_pda[raw_smp_processor_id()].ex_imask = kgdb_arch_imask;
366 kgdb_arch_imask = 0;
367 }
900de051 368#endif
b68233e7 369}
900de051 370
a5ac0129 371int kgdb_arch_handle_exception(int vector, int signo,
474f1a66
SZ
372 int err_code, char *remcom_in_buffer,
373 char *remcom_out_buffer,
a5ac0129 374 struct pt_regs *regs)
474f1a66
SZ
375{
376 long addr;
474f1a66
SZ
377 char *ptr;
378 int newPC;
0d1cdd7a 379 int i;
474f1a66
SZ
380
381 switch (remcom_in_buffer[0]) {
382 case 'c':
383 case 's':
384 if (kgdb_contthread && kgdb_contthread != current) {
385 strcpy(remcom_out_buffer, "E00");
386 break;
387 }
388
389 kgdb_contthread = NULL;
390
391 /* try to read optional parameter, pc unchanged if no parm */
392 ptr = &remcom_in_buffer[1];
393 if (kgdb_hex2long(&ptr, &addr)) {
a5ac0129 394 regs->retx = addr;
474f1a66 395 }
a5ac0129 396 newPC = regs->retx;
474f1a66
SZ
397
398 /* clear the trace bit */
a5ac0129 399 regs->syscfg &= 0xfffffffe;
474f1a66
SZ
400
401 /* set the trace bit if we're stepping */
402 if (remcom_in_buffer[0] == 's') {
a5ac0129
SZ
403 regs->syscfg |= 0x1;
404 kgdb_single_step = regs->ipend;
405 kgdb_single_step >>= 6;
406 for (i = 10; i > 0; i--, kgdb_single_step >>= 1)
407 if (kgdb_single_step & 1)
0d1cdd7a
SZ
408 break;
409 /* i indicate event priority of current stopped instruction
410 * user space instruction is 0, IVG15 is 1, IVTMR is 10.
a5ac0129 411 * kgdb_single_step > 0 means in single step mode
0d1cdd7a 412 */
a5ac0129 413 kgdb_single_step = i + 1;
900de051 414
b68233e7 415 preempt_disable();
900de051
SZ
416#ifdef CONFIG_IPIPE
417 kgdb_arch_imask = cpu_pda[raw_smp_processor_id()].ex_imask;
418 cpu_pda[raw_smp_processor_id()].ex_imask = 0;
419#endif
474f1a66
SZ
420 }
421
a5ac0129 422 bfin_correct_hw_break();
474f1a66
SZ
423
424 return 0;
425 } /* switch */
426 return -1; /* this means that we do not want to exit from the handler */
427}
428
429struct kgdb_arch arch_kgdb_ops = {
430 .gdb_bpt_instr = {0xa1},
431 .flags = KGDB_HW_BREAKPOINT,
a5ac0129
SZ
432 .set_hw_breakpoint = bfin_set_hw_break,
433 .remove_hw_breakpoint = bfin_remove_hw_break,
d7ba979d 434 .disable_hw_break = bfin_disable_hw_debug,
a5ac0129
SZ
435 .remove_all_hw_break = bfin_remove_all_hw_break,
436 .correct_hw_break = bfin_correct_hw_break,
474f1a66 437};
a5ac0129 438
e56e03b0
MF
439#define IN_MEM(addr, size, l1_addr, l1_size) \
440({ \
441 unsigned long __addr = (unsigned long)(addr); \
442 (l1_size && __addr >= l1_addr && __addr + (size) <= l1_addr + l1_size); \
443})
444#define ASYNC_BANK_SIZE \
445 (ASYNC_BANK0_SIZE + ASYNC_BANK1_SIZE + \
446 ASYNC_BANK2_SIZE + ASYNC_BANK3_SIZE)
447
a5ac0129
SZ
448int kgdb_validate_break_address(unsigned long addr)
449{
450 int cpu = raw_smp_processor_id();
451
452 if (addr >= 0x1000 && (addr + BREAK_INSTR_SIZE) <= physical_mem_end)
453 return 0;
31fba6e7 454 if (IN_MEM(addr, BREAK_INSTR_SIZE, ASYNC_BANK0_BASE, ASYNC_BANK_SIZE))
a5ac0129 455 return 0;
31fba6e7 456 if (cpu == 0 && IN_MEM(addr, BREAK_INSTR_SIZE, L1_CODE_START, L1_CODE_LENGTH))
a5ac0129 457 return 0;
31fba6e7
MF
458#ifdef CONFIG_SMP
459 else if (cpu == 1 && IN_MEM(addr, BREAK_INSTR_SIZE, COREB_L1_CODE_START, L1_CODE_LENGTH))
a5ac0129 460 return 0;
a5ac0129 461#endif
31fba6e7 462 if (IN_MEM(addr, BREAK_INSTR_SIZE, L2_START, L2_LENGTH))
a5ac0129 463 return 0;
a5ac0129 464
11aca0e7 465 return -EFAULT;
a5ac0129
SZ
466}
467
e8861129
JW
468void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
469{
470 regs->retx = ip;
471}
472
a5ac0129
SZ
473int kgdb_arch_init(void)
474{
475 kgdb_single_step = 0;
900de051
SZ
476#ifdef CONFIG_IPIPE
477 kgdb_arch_imask = 0;
478#endif
a5ac0129
SZ
479
480 bfin_remove_all_hw_break();
481 return 0;
482}
483
484void kgdb_arch_exit(void)
485{
486}
This page took 0.62143 seconds and 4 git commands to generate.