2 * Kernel Debugger Architecture Independent Support Functions
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
8 * Copyright (c) 1999-2004 Silicon Graphics, Inc. All Rights Reserved.
9 * Copyright (C) David Mosberger-Tang <davidm@hpl.hp.com>
12 #include <linux/config.h>
13 #include <linux/string.h>
14 #include <linux/stddef.h>
15 #include <linux/kernel.h>
16 #include <linux/ptrace.h>
17 #include <linux/interrupt.h>
19 #include <linux/sched.h>
20 #include <linux/kdb.h>
21 #include <linux/kdbprivate.h>
23 #include <asm/processor.h>
24 #include <asm/uaccess.h>
26 #include <asm/delay.h>
28 #include <asm/hw_irq.h>
32 kdba_itm (int argc, const char **argv, const char **envp, struct pt_regs *regs)
37 diag = kdbgetularg(argv[1], &val);
40 kdb_printf("new itm=" kdb_machreg_fmt "\n", val);
47 kdba_show_intregs(void)
49 u64 lid, tpr, lrr0, lrr1, itv, pmv, cmcv;
51 asm ("mov %0=cr.lid" : "=r"(lid));
52 asm ("mov %0=cr.tpr" : "=r"(tpr));
53 asm ("mov %0=cr.lrr0" : "=r"(lrr0));
54 asm ("mov %0=cr.lrr1" : "=r"(lrr1));
55 kdb_printf("lid=" kdb_machreg_fmt ", tpr=" kdb_machreg_fmt ", lrr0=" kdb_machreg_fmt ", llr1=" kdb_machreg_fmt "\n", lid, tpr, lrr0, lrr1);
57 asm ("mov %0=cr.itv" : "=r"(itv));
58 asm ("mov %0=cr.pmv" : "=r"(pmv));
59 asm ("mov %0=cr.cmcv" : "=r"(cmcv));
60 kdb_printf("itv=" kdb_machreg_fmt ", pmv=" kdb_machreg_fmt ", cmcv=" kdb_machreg_fmt "\n", itv, pmv, cmcv);
62 kdb_printf("irr=0x%016lx,0x%016lx,0x%016lx,0x%016lx\n",
63 ia64_getreg(_IA64_REG_CR_IRR0), ia64_getreg(_IA64_REG_CR_IRR1), ia64_getreg(_IA64_REG_CR_IRR2), ia64_getreg(_IA64_REG_CR_IRR3));
65 kdb_printf("itc=0x%016lx, itm=0x%016lx\n", ia64_get_itc(), ia64_get_itm());
69 kdba_sir (int argc, const char **argv, const char **envp, struct pt_regs *regs)
79 * Format a struct pt_regs
83 * argv argument vector
84 * envp environment vector
85 * regs registers at time kdb was entered.
89 * zero for success, a kdb diagnostic if error
93 * If no address is supplied, it uses regs.
97 kdba_pt_regs(int argc, const char **argv, const char **envp, struct pt_regs *regs)
106 addr = (kdb_machreg_t) regs;
107 } else if (argc == 1) {
109 diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs);
116 p = (struct pt_regs *) addr;
117 kdb_printf("struct pt_regs %p-%p\n", p, (unsigned char *)p + sizeof(*p) - 1);
118 kdb_print_nameval("b6", p->b6);
119 kdb_print_nameval("b7", p->b7);
120 kdb_printf(" ar_csd 0x%lx\n", p->ar_csd);
121 kdb_printf(" ar_ssd 0x%lx\n", p->ar_ssd);
122 kdb_print_nameval("r8", p->r8);
123 kdb_print_nameval("r9", p->r9);
124 kdb_print_nameval("r10", p->r10);
125 kdb_print_nameval("r11", p->r11);
126 kdb_printf(" cr_ipsr 0x%lx\n", p->cr_ipsr);
127 kdb_print_nameval("cr_iip", p->cr_iip);
128 kdb_printf(" cr_ifs 0x%lx\n", p->cr_ifs);
129 kdb_printf(" ar_unat 0x%lx\n", p->ar_unat);
130 kdb_printf(" ar_pfs 0x%lx\n", p->ar_pfs);
131 kdb_printf(" ar_rsc 0x%lx\n", p->ar_rsc);
132 kdb_printf(" ar_rnat 0x%lx\n", p->ar_rnat);
133 kdb_printf(" ar_bspstore 0x%lx\n", p->ar_bspstore);
134 kdb_printf(" pr 0x%lx\n", p->pr);
135 kdb_print_nameval("b0", p->b0);
136 kdb_printf(" loadrs 0x%lx\n", p->loadrs);
137 kdb_print_nameval("r1", p->r1);
138 kdb_print_nameval("r12", p->r12);
139 kdb_print_nameval("r13", p->r13);
140 kdb_printf(" ar_fpsr 0x%lx\n", p->ar_fpsr);
141 kdb_print_nameval("r15", p->r15);
142 kdb_print_nameval("r14", p->r14);
143 kdb_print_nameval("r2", p->r2);
144 kdb_print_nameval("r3", p->r3);
145 kdb_print_nameval("r16", p->r16);
146 kdb_print_nameval("r17", p->r17);
147 kdb_print_nameval("r18", p->r18);
148 kdb_print_nameval("r19", p->r19);
149 kdb_print_nameval("r20", p->r20);
150 kdb_print_nameval("r21", p->r21);
151 kdb_print_nameval("r22", p->r22);
152 kdb_print_nameval("r23", p->r23);
153 kdb_print_nameval("r24", p->r24);
154 kdb_print_nameval("r25", p->r25);
155 kdb_print_nameval("r26", p->r26);
156 kdb_print_nameval("r27", p->r27);
157 kdb_print_nameval("r28", p->r28);
158 kdb_print_nameval("r29", p->r29);
159 kdb_print_nameval("r30", p->r30);
160 kdb_print_nameval("r31", p->r31);
161 kdb_printf(" ar_ccv 0x%lx\n", p->ar_ccv);
162 kdb_printf(" f6 0x%lx 0x%lx\n", p->f6.u.bits[0], p->f6.u.bits[1]);
163 kdb_printf(" f7 0x%lx 0x%lx\n", p->f7.u.bits[0], p->f7.u.bits[1]);
164 kdb_printf(" f8 0x%lx 0x%lx\n", p->f8.u.bits[0], p->f8.u.bits[1]);
165 kdb_printf(" f9 0x%lx 0x%lx\n", p->f9.u.bits[0], p->f9.u.bits[1]);
166 kdb_printf(" f10 0x%lx 0x%lx\n", p->f10.u.bits[0], p->f10.u.bits[1]);
167 kdb_printf(" f11 0x%lx 0x%lx\n", p->f11.u.bits[0], p->f11.u.bits[1]);
175 * Print processes that are using more than a specific percentage of their
179 * argc argument count
180 * argv argument vector
181 * envp environment vector
182 * regs registers at time kdb was entered.
186 * zero for success, a kdb diagnostic if error
190 * If no percentage is supplied, it uses 60.
194 kdba_stackdepth(int argc, const char **argv, const char **envp, struct pt_regs *regs)
196 int diag, threshold, used;
201 struct task_struct *p, *g;
202 struct switch_stack *sw;
206 } else if (argc == 1) {
208 diag = kdbgetaddrarg(argc, argv, &nextarg, &percentage, &offset, NULL, regs);
214 percentage = max_t(int, percentage, 1);
215 percentage = min_t(int, percentage, 100);
216 threshold = ((2 * THREAD_SIZE * percentage) / 100 + 1) >> 1;
217 kdb_printf("stackdepth: processes using more than %ld%% (%d bytes) of stack\n",
218 percentage, threshold);
219 kdb_do_each_thread(g, p) {
220 if (kdb_task_has_cpu(p)) {
221 struct kdb_running_process *krp = kdb_running_process + kdb_process_cpu(p);
227 sw = (struct switch_stack *) (p->thread.ksp + 16);
230 esp = (unsigned long) sw;
231 used = THREAD_SIZE - (esp - sw->ar_bspstore);
232 if (used >= threshold) {
234 kdb_printf(" esp %lx bsp %lx used %d\n", esp, sw->ar_bspstore, used);
236 } kdb_while_each_thread(g, p);
244 * Format a struct switch_stack
247 * argc argument count
248 * argv argument vector
249 * envp environment vector
250 * regs registers at time kdb was entered.
254 * zero for success, a kdb diagnostic if error
258 * If no address is supplied, it uses kdb_running_process[smp_processor_id()].arch.sw.
262 kdba_switch_stack(int argc, const char **argv, const char **envp, struct pt_regs *regs)
268 struct switch_stack *p;
271 addr = (kdb_machreg_t) kdb_running_process[smp_processor_id()].arch.sw;
272 } else if (argc == 1) {
274 diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs);
281 p = (struct switch_stack *) addr;
282 kdb_printf("struct switch_stack %p-%p\n", p, (unsigned char *)p + sizeof(*p) - 1);
283 kdb_printf(" caller_unat 0x%lx\n", p->caller_unat);
284 kdb_printf(" ar_fpsr 0x%lx\n", p->ar_fpsr);
285 kdb_printf(" f2 0x%lx 0x%lx\n", p->f2.u.bits[0], p->f2.u.bits[1]);
286 kdb_printf(" f3 0x%lx 0x%lx\n", p->f3.u.bits[0], p->f3.u.bits[1]);
287 kdb_printf(" f4 0x%lx 0x%lx\n", p->f4.u.bits[0], p->f4.u.bits[1]);
288 kdb_printf(" f5 0x%lx 0x%lx\n", p->f5.u.bits[0], p->f5.u.bits[1]);
289 kdb_printf(" f12 0x%lx 0x%lx\n", p->f12.u.bits[0], p->f12.u.bits[1]);
290 kdb_printf(" f13 0x%lx 0x%lx\n", p->f13.u.bits[0], p->f13.u.bits[1]);
291 kdb_printf(" f14 0x%lx 0x%lx\n", p->f14.u.bits[0], p->f14.u.bits[1]);
292 kdb_printf(" f15 0x%lx 0x%lx\n", p->f15.u.bits[0], p->f15.u.bits[1]);
293 kdb_printf(" f16 0x%lx 0x%lx\n", p->f16.u.bits[0], p->f16.u.bits[1]);
294 kdb_printf(" f17 0x%lx 0x%lx\n", p->f17.u.bits[0], p->f17.u.bits[1]);
295 kdb_printf(" f18 0x%lx 0x%lx\n", p->f18.u.bits[0], p->f18.u.bits[1]);
296 kdb_printf(" f19 0x%lx 0x%lx\n", p->f19.u.bits[0], p->f19.u.bits[1]);
297 kdb_printf(" f20 0x%lx 0x%lx\n", p->f20.u.bits[0], p->f20.u.bits[1]);
298 kdb_printf(" f21 0x%lx 0x%lx\n", p->f21.u.bits[0], p->f21.u.bits[1]);
299 kdb_printf(" f22 0x%lx 0x%lx\n", p->f22.u.bits[0], p->f22.u.bits[1]);
300 kdb_printf(" f23 0x%lx 0x%lx\n", p->f23.u.bits[0], p->f23.u.bits[1]);
301 kdb_printf(" f24 0x%lx 0x%lx\n", p->f24.u.bits[0], p->f24.u.bits[1]);
302 kdb_printf(" f25 0x%lx 0x%lx\n", p->f25.u.bits[0], p->f25.u.bits[1]);
303 kdb_printf(" f26 0x%lx 0x%lx\n", p->f26.u.bits[0], p->f26.u.bits[1]);
304 kdb_printf(" f27 0x%lx 0x%lx\n", p->f27.u.bits[0], p->f27.u.bits[1]);
305 kdb_printf(" f28 0x%lx 0x%lx\n", p->f28.u.bits[0], p->f28.u.bits[1]);
306 kdb_printf(" f29 0x%lx 0x%lx\n", p->f29.u.bits[0], p->f29.u.bits[1]);
307 kdb_printf(" f30 0x%lx 0x%lx\n", p->f30.u.bits[0], p->f30.u.bits[1]);
308 kdb_printf(" f31 0x%lx 0x%lx\n", p->f31.u.bits[0], p->f31.u.bits[1]);
309 kdb_print_nameval("r4", p->r4);
310 kdb_print_nameval("r5", p->r5);
311 kdb_print_nameval("r6", p->r6);
312 kdb_print_nameval("r7", p->r7);
313 kdb_print_nameval("b0", p->b0);
314 kdb_print_nameval("b1", p->b1);
315 kdb_print_nameval("b2", p->b2);
316 kdb_print_nameval("b3", p->b3);
317 kdb_print_nameval("b4", p->b4);
318 kdb_print_nameval("b5", p->b5);
319 kdb_printf(" ar_pfs 0x%lx\n", p->ar_pfs);
320 kdb_printf(" ar_lc 0x%lx\n", p->ar_lc);
321 kdb_printf(" ar_unat 0x%lx\n", p->ar_unat);
322 kdb_printf(" ar_rnat 0x%lx\n", p->ar_rnat);
323 kdb_printf(" ar_bspstore 0x%lx\n", p->ar_bspstore);
324 kdb_printf(" pr 0x%lx\n", p->pr);
332 * Format struct cpuinfo_ia64.
335 * argc argument count
336 * argv argument vector
337 * envp environment vector
338 * regs registers at time kdb was entered.
342 * zero for success, a kdb diagnostic if error
346 * If no cpu is supplied, it prints cpuinfo for all online cpus.
350 kdba_cpuinfo(int argc, const char **argv, const char **envp, struct pt_regs *regs)
356 struct cpuinfo_ia64 *cpuinfo;
360 diag = kdbgetaddrarg(argc, argv, &nextarg, &cpunum, &offset, NULL, regs);
363 if (cpunum >= NR_CPUS || !cpu_online(cpunum))
364 return KDB_BADCPUNUM;
365 } else if (argc > 1) {
369 for (c = (cpunum < 0 ? 0 : cpunum);
370 c < (cpunum < 0 ? NR_CPUS : cpunum+1);
374 cpuinfo = cpu_data(c);
375 kdb_printf("struct cpuinfo_ia64 for cpu %d is at 0x%p\n", c, cpuinfo);
376 kdb_printf(" softirq_pending 0x%x\n", cpuinfo->softirq_pending);
377 kdb_printf(" itm_delta %ld\n", cpuinfo->itm_delta);
378 kdb_printf(" itm_next %ld\n", cpuinfo->itm_next);
379 kdb_printf(" nsec_per_cyc %ld\n", cpuinfo->nsec_per_cyc);
380 kdb_printf(" unimpl_va_mask 0x%lx\n", cpuinfo->unimpl_va_mask);
381 kdb_printf(" unimpl_pa_mask 0x%lx\n", cpuinfo->unimpl_pa_mask);
382 kdb_printf(" pgd_quick 0x%p\n", cpuinfo->pgd_quick);
383 kdb_printf(" pgtable_cache_sz %ld\n", cpuinfo->pgtable_cache_sz);
384 kdb_printf(" itc_freq %ld\n", cpuinfo->itc_freq);
385 kdb_printf(" proc_freq %ld\n", cpuinfo->proc_freq);
386 kdb_printf(" cyc_per_usec %ld\n", cpuinfo->cyc_per_usec);
387 kdb_printf(" cyc_per_usec %ld\n", cpuinfo->cyc_per_usec);
388 #if 0 /* RJA per-cpu MCA */
389 kdb_printf(" percpu_paddr 0x%lx\n", cpuinfo->percpu_paddr);
391 kdb_printf(" ptce_base 0x%lx\n", cpuinfo->ptce_base);
392 kdb_printf(" ptce_count %d %d\n", cpuinfo->ptce_count[0], cpuinfo->ptce_count[1]);
393 kdb_printf(" ptce_stride %d %d\n", cpuinfo->ptce_stride[0], cpuinfo->ptce_stride[1]);
394 #if 0 /* RJA per-cpu MCA */
395 kdb_printf(" pal_paddr 0x%lx\n", cpuinfo->pal_paddr);
396 kdb_printf(" pal_base 0x%lx\n", cpuinfo->pal_base);
398 kdb_printf(" ksoftirqd 0x%p\n", cpuinfo->ksoftirqd);
400 kdb_printf(" loops_per_jiffy %ld\n", cpuinfo->loops_per_jiffy);
401 kdb_printf(" cpu %d\n", cpuinfo->cpu);
403 kdb_printf(" ppn 0x%lx\n", cpuinfo->ppn);
404 kdb_printf(" features 0x%lx\n", cpuinfo->features);
405 kdb_printf(" number %d\n", cpuinfo->number);
406 kdb_printf(" revision %d\n", cpuinfo->revision);
407 kdb_printf(" model %d\n", cpuinfo->model);
408 kdb_printf(" family %d\n", cpuinfo->family);
409 kdb_printf(" archrev %d\n", cpuinfo->archrev);
410 kdb_printf(" vendor ");
411 for (i = 0; i < sizeof(cpuinfo->vendor); ++i)
412 kdb_printf(" 0x%02x", cpuinfo->vendor[i]);
415 kdb_printf(" node_data 0x%p\n", cpuinfo->node_data);
417 #if 0 /* RJA per-cpu MCA */
418 kdb_printf(" ia64_pa_mca_data 0x%p\n", cpuinfo->ia64_pa_mca_data);
425 kdba_installdbreg(kdb_bp_t *bp)
427 /* FIXME: code this */
431 kdba_removedbreg(kdb_bp_t *bp)
433 /* FIXME: code this */
437 kdba_getdr(int regnum)
439 kdb_machreg_t contents = 0;
440 unsigned long reg = (unsigned long)regnum;
442 __asm__ ("mov %0=ibr[%1]"::"r"(contents),"r"(reg));
443 // __asm__ ("mov ibr[%0]=%1"::"r"(dbreg_cond),"r"(value));
450 get_fault_regs(fault_regs_t *fr)
455 __asm__ ("rsm psr.ic;;") ;
457 __asm__ ("mov %0=cr.ifa" : "=r"(fr->ifa));
458 __asm__ ("mov %0=cr.isr" : "=r"(fr->isr));
459 __asm__ ("ssm psr.ic;;") ;
464 show_kernel_regs (void)
469 asm ("mov %0=ar.k0" : "=r"(kr[0])); asm ("mov %0=ar.k1" : "=r"(kr[1]));
470 asm ("mov %0=ar.k2" : "=r"(kr[2])); asm ("mov %0=ar.k3" : "=r"(kr[3]));
471 asm ("mov %0=ar.k4" : "=r"(kr[4])); asm ("mov %0=ar.k5" : "=r"(kr[5]));
472 asm ("mov %0=ar.k6" : "=r"(kr[6])); asm ("mov %0=ar.k7" : "=r"(kr[7]));
474 for (i = 0; i < 4; ++i)
475 kdb_printf(" kr%d: %016lx kr%d: %016lx\n", 2*i, kr[2*i], 2*i+1, kr[2*i+1]);
480 change_cur_stack_frame(struct pt_regs *regs, int regno, unsigned long *contents)
482 unsigned long sof, i, cfm, sp, *bsp;
483 struct unw_frame_info info;
486 unw_init_frame_info(&info, current, kdb_running_process[smp_processor_id()].arch.sw);
488 if (unw_unwind(&info) < 0) {
489 kdb_printf("Failed to unwind\n");
492 unw_get_sp(&info, &sp);
493 } while (sp <= (unsigned long) regs);
494 unw_get_bsp(&info, (unsigned long *) &bsp);
495 unw_get_cfm(&info, &cfm);
498 kdb_printf("Unable to get Current Stack Frame\n");
504 if(((unsigned long)regno - 32) >= (sof - 2)) return 1;
506 old_fs = set_fs(KERNEL_DS);
508 for (i = 0; i < (regno - 32); ++i) {
509 bsp = ia64_rse_skip_regs(bsp, 1);
511 put_user(*contents, bsp);
519 show_cur_stack_frame(struct pt_regs *regs, int regno, unsigned long *contents)
521 unsigned long sof, i, cfm, val, sp, *bsp;
522 struct unw_frame_info info;
525 /* XXX It would be better to simply create a copy of an unw_frame_info structure
526 * that is set up in kdba_main_loop(). That way, we could avoid having to skip
527 * over the first few frames every time...
529 unw_init_frame_info(&info, current, kdb_running_process[smp_processor_id()].arch.sw);
531 if (unw_unwind(&info) < 0) {
532 kdb_printf("Failed to unwind\n");
535 unw_get_sp(&info, &sp);
536 } while (sp <= (unsigned long) regs);
537 unw_get_bsp(&info, (unsigned long *) &bsp);
538 unw_get_cfm(&info, &cfm);
541 kdb_printf("Unable to display Current Stack Frame\n");
548 if ((unsigned) regno - 32 >= sof)
550 bsp = ia64_rse_skip_regs(bsp, regno - 32);
551 old_fs = set_fs(KERNEL_DS);
560 old_fs = set_fs(KERNEL_DS);
562 for (i = 0; i < sof; ++i) {
564 kdb_printf(" r%lu: %016lx ", 32 + i, val);
567 bsp = ia64_rse_skip_regs(bsp, 1);
577 * kdba_getregcontents
579 * Return the contents of the register specified by the
580 * input string argument. Return an error if the string
581 * does not match a machine register.
583 * The following pseudo register names are supported:
584 * ®s - Prints address of exception frame
585 * kesp - Prints kernel stack pointer at time of fault
586 * sstk - Prints switch stack for ia64
587 * %<regname> - Uses the value of the registers at the
588 * last time the user process entered kernel
589 * mode, instead of the registers at the time
593 * regname Pointer to string naming register
594 * regs Pointer to structure containing registers.
596 * *contents Pointer to unsigned long to recieve register contents
599 * KDB_BADREG Invalid register name
604 * Note that this function is really machine independent. The kdb
605 * register list is not, however.
608 static struct kdbregs {
612 { "psr", offsetof(struct pt_regs, cr_ipsr) },
613 { "ifs", offsetof(struct pt_regs, cr_ifs) },
614 { "ip", offsetof(struct pt_regs, cr_iip) },
616 { "unat", offsetof(struct pt_regs, ar_unat) },
617 { "pfs", offsetof(struct pt_regs, ar_pfs) },
618 { "rsc", offsetof(struct pt_regs, ar_rsc) },
620 { "rnat", offsetof(struct pt_regs, ar_rnat) },
621 { "bsps", offsetof(struct pt_regs, ar_bspstore) },
622 { "pr", offsetof(struct pt_regs, pr) },
624 { "ldrs", offsetof(struct pt_regs, loadrs) },
625 { "ccv", offsetof(struct pt_regs, ar_ccv) },
626 { "fpsr", offsetof(struct pt_regs, ar_fpsr) },
628 { "b0", offsetof(struct pt_regs, b0) },
629 { "b6", offsetof(struct pt_regs, b6) },
630 { "b7", offsetof(struct pt_regs, b7) },
632 { "r1",offsetof(struct pt_regs, r1) },
633 { "r2",offsetof(struct pt_regs, r2) },
634 { "r3",offsetof(struct pt_regs, r3) },
636 { "r8",offsetof(struct pt_regs, r8) },
637 { "r9",offsetof(struct pt_regs, r9) },
638 { "r10",offsetof(struct pt_regs, r10) },
640 { "r11",offsetof(struct pt_regs, r11) },
641 { "r12",offsetof(struct pt_regs, r12) },
642 { "r13",offsetof(struct pt_regs, r13) },
644 { "r14",offsetof(struct pt_regs, r14) },
645 { "r15",offsetof(struct pt_regs, r15) },
646 { "r16",offsetof(struct pt_regs, r16) },
648 { "r17",offsetof(struct pt_regs, r17) },
649 { "r18",offsetof(struct pt_regs, r18) },
650 { "r19",offsetof(struct pt_regs, r19) },
652 { "r20",offsetof(struct pt_regs, r20) },
653 { "r21",offsetof(struct pt_regs, r21) },
654 { "r22",offsetof(struct pt_regs, r22) },
656 { "r23",offsetof(struct pt_regs, r23) },
657 { "r24",offsetof(struct pt_regs, r24) },
658 { "r25",offsetof(struct pt_regs, r25) },
660 { "r26",offsetof(struct pt_regs, r26) },
661 { "r27",offsetof(struct pt_regs, r27) },
662 { "r28",offsetof(struct pt_regs, r28) },
664 { "r29",offsetof(struct pt_regs, r29) },
665 { "r30",offsetof(struct pt_regs, r30) },
666 { "r31",offsetof(struct pt_regs, r31) },
670 static const int nkdbreglist = sizeof(kdbreglist) / sizeof(struct kdbregs);
673 kdba_getregcontents(const char *regname, struct pt_regs *regs, unsigned long *contents)
677 if (strcmp(regname, "isr") == 0) {
679 get_fault_regs(&fr) ;
685 kdb_printf("%s: pt_regs not available\n", __FUNCTION__);
689 if (strcmp(regname, "®s") == 0) {
690 *contents = (unsigned long)regs;
694 if (strcmp(regname, "sstk") == 0) {
695 *contents = (unsigned long)getprsregs(regs) ;
699 if (strcmp(regname, "ksp") == 0) {
700 *contents = (unsigned long) (regs + 1);
704 for (i=0; i<nkdbreglist; i++) {
705 if (strstr(kdbreglist[i].reg_name, regname))
709 if (i == nkdbreglist) {
710 /* Lets check the rse maybe */
711 if (regname[0] == 'r')
712 if (show_cur_stack_frame(regs, simple_strtoul(regname+1, 0, 0), contents))
717 *contents = *(unsigned long *)((unsigned long)regs +
718 kdbreglist[i].reg_offset);
724 * kdba_setregcontents
726 * Set the contents of the register specified by the
727 * input string argument. Return an error if the string
728 * does not match a machine register.
730 * Supports modification of user-mode registers via
734 * regname Pointer to string naming register
735 * regs Pointer to structure containing registers.
736 * contents Unsigned long containing new register contents
740 * KDB_BADREG Invalid register name
747 kdba_setregcontents(const char *regname,
748 struct pt_regs *regs,
749 unsigned long contents)
751 int i, ret = 0, fixed = 0;
755 if (regname[0] == '%') {
757 regs = (struct pt_regs *)
758 (kdb_current_task->thread.ksp - sizeof(struct pt_regs));
762 kdb_printf("%s: pt_regs not available\n", __FUNCTION__);
766 /* fixed registers */
767 for (i=0; i<nkdbreglist; i++) {
768 if (strnicmp(kdbreglist[i].reg_name,
770 strlen(regname)) == 0) {
776 /* stacked registers */
778 regno = (simple_strtoul(®name[1], &endp, 10));
779 if ((regname[0] == 'r') && regno > (unsigned long)31) {
780 ret = change_cur_stack_frame(regs, regno, &contents);
785 if ((i == nkdbreglist)
786 || (strlen(kdbreglist[i].reg_name) != strlen(regname))
791 /* just in case of "standard" register */
792 *(unsigned long *)((unsigned long)regs + kdbreglist[i].reg_offset) =
801 * Dump the specified register set to the display.
804 * regs Pointer to structure containing registers.
805 * type Character string identifying register set to dump
806 * extra string further identifying register (optional)
813 * This function will dump the general register set if the type
814 * argument is NULL (struct pt_regs). The alternate register
815 * set types supported by this function:
818 * c Control registers
819 * u User registers at most recent entry to kernel
820 * i Interrupt registers -- same as "irr" command
821 * Following not yet implemented:
822 * m Model Specific Registers (extra defines register #)
823 * r Memory Type Range Registers (extra defines register)
825 * For now, all registers are covered as follows:
827 * rd - dumps all regs
828 * rd %isr - current interrupt status reg, read freshly
829 * rd s - valid stacked regs
830 * rd %sstk - gets switch stack addr. dump memory and search
831 * rd d - debug regs, may not be too useful
832 * rd k - dump kernel regs
835 * OTHERS TB Decided ??
838 * These will be implemented later - Srinivasa
842 * g dump all General static registers
843 * s dump all general Stacked registers
844 * f dump all Floating Point registers
845 * p dump all Predicate registers
846 * b dump all Branch registers
847 * a dump all Application registers
848 * c dump all Control registers
853 kdba_dumpregs(struct pt_regs *regs,
862 && (type[0] == 'u')) {
864 regs = (struct pt_regs *)
865 (kdb_current_task->thread.ksp - sizeof(struct pt_regs));
870 kdb_printf("%s: pt_regs not available\n", __FUNCTION__);
873 for (i=0; i<nkdbreglist; i++) {
874 kdb_printf("%4s: 0x%16.16lx ",
875 kdbreglist[i].reg_name,
876 *(unsigned long *)((unsigned long)regs +
877 kdbreglist[i].reg_offset));
879 if ((++count % 3) == 0)
883 kdb_printf("®s = %p\n", (void *)regs);
891 for(i=0; i<8; i+=2) {
892 kdb_printf("idr%d: 0x%16.16lx idr%d: 0x%16.16lx\n", i,
893 kdba_getdr(i), i+1, kdba_getdr(i+1));
912 kdb_printf("%s: pt_regs not available\n", __FUNCTION__);
915 show_cur_stack_frame(regs, 0, NULL) ;
922 unsigned long contents ;
924 if (!kdba_getregcontents(type+1, regs, &contents))
925 kdb_printf("%s = 0x%16.16lx\n", type+1, contents) ;
927 kdb_printf("diag: Invalid register %s\n", type+1) ;
941 kdba_getpc(struct pt_regs *regs)
943 return regs ? regs->cr_iip + ia64_psr(regs)->ri : 0;
947 kdba_setpc(struct pt_regs *regs, kdb_machreg_t newpc)
949 if (KDB_NULL_REGS(regs))
951 regs->cr_iip = newpc & ~0xf;
952 ia64_psr(regs)->ri = newpc & 0x3;
953 KDB_STATE_SET(IP_ADJUSTED);
957 struct kdba_main_loop_data {
959 kdb_reason_t reason2;
961 kdb_dbtrap_t db_result;
962 struct pt_regs *regs;
968 * Invoked from interrupt wrappers via unw_init_running() after that
969 * routine has pushed a struct switch_stack. The interrupt wrappers
970 * go around functions that disappear into sal/pal and therefore cannot
971 * get into kdb. This routine saves the switch stack information so
972 * kdb can get diagnostics for such routines, even though they are not
973 * blocked in the kernel.
976 * info Unwind information.
977 * data structure passed as void * to unw_init_running. It identifies
978 * the real interrupt handler and contains its parameters.
980 * none (unw_init_running requires void).
986 * unw_init_running() creates struct switch_stack then struct
987 * unw_frame_info. We get the address of the info so step over
988 * that to get switch_stack. Just hope that unw_init_running
989 * does not change its stack usage. unw_init_running adds padding
990 * to put switch_stack on a 16 byte boundary.
993 KDBA_UNWIND_HANDLER(kdba_sw_interrupt, struct kdba_sw_interrupt_data, data->irq,
994 data->ret = (data->handler)(data->irq, data->arg, data->regs)
1000 * Invoked from kdba_main_loop via unw_init_running() after that routine
1001 * has pushed a struct switch_stack.
1004 * info Unwind information.
1005 * data kdb data passed as void * to unw_init_running.
1007 * none (unw_init_running requires void). vdata->ret is set to
1008 * 0 KDB was invoked for an event which it wasn't responsible
1009 * 1 KDB handled the event for which it was invoked.
1015 * As for kdba_sw_interrupt above.
1018 static KDBA_UNWIND_HANDLER(do_kdba_main_loop, struct kdba_main_loop_data, data->reason,
1019 data->ret = kdb_main_loop(data->reason, data->reason2, data->error, data->db_result, data->regs));
1024 * Do any architecture specific set up before entering the main kdb loop.
1025 * The primary function of this routine is to make all processes look the
1026 * same to kdb, kdb must be able to list a process without worrying if the
1027 * process is running or blocked, so make all processes look as though they
1031 * reason The reason KDB was invoked
1032 * error The hardware-defined error code
1033 * error2 kdb's current reason code. Initially error but can change
1034 * acording to kdb state.
1035 * db_result Result from break or debug point.
1036 * regs The exception frame at time of fault/breakpoint. If reason
1037 * is KDB_REASON_SILENT then regs is NULL, otherwise it should
1040 * 0 KDB was invoked for an event which it wasn't responsible
1041 * 1 KDB handled the event for which it was invoked.
1043 * Builds a switch_stack structure before calling the main loop.
1051 kdba_main_loop(kdb_reason_t reason, kdb_reason_t reason2, int error,
1052 kdb_dbtrap_t db_result, struct pt_regs *regs)
1054 struct kdba_main_loop_data data;
1055 KDB_DEBUG_STATE("kdba_main_loop", reason);
1056 data.reason = reason;
1057 data.reason2 = reason2;
1059 data.db_result = db_result;
1061 if (reason == KDB_REASON_CALL_PRESET) {
1062 /* kdb_running_process has been preset, do not overwrite it */
1063 KDB_DEBUG_STATE(__FUNCTION__, KDB_REASON_CALL_PRESET);
1064 data.ret = kdb_main_loop(KDB_REASON_CALL, KDB_REASON_CALL, data.error, data.db_result, data.regs);
1067 unw_init_running(do_kdba_main_loop, &data);
1072 kdba_disableint(kdb_intstate_t *state)
1074 unsigned long *fp = (unsigned long *)state;
1075 unsigned long flags;
1077 local_irq_save(flags);
1082 kdba_restoreint(kdb_intstate_t *state)
1084 unsigned long flags = *(unsigned long *)state;
1085 local_irq_restore(flags);
1089 kdba_setsinglestep(struct pt_regs *regs)
1091 if (KDB_NULL_REGS(regs))
1093 ia64_psr(regs)->ss = 1;
1097 kdba_clearsinglestep(struct pt_regs *regs)
1099 if (KDB_NULL_REGS(regs))
1101 ia64_psr(regs)->ss = 0;
1107 * Enable last branch recording.
1120 kdba_enable_lbr(void)
1127 * disable last branch recording.
1140 kdba_disable_lbr(void)
1147 * Print last branch and last exception addresses
1160 kdba_print_lbr(void)
1166 * Virtual to Physical address translation command.
1171 * argc Count of arguments in argv
1172 * argv Space delimited command line arguments
1173 * envp Environment value
1174 * regs Exception frame at entry to kernel debugger
1178 * Zero for success, a kdb diagnostic if failure.
1183 #define __xtpa(x) ({ia64_va _v; asm("tpa %0=%1" : "=r"(_v.l) : "r"(x)); _v.l;})
1185 kdba_tpa(int argc, const char **argv, const char **envp, struct pt_regs* regs)
1195 return KDB_ARGCOUNT;
1196 diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs);
1199 if (kdb_getarea(c, addr))
1201 kdb_printf("vaddr: 0x%lx , paddr: 0x%lx\n", addr, __xtpa(addr));
1204 #if defined(CONFIG_NUMA)
1206 kdba_tpav(int argc, const char **argv, const char **envp, struct pt_regs* regs)
1208 kdb_machreg_t addr, end, paddr;
1211 int nextarg, nid, nid_old;
1216 return KDB_ARGCOUNT;
1217 diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs);
1220 diag = kdbgetaddrarg(argc, argv, &nextarg, &end, &offset, NULL, regs);
1223 if (kdb_getarea(c, addr))
1225 if (kdb_getarea(c, end))
1228 nid = paddr_to_nid(paddr);
1229 kdb_printf("begin: 0x%lx , paddr: 0x%lx , nid: %d\n", addr, __xtpa(addr), nid);
1230 for(;addr<end; addr += PAGE_SIZE) {
1232 paddr =__xtpa(addr);
1233 nid = paddr_to_nid(paddr);
1235 kdb_printf("NOT on same NODE: addr: 0x%lx , paddr: 0x%lx , nid: %d\n", addr, paddr, nid);
1238 nid=paddr_to_nid(end);
1239 kdb_printf("end: 0x%lx , paddr: 0x%lx , nid: %d\n", end, paddr, nid);
1244 #if defined(CONFIG_SMP)
1248 * This function implements the 'init' command.
1253 * argc argument count
1254 * argv argument vector
1255 * envp environment vector
1256 * regs registers at time kdb was entered.
1260 * zero for success, a kdb diagnostic if error
1267 kdba_sendinit(int argc, const char **argv, const char **envp, struct pt_regs *regs)
1269 unsigned long cpunum;
1273 return KDB_ARGCOUNT;
1275 diag = kdbgetularg(argv[1], &cpunum);
1279 if (cpunum >= NR_CPUS || !cpu_online(cpunum))
1280 return KDB_BADCPUNUM;
1282 platform_send_ipi(cpunum, 0, IA64_IPI_DM_INIT, 0);
1285 #endif /* CONFIG_SMP */
1290 * Architecture specific initialization.
1306 kdb_register("irr", kdba_sir, "", "Show interrupt registers", 0);
1307 kdb_register("itm", kdba_itm, "", "Set new ITM value", 0);
1308 #if defined(CONFIG_SMP)
1309 kdb_register("init", kdba_sendinit, "", "Send INIT to cpu", 0);
1311 kdb_register("pt_regs", kdba_pt_regs, "address", "Format struct pt_regs", 0);
1312 kdb_register("switch_stack", kdba_switch_stack, "address", "Format struct switch_stack", 0);
1313 kdb_register("tpa", kdba_tpa, "<vaddr>", "Translate virtual to physical address", 0);
1314 #if defined(CONFIG_NUMA)
1315 kdb_register("tpav", kdba_tpav, "<begin addr> <end addr>", "Verify that physical addresses corresponding to virtual addresses from <begin addr> to <end addr> are in same node", 0);
1317 kdb_register("stackdepth", kdba_stackdepth, "[percentage]", "Print processes using >= stack percentage", 0);
1318 kdb_register("cpuinfo", kdba_cpuinfo, "[cpu]", "Print struct cpuinfo_ia64", 0);
1320 #ifdef CONFIG_SERIAL_8250_CONSOLE
1321 kdba_serial_console = KDBA_SC_STANDARD;
1323 #ifdef CONFIG_SERIAL_SGI_L1_CONSOLE
1324 if (ia64_platform_is("sn2"))
1325 kdba_serial_console = KDBA_SC_SGI_L1;
1333 * Architecture specific adjustment of instruction pointer before leaving
1337 * reason The reason KDB was invoked
1338 * error The hardware-defined error code
1339 * regs The exception frame at time of fault/breakpoint. If reason
1340 * is KDB_REASON_SILENT then regs is NULL, otherwise it should
1347 * On IA64, KDB_ENTER() uses break which is a fault, not a trap. The
1348 * instruction pointer must be stepped before leaving kdb, otherwise we
1353 kdba_adjust_ip(kdb_reason_t reason, int error, struct pt_regs *regs)
1355 if (reason == KDB_REASON_ENTER &&
1356 !KDB_STATE(IP_ADJUSTED)) {
1357 if (KDB_NULL_REGS(regs))
1359 if (ia64_psr(regs)->ri < 2)
1360 kdba_setpc(regs, regs->cr_iip + ia64_psr(regs)->ri + 1);
1362 kdba_setpc(regs, regs->cr_iip + 16);