Drop obsoleted patch.
[linux-flexiantxendom0-3.2.10.git] / arch / ia64 / kdb / kdbasupport.c
1 /*
2  * Kernel Debugger Architecture Independent Support Functions
3  *
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
6  * for more details.
7  *
8  * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
9  * Copyright (C) David Mosberger-Tang <davidm@hpl.hp.com>
10  */
11
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>
18 #include <linux/mm.h>
19 #include <linux/sched.h>
20 #include <linux/kdb.h>
21 #include <linux/kdbprivate.h>
22
23 #include <asm/processor.h>
24 #include <asm/uaccess.h>
25 #include <asm/rse.h>
26 #include <asm/delay.h>
27 #ifdef CONFIG_SMP
28 #include <asm/hw_irq.h>
29 #endif
30
31 static int
32 kdba_itm (int argc, const char **argv, const char **envp, struct pt_regs *regs)
33 {
34         int diag;
35         unsigned long val;
36
37         diag = kdbgetularg(argv[1], &val);
38         if (diag)
39                 return diag;
40         kdb_printf("new itm=" kdb_machreg_fmt "\n", val);
41
42         ia64_set_itm(val);
43         return 0;
44 }
45
46 static void
47 kdba_show_intregs(void)
48 {
49         u64 lid, tpr, lrr0, lrr1, itv, pmv, cmcv;
50
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);
56
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);
61
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));
64
65         kdb_printf("itc=0x%016lx, itm=0x%016lx\n", ia64_get_itc(), ia64_get_itm());
66 }
67
68 static int
69 kdba_sir (int argc, const char **argv, const char **envp, struct pt_regs *regs)
70 {
71         kdba_show_intregs();
72
73         return 0;
74 }
75
76 /*
77  * kdba_pt_regs
78  *
79  *      Format a struct pt_regs
80  *
81  * Inputs:
82  *      argc    argument count
83  *      argv    argument vector
84  *      envp    environment vector
85  *      regs    registers at time kdb was entered.
86  * Outputs:
87  *      None.
88  * Returns:
89  *      zero for success, a kdb diagnostic if error
90  * Locking:
91  *      none.
92  * Remarks:
93  *      If no address is supplied, it uses regs.
94  */
95
96 static int
97 kdba_pt_regs(int argc, const char **argv, const char **envp, struct pt_regs *regs)
98 {
99         int diag;
100         kdb_machreg_t addr;
101         long offset = 0;
102         int nextarg;
103         struct pt_regs *p;
104
105         if (argc == 0) {
106                 addr = (kdb_machreg_t) regs;
107         } else if (argc == 1) {
108                 nextarg = 1;
109                 diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs);
110                 if (diag)
111                         return diag;
112         } else {
113                 return KDB_ARGCOUNT;
114         }
115
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]);
168
169         return 0;
170 }
171
172 /*
173  * kdba_stackdepth
174  *
175  *      Print processes that are using more than a specific percentage of their
176  *      stack.
177  *
178  * Inputs:
179  *      argc    argument count
180  *      argv    argument vector
181  *      envp    environment vector
182  *      regs    registers at time kdb was entered.
183  * Outputs:
184  *      None.
185  * Returns:
186  *      zero for success, a kdb diagnostic if error
187  * Locking:
188  *      none.
189  * Remarks:
190  *      If no percentage is supplied, it uses 60.
191  */
192
193 static int
194 kdba_stackdepth(int argc, const char **argv, const char **envp, struct pt_regs *regs)
195 {
196         int diag, threshold, used;
197         long percentage;
198         unsigned long esp;
199         long offset = 0;
200         int nextarg;
201         struct task_struct *p, *g;
202         struct switch_stack *sw;
203
204         if (argc == 0) {
205                 percentage = 60;
206         } else if (argc == 1) {
207                 nextarg = 1;
208                 diag = kdbgetaddrarg(argc, argv, &nextarg, &percentage, &offset, NULL, regs);
209                 if (diag)
210                         return diag;
211         } else {
212                 return KDB_ARGCOUNT;
213         }
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);
222                         if (krp->seqno)
223                                 sw = krp->arch.sw;
224                         else
225                                 sw = NULL;
226                 } else
227                         sw = (struct switch_stack *) (p->thread.ksp + 16);
228                 if (!sw)
229                         continue;
230                 esp = (unsigned long) sw;
231                 used = THREAD_SIZE - (esp - sw->ar_bspstore);
232                 if (used >= threshold) {
233                         kdb_ps1(p);
234                         kdb_printf("  esp %lx bsp %lx used %d\n", esp, sw->ar_bspstore, used);
235                 }
236         } kdb_while_each_thread(g, p);
237
238         return 0;
239 }
240
241 /*
242  * kdb_switch_stack
243  *
244  *      Format a struct switch_stack
245  *
246  * Inputs:
247  *      argc    argument count
248  *      argv    argument vector
249  *      envp    environment vector
250  *      regs    registers at time kdb was entered.
251  * Outputs:
252  *      None.
253  * Returns:
254  *      zero for success, a kdb diagnostic if error
255  * Locking:
256  *      none.
257  * Remarks:
258  *      If no address is supplied, it uses kdb_running_process[smp_processor_id()].arch.sw.
259  */
260
261 static int
262 kdba_switch_stack(int argc, const char **argv, const char **envp, struct pt_regs *regs)
263 {
264         int diag;
265         kdb_machreg_t addr;
266         long offset = 0;
267         int nextarg;
268         struct switch_stack *p;
269
270         if (argc == 0) {
271                 addr = (kdb_machreg_t) kdb_running_process[smp_processor_id()].arch.sw;
272         } else if (argc == 1) {
273                 nextarg = 1;
274                 diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs);
275                 if (diag)
276                         return diag;
277         } else {
278                 return KDB_ARGCOUNT;
279         }
280
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);
325
326         return 0;
327 }
328
329 /*
330  * kdba_cpuinfo
331  *
332  *      Format struct cpuinfo_ia64.
333  *
334  * Inputs:
335  *      argc    argument count
336  *      argv    argument vector
337  *      envp    environment vector
338  *      regs    registers at time kdb was entered.
339  * Outputs:
340  *      None.
341  * Returns:
342  *      zero for success, a kdb diagnostic if error
343  * Locking:
344  *      none.
345  * Remarks:
346  *      If no cpu is supplied, it prints cpuinfo for all online cpus.
347  */
348
349 static int
350 kdba_cpuinfo(int argc, const char **argv, const char **envp, struct pt_regs *regs)
351 {
352         int diag;
353         long cpunum = -1;
354         long offset = 0;
355         int nextarg, c, i;
356         struct cpuinfo_ia64 *cpuinfo;
357
358         if (argc == 1) {
359                 nextarg = 1;
360                 diag = kdbgetaddrarg(argc, argv, &nextarg, &cpunum, &offset, NULL, regs);
361                 if (diag)
362                         return diag;
363                 if (cpunum >= NR_CPUS || !cpu_online(cpunum))
364                         return KDB_BADCPUNUM;
365         } else if (argc > 1) {
366                 return KDB_ARGCOUNT;
367         }
368
369         for (c = (cpunum < 0 ? 0 : cpunum);
370              c < (cpunum < 0 ? NR_CPUS : cpunum+1);
371              ++c) {
372                 if (!cpu_online(c))
373                         continue;
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);
390 #endif
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);
397 #endif
398                 kdb_printf("  ksoftirqd        0x%p\n",   cpuinfo->ksoftirqd);
399 #ifdef CONFIG_SMP
400                 kdb_printf("  loops_per_jiffy  %ld\n",    cpuinfo->loops_per_jiffy);
401                 kdb_printf("  cpu              %d\n",     cpuinfo->cpu);
402 #endif
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]);
413                 kdb_printf("\n");
414 #ifdef CONFIG_NUMA
415                 kdb_printf("  node_data        0x%p\n",   cpuinfo->node_data);
416 #endif
417 #if 0   /* RJA per-cpu MCA */
418                 kdb_printf("  ia64_pa_mca_data 0x%p\n",   cpuinfo->ia64_pa_mca_data);
419 #endif
420         }
421         return 0;
422 }
423
424 void
425 kdba_installdbreg(kdb_bp_t *bp)
426 {
427         /* FIXME: code this */
428 }
429
430 void
431 kdba_removedbreg(kdb_bp_t *bp)
432 {
433         /* FIXME: code this */
434 }
435
436 static kdb_machreg_t
437 kdba_getdr(int regnum)
438 {
439         kdb_machreg_t contents = 0;
440         unsigned long reg = (unsigned long)regnum;
441
442         __asm__ ("mov %0=ibr[%1]"::"r"(contents),"r"(reg));
443 //        __asm__ ("mov ibr[%0]=%1"::"r"(dbreg_cond),"r"(value));
444
445         return contents;
446 }
447
448
449 static void
450 get_fault_regs(fault_regs_t *fr)
451 {
452         fr->ifa = 0 ;
453         fr->isr = 0 ;
454
455         __asm__ ("rsm psr.ic;;") ;
456         ia64_srlz_d();
457         __asm__ ("mov %0=cr.ifa" : "=r"(fr->ifa));
458         __asm__ ("mov %0=cr.isr" : "=r"(fr->isr));
459         __asm__ ("ssm psr.ic;;") ;
460         ia64_srlz_d();
461 }
462
463 static void
464 show_kernel_regs (void)
465 {
466         unsigned long kr[8];
467         int i;
468
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]));
473
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]);
476         kdb_printf("\n");
477 }
478
479 static int
480 change_cur_stack_frame(struct pt_regs *regs, int regno, unsigned long *contents)
481 {
482         unsigned long sof, i, cfm, sp, *bsp;
483         struct unw_frame_info info;
484         mm_segment_t old_fs;
485
486         unw_init_frame_info(&info, current, kdb_running_process[smp_processor_id()].arch.sw);
487         do {
488                 if (unw_unwind(&info) < 0) {
489                         kdb_printf("Failed to unwind\n");
490                         return 0;
491                 }
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);
496
497         if (!bsp) {
498                 kdb_printf("Unable to get Current Stack Frame\n");
499                 return 0;
500         }
501
502         sof = (cfm & 0x7f);
503
504         if(((unsigned long)regno - 32) >= (sof - 2)) return 1;
505
506         old_fs = set_fs(KERNEL_DS);
507         {
508                 for (i = 0; i < (regno - 32); ++i) {
509                         bsp = ia64_rse_skip_regs(bsp, 1);
510                 }
511                 put_user(*contents, bsp);
512         }
513         set_fs(old_fs);
514
515         return 0 ;
516 }
517
518 static int
519 show_cur_stack_frame(struct pt_regs *regs, int regno, unsigned long *contents)
520 {
521         unsigned long sof, i, cfm, val, sp, *bsp;
522         struct unw_frame_info info;
523         mm_segment_t old_fs;
524
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...
528          */
529         unw_init_frame_info(&info, current, kdb_running_process[smp_processor_id()].arch.sw);
530         do {
531                 if (unw_unwind(&info) < 0) {
532                         kdb_printf("Failed to unwind\n");
533                         return 0;
534                 }
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);
539
540         if (!bsp) {
541                 kdb_printf("Unable to display Current Stack Frame\n");
542                 return 0;
543         }
544
545         sof = (cfm & 0x7f);
546
547         if (regno) {
548                 if ((unsigned) regno - 32 >= sof)
549                         return 0;
550                 bsp = ia64_rse_skip_regs(bsp, regno - 32);
551                 old_fs = set_fs(KERNEL_DS);
552                 {
553                         get_user(val, bsp);
554                 }
555                 set_fs(old_fs);
556                 *contents = val;
557                 return 1;
558         }
559
560         old_fs = set_fs(KERNEL_DS);
561         {
562                 for (i = 0; i < sof; ++i) {
563                         get_user(val, bsp);
564                         kdb_printf(" r%lu: %016lx ", 32 + i, val);
565                         if (!((i + 1) % 3))
566                                 kdb_printf("\n");
567                         bsp = ia64_rse_skip_regs(bsp, 1);
568                 }
569                 kdb_printf("\n");
570         }
571         set_fs(old_fs);
572
573         return 0 ;
574 }
575
576 /*
577  * kdba_getregcontents
578  *
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.
582  *
583  *      The following pseudo register names are supported:
584  *         &regs         - 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
590  *                         kdb was entered.
591  *
592  * Parameters:
593  *      regname         Pointer to string naming register
594  *      regs            Pointer to structure containing registers.
595  * Outputs:
596  *      *contents       Pointer to unsigned long to recieve register contents
597  * Returns:
598  *      0               Success
599  *      KDB_BADREG      Invalid register name
600  * Locking:
601  *      None.
602  * Remarks:
603  *
604  *      Note that this function is really machine independent.   The kdb
605  *      register list is not, however.
606  */
607
608 static struct kdbregs {
609         char   *reg_name;
610         size_t  reg_offset;
611 } kdbreglist[] = {
612         { "psr",        offsetof(struct pt_regs, cr_ipsr) },
613         { "ifs",        offsetof(struct pt_regs, cr_ifs) },
614         { "ip", offsetof(struct pt_regs, cr_iip) },
615
616         { "unat",       offsetof(struct pt_regs, ar_unat) },
617         { "pfs",        offsetof(struct pt_regs, ar_pfs) },
618         { "rsc",        offsetof(struct pt_regs, ar_rsc) },
619
620         { "rnat",       offsetof(struct pt_regs, ar_rnat) },
621         { "bsps",       offsetof(struct pt_regs, ar_bspstore) },
622         { "pr", offsetof(struct pt_regs, pr) },
623
624         { "ldrs",       offsetof(struct pt_regs, loadrs) },
625         { "ccv",        offsetof(struct pt_regs, ar_ccv) },
626         { "fpsr",       offsetof(struct pt_regs, ar_fpsr) },
627
628         { "b0", offsetof(struct pt_regs, b0) },
629         { "b6", offsetof(struct pt_regs, b6) },
630         { "b7", offsetof(struct pt_regs, b7) },
631
632         { "r1",offsetof(struct pt_regs, r1) },
633         { "r2",offsetof(struct pt_regs, r2) },
634         { "r3",offsetof(struct pt_regs, r3) },
635
636         { "r8",offsetof(struct pt_regs, r8) },
637         { "r9",offsetof(struct pt_regs, r9) },
638         { "r10",offsetof(struct pt_regs, r10) },
639
640         { "r11",offsetof(struct pt_regs, r11) },
641         { "r12",offsetof(struct pt_regs, r12) },
642         { "r13",offsetof(struct pt_regs, r13) },
643
644         { "r14",offsetof(struct pt_regs, r14) },
645         { "r15",offsetof(struct pt_regs, r15) },
646         { "r16",offsetof(struct pt_regs, r16) },
647
648         { "r17",offsetof(struct pt_regs, r17) },
649         { "r18",offsetof(struct pt_regs, r18) },
650         { "r19",offsetof(struct pt_regs, r19) },
651
652         { "r20",offsetof(struct pt_regs, r20) },
653         { "r21",offsetof(struct pt_regs, r21) },
654         { "r22",offsetof(struct pt_regs, r22) },
655
656         { "r23",offsetof(struct pt_regs, r23) },
657         { "r24",offsetof(struct pt_regs, r24) },
658         { "r25",offsetof(struct pt_regs, r25) },
659
660         { "r26",offsetof(struct pt_regs, r26) },
661         { "r27",offsetof(struct pt_regs, r27) },
662         { "r28",offsetof(struct pt_regs, r28) },
663
664         { "r29",offsetof(struct pt_regs, r29) },
665         { "r30",offsetof(struct pt_regs, r30) },
666         { "r31",offsetof(struct pt_regs, r31) },
667
668 };
669
670 static const int nkdbreglist = sizeof(kdbreglist) / sizeof(struct kdbregs);
671
672 int
673 kdba_getregcontents(const char *regname, struct pt_regs *regs, unsigned long *contents)
674 {
675         int i;
676
677         if (strcmp(regname, "isr") == 0) {
678                 fault_regs_t fr ;
679                 get_fault_regs(&fr) ;
680                 *contents = fr.isr ;
681                 return 0 ;
682         }
683
684         if (!regs) {
685                 kdb_printf("%s: pt_regs not available\n", __FUNCTION__);
686                 return KDB_BADREG;
687         }
688
689         if (strcmp(regname, "&regs") == 0) {
690                 *contents = (unsigned long)regs;
691                 return 0;
692         }
693
694         if (strcmp(regname, "sstk") == 0) {
695                 *contents = (unsigned long)getprsregs(regs) ;
696                 return 0;
697         }
698
699         if (strcmp(regname, "ksp") == 0) {
700                 *contents = (unsigned long) (regs + 1);
701                 return 0;
702         }
703
704         for (i=0; i<nkdbreglist; i++) {
705                 if (strstr(kdbreglist[i].reg_name, regname))
706                         break;
707         }
708
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))
713                                 return 0 ;
714                 return KDB_BADREG;
715         }
716
717         *contents = *(unsigned long *)((unsigned long)regs +
718                         kdbreglist[i].reg_offset);
719
720         return 0;
721 }
722
723 /*
724  * kdba_setregcontents
725  *
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.
729  *
730  *      Supports modification of user-mode registers via
731  *      %<register-name>
732  *
733  * Parameters:
734  *      regname         Pointer to string naming register
735  *      regs            Pointer to structure containing registers.
736  *      contents        Unsigned long containing new register contents
737  * Outputs:
738  * Returns:
739  *      0               Success
740  *      KDB_BADREG      Invalid register name
741  * Locking:
742  *      None.
743  * Remarks:
744  */
745
746 int
747 kdba_setregcontents(const char *regname,
748                   struct pt_regs *regs,
749                   unsigned long contents)
750 {
751         int i, ret = 0, fixed = 0;
752         char *endp;
753         unsigned long regno;
754
755         if (regname[0] == '%') {
756                 regname++;
757                 regs = (struct pt_regs *)
758                         (kdb_current_task->thread.ksp - sizeof(struct pt_regs));
759         }
760
761         if (!regs) {
762                 kdb_printf("%s: pt_regs not available\n", __FUNCTION__);
763                 return KDB_BADREG;
764         }
765
766         /* fixed registers */
767         for (i=0; i<nkdbreglist; i++) {
768                 if (strnicmp(kdbreglist[i].reg_name,
769                              regname,
770                              strlen(regname)) == 0) {
771                         fixed = 1;
772                         break;
773                 }
774         }
775
776         /* stacked registers */
777         if (!fixed) {
778                 regno = (simple_strtoul(&regname[1], &endp, 10));
779                 if ((regname[0] == 'r') && regno > (unsigned long)31) {
780                         ret = change_cur_stack_frame(regs, regno, &contents);
781                         if(!ret) return 0;
782                 }
783         }
784
785         if ((i == nkdbreglist)
786             || (strlen(kdbreglist[i].reg_name) != strlen(regname))
787             || ret) {
788                 return KDB_BADREG;
789         }
790
791         /* just in case of "standard" register */
792         *(unsigned long *)((unsigned long)regs + kdbreglist[i].reg_offset) =
793                 contents;
794
795         return 0;
796 }
797
798 /*
799  * kdba_dumpregs
800  *
801  *      Dump the specified register set to the display.
802  *
803  * Parameters:
804  *      regs            Pointer to structure containing registers.
805  *      type            Character string identifying register set to dump
806  *      extra           string further identifying register (optional)
807  * Outputs:
808  * Returns:
809  *      0               Success
810  * Locking:
811  *      None.
812  * Remarks:
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:
816  *
817  *      d               Debug registers
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)
824  *
825  *      For now, all registers are covered as follows:
826  *
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
833  *
834  *      ARs             TB Done
835  *      OTHERS          TB Decided ??
836  *
837  *      Intel wish list
838  *      These will be implemented later - Srinivasa
839  *
840  *      type        action
841  *      ----        ------
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
849  *
850  */
851
852 int
853 kdba_dumpregs(struct pt_regs *regs,
854             const char *type,
855             const char *extra)
856
857 {
858         int i;
859         int count = 0;
860
861         if (type
862          && (type[0] == 'u')) {
863                 type = NULL;
864                 regs = (struct pt_regs *)
865                         (kdb_current_task->thread.ksp - sizeof(struct pt_regs));
866         }
867
868         if (type == NULL) {
869                 if (!regs) {
870                         kdb_printf("%s: pt_regs not available\n", __FUNCTION__);
871                         return KDB_BADREG;
872                 }
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));
878
879                         if ((++count % 3) == 0)
880                                 kdb_printf("\n");
881                 }
882
883                 kdb_printf("&regs = %p\n", (void *)regs);
884
885                 return 0;
886         }
887
888         switch (type[0]) {
889         case 'd':
890         {
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));
894
895                 }
896                 return 0;
897         }
898         case 'i':
899                 kdba_show_intregs();
900                 break;
901         case 'k':
902                 show_kernel_regs();
903                 break;
904         case 'm':
905                 break;
906         case 'r':
907                 break;
908
909         case 's':
910         {
911                 if (!regs) {
912                         kdb_printf("%s: pt_regs not available\n", __FUNCTION__);
913                         return KDB_BADREG;
914                 }
915                 show_cur_stack_frame(regs, 0, NULL) ;
916
917                 return 0 ;
918         }
919
920         case '%':
921         {
922                 unsigned long contents ;
923
924                 if (!kdba_getregcontents(type+1, regs, &contents))
925                         kdb_printf("%s = 0x%16.16lx\n", type+1, contents) ;
926                 else
927                         kdb_printf("diag: Invalid register %s\n", type+1) ;
928
929                 return 0 ;
930         }
931
932         default:
933                 return KDB_BADREG;
934         }
935
936         /* NOTREACHED */
937         return 0;
938 }
939
940 kdb_machreg_t
941 kdba_getpc(struct pt_regs *regs)
942 {
943         return regs ? regs->cr_iip + ia64_psr(regs)->ri : 0;
944 }
945
946 int
947 kdba_setpc(struct pt_regs *regs, kdb_machreg_t newpc)
948 {
949         if (KDB_NULL_REGS(regs))
950                 return KDB_BADREG;
951         regs->cr_iip = newpc & ~0xf;
952         ia64_psr(regs)->ri = newpc & 0x3;
953         KDB_STATE_SET(IP_ADJUSTED);
954         return 0;
955 }
956
957 struct kdba_main_loop_data {
958         kdb_reason_t reason;
959         kdb_reason_t reason2;
960         int error;
961         kdb_dbtrap_t db_result;
962         struct pt_regs *regs;
963         int ret;
964 };
965
966 /*
967  * kdba_sw_interrupt
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.
974  *
975  * Inputs:
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.
979  * Returns:
980  *      none (unw_init_running requires void).
981  * Outputs:
982  *      none
983  * Locking:
984  *      None.
985  * Remarks:
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.
991  */
992
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)
995         );
996
997 /*
998  * do_kdba_main_loop
999  *
1000  *      Invoked from kdba_main_loop via unw_init_running() after that routine
1001  *      has pushed a struct switch_stack.
1002  *
1003  * Inputs:
1004  *      info    Unwind information.
1005  *      data    kdb data passed as void * to unw_init_running.
1006  * Returns:
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.
1010  * Outputs:
1011  *      none
1012  * Locking:
1013  *      None.
1014  * Remarks:
1015  *      As for kdba_sw_interrupt above.
1016  */
1017
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));
1020
1021 /*
1022  * kdba_main_loop
1023  *
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
1028  *      are blocked.
1029  *
1030  * Inputs:
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
1038  *                      always be valid.
1039  * Returns:
1040  *      0       KDB was invoked for an event which it wasn't responsible
1041  *      1       KDB handled the event for which it was invoked.
1042  * Outputs:
1043  *      Builds a switch_stack structure before calling the main loop.
1044  * Locking:
1045  *      None.
1046  * Remarks:
1047  *      none.
1048  */
1049
1050 int
1051 kdba_main_loop(kdb_reason_t reason, kdb_reason_t reason2, int error,
1052                kdb_dbtrap_t db_result, struct pt_regs *regs)
1053 {
1054         struct kdba_main_loop_data data;
1055         KDB_DEBUG_STATE("kdba_main_loop", reason);
1056         data.reason = reason;
1057         data.reason2 = reason2;
1058         data.error = error;
1059         data.db_result = db_result;
1060         data.regs = regs;
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);
1065         }
1066         else
1067                 unw_init_running(do_kdba_main_loop, &data);
1068         return(data.ret);
1069 }
1070
1071 void
1072 kdba_disableint(kdb_intstate_t *state)
1073 {
1074         unsigned long *fp = (unsigned long *)state;
1075         unsigned long flags;
1076
1077         local_irq_save(flags);
1078         *fp = flags;
1079 }
1080
1081 void
1082 kdba_restoreint(kdb_intstate_t *state)
1083 {
1084         unsigned long flags = *(unsigned long *)state;
1085         local_irq_restore(flags);
1086 }
1087
1088 void
1089 kdba_setsinglestep(struct pt_regs *regs)
1090 {
1091         if (KDB_NULL_REGS(regs))
1092                 return;
1093         ia64_psr(regs)->ss = 1;
1094 }
1095
1096 void
1097 kdba_clearsinglestep(struct pt_regs *regs)
1098 {
1099         if (KDB_NULL_REGS(regs))
1100                 return;
1101         ia64_psr(regs)->ss = 0;
1102 }
1103
1104 /*
1105  * kdba_enable_lbr
1106  *
1107  *      Enable last branch recording.
1108  *
1109  * Parameters:
1110  *      None.
1111  * Returns:
1112  *      None
1113  * Locking:
1114  *      None
1115  * Remarks:
1116  *      None.
1117  */
1118
1119 void
1120 kdba_enable_lbr(void)
1121 {
1122 }
1123
1124 /*
1125  * kdba_disable_lbr
1126  *
1127  *      disable last branch recording.
1128  *
1129  * Parameters:
1130  *      None.
1131  * Returns:
1132  *      None
1133  * Locking:
1134  *      None
1135  * Remarks:
1136  *      None.
1137  */
1138
1139 void
1140 kdba_disable_lbr(void)
1141 {
1142 }
1143
1144 /*
1145  * kdba_print_lbr
1146  *
1147  *      Print last branch and last exception addresses
1148  *
1149  * Parameters:
1150  *      None.
1151  * Returns:
1152  *      None
1153  * Locking:
1154  *      None
1155  * Remarks:
1156  *      None.
1157  */
1158
1159 void
1160 kdba_print_lbr(void)
1161 {
1162 }
1163 /*
1164  * kdb_tpa
1165  *
1166  *      Virtual to Physical address translation command.
1167  *
1168  *      tpa  <addr>
1169  *
1170  * Parameters:
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
1175  * Outputs:
1176  *      None.
1177  * Returns:
1178  *      Zero for success, a kdb diagnostic if failure.
1179  * Locking:
1180  *      None.
1181  * Remarks:
1182  */
1183 #define __xtpa(x)               ({ia64_va _v; asm("tpa %0=%1" : "=r"(_v.l) : "r"(x)); _v.l;})
1184 static int
1185 kdba_tpa(int argc, const char **argv, const char **envp, struct pt_regs* regs)
1186 {
1187         kdb_machreg_t addr;
1188         int diag;
1189         long offset = 0;
1190         int nextarg;
1191         char c;
1192
1193         nextarg = 1;
1194         if (argc != 1)
1195                 return KDB_ARGCOUNT;
1196         diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs);
1197         if (diag)
1198                 return diag;
1199         if (kdb_getarea(c, addr))
1200                 return(0);
1201         kdb_printf("vaddr: 0x%lx , paddr: 0x%lx\n", addr, __xtpa(addr));
1202         return(0);
1203 }
1204 #if defined(CONFIG_NUMA)
1205 static int
1206 kdba_tpav(int argc, const char **argv, const char **envp, struct pt_regs* regs)
1207 {
1208         kdb_machreg_t addr, end, paddr;
1209         int diag;
1210         long offset = 0;
1211         int nextarg, nid, nid_old;
1212         char c;
1213
1214         nextarg = 1;
1215         if (argc != 2)
1216                 return KDB_ARGCOUNT;
1217         diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs);
1218         if (diag)
1219                 return diag;
1220         diag = kdbgetaddrarg(argc, argv, &nextarg, &end, &offset, NULL, regs);
1221         if (diag)
1222                 return diag;
1223         if (kdb_getarea(c, addr))
1224                 return(0);
1225         if (kdb_getarea(c, end))
1226                 return(0);
1227         paddr=__xtpa(addr);
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) {
1231                 nid_old=nid;
1232                 paddr =__xtpa(addr);
1233                 nid = paddr_to_nid(paddr);
1234                 if (nid != nid_old)
1235                         kdb_printf("NOT on same NODE: addr: 0x%lx , paddr: 0x%lx , nid: %d\n", addr, paddr, nid);
1236         }
1237         paddr=__xtpa(end);
1238         nid=paddr_to_nid(end);
1239         kdb_printf("end: 0x%lx , paddr: 0x%lx , nid: %d\n", end, paddr, nid);
1240         return(0);
1241 }
1242 #endif
1243
1244 #if defined(CONFIG_SMP)
1245 /*
1246  * kdba_sendinit
1247  *
1248  *      This function implements the 'init' command.
1249  *
1250  *      init    [<cpunum>]
1251  *
1252  * Inputs:
1253  *      argc    argument count
1254  *      argv    argument vector
1255  *      envp    environment vector
1256  *      regs    registers at time kdb was entered.
1257  * Outputs:
1258  *      None.
1259  * Returns:
1260  *      zero for success, a kdb diagnostic if error
1261  * Locking:
1262  *      none.
1263  * Remarks:
1264  */
1265
1266 static int
1267 kdba_sendinit(int argc, const char **argv, const char **envp, struct pt_regs *regs)
1268 {
1269         unsigned long cpunum;
1270         int diag;
1271
1272         if (argc != 1)
1273                 return KDB_ARGCOUNT;
1274
1275         diag = kdbgetularg(argv[1], &cpunum);
1276         if (diag)
1277                 return diag;
1278
1279         if (cpunum >= NR_CPUS || !cpu_online(cpunum))
1280                 return KDB_BADCPUNUM;
1281
1282         platform_send_ipi(cpunum, 0, IA64_IPI_DM_INIT, 0);
1283         return 0;
1284 }
1285 #endif /* CONFIG_SMP */
1286
1287 /*
1288  * kdba_init
1289  *
1290  *      Architecture specific initialization.
1291  *
1292  * Parameters:
1293  *      None.
1294  * Returns:
1295  *      None.
1296  * Locking:
1297  *      None.
1298  * Remarks:
1299  *      None.
1300  */
1301
1302 void
1303 kdba_init(void)
1304 {
1305         kdba_enable_lbr();
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);
1310 #endif
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);
1316 #endif
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);
1319
1320 #ifdef CONFIG_SERIAL_8250_CONSOLE
1321         kdba_serial_console = KDBA_SC_STANDARD;
1322 #endif
1323 #ifdef CONFIG_SERIAL_SGI_L1_CONSOLE
1324         if (ia64_platform_is("sn2"))
1325                 kdba_serial_console = KDBA_SC_SGI_L1;
1326 #endif
1327         return;
1328 }
1329
1330 /*
1331  * kdba_adjust_ip
1332  *
1333  *      Architecture specific adjustment of instruction pointer before leaving
1334  *      kdb.
1335  *
1336  * Parameters:
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
1341  *                      always be valid.
1342  * Returns:
1343  *      None.
1344  * Locking:
1345  *      None.
1346  * Remarks:
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
1349  *      get a loop.
1350  */
1351
1352 void
1353 kdba_adjust_ip(kdb_reason_t reason, int error, struct pt_regs *regs)
1354 {
1355         if (reason == KDB_REASON_ENTER &&
1356             !KDB_STATE(IP_ADJUSTED)) {
1357                 if (KDB_NULL_REGS(regs))
1358                         return;
1359                 if (ia64_psr(regs)->ri < 2)
1360                         kdba_setpc(regs, regs->cr_iip + ia64_psr(regs)->ri + 1);
1361                 else
1362                         kdba_setpc(regs, regs->cr_iip + 16);
1363         }
1364 }