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.
13 #include <linux/errno.h>
14 #include <linux/sched.h>
15 #include <linux/smp.h>
17 #include <linux/reboot.h>
18 #include <linux/delay.h>
19 #include <linux/kallsyms.h>
20 #include <linux/kmsg_dump.h>
21 #include <linux/cpumask.h>
22 #include <linux/export.h>
23 #include <linux/sysrq.h>
24 #include <linux/interrupt.h>
25 #include <linux/irq.h>
26 #include <linux/bug.h>
27 #include <linux/nmi.h>
28 #include <linux/ctype.h>
30 #include <asm/ptrace.h>
31 #include <asm/string.h>
33 #include <asm/machdep.h>
35 #include <asm/processor.h>
36 #include <asm/pgtable.h>
38 #include <asm/mmu_context.h>
39 #include <asm/cputable.h>
41 #include <asm/sstep.h>
42 #include <asm/irq_regs.h>
44 #include <asm/spu_priv1.h>
45 #include <asm/setjmp.h>
47 #include <asm/debug.h>
48 #include <asm/hw_breakpoint.h>
51 #include <asm/firmware.h>
54 #include <asm/hvcall.h>
58 #if defined(CONFIG_PPC_SPLPAR)
59 #include <asm/plpar_wrappers.h>
61 static inline long plapr_set_ciabr(unsigned long ciabr
) {return 0; };
68 static cpumask_t cpus_in_xmon
= CPU_MASK_NONE
;
69 static unsigned long xmon_taken
= 1;
70 static int xmon_owner
;
74 #endif /* CONFIG_SMP */
76 static unsigned long in_xmon __read_mostly
= 0;
78 static unsigned long adrs
;
80 #define MAX_DUMP (128 * 1024)
81 static unsigned long ndump
= 64;
82 static unsigned long nidump
= 16;
83 static unsigned long ncsum
= 4096;
85 static char tmpstr
[128];
87 static long bus_error_jmp
[JMP_BUF_LEN
];
88 static int catch_memory_errors
;
89 static long *xmon_fault_jmp
[NR_CPUS
];
91 /* Breakpoint stuff */
93 unsigned long address
;
94 unsigned int instr
[2];
100 /* Bits in bpt.enabled */
106 static struct bpt bpts
[NBPTS
];
107 static struct bpt dabr
;
108 static struct bpt
*iabr
;
109 static unsigned bpinstr
= 0x7fe00008; /* trap */
111 #define BP_NUM(bp) ((bp) - bpts + 1)
114 static int cmds(struct pt_regs
*);
115 static int mread(unsigned long, void *, int);
116 static int mwrite(unsigned long, void *, int);
117 static int handle_fault(struct pt_regs
*);
118 static void byterev(unsigned char *, int);
119 static void memex(void);
120 static int bsesc(void);
121 static void dump(void);
122 static void prdump(unsigned long, long);
123 static int ppc_inst_dump(unsigned long, long, int);
124 static void dump_log_buf(void);
126 #ifdef CONFIG_PPC_POWERNV
127 static void dump_opal_msglog(void);
129 static inline void dump_opal_msglog(void)
131 printf("Machine is not running OPAL firmware.\n");
135 static void backtrace(struct pt_regs
*);
136 static void excprint(struct pt_regs
*);
137 static void prregs(struct pt_regs
*);
138 static void memops(int);
139 static void memlocate(void);
140 static void memzcan(void);
141 static void memdiffs(unsigned char *, unsigned char *, unsigned, unsigned);
143 int scanhex(unsigned long *valp
);
144 static void scannl(void);
145 static int hexdigit(int);
146 void getstring(char *, int);
147 static void flush_input(void);
148 static int inchar(void);
149 static void take_input(char *);
150 static unsigned long read_spr(int);
151 static void write_spr(int, unsigned long);
152 static void super_regs(void);
153 static void remove_bpts(void);
154 static void insert_bpts(void);
155 static void remove_cpu_bpts(void);
156 static void insert_cpu_bpts(void);
157 static struct bpt
*at_breakpoint(unsigned long pc
);
158 static struct bpt
*in_breakpoint_table(unsigned long pc
, unsigned long *offp
);
159 static int do_step(struct pt_regs
*);
160 static void bpt_cmds(void);
161 static void cacheflush(void);
162 static int cpu_cmd(void);
163 static void csum(void);
164 static void bootcmds(void);
165 static void proccall(void);
166 static void show_tasks(void);
167 void dump_segments(void);
168 static void symbol_lookup(void);
169 static void xmon_show_stack(unsigned long sp
, unsigned long lr
,
171 static void xmon_print_symbol(unsigned long address
, const char *mid
,
173 static const char *getvecname(unsigned long vec
);
175 static int do_spu_cmd(void);
178 static void dump_tlb_44x(void);
180 #ifdef CONFIG_PPC_BOOK3E
181 static void dump_tlb_book3e(void);
184 static int xmon_no_auto_backtrace
;
186 extern void xmon_enter(void);
187 extern void xmon_leave(void);
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 e print exception information\n\
232 la lookup symbol+offset of specified address\n\
233 ls lookup address of specified symbol\n\
234 m examine/change memory\n\
235 mm move a block of memory\n\
236 ms set a block of memory\n\
237 md compare two blocks of memory\n\
238 ml locate a block of memory\n\
239 mz zero a block of memory\n\
240 mi show information about memory allocation\n\
241 p call a procedure\n\
242 P list processes/tasks\n\
245 #ifdef CONFIG_SPU_BASE
246 " ss stop execution on all spus\n\
247 sr restore execution on stopped spus\n\
248 sf # dump spu fields for spu # (in hex)\n\
249 sd # dump spu local store for spu # (in hex)\n\
250 sdi # disassemble spu local store for spu # (in hex)\n"
252 " S print special registers\n\
254 x exit monitor and recover\n\
255 X exit monitor and don't recover\n"
256 #if defined(CONFIG_PPC64) && !defined(CONFIG_PPC_BOOK3E)
257 " u dump segment table or SLB\n"
258 #elif defined(CONFIG_PPC_STD_MMU_32)
259 " u dump segment registers\n"
260 #elif defined(CONFIG_44x) || defined(CONFIG_PPC_BOOK3E)
264 " # n limit output to n lines per page (for dp, dpa, dl)\n"
269 static struct pt_regs
*xmon_regs
;
271 static inline void sync(void)
273 asm volatile("sync; isync");
276 static inline void store_inst(void *p
)
278 asm volatile ("dcbst 0,%0; sync; icbi 0,%0; isync" : : "r" (p
));
281 static inline void cflush(void *p
)
283 asm volatile ("dcbf 0,%0; icbi 0,%0" : : "r" (p
));
286 static inline void cinval(void *p
)
288 asm volatile ("dcbi 0,%0; icbi 0,%0" : : "r" (p
));
292 * write_ciabr() - write the CIABR SPR
293 * @ciabr: The value to write.
295 * This function writes a value to the CIARB register either directly
296 * through mtspr instruction if the kernel is in HV privilege mode or
297 * call a hypervisor function to achieve the same in case the kernel
298 * is in supervisor privilege mode.
300 static void write_ciabr(unsigned long ciabr
)
302 if (!cpu_has_feature(CPU_FTR_ARCH_207S
))
305 if (cpu_has_feature(CPU_FTR_HVMODE
)) {
306 mtspr(SPRN_CIABR
, ciabr
);
309 plapr_set_ciabr(ciabr
);
313 * set_ciabr() - set the CIABR
314 * @addr: The value to set.
316 * This function sets the correct privilege value into the the HW
317 * breakpoint address before writing it up in the CIABR register.
319 static void set_ciabr(unsigned long addr
)
323 if (cpu_has_feature(CPU_FTR_HVMODE
))
324 addr
|= CIABR_PRIV_HYPER
;
326 addr
|= CIABR_PRIV_SUPER
;
331 * Disable surveillance (the service processor watchdog function)
332 * while we are in xmon.
333 * XXX we should re-enable it when we leave. :)
335 #define SURVEILLANCE_TOKEN 9000
337 static inline void disable_surveillance(void)
339 #ifdef CONFIG_PPC_PSERIES
340 /* Since this can't be a module, args should end up below 4GB. */
341 static struct rtas_args args
;
345 * At this point we have got all the cpus we can into
346 * xmon, so there is hopefully no other cpu calling RTAS
347 * at the moment, even though we don't take rtas.lock.
348 * If we did try to take rtas.lock there would be a
349 * real possibility of deadlock.
351 token
= rtas_token("set-indicator");
352 if (token
== RTAS_UNKNOWN_SERVICE
)
355 rtas_call_unlocked(&args
, token
, 3, 1, NULL
, SURVEILLANCE_TOKEN
, 0, 0);
357 #endif /* CONFIG_PPC_PSERIES */
361 static int xmon_speaker
;
363 static void get_output_lock(void)
365 int me
= smp_processor_id() + 0x100;
366 int last_speaker
= 0, prev
;
369 if (xmon_speaker
== me
)
373 last_speaker
= cmpxchg(&xmon_speaker
, 0, me
);
374 if (last_speaker
== 0)
378 * Wait a full second for the lock, we might be on a slow
379 * console, but check every 100us.
382 while (xmon_speaker
== last_speaker
) {
388 /* hostile takeover */
389 prev
= cmpxchg(&xmon_speaker
, last_speaker
, me
);
390 if (prev
== last_speaker
)
397 static void release_output_lock(void)
402 int cpus_are_in_xmon(void)
404 return !cpumask_empty(&cpus_in_xmon
);
408 static inline int unrecoverable_excp(struct pt_regs
*regs
)
410 #if defined(CONFIG_4xx) || defined(CONFIG_PPC_BOOK3E)
411 /* We have no MSR_RI bit on 4xx or Book3e, so we simply return false */
414 return ((regs
->msr
& MSR_RI
) == 0);
418 static int xmon_core(struct pt_regs
*regs
, int fromipi
)
422 long recurse_jmp
[JMP_BUF_LEN
];
423 unsigned long offset
;
428 unsigned long timeout
;
431 local_irq_save(flags
);
434 bp
= in_breakpoint_table(regs
->nip
, &offset
);
436 regs
->nip
= bp
->address
+ offset
;
437 atomic_dec(&bp
->ref_count
);
443 cpu
= smp_processor_id();
444 if (cpumask_test_cpu(cpu
, &cpus_in_xmon
)) {
447 printf("cpu 0x%x: Exception %lx %s in xmon, "
448 "returning to main loop\n",
449 cpu
, regs
->trap
, getvecname(TRAP(regs
)));
450 release_output_lock();
451 longjmp(xmon_fault_jmp
[cpu
], 1);
454 if (setjmp(recurse_jmp
) != 0) {
455 if (!in_xmon
|| !xmon_gate
) {
457 printf("xmon: WARNING: bad recursive fault "
458 "on cpu 0x%x\n", cpu
);
459 release_output_lock();
462 secondary
= !(xmon_taken
&& cpu
== xmon_owner
);
466 xmon_fault_jmp
[cpu
] = recurse_jmp
;
469 if ((regs
->msr
& (MSR_IR
|MSR_PR
|MSR_64BIT
)) == (MSR_IR
|MSR_64BIT
))
470 bp
= at_breakpoint(regs
->nip
);
471 if (bp
|| unrecoverable_excp(regs
))
478 printf("cpu 0x%x stopped at breakpoint 0x%lx (",
480 xmon_print_symbol(regs
->nip
, " ", ")\n");
482 if (unrecoverable_excp(regs
))
483 printf("WARNING: exception is not recoverable, "
485 release_output_lock();
488 cpumask_set_cpu(cpu
, &cpus_in_xmon
);
492 while (secondary
&& !xmon_gate
) {
496 secondary
= test_and_set_bit(0, &in_xmon
);
501 if (!secondary
&& !xmon_gate
) {
502 /* we are the first cpu to come in */
503 /* interrupt other cpu(s) */
504 int ncpus
= num_online_cpus();
509 smp_send_debugger_break();
510 /* wait for other cpus to come in */
511 for (timeout
= 100000000; timeout
!= 0; --timeout
) {
512 if (cpumask_weight(&cpus_in_xmon
) >= ncpus
)
518 disable_surveillance();
519 /* for breakpoint or single step, print the current instr. */
520 if (bp
|| TRAP(regs
) == 0xd00)
521 ppc_inst_dump(regs
->nip
, 1, 0);
522 printf("enter ? for help\n");
531 if (cpu
== xmon_owner
) {
532 if (!test_and_set_bit(0, &xmon_taken
)) {
537 while (cpu
== xmon_owner
)
551 /* have switched to some other cpu */
556 cpumask_clear_cpu(cpu
, &cpus_in_xmon
);
557 xmon_fault_jmp
[cpu
] = NULL
;
559 /* UP is simple... */
561 printf("Exception %lx %s in xmon, returning to main loop\n",
562 regs
->trap
, getvecname(TRAP(regs
)));
563 longjmp(xmon_fault_jmp
[0], 1);
565 if (setjmp(recurse_jmp
) == 0) {
566 xmon_fault_jmp
[0] = recurse_jmp
;
570 bp
= at_breakpoint(regs
->nip
);
572 printf("Stopped at breakpoint %lx (", BP_NUM(bp
));
573 xmon_print_symbol(regs
->nip
, " ", ")\n");
575 if (unrecoverable_excp(regs
))
576 printf("WARNING: exception is not recoverable, "
579 disable_surveillance();
580 /* for breakpoint or single step, print the current instr. */
581 if (bp
|| TRAP(regs
) == 0xd00)
582 ppc_inst_dump(regs
->nip
, 1, 0);
583 printf("enter ? for help\n");
593 if (regs
->msr
& MSR_DE
) {
594 bp
= at_breakpoint(regs
->nip
);
596 regs
->nip
= (unsigned long) &bp
->instr
[0];
597 atomic_inc(&bp
->ref_count
);
601 if ((regs
->msr
& (MSR_IR
|MSR_PR
|MSR_64BIT
)) == (MSR_IR
|MSR_64BIT
)) {
602 bp
= at_breakpoint(regs
->nip
);
604 int stepped
= emulate_step(regs
, bp
->instr
[0]);
606 regs
->nip
= (unsigned long) &bp
->instr
[0];
607 atomic_inc(&bp
->ref_count
);
608 } else if (stepped
< 0) {
609 printf("Couldn't single-step %s instruction\n",
610 (IS_RFID(bp
->instr
[0])? "rfid": "mtmsrd"));
617 touch_nmi_watchdog();
618 local_irq_restore(flags
);
620 return cmd
!= 'X' && cmd
!= EOF
;
623 int xmon(struct pt_regs
*excp
)
628 ppc_save_regs(®s
);
632 return xmon_core(excp
, 0);
636 irqreturn_t
xmon_irq(int irq
, void *d
)
639 local_irq_save(flags
);
640 printf("Keyboard interrupt\n");
641 xmon(get_irq_regs());
642 local_irq_restore(flags
);
646 static int xmon_bpt(struct pt_regs
*regs
)
649 unsigned long offset
;
651 if ((regs
->msr
& (MSR_IR
|MSR_PR
|MSR_64BIT
)) != (MSR_IR
|MSR_64BIT
))
654 /* Are we at the trap at bp->instr[1] for some bp? */
655 bp
= in_breakpoint_table(regs
->nip
, &offset
);
656 if (bp
!= NULL
&& offset
== 4) {
657 regs
->nip
= bp
->address
+ 4;
658 atomic_dec(&bp
->ref_count
);
662 /* Are we at a breakpoint? */
663 bp
= at_breakpoint(regs
->nip
);
672 static int xmon_sstep(struct pt_regs
*regs
)
680 static int xmon_break_match(struct pt_regs
*regs
)
682 if ((regs
->msr
& (MSR_IR
|MSR_PR
|MSR_64BIT
)) != (MSR_IR
|MSR_64BIT
))
684 if (dabr
.enabled
== 0)
690 static int xmon_iabr_match(struct pt_regs
*regs
)
692 if ((regs
->msr
& (MSR_IR
|MSR_PR
|MSR_64BIT
)) != (MSR_IR
|MSR_64BIT
))
700 static int xmon_ipi(struct pt_regs
*regs
)
703 if (in_xmon
&& !cpumask_test_cpu(smp_processor_id(), &cpus_in_xmon
))
709 static int xmon_fault_handler(struct pt_regs
*regs
)
712 unsigned long offset
;
714 if (in_xmon
&& catch_memory_errors
)
715 handle_fault(regs
); /* doesn't return */
717 if ((regs
->msr
& (MSR_IR
|MSR_PR
|MSR_64BIT
)) == (MSR_IR
|MSR_64BIT
)) {
718 bp
= in_breakpoint_table(regs
->nip
, &offset
);
720 regs
->nip
= bp
->address
+ offset
;
721 atomic_dec(&bp
->ref_count
);
728 static struct bpt
*at_breakpoint(unsigned long pc
)
734 for (i
= 0; i
< NBPTS
; ++i
, ++bp
)
735 if (bp
->enabled
&& pc
== bp
->address
)
740 static struct bpt
*in_breakpoint_table(unsigned long nip
, unsigned long *offp
)
744 off
= nip
- (unsigned long) bpts
;
745 if (off
>= sizeof(bpts
))
747 off
%= sizeof(struct bpt
);
748 if (off
!= offsetof(struct bpt
, instr
[0])
749 && off
!= offsetof(struct bpt
, instr
[1]))
751 *offp
= off
- offsetof(struct bpt
, instr
[0]);
752 return (struct bpt
*) (nip
- off
);
755 static struct bpt
*new_breakpoint(unsigned long a
)
760 bp
= at_breakpoint(a
);
764 for (bp
= bpts
; bp
< &bpts
[NBPTS
]; ++bp
) {
765 if (!bp
->enabled
&& atomic_read(&bp
->ref_count
) == 0) {
767 bp
->instr
[1] = bpinstr
;
768 store_inst(&bp
->instr
[1]);
773 printf("Sorry, no free breakpoints. Please clear one first.\n");
777 static void insert_bpts(void)
783 for (i
= 0; i
< NBPTS
; ++i
, ++bp
) {
784 if ((bp
->enabled
& (BP_TRAP
|BP_CIABR
)) == 0)
786 if (mread(bp
->address
, &bp
->instr
[0], 4) != 4) {
787 printf("Couldn't read instruction at %lx, "
788 "disabling breakpoint there\n", bp
->address
);
792 if (IS_MTMSRD(bp
->instr
[0]) || IS_RFID(bp
->instr
[0])) {
793 printf("Breakpoint at %lx is on an mtmsrd or rfid "
794 "instruction, disabling it\n", bp
->address
);
798 store_inst(&bp
->instr
[0]);
799 if (bp
->enabled
& BP_CIABR
)
801 if (mwrite(bp
->address
, &bpinstr
, 4) != 4) {
802 printf("Couldn't write instruction at %lx, "
803 "disabling breakpoint there\n", bp
->address
);
804 bp
->enabled
&= ~BP_TRAP
;
807 store_inst((void *)bp
->address
);
811 static void insert_cpu_bpts(void)
813 struct arch_hw_breakpoint brk
;
816 brk
.address
= dabr
.address
;
817 brk
.type
= (dabr
.enabled
& HW_BRK_TYPE_DABR
) | HW_BRK_TYPE_PRIV_ALL
;
819 __set_breakpoint(&brk
);
823 set_ciabr(iabr
->address
);
826 static void remove_bpts(void)
833 for (i
= 0; i
< NBPTS
; ++i
, ++bp
) {
834 if ((bp
->enabled
& (BP_TRAP
|BP_CIABR
)) != BP_TRAP
)
836 if (mread(bp
->address
, &instr
, 4) == 4
838 && mwrite(bp
->address
, &bp
->instr
, 4) != 4)
839 printf("Couldn't remove breakpoint at %lx\n",
842 store_inst((void *)bp
->address
);
846 static void remove_cpu_bpts(void)
848 hw_breakpoint_disable();
852 static void set_lpp_cmd(void)
856 if (!scanhex(&lpp
)) {
857 printf("Invalid number.\n");
860 xmon_set_pagination_lpp(lpp
);
862 /* Command interpreting routine */
863 static char *last_cmd
;
866 cmds(struct pt_regs
*excp
)
873 if (!xmon_no_auto_backtrace
) {
874 xmon_no_auto_backtrace
= 1;
875 xmon_show_stack(excp
->gpr
[1], excp
->link
, excp
->nip
);
880 printf("%x:", smp_processor_id());
881 #endif /* CONFIG_SMP */
887 if (last_cmd
== NULL
)
889 take_input(last_cmd
);
923 prregs(excp
); /* print regs */
938 if (do_spu_cmd() == 0)
947 printf(" <no input ...>\n");
951 xmon_puts(help_string
);
975 #ifdef CONFIG_PPC_STD_MMU
979 #elif defined(CONFIG_44x)
983 #elif defined(CONFIG_PPC_BOOK3E)
989 printf("Unrecognized command: ");
991 if (' ' < cmd
&& cmd
<= '~')
994 printf("\\x%x", cmd
);
996 } while (cmd
!= '\n');
997 printf(" (type ? for help)\n");
1004 static int do_step(struct pt_regs
*regs
)
1006 regs
->msr
|= MSR_DE
;
1007 mtspr(SPRN_DBCR0
, mfspr(SPRN_DBCR0
) | DBCR0_IC
| DBCR0_IDM
);
1012 * Step a single instruction.
1013 * Some instructions we emulate, others we execute with MSR_SE set.
1015 static int do_step(struct pt_regs
*regs
)
1020 /* check we are in 64-bit kernel mode, translation enabled */
1021 if ((regs
->msr
& (MSR_64BIT
|MSR_PR
|MSR_IR
)) == (MSR_64BIT
|MSR_IR
)) {
1022 if (mread(regs
->nip
, &instr
, 4) == 4) {
1023 stepped
= emulate_step(regs
, instr
);
1025 printf("Couldn't single-step %s instruction\n",
1026 (IS_RFID(instr
)? "rfid": "mtmsrd"));
1030 regs
->trap
= 0xd00 | (regs
->trap
& 1);
1031 printf("stepped to ");
1032 xmon_print_symbol(regs
->nip
, " ", "\n");
1033 ppc_inst_dump(regs
->nip
, 1, 0);
1038 regs
->msr
|= MSR_SE
;
1043 static void bootcmds(void)
1049 ppc_md
.restart(NULL
);
1050 else if (cmd
== 'h')
1052 else if (cmd
== 'p')
1057 static int cpu_cmd(void)
1060 unsigned long cpu
, first_cpu
, last_cpu
;
1063 if (!scanhex(&cpu
)) {
1064 /* print cpus waiting or in xmon */
1065 printf("cpus stopped:");
1066 last_cpu
= first_cpu
= NR_CPUS
;
1067 for_each_possible_cpu(cpu
) {
1068 if (cpumask_test_cpu(cpu
, &cpus_in_xmon
)) {
1069 if (cpu
== last_cpu
+ 1) {
1072 if (last_cpu
!= first_cpu
)
1073 printf("-0x%lx", last_cpu
);
1074 last_cpu
= first_cpu
= cpu
;
1075 printf(" 0x%lx", cpu
);
1079 if (last_cpu
!= first_cpu
)
1080 printf("-0x%lx", last_cpu
);
1084 /* try to switch to cpu specified */
1085 if (!cpumask_test_cpu(cpu
, &cpus_in_xmon
)) {
1086 printf("cpu 0x%x isn't in xmon\n", cpu
);
1093 while (!xmon_taken
) {
1094 if (--timeout
== 0) {
1095 if (test_and_set_bit(0, &xmon_taken
))
1097 /* take control back */
1099 xmon_owner
= smp_processor_id();
1100 printf("cpu 0x%x didn't take control\n", cpu
);
1108 #endif /* CONFIG_SMP */
1111 static unsigned short fcstab
[256] = {
1112 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
1113 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
1114 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
1115 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
1116 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
1117 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
1118 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
1119 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
1120 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
1121 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
1122 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
1123 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
1124 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
1125 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
1126 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
1127 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
1128 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
1129 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
1130 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
1131 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
1132 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
1133 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
1134 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
1135 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
1136 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
1137 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
1138 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
1139 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
1140 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
1141 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
1142 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
1143 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
1146 #define FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
1155 if (!scanhex(&adrs
))
1157 if (!scanhex(&ncsum
))
1160 for (i
= 0; i
< ncsum
; ++i
) {
1161 if (mread(adrs
+i
, &v
, 1) == 0) {
1162 printf("csum stopped at "REG
"\n", adrs
+i
);
1167 printf("%x\n", fcs
);
1171 * Check if this is a suitable place to put a breakpoint.
1173 static long check_bp_loc(unsigned long addr
)
1178 if (!is_kernel_addr(addr
)) {
1179 printf("Breakpoints may only be placed at kernel addresses\n");
1182 if (!mread(addr
, &instr
, sizeof(instr
))) {
1183 printf("Can't read instruction at address %lx\n", addr
);
1186 if (IS_MTMSRD(instr
) || IS_RFID(instr
)) {
1187 printf("Breakpoints may not be placed on mtmsrd or rfid "
1194 static char *breakpoint_help_string
=
1195 "Breakpoint command usage:\n"
1196 "b show breakpoints\n"
1197 "b <addr> [cnt] set breakpoint at given instr addr\n"
1198 "bc clear all breakpoints\n"
1199 "bc <n/addr> clear breakpoint number n or at addr\n"
1200 "bi <addr> [cnt] set hardware instr breakpoint (POWER8 only)\n"
1201 "bd <addr> [cnt] set hardware data breakpoint\n"
1211 const char badaddr
[] = "Only kernel addresses are permitted "
1212 "for breakpoints\n";
1217 case 'd': /* bd - hardware data breakpoint */
1222 else if (cmd
== 'w')
1228 if (scanhex(&dabr
.address
)) {
1229 if (!is_kernel_addr(dabr
.address
)) {
1233 dabr
.address
&= ~HW_BRK_TYPE_DABR
;
1234 dabr
.enabled
= mode
| BP_DABR
;
1238 case 'i': /* bi - hardware instr breakpoint */
1239 if (!cpu_has_feature(CPU_FTR_ARCH_207S
)) {
1240 printf("Hardware instruction breakpoint "
1241 "not supported on this cpu\n");
1245 iabr
->enabled
&= ~BP_CIABR
;
1250 if (!check_bp_loc(a
))
1252 bp
= new_breakpoint(a
);
1254 bp
->enabled
|= BP_CIABR
;
1262 /* clear all breakpoints */
1263 for (i
= 0; i
< NBPTS
; ++i
)
1264 bpts
[i
].enabled
= 0;
1267 printf("All breakpoints cleared\n");
1271 if (a
<= NBPTS
&& a
>= 1) {
1272 /* assume a breakpoint number */
1273 bp
= &bpts
[a
-1]; /* bp nums are 1 based */
1275 /* assume a breakpoint address */
1276 bp
= at_breakpoint(a
);
1278 printf("No breakpoint at %lx\n", a
);
1283 printf("Cleared breakpoint %lx (", BP_NUM(bp
));
1284 xmon_print_symbol(bp
->address
, " ", ")\n");
1292 printf(breakpoint_help_string
);
1297 /* print all breakpoints */
1298 printf(" type address\n");
1300 printf(" data "REG
" [", dabr
.address
);
1301 if (dabr
.enabled
& 1)
1303 if (dabr
.enabled
& 2)
1307 for (bp
= bpts
; bp
< &bpts
[NBPTS
]; ++bp
) {
1310 printf("%2x %s ", BP_NUM(bp
),
1311 (bp
->enabled
& BP_CIABR
) ? "inst": "trap");
1312 xmon_print_symbol(bp
->address
, " ", "\n");
1317 if (!check_bp_loc(a
))
1319 bp
= new_breakpoint(a
);
1321 bp
->enabled
|= BP_TRAP
;
1326 /* Very cheap human name for vector lookup. */
1328 const char *getvecname(unsigned long vec
)
1333 case 0x100: ret
= "(System Reset)"; break;
1334 case 0x200: ret
= "(Machine Check)"; break;
1335 case 0x300: ret
= "(Data Access)"; break;
1336 case 0x380: ret
= "(Data SLB Access)"; break;
1337 case 0x400: ret
= "(Instruction Access)"; break;
1338 case 0x480: ret
= "(Instruction SLB Access)"; break;
1339 case 0x500: ret
= "(Hardware Interrupt)"; break;
1340 case 0x600: ret
= "(Alignment)"; break;
1341 case 0x700: ret
= "(Program Check)"; break;
1342 case 0x800: ret
= "(FPU Unavailable)"; break;
1343 case 0x900: ret
= "(Decrementer)"; break;
1344 case 0x980: ret
= "(Hypervisor Decrementer)"; break;
1345 case 0xa00: ret
= "(Doorbell)"; break;
1346 case 0xc00: ret
= "(System Call)"; break;
1347 case 0xd00: ret
= "(Single Step)"; break;
1348 case 0xe40: ret
= "(Emulation Assist)"; break;
1349 case 0xe60: ret
= "(HMI)"; break;
1350 case 0xe80: ret
= "(Hypervisor Doorbell)"; break;
1351 case 0xf00: ret
= "(Performance Monitor)"; break;
1352 case 0xf20: ret
= "(Altivec Unavailable)"; break;
1353 case 0x1300: ret
= "(Instruction Breakpoint)"; break;
1354 case 0x1500: ret
= "(Denormalisation)"; break;
1355 case 0x1700: ret
= "(Altivec Assist)"; break;
1361 static void get_function_bounds(unsigned long pc
, unsigned long *startp
,
1362 unsigned long *endp
)
1364 unsigned long size
, offset
;
1367 *startp
= *endp
= 0;
1370 if (setjmp(bus_error_jmp
) == 0) {
1371 catch_memory_errors
= 1;
1373 name
= kallsyms_lookup(pc
, &size
, &offset
, NULL
, tmpstr
);
1375 *startp
= pc
- offset
;
1376 *endp
= pc
- offset
+ size
;
1380 catch_memory_errors
= 0;
1383 #define LRSAVE_OFFSET (STACK_FRAME_LR_SAVE * sizeof(unsigned long))
1384 #define MARKER_OFFSET (STACK_FRAME_MARKER * sizeof(unsigned long))
1386 static void xmon_show_stack(unsigned long sp
, unsigned long lr
,
1389 int max_to_print
= 64;
1391 unsigned long newsp
;
1392 unsigned long marker
;
1393 struct pt_regs regs
;
1395 while (max_to_print
--) {
1396 if (sp
< PAGE_OFFSET
) {
1398 printf("SP (%lx) is in userspace\n", sp
);
1402 if (!mread(sp
+ LRSAVE_OFFSET
, &ip
, sizeof(unsigned long))
1403 || !mread(sp
, &newsp
, sizeof(unsigned long))) {
1404 printf("Couldn't read stack frame at %lx\n", sp
);
1409 * For the first stack frame, try to work out if
1410 * LR and/or the saved LR value in the bottommost
1411 * stack frame are valid.
1413 if ((pc
| lr
) != 0) {
1414 unsigned long fnstart
, fnend
;
1415 unsigned long nextip
;
1418 get_function_bounds(pc
, &fnstart
, &fnend
);
1421 mread(newsp
+ LRSAVE_OFFSET
, &nextip
,
1422 sizeof(unsigned long));
1424 if (lr
< PAGE_OFFSET
1425 || (fnstart
<= lr
&& lr
< fnend
))
1427 } else if (lr
== nextip
) {
1429 } else if (lr
>= PAGE_OFFSET
1430 && !(fnstart
<= lr
&& lr
< fnend
)) {
1431 printf("[link register ] ");
1432 xmon_print_symbol(lr
, " ", "\n");
1435 printf("["REG
"] ", sp
);
1436 xmon_print_symbol(ip
, " ", " (unreliable)\n");
1441 printf("["REG
"] ", sp
);
1442 xmon_print_symbol(ip
, " ", "\n");
1445 /* Look for "regshere" marker to see if this is
1446 an exception frame. */
1447 if (mread(sp
+ MARKER_OFFSET
, &marker
, sizeof(unsigned long))
1448 && marker
== STACK_FRAME_REGS_MARKER
) {
1449 if (mread(sp
+ STACK_FRAME_OVERHEAD
, ®s
, sizeof(regs
))
1451 printf("Couldn't read registers at %lx\n",
1452 sp
+ STACK_FRAME_OVERHEAD
);
1455 printf("--- Exception: %lx %s at ", regs
.trap
,
1456 getvecname(TRAP(®s
)));
1459 xmon_print_symbol(pc
, " ", "\n");
1469 static void backtrace(struct pt_regs
*excp
)
1474 xmon_show_stack(sp
, 0, 0);
1476 xmon_show_stack(excp
->gpr
[1], excp
->link
, excp
->nip
);
1480 static void print_bug_trap(struct pt_regs
*regs
)
1483 const struct bug_entry
*bug
;
1486 if (regs
->msr
& MSR_PR
)
1487 return; /* not in kernel */
1488 addr
= regs
->nip
; /* address of trap instruction */
1489 if (addr
< PAGE_OFFSET
)
1491 bug
= find_bug(regs
->nip
);
1494 if (is_warning_bug(bug
))
1497 #ifdef CONFIG_DEBUG_BUGVERBOSE
1498 printf("kernel BUG at %s:%u!\n",
1499 bug
->file
, bug
->line
);
1501 printf("kernel BUG at %p!\n", (void *)bug
->bug_addr
);
1503 #endif /* CONFIG_BUG */
1506 static void excprint(struct pt_regs
*fp
)
1511 printf("cpu 0x%x: ", smp_processor_id());
1512 #endif /* CONFIG_SMP */
1515 printf("Vector: %lx %s at [%lx]\n", fp
->trap
, getvecname(trap
), fp
);
1517 xmon_print_symbol(fp
->nip
, ": ", "\n");
1519 printf(" lr: ", fp
->link
);
1520 xmon_print_symbol(fp
->link
, ": ", "\n");
1522 printf(" sp: %lx\n", fp
->gpr
[1]);
1523 printf(" msr: %lx\n", fp
->msr
);
1525 if (trap
== 0x300 || trap
== 0x380 || trap
== 0x600 || trap
== 0x200) {
1526 printf(" dar: %lx\n", fp
->dar
);
1528 printf(" dsisr: %lx\n", fp
->dsisr
);
1531 printf(" current = 0x%lx\n", current
);
1533 printf(" paca = 0x%lx\t softe: %d\t irq_happened: 0x%02x\n",
1534 local_paca
, local_paca
->soft_enabled
, local_paca
->irq_happened
);
1537 printf(" pid = %ld, comm = %s\n",
1538 current
->pid
, current
->comm
);
1544 printf(linux_banner
);
1547 static void prregs(struct pt_regs
*fp
)
1551 struct pt_regs regs
;
1553 if (scanhex(&base
)) {
1554 if (setjmp(bus_error_jmp
) == 0) {
1555 catch_memory_errors
= 1;
1557 regs
= *(struct pt_regs
*)base
;
1561 catch_memory_errors
= 0;
1562 printf("*** Error reading registers from "REG
"\n",
1566 catch_memory_errors
= 0;
1571 if (FULL_REGS(fp
)) {
1572 for (n
= 0; n
< 16; ++n
)
1573 printf("R%.2ld = "REG
" R%.2ld = "REG
"\n",
1574 n
, fp
->gpr
[n
], n
+16, fp
->gpr
[n
+16]);
1576 for (n
= 0; n
< 7; ++n
)
1577 printf("R%.2ld = "REG
" R%.2ld = "REG
"\n",
1578 n
, fp
->gpr
[n
], n
+7, fp
->gpr
[n
+7]);
1581 for (n
= 0; n
< 32; ++n
) {
1582 printf("R%.2d = %.8x%s", n
, fp
->gpr
[n
],
1583 (n
& 3) == 3? "\n": " ");
1584 if (n
== 12 && !FULL_REGS(fp
)) {
1591 xmon_print_symbol(fp
->nip
, " ", "\n");
1592 if (TRAP(fp
) != 0xc00 && cpu_has_feature(CPU_FTR_CFAR
)) {
1594 xmon_print_symbol(fp
->orig_gpr3
, " ", "\n");
1597 xmon_print_symbol(fp
->link
, " ", "\n");
1598 printf("msr = "REG
" cr = %.8lx\n", fp
->msr
, fp
->ccr
);
1599 printf("ctr = "REG
" xer = "REG
" trap = %4lx\n",
1600 fp
->ctr
, fp
->xer
, fp
->trap
);
1602 if (trap
== 0x300 || trap
== 0x380 || trap
== 0x600)
1603 printf("dar = "REG
" dsisr = %.8lx\n", fp
->dar
, fp
->dsisr
);
1606 static void cacheflush(void)
1609 unsigned long nflush
;
1614 scanhex((void *)&adrs
);
1619 nflush
= (nflush
+ L1_CACHE_BYTES
- 1) / L1_CACHE_BYTES
;
1620 if (setjmp(bus_error_jmp
) == 0) {
1621 catch_memory_errors
= 1;
1625 for (; nflush
> 0; --nflush
, adrs
+= L1_CACHE_BYTES
)
1626 cflush((void *) adrs
);
1628 for (; nflush
> 0; --nflush
, adrs
+= L1_CACHE_BYTES
)
1629 cinval((void *) adrs
);
1632 /* wait a little while to see if we get a machine check */
1635 catch_memory_errors
= 0;
1638 static unsigned long
1641 unsigned int instrs
[2];
1642 unsigned long (*code
)(void);
1643 unsigned long ret
= -1UL;
1645 unsigned long opd
[3];
1647 opd
[0] = (unsigned long)instrs
;
1650 code
= (unsigned long (*)(void)) opd
;
1652 code
= (unsigned long (*)(void)) instrs
;
1655 /* mfspr r3,n; blr */
1656 instrs
[0] = 0x7c6002a6 + ((n
& 0x1F) << 16) + ((n
& 0x3e0) << 6);
1657 instrs
[1] = 0x4e800020;
1659 store_inst(instrs
+1);
1661 if (setjmp(bus_error_jmp
) == 0) {
1662 catch_memory_errors
= 1;
1668 /* wait a little while to see if we get a machine check */
1677 write_spr(int n
, unsigned long val
)
1679 unsigned int instrs
[2];
1680 unsigned long (*code
)(unsigned long);
1682 unsigned long opd
[3];
1684 opd
[0] = (unsigned long)instrs
;
1687 code
= (unsigned long (*)(unsigned long)) opd
;
1689 code
= (unsigned long (*)(unsigned long)) instrs
;
1692 instrs
[0] = 0x7c6003a6 + ((n
& 0x1F) << 16) + ((n
& 0x3e0) << 6);
1693 instrs
[1] = 0x4e800020;
1695 store_inst(instrs
+1);
1697 if (setjmp(bus_error_jmp
) == 0) {
1698 catch_memory_errors
= 1;
1704 /* wait a little while to see if we get a machine check */
1710 static unsigned long regno
;
1711 extern char exc_prolog
;
1712 extern char dec_exc
;
1714 static void super_regs(void)
1721 unsigned long sp
, toc
;
1722 asm("mr %0,1" : "=r" (sp
) :);
1723 asm("mr %0,2" : "=r" (toc
) :);
1725 printf("msr = "REG
" sprg0= "REG
"\n",
1726 mfmsr(), mfspr(SPRN_SPRG0
));
1727 printf("pvr = "REG
" sprg1= "REG
"\n",
1728 mfspr(SPRN_PVR
), mfspr(SPRN_SPRG1
));
1729 printf("dec = "REG
" sprg2= "REG
"\n",
1730 mfspr(SPRN_DEC
), mfspr(SPRN_SPRG2
));
1731 printf("sp = "REG
" sprg3= "REG
"\n", sp
, mfspr(SPRN_SPRG3
));
1732 printf("toc = "REG
" dar = "REG
"\n", toc
, mfspr(SPRN_DAR
));
1740 val
= read_spr(regno
);
1742 write_spr(regno
, val
);
1745 printf("spr %lx = %lx\n", regno
, read_spr(regno
));
1752 * Stuff for reading and writing memory safely
1755 mread(unsigned long adrs
, void *buf
, int size
)
1761 if (setjmp(bus_error_jmp
) == 0) {
1762 catch_memory_errors
= 1;
1768 *(u16
*)q
= *(u16
*)p
;
1771 *(u32
*)q
= *(u32
*)p
;
1774 *(u64
*)q
= *(u64
*)p
;
1777 for( ; n
< size
; ++n
) {
1783 /* wait a little while to see if we get a machine check */
1787 catch_memory_errors
= 0;
1792 mwrite(unsigned long adrs
, void *buf
, int size
)
1798 if (setjmp(bus_error_jmp
) == 0) {
1799 catch_memory_errors
= 1;
1805 *(u16
*)p
= *(u16
*)q
;
1808 *(u32
*)p
= *(u32
*)q
;
1811 *(u64
*)p
= *(u64
*)q
;
1814 for ( ; n
< size
; ++n
) {
1820 /* wait a little while to see if we get a machine check */
1824 printf("*** Error writing address "REG
"\n", adrs
+ n
);
1826 catch_memory_errors
= 0;
1830 static int fault_type
;
1831 static int fault_except
;
1832 static char *fault_chars
[] = { "--", "**", "##" };
1834 static int handle_fault(struct pt_regs
*regs
)
1836 fault_except
= TRAP(regs
);
1837 switch (TRAP(regs
)) {
1849 longjmp(bus_error_jmp
, 1);
1854 #define SWAP(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
1857 byterev(unsigned char *val
, int size
)
1863 SWAP(val
[0], val
[1], t
);
1866 SWAP(val
[0], val
[3], t
);
1867 SWAP(val
[1], val
[2], t
);
1869 case 8: /* is there really any use for this? */
1870 SWAP(val
[0], val
[7], t
);
1871 SWAP(val
[1], val
[6], t
);
1872 SWAP(val
[2], val
[5], t
);
1873 SWAP(val
[3], val
[4], t
);
1881 static char *memex_help_string
=
1882 "Memory examine command usage:\n"
1883 "m [addr] [flags] examine/change memory\n"
1884 " addr is optional. will start where left off.\n"
1885 " flags may include chars from this set:\n"
1886 " b modify by bytes (default)\n"
1887 " w modify by words (2 byte)\n"
1888 " l modify by longs (4 byte)\n"
1889 " d modify by doubleword (8 byte)\n"
1890 " r toggle reverse byte order mode\n"
1891 " n do not read memory (for i/o spaces)\n"
1892 " . ok to read (default)\n"
1893 "NOTE: flags are saved as defaults\n"
1896 static char *memex_subcmd_help_string
=
1897 "Memory examine subcommands:\n"
1898 " hexval write this val to current location\n"
1899 " 'string' write chars from string to this location\n"
1900 " ' increment address\n"
1901 " ^ decrement address\n"
1902 " / increment addr by 0x10. //=0x100, ///=0x1000, etc\n"
1903 " \\ decrement addr by 0x10. \\\\=0x100, \\\\\\=0x1000, etc\n"
1904 " ` clear no-read flag\n"
1905 " ; stay at this addr\n"
1906 " v change to byte mode\n"
1907 " w change to word (2 byte) mode\n"
1908 " l change to long (4 byte) mode\n"
1909 " u change to doubleword (8 byte) mode\n"
1910 " m addr change current addr\n"
1911 " n toggle no-read flag\n"
1912 " r toggle byte reverse flag\n"
1913 " < count back up count bytes\n"
1914 " > count skip forward count bytes\n"
1915 " x exit this mode\n"
1921 int cmd
, inc
, i
, nslash
;
1923 unsigned char val
[16];
1925 scanhex((void *)&adrs
);
1928 printf(memex_help_string
);
1934 while ((cmd
= skipbl()) != '\n') {
1936 case 'b': size
= 1; break;
1937 case 'w': size
= 2; break;
1938 case 'l': size
= 4; break;
1939 case 'd': size
= 8; break;
1940 case 'r': brev
= !brev
; break;
1941 case 'n': mnoread
= 1; break;
1942 case '.': mnoread
= 0; break;
1951 n
= mread(adrs
, val
, size
);
1952 printf(REG
"%c", adrs
, brev
? 'r': ' ');
1957 for (i
= 0; i
< n
; ++i
)
1958 printf("%.2x", val
[i
]);
1959 for (; i
< size
; ++i
)
1960 printf("%s", fault_chars
[fault_type
]);
1967 for (i
= 0; i
< size
; ++i
)
1968 val
[i
] = n
>> (i
* 8);
1971 mwrite(adrs
, val
, size
);
1984 else if( n
== '\'' )
1986 for (i
= 0; i
< size
; ++i
)
1987 val
[i
] = n
>> (i
* 8);
1990 mwrite(adrs
, val
, size
);
2026 adrs
-= 1 << nslash
;
2030 adrs
+= 1 << nslash
;
2034 adrs
+= 1 << -nslash
;
2038 adrs
-= 1 << -nslash
;
2041 scanhex((void *)&adrs
);
2060 printf(memex_subcmd_help_string
);
2075 case 'n': c
= '\n'; break;
2076 case 'r': c
= '\r'; break;
2077 case 'b': c
= '\b'; break;
2078 case 't': c
= '\t'; break;
2083 static void xmon_rawdump (unsigned long adrs
, long ndump
)
2086 unsigned char temp
[16];
2088 for (n
= ndump
; n
> 0;) {
2090 nr
= mread(adrs
, temp
, r
);
2092 for (m
= 0; m
< r
; ++m
) {
2094 printf("%.2x", temp
[m
]);
2096 printf("%s", fault_chars
[fault_type
]);
2106 static void dump_one_paca(int cpu
)
2108 struct paca_struct
*p
;
2109 #ifdef CONFIG_PPC_STD_MMU_64
2113 if (setjmp(bus_error_jmp
) != 0) {
2114 printf("*** Error dumping paca for cpu 0x%x!\n", cpu
);
2118 catch_memory_errors
= 1;
2123 printf("paca for cpu 0x%x @ %p:\n", cpu
, p
);
2125 printf(" %-*s = %s\n", 20, "possible", cpu_possible(cpu
) ? "yes" : "no");
2126 printf(" %-*s = %s\n", 20, "present", cpu_present(cpu
) ? "yes" : "no");
2127 printf(" %-*s = %s\n", 20, "online", cpu_online(cpu
) ? "yes" : "no");
2129 #define DUMP(paca, name, format) \
2130 printf(" %-*s = %#-*"format"\t(0x%lx)\n", 20, #name, 18, paca->name, \
2131 offsetof(struct paca_struct, name));
2133 DUMP(p
, lock_token
, "x");
2134 DUMP(p
, paca_index
, "x");
2135 DUMP(p
, kernel_toc
, "lx");
2136 DUMP(p
, kernelbase
, "lx");
2137 DUMP(p
, kernel_msr
, "lx");
2138 DUMP(p
, emergency_sp
, "p");
2139 #ifdef CONFIG_PPC_BOOK3S_64
2140 DUMP(p
, mc_emergency_sp
, "p");
2141 DUMP(p
, in_mce
, "x");
2142 DUMP(p
, hmi_event_available
, "x");
2144 DUMP(p
, data_offset
, "lx");
2145 DUMP(p
, hw_cpu_id
, "x");
2146 DUMP(p
, cpu_start
, "x");
2147 DUMP(p
, kexec_state
, "x");
2148 #ifdef CONFIG_PPC_STD_MMU_64
2149 for (i
= 0; i
< SLB_NUM_BOLTED
; i
++) {
2152 if (!p
->slb_shadow_ptr
)
2155 esid
= be64_to_cpu(p
->slb_shadow_ptr
->save_area
[i
].esid
);
2156 vsid
= be64_to_cpu(p
->slb_shadow_ptr
->save_area
[i
].vsid
);
2159 printf(" slb_shadow[%d]: = 0x%016lx 0x%016lx\n",
2163 DUMP(p
, vmalloc_sllp
, "x");
2164 DUMP(p
, slb_cache_ptr
, "x");
2165 for (i
= 0; i
< SLB_CACHE_ENTRIES
; i
++)
2166 printf(" slb_cache[%d]: = 0x%016lx\n", i
, p
->slb_cache
[i
]);
2168 DUMP(p
, dscr_default
, "llx");
2169 #ifdef CONFIG_PPC_BOOK3E
2171 DUMP(p
, kernel_pgd
, "p");
2172 DUMP(p
, tcd_ptr
, "p");
2173 DUMP(p
, mc_kstack
, "p");
2174 DUMP(p
, crit_kstack
, "p");
2175 DUMP(p
, dbg_kstack
, "p");
2177 DUMP(p
, __current
, "p");
2178 DUMP(p
, kstack
, "lx");
2179 DUMP(p
, stab_rr
, "lx");
2180 DUMP(p
, saved_r1
, "lx");
2181 DUMP(p
, trap_save
, "x");
2182 DUMP(p
, soft_enabled
, "x");
2183 DUMP(p
, irq_happened
, "x");
2184 DUMP(p
, io_sync
, "x");
2185 DUMP(p
, irq_work_pending
, "x");
2186 DUMP(p
, nap_state_lost
, "x");
2187 DUMP(p
, sprg_vdso
, "llx");
2189 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
2190 DUMP(p
, tm_scratch
, "llx");
2193 #ifdef CONFIG_PPC_POWERNV
2194 DUMP(p
, core_idle_state_ptr
, "p");
2195 DUMP(p
, thread_idle_state
, "x");
2196 DUMP(p
, thread_mask
, "x");
2197 DUMP(p
, subcore_sibling_mask
, "x");
2200 DUMP(p
, user_time
, "llx");
2201 DUMP(p
, system_time
, "llx");
2202 DUMP(p
, user_time_scaled
, "llx");
2203 DUMP(p
, starttime
, "llx");
2204 DUMP(p
, starttime_user
, "llx");
2205 DUMP(p
, startspurr
, "llx");
2206 DUMP(p
, utime_sspurr
, "llx");
2207 DUMP(p
, stolen_time
, "llx");
2210 catch_memory_errors
= 0;
2214 static void dump_all_pacas(void)
2218 if (num_possible_cpus() == 0) {
2219 printf("No possible cpus, use 'dp #' to dump individual cpus\n");
2223 for_each_possible_cpu(cpu
)
2227 static void dump_pacas(void)
2238 termch
= c
; /* Put c back, it wasn't 'a' */
2243 dump_one_paca(xmon_owner
);
2256 xmon_start_pagination();
2258 xmon_end_pagination();
2263 if ((isxdigit(c
) && c
!= 'f' && c
!= 'd') || c
== '\n')
2265 scanhex((void *)&adrs
);
2272 else if (nidump
> MAX_DUMP
)
2274 adrs
+= ppc_inst_dump(adrs
, nidump
, 1);
2276 } else if (c
== 'l') {
2278 } else if (c
== 'o') {
2280 } else if (c
== 'r') {
2284 xmon_rawdump(adrs
, ndump
);
2291 else if (ndump
> MAX_DUMP
)
2293 prdump(adrs
, ndump
);
2300 prdump(unsigned long adrs
, long ndump
)
2302 long n
, m
, c
, r
, nr
;
2303 unsigned char temp
[16];
2305 for (n
= ndump
; n
> 0;) {
2309 nr
= mread(adrs
, temp
, r
);
2311 for (m
= 0; m
< r
; ++m
) {
2312 if ((m
& (sizeof(long) - 1)) == 0 && m
> 0)
2315 printf("%.2x", temp
[m
]);
2317 printf("%s", fault_chars
[fault_type
]);
2319 for (; m
< 16; ++m
) {
2320 if ((m
& (sizeof(long) - 1)) == 0)
2325 for (m
= 0; m
< r
; ++m
) {
2328 putchar(' ' <= c
&& c
<= '~'? c
: '.');
2341 typedef int (*instruction_dump_func
)(unsigned long inst
, unsigned long addr
);
2344 generic_inst_dump(unsigned long adr
, long count
, int praddr
,
2345 instruction_dump_func dump_func
)
2348 unsigned long first_adr
;
2349 unsigned long inst
, last_inst
= 0;
2350 unsigned char val
[4];
2353 for (first_adr
= adr
; count
> 0; --count
, adr
+= 4) {
2354 nr
= mread(adr
, val
, 4);
2357 const char *x
= fault_chars
[fault_type
];
2358 printf(REG
" %s%s%s%s\n", adr
, x
, x
, x
, x
);
2362 inst
= GETWORD(val
);
2363 if (adr
> first_adr
&& inst
== last_inst
) {
2373 printf(REG
" %.8x", adr
, inst
);
2375 dump_func(inst
, adr
);
2378 return adr
- first_adr
;
2382 ppc_inst_dump(unsigned long adr
, long count
, int praddr
)
2384 return generic_inst_dump(adr
, count
, praddr
, print_insn_powerpc
);
2388 print_address(unsigned long addr
)
2390 xmon_print_symbol(addr
, "\t# ", "");
2396 struct kmsg_dumper dumper
= { .active
= 1 };
2397 unsigned char buf
[128];
2400 if (setjmp(bus_error_jmp
) != 0) {
2401 printf("Error dumping printk buffer!\n");
2405 catch_memory_errors
= 1;
2408 kmsg_dump_rewind_nolock(&dumper
);
2409 xmon_start_pagination();
2410 while (kmsg_dump_get_line_nolock(&dumper
, false, buf
, sizeof(buf
), &len
)) {
2414 xmon_end_pagination();
2417 /* wait a little while to see if we get a machine check */
2419 catch_memory_errors
= 0;
2422 #ifdef CONFIG_PPC_POWERNV
2423 static void dump_opal_msglog(void)
2425 unsigned char buf
[128];
2429 if (!firmware_has_feature(FW_FEATURE_OPAL
)) {
2430 printf("Machine is not running OPAL firmware.\n");
2434 if (setjmp(bus_error_jmp
) != 0) {
2435 printf("Error dumping OPAL msglog!\n");
2439 catch_memory_errors
= 1;
2442 xmon_start_pagination();
2443 while ((res
= opal_msglog_copy(buf
, pos
, sizeof(buf
) - 1))) {
2445 printf("Error dumping OPAL msglog! Error: %zd\n", res
);
2452 xmon_end_pagination();
2455 /* wait a little while to see if we get a machine check */
2457 catch_memory_errors
= 0;
2462 * Memory operations - move, set, print differences
2464 static unsigned long mdest
; /* destination address */
2465 static unsigned long msrc
; /* source address */
2466 static unsigned long mval
; /* byte value to set memory to */
2467 static unsigned long mcount
; /* # bytes to affect */
2468 static unsigned long mdiffs
; /* max # differences to print */
2473 scanhex((void *)&mdest
);
2474 if( termch
!= '\n' )
2476 scanhex((void *)(cmd
== 's'? &mval
: &msrc
));
2477 if( termch
!= '\n' )
2479 scanhex((void *)&mcount
);
2482 memmove((void *)mdest
, (void *)msrc
, mcount
);
2485 memset((void *)mdest
, mval
, mcount
);
2488 if( termch
!= '\n' )
2490 scanhex((void *)&mdiffs
);
2491 memdiffs((unsigned char *)mdest
, (unsigned char *)msrc
, mcount
, mdiffs
);
2497 memdiffs(unsigned char *p1
, unsigned char *p2
, unsigned nb
, unsigned maxpr
)
2502 for( n
= nb
; n
> 0; --n
)
2503 if( *p1
++ != *p2
++ )
2504 if( ++prt
<= maxpr
)
2505 printf("%.16x %.2x # %.16x %.2x\n", p1
- 1,
2506 p1
[-1], p2
- 1, p2
[-1]);
2508 printf("Total of %d differences\n", prt
);
2511 static unsigned mend
;
2512 static unsigned mask
;
2518 unsigned char val
[4];
2521 scanhex((void *)&mdest
);
2522 if (termch
!= '\n') {
2524 scanhex((void *)&mend
);
2525 if (termch
!= '\n') {
2527 scanhex((void *)&mval
);
2529 if (termch
!= '\n') termch
= 0;
2530 scanhex((void *)&mask
);
2534 for (a
= mdest
; a
< mend
; a
+= 4) {
2535 if (mread(a
, val
, 4) == 4
2536 && ((GETWORD(val
) ^ mval
) & mask
) == 0) {
2537 printf("%.16x: %.16x\n", a
, GETWORD(val
));
2544 static unsigned long mskip
= 0x1000;
2545 static unsigned long mlim
= 0xffffffff;
2555 if (termch
!= '\n') termch
= 0;
2557 if (termch
!= '\n') termch
= 0;
2560 for (a
= mdest
; a
< mlim
; a
+= mskip
) {
2561 ok
= mread(a
, &v
, 1);
2563 printf("%.8x .. ", a
);
2564 } else if (!ok
&& ook
)
2565 printf("%.8x\n", a
- mskip
);
2571 printf("%.8x\n", a
- mskip
);
2574 static void show_task(struct task_struct
*tsk
)
2579 * Cloned from kdb_task_state_char(), which is not entirely
2580 * appropriate for calling from xmon. This could be moved
2581 * to a common, generic, routine used by both.
2583 state
= (tsk
->state
== 0) ? 'R' :
2584 (tsk
->state
< 0) ? 'U' :
2585 (tsk
->state
& TASK_UNINTERRUPTIBLE
) ? 'D' :
2586 (tsk
->state
& TASK_STOPPED
) ? 'T' :
2587 (tsk
->state
& TASK_TRACED
) ? 'C' :
2588 (tsk
->exit_state
& EXIT_ZOMBIE
) ? 'Z' :
2589 (tsk
->exit_state
& EXIT_DEAD
) ? 'E' :
2590 (tsk
->state
& TASK_INTERRUPTIBLE
) ? 'S' : '?';
2592 printf("%p %016lx %6d %6d %c %2d %s\n", tsk
,
2594 tsk
->pid
, tsk
->parent
->pid
,
2595 state
, task_thread_info(tsk
)->cpu
,
2599 static void show_tasks(void)
2602 struct task_struct
*tsk
= NULL
;
2604 printf(" task_struct ->thread.ksp PID PPID S P CMD\n");
2607 tsk
= (struct task_struct
*)tskv
;
2609 if (setjmp(bus_error_jmp
) != 0) {
2610 catch_memory_errors
= 0;
2611 printf("*** Error dumping task %p\n", tsk
);
2615 catch_memory_errors
= 1;
2621 for_each_process(tsk
)
2626 catch_memory_errors
= 0;
2629 static void proccall(void)
2631 unsigned long args
[8];
2634 typedef unsigned long (*callfunc_t
)(unsigned long, unsigned long,
2635 unsigned long, unsigned long, unsigned long,
2636 unsigned long, unsigned long, unsigned long);
2639 if (!scanhex(&adrs
))
2643 for (i
= 0; i
< 8; ++i
)
2645 for (i
= 0; i
< 8; ++i
) {
2646 if (!scanhex(&args
[i
]) || termch
== '\n')
2650 func
= (callfunc_t
) adrs
;
2652 if (setjmp(bus_error_jmp
) == 0) {
2653 catch_memory_errors
= 1;
2655 ret
= func(args
[0], args
[1], args
[2], args
[3],
2656 args
[4], args
[5], args
[6], args
[7]);
2658 printf("return value is 0x%lx\n", ret
);
2660 printf("*** %x exception occurred\n", fault_except
);
2662 catch_memory_errors
= 0;
2665 /* Input scanning routines */
2676 while( c
== ' ' || c
== '\t' )
2682 static char *regnames
[N_PTREGS
] = {
2683 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2684 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
2685 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
2686 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
2687 "pc", "msr", "or3", "ctr", "lr", "xer", "ccr",
2693 "trap", "dar", "dsisr", "res"
2697 scanhex(unsigned long *vp
)
2704 /* parse register name */
2708 for (i
= 0; i
< sizeof(regname
) - 1; ++i
) {
2717 for (i
= 0; i
< N_PTREGS
; ++i
) {
2718 if (strcmp(regnames
[i
], regname
) == 0) {
2719 if (xmon_regs
== NULL
) {
2720 printf("regs not available\n");
2723 *vp
= ((unsigned long *)xmon_regs
)[i
];
2727 printf("invalid register name '%%%s'\n", regname
);
2731 /* skip leading "0x" if any */
2745 } else if (c
== '$') {
2747 for (i
=0; i
<63; i
++) {
2749 if (isspace(c
) || c
== '\0') {
2757 if (setjmp(bus_error_jmp
) == 0) {
2758 catch_memory_errors
= 1;
2760 *vp
= kallsyms_lookup_name(tmpstr
);
2763 catch_memory_errors
= 0;
2765 printf("unknown symbol '%s'\n", tmpstr
);
2798 static int hexdigit(int c
)
2800 if( '0' <= c
&& c
<= '9' )
2802 if( 'A' <= c
&& c
<= 'F' )
2803 return c
- ('A' - 10);
2804 if( 'a' <= c
&& c
<= 'f' )
2805 return c
- ('a' - 10);
2810 getstring(char *s
, int size
)
2821 } while( c
!= ' ' && c
!= '\t' && c
!= '\n' );
2826 static char line
[256];
2827 static char *lineptr
;
2838 if (lineptr
== NULL
|| *lineptr
== 0) {
2839 if (xmon_gets(line
, sizeof(line
)) == NULL
) {
2849 take_input(char *str
)
2858 int type
= inchar();
2860 static char tmp
[64];
2865 xmon_print_symbol(addr
, ": ", "\n");
2870 if (setjmp(bus_error_jmp
) == 0) {
2871 catch_memory_errors
= 1;
2873 addr
= kallsyms_lookup_name(tmp
);
2875 printf("%s: %lx\n", tmp
, addr
);
2877 printf("Symbol '%s' not found.\n", tmp
);
2880 catch_memory_errors
= 0;
2887 /* Print an address in numeric and symbolic form (if possible) */
2888 static void xmon_print_symbol(unsigned long address
, const char *mid
,
2892 const char *name
= NULL
;
2893 unsigned long offset
, size
;
2895 printf(REG
, address
);
2896 if (setjmp(bus_error_jmp
) == 0) {
2897 catch_memory_errors
= 1;
2899 name
= kallsyms_lookup(address
, &size
, &offset
, &modname
,
2902 /* wait a little while to see if we get a machine check */
2906 catch_memory_errors
= 0;
2909 printf("%s%s+%#lx/%#lx", mid
, name
, offset
, size
);
2911 printf(" [%s]", modname
);
2913 printf("%s", after
);
2916 #ifdef CONFIG_PPC_BOOK3S_64
2917 void dump_segments(void)
2920 unsigned long esid
,vsid
;
2923 printf("SLB contents of cpu 0x%x\n", smp_processor_id());
2925 for (i
= 0; i
< mmu_slb_size
; i
++) {
2926 asm volatile("slbmfee %0,%1" : "=r" (esid
) : "r" (i
));
2927 asm volatile("slbmfev %0,%1" : "=r" (vsid
) : "r" (i
));
2929 printf("%02d %016lx %016lx", i
, esid
, vsid
);
2930 if (esid
& SLB_ESID_V
) {
2931 llp
= vsid
& SLB_VSID_LLP
;
2932 if (vsid
& SLB_VSID_B_1T
) {
2933 printf(" 1T ESID=%9lx VSID=%13lx LLP:%3lx \n",
2935 (vsid
& ~SLB_VSID_B
) >> SLB_VSID_SHIFT_1T
,
2938 printf(" 256M ESID=%9lx VSID=%13lx LLP:%3lx \n",
2940 (vsid
& ~SLB_VSID_B
) >> SLB_VSID_SHIFT
,
2950 #ifdef CONFIG_PPC_STD_MMU_32
2951 void dump_segments(void)
2956 for (i
= 0; i
< 16; ++i
)
2957 printf(" %x", mfsrin(i
));
2963 static void dump_tlb_44x(void)
2967 for (i
= 0; i
< PPC44x_TLB_SIZE
; i
++) {
2968 unsigned long w0
,w1
,w2
;
2969 asm volatile("tlbre %0,%1,0" : "=r" (w0
) : "r" (i
));
2970 asm volatile("tlbre %0,%1,1" : "=r" (w1
) : "r" (i
));
2971 asm volatile("tlbre %0,%1,2" : "=r" (w2
) : "r" (i
));
2972 printf("[%02x] %08x %08x %08x ", i
, w0
, w1
, w2
);
2973 if (w0
& PPC44x_TLB_VALID
) {
2974 printf("V %08x -> %01x%08x %c%c%c%c%c",
2975 w0
& PPC44x_TLB_EPN_MASK
,
2976 w1
& PPC44x_TLB_ERPN_MASK
,
2977 w1
& PPC44x_TLB_RPN_MASK
,
2978 (w2
& PPC44x_TLB_W
) ? 'W' : 'w',
2979 (w2
& PPC44x_TLB_I
) ? 'I' : 'i',
2980 (w2
& PPC44x_TLB_M
) ? 'M' : 'm',
2981 (w2
& PPC44x_TLB_G
) ? 'G' : 'g',
2982 (w2
& PPC44x_TLB_E
) ? 'E' : 'e');
2987 #endif /* CONFIG_44x */
2989 #ifdef CONFIG_PPC_BOOK3E
2990 static void dump_tlb_book3e(void)
2992 u32 mmucfg
, pidmask
, lpidmask
;
2994 int i
, tlb
, ntlbs
, pidsz
, lpidsz
, rasz
, lrat
= 0;
2996 static const char *pgsz_names
[] = {
3031 /* Gather some infos about the MMU */
3032 mmucfg
= mfspr(SPRN_MMUCFG
);
3033 mmu_version
= (mmucfg
& 3) + 1;
3034 ntlbs
= ((mmucfg
>> 2) & 3) + 1;
3035 pidsz
= ((mmucfg
>> 6) & 0x1f) + 1;
3036 lpidsz
= (mmucfg
>> 24) & 0xf;
3037 rasz
= (mmucfg
>> 16) & 0x7f;
3038 if ((mmu_version
> 1) && (mmucfg
& 0x10000))
3040 printf("Book3E MMU MAV=%d.0,%d TLBs,%d-bit PID,%d-bit LPID,%d-bit RA\n",
3041 mmu_version
, ntlbs
, pidsz
, lpidsz
, rasz
);
3042 pidmask
= (1ul << pidsz
) - 1;
3043 lpidmask
= (1ul << lpidsz
) - 1;
3044 ramask
= (1ull << rasz
) - 1;
3046 for (tlb
= 0; tlb
< ntlbs
; tlb
++) {
3048 int nent
, assoc
, new_cc
= 1;
3049 printf("TLB %d:\n------\n", tlb
);
3052 tlbcfg
= mfspr(SPRN_TLB0CFG
);
3055 tlbcfg
= mfspr(SPRN_TLB1CFG
);
3058 tlbcfg
= mfspr(SPRN_TLB2CFG
);
3061 tlbcfg
= mfspr(SPRN_TLB3CFG
);
3064 printf("Unsupported TLB number !\n");
3067 nent
= tlbcfg
& 0xfff;
3068 assoc
= (tlbcfg
>> 24) & 0xff;
3069 for (i
= 0; i
< nent
; i
++) {
3070 u32 mas0
= MAS0_TLBSEL(tlb
);
3071 u32 mas1
= MAS1_TSIZE(BOOK3E_PAGESZ_4K
);
3074 int esel
= i
, cc
= i
;
3082 mas0
|= MAS0_ESEL(esel
);
3083 mtspr(SPRN_MAS0
, mas0
);
3084 mtspr(SPRN_MAS1
, mas1
);
3085 mtspr(SPRN_MAS2
, mas2
);
3086 asm volatile("tlbre 0,0,0" : : : "memory");
3087 mas1
= mfspr(SPRN_MAS1
);
3088 mas2
= mfspr(SPRN_MAS2
);
3089 mas7_mas3
= mfspr(SPRN_MAS7_MAS3
);
3090 if (assoc
&& (i
% assoc
) == 0)
3092 if (!(mas1
& MAS1_VALID
))
3095 printf("%04x- ", i
);
3097 printf("%04x-%c", cc
, 'A' + esel
);
3099 printf(" |%c", 'A' + esel
);
3101 printf(" %016llx %04x %s %c%c AS%c",
3103 (mas1
>> 16) & 0x3fff,
3104 pgsz_names
[(mas1
>> 7) & 0x1f],
3105 mas1
& MAS1_IND
? 'I' : ' ',
3106 mas1
& MAS1_IPROT
? 'P' : ' ',
3107 mas1
& MAS1_TS
? '1' : '0');
3108 printf(" %c%c%c%c%c%c%c",
3109 mas2
& MAS2_X0
? 'a' : ' ',
3110 mas2
& MAS2_X1
? 'v' : ' ',
3111 mas2
& MAS2_W
? 'w' : ' ',
3112 mas2
& MAS2_I
? 'i' : ' ',
3113 mas2
& MAS2_M
? 'm' : ' ',
3114 mas2
& MAS2_G
? 'g' : ' ',
3115 mas2
& MAS2_E
? 'e' : ' ');
3116 printf(" %016llx", mas7_mas3
& ramask
& ~0x7ffull
);
3117 if (mas1
& MAS1_IND
)
3119 pgsz_names
[(mas7_mas3
>> 1) & 0x1f]);
3121 printf(" U%c%c%c S%c%c%c\n",
3122 mas7_mas3
& MAS3_UX
? 'x' : ' ',
3123 mas7_mas3
& MAS3_UW
? 'w' : ' ',
3124 mas7_mas3
& MAS3_UR
? 'r' : ' ',
3125 mas7_mas3
& MAS3_SX
? 'x' : ' ',
3126 mas7_mas3
& MAS3_SW
? 'w' : ' ',
3127 mas7_mas3
& MAS3_SR
? 'r' : ' ');
3131 #endif /* CONFIG_PPC_BOOK3E */
3133 static void xmon_init(int enable
)
3137 __debugger_ipi
= xmon_ipi
;
3138 __debugger_bpt
= xmon_bpt
;
3139 __debugger_sstep
= xmon_sstep
;
3140 __debugger_iabr_match
= xmon_iabr_match
;
3141 __debugger_break_match
= xmon_break_match
;
3142 __debugger_fault_handler
= xmon_fault_handler
;
3145 __debugger_ipi
= NULL
;
3146 __debugger_bpt
= NULL
;
3147 __debugger_sstep
= NULL
;
3148 __debugger_iabr_match
= NULL
;
3149 __debugger_break_match
= NULL
;
3150 __debugger_fault_handler
= NULL
;
3154 #ifdef CONFIG_MAGIC_SYSRQ
3155 static void sysrq_handle_xmon(int key
)
3157 /* ensure xmon is enabled */
3159 debugger(get_irq_regs());
3162 static struct sysrq_key_op sysrq_xmon_op
= {
3163 .handler
= sysrq_handle_xmon
,
3164 .help_msg
= "xmon(x)",
3165 .action_msg
= "Entering xmon",
3168 static int __init
setup_xmon_sysrq(void)
3170 register_sysrq_key('x', &sysrq_xmon_op
);
3173 __initcall(setup_xmon_sysrq
);
3174 #endif /* CONFIG_MAGIC_SYSRQ */
3176 static int __initdata xmon_early
, xmon_off
;
3178 static int __init
early_parse_xmon(char *p
)
3180 if (!p
|| strncmp(p
, "early", 5) == 0) {
3181 /* just "xmon" is equivalent to "xmon=early" */
3184 } else if (strncmp(p
, "on", 2) == 0)
3186 else if (strncmp(p
, "off", 3) == 0)
3188 else if (strncmp(p
, "nobt", 4) == 0)
3189 xmon_no_auto_backtrace
= 1;
3195 early_param("xmon", early_parse_xmon
);
3197 void __init
xmon_setup(void)
3199 #ifdef CONFIG_XMON_DEFAULT
3207 #ifdef CONFIG_SPU_BASE
3211 u64 saved_mfc_sr1_RW
;
3212 u32 saved_spu_runcntl_RW
;
3213 unsigned long dump_addr
;
3217 #define XMON_NUM_SPUS 16 /* Enough for current hardware */
3219 static struct spu_info spu_info
[XMON_NUM_SPUS
];
3221 void xmon_register_spus(struct list_head
*list
)
3225 list_for_each_entry(spu
, list
, full_list
) {
3226 if (spu
->number
>= XMON_NUM_SPUS
) {
3231 spu_info
[spu
->number
].spu
= spu
;
3232 spu_info
[spu
->number
].stopped_ok
= 0;
3233 spu_info
[spu
->number
].dump_addr
= (unsigned long)
3234 spu_info
[spu
->number
].spu
->local_store
;
3238 static void stop_spus(void)
3244 for (i
= 0; i
< XMON_NUM_SPUS
; i
++) {
3245 if (!spu_info
[i
].spu
)
3248 if (setjmp(bus_error_jmp
) == 0) {
3249 catch_memory_errors
= 1;
3252 spu
= spu_info
[i
].spu
;
3254 spu_info
[i
].saved_spu_runcntl_RW
=
3255 in_be32(&spu
->problem
->spu_runcntl_RW
);
3257 tmp
= spu_mfc_sr1_get(spu
);
3258 spu_info
[i
].saved_mfc_sr1_RW
= tmp
;
3260 tmp
&= ~MFC_STATE1_MASTER_RUN_CONTROL_MASK
;
3261 spu_mfc_sr1_set(spu
, tmp
);
3266 spu_info
[i
].stopped_ok
= 1;
3268 printf("Stopped spu %.2d (was %s)\n", i
,
3269 spu_info
[i
].saved_spu_runcntl_RW
?
3270 "running" : "stopped");
3272 catch_memory_errors
= 0;
3273 printf("*** Error stopping spu %.2d\n", i
);
3275 catch_memory_errors
= 0;
3279 static void restart_spus(void)
3284 for (i
= 0; i
< XMON_NUM_SPUS
; i
++) {
3285 if (!spu_info
[i
].spu
)
3288 if (!spu_info
[i
].stopped_ok
) {
3289 printf("*** Error, spu %d was not successfully stopped"
3290 ", not restarting\n", i
);
3294 if (setjmp(bus_error_jmp
) == 0) {
3295 catch_memory_errors
= 1;
3298 spu
= spu_info
[i
].spu
;
3299 spu_mfc_sr1_set(spu
, spu_info
[i
].saved_mfc_sr1_RW
);
3300 out_be32(&spu
->problem
->spu_runcntl_RW
,
3301 spu_info
[i
].saved_spu_runcntl_RW
);
3306 printf("Restarted spu %.2d\n", i
);
3308 catch_memory_errors
= 0;
3309 printf("*** Error restarting spu %.2d\n", i
);
3311 catch_memory_errors
= 0;
3315 #define DUMP_WIDTH 23
3316 #define DUMP_VALUE(format, field, value) \
3318 if (setjmp(bus_error_jmp) == 0) { \
3319 catch_memory_errors = 1; \
3321 printf(" %-*s = "format"\n", DUMP_WIDTH, \
3326 catch_memory_errors = 0; \
3327 printf(" %-*s = *** Error reading field.\n", \
3328 DUMP_WIDTH, #field); \
3330 catch_memory_errors = 0; \
3333 #define DUMP_FIELD(obj, format, field) \
3334 DUMP_VALUE(format, field, obj->field)
3336 static void dump_spu_fields(struct spu
*spu
)
3338 printf("Dumping spu fields at address %p:\n", spu
);
3340 DUMP_FIELD(spu
, "0x%x", number
);
3341 DUMP_FIELD(spu
, "%s", name
);
3342 DUMP_FIELD(spu
, "0x%lx", local_store_phys
);
3343 DUMP_FIELD(spu
, "0x%p", local_store
);
3344 DUMP_FIELD(spu
, "0x%lx", ls_size
);
3345 DUMP_FIELD(spu
, "0x%x", node
);
3346 DUMP_FIELD(spu
, "0x%lx", flags
);
3347 DUMP_FIELD(spu
, "%d", class_0_pending
);
3348 DUMP_FIELD(spu
, "0x%lx", class_0_dar
);
3349 DUMP_FIELD(spu
, "0x%lx", class_1_dar
);
3350 DUMP_FIELD(spu
, "0x%lx", class_1_dsisr
);
3351 DUMP_FIELD(spu
, "0x%lx", irqs
[0]);
3352 DUMP_FIELD(spu
, "0x%lx", irqs
[1]);
3353 DUMP_FIELD(spu
, "0x%lx", irqs
[2]);
3354 DUMP_FIELD(spu
, "0x%x", slb_replace
);
3355 DUMP_FIELD(spu
, "%d", pid
);
3356 DUMP_FIELD(spu
, "0x%p", mm
);
3357 DUMP_FIELD(spu
, "0x%p", ctx
);
3358 DUMP_FIELD(spu
, "0x%p", rq
);
3359 DUMP_FIELD(spu
, "0x%p", timestamp
);
3360 DUMP_FIELD(spu
, "0x%lx", problem_phys
);
3361 DUMP_FIELD(spu
, "0x%p", problem
);
3362 DUMP_VALUE("0x%x", problem
->spu_runcntl_RW
,
3363 in_be32(&spu
->problem
->spu_runcntl_RW
));
3364 DUMP_VALUE("0x%x", problem
->spu_status_R
,
3365 in_be32(&spu
->problem
->spu_status_R
));
3366 DUMP_VALUE("0x%x", problem
->spu_npc_RW
,
3367 in_be32(&spu
->problem
->spu_npc_RW
));
3368 DUMP_FIELD(spu
, "0x%p", priv2
);
3369 DUMP_FIELD(spu
, "0x%p", pdata
);
3373 spu_inst_dump(unsigned long adr
, long count
, int praddr
)
3375 return generic_inst_dump(adr
, count
, praddr
, print_insn_spu
);
3378 static void dump_spu_ls(unsigned long num
, int subcmd
)
3380 unsigned long offset
, addr
, ls_addr
;
3382 if (setjmp(bus_error_jmp
) == 0) {
3383 catch_memory_errors
= 1;
3385 ls_addr
= (unsigned long)spu_info
[num
].spu
->local_store
;
3389 catch_memory_errors
= 0;
3390 printf("*** Error: accessing spu info for spu %d\n", num
);
3393 catch_memory_errors
= 0;
3395 if (scanhex(&offset
))
3396 addr
= ls_addr
+ offset
;
3398 addr
= spu_info
[num
].dump_addr
;
3400 if (addr
>= ls_addr
+ LS_SIZE
) {
3401 printf("*** Error: address outside of local store\n");
3407 addr
+= spu_inst_dump(addr
, 16, 1);
3417 spu_info
[num
].dump_addr
= addr
;
3420 static int do_spu_cmd(void)
3422 static unsigned long num
= 0;
3423 int cmd
, subcmd
= 0;
3435 if (isxdigit(subcmd
) || subcmd
== '\n')
3439 if (num
>= XMON_NUM_SPUS
|| !spu_info
[num
].spu
) {
3440 printf("*** Error: invalid spu number\n");
3446 dump_spu_fields(spu_info
[num
].spu
);
3449 dump_spu_ls(num
, subcmd
);
3460 #else /* ! CONFIG_SPU_BASE */
3461 static int do_spu_cmd(void)