2 * Routines providing a simple monitor for use on the PowerMac.
4 * Copyright (C) 1996-2005 Paul Mackerras.
5 * Copyright (C) 2001 PPC64 Team, IBM Corp
6 * Copyrignt (C) 2006 Michael Ellerman, IBM Corp
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
14 #include <linux/kernel.h>
15 #include <linux/errno.h>
16 #include <linux/sched.h>
17 #include <linux/smp.h>
19 #include <linux/reboot.h>
20 #include <linux/delay.h>
21 #include <linux/kallsyms.h>
22 #include <linux/kmsg_dump.h>
23 #include <linux/cpumask.h>
24 #include <linux/export.h>
25 #include <linux/sysrq.h>
26 #include <linux/interrupt.h>
27 #include <linux/irq.h>
28 #include <linux/bug.h>
29 #include <linux/nmi.h>
30 #include <linux/ctype.h>
32 #include <asm/ptrace.h>
33 #include <asm/string.h>
35 #include <asm/machdep.h>
37 #include <asm/processor.h>
38 #include <asm/pgtable.h>
40 #include <asm/mmu_context.h>
41 #include <asm/cputable.h>
43 #include <asm/sstep.h>
44 #include <asm/irq_regs.h>
46 #include <asm/spu_priv1.h>
47 #include <asm/setjmp.h>
49 #include <asm/debug.h>
50 #include <asm/hw_breakpoint.h>
53 #include <asm/firmware.h>
56 #include <asm/hvcall.h>
60 #if defined(CONFIG_PPC_SPLPAR)
61 #include <asm/plpar_wrappers.h>
63 static inline long plapr_set_ciabr(unsigned long ciabr
) {return 0; };
70 static cpumask_t cpus_in_xmon
= CPU_MASK_NONE
;
71 static unsigned long xmon_taken
= 1;
72 static int xmon_owner
;
76 #endif /* CONFIG_SMP */
78 static unsigned long in_xmon __read_mostly
= 0;
80 static unsigned long adrs
;
82 #define MAX_DUMP (128 * 1024)
83 static unsigned long ndump
= 64;
84 static unsigned long nidump
= 16;
85 static unsigned long ncsum
= 4096;
87 static char tmpstr
[128];
89 static long bus_error_jmp
[JMP_BUF_LEN
];
90 static int catch_memory_errors
;
91 static int catch_spr_faults
;
92 static long *xmon_fault_jmp
[NR_CPUS
];
94 /* Breakpoint stuff */
96 unsigned long address
;
97 unsigned int instr
[2];
103 /* Bits in bpt.enabled */
109 static struct bpt bpts
[NBPTS
];
110 static struct bpt dabr
;
111 static struct bpt
*iabr
;
112 static unsigned bpinstr
= 0x7fe00008; /* trap */
114 #define BP_NUM(bp) ((bp) - bpts + 1)
117 static int cmds(struct pt_regs
*);
118 static int mread(unsigned long, void *, int);
119 static int mwrite(unsigned long, void *, int);
120 static int handle_fault(struct pt_regs
*);
121 static void byterev(unsigned char *, int);
122 static void memex(void);
123 static int bsesc(void);
124 static void dump(void);
125 static void prdump(unsigned long, long);
126 static int ppc_inst_dump(unsigned long, long, int);
127 static void dump_log_buf(void);
129 #ifdef CONFIG_PPC_POWERNV
130 static void dump_opal_msglog(void);
132 static inline void dump_opal_msglog(void)
134 printf("Machine is not running OPAL firmware.\n");
138 static void backtrace(struct pt_regs
*);
139 static void excprint(struct pt_regs
*);
140 static void prregs(struct pt_regs
*);
141 static void memops(int);
142 static void memlocate(void);
143 static void memzcan(void);
144 static void memdiffs(unsigned char *, unsigned char *, unsigned, unsigned);
146 int scanhex(unsigned long *valp
);
147 static void scannl(void);
148 static int hexdigit(int);
149 void getstring(char *, int);
150 static void flush_input(void);
151 static int inchar(void);
152 static void take_input(char *);
153 static int read_spr(int, unsigned long *);
154 static void write_spr(int, unsigned long);
155 static void super_regs(void);
156 static void remove_bpts(void);
157 static void insert_bpts(void);
158 static void remove_cpu_bpts(void);
159 static void insert_cpu_bpts(void);
160 static struct bpt
*at_breakpoint(unsigned long pc
);
161 static struct bpt
*in_breakpoint_table(unsigned long pc
, unsigned long *offp
);
162 static int do_step(struct pt_regs
*);
163 static void bpt_cmds(void);
164 static void cacheflush(void);
165 static int cpu_cmd(void);
166 static void csum(void);
167 static void bootcmds(void);
168 static void proccall(void);
169 static void show_tasks(void);
170 void dump_segments(void);
171 static void symbol_lookup(void);
172 static void xmon_show_stack(unsigned long sp
, unsigned long lr
,
174 static void xmon_print_symbol(unsigned long address
, const char *mid
,
176 static const char *getvecname(unsigned long vec
);
178 static int do_spu_cmd(void);
181 static void dump_tlb_44x(void);
183 #ifdef CONFIG_PPC_BOOK3E
184 static void dump_tlb_book3e(void);
187 static int xmon_no_auto_backtrace
;
195 #ifdef __LITTLE_ENDIAN__
196 #define GETWORD(v) (((v)[3] << 24) + ((v)[2] << 16) + ((v)[1] << 8) + (v)[0])
198 #define GETWORD(v) (((v)[0] << 24) + ((v)[1] << 16) + ((v)[2] << 8) + (v)[3])
201 static char *help_string
= "\
203 b show breakpoints\n\
204 bd set data breakpoint\n\
205 bi set instruction breakpoint\n\
206 bc clear breakpoint\n"
209 c print cpus stopped in xmon\n\
210 c# try to switch to cpu number h (in hex)\n"
215 di dump instructions\n\
216 df dump float values\n\
217 dd dump double values\n\
218 dl dump the kernel log buffer\n"
219 #ifdef CONFIG_PPC_POWERNV
221 do dump the OPAL message log\n"
225 dp[#] dump paca for current cpu, or cpu #\n\
226 dpa dump paca for all possible cpus\n"
229 dr dump stream of raw bytes\n\
230 dt dump the tracing buffers (uses printk)\n\
231 e print exception information\n\
233 la lookup symbol+offset of specified address\n\
234 ls lookup address of specified symbol\n\
235 m examine/change memory\n\
236 mm move a block of memory\n\
237 ms set a block of memory\n\
238 md compare two blocks of memory\n\
239 ml locate a block of memory\n\
240 mz zero a block of memory\n\
241 mi show information about memory allocation\n\
242 p call a procedure\n\
243 P list processes/tasks\n\
246 #ifdef CONFIG_SPU_BASE
247 " ss stop execution on all spus\n\
248 sr restore execution on stopped spus\n\
249 sf # dump spu fields for spu # (in hex)\n\
250 sd # dump spu local store for spu # (in hex)\n\
251 sdi # disassemble spu local store for spu # (in hex)\n"
253 " S print special registers\n\
256 Sw #v write v to SPR #\n\
258 x exit monitor and recover\n\
259 X exit monitor and don't recover\n"
260 #if defined(CONFIG_PPC64) && !defined(CONFIG_PPC_BOOK3E)
261 " u dump segment table or SLB\n"
262 #elif defined(CONFIG_PPC_STD_MMU_32)
263 " u dump segment registers\n"
264 #elif defined(CONFIG_44x) || defined(CONFIG_PPC_BOOK3E)
268 " # n limit output to n lines per page (for dp, dpa, dl)\n"
273 static struct pt_regs
*xmon_regs
;
275 static inline void sync(void)
277 asm volatile("sync; isync");
280 static inline void store_inst(void *p
)
282 asm volatile ("dcbst 0,%0; sync; icbi 0,%0; isync" : : "r" (p
));
285 static inline void cflush(void *p
)
287 asm volatile ("dcbf 0,%0; icbi 0,%0" : : "r" (p
));
290 static inline void cinval(void *p
)
292 asm volatile ("dcbi 0,%0; icbi 0,%0" : : "r" (p
));
296 * write_ciabr() - write the CIABR SPR
297 * @ciabr: The value to write.
299 * This function writes a value to the CIARB register either directly
300 * through mtspr instruction if the kernel is in HV privilege mode or
301 * call a hypervisor function to achieve the same in case the kernel
302 * is in supervisor privilege mode.
304 static void write_ciabr(unsigned long ciabr
)
306 if (!cpu_has_feature(CPU_FTR_ARCH_207S
))
309 if (cpu_has_feature(CPU_FTR_HVMODE
)) {
310 mtspr(SPRN_CIABR
, ciabr
);
313 plapr_set_ciabr(ciabr
);
317 * set_ciabr() - set the CIABR
318 * @addr: The value to set.
320 * This function sets the correct privilege value into the the HW
321 * breakpoint address before writing it up in the CIABR register.
323 static void set_ciabr(unsigned long addr
)
327 if (cpu_has_feature(CPU_FTR_HVMODE
))
328 addr
|= CIABR_PRIV_HYPER
;
330 addr
|= CIABR_PRIV_SUPER
;
335 * Disable surveillance (the service processor watchdog function)
336 * while we are in xmon.
337 * XXX we should re-enable it when we leave. :)
339 #define SURVEILLANCE_TOKEN 9000
341 static inline void disable_surveillance(void)
343 #ifdef CONFIG_PPC_PSERIES
344 /* Since this can't be a module, args should end up below 4GB. */
345 static struct rtas_args args
;
349 * At this point we have got all the cpus we can into
350 * xmon, so there is hopefully no other cpu calling RTAS
351 * at the moment, even though we don't take rtas.lock.
352 * If we did try to take rtas.lock there would be a
353 * real possibility of deadlock.
355 token
= rtas_token("set-indicator");
356 if (token
== RTAS_UNKNOWN_SERVICE
)
359 rtas_call_unlocked(&args
, token
, 3, 1, NULL
, SURVEILLANCE_TOKEN
, 0, 0);
361 #endif /* CONFIG_PPC_PSERIES */
365 static int xmon_speaker
;
367 static void get_output_lock(void)
369 int me
= smp_processor_id() + 0x100;
370 int last_speaker
= 0, prev
;
373 if (xmon_speaker
== me
)
377 last_speaker
= cmpxchg(&xmon_speaker
, 0, me
);
378 if (last_speaker
== 0)
382 * Wait a full second for the lock, we might be on a slow
383 * console, but check every 100us.
386 while (xmon_speaker
== last_speaker
) {
392 /* hostile takeover */
393 prev
= cmpxchg(&xmon_speaker
, last_speaker
, me
);
394 if (prev
== last_speaker
)
401 static void release_output_lock(void)
406 int cpus_are_in_xmon(void)
408 return !cpumask_empty(&cpus_in_xmon
);
412 static inline int unrecoverable_excp(struct pt_regs
*regs
)
414 #if defined(CONFIG_4xx) || defined(CONFIG_PPC_BOOK3E)
415 /* We have no MSR_RI bit on 4xx or Book3e, so we simply return false */
418 return ((regs
->msr
& MSR_RI
) == 0);
422 static int xmon_core(struct pt_regs
*regs
, int fromipi
)
426 long recurse_jmp
[JMP_BUF_LEN
];
427 unsigned long offset
;
432 unsigned long timeout
;
435 local_irq_save(flags
);
438 bp
= in_breakpoint_table(regs
->nip
, &offset
);
440 regs
->nip
= bp
->address
+ offset
;
441 atomic_dec(&bp
->ref_count
);
447 cpu
= smp_processor_id();
448 if (cpumask_test_cpu(cpu
, &cpus_in_xmon
)) {
450 * We catch SPR read/write faults here because the 0x700, 0xf60
451 * etc. handlers don't call debugger_fault_handler().
453 if (catch_spr_faults
)
454 longjmp(bus_error_jmp
, 1);
457 printf("cpu 0x%x: Exception %lx %s in xmon, "
458 "returning to main loop\n",
459 cpu
, regs
->trap
, getvecname(TRAP(regs
)));
460 release_output_lock();
461 longjmp(xmon_fault_jmp
[cpu
], 1);
464 if (setjmp(recurse_jmp
) != 0) {
465 if (!in_xmon
|| !xmon_gate
) {
467 printf("xmon: WARNING: bad recursive fault "
468 "on cpu 0x%x\n", cpu
);
469 release_output_lock();
472 secondary
= !(xmon_taken
&& cpu
== xmon_owner
);
476 xmon_fault_jmp
[cpu
] = recurse_jmp
;
479 if ((regs
->msr
& (MSR_IR
|MSR_PR
|MSR_64BIT
)) == (MSR_IR
|MSR_64BIT
))
480 bp
= at_breakpoint(regs
->nip
);
481 if (bp
|| unrecoverable_excp(regs
))
488 printf("cpu 0x%x stopped at breakpoint 0x%lx (",
490 xmon_print_symbol(regs
->nip
, " ", ")\n");
492 if (unrecoverable_excp(regs
))
493 printf("WARNING: exception is not recoverable, "
495 release_output_lock();
498 cpumask_set_cpu(cpu
, &cpus_in_xmon
);
502 while (secondary
&& !xmon_gate
) {
506 secondary
= test_and_set_bit(0, &in_xmon
);
511 if (!secondary
&& !xmon_gate
) {
512 /* we are the first cpu to come in */
513 /* interrupt other cpu(s) */
514 int ncpus
= num_online_cpus();
519 smp_send_debugger_break();
520 /* wait for other cpus to come in */
521 for (timeout
= 100000000; timeout
!= 0; --timeout
) {
522 if (cpumask_weight(&cpus_in_xmon
) >= ncpus
)
528 disable_surveillance();
529 /* for breakpoint or single step, print the current instr. */
530 if (bp
|| TRAP(regs
) == 0xd00)
531 ppc_inst_dump(regs
->nip
, 1, 0);
532 printf("enter ? for help\n");
541 if (cpu
== xmon_owner
) {
542 if (!test_and_set_bit(0, &xmon_taken
)) {
547 while (cpu
== xmon_owner
)
561 /* have switched to some other cpu */
566 cpumask_clear_cpu(cpu
, &cpus_in_xmon
);
567 xmon_fault_jmp
[cpu
] = NULL
;
569 /* UP is simple... */
571 printf("Exception %lx %s in xmon, returning to main loop\n",
572 regs
->trap
, getvecname(TRAP(regs
)));
573 longjmp(xmon_fault_jmp
[0], 1);
575 if (setjmp(recurse_jmp
) == 0) {
576 xmon_fault_jmp
[0] = recurse_jmp
;
580 bp
= at_breakpoint(regs
->nip
);
582 printf("Stopped at breakpoint %lx (", BP_NUM(bp
));
583 xmon_print_symbol(regs
->nip
, " ", ")\n");
585 if (unrecoverable_excp(regs
))
586 printf("WARNING: exception is not recoverable, "
589 disable_surveillance();
590 /* for breakpoint or single step, print the current instr. */
591 if (bp
|| TRAP(regs
) == 0xd00)
592 ppc_inst_dump(regs
->nip
, 1, 0);
593 printf("enter ? for help\n");
603 if (regs
->msr
& MSR_DE
) {
604 bp
= at_breakpoint(regs
->nip
);
606 regs
->nip
= (unsigned long) &bp
->instr
[0];
607 atomic_inc(&bp
->ref_count
);
611 if ((regs
->msr
& (MSR_IR
|MSR_PR
|MSR_64BIT
)) == (MSR_IR
|MSR_64BIT
)) {
612 bp
= at_breakpoint(regs
->nip
);
614 int stepped
= emulate_step(regs
, bp
->instr
[0]);
616 regs
->nip
= (unsigned long) &bp
->instr
[0];
617 atomic_inc(&bp
->ref_count
);
618 } else if (stepped
< 0) {
619 printf("Couldn't single-step %s instruction\n",
620 (IS_RFID(bp
->instr
[0])? "rfid": "mtmsrd"));
627 touch_nmi_watchdog();
628 local_irq_restore(flags
);
630 return cmd
!= 'X' && cmd
!= EOF
;
633 int xmon(struct pt_regs
*excp
)
638 ppc_save_regs(®s
);
642 return xmon_core(excp
, 0);
646 irqreturn_t
xmon_irq(int irq
, void *d
)
649 local_irq_save(flags
);
650 printf("Keyboard interrupt\n");
651 xmon(get_irq_regs());
652 local_irq_restore(flags
);
656 static int xmon_bpt(struct pt_regs
*regs
)
659 unsigned long offset
;
661 if ((regs
->msr
& (MSR_IR
|MSR_PR
|MSR_64BIT
)) != (MSR_IR
|MSR_64BIT
))
664 /* Are we at the trap at bp->instr[1] for some bp? */
665 bp
= in_breakpoint_table(regs
->nip
, &offset
);
666 if (bp
!= NULL
&& offset
== 4) {
667 regs
->nip
= bp
->address
+ 4;
668 atomic_dec(&bp
->ref_count
);
672 /* Are we at a breakpoint? */
673 bp
= at_breakpoint(regs
->nip
);
682 static int xmon_sstep(struct pt_regs
*regs
)
690 static int xmon_break_match(struct pt_regs
*regs
)
692 if ((regs
->msr
& (MSR_IR
|MSR_PR
|MSR_64BIT
)) != (MSR_IR
|MSR_64BIT
))
694 if (dabr
.enabled
== 0)
700 static int xmon_iabr_match(struct pt_regs
*regs
)
702 if ((regs
->msr
& (MSR_IR
|MSR_PR
|MSR_64BIT
)) != (MSR_IR
|MSR_64BIT
))
710 static int xmon_ipi(struct pt_regs
*regs
)
713 if (in_xmon
&& !cpumask_test_cpu(smp_processor_id(), &cpus_in_xmon
))
719 static int xmon_fault_handler(struct pt_regs
*regs
)
722 unsigned long offset
;
724 if (in_xmon
&& catch_memory_errors
)
725 handle_fault(regs
); /* doesn't return */
727 if ((regs
->msr
& (MSR_IR
|MSR_PR
|MSR_64BIT
)) == (MSR_IR
|MSR_64BIT
)) {
728 bp
= in_breakpoint_table(regs
->nip
, &offset
);
730 regs
->nip
= bp
->address
+ offset
;
731 atomic_dec(&bp
->ref_count
);
738 static struct bpt
*at_breakpoint(unsigned long pc
)
744 for (i
= 0; i
< NBPTS
; ++i
, ++bp
)
745 if (bp
->enabled
&& pc
== bp
->address
)
750 static struct bpt
*in_breakpoint_table(unsigned long nip
, unsigned long *offp
)
754 off
= nip
- (unsigned long) bpts
;
755 if (off
>= sizeof(bpts
))
757 off
%= sizeof(struct bpt
);
758 if (off
!= offsetof(struct bpt
, instr
[0])
759 && off
!= offsetof(struct bpt
, instr
[1]))
761 *offp
= off
- offsetof(struct bpt
, instr
[0]);
762 return (struct bpt
*) (nip
- off
);
765 static struct bpt
*new_breakpoint(unsigned long a
)
770 bp
= at_breakpoint(a
);
774 for (bp
= bpts
; bp
< &bpts
[NBPTS
]; ++bp
) {
775 if (!bp
->enabled
&& atomic_read(&bp
->ref_count
) == 0) {
777 bp
->instr
[1] = bpinstr
;
778 store_inst(&bp
->instr
[1]);
783 printf("Sorry, no free breakpoints. Please clear one first.\n");
787 static void insert_bpts(void)
793 for (i
= 0; i
< NBPTS
; ++i
, ++bp
) {
794 if ((bp
->enabled
& (BP_TRAP
|BP_CIABR
)) == 0)
796 if (mread(bp
->address
, &bp
->instr
[0], 4) != 4) {
797 printf("Couldn't read instruction at %lx, "
798 "disabling breakpoint there\n", bp
->address
);
802 if (IS_MTMSRD(bp
->instr
[0]) || IS_RFID(bp
->instr
[0])) {
803 printf("Breakpoint at %lx is on an mtmsrd or rfid "
804 "instruction, disabling it\n", bp
->address
);
808 store_inst(&bp
->instr
[0]);
809 if (bp
->enabled
& BP_CIABR
)
811 if (mwrite(bp
->address
, &bpinstr
, 4) != 4) {
812 printf("Couldn't write instruction at %lx, "
813 "disabling breakpoint there\n", bp
->address
);
814 bp
->enabled
&= ~BP_TRAP
;
817 store_inst((void *)bp
->address
);
821 static void insert_cpu_bpts(void)
823 struct arch_hw_breakpoint brk
;
826 brk
.address
= dabr
.address
;
827 brk
.type
= (dabr
.enabled
& HW_BRK_TYPE_DABR
) | HW_BRK_TYPE_PRIV_ALL
;
829 __set_breakpoint(&brk
);
833 set_ciabr(iabr
->address
);
836 static void remove_bpts(void)
843 for (i
= 0; i
< NBPTS
; ++i
, ++bp
) {
844 if ((bp
->enabled
& (BP_TRAP
|BP_CIABR
)) != BP_TRAP
)
846 if (mread(bp
->address
, &instr
, 4) == 4
848 && mwrite(bp
->address
, &bp
->instr
, 4) != 4)
849 printf("Couldn't remove breakpoint at %lx\n",
852 store_inst((void *)bp
->address
);
856 static void remove_cpu_bpts(void)
858 hw_breakpoint_disable();
862 static void set_lpp_cmd(void)
866 if (!scanhex(&lpp
)) {
867 printf("Invalid number.\n");
870 xmon_set_pagination_lpp(lpp
);
872 /* Command interpreting routine */
873 static char *last_cmd
;
876 cmds(struct pt_regs
*excp
)
883 if (!xmon_no_auto_backtrace
) {
884 xmon_no_auto_backtrace
= 1;
885 xmon_show_stack(excp
->gpr
[1], excp
->link
, excp
->nip
);
890 printf("%x:", smp_processor_id());
891 #endif /* CONFIG_SMP */
897 if (last_cmd
== NULL
)
899 take_input(last_cmd
);
933 prregs(excp
); /* print regs */
948 if (do_spu_cmd() == 0)
957 printf(" <no input ...>\n");
961 xmon_puts(help_string
);
985 #ifdef CONFIG_PPC_STD_MMU
989 #elif defined(CONFIG_44x)
993 #elif defined(CONFIG_PPC_BOOK3E)
999 printf("Unrecognized command: ");
1001 if (' ' < cmd
&& cmd
<= '~')
1004 printf("\\x%x", cmd
);
1006 } while (cmd
!= '\n');
1007 printf(" (type ? for help)\n");
1014 static int do_step(struct pt_regs
*regs
)
1016 regs
->msr
|= MSR_DE
;
1017 mtspr(SPRN_DBCR0
, mfspr(SPRN_DBCR0
) | DBCR0_IC
| DBCR0_IDM
);
1022 * Step a single instruction.
1023 * Some instructions we emulate, others we execute with MSR_SE set.
1025 static int do_step(struct pt_regs
*regs
)
1030 /* check we are in 64-bit kernel mode, translation enabled */
1031 if ((regs
->msr
& (MSR_64BIT
|MSR_PR
|MSR_IR
)) == (MSR_64BIT
|MSR_IR
)) {
1032 if (mread(regs
->nip
, &instr
, 4) == 4) {
1033 stepped
= emulate_step(regs
, instr
);
1035 printf("Couldn't single-step %s instruction\n",
1036 (IS_RFID(instr
)? "rfid": "mtmsrd"));
1040 regs
->trap
= 0xd00 | (regs
->trap
& 1);
1041 printf("stepped to ");
1042 xmon_print_symbol(regs
->nip
, " ", "\n");
1043 ppc_inst_dump(regs
->nip
, 1, 0);
1048 regs
->msr
|= MSR_SE
;
1053 static void bootcmds(void)
1059 ppc_md
.restart(NULL
);
1060 else if (cmd
== 'h')
1062 else if (cmd
== 'p')
1067 static int cpu_cmd(void)
1070 unsigned long cpu
, first_cpu
, last_cpu
;
1073 if (!scanhex(&cpu
)) {
1074 /* print cpus waiting or in xmon */
1075 printf("cpus stopped:");
1076 last_cpu
= first_cpu
= NR_CPUS
;
1077 for_each_possible_cpu(cpu
) {
1078 if (cpumask_test_cpu(cpu
, &cpus_in_xmon
)) {
1079 if (cpu
== last_cpu
+ 1) {
1082 if (last_cpu
!= first_cpu
)
1083 printf("-0x%lx", last_cpu
);
1084 last_cpu
= first_cpu
= cpu
;
1085 printf(" 0x%lx", cpu
);
1089 if (last_cpu
!= first_cpu
)
1090 printf("-0x%lx", last_cpu
);
1094 /* try to switch to cpu specified */
1095 if (!cpumask_test_cpu(cpu
, &cpus_in_xmon
)) {
1096 printf("cpu 0x%x isn't in xmon\n", cpu
);
1103 while (!xmon_taken
) {
1104 if (--timeout
== 0) {
1105 if (test_and_set_bit(0, &xmon_taken
))
1107 /* take control back */
1109 xmon_owner
= smp_processor_id();
1110 printf("cpu 0x%x didn't take control\n", cpu
);
1118 #endif /* CONFIG_SMP */
1121 static unsigned short fcstab
[256] = {
1122 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
1123 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
1124 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
1125 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
1126 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
1127 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
1128 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
1129 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
1130 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
1131 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
1132 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
1133 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
1134 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
1135 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
1136 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
1137 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
1138 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
1139 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
1140 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
1141 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
1142 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
1143 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
1144 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
1145 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
1146 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
1147 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
1148 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
1149 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
1150 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
1151 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
1152 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
1153 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
1156 #define FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
1165 if (!scanhex(&adrs
))
1167 if (!scanhex(&ncsum
))
1170 for (i
= 0; i
< ncsum
; ++i
) {
1171 if (mread(adrs
+i
, &v
, 1) == 0) {
1172 printf("csum stopped at "REG
"\n", adrs
+i
);
1177 printf("%x\n", fcs
);
1181 * Check if this is a suitable place to put a breakpoint.
1183 static long check_bp_loc(unsigned long addr
)
1188 if (!is_kernel_addr(addr
)) {
1189 printf("Breakpoints may only be placed at kernel addresses\n");
1192 if (!mread(addr
, &instr
, sizeof(instr
))) {
1193 printf("Can't read instruction at address %lx\n", addr
);
1196 if (IS_MTMSRD(instr
) || IS_RFID(instr
)) {
1197 printf("Breakpoints may not be placed on mtmsrd or rfid "
1204 static char *breakpoint_help_string
=
1205 "Breakpoint command usage:\n"
1206 "b show breakpoints\n"
1207 "b <addr> [cnt] set breakpoint at given instr addr\n"
1208 "bc clear all breakpoints\n"
1209 "bc <n/addr> clear breakpoint number n or at addr\n"
1210 "bi <addr> [cnt] set hardware instr breakpoint (POWER8 only)\n"
1211 "bd <addr> [cnt] set hardware data breakpoint\n"
1221 const char badaddr
[] = "Only kernel addresses are permitted "
1222 "for breakpoints\n";
1227 case 'd': /* bd - hardware data breakpoint */
1232 else if (cmd
== 'w')
1238 if (scanhex(&dabr
.address
)) {
1239 if (!is_kernel_addr(dabr
.address
)) {
1243 dabr
.address
&= ~HW_BRK_TYPE_DABR
;
1244 dabr
.enabled
= mode
| BP_DABR
;
1248 case 'i': /* bi - hardware instr breakpoint */
1249 if (!cpu_has_feature(CPU_FTR_ARCH_207S
)) {
1250 printf("Hardware instruction breakpoint "
1251 "not supported on this cpu\n");
1255 iabr
->enabled
&= ~BP_CIABR
;
1260 if (!check_bp_loc(a
))
1262 bp
= new_breakpoint(a
);
1264 bp
->enabled
|= BP_CIABR
;
1272 /* clear all breakpoints */
1273 for (i
= 0; i
< NBPTS
; ++i
)
1274 bpts
[i
].enabled
= 0;
1277 printf("All breakpoints cleared\n");
1281 if (a
<= NBPTS
&& a
>= 1) {
1282 /* assume a breakpoint number */
1283 bp
= &bpts
[a
-1]; /* bp nums are 1 based */
1285 /* assume a breakpoint address */
1286 bp
= at_breakpoint(a
);
1288 printf("No breakpoint at %lx\n", a
);
1293 printf("Cleared breakpoint %lx (", BP_NUM(bp
));
1294 xmon_print_symbol(bp
->address
, " ", ")\n");
1302 printf(breakpoint_help_string
);
1307 /* print all breakpoints */
1308 printf(" type address\n");
1310 printf(" data "REG
" [", dabr
.address
);
1311 if (dabr
.enabled
& 1)
1313 if (dabr
.enabled
& 2)
1317 for (bp
= bpts
; bp
< &bpts
[NBPTS
]; ++bp
) {
1320 printf("%2x %s ", BP_NUM(bp
),
1321 (bp
->enabled
& BP_CIABR
) ? "inst": "trap");
1322 xmon_print_symbol(bp
->address
, " ", "\n");
1327 if (!check_bp_loc(a
))
1329 bp
= new_breakpoint(a
);
1331 bp
->enabled
|= BP_TRAP
;
1336 /* Very cheap human name for vector lookup. */
1338 const char *getvecname(unsigned long vec
)
1343 case 0x100: ret
= "(System Reset)"; break;
1344 case 0x200: ret
= "(Machine Check)"; break;
1345 case 0x300: ret
= "(Data Access)"; break;
1346 case 0x380: ret
= "(Data SLB Access)"; break;
1347 case 0x400: ret
= "(Instruction Access)"; break;
1348 case 0x480: ret
= "(Instruction SLB Access)"; break;
1349 case 0x500: ret
= "(Hardware Interrupt)"; break;
1350 case 0x600: ret
= "(Alignment)"; break;
1351 case 0x700: ret
= "(Program Check)"; break;
1352 case 0x800: ret
= "(FPU Unavailable)"; break;
1353 case 0x900: ret
= "(Decrementer)"; break;
1354 case 0x980: ret
= "(Hypervisor Decrementer)"; break;
1355 case 0xa00: ret
= "(Doorbell)"; break;
1356 case 0xc00: ret
= "(System Call)"; break;
1357 case 0xd00: ret
= "(Single Step)"; break;
1358 case 0xe40: ret
= "(Emulation Assist)"; break;
1359 case 0xe60: ret
= "(HMI)"; break;
1360 case 0xe80: ret
= "(Hypervisor Doorbell)"; break;
1361 case 0xf00: ret
= "(Performance Monitor)"; break;
1362 case 0xf20: ret
= "(Altivec Unavailable)"; break;
1363 case 0x1300: ret
= "(Instruction Breakpoint)"; break;
1364 case 0x1500: ret
= "(Denormalisation)"; break;
1365 case 0x1700: ret
= "(Altivec Assist)"; break;
1371 static void get_function_bounds(unsigned long pc
, unsigned long *startp
,
1372 unsigned long *endp
)
1374 unsigned long size
, offset
;
1377 *startp
= *endp
= 0;
1380 if (setjmp(bus_error_jmp
) == 0) {
1381 catch_memory_errors
= 1;
1383 name
= kallsyms_lookup(pc
, &size
, &offset
, NULL
, tmpstr
);
1385 *startp
= pc
- offset
;
1386 *endp
= pc
- offset
+ size
;
1390 catch_memory_errors
= 0;
1393 #define LRSAVE_OFFSET (STACK_FRAME_LR_SAVE * sizeof(unsigned long))
1394 #define MARKER_OFFSET (STACK_FRAME_MARKER * sizeof(unsigned long))
1396 static void xmon_show_stack(unsigned long sp
, unsigned long lr
,
1399 int max_to_print
= 64;
1401 unsigned long newsp
;
1402 unsigned long marker
;
1403 struct pt_regs regs
;
1405 while (max_to_print
--) {
1406 if (sp
< PAGE_OFFSET
) {
1408 printf("SP (%lx) is in userspace\n", sp
);
1412 if (!mread(sp
+ LRSAVE_OFFSET
, &ip
, sizeof(unsigned long))
1413 || !mread(sp
, &newsp
, sizeof(unsigned long))) {
1414 printf("Couldn't read stack frame at %lx\n", sp
);
1419 * For the first stack frame, try to work out if
1420 * LR and/or the saved LR value in the bottommost
1421 * stack frame are valid.
1423 if ((pc
| lr
) != 0) {
1424 unsigned long fnstart
, fnend
;
1425 unsigned long nextip
;
1428 get_function_bounds(pc
, &fnstart
, &fnend
);
1431 mread(newsp
+ LRSAVE_OFFSET
, &nextip
,
1432 sizeof(unsigned long));
1434 if (lr
< PAGE_OFFSET
1435 || (fnstart
<= lr
&& lr
< fnend
))
1437 } else if (lr
== nextip
) {
1439 } else if (lr
>= PAGE_OFFSET
1440 && !(fnstart
<= lr
&& lr
< fnend
)) {
1441 printf("[link register ] ");
1442 xmon_print_symbol(lr
, " ", "\n");
1445 printf("["REG
"] ", sp
);
1446 xmon_print_symbol(ip
, " ", " (unreliable)\n");
1451 printf("["REG
"] ", sp
);
1452 xmon_print_symbol(ip
, " ", "\n");
1455 /* Look for "regshere" marker to see if this is
1456 an exception frame. */
1457 if (mread(sp
+ MARKER_OFFSET
, &marker
, sizeof(unsigned long))
1458 && marker
== STACK_FRAME_REGS_MARKER
) {
1459 if (mread(sp
+ STACK_FRAME_OVERHEAD
, ®s
, sizeof(regs
))
1461 printf("Couldn't read registers at %lx\n",
1462 sp
+ STACK_FRAME_OVERHEAD
);
1465 printf("--- Exception: %lx %s at ", regs
.trap
,
1466 getvecname(TRAP(®s
)));
1469 xmon_print_symbol(pc
, " ", "\n");
1479 static void backtrace(struct pt_regs
*excp
)
1484 xmon_show_stack(sp
, 0, 0);
1486 xmon_show_stack(excp
->gpr
[1], excp
->link
, excp
->nip
);
1490 static void print_bug_trap(struct pt_regs
*regs
)
1493 const struct bug_entry
*bug
;
1496 if (regs
->msr
& MSR_PR
)
1497 return; /* not in kernel */
1498 addr
= regs
->nip
; /* address of trap instruction */
1499 if (addr
< PAGE_OFFSET
)
1501 bug
= find_bug(regs
->nip
);
1504 if (is_warning_bug(bug
))
1507 #ifdef CONFIG_DEBUG_BUGVERBOSE
1508 printf("kernel BUG at %s:%u!\n",
1509 bug
->file
, bug
->line
);
1511 printf("kernel BUG at %p!\n", (void *)bug
->bug_addr
);
1513 #endif /* CONFIG_BUG */
1516 static void excprint(struct pt_regs
*fp
)
1521 printf("cpu 0x%x: ", smp_processor_id());
1522 #endif /* CONFIG_SMP */
1525 printf("Vector: %lx %s at [%lx]\n", fp
->trap
, getvecname(trap
), fp
);
1527 xmon_print_symbol(fp
->nip
, ": ", "\n");
1529 printf(" lr: ", fp
->link
);
1530 xmon_print_symbol(fp
->link
, ": ", "\n");
1532 printf(" sp: %lx\n", fp
->gpr
[1]);
1533 printf(" msr: %lx\n", fp
->msr
);
1535 if (trap
== 0x300 || trap
== 0x380 || trap
== 0x600 || trap
== 0x200) {
1536 printf(" dar: %lx\n", fp
->dar
);
1538 printf(" dsisr: %lx\n", fp
->dsisr
);
1541 printf(" current = 0x%lx\n", current
);
1543 printf(" paca = 0x%lx\t softe: %d\t irq_happened: 0x%02x\n",
1544 local_paca
, local_paca
->soft_enabled
, local_paca
->irq_happened
);
1547 printf(" pid = %ld, comm = %s\n",
1548 current
->pid
, current
->comm
);
1554 printf(linux_banner
);
1557 static void prregs(struct pt_regs
*fp
)
1561 struct pt_regs regs
;
1563 if (scanhex(&base
)) {
1564 if (setjmp(bus_error_jmp
) == 0) {
1565 catch_memory_errors
= 1;
1567 regs
= *(struct pt_regs
*)base
;
1571 catch_memory_errors
= 0;
1572 printf("*** Error reading registers from "REG
"\n",
1576 catch_memory_errors
= 0;
1581 if (FULL_REGS(fp
)) {
1582 for (n
= 0; n
< 16; ++n
)
1583 printf("R%.2ld = "REG
" R%.2ld = "REG
"\n",
1584 n
, fp
->gpr
[n
], n
+16, fp
->gpr
[n
+16]);
1586 for (n
= 0; n
< 7; ++n
)
1587 printf("R%.2ld = "REG
" R%.2ld = "REG
"\n",
1588 n
, fp
->gpr
[n
], n
+7, fp
->gpr
[n
+7]);
1591 for (n
= 0; n
< 32; ++n
) {
1592 printf("R%.2d = %.8x%s", n
, fp
->gpr
[n
],
1593 (n
& 3) == 3? "\n": " ");
1594 if (n
== 12 && !FULL_REGS(fp
)) {
1601 xmon_print_symbol(fp
->nip
, " ", "\n");
1602 if (TRAP(fp
) != 0xc00 && cpu_has_feature(CPU_FTR_CFAR
)) {
1604 xmon_print_symbol(fp
->orig_gpr3
, " ", "\n");
1607 xmon_print_symbol(fp
->link
, " ", "\n");
1608 printf("msr = "REG
" cr = %.8lx\n", fp
->msr
, fp
->ccr
);
1609 printf("ctr = "REG
" xer = "REG
" trap = %4lx\n",
1610 fp
->ctr
, fp
->xer
, fp
->trap
);
1612 if (trap
== 0x300 || trap
== 0x380 || trap
== 0x600)
1613 printf("dar = "REG
" dsisr = %.8lx\n", fp
->dar
, fp
->dsisr
);
1616 static void cacheflush(void)
1619 unsigned long nflush
;
1624 scanhex((void *)&adrs
);
1629 nflush
= (nflush
+ L1_CACHE_BYTES
- 1) / L1_CACHE_BYTES
;
1630 if (setjmp(bus_error_jmp
) == 0) {
1631 catch_memory_errors
= 1;
1635 for (; nflush
> 0; --nflush
, adrs
+= L1_CACHE_BYTES
)
1636 cflush((void *) adrs
);
1638 for (; nflush
> 0; --nflush
, adrs
+= L1_CACHE_BYTES
)
1639 cinval((void *) adrs
);
1642 /* wait a little while to see if we get a machine check */
1645 catch_memory_errors
= 0;
1648 extern unsigned long xmon_mfspr(int spr
, unsigned long default_value
);
1649 extern void xmon_mtspr(int spr
, unsigned long value
);
1652 read_spr(int n
, unsigned long *vp
)
1654 unsigned long ret
= -1UL;
1657 if (setjmp(bus_error_jmp
) == 0) {
1658 catch_spr_faults
= 1;
1661 ret
= xmon_mfspr(n
, *vp
);
1667 catch_spr_faults
= 0;
1673 write_spr(int n
, unsigned long val
)
1675 if (setjmp(bus_error_jmp
) == 0) {
1676 catch_spr_faults
= 1;
1683 printf("SPR 0x%03x (%4d) Faulted during write\n", n
, n
);
1685 catch_spr_faults
= 0;
1688 static void dump_206_sprs(void)
1691 if (!cpu_has_feature(CPU_FTR_ARCH_206
))
1694 /* Actually some of these pre-date 2.06, but whatevs */
1696 printf("srr0 = %.16x srr1 = %.16x dsisr = %.8x\n",
1697 mfspr(SPRN_SRR0
), mfspr(SPRN_SRR1
), mfspr(SPRN_DSISR
));
1698 printf("dscr = %.16x ppr = %.16x pir = %.8x\n",
1699 mfspr(SPRN_DSCR
), mfspr(SPRN_PPR
), mfspr(SPRN_PIR
));
1701 if (!(mfmsr() & MSR_HV
))
1704 printf("sdr1 = %.16x hdar = %.16x hdsisr = %.8x\n",
1705 mfspr(SPRN_SDR1
), mfspr(SPRN_HDAR
), mfspr(SPRN_HDSISR
));
1706 printf("hsrr0 = %.16x hsrr1 = %.16x hdec = %.8x\n",
1707 mfspr(SPRN_HSRR0
), mfspr(SPRN_HSRR1
), mfspr(SPRN_HDEC
));
1708 printf("lpcr = %.16x pcr = %.16x lpidr = %.8x\n",
1709 mfspr(SPRN_LPCR
), mfspr(SPRN_PCR
), mfspr(SPRN_LPID
));
1710 printf("hsprg0 = %.16x hsprg1 = %.16x\n",
1711 mfspr(SPRN_HSPRG0
), mfspr(SPRN_HSPRG1
));
1712 printf("dabr = %.16x dabrx = %.16x\n",
1713 mfspr(SPRN_DABR
), mfspr(SPRN_DABRX
));
1717 static void dump_207_sprs(void)
1722 if (!cpu_has_feature(CPU_FTR_ARCH_207S
))
1725 printf("dpdes = %.16x tir = %.16x cir = %.8x\n",
1726 mfspr(SPRN_DPDES
), mfspr(SPRN_TIR
), mfspr(SPRN_CIR
));
1728 printf("fscr = %.16x tar = %.16x pspb = %.8x\n",
1729 mfspr(SPRN_FSCR
), mfspr(SPRN_TAR
), mfspr(SPRN_PSPB
));
1733 /* Only if TM has been enabled in the kernel */
1734 printf("tfhar = %.16x tfiar = %.16x texasr = %.16x\n",
1735 mfspr(SPRN_TFHAR
), mfspr(SPRN_TFIAR
),
1736 mfspr(SPRN_TEXASR
));
1739 printf("mmcr0 = %.16x mmcr1 = %.16x mmcr2 = %.16x\n",
1740 mfspr(SPRN_MMCR0
), mfspr(SPRN_MMCR1
), mfspr(SPRN_MMCR2
));
1741 printf("pmc1 = %.8x pmc2 = %.8x pmc3 = %.8x pmc4 = %.8x\n",
1742 mfspr(SPRN_PMC1
), mfspr(SPRN_PMC2
),
1743 mfspr(SPRN_PMC3
), mfspr(SPRN_PMC4
));
1744 printf("mmcra = %.16x siar = %.16x pmc5 = %.8x\n",
1745 mfspr(SPRN_MMCRA
), mfspr(SPRN_SIAR
), mfspr(SPRN_PMC5
));
1746 printf("sdar = %.16x sier = %.16x pmc6 = %.8x\n",
1747 mfspr(SPRN_SDAR
), mfspr(SPRN_SIER
), mfspr(SPRN_PMC6
));
1748 printf("ebbhr = %.16x ebbrr = %.16x bescr = %.16x\n",
1749 mfspr(SPRN_EBBHR
), mfspr(SPRN_EBBRR
), mfspr(SPRN_BESCR
));
1751 if (!(msr
& MSR_HV
))
1754 printf("hfscr = %.16x dhdes = %.16x rpr = %.16x\n",
1755 mfspr(SPRN_HFSCR
), mfspr(SPRN_DHDES
), mfspr(SPRN_RPR
));
1756 printf("dawr = %.16x dawrx = %.16x ciabr = %.16x\n",
1757 mfspr(SPRN_DAWR
), mfspr(SPRN_DAWRX
), mfspr(SPRN_CIABR
));
1761 static void dump_one_spr(int spr
, bool show_unimplemented
)
1766 if (!read_spr(spr
, &val
)) {
1767 printf("SPR 0x%03x (%4d) Faulted during read\n", spr
, spr
);
1771 if (val
== 0xdeadbeef) {
1772 /* Looks like read was a nop, confirm */
1774 if (!read_spr(spr
, &val
)) {
1775 printf("SPR 0x%03x (%4d) Faulted during read\n", spr
, spr
);
1779 if (val
== 0x0badcafe) {
1780 if (show_unimplemented
)
1781 printf("SPR 0x%03x (%4d) Unimplemented\n", spr
, spr
);
1786 printf("SPR 0x%03x (%4d) = 0x%lx\n", spr
, spr
, val
);
1789 static void super_regs(void)
1791 static unsigned long regno
;
1799 unsigned long sp
, toc
;
1800 asm("mr %0,1" : "=r" (sp
) :);
1801 asm("mr %0,2" : "=r" (toc
) :);
1803 printf("msr = "REG
" sprg0 = "REG
"\n",
1804 mfmsr(), mfspr(SPRN_SPRG0
));
1805 printf("pvr = "REG
" sprg1 = "REG
"\n",
1806 mfspr(SPRN_PVR
), mfspr(SPRN_SPRG1
));
1807 printf("dec = "REG
" sprg2 = "REG
"\n",
1808 mfspr(SPRN_DEC
), mfspr(SPRN_SPRG2
));
1809 printf("sp = "REG
" sprg3 = "REG
"\n", sp
, mfspr(SPRN_SPRG3
));
1810 printf("toc = "REG
" dar = "REG
"\n", toc
, mfspr(SPRN_DAR
));
1821 read_spr(regno
, &val
);
1823 write_spr(regno
, val
);
1824 dump_one_spr(regno
, true);
1829 dump_one_spr(regno
, true);
1833 for (spr
= 1; spr
< 1024; ++spr
)
1834 dump_one_spr(spr
, false);
1842 * Stuff for reading and writing memory safely
1845 mread(unsigned long adrs
, void *buf
, int size
)
1851 if (setjmp(bus_error_jmp
) == 0) {
1852 catch_memory_errors
= 1;
1858 *(u16
*)q
= *(u16
*)p
;
1861 *(u32
*)q
= *(u32
*)p
;
1864 *(u64
*)q
= *(u64
*)p
;
1867 for( ; n
< size
; ++n
) {
1873 /* wait a little while to see if we get a machine check */
1877 catch_memory_errors
= 0;
1882 mwrite(unsigned long adrs
, void *buf
, int size
)
1888 if (setjmp(bus_error_jmp
) == 0) {
1889 catch_memory_errors
= 1;
1895 *(u16
*)p
= *(u16
*)q
;
1898 *(u32
*)p
= *(u32
*)q
;
1901 *(u64
*)p
= *(u64
*)q
;
1904 for ( ; n
< size
; ++n
) {
1910 /* wait a little while to see if we get a machine check */
1914 printf("*** Error writing address "REG
"\n", adrs
+ n
);
1916 catch_memory_errors
= 0;
1920 static int fault_type
;
1921 static int fault_except
;
1922 static char *fault_chars
[] = { "--", "**", "##" };
1924 static int handle_fault(struct pt_regs
*regs
)
1926 fault_except
= TRAP(regs
);
1927 switch (TRAP(regs
)) {
1939 longjmp(bus_error_jmp
, 1);
1944 #define SWAP(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
1947 byterev(unsigned char *val
, int size
)
1953 SWAP(val
[0], val
[1], t
);
1956 SWAP(val
[0], val
[3], t
);
1957 SWAP(val
[1], val
[2], t
);
1959 case 8: /* is there really any use for this? */
1960 SWAP(val
[0], val
[7], t
);
1961 SWAP(val
[1], val
[6], t
);
1962 SWAP(val
[2], val
[5], t
);
1963 SWAP(val
[3], val
[4], t
);
1971 static char *memex_help_string
=
1972 "Memory examine command usage:\n"
1973 "m [addr] [flags] examine/change memory\n"
1974 " addr is optional. will start where left off.\n"
1975 " flags may include chars from this set:\n"
1976 " b modify by bytes (default)\n"
1977 " w modify by words (2 byte)\n"
1978 " l modify by longs (4 byte)\n"
1979 " d modify by doubleword (8 byte)\n"
1980 " r toggle reverse byte order mode\n"
1981 " n do not read memory (for i/o spaces)\n"
1982 " . ok to read (default)\n"
1983 "NOTE: flags are saved as defaults\n"
1986 static char *memex_subcmd_help_string
=
1987 "Memory examine subcommands:\n"
1988 " hexval write this val to current location\n"
1989 " 'string' write chars from string to this location\n"
1990 " ' increment address\n"
1991 " ^ decrement address\n"
1992 " / increment addr by 0x10. //=0x100, ///=0x1000, etc\n"
1993 " \\ decrement addr by 0x10. \\\\=0x100, \\\\\\=0x1000, etc\n"
1994 " ` clear no-read flag\n"
1995 " ; stay at this addr\n"
1996 " v change to byte mode\n"
1997 " w change to word (2 byte) mode\n"
1998 " l change to long (4 byte) mode\n"
1999 " u change to doubleword (8 byte) mode\n"
2000 " m addr change current addr\n"
2001 " n toggle no-read flag\n"
2002 " r toggle byte reverse flag\n"
2003 " < count back up count bytes\n"
2004 " > count skip forward count bytes\n"
2005 " x exit this mode\n"
2011 int cmd
, inc
, i
, nslash
;
2013 unsigned char val
[16];
2015 scanhex((void *)&adrs
);
2018 printf(memex_help_string
);
2024 while ((cmd
= skipbl()) != '\n') {
2026 case 'b': size
= 1; break;
2027 case 'w': size
= 2; break;
2028 case 'l': size
= 4; break;
2029 case 'd': size
= 8; break;
2030 case 'r': brev
= !brev
; break;
2031 case 'n': mnoread
= 1; break;
2032 case '.': mnoread
= 0; break;
2041 n
= mread(adrs
, val
, size
);
2042 printf(REG
"%c", adrs
, brev
? 'r': ' ');
2047 for (i
= 0; i
< n
; ++i
)
2048 printf("%.2x", val
[i
]);
2049 for (; i
< size
; ++i
)
2050 printf("%s", fault_chars
[fault_type
]);
2057 for (i
= 0; i
< size
; ++i
)
2058 val
[i
] = n
>> (i
* 8);
2061 mwrite(adrs
, val
, size
);
2074 else if( n
== '\'' )
2076 for (i
= 0; i
< size
; ++i
)
2077 val
[i
] = n
>> (i
* 8);
2080 mwrite(adrs
, val
, size
);
2116 adrs
-= 1 << nslash
;
2120 adrs
+= 1 << nslash
;
2124 adrs
+= 1 << -nslash
;
2128 adrs
-= 1 << -nslash
;
2131 scanhex((void *)&adrs
);
2150 printf(memex_subcmd_help_string
);
2165 case 'n': c
= '\n'; break;
2166 case 'r': c
= '\r'; break;
2167 case 'b': c
= '\b'; break;
2168 case 't': c
= '\t'; break;
2173 static void xmon_rawdump (unsigned long adrs
, long ndump
)
2176 unsigned char temp
[16];
2178 for (n
= ndump
; n
> 0;) {
2180 nr
= mread(adrs
, temp
, r
);
2182 for (m
= 0; m
< r
; ++m
) {
2184 printf("%.2x", temp
[m
]);
2186 printf("%s", fault_chars
[fault_type
]);
2196 static void dump_one_paca(int cpu
)
2198 struct paca_struct
*p
;
2199 #ifdef CONFIG_PPC_STD_MMU_64
2203 if (setjmp(bus_error_jmp
) != 0) {
2204 printf("*** Error dumping paca for cpu 0x%x!\n", cpu
);
2208 catch_memory_errors
= 1;
2213 printf("paca for cpu 0x%x @ %p:\n", cpu
, p
);
2215 printf(" %-*s = %s\n", 20, "possible", cpu_possible(cpu
) ? "yes" : "no");
2216 printf(" %-*s = %s\n", 20, "present", cpu_present(cpu
) ? "yes" : "no");
2217 printf(" %-*s = %s\n", 20, "online", cpu_online(cpu
) ? "yes" : "no");
2219 #define DUMP(paca, name, format) \
2220 printf(" %-*s = %#-*"format"\t(0x%lx)\n", 20, #name, 18, paca->name, \
2221 offsetof(struct paca_struct, name));
2223 DUMP(p
, lock_token
, "x");
2224 DUMP(p
, paca_index
, "x");
2225 DUMP(p
, kernel_toc
, "lx");
2226 DUMP(p
, kernelbase
, "lx");
2227 DUMP(p
, kernel_msr
, "lx");
2228 DUMP(p
, emergency_sp
, "p");
2229 #ifdef CONFIG_PPC_BOOK3S_64
2230 DUMP(p
, mc_emergency_sp
, "p");
2231 DUMP(p
, in_mce
, "x");
2232 DUMP(p
, hmi_event_available
, "x");
2234 DUMP(p
, data_offset
, "lx");
2235 DUMP(p
, hw_cpu_id
, "x");
2236 DUMP(p
, cpu_start
, "x");
2237 DUMP(p
, kexec_state
, "x");
2238 #ifdef CONFIG_PPC_STD_MMU_64
2239 for (i
= 0; i
< SLB_NUM_BOLTED
; i
++) {
2242 if (!p
->slb_shadow_ptr
)
2245 esid
= be64_to_cpu(p
->slb_shadow_ptr
->save_area
[i
].esid
);
2246 vsid
= be64_to_cpu(p
->slb_shadow_ptr
->save_area
[i
].vsid
);
2249 printf(" slb_shadow[%d]: = 0x%016lx 0x%016lx\n",
2253 DUMP(p
, vmalloc_sllp
, "x");
2254 DUMP(p
, slb_cache_ptr
, "x");
2255 for (i
= 0; i
< SLB_CACHE_ENTRIES
; i
++)
2256 printf(" slb_cache[%d]: = 0x%016lx\n", i
, p
->slb_cache
[i
]);
2258 DUMP(p
, dscr_default
, "llx");
2259 #ifdef CONFIG_PPC_BOOK3E
2261 DUMP(p
, kernel_pgd
, "p");
2262 DUMP(p
, tcd_ptr
, "p");
2263 DUMP(p
, mc_kstack
, "p");
2264 DUMP(p
, crit_kstack
, "p");
2265 DUMP(p
, dbg_kstack
, "p");
2267 DUMP(p
, __current
, "p");
2268 DUMP(p
, kstack
, "lx");
2269 DUMP(p
, stab_rr
, "lx");
2270 DUMP(p
, saved_r1
, "lx");
2271 DUMP(p
, trap_save
, "x");
2272 DUMP(p
, soft_enabled
, "x");
2273 DUMP(p
, irq_happened
, "x");
2274 DUMP(p
, io_sync
, "x");
2275 DUMP(p
, irq_work_pending
, "x");
2276 DUMP(p
, nap_state_lost
, "x");
2277 DUMP(p
, sprg_vdso
, "llx");
2279 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
2280 DUMP(p
, tm_scratch
, "llx");
2283 #ifdef CONFIG_PPC_POWERNV
2284 DUMP(p
, core_idle_state_ptr
, "p");
2285 DUMP(p
, thread_idle_state
, "x");
2286 DUMP(p
, thread_mask
, "x");
2287 DUMP(p
, subcore_sibling_mask
, "x");
2290 DUMP(p
, accounting
.user_time
, "llx");
2291 DUMP(p
, accounting
.system_time
, "llx");
2292 DUMP(p
, accounting
.user_time_scaled
, "llx");
2293 DUMP(p
, accounting
.starttime
, "llx");
2294 DUMP(p
, accounting
.starttime_user
, "llx");
2295 DUMP(p
, accounting
.startspurr
, "llx");
2296 DUMP(p
, accounting
.utime_sspurr
, "llx");
2297 DUMP(p
, stolen_time
, "llx");
2300 catch_memory_errors
= 0;
2304 static void dump_all_pacas(void)
2308 if (num_possible_cpus() == 0) {
2309 printf("No possible cpus, use 'dp #' to dump individual cpus\n");
2313 for_each_possible_cpu(cpu
)
2317 static void dump_pacas(void)
2328 termch
= c
; /* Put c back, it wasn't 'a' */
2333 dump_one_paca(xmon_owner
);
2346 xmon_start_pagination();
2348 xmon_end_pagination();
2353 if ((isxdigit(c
) && c
!= 'f' && c
!= 'd') || c
== '\n')
2355 scanhex((void *)&adrs
);
2362 else if (nidump
> MAX_DUMP
)
2364 adrs
+= ppc_inst_dump(adrs
, nidump
, 1);
2366 } else if (c
== 'l') {
2368 } else if (c
== 'o') {
2370 } else if (c
== 't') {
2371 ftrace_dump(DUMP_ALL
);
2373 } else if (c
== 'r') {
2377 xmon_rawdump(adrs
, ndump
);
2384 else if (ndump
> MAX_DUMP
)
2386 prdump(adrs
, ndump
);
2393 prdump(unsigned long adrs
, long ndump
)
2395 long n
, m
, c
, r
, nr
;
2396 unsigned char temp
[16];
2398 for (n
= ndump
; n
> 0;) {
2402 nr
= mread(adrs
, temp
, r
);
2404 for (m
= 0; m
< r
; ++m
) {
2405 if ((m
& (sizeof(long) - 1)) == 0 && m
> 0)
2408 printf("%.2x", temp
[m
]);
2410 printf("%s", fault_chars
[fault_type
]);
2412 for (; m
< 16; ++m
) {
2413 if ((m
& (sizeof(long) - 1)) == 0)
2418 for (m
= 0; m
< r
; ++m
) {
2421 putchar(' ' <= c
&& c
<= '~'? c
: '.');
2434 typedef int (*instruction_dump_func
)(unsigned long inst
, unsigned long addr
);
2437 generic_inst_dump(unsigned long adr
, long count
, int praddr
,
2438 instruction_dump_func dump_func
)
2441 unsigned long first_adr
;
2442 unsigned long inst
, last_inst
= 0;
2443 unsigned char val
[4];
2446 for (first_adr
= adr
; count
> 0; --count
, adr
+= 4) {
2447 nr
= mread(adr
, val
, 4);
2450 const char *x
= fault_chars
[fault_type
];
2451 printf(REG
" %s%s%s%s\n", adr
, x
, x
, x
, x
);
2455 inst
= GETWORD(val
);
2456 if (adr
> first_adr
&& inst
== last_inst
) {
2466 printf(REG
" %.8x", adr
, inst
);
2468 dump_func(inst
, adr
);
2471 return adr
- first_adr
;
2475 ppc_inst_dump(unsigned long adr
, long count
, int praddr
)
2477 return generic_inst_dump(adr
, count
, praddr
, print_insn_powerpc
);
2481 print_address(unsigned long addr
)
2483 xmon_print_symbol(addr
, "\t# ", "");
2489 struct kmsg_dumper dumper
= { .active
= 1 };
2490 unsigned char buf
[128];
2493 if (setjmp(bus_error_jmp
) != 0) {
2494 printf("Error dumping printk buffer!\n");
2498 catch_memory_errors
= 1;
2501 kmsg_dump_rewind_nolock(&dumper
);
2502 xmon_start_pagination();
2503 while (kmsg_dump_get_line_nolock(&dumper
, false, buf
, sizeof(buf
), &len
)) {
2507 xmon_end_pagination();
2510 /* wait a little while to see if we get a machine check */
2512 catch_memory_errors
= 0;
2515 #ifdef CONFIG_PPC_POWERNV
2516 static void dump_opal_msglog(void)
2518 unsigned char buf
[128];
2522 if (!firmware_has_feature(FW_FEATURE_OPAL
)) {
2523 printf("Machine is not running OPAL firmware.\n");
2527 if (setjmp(bus_error_jmp
) != 0) {
2528 printf("Error dumping OPAL msglog!\n");
2532 catch_memory_errors
= 1;
2535 xmon_start_pagination();
2536 while ((res
= opal_msglog_copy(buf
, pos
, sizeof(buf
) - 1))) {
2538 printf("Error dumping OPAL msglog! Error: %zd\n", res
);
2545 xmon_end_pagination();
2548 /* wait a little while to see if we get a machine check */
2550 catch_memory_errors
= 0;
2555 * Memory operations - move, set, print differences
2557 static unsigned long mdest
; /* destination address */
2558 static unsigned long msrc
; /* source address */
2559 static unsigned long mval
; /* byte value to set memory to */
2560 static unsigned long mcount
; /* # bytes to affect */
2561 static unsigned long mdiffs
; /* max # differences to print */
2566 scanhex((void *)&mdest
);
2567 if( termch
!= '\n' )
2569 scanhex((void *)(cmd
== 's'? &mval
: &msrc
));
2570 if( termch
!= '\n' )
2572 scanhex((void *)&mcount
);
2575 memmove((void *)mdest
, (void *)msrc
, mcount
);
2578 memset((void *)mdest
, mval
, mcount
);
2581 if( termch
!= '\n' )
2583 scanhex((void *)&mdiffs
);
2584 memdiffs((unsigned char *)mdest
, (unsigned char *)msrc
, mcount
, mdiffs
);
2590 memdiffs(unsigned char *p1
, unsigned char *p2
, unsigned nb
, unsigned maxpr
)
2595 for( n
= nb
; n
> 0; --n
)
2596 if( *p1
++ != *p2
++ )
2597 if( ++prt
<= maxpr
)
2598 printf("%.16x %.2x # %.16x %.2x\n", p1
- 1,
2599 p1
[-1], p2
- 1, p2
[-1]);
2601 printf("Total of %d differences\n", prt
);
2604 static unsigned mend
;
2605 static unsigned mask
;
2611 unsigned char val
[4];
2614 scanhex((void *)&mdest
);
2615 if (termch
!= '\n') {
2617 scanhex((void *)&mend
);
2618 if (termch
!= '\n') {
2620 scanhex((void *)&mval
);
2622 if (termch
!= '\n') termch
= 0;
2623 scanhex((void *)&mask
);
2627 for (a
= mdest
; a
< mend
; a
+= 4) {
2628 if (mread(a
, val
, 4) == 4
2629 && ((GETWORD(val
) ^ mval
) & mask
) == 0) {
2630 printf("%.16x: %.16x\n", a
, GETWORD(val
));
2637 static unsigned long mskip
= 0x1000;
2638 static unsigned long mlim
= 0xffffffff;
2648 if (termch
!= '\n') termch
= 0;
2650 if (termch
!= '\n') termch
= 0;
2653 for (a
= mdest
; a
< mlim
; a
+= mskip
) {
2654 ok
= mread(a
, &v
, 1);
2656 printf("%.8x .. ", a
);
2657 } else if (!ok
&& ook
)
2658 printf("%.8x\n", a
- mskip
);
2664 printf("%.8x\n", a
- mskip
);
2667 static void show_task(struct task_struct
*tsk
)
2672 * Cloned from kdb_task_state_char(), which is not entirely
2673 * appropriate for calling from xmon. This could be moved
2674 * to a common, generic, routine used by both.
2676 state
= (tsk
->state
== 0) ? 'R' :
2677 (tsk
->state
< 0) ? 'U' :
2678 (tsk
->state
& TASK_UNINTERRUPTIBLE
) ? 'D' :
2679 (tsk
->state
& TASK_STOPPED
) ? 'T' :
2680 (tsk
->state
& TASK_TRACED
) ? 'C' :
2681 (tsk
->exit_state
& EXIT_ZOMBIE
) ? 'Z' :
2682 (tsk
->exit_state
& EXIT_DEAD
) ? 'E' :
2683 (tsk
->state
& TASK_INTERRUPTIBLE
) ? 'S' : '?';
2685 printf("%p %016lx %6d %6d %c %2d %s\n", tsk
,
2687 tsk
->pid
, tsk
->parent
->pid
,
2688 state
, task_thread_info(tsk
)->cpu
,
2692 static void show_tasks(void)
2695 struct task_struct
*tsk
= NULL
;
2697 printf(" task_struct ->thread.ksp PID PPID S P CMD\n");
2700 tsk
= (struct task_struct
*)tskv
;
2702 if (setjmp(bus_error_jmp
) != 0) {
2703 catch_memory_errors
= 0;
2704 printf("*** Error dumping task %p\n", tsk
);
2708 catch_memory_errors
= 1;
2714 for_each_process(tsk
)
2719 catch_memory_errors
= 0;
2722 static void proccall(void)
2724 unsigned long args
[8];
2727 typedef unsigned long (*callfunc_t
)(unsigned long, unsigned long,
2728 unsigned long, unsigned long, unsigned long,
2729 unsigned long, unsigned long, unsigned long);
2732 if (!scanhex(&adrs
))
2736 for (i
= 0; i
< 8; ++i
)
2738 for (i
= 0; i
< 8; ++i
) {
2739 if (!scanhex(&args
[i
]) || termch
== '\n')
2743 func
= (callfunc_t
) adrs
;
2745 if (setjmp(bus_error_jmp
) == 0) {
2746 catch_memory_errors
= 1;
2748 ret
= func(args
[0], args
[1], args
[2], args
[3],
2749 args
[4], args
[5], args
[6], args
[7]);
2751 printf("return value is 0x%lx\n", ret
);
2753 printf("*** %x exception occurred\n", fault_except
);
2755 catch_memory_errors
= 0;
2758 /* Input scanning routines */
2769 while( c
== ' ' || c
== '\t' )
2775 static char *regnames
[N_PTREGS
] = {
2776 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2777 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
2778 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
2779 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
2780 "pc", "msr", "or3", "ctr", "lr", "xer", "ccr",
2786 "trap", "dar", "dsisr", "res"
2790 scanhex(unsigned long *vp
)
2797 /* parse register name */
2801 for (i
= 0; i
< sizeof(regname
) - 1; ++i
) {
2810 for (i
= 0; i
< N_PTREGS
; ++i
) {
2811 if (strcmp(regnames
[i
], regname
) == 0) {
2812 if (xmon_regs
== NULL
) {
2813 printf("regs not available\n");
2816 *vp
= ((unsigned long *)xmon_regs
)[i
];
2820 printf("invalid register name '%%%s'\n", regname
);
2824 /* skip leading "0x" if any */
2838 } else if (c
== '$') {
2840 for (i
=0; i
<63; i
++) {
2842 if (isspace(c
) || c
== '\0') {
2850 if (setjmp(bus_error_jmp
) == 0) {
2851 catch_memory_errors
= 1;
2853 *vp
= kallsyms_lookup_name(tmpstr
);
2856 catch_memory_errors
= 0;
2858 printf("unknown symbol '%s'\n", tmpstr
);
2891 static int hexdigit(int c
)
2893 if( '0' <= c
&& c
<= '9' )
2895 if( 'A' <= c
&& c
<= 'F' )
2896 return c
- ('A' - 10);
2897 if( 'a' <= c
&& c
<= 'f' )
2898 return c
- ('a' - 10);
2903 getstring(char *s
, int size
)
2914 } while( c
!= ' ' && c
!= '\t' && c
!= '\n' );
2919 static char line
[256];
2920 static char *lineptr
;
2931 if (lineptr
== NULL
|| *lineptr
== 0) {
2932 if (xmon_gets(line
, sizeof(line
)) == NULL
) {
2942 take_input(char *str
)
2951 int type
= inchar();
2953 static char tmp
[64];
2958 xmon_print_symbol(addr
, ": ", "\n");
2963 if (setjmp(bus_error_jmp
) == 0) {
2964 catch_memory_errors
= 1;
2966 addr
= kallsyms_lookup_name(tmp
);
2968 printf("%s: %lx\n", tmp
, addr
);
2970 printf("Symbol '%s' not found.\n", tmp
);
2973 catch_memory_errors
= 0;
2980 /* Print an address in numeric and symbolic form (if possible) */
2981 static void xmon_print_symbol(unsigned long address
, const char *mid
,
2985 const char *name
= NULL
;
2986 unsigned long offset
, size
;
2988 printf(REG
, address
);
2989 if (setjmp(bus_error_jmp
) == 0) {
2990 catch_memory_errors
= 1;
2992 name
= kallsyms_lookup(address
, &size
, &offset
, &modname
,
2995 /* wait a little while to see if we get a machine check */
2999 catch_memory_errors
= 0;
3002 printf("%s%s+%#lx/%#lx", mid
, name
, offset
, size
);
3004 printf(" [%s]", modname
);
3006 printf("%s", after
);
3009 #ifdef CONFIG_PPC_STD_MMU_64
3010 void dump_segments(void)
3013 unsigned long esid
,vsid
;
3016 printf("SLB contents of cpu 0x%x\n", smp_processor_id());
3018 for (i
= 0; i
< mmu_slb_size
; i
++) {
3019 asm volatile("slbmfee %0,%1" : "=r" (esid
) : "r" (i
));
3020 asm volatile("slbmfev %0,%1" : "=r" (vsid
) : "r" (i
));
3022 printf("%02d %016lx %016lx", i
, esid
, vsid
);
3023 if (esid
& SLB_ESID_V
) {
3024 llp
= vsid
& SLB_VSID_LLP
;
3025 if (vsid
& SLB_VSID_B_1T
) {
3026 printf(" 1T ESID=%9lx VSID=%13lx LLP:%3lx \n",
3028 (vsid
& ~SLB_VSID_B
) >> SLB_VSID_SHIFT_1T
,
3031 printf(" 256M ESID=%9lx VSID=%13lx LLP:%3lx \n",
3033 (vsid
& ~SLB_VSID_B
) >> SLB_VSID_SHIFT
,
3043 #ifdef CONFIG_PPC_STD_MMU_32
3044 void dump_segments(void)
3049 for (i
= 0; i
< 16; ++i
)
3050 printf(" %x", mfsrin(i
));
3056 static void dump_tlb_44x(void)
3060 for (i
= 0; i
< PPC44x_TLB_SIZE
; i
++) {
3061 unsigned long w0
,w1
,w2
;
3062 asm volatile("tlbre %0,%1,0" : "=r" (w0
) : "r" (i
));
3063 asm volatile("tlbre %0,%1,1" : "=r" (w1
) : "r" (i
));
3064 asm volatile("tlbre %0,%1,2" : "=r" (w2
) : "r" (i
));
3065 printf("[%02x] %08x %08x %08x ", i
, w0
, w1
, w2
);
3066 if (w0
& PPC44x_TLB_VALID
) {
3067 printf("V %08x -> %01x%08x %c%c%c%c%c",
3068 w0
& PPC44x_TLB_EPN_MASK
,
3069 w1
& PPC44x_TLB_ERPN_MASK
,
3070 w1
& PPC44x_TLB_RPN_MASK
,
3071 (w2
& PPC44x_TLB_W
) ? 'W' : 'w',
3072 (w2
& PPC44x_TLB_I
) ? 'I' : 'i',
3073 (w2
& PPC44x_TLB_M
) ? 'M' : 'm',
3074 (w2
& PPC44x_TLB_G
) ? 'G' : 'g',
3075 (w2
& PPC44x_TLB_E
) ? 'E' : 'e');
3080 #endif /* CONFIG_44x */
3082 #ifdef CONFIG_PPC_BOOK3E
3083 static void dump_tlb_book3e(void)
3085 u32 mmucfg
, pidmask
, lpidmask
;
3087 int i
, tlb
, ntlbs
, pidsz
, lpidsz
, rasz
, lrat
= 0;
3089 static const char *pgsz_names
[] = {
3124 /* Gather some infos about the MMU */
3125 mmucfg
= mfspr(SPRN_MMUCFG
);
3126 mmu_version
= (mmucfg
& 3) + 1;
3127 ntlbs
= ((mmucfg
>> 2) & 3) + 1;
3128 pidsz
= ((mmucfg
>> 6) & 0x1f) + 1;
3129 lpidsz
= (mmucfg
>> 24) & 0xf;
3130 rasz
= (mmucfg
>> 16) & 0x7f;
3131 if ((mmu_version
> 1) && (mmucfg
& 0x10000))
3133 printf("Book3E MMU MAV=%d.0,%d TLBs,%d-bit PID,%d-bit LPID,%d-bit RA\n",
3134 mmu_version
, ntlbs
, pidsz
, lpidsz
, rasz
);
3135 pidmask
= (1ul << pidsz
) - 1;
3136 lpidmask
= (1ul << lpidsz
) - 1;
3137 ramask
= (1ull << rasz
) - 1;
3139 for (tlb
= 0; tlb
< ntlbs
; tlb
++) {
3141 int nent
, assoc
, new_cc
= 1;
3142 printf("TLB %d:\n------\n", tlb
);
3145 tlbcfg
= mfspr(SPRN_TLB0CFG
);
3148 tlbcfg
= mfspr(SPRN_TLB1CFG
);
3151 tlbcfg
= mfspr(SPRN_TLB2CFG
);
3154 tlbcfg
= mfspr(SPRN_TLB3CFG
);
3157 printf("Unsupported TLB number !\n");
3160 nent
= tlbcfg
& 0xfff;
3161 assoc
= (tlbcfg
>> 24) & 0xff;
3162 for (i
= 0; i
< nent
; i
++) {
3163 u32 mas0
= MAS0_TLBSEL(tlb
);
3164 u32 mas1
= MAS1_TSIZE(BOOK3E_PAGESZ_4K
);
3167 int esel
= i
, cc
= i
;
3175 mas0
|= MAS0_ESEL(esel
);
3176 mtspr(SPRN_MAS0
, mas0
);
3177 mtspr(SPRN_MAS1
, mas1
);
3178 mtspr(SPRN_MAS2
, mas2
);
3179 asm volatile("tlbre 0,0,0" : : : "memory");
3180 mas1
= mfspr(SPRN_MAS1
);
3181 mas2
= mfspr(SPRN_MAS2
);
3182 mas7_mas3
= mfspr(SPRN_MAS7_MAS3
);
3183 if (assoc
&& (i
% assoc
) == 0)
3185 if (!(mas1
& MAS1_VALID
))
3188 printf("%04x- ", i
);
3190 printf("%04x-%c", cc
, 'A' + esel
);
3192 printf(" |%c", 'A' + esel
);
3194 printf(" %016llx %04x %s %c%c AS%c",
3196 (mas1
>> 16) & 0x3fff,
3197 pgsz_names
[(mas1
>> 7) & 0x1f],
3198 mas1
& MAS1_IND
? 'I' : ' ',
3199 mas1
& MAS1_IPROT
? 'P' : ' ',
3200 mas1
& MAS1_TS
? '1' : '0');
3201 printf(" %c%c%c%c%c%c%c",
3202 mas2
& MAS2_X0
? 'a' : ' ',
3203 mas2
& MAS2_X1
? 'v' : ' ',
3204 mas2
& MAS2_W
? 'w' : ' ',
3205 mas2
& MAS2_I
? 'i' : ' ',
3206 mas2
& MAS2_M
? 'm' : ' ',
3207 mas2
& MAS2_G
? 'g' : ' ',
3208 mas2
& MAS2_E
? 'e' : ' ');
3209 printf(" %016llx", mas7_mas3
& ramask
& ~0x7ffull
);
3210 if (mas1
& MAS1_IND
)
3212 pgsz_names
[(mas7_mas3
>> 1) & 0x1f]);
3214 printf(" U%c%c%c S%c%c%c\n",
3215 mas7_mas3
& MAS3_UX
? 'x' : ' ',
3216 mas7_mas3
& MAS3_UW
? 'w' : ' ',
3217 mas7_mas3
& MAS3_UR
? 'r' : ' ',
3218 mas7_mas3
& MAS3_SX
? 'x' : ' ',
3219 mas7_mas3
& MAS3_SW
? 'w' : ' ',
3220 mas7_mas3
& MAS3_SR
? 'r' : ' ');
3224 #endif /* CONFIG_PPC_BOOK3E */
3226 static void xmon_init(int enable
)
3230 __debugger_ipi
= xmon_ipi
;
3231 __debugger_bpt
= xmon_bpt
;
3232 __debugger_sstep
= xmon_sstep
;
3233 __debugger_iabr_match
= xmon_iabr_match
;
3234 __debugger_break_match
= xmon_break_match
;
3235 __debugger_fault_handler
= xmon_fault_handler
;
3238 __debugger_ipi
= NULL
;
3239 __debugger_bpt
= NULL
;
3240 __debugger_sstep
= NULL
;
3241 __debugger_iabr_match
= NULL
;
3242 __debugger_break_match
= NULL
;
3243 __debugger_fault_handler
= NULL
;
3247 #ifdef CONFIG_MAGIC_SYSRQ
3248 static void sysrq_handle_xmon(int key
)
3250 /* ensure xmon is enabled */
3252 debugger(get_irq_regs());
3255 static struct sysrq_key_op sysrq_xmon_op
= {
3256 .handler
= sysrq_handle_xmon
,
3257 .help_msg
= "xmon(x)",
3258 .action_msg
= "Entering xmon",
3261 static int __init
setup_xmon_sysrq(void)
3263 register_sysrq_key('x', &sysrq_xmon_op
);
3266 __initcall(setup_xmon_sysrq
);
3267 #endif /* CONFIG_MAGIC_SYSRQ */
3269 static int __initdata xmon_early
, xmon_off
;
3271 static int __init
early_parse_xmon(char *p
)
3273 if (!p
|| strncmp(p
, "early", 5) == 0) {
3274 /* just "xmon" is equivalent to "xmon=early" */
3277 } else if (strncmp(p
, "on", 2) == 0)
3279 else if (strncmp(p
, "off", 3) == 0)
3281 else if (strncmp(p
, "nobt", 4) == 0)
3282 xmon_no_auto_backtrace
= 1;
3288 early_param("xmon", early_parse_xmon
);
3290 void __init
xmon_setup(void)
3292 #ifdef CONFIG_XMON_DEFAULT
3300 #ifdef CONFIG_SPU_BASE
3304 u64 saved_mfc_sr1_RW
;
3305 u32 saved_spu_runcntl_RW
;
3306 unsigned long dump_addr
;
3310 #define XMON_NUM_SPUS 16 /* Enough for current hardware */
3312 static struct spu_info spu_info
[XMON_NUM_SPUS
];
3314 void xmon_register_spus(struct list_head
*list
)
3318 list_for_each_entry(spu
, list
, full_list
) {
3319 if (spu
->number
>= XMON_NUM_SPUS
) {
3324 spu_info
[spu
->number
].spu
= spu
;
3325 spu_info
[spu
->number
].stopped_ok
= 0;
3326 spu_info
[spu
->number
].dump_addr
= (unsigned long)
3327 spu_info
[spu
->number
].spu
->local_store
;
3331 static void stop_spus(void)
3337 for (i
= 0; i
< XMON_NUM_SPUS
; i
++) {
3338 if (!spu_info
[i
].spu
)
3341 if (setjmp(bus_error_jmp
) == 0) {
3342 catch_memory_errors
= 1;
3345 spu
= spu_info
[i
].spu
;
3347 spu_info
[i
].saved_spu_runcntl_RW
=
3348 in_be32(&spu
->problem
->spu_runcntl_RW
);
3350 tmp
= spu_mfc_sr1_get(spu
);
3351 spu_info
[i
].saved_mfc_sr1_RW
= tmp
;
3353 tmp
&= ~MFC_STATE1_MASTER_RUN_CONTROL_MASK
;
3354 spu_mfc_sr1_set(spu
, tmp
);
3359 spu_info
[i
].stopped_ok
= 1;
3361 printf("Stopped spu %.2d (was %s)\n", i
,
3362 spu_info
[i
].saved_spu_runcntl_RW
?
3363 "running" : "stopped");
3365 catch_memory_errors
= 0;
3366 printf("*** Error stopping spu %.2d\n", i
);
3368 catch_memory_errors
= 0;
3372 static void restart_spus(void)
3377 for (i
= 0; i
< XMON_NUM_SPUS
; i
++) {
3378 if (!spu_info
[i
].spu
)
3381 if (!spu_info
[i
].stopped_ok
) {
3382 printf("*** Error, spu %d was not successfully stopped"
3383 ", not restarting\n", i
);
3387 if (setjmp(bus_error_jmp
) == 0) {
3388 catch_memory_errors
= 1;
3391 spu
= spu_info
[i
].spu
;
3392 spu_mfc_sr1_set(spu
, spu_info
[i
].saved_mfc_sr1_RW
);
3393 out_be32(&spu
->problem
->spu_runcntl_RW
,
3394 spu_info
[i
].saved_spu_runcntl_RW
);
3399 printf("Restarted spu %.2d\n", i
);
3401 catch_memory_errors
= 0;
3402 printf("*** Error restarting spu %.2d\n", i
);
3404 catch_memory_errors
= 0;
3408 #define DUMP_WIDTH 23
3409 #define DUMP_VALUE(format, field, value) \
3411 if (setjmp(bus_error_jmp) == 0) { \
3412 catch_memory_errors = 1; \
3414 printf(" %-*s = "format"\n", DUMP_WIDTH, \
3419 catch_memory_errors = 0; \
3420 printf(" %-*s = *** Error reading field.\n", \
3421 DUMP_WIDTH, #field); \
3423 catch_memory_errors = 0; \
3426 #define DUMP_FIELD(obj, format, field) \
3427 DUMP_VALUE(format, field, obj->field)
3429 static void dump_spu_fields(struct spu
*spu
)
3431 printf("Dumping spu fields at address %p:\n", spu
);
3433 DUMP_FIELD(spu
, "0x%x", number
);
3434 DUMP_FIELD(spu
, "%s", name
);
3435 DUMP_FIELD(spu
, "0x%lx", local_store_phys
);
3436 DUMP_FIELD(spu
, "0x%p", local_store
);
3437 DUMP_FIELD(spu
, "0x%lx", ls_size
);
3438 DUMP_FIELD(spu
, "0x%x", node
);
3439 DUMP_FIELD(spu
, "0x%lx", flags
);
3440 DUMP_FIELD(spu
, "%d", class_0_pending
);
3441 DUMP_FIELD(spu
, "0x%lx", class_0_dar
);
3442 DUMP_FIELD(spu
, "0x%lx", class_1_dar
);
3443 DUMP_FIELD(spu
, "0x%lx", class_1_dsisr
);
3444 DUMP_FIELD(spu
, "0x%lx", irqs
[0]);
3445 DUMP_FIELD(spu
, "0x%lx", irqs
[1]);
3446 DUMP_FIELD(spu
, "0x%lx", irqs
[2]);
3447 DUMP_FIELD(spu
, "0x%x", slb_replace
);
3448 DUMP_FIELD(spu
, "%d", pid
);
3449 DUMP_FIELD(spu
, "0x%p", mm
);
3450 DUMP_FIELD(spu
, "0x%p", ctx
);
3451 DUMP_FIELD(spu
, "0x%p", rq
);
3452 DUMP_FIELD(spu
, "0x%p", timestamp
);
3453 DUMP_FIELD(spu
, "0x%lx", problem_phys
);
3454 DUMP_FIELD(spu
, "0x%p", problem
);
3455 DUMP_VALUE("0x%x", problem
->spu_runcntl_RW
,
3456 in_be32(&spu
->problem
->spu_runcntl_RW
));
3457 DUMP_VALUE("0x%x", problem
->spu_status_R
,
3458 in_be32(&spu
->problem
->spu_status_R
));
3459 DUMP_VALUE("0x%x", problem
->spu_npc_RW
,
3460 in_be32(&spu
->problem
->spu_npc_RW
));
3461 DUMP_FIELD(spu
, "0x%p", priv2
);
3462 DUMP_FIELD(spu
, "0x%p", pdata
);
3466 spu_inst_dump(unsigned long adr
, long count
, int praddr
)
3468 return generic_inst_dump(adr
, count
, praddr
, print_insn_spu
);
3471 static void dump_spu_ls(unsigned long num
, int subcmd
)
3473 unsigned long offset
, addr
, ls_addr
;
3475 if (setjmp(bus_error_jmp
) == 0) {
3476 catch_memory_errors
= 1;
3478 ls_addr
= (unsigned long)spu_info
[num
].spu
->local_store
;
3482 catch_memory_errors
= 0;
3483 printf("*** Error: accessing spu info for spu %d\n", num
);
3486 catch_memory_errors
= 0;
3488 if (scanhex(&offset
))
3489 addr
= ls_addr
+ offset
;
3491 addr
= spu_info
[num
].dump_addr
;
3493 if (addr
>= ls_addr
+ LS_SIZE
) {
3494 printf("*** Error: address outside of local store\n");
3500 addr
+= spu_inst_dump(addr
, 16, 1);
3510 spu_info
[num
].dump_addr
= addr
;
3513 static int do_spu_cmd(void)
3515 static unsigned long num
= 0;
3516 int cmd
, subcmd
= 0;
3528 if (isxdigit(subcmd
) || subcmd
== '\n')
3532 if (num
>= XMON_NUM_SPUS
|| !spu_info
[num
].spu
) {
3533 printf("*** Error: invalid spu number\n");
3539 dump_spu_fields(spu_info
[num
].spu
);
3542 dump_spu_ls(num
, subcmd
);
3553 #else /* ! CONFIG_SPU_BASE */
3554 static int do_spu_cmd(void)