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/signal.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/debugfs.h>
33 #include <asm/ptrace.h>
35 #include <asm/string.h>
37 #include <asm/machdep.h>
39 #include <asm/processor.h>
40 #include <asm/pgtable.h>
42 #include <asm/mmu_context.h>
43 #include <asm/cputable.h>
45 #include <asm/sstep.h>
46 #include <asm/irq_regs.h>
48 #include <asm/spu_priv1.h>
49 #include <asm/setjmp.h>
51 #include <asm/debug.h>
52 #include <asm/hw_breakpoint.h>
55 #include <asm/firmware.h>
58 #include <asm/hvcall.h>
62 #if defined(CONFIG_PPC_SPLPAR)
63 #include <asm/plpar_wrappers.h>
65 static inline long plapr_set_ciabr(unsigned long ciabr) {return 0; };
72 static cpumask_t cpus_in_xmon = CPU_MASK_NONE;
73 static unsigned long xmon_taken = 1;
74 static int xmon_owner;
78 #endif /* CONFIG_SMP */
80 static unsigned long in_xmon __read_mostly = 0;
81 static int xmon_on = IS_ENABLED(CONFIG_XMON_DEFAULT);
83 static unsigned long adrs;
85 #define MAX_DUMP (128 * 1024)
86 static unsigned long ndump = 64;
87 static unsigned long nidump = 16;
88 static unsigned long ncsum = 4096;
90 static char tmpstr[128];
92 static long bus_error_jmp[JMP_BUF_LEN];
93 static int catch_memory_errors;
94 static int catch_spr_faults;
95 static long *xmon_fault_jmp[NR_CPUS];
97 /* Breakpoint stuff */
99 unsigned long address;
100 unsigned int instr[2];
106 /* Bits in bpt.enabled */
112 static struct bpt bpts[NBPTS];
113 static struct bpt dabr;
114 static struct bpt *iabr;
115 static unsigned bpinstr = 0x7fe00008; /* trap */
117 #define BP_NUM(bp) ((bp) - bpts + 1)
120 static int cmds(struct pt_regs *);
121 static int mread(unsigned long, void *, int);
122 static int mwrite(unsigned long, void *, int);
123 static int handle_fault(struct pt_regs *);
124 static void byterev(unsigned char *, int);
125 static void memex(void);
126 static int bsesc(void);
127 static void dump(void);
128 static void prdump(unsigned long, long);
129 static int ppc_inst_dump(unsigned long, long, int);
130 static void dump_log_buf(void);
132 #ifdef CONFIG_PPC_POWERNV
133 static void dump_opal_msglog(void);
135 static inline void dump_opal_msglog(void)
137 printf("Machine is not running OPAL firmware.\n");
141 static void backtrace(struct pt_regs *);
142 static void excprint(struct pt_regs *);
143 static void prregs(struct pt_regs *);
144 static void memops(int);
145 static void memlocate(void);
146 static void memzcan(void);
147 static void memdiffs(unsigned char *, unsigned char *, unsigned, unsigned);
149 int scanhex(unsigned long *valp);
150 static void scannl(void);
151 static int hexdigit(int);
152 void getstring(char *, int);
153 static void flush_input(void);
154 static int inchar(void);
155 static void take_input(char *);
156 static int read_spr(int, unsigned long *);
157 static void write_spr(int, unsigned long);
158 static void super_regs(void);
159 static void remove_bpts(void);
160 static void insert_bpts(void);
161 static void remove_cpu_bpts(void);
162 static void insert_cpu_bpts(void);
163 static struct bpt *at_breakpoint(unsigned long pc);
164 static struct bpt *in_breakpoint_table(unsigned long pc, unsigned long *offp);
165 static int do_step(struct pt_regs *);
166 static void bpt_cmds(void);
167 static void cacheflush(void);
168 static int cpu_cmd(void);
169 static void csum(void);
170 static void bootcmds(void);
171 static void proccall(void);
172 static void show_tasks(void);
173 void dump_segments(void);
174 static void symbol_lookup(void);
175 static void xmon_show_stack(unsigned long sp, unsigned long lr,
177 static void xmon_print_symbol(unsigned long address, const char *mid,
179 static const char *getvecname(unsigned long vec);
181 static int do_spu_cmd(void);
184 static void dump_tlb_44x(void);
186 #ifdef CONFIG_PPC_BOOK3E
187 static void dump_tlb_book3e(void);
196 #ifdef __LITTLE_ENDIAN__
197 #define GETWORD(v) (((v)[3] << 24) + ((v)[2] << 16) + ((v)[1] << 8) + (v)[0])
199 #define GETWORD(v) (((v)[0] << 24) + ((v)[1] << 16) + ((v)[2] << 8) + (v)[3])
202 static char *help_string = "\
204 b show breakpoints\n\
205 bd set data breakpoint\n\
206 bi set instruction breakpoint\n\
207 bc clear breakpoint\n"
210 c print cpus stopped in xmon\n\
211 c# try to switch to cpu number h (in hex)\n"
216 d1 dump 1 byte values\n\
217 d2 dump 2 byte values\n\
218 d4 dump 4 byte values\n\
219 d8 dump 8 byte values\n\
220 di dump instructions\n\
221 df dump float values\n\
222 dd dump double values\n\
223 dl dump the kernel log buffer\n"
224 #ifdef CONFIG_PPC_POWERNV
226 do dump the OPAL message log\n"
230 dp[#] dump paca for current cpu, or cpu #\n\
231 dpa dump paca for all possible cpus\n"
234 dr dump stream of raw bytes\n\
235 dt dump the tracing buffers (uses printk)\n\
237 #ifdef CONFIG_PPC_POWERNV
238 " dx# dump xive on CPU #\n\
239 dxi# dump xive irq state #\n\
240 dxa dump xive on all CPUs\n"
242 " e print exception information\n\
244 la lookup symbol+offset of specified address\n\
245 ls lookup address of specified symbol\n\
246 m examine/change memory\n\
247 mm move a block of memory\n\
248 ms set a block of memory\n\
249 md compare two blocks of memory\n\
250 ml locate a block of memory\n\
251 mz zero a block of memory\n\
252 mi show information about memory allocation\n\
253 p call a procedure\n\
254 P list processes/tasks\n\
257 #ifdef CONFIG_SPU_BASE
258 " ss stop execution on all spus\n\
259 sr restore execution on stopped spus\n\
260 sf # dump spu fields for spu # (in hex)\n\
261 sd # dump spu local store for spu # (in hex)\n\
262 sdi # disassemble spu local store for spu # (in hex)\n"
264 " S print special registers\n\
267 Sw #v write v to SPR #\n\
269 x exit monitor and recover\n\
270 X exit monitor and don't recover\n"
271 #if defined(CONFIG_PPC64) && !defined(CONFIG_PPC_BOOK3E)
272 " u dump segment table or SLB\n"
273 #elif defined(CONFIG_PPC_STD_MMU_32)
274 " u dump segment registers\n"
275 #elif defined(CONFIG_44x) || defined(CONFIG_PPC_BOOK3E)
279 " # n limit output to n lines per page (for dp, dpa, dl)\n"
284 static struct pt_regs *xmon_regs;
286 static inline void sync(void)
288 asm volatile("sync; isync");
291 static inline void store_inst(void *p)
293 asm volatile ("dcbst 0,%0; sync; icbi 0,%0; isync" : : "r" (p));
296 static inline void cflush(void *p)
298 asm volatile ("dcbf 0,%0; icbi 0,%0" : : "r" (p));
301 static inline void cinval(void *p)
303 asm volatile ("dcbi 0,%0; icbi 0,%0" : : "r" (p));
307 * write_ciabr() - write the CIABR SPR
308 * @ciabr: The value to write.
310 * This function writes a value to the CIARB register either directly
311 * through mtspr instruction if the kernel is in HV privilege mode or
312 * call a hypervisor function to achieve the same in case the kernel
313 * is in supervisor privilege mode.
315 static void write_ciabr(unsigned long ciabr)
317 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
320 if (cpu_has_feature(CPU_FTR_HVMODE)) {
321 mtspr(SPRN_CIABR, ciabr);
324 plapr_set_ciabr(ciabr);
328 * set_ciabr() - set the CIABR
329 * @addr: The value to set.
331 * This function sets the correct privilege value into the the HW
332 * breakpoint address before writing it up in the CIABR register.
334 static void set_ciabr(unsigned long addr)
338 if (cpu_has_feature(CPU_FTR_HVMODE))
339 addr |= CIABR_PRIV_HYPER;
341 addr |= CIABR_PRIV_SUPER;
346 * Disable surveillance (the service processor watchdog function)
347 * while we are in xmon.
348 * XXX we should re-enable it when we leave. :)
350 #define SURVEILLANCE_TOKEN 9000
352 static inline void disable_surveillance(void)
354 #ifdef CONFIG_PPC_PSERIES
355 /* Since this can't be a module, args should end up below 4GB. */
356 static struct rtas_args args;
360 * At this point we have got all the cpus we can into
361 * xmon, so there is hopefully no other cpu calling RTAS
362 * at the moment, even though we don't take rtas.lock.
363 * If we did try to take rtas.lock there would be a
364 * real possibility of deadlock.
366 token = rtas_token("set-indicator");
367 if (token == RTAS_UNKNOWN_SERVICE)
370 rtas_call_unlocked(&args, token, 3, 1, NULL, SURVEILLANCE_TOKEN, 0, 0);
372 #endif /* CONFIG_PPC_PSERIES */
376 static int xmon_speaker;
378 static void get_output_lock(void)
380 int me = smp_processor_id() + 0x100;
381 int last_speaker = 0, prev;
384 if (xmon_speaker == me)
388 last_speaker = cmpxchg(&xmon_speaker, 0, me);
389 if (last_speaker == 0)
393 * Wait a full second for the lock, we might be on a slow
394 * console, but check every 100us.
397 while (xmon_speaker == last_speaker) {
403 /* hostile takeover */
404 prev = cmpxchg(&xmon_speaker, last_speaker, me);
405 if (prev == last_speaker)
412 static void release_output_lock(void)
417 int cpus_are_in_xmon(void)
419 return !cpumask_empty(&cpus_in_xmon);
423 static inline int unrecoverable_excp(struct pt_regs *regs)
425 #if defined(CONFIG_4xx) || defined(CONFIG_PPC_BOOK3E)
426 /* We have no MSR_RI bit on 4xx or Book3e, so we simply return false */
429 return ((regs->msr & MSR_RI) == 0);
433 static int xmon_core(struct pt_regs *regs, int fromipi)
437 long recurse_jmp[JMP_BUF_LEN];
438 unsigned long offset;
443 unsigned long timeout;
446 local_irq_save(flags);
449 bp = in_breakpoint_table(regs->nip, &offset);
451 regs->nip = bp->address + offset;
452 atomic_dec(&bp->ref_count);
458 cpu = smp_processor_id();
459 if (cpumask_test_cpu(cpu, &cpus_in_xmon)) {
461 * We catch SPR read/write faults here because the 0x700, 0xf60
462 * etc. handlers don't call debugger_fault_handler().
464 if (catch_spr_faults)
465 longjmp(bus_error_jmp, 1);
468 printf("cpu 0x%x: Exception %lx %s in xmon, "
469 "returning to main loop\n",
470 cpu, regs->trap, getvecname(TRAP(regs)));
471 release_output_lock();
472 longjmp(xmon_fault_jmp[cpu], 1);
475 if (setjmp(recurse_jmp) != 0) {
476 if (!in_xmon || !xmon_gate) {
478 printf("xmon: WARNING: bad recursive fault "
479 "on cpu 0x%x\n", cpu);
480 release_output_lock();
483 secondary = !(xmon_taken && cpu == xmon_owner);
487 xmon_fault_jmp[cpu] = recurse_jmp;
490 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) == (MSR_IR|MSR_64BIT))
491 bp = at_breakpoint(regs->nip);
492 if (bp || unrecoverable_excp(regs))
499 printf("cpu 0x%x stopped at breakpoint 0x%lx (",
501 xmon_print_symbol(regs->nip, " ", ")\n");
503 if (unrecoverable_excp(regs))
504 printf("WARNING: exception is not recoverable, "
506 release_output_lock();
509 cpumask_set_cpu(cpu, &cpus_in_xmon);
513 while (secondary && !xmon_gate) {
517 secondary = test_and_set_bit(0, &in_xmon);
522 if (!secondary && !xmon_gate) {
523 /* we are the first cpu to come in */
524 /* interrupt other cpu(s) */
525 int ncpus = num_online_cpus();
530 smp_send_debugger_break();
531 /* wait for other cpus to come in */
532 for (timeout = 100000000; timeout != 0; --timeout) {
533 if (cpumask_weight(&cpus_in_xmon) >= ncpus)
539 disable_surveillance();
540 /* for breakpoint or single step, print the current instr. */
541 if (bp || TRAP(regs) == 0xd00)
542 ppc_inst_dump(regs->nip, 1, 0);
543 printf("enter ? for help\n");
552 if (cpu == xmon_owner) {
553 if (!test_and_set_bit(0, &xmon_taken)) {
558 while (cpu == xmon_owner)
572 /* have switched to some other cpu */
577 cpumask_clear_cpu(cpu, &cpus_in_xmon);
578 xmon_fault_jmp[cpu] = NULL;
580 /* UP is simple... */
582 printf("Exception %lx %s in xmon, returning to main loop\n",
583 regs->trap, getvecname(TRAP(regs)));
584 longjmp(xmon_fault_jmp[0], 1);
586 if (setjmp(recurse_jmp) == 0) {
587 xmon_fault_jmp[0] = recurse_jmp;
591 bp = at_breakpoint(regs->nip);
593 printf("Stopped at breakpoint %lx (", BP_NUM(bp));
594 xmon_print_symbol(regs->nip, " ", ")\n");
596 if (unrecoverable_excp(regs))
597 printf("WARNING: exception is not recoverable, "
600 disable_surveillance();
601 /* for breakpoint or single step, print the current instr. */
602 if (bp || TRAP(regs) == 0xd00)
603 ppc_inst_dump(regs->nip, 1, 0);
604 printf("enter ? for help\n");
614 if (regs->msr & MSR_DE) {
615 bp = at_breakpoint(regs->nip);
617 regs->nip = (unsigned long) &bp->instr[0];
618 atomic_inc(&bp->ref_count);
622 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) == (MSR_IR|MSR_64BIT)) {
623 bp = at_breakpoint(regs->nip);
625 int stepped = emulate_step(regs, bp->instr[0]);
627 regs->nip = (unsigned long) &bp->instr[0];
628 atomic_inc(&bp->ref_count);
629 } else if (stepped < 0) {
630 printf("Couldn't single-step %s instruction\n",
631 (IS_RFID(bp->instr[0])? "rfid": "mtmsrd"));
638 touch_nmi_watchdog();
639 local_irq_restore(flags);
641 return cmd != 'X' && cmd != EOF;
644 int xmon(struct pt_regs *excp)
649 ppc_save_regs(®s);
653 return xmon_core(excp, 0);
657 irqreturn_t xmon_irq(int irq, void *d)
660 local_irq_save(flags);
661 printf("Keyboard interrupt\n");
662 xmon(get_irq_regs());
663 local_irq_restore(flags);
667 static int xmon_bpt(struct pt_regs *regs)
670 unsigned long offset;
672 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) != (MSR_IR|MSR_64BIT))
675 /* Are we at the trap at bp->instr[1] for some bp? */
676 bp = in_breakpoint_table(regs->nip, &offset);
677 if (bp != NULL && offset == 4) {
678 regs->nip = bp->address + 4;
679 atomic_dec(&bp->ref_count);
683 /* Are we at a breakpoint? */
684 bp = at_breakpoint(regs->nip);
693 static int xmon_sstep(struct pt_regs *regs)
701 static int xmon_break_match(struct pt_regs *regs)
703 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) != (MSR_IR|MSR_64BIT))
705 if (dabr.enabled == 0)
711 static int xmon_iabr_match(struct pt_regs *regs)
713 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) != (MSR_IR|MSR_64BIT))
721 static int xmon_ipi(struct pt_regs *regs)
724 if (in_xmon && !cpumask_test_cpu(smp_processor_id(), &cpus_in_xmon))
730 static int xmon_fault_handler(struct pt_regs *regs)
733 unsigned long offset;
735 if (in_xmon && catch_memory_errors)
736 handle_fault(regs); /* doesn't return */
738 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) == (MSR_IR|MSR_64BIT)) {
739 bp = in_breakpoint_table(regs->nip, &offset);
741 regs->nip = bp->address + offset;
742 atomic_dec(&bp->ref_count);
749 static struct bpt *at_breakpoint(unsigned long pc)
755 for (i = 0; i < NBPTS; ++i, ++bp)
756 if (bp->enabled && pc == bp->address)
761 static struct bpt *in_breakpoint_table(unsigned long nip, unsigned long *offp)
765 off = nip - (unsigned long) bpts;
766 if (off >= sizeof(bpts))
768 off %= sizeof(struct bpt);
769 if (off != offsetof(struct bpt, instr[0])
770 && off != offsetof(struct bpt, instr[1]))
772 *offp = off - offsetof(struct bpt, instr[0]);
773 return (struct bpt *) (nip - off);
776 static struct bpt *new_breakpoint(unsigned long a)
781 bp = at_breakpoint(a);
785 for (bp = bpts; bp < &bpts[NBPTS]; ++bp) {
786 if (!bp->enabled && atomic_read(&bp->ref_count) == 0) {
788 bp->instr[1] = bpinstr;
789 store_inst(&bp->instr[1]);
794 printf("Sorry, no free breakpoints. Please clear one first.\n");
798 static void insert_bpts(void)
804 for (i = 0; i < NBPTS; ++i, ++bp) {
805 if ((bp->enabled & (BP_TRAP|BP_CIABR)) == 0)
807 if (mread(bp->address, &bp->instr[0], 4) != 4) {
808 printf("Couldn't read instruction at %lx, "
809 "disabling breakpoint there\n", bp->address);
813 if (IS_MTMSRD(bp->instr[0]) || IS_RFID(bp->instr[0])) {
814 printf("Breakpoint at %lx is on an mtmsrd or rfid "
815 "instruction, disabling it\n", bp->address);
819 store_inst(&bp->instr[0]);
820 if (bp->enabled & BP_CIABR)
822 if (mwrite(bp->address, &bpinstr, 4) != 4) {
823 printf("Couldn't write instruction at %lx, "
824 "disabling breakpoint there\n", bp->address);
825 bp->enabled &= ~BP_TRAP;
828 store_inst((void *)bp->address);
832 static void insert_cpu_bpts(void)
834 struct arch_hw_breakpoint brk;
837 brk.address = dabr.address;
838 brk.type = (dabr.enabled & HW_BRK_TYPE_DABR) | HW_BRK_TYPE_PRIV_ALL;
840 __set_breakpoint(&brk);
844 set_ciabr(iabr->address);
847 static void remove_bpts(void)
854 for (i = 0; i < NBPTS; ++i, ++bp) {
855 if ((bp->enabled & (BP_TRAP|BP_CIABR)) != BP_TRAP)
857 if (mread(bp->address, &instr, 4) == 4
859 && mwrite(bp->address, &bp->instr, 4) != 4)
860 printf("Couldn't remove breakpoint at %lx\n",
863 store_inst((void *)bp->address);
867 static void remove_cpu_bpts(void)
869 hw_breakpoint_disable();
873 static void set_lpp_cmd(void)
877 if (!scanhex(&lpp)) {
878 printf("Invalid number.\n");
881 xmon_set_pagination_lpp(lpp);
883 /* Command interpreting routine */
884 static char *last_cmd;
887 cmds(struct pt_regs *excp)
894 xmon_show_stack(excp->gpr[1], excp->link, excp->nip);
898 printf("%x:", smp_processor_id());
899 #endif /* CONFIG_SMP */
905 if (last_cmd == NULL)
907 take_input(last_cmd);
941 prregs(excp); /* print regs */
956 if (do_spu_cmd() == 0)
965 printf(" <no input ...>\n");
969 xmon_puts(help_string);
993 #ifdef CONFIG_PPC_STD_MMU
997 #elif defined(CONFIG_44x)
1001 #elif defined(CONFIG_PPC_BOOK3E)
1007 printf("Unrecognized command: ");
1009 if (' ' < cmd && cmd <= '~')
1012 printf("\\x%x", cmd);
1014 } while (cmd != '\n');
1015 printf(" (type ? for help)\n");
1022 static int do_step(struct pt_regs *regs)
1024 regs->msr |= MSR_DE;
1025 mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) | DBCR0_IC | DBCR0_IDM);
1030 * Step a single instruction.
1031 * Some instructions we emulate, others we execute with MSR_SE set.
1033 static int do_step(struct pt_regs *regs)
1038 /* check we are in 64-bit kernel mode, translation enabled */
1039 if ((regs->msr & (MSR_64BIT|MSR_PR|MSR_IR)) == (MSR_64BIT|MSR_IR)) {
1040 if (mread(regs->nip, &instr, 4) == 4) {
1041 stepped = emulate_step(regs, instr);
1043 printf("Couldn't single-step %s instruction\n",
1044 (IS_RFID(instr)? "rfid": "mtmsrd"));
1048 regs->trap = 0xd00 | (regs->trap & 1);
1049 printf("stepped to ");
1050 xmon_print_symbol(regs->nip, " ", "\n");
1051 ppc_inst_dump(regs->nip, 1, 0);
1056 regs->msr |= MSR_SE;
1061 static void bootcmds(void)
1067 ppc_md.restart(NULL);
1068 else if (cmd == 'h')
1070 else if (cmd == 'p')
1075 static int cpu_cmd(void)
1078 unsigned long cpu, first_cpu, last_cpu;
1081 if (!scanhex(&cpu)) {
1082 /* print cpus waiting or in xmon */
1083 printf("cpus stopped:");
1084 last_cpu = first_cpu = NR_CPUS;
1085 for_each_possible_cpu(cpu) {
1086 if (cpumask_test_cpu(cpu, &cpus_in_xmon)) {
1087 if (cpu == last_cpu + 1) {
1090 if (last_cpu != first_cpu)
1091 printf("-0x%lx", last_cpu);
1092 last_cpu = first_cpu = cpu;
1093 printf(" 0x%lx", cpu);
1097 if (last_cpu != first_cpu)
1098 printf("-0x%lx", last_cpu);
1102 /* try to switch to cpu specified */
1103 if (!cpumask_test_cpu(cpu, &cpus_in_xmon)) {
1104 printf("cpu 0x%x isn't in xmon\n", cpu);
1111 while (!xmon_taken) {
1112 if (--timeout == 0) {
1113 if (test_and_set_bit(0, &xmon_taken))
1115 /* take control back */
1117 xmon_owner = smp_processor_id();
1118 printf("cpu 0x%x didn't take control\n", cpu);
1126 #endif /* CONFIG_SMP */
1129 static unsigned short fcstab[256] = {
1130 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
1131 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
1132 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
1133 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
1134 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
1135 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
1136 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
1137 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
1138 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
1139 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
1140 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
1141 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
1142 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
1143 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
1144 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
1145 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
1146 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
1147 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
1148 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
1149 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
1150 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
1151 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
1152 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
1153 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
1154 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
1155 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
1156 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
1157 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
1158 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
1159 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
1160 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
1161 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
1164 #define FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
1173 if (!scanhex(&adrs))
1175 if (!scanhex(&ncsum))
1178 for (i = 0; i < ncsum; ++i) {
1179 if (mread(adrs+i, &v, 1) == 0) {
1180 printf("csum stopped at "REG"\n", adrs+i);
1185 printf("%x\n", fcs);
1189 * Check if this is a suitable place to put a breakpoint.
1191 static long check_bp_loc(unsigned long addr)
1196 if (!is_kernel_addr(addr)) {
1197 printf("Breakpoints may only be placed at kernel addresses\n");
1200 if (!mread(addr, &instr, sizeof(instr))) {
1201 printf("Can't read instruction at address %lx\n", addr);
1204 if (IS_MTMSRD(instr) || IS_RFID(instr)) {
1205 printf("Breakpoints may not be placed on mtmsrd or rfid "
1212 static char *breakpoint_help_string =
1213 "Breakpoint command usage:\n"
1214 "b show breakpoints\n"
1215 "b <addr> [cnt] set breakpoint at given instr addr\n"
1216 "bc clear all breakpoints\n"
1217 "bc <n/addr> clear breakpoint number n or at addr\n"
1218 "bi <addr> [cnt] set hardware instr breakpoint (POWER8 only)\n"
1219 "bd <addr> [cnt] set hardware data breakpoint\n"
1229 const char badaddr[] = "Only kernel addresses are permitted "
1230 "for breakpoints\n";
1235 case 'd': /* bd - hardware data breakpoint */
1240 else if (cmd == 'w')
1246 if (scanhex(&dabr.address)) {
1247 if (!is_kernel_addr(dabr.address)) {
1251 dabr.address &= ~HW_BRK_TYPE_DABR;
1252 dabr.enabled = mode | BP_DABR;
1256 case 'i': /* bi - hardware instr breakpoint */
1257 if (!cpu_has_feature(CPU_FTR_ARCH_207S)) {
1258 printf("Hardware instruction breakpoint "
1259 "not supported on this cpu\n");
1263 iabr->enabled &= ~BP_CIABR;
1268 if (!check_bp_loc(a))
1270 bp = new_breakpoint(a);
1272 bp->enabled |= BP_CIABR;
1280 /* clear all breakpoints */
1281 for (i = 0; i < NBPTS; ++i)
1282 bpts[i].enabled = 0;
1285 printf("All breakpoints cleared\n");
1289 if (a <= NBPTS && a >= 1) {
1290 /* assume a breakpoint number */
1291 bp = &bpts[a-1]; /* bp nums are 1 based */
1293 /* assume a breakpoint address */
1294 bp = at_breakpoint(a);
1296 printf("No breakpoint at %lx\n", a);
1301 printf("Cleared breakpoint %lx (", BP_NUM(bp));
1302 xmon_print_symbol(bp->address, " ", ")\n");
1310 printf(breakpoint_help_string);
1315 /* print all breakpoints */
1316 printf(" type address\n");
1318 printf(" data "REG" [", dabr.address);
1319 if (dabr.enabled & 1)
1321 if (dabr.enabled & 2)
1325 for (bp = bpts; bp < &bpts[NBPTS]; ++bp) {
1328 printf("%2x %s ", BP_NUM(bp),
1329 (bp->enabled & BP_CIABR) ? "inst": "trap");
1330 xmon_print_symbol(bp->address, " ", "\n");
1335 if (!check_bp_loc(a))
1337 bp = new_breakpoint(a);
1339 bp->enabled |= BP_TRAP;
1344 /* Very cheap human name for vector lookup. */
1346 const char *getvecname(unsigned long vec)
1351 case 0x100: ret = "(System Reset)"; break;
1352 case 0x200: ret = "(Machine Check)"; break;
1353 case 0x300: ret = "(Data Access)"; break;
1354 case 0x380: ret = "(Data SLB Access)"; break;
1355 case 0x400: ret = "(Instruction Access)"; break;
1356 case 0x480: ret = "(Instruction SLB Access)"; break;
1357 case 0x500: ret = "(Hardware Interrupt)"; break;
1358 case 0x600: ret = "(Alignment)"; break;
1359 case 0x700: ret = "(Program Check)"; break;
1360 case 0x800: ret = "(FPU Unavailable)"; break;
1361 case 0x900: ret = "(Decrementer)"; break;
1362 case 0x980: ret = "(Hypervisor Decrementer)"; break;
1363 case 0xa00: ret = "(Doorbell)"; break;
1364 case 0xc00: ret = "(System Call)"; break;
1365 case 0xd00: ret = "(Single Step)"; break;
1366 case 0xe40: ret = "(Emulation Assist)"; break;
1367 case 0xe60: ret = "(HMI)"; break;
1368 case 0xe80: ret = "(Hypervisor Doorbell)"; break;
1369 case 0xf00: ret = "(Performance Monitor)"; break;
1370 case 0xf20: ret = "(Altivec Unavailable)"; break;
1371 case 0x1300: ret = "(Instruction Breakpoint)"; break;
1372 case 0x1500: ret = "(Denormalisation)"; break;
1373 case 0x1700: ret = "(Altivec Assist)"; break;
1379 static void get_function_bounds(unsigned long pc, unsigned long *startp,
1380 unsigned long *endp)
1382 unsigned long size, offset;
1385 *startp = *endp = 0;
1388 if (setjmp(bus_error_jmp) == 0) {
1389 catch_memory_errors = 1;
1391 name = kallsyms_lookup(pc, &size, &offset, NULL, tmpstr);
1393 *startp = pc - offset;
1394 *endp = pc - offset + size;
1398 catch_memory_errors = 0;
1401 #define LRSAVE_OFFSET (STACK_FRAME_LR_SAVE * sizeof(unsigned long))
1402 #define MARKER_OFFSET (STACK_FRAME_MARKER * sizeof(unsigned long))
1404 static void xmon_show_stack(unsigned long sp, unsigned long lr,
1407 int max_to_print = 64;
1409 unsigned long newsp;
1410 unsigned long marker;
1411 struct pt_regs regs;
1413 while (max_to_print--) {
1414 if (!is_kernel_addr(sp)) {
1416 printf("SP (%lx) is in userspace\n", sp);
1420 if (!mread(sp + LRSAVE_OFFSET, &ip, sizeof(unsigned long))
1421 || !mread(sp, &newsp, sizeof(unsigned long))) {
1422 printf("Couldn't read stack frame at %lx\n", sp);
1427 * For the first stack frame, try to work out if
1428 * LR and/or the saved LR value in the bottommost
1429 * stack frame are valid.
1431 if ((pc | lr) != 0) {
1432 unsigned long fnstart, fnend;
1433 unsigned long nextip;
1436 get_function_bounds(pc, &fnstart, &fnend);
1439 mread(newsp + LRSAVE_OFFSET, &nextip,
1440 sizeof(unsigned long));
1442 if (!is_kernel_addr(lr)
1443 || (fnstart <= lr && lr < fnend))
1445 } else if (lr == nextip) {
1447 } else if (is_kernel_addr(lr)
1448 && !(fnstart <= lr && lr < fnend)) {
1449 printf("[link register ] ");
1450 xmon_print_symbol(lr, " ", "\n");
1453 printf("["REG"] ", sp);
1454 xmon_print_symbol(ip, " ", " (unreliable)\n");
1459 printf("["REG"] ", sp);
1460 xmon_print_symbol(ip, " ", "\n");
1463 /* Look for "regshere" marker to see if this is
1464 an exception frame. */
1465 if (mread(sp + MARKER_OFFSET, &marker, sizeof(unsigned long))
1466 && marker == STACK_FRAME_REGS_MARKER) {
1467 if (mread(sp + STACK_FRAME_OVERHEAD, ®s, sizeof(regs))
1469 printf("Couldn't read registers at %lx\n",
1470 sp + STACK_FRAME_OVERHEAD);
1473 printf("--- Exception: %lx %s at ", regs.trap,
1474 getvecname(TRAP(®s)));
1477 xmon_print_symbol(pc, " ", "\n");
1487 static void backtrace(struct pt_regs *excp)
1492 xmon_show_stack(sp, 0, 0);
1494 xmon_show_stack(excp->gpr[1], excp->link, excp->nip);
1498 static void print_bug_trap(struct pt_regs *regs)
1501 const struct bug_entry *bug;
1504 if (regs->msr & MSR_PR)
1505 return; /* not in kernel */
1506 addr = regs->nip; /* address of trap instruction */
1507 if (!is_kernel_addr(addr))
1509 bug = find_bug(regs->nip);
1512 if (is_warning_bug(bug))
1515 #ifdef CONFIG_DEBUG_BUGVERBOSE
1516 printf("kernel BUG at %s:%u!\n",
1517 bug->file, bug->line);
1519 printf("kernel BUG at %p!\n", (void *)bug->bug_addr);
1521 #endif /* CONFIG_BUG */
1524 static void excprint(struct pt_regs *fp)
1529 printf("cpu 0x%x: ", smp_processor_id());
1530 #endif /* CONFIG_SMP */
1533 printf("Vector: %lx %s at [%lx]\n", fp->trap, getvecname(trap), fp);
1535 xmon_print_symbol(fp->nip, ": ", "\n");
1537 printf(" lr: ", fp->link);
1538 xmon_print_symbol(fp->link, ": ", "\n");
1540 printf(" sp: %lx\n", fp->gpr[1]);
1541 printf(" msr: %lx\n", fp->msr);
1543 if (trap == 0x300 || trap == 0x380 || trap == 0x600 || trap == 0x200) {
1544 printf(" dar: %lx\n", fp->dar);
1546 printf(" dsisr: %lx\n", fp->dsisr);
1549 printf(" current = 0x%lx\n", current);
1551 printf(" paca = 0x%lx\t softe: %d\t irq_happened: 0x%02x\n",
1552 local_paca, local_paca->soft_enabled, local_paca->irq_happened);
1555 printf(" pid = %ld, comm = %s\n",
1556 current->pid, current->comm);
1562 printf(linux_banner);
1565 static void prregs(struct pt_regs *fp)
1569 struct pt_regs regs;
1571 if (scanhex(&base)) {
1572 if (setjmp(bus_error_jmp) == 0) {
1573 catch_memory_errors = 1;
1575 regs = *(struct pt_regs *)base;
1579 catch_memory_errors = 0;
1580 printf("*** Error reading registers from "REG"\n",
1584 catch_memory_errors = 0;
1589 if (FULL_REGS(fp)) {
1590 for (n = 0; n < 16; ++n)
1591 printf("R%.2ld = "REG" R%.2ld = "REG"\n",
1592 n, fp->gpr[n], n+16, fp->gpr[n+16]);
1594 for (n = 0; n < 7; ++n)
1595 printf("R%.2ld = "REG" R%.2ld = "REG"\n",
1596 n, fp->gpr[n], n+7, fp->gpr[n+7]);
1599 for (n = 0; n < 32; ++n) {
1600 printf("R%.2d = %.8x%s", n, fp->gpr[n],
1601 (n & 3) == 3? "\n": " ");
1602 if (n == 12 && !FULL_REGS(fp)) {
1609 xmon_print_symbol(fp->nip, " ", "\n");
1610 if (TRAP(fp) != 0xc00 && cpu_has_feature(CPU_FTR_CFAR)) {
1612 xmon_print_symbol(fp->orig_gpr3, " ", "\n");
1615 xmon_print_symbol(fp->link, " ", "\n");
1616 printf("msr = "REG" cr = %.8lx\n", fp->msr, fp->ccr);
1617 printf("ctr = "REG" xer = "REG" trap = %4lx\n",
1618 fp->ctr, fp->xer, fp->trap);
1620 if (trap == 0x300 || trap == 0x380 || trap == 0x600)
1621 printf("dar = "REG" dsisr = %.8lx\n", fp->dar, fp->dsisr);
1624 static void cacheflush(void)
1627 unsigned long nflush;
1632 scanhex((void *)&adrs);
1637 nflush = (nflush + L1_CACHE_BYTES - 1) / L1_CACHE_BYTES;
1638 if (setjmp(bus_error_jmp) == 0) {
1639 catch_memory_errors = 1;
1643 for (; nflush > 0; --nflush, adrs += L1_CACHE_BYTES)
1644 cflush((void *) adrs);
1646 for (; nflush > 0; --nflush, adrs += L1_CACHE_BYTES)
1647 cinval((void *) adrs);
1650 /* wait a little while to see if we get a machine check */
1653 catch_memory_errors = 0;
1656 extern unsigned long xmon_mfspr(int spr, unsigned long default_value);
1657 extern void xmon_mtspr(int spr, unsigned long value);
1660 read_spr(int n, unsigned long *vp)
1662 unsigned long ret = -1UL;
1665 if (setjmp(bus_error_jmp) == 0) {
1666 catch_spr_faults = 1;
1669 ret = xmon_mfspr(n, *vp);
1675 catch_spr_faults = 0;
1681 write_spr(int n, unsigned long val)
1683 if (setjmp(bus_error_jmp) == 0) {
1684 catch_spr_faults = 1;
1691 printf("SPR 0x%03x (%4d) Faulted during write\n", n, n);
1693 catch_spr_faults = 0;
1696 static void dump_206_sprs(void)
1699 if (!cpu_has_feature(CPU_FTR_ARCH_206))
1702 /* Actually some of these pre-date 2.06, but whatevs */
1704 printf("srr0 = %.16x srr1 = %.16x dsisr = %.8x\n",
1705 mfspr(SPRN_SRR0), mfspr(SPRN_SRR1), mfspr(SPRN_DSISR));
1706 printf("dscr = %.16x ppr = %.16x pir = %.8x\n",
1707 mfspr(SPRN_DSCR), mfspr(SPRN_PPR), mfspr(SPRN_PIR));
1709 if (!(mfmsr() & MSR_HV))
1712 printf("sdr1 = %.16x hdar = %.16x hdsisr = %.8x\n",
1713 mfspr(SPRN_SDR1), mfspr(SPRN_HDAR), mfspr(SPRN_HDSISR));
1714 printf("hsrr0 = %.16x hsrr1 = %.16x hdec = %.8x\n",
1715 mfspr(SPRN_HSRR0), mfspr(SPRN_HSRR1), mfspr(SPRN_HDEC));
1716 printf("lpcr = %.16x pcr = %.16x lpidr = %.8x\n",
1717 mfspr(SPRN_LPCR), mfspr(SPRN_PCR), mfspr(SPRN_LPID));
1718 printf("hsprg0 = %.16x hsprg1 = %.16x\n",
1719 mfspr(SPRN_HSPRG0), mfspr(SPRN_HSPRG1));
1720 printf("dabr = %.16x dabrx = %.16x\n",
1721 mfspr(SPRN_DABR), mfspr(SPRN_DABRX));
1725 static void dump_207_sprs(void)
1730 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
1733 printf("dpdes = %.16x tir = %.16x cir = %.8x\n",
1734 mfspr(SPRN_DPDES), mfspr(SPRN_TIR), mfspr(SPRN_CIR));
1736 printf("fscr = %.16x tar = %.16x pspb = %.8x\n",
1737 mfspr(SPRN_FSCR), mfspr(SPRN_TAR), mfspr(SPRN_PSPB));
1741 /* Only if TM has been enabled in the kernel */
1742 printf("tfhar = %.16x tfiar = %.16x texasr = %.16x\n",
1743 mfspr(SPRN_TFHAR), mfspr(SPRN_TFIAR),
1744 mfspr(SPRN_TEXASR));
1747 printf("mmcr0 = %.16x mmcr1 = %.16x mmcr2 = %.16x\n",
1748 mfspr(SPRN_MMCR0), mfspr(SPRN_MMCR1), mfspr(SPRN_MMCR2));
1749 printf("pmc1 = %.8x pmc2 = %.8x pmc3 = %.8x pmc4 = %.8x\n",
1750 mfspr(SPRN_PMC1), mfspr(SPRN_PMC2),
1751 mfspr(SPRN_PMC3), mfspr(SPRN_PMC4));
1752 printf("mmcra = %.16x siar = %.16x pmc5 = %.8x\n",
1753 mfspr(SPRN_MMCRA), mfspr(SPRN_SIAR), mfspr(SPRN_PMC5));
1754 printf("sdar = %.16x sier = %.16x pmc6 = %.8x\n",
1755 mfspr(SPRN_SDAR), mfspr(SPRN_SIER), mfspr(SPRN_PMC6));
1756 printf("ebbhr = %.16x ebbrr = %.16x bescr = %.16x\n",
1757 mfspr(SPRN_EBBHR), mfspr(SPRN_EBBRR), mfspr(SPRN_BESCR));
1759 if (!(msr & MSR_HV))
1762 printf("hfscr = %.16x dhdes = %.16x rpr = %.16x\n",
1763 mfspr(SPRN_HFSCR), mfspr(SPRN_DHDES), mfspr(SPRN_RPR));
1764 printf("dawr = %.16x dawrx = %.16x ciabr = %.16x\n",
1765 mfspr(SPRN_DAWR), mfspr(SPRN_DAWRX), mfspr(SPRN_CIABR));
1769 static void dump_one_spr(int spr, bool show_unimplemented)
1774 if (!read_spr(spr, &val)) {
1775 printf("SPR 0x%03x (%4d) Faulted during read\n", spr, spr);
1779 if (val == 0xdeadbeef) {
1780 /* Looks like read was a nop, confirm */
1782 if (!read_spr(spr, &val)) {
1783 printf("SPR 0x%03x (%4d) Faulted during read\n", spr, spr);
1787 if (val == 0x0badcafe) {
1788 if (show_unimplemented)
1789 printf("SPR 0x%03x (%4d) Unimplemented\n", spr, spr);
1794 printf("SPR 0x%03x (%4d) = 0x%lx\n", spr, spr, val);
1797 static void super_regs(void)
1799 static unsigned long regno;
1807 unsigned long sp, toc;
1808 asm("mr %0,1" : "=r" (sp) :);
1809 asm("mr %0,2" : "=r" (toc) :);
1811 printf("msr = "REG" sprg0 = "REG"\n",
1812 mfmsr(), mfspr(SPRN_SPRG0));
1813 printf("pvr = "REG" sprg1 = "REG"\n",
1814 mfspr(SPRN_PVR), mfspr(SPRN_SPRG1));
1815 printf("dec = "REG" sprg2 = "REG"\n",
1816 mfspr(SPRN_DEC), mfspr(SPRN_SPRG2));
1817 printf("sp = "REG" sprg3 = "REG"\n", sp, mfspr(SPRN_SPRG3));
1818 printf("toc = "REG" dar = "REG"\n", toc, mfspr(SPRN_DAR));
1829 read_spr(regno, &val);
1831 write_spr(regno, val);
1832 dump_one_spr(regno, true);
1837 dump_one_spr(regno, true);
1841 for (spr = 1; spr < 1024; ++spr)
1842 dump_one_spr(spr, false);
1850 * Stuff for reading and writing memory safely
1853 mread(unsigned long adrs, void *buf, int size)
1859 if (setjmp(bus_error_jmp) == 0) {
1860 catch_memory_errors = 1;
1866 *(u16 *)q = *(u16 *)p;
1869 *(u32 *)q = *(u32 *)p;
1872 *(u64 *)q = *(u64 *)p;
1875 for( ; n < size; ++n) {
1881 /* wait a little while to see if we get a machine check */
1885 catch_memory_errors = 0;
1890 mwrite(unsigned long adrs, void *buf, int size)
1896 if (setjmp(bus_error_jmp) == 0) {
1897 catch_memory_errors = 1;
1903 *(u16 *)p = *(u16 *)q;
1906 *(u32 *)p = *(u32 *)q;
1909 *(u64 *)p = *(u64 *)q;
1912 for ( ; n < size; ++n) {
1918 /* wait a little while to see if we get a machine check */
1922 printf("*** Error writing address "REG"\n", adrs + n);
1924 catch_memory_errors = 0;
1928 static int fault_type;
1929 static int fault_except;
1930 static char *fault_chars[] = { "--", "**", "##" };
1932 static int handle_fault(struct pt_regs *regs)
1934 fault_except = TRAP(regs);
1935 switch (TRAP(regs)) {
1947 longjmp(bus_error_jmp, 1);
1952 #define SWAP(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
1955 byterev(unsigned char *val, int size)
1961 SWAP(val[0], val[1], t);
1964 SWAP(val[0], val[3], t);
1965 SWAP(val[1], val[2], t);
1967 case 8: /* is there really any use for this? */
1968 SWAP(val[0], val[7], t);
1969 SWAP(val[1], val[6], t);
1970 SWAP(val[2], val[5], t);
1971 SWAP(val[3], val[4], t);
1979 static char *memex_help_string =
1980 "Memory examine command usage:\n"
1981 "m [addr] [flags] examine/change memory\n"
1982 " addr is optional. will start where left off.\n"
1983 " flags may include chars from this set:\n"
1984 " b modify by bytes (default)\n"
1985 " w modify by words (2 byte)\n"
1986 " l modify by longs (4 byte)\n"
1987 " d modify by doubleword (8 byte)\n"
1988 " r toggle reverse byte order mode\n"
1989 " n do not read memory (for i/o spaces)\n"
1990 " . ok to read (default)\n"
1991 "NOTE: flags are saved as defaults\n"
1994 static char *memex_subcmd_help_string =
1995 "Memory examine subcommands:\n"
1996 " hexval write this val to current location\n"
1997 " 'string' write chars from string to this location\n"
1998 " ' increment address\n"
1999 " ^ decrement address\n"
2000 " / increment addr by 0x10. //=0x100, ///=0x1000, etc\n"
2001 " \\ decrement addr by 0x10. \\\\=0x100, \\\\\\=0x1000, etc\n"
2002 " ` clear no-read flag\n"
2003 " ; stay at this addr\n"
2004 " v change to byte mode\n"
2005 " w change to word (2 byte) mode\n"
2006 " l change to long (4 byte) mode\n"
2007 " u change to doubleword (8 byte) mode\n"
2008 " m addr change current addr\n"
2009 " n toggle no-read flag\n"
2010 " r toggle byte reverse flag\n"
2011 " < count back up count bytes\n"
2012 " > count skip forward count bytes\n"
2013 " x exit this mode\n"
2019 int cmd, inc, i, nslash;
2021 unsigned char val[16];
2023 scanhex((void *)&adrs);
2026 printf(memex_help_string);
2032 while ((cmd = skipbl()) != '\n') {
2034 case 'b': size = 1; break;
2035 case 'w': size = 2; break;
2036 case 'l': size = 4; break;
2037 case 'd': size = 8; break;
2038 case 'r': brev = !brev; break;
2039 case 'n': mnoread = 1; break;
2040 case '.': mnoread = 0; break;
2049 n = mread(adrs, val, size);
2050 printf(REG"%c", adrs, brev? 'r': ' ');
2055 for (i = 0; i < n; ++i)
2056 printf("%.2x", val[i]);
2057 for (; i < size; ++i)
2058 printf("%s", fault_chars[fault_type]);
2065 for (i = 0; i < size; ++i)
2066 val[i] = n >> (i * 8);
2069 mwrite(adrs, val, size);
2082 else if( n == '\'' )
2084 for (i = 0; i < size; ++i)
2085 val[i] = n >> (i * 8);
2088 mwrite(adrs, val, size);
2124 adrs -= 1 << nslash;
2128 adrs += 1 << nslash;
2132 adrs += 1 << -nslash;
2136 adrs -= 1 << -nslash;
2139 scanhex((void *)&adrs);
2158 printf(memex_subcmd_help_string);
2173 case 'n': c = '\n'; break;
2174 case 'r': c = '\r'; break;
2175 case 'b': c = '\b'; break;
2176 case 't': c = '\t'; break;
2181 static void xmon_rawdump (unsigned long adrs, long ndump)
2184 unsigned char temp[16];
2186 for (n = ndump; n > 0;) {
2188 nr = mread(adrs, temp, r);
2190 for (m = 0; m < r; ++m) {
2192 printf("%.2x", temp[m]);
2194 printf("%s", fault_chars[fault_type]);
2204 static void dump_one_paca(int cpu)
2206 struct paca_struct *p;
2207 #ifdef CONFIG_PPC_STD_MMU_64
2211 if (setjmp(bus_error_jmp) != 0) {
2212 printf("*** Error dumping paca for cpu 0x%x!\n", cpu);
2216 catch_memory_errors = 1;
2221 printf("paca for cpu 0x%x @ %p:\n", cpu, p);
2223 printf(" %-*s = %s\n", 20, "possible", cpu_possible(cpu) ? "yes" : "no");
2224 printf(" %-*s = %s\n", 20, "present", cpu_present(cpu) ? "yes" : "no");
2225 printf(" %-*s = %s\n", 20, "online", cpu_online(cpu) ? "yes" : "no");
2227 #define DUMP(paca, name, format) \
2228 printf(" %-*s = %#-*"format"\t(0x%lx)\n", 20, #name, 18, paca->name, \
2229 offsetof(struct paca_struct, name));
2231 DUMP(p, lock_token, "x");
2232 DUMP(p, paca_index, "x");
2233 DUMP(p, kernel_toc, "lx");
2234 DUMP(p, kernelbase, "lx");
2235 DUMP(p, kernel_msr, "lx");
2236 DUMP(p, emergency_sp, "p");
2237 #ifdef CONFIG_PPC_BOOK3S_64
2238 DUMP(p, mc_emergency_sp, "p");
2239 DUMP(p, in_nmi, "x");
2240 DUMP(p, in_mce, "x");
2241 DUMP(p, hmi_event_available, "x");
2243 DUMP(p, data_offset, "lx");
2244 DUMP(p, hw_cpu_id, "x");
2245 DUMP(p, cpu_start, "x");
2246 DUMP(p, kexec_state, "x");
2247 #ifdef CONFIG_PPC_STD_MMU_64
2248 for (i = 0; i < SLB_NUM_BOLTED; i++) {
2251 if (!p->slb_shadow_ptr)
2254 esid = be64_to_cpu(p->slb_shadow_ptr->save_area[i].esid);
2255 vsid = be64_to_cpu(p->slb_shadow_ptr->save_area[i].vsid);
2258 printf(" slb_shadow[%d]: = 0x%016lx 0x%016lx\n",
2262 DUMP(p, vmalloc_sllp, "x");
2263 DUMP(p, slb_cache_ptr, "x");
2264 for (i = 0; i < SLB_CACHE_ENTRIES; i++)
2265 printf(" slb_cache[%d]: = 0x%016lx\n", i, p->slb_cache[i]);
2267 DUMP(p, dscr_default, "llx");
2268 #ifdef CONFIG_PPC_BOOK3E
2270 DUMP(p, kernel_pgd, "p");
2271 DUMP(p, tcd_ptr, "p");
2272 DUMP(p, mc_kstack, "p");
2273 DUMP(p, crit_kstack, "p");
2274 DUMP(p, dbg_kstack, "p");
2276 DUMP(p, __current, "p");
2277 DUMP(p, kstack, "lx");
2278 DUMP(p, stab_rr, "lx");
2279 DUMP(p, saved_r1, "lx");
2280 DUMP(p, trap_save, "x");
2281 DUMP(p, soft_enabled, "x");
2282 DUMP(p, irq_happened, "x");
2283 DUMP(p, io_sync, "x");
2284 DUMP(p, irq_work_pending, "x");
2285 DUMP(p, nap_state_lost, "x");
2286 DUMP(p, sprg_vdso, "llx");
2288 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
2289 DUMP(p, tm_scratch, "llx");
2292 #ifdef CONFIG_PPC_POWERNV
2293 DUMP(p, core_idle_state_ptr, "p");
2294 DUMP(p, thread_idle_state, "x");
2295 DUMP(p, thread_mask, "x");
2296 DUMP(p, subcore_sibling_mask, "x");
2299 DUMP(p, accounting.utime, "llx");
2300 DUMP(p, accounting.stime, "llx");
2301 DUMP(p, accounting.utime_scaled, "llx");
2302 DUMP(p, accounting.starttime, "llx");
2303 DUMP(p, accounting.starttime_user, "llx");
2304 DUMP(p, accounting.startspurr, "llx");
2305 DUMP(p, accounting.utime_sspurr, "llx");
2306 DUMP(p, accounting.steal_time, "llx");
2309 catch_memory_errors = 0;
2313 static void dump_all_pacas(void)
2317 if (num_possible_cpus() == 0) {
2318 printf("No possible cpus, use 'dp #' to dump individual cpus\n");
2322 for_each_possible_cpu(cpu)
2326 static void dump_pacas(void)
2337 termch = c; /* Put c back, it wasn't 'a' */
2342 dump_one_paca(xmon_owner);
2346 #ifdef CONFIG_PPC_POWERNV
2347 static void dump_one_xive(int cpu)
2349 unsigned int hwid = get_hard_smp_processor_id(cpu);
2351 opal_xive_dump(XIVE_DUMP_TM_HYP, hwid);
2352 opal_xive_dump(XIVE_DUMP_TM_POOL, hwid);
2353 opal_xive_dump(XIVE_DUMP_TM_OS, hwid);
2354 opal_xive_dump(XIVE_DUMP_TM_USER, hwid);
2355 opal_xive_dump(XIVE_DUMP_VP, hwid);
2356 opal_xive_dump(XIVE_DUMP_EMU_STATE, hwid);
2358 if (setjmp(bus_error_jmp) != 0) {
2359 catch_memory_errors = 0;
2360 printf("*** Error dumping xive on cpu %d\n", cpu);
2364 catch_memory_errors = 1;
2366 xmon_xive_do_dump(cpu);
2369 catch_memory_errors = 0;
2372 static void dump_all_xives(void)
2376 if (num_possible_cpus() == 0) {
2377 printf("No possible cpus, use 'dx #' to dump individual cpus\n");
2381 for_each_possible_cpu(cpu)
2385 static void dump_one_xive_irq(u32 num)
2392 rc = opal_xive_get_irq_config(num, &vp, &prio, &lirq);
2393 xmon_printf("IRQ 0x%x config: vp=0x%llx prio=%d lirq=0x%x (rc=%lld)\n",
2394 num, be64_to_cpu(vp), prio, be32_to_cpu(lirq), rc);
2397 static void dump_xives(void)
2406 } else if (c == 'i') {
2408 dump_one_xive_irq(num);
2412 termch = c; /* Put c back, it wasn't 'a' */
2417 dump_one_xive(xmon_owner);
2419 #endif /* CONFIG_PPC_POWERNV */
2421 static void dump_by_size(unsigned long addr, long count, int size)
2423 unsigned char temp[16];
2427 count = ALIGN(count, 16);
2429 for (i = 0; i < count; i += 16, addr += 16) {
2432 if (mread(addr, temp, 16) != 16) {
2433 printf("\nFaulted reading %d bytes from 0x"REG"\n", 16, addr);
2437 for (j = 0; j < 16; j += size) {
2440 case 1: val = temp[j]; break;
2441 case 2: val = *(u16 *)&temp[j]; break;
2442 case 4: val = *(u32 *)&temp[j]; break;
2443 case 8: val = *(u64 *)&temp[j]; break;
2447 printf("%0*lx", size * 2, val);
2456 static char last[] = { "d?\n" };
2463 xmon_start_pagination();
2465 xmon_end_pagination();
2469 #ifdef CONFIG_PPC_POWERNV
2471 xmon_start_pagination();
2473 xmon_end_pagination();
2481 scanhex((void *)&adrs);
2488 else if (nidump > MAX_DUMP)
2490 adrs += ppc_inst_dump(adrs, nidump, 1);
2492 } else if (c == 'l') {
2494 } else if (c == 'o') {
2496 } else if (c == 't') {
2497 ftrace_dump(DUMP_ALL);
2499 } else if (c == 'r') {
2503 xmon_rawdump(adrs, ndump);
2510 else if (ndump > MAX_DUMP)
2518 ndump = ALIGN(ndump, 16);
2519 dump_by_size(adrs, ndump, c - '0');
2524 prdump(adrs, ndump);
2533 prdump(unsigned long adrs, long ndump)
2535 long n, m, c, r, nr;
2536 unsigned char temp[16];
2538 for (n = ndump; n > 0;) {
2542 nr = mread(adrs, temp, r);
2544 for (m = 0; m < r; ++m) {
2545 if ((m & (sizeof(long) - 1)) == 0 && m > 0)
2548 printf("%.2x", temp[m]);
2550 printf("%s", fault_chars[fault_type]);
2552 for (; m < 16; ++m) {
2553 if ((m & (sizeof(long) - 1)) == 0)
2558 for (m = 0; m < r; ++m) {
2561 putchar(' ' <= c && c <= '~'? c: '.');
2574 typedef int (*instruction_dump_func)(unsigned long inst, unsigned long addr);
2577 generic_inst_dump(unsigned long adr, long count, int praddr,
2578 instruction_dump_func dump_func)
2581 unsigned long first_adr;
2582 unsigned long inst, last_inst = 0;
2583 unsigned char val[4];
2586 for (first_adr = adr; count > 0; --count, adr += 4) {
2587 nr = mread(adr, val, 4);
2590 const char *x = fault_chars[fault_type];
2591 printf(REG" %s%s%s%s\n", adr, x, x, x, x);
2595 inst = GETWORD(val);
2596 if (adr > first_adr && inst == last_inst) {
2606 printf(REG" %.8x", adr, inst);
2608 dump_func(inst, adr);
2611 return adr - first_adr;
2615 ppc_inst_dump(unsigned long adr, long count, int praddr)
2617 return generic_inst_dump(adr, count, praddr, print_insn_powerpc);
2621 print_address(unsigned long addr)
2623 xmon_print_symbol(addr, "\t# ", "");
2629 struct kmsg_dumper dumper = { .active = 1 };
2630 unsigned char buf[128];
2633 if (setjmp(bus_error_jmp) != 0) {
2634 printf("Error dumping printk buffer!\n");
2638 catch_memory_errors = 1;
2641 kmsg_dump_rewind_nolock(&dumper);
2642 xmon_start_pagination();
2643 while (kmsg_dump_get_line_nolock(&dumper, false, buf, sizeof(buf), &len)) {
2647 xmon_end_pagination();
2650 /* wait a little while to see if we get a machine check */
2652 catch_memory_errors = 0;
2655 #ifdef CONFIG_PPC_POWERNV
2656 static void dump_opal_msglog(void)
2658 unsigned char buf[128];
2662 if (!firmware_has_feature(FW_FEATURE_OPAL)) {
2663 printf("Machine is not running OPAL firmware.\n");
2667 if (setjmp(bus_error_jmp) != 0) {
2668 printf("Error dumping OPAL msglog!\n");
2672 catch_memory_errors = 1;
2675 xmon_start_pagination();
2676 while ((res = opal_msglog_copy(buf, pos, sizeof(buf) - 1))) {
2678 printf("Error dumping OPAL msglog! Error: %zd\n", res);
2685 xmon_end_pagination();
2688 /* wait a little while to see if we get a machine check */
2690 catch_memory_errors = 0;
2695 * Memory operations - move, set, print differences
2697 static unsigned long mdest; /* destination address */
2698 static unsigned long msrc; /* source address */
2699 static unsigned long mval; /* byte value to set memory to */
2700 static unsigned long mcount; /* # bytes to affect */
2701 static unsigned long mdiffs; /* max # differences to print */
2706 scanhex((void *)&mdest);
2707 if( termch != '\n' )
2709 scanhex((void *)(cmd == 's'? &mval: &msrc));
2710 if( termch != '\n' )
2712 scanhex((void *)&mcount);
2715 memmove((void *)mdest, (void *)msrc, mcount);
2718 memset((void *)mdest, mval, mcount);
2721 if( termch != '\n' )
2723 scanhex((void *)&mdiffs);
2724 memdiffs((unsigned char *)mdest, (unsigned char *)msrc, mcount, mdiffs);
2730 memdiffs(unsigned char *p1, unsigned char *p2, unsigned nb, unsigned maxpr)
2735 for( n = nb; n > 0; --n )
2736 if( *p1++ != *p2++ )
2737 if( ++prt <= maxpr )
2738 printf("%.16x %.2x # %.16x %.2x\n", p1 - 1,
2739 p1[-1], p2 - 1, p2[-1]);
2741 printf("Total of %d differences\n", prt);
2744 static unsigned mend;
2745 static unsigned mask;
2751 unsigned char val[4];
2754 scanhex((void *)&mdest);
2755 if (termch != '\n') {
2757 scanhex((void *)&mend);
2758 if (termch != '\n') {
2760 scanhex((void *)&mval);
2762 if (termch != '\n') termch = 0;
2763 scanhex((void *)&mask);
2767 for (a = mdest; a < mend; a += 4) {
2768 if (mread(a, val, 4) == 4
2769 && ((GETWORD(val) ^ mval) & mask) == 0) {
2770 printf("%.16x: %.16x\n", a, GETWORD(val));
2777 static unsigned long mskip = 0x1000;
2778 static unsigned long mlim = 0xffffffff;
2788 if (termch != '\n') termch = 0;
2790 if (termch != '\n') termch = 0;
2793 for (a = mdest; a < mlim; a += mskip) {
2794 ok = mread(a, &v, 1);
2796 printf("%.8x .. ", a);
2797 } else if (!ok && ook)
2798 printf("%.8x\n", a - mskip);
2804 printf("%.8x\n", a - mskip);
2807 static void show_task(struct task_struct *tsk)
2812 * Cloned from kdb_task_state_char(), which is not entirely
2813 * appropriate for calling from xmon. This could be moved
2814 * to a common, generic, routine used by both.
2816 state = (tsk->state == 0) ? 'R' :
2817 (tsk->state < 0) ? 'U' :
2818 (tsk->state & TASK_UNINTERRUPTIBLE) ? 'D' :
2819 (tsk->state & TASK_STOPPED) ? 'T' :
2820 (tsk->state & TASK_TRACED) ? 'C' :
2821 (tsk->exit_state & EXIT_ZOMBIE) ? 'Z' :
2822 (tsk->exit_state & EXIT_DEAD) ? 'E' :
2823 (tsk->state & TASK_INTERRUPTIBLE) ? 'S' : '?';
2825 printf("%p %016lx %6d %6d %c %2d %s\n", tsk,
2827 tsk->pid, tsk->parent->pid,
2828 state, task_thread_info(tsk)->cpu,
2832 static void show_tasks(void)
2835 struct task_struct *tsk = NULL;
2837 printf(" task_struct ->thread.ksp PID PPID S P CMD\n");
2840 tsk = (struct task_struct *)tskv;
2842 if (setjmp(bus_error_jmp) != 0) {
2843 catch_memory_errors = 0;
2844 printf("*** Error dumping task %p\n", tsk);
2848 catch_memory_errors = 1;
2854 for_each_process(tsk)
2859 catch_memory_errors = 0;
2862 static void proccall(void)
2864 unsigned long args[8];
2867 typedef unsigned long (*callfunc_t)(unsigned long, unsigned long,
2868 unsigned long, unsigned long, unsigned long,
2869 unsigned long, unsigned long, unsigned long);
2872 if (!scanhex(&adrs))
2876 for (i = 0; i < 8; ++i)
2878 for (i = 0; i < 8; ++i) {
2879 if (!scanhex(&args[i]) || termch == '\n')
2883 func = (callfunc_t) adrs;
2885 if (setjmp(bus_error_jmp) == 0) {
2886 catch_memory_errors = 1;
2888 ret = func(args[0], args[1], args[2], args[3],
2889 args[4], args[5], args[6], args[7]);
2891 printf("return value is 0x%lx\n", ret);
2893 printf("*** %x exception occurred\n", fault_except);
2895 catch_memory_errors = 0;
2898 /* Input scanning routines */
2909 while( c == ' ' || c == '\t' )
2915 static char *regnames[N_PTREGS] = {
2916 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2917 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
2918 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
2919 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
2920 "pc", "msr", "or3", "ctr", "lr", "xer", "ccr",
2926 "trap", "dar", "dsisr", "res"
2930 scanhex(unsigned long *vp)
2937 /* parse register name */
2941 for (i = 0; i < sizeof(regname) - 1; ++i) {
2950 for (i = 0; i < N_PTREGS; ++i) {
2951 if (strcmp(regnames[i], regname) == 0) {
2952 if (xmon_regs == NULL) {
2953 printf("regs not available\n");
2956 *vp = ((unsigned long *)xmon_regs)[i];
2960 printf("invalid register name '%%%s'\n", regname);
2964 /* skip leading "0x" if any */
2978 } else if (c == '$') {
2980 for (i=0; i<63; i++) {
2982 if (isspace(c) || c == '\0') {
2990 if (setjmp(bus_error_jmp) == 0) {
2991 catch_memory_errors = 1;
2993 *vp = kallsyms_lookup_name(tmpstr);
2996 catch_memory_errors = 0;
2998 printf("unknown symbol '%s'\n", tmpstr);
3031 static int hexdigit(int c)
3033 if( '0' <= c && c <= '9' )
3035 if( 'A' <= c && c <= 'F' )
3036 return c - ('A' - 10);
3037 if( 'a' <= c && c <= 'f' )
3038 return c - ('a' - 10);
3043 getstring(char *s, int size)
3054 } while( c != ' ' && c != '\t' && c != '\n' );
3059 static char line[256];
3060 static char *lineptr;
3071 if (lineptr == NULL || *lineptr == 0) {
3072 if (xmon_gets(line, sizeof(line)) == NULL) {
3082 take_input(char *str)
3091 int type = inchar();
3093 static char tmp[64];
3098 xmon_print_symbol(addr, ": ", "\n");
3103 if (setjmp(bus_error_jmp) == 0) {
3104 catch_memory_errors = 1;
3106 addr = kallsyms_lookup_name(tmp);
3108 printf("%s: %lx\n", tmp, addr);
3110 printf("Symbol '%s' not found.\n", tmp);
3113 catch_memory_errors = 0;
3120 /* Print an address in numeric and symbolic form (if possible) */
3121 static void xmon_print_symbol(unsigned long address, const char *mid,
3125 const char *name = NULL;
3126 unsigned long offset, size;
3128 printf(REG, address);
3129 if (setjmp(bus_error_jmp) == 0) {
3130 catch_memory_errors = 1;
3132 name = kallsyms_lookup(address, &size, &offset, &modname,
3135 /* wait a little while to see if we get a machine check */
3139 catch_memory_errors = 0;
3142 printf("%s%s+%#lx/%#lx", mid, name, offset, size);
3144 printf(" [%s]", modname);
3146 printf("%s", after);
3149 #ifdef CONFIG_PPC_STD_MMU_64
3150 void dump_segments(void)
3153 unsigned long esid,vsid;
3156 printf("SLB contents of cpu 0x%x\n", smp_processor_id());
3158 for (i = 0; i < mmu_slb_size; i++) {
3159 asm volatile("slbmfee %0,%1" : "=r" (esid) : "r" (i));
3160 asm volatile("slbmfev %0,%1" : "=r" (vsid) : "r" (i));
3165 printf("%02d %016lx %016lx", i, esid, vsid);
3167 if (!(esid & SLB_ESID_V)) {
3172 llp = vsid & SLB_VSID_LLP;
3173 if (vsid & SLB_VSID_B_1T) {
3174 printf(" 1T ESID=%9lx VSID=%13lx LLP:%3lx \n",
3176 (vsid & ~SLB_VSID_B) >> SLB_VSID_SHIFT_1T,
3179 printf(" 256M ESID=%9lx VSID=%13lx LLP:%3lx \n",
3181 (vsid & ~SLB_VSID_B) >> SLB_VSID_SHIFT,
3188 #ifdef CONFIG_PPC_STD_MMU_32
3189 void dump_segments(void)
3194 for (i = 0; i < 16; ++i)
3195 printf(" %x", mfsrin(i));
3201 static void dump_tlb_44x(void)
3205 for (i = 0; i < PPC44x_TLB_SIZE; i++) {
3206 unsigned long w0,w1,w2;
3207 asm volatile("tlbre %0,%1,0" : "=r" (w0) : "r" (i));
3208 asm volatile("tlbre %0,%1,1" : "=r" (w1) : "r" (i));
3209 asm volatile("tlbre %0,%1,2" : "=r" (w2) : "r" (i));
3210 printf("[%02x] %08x %08x %08x ", i, w0, w1, w2);
3211 if (w0 & PPC44x_TLB_VALID) {
3212 printf("V %08x -> %01x%08x %c%c%c%c%c",
3213 w0 & PPC44x_TLB_EPN_MASK,
3214 w1 & PPC44x_TLB_ERPN_MASK,
3215 w1 & PPC44x_TLB_RPN_MASK,
3216 (w2 & PPC44x_TLB_W) ? 'W' : 'w',
3217 (w2 & PPC44x_TLB_I) ? 'I' : 'i',
3218 (w2 & PPC44x_TLB_M) ? 'M' : 'm',
3219 (w2 & PPC44x_TLB_G) ? 'G' : 'g',
3220 (w2 & PPC44x_TLB_E) ? 'E' : 'e');
3225 #endif /* CONFIG_44x */
3227 #ifdef CONFIG_PPC_BOOK3E
3228 static void dump_tlb_book3e(void)
3230 u32 mmucfg, pidmask, lpidmask;
3232 int i, tlb, ntlbs, pidsz, lpidsz, rasz, lrat = 0;
3234 static const char *pgsz_names[] = {
3269 /* Gather some infos about the MMU */
3270 mmucfg = mfspr(SPRN_MMUCFG);
3271 mmu_version = (mmucfg & 3) + 1;
3272 ntlbs = ((mmucfg >> 2) & 3) + 1;
3273 pidsz = ((mmucfg >> 6) & 0x1f) + 1;
3274 lpidsz = (mmucfg >> 24) & 0xf;
3275 rasz = (mmucfg >> 16) & 0x7f;
3276 if ((mmu_version > 1) && (mmucfg & 0x10000))
3278 printf("Book3E MMU MAV=%d.0,%d TLBs,%d-bit PID,%d-bit LPID,%d-bit RA\n",
3279 mmu_version, ntlbs, pidsz, lpidsz, rasz);
3280 pidmask = (1ul << pidsz) - 1;
3281 lpidmask = (1ul << lpidsz) - 1;
3282 ramask = (1ull << rasz) - 1;
3284 for (tlb = 0; tlb < ntlbs; tlb++) {
3286 int nent, assoc, new_cc = 1;
3287 printf("TLB %d:\n------\n", tlb);
3290 tlbcfg = mfspr(SPRN_TLB0CFG);
3293 tlbcfg = mfspr(SPRN_TLB1CFG);
3296 tlbcfg = mfspr(SPRN_TLB2CFG);
3299 tlbcfg = mfspr(SPRN_TLB3CFG);
3302 printf("Unsupported TLB number !\n");
3305 nent = tlbcfg & 0xfff;
3306 assoc = (tlbcfg >> 24) & 0xff;
3307 for (i = 0; i < nent; i++) {
3308 u32 mas0 = MAS0_TLBSEL(tlb);
3309 u32 mas1 = MAS1_TSIZE(BOOK3E_PAGESZ_4K);
3312 int esel = i, cc = i;
3320 mas0 |= MAS0_ESEL(esel);
3321 mtspr(SPRN_MAS0, mas0);
3322 mtspr(SPRN_MAS1, mas1);
3323 mtspr(SPRN_MAS2, mas2);
3324 asm volatile("tlbre 0,0,0" : : : "memory");
3325 mas1 = mfspr(SPRN_MAS1);
3326 mas2 = mfspr(SPRN_MAS2);
3327 mas7_mas3 = mfspr(SPRN_MAS7_MAS3);
3328 if (assoc && (i % assoc) == 0)
3330 if (!(mas1 & MAS1_VALID))
3333 printf("%04x- ", i);
3335 printf("%04x-%c", cc, 'A' + esel);
3337 printf(" |%c", 'A' + esel);
3339 printf(" %016llx %04x %s %c%c AS%c",
3341 (mas1 >> 16) & 0x3fff,
3342 pgsz_names[(mas1 >> 7) & 0x1f],
3343 mas1 & MAS1_IND ? 'I' : ' ',
3344 mas1 & MAS1_IPROT ? 'P' : ' ',
3345 mas1 & MAS1_TS ? '1' : '0');
3346 printf(" %c%c%c%c%c%c%c",
3347 mas2 & MAS2_X0 ? 'a' : ' ',
3348 mas2 & MAS2_X1 ? 'v' : ' ',
3349 mas2 & MAS2_W ? 'w' : ' ',
3350 mas2 & MAS2_I ? 'i' : ' ',
3351 mas2 & MAS2_M ? 'm' : ' ',
3352 mas2 & MAS2_G ? 'g' : ' ',
3353 mas2 & MAS2_E ? 'e' : ' ');
3354 printf(" %016llx", mas7_mas3 & ramask & ~0x7ffull);
3355 if (mas1 & MAS1_IND)
3357 pgsz_names[(mas7_mas3 >> 1) & 0x1f]);
3359 printf(" U%c%c%c S%c%c%c\n",
3360 mas7_mas3 & MAS3_UX ? 'x' : ' ',
3361 mas7_mas3 & MAS3_UW ? 'w' : ' ',
3362 mas7_mas3 & MAS3_UR ? 'r' : ' ',
3363 mas7_mas3 & MAS3_SX ? 'x' : ' ',
3364 mas7_mas3 & MAS3_SW ? 'w' : ' ',
3365 mas7_mas3 & MAS3_SR ? 'r' : ' ');
3369 #endif /* CONFIG_PPC_BOOK3E */
3371 static void xmon_init(int enable)
3375 __debugger_ipi = xmon_ipi;
3376 __debugger_bpt = xmon_bpt;
3377 __debugger_sstep = xmon_sstep;
3378 __debugger_iabr_match = xmon_iabr_match;
3379 __debugger_break_match = xmon_break_match;
3380 __debugger_fault_handler = xmon_fault_handler;
3383 __debugger_ipi = NULL;
3384 __debugger_bpt = NULL;
3385 __debugger_sstep = NULL;
3386 __debugger_iabr_match = NULL;
3387 __debugger_break_match = NULL;
3388 __debugger_fault_handler = NULL;
3392 #ifdef CONFIG_MAGIC_SYSRQ
3393 static void sysrq_handle_xmon(int key)
3395 /* ensure xmon is enabled */
3397 debugger(get_irq_regs());
3402 static struct sysrq_key_op sysrq_xmon_op = {
3403 .handler = sysrq_handle_xmon,
3404 .help_msg = "xmon(x)",
3405 .action_msg = "Entering xmon",
3408 static int __init setup_xmon_sysrq(void)
3410 register_sysrq_key('x', &sysrq_xmon_op);
3413 device_initcall(setup_xmon_sysrq);
3414 #endif /* CONFIG_MAGIC_SYSRQ */
3416 #ifdef CONFIG_DEBUG_FS
3417 static int xmon_dbgfs_set(void *data, u64 val)
3425 static int xmon_dbgfs_get(void *data, u64 *val)
3431 DEFINE_SIMPLE_ATTRIBUTE(xmon_dbgfs_ops, xmon_dbgfs_get,
3432 xmon_dbgfs_set, "%llu\n");
3434 static int __init setup_xmon_dbgfs(void)
3436 debugfs_create_file("xmon", 0600, powerpc_debugfs_root, NULL,
3440 device_initcall(setup_xmon_dbgfs);
3441 #endif /* CONFIG_DEBUG_FS */
3443 static int xmon_early __initdata;
3445 static int __init early_parse_xmon(char *p)
3447 if (!p || strncmp(p, "early", 5) == 0) {
3448 /* just "xmon" is equivalent to "xmon=early" */
3452 } else if (strncmp(p, "on", 2) == 0) {
3455 } else if (strncmp(p, "off", 3) == 0)
3462 early_param("xmon", early_parse_xmon);
3464 void __init xmon_setup(void)
3472 #ifdef CONFIG_SPU_BASE
3476 u64 saved_mfc_sr1_RW;
3477 u32 saved_spu_runcntl_RW;
3478 unsigned long dump_addr;
3482 #define XMON_NUM_SPUS 16 /* Enough for current hardware */
3484 static struct spu_info spu_info[XMON_NUM_SPUS];
3486 void xmon_register_spus(struct list_head *list)
3490 list_for_each_entry(spu, list, full_list) {
3491 if (spu->number >= XMON_NUM_SPUS) {
3496 spu_info[spu->number].spu = spu;
3497 spu_info[spu->number].stopped_ok = 0;
3498 spu_info[spu->number].dump_addr = (unsigned long)
3499 spu_info[spu->number].spu->local_store;
3503 static void stop_spus(void)
3509 for (i = 0; i < XMON_NUM_SPUS; i++) {
3510 if (!spu_info[i].spu)
3513 if (setjmp(bus_error_jmp) == 0) {
3514 catch_memory_errors = 1;
3517 spu = spu_info[i].spu;
3519 spu_info[i].saved_spu_runcntl_RW =
3520 in_be32(&spu->problem->spu_runcntl_RW);
3522 tmp = spu_mfc_sr1_get(spu);
3523 spu_info[i].saved_mfc_sr1_RW = tmp;
3525 tmp &= ~MFC_STATE1_MASTER_RUN_CONTROL_MASK;
3526 spu_mfc_sr1_set(spu, tmp);
3531 spu_info[i].stopped_ok = 1;
3533 printf("Stopped spu %.2d (was %s)\n", i,
3534 spu_info[i].saved_spu_runcntl_RW ?
3535 "running" : "stopped");
3537 catch_memory_errors = 0;
3538 printf("*** Error stopping spu %.2d\n", i);
3540 catch_memory_errors = 0;
3544 static void restart_spus(void)
3549 for (i = 0; i < XMON_NUM_SPUS; i++) {
3550 if (!spu_info[i].spu)
3553 if (!spu_info[i].stopped_ok) {
3554 printf("*** Error, spu %d was not successfully stopped"
3555 ", not restarting\n", i);
3559 if (setjmp(bus_error_jmp) == 0) {
3560 catch_memory_errors = 1;
3563 spu = spu_info[i].spu;
3564 spu_mfc_sr1_set(spu, spu_info[i].saved_mfc_sr1_RW);
3565 out_be32(&spu->problem->spu_runcntl_RW,
3566 spu_info[i].saved_spu_runcntl_RW);
3571 printf("Restarted spu %.2d\n", i);
3573 catch_memory_errors = 0;
3574 printf("*** Error restarting spu %.2d\n", i);
3576 catch_memory_errors = 0;
3580 #define DUMP_WIDTH 23
3581 #define DUMP_VALUE(format, field, value) \
3583 if (setjmp(bus_error_jmp) == 0) { \
3584 catch_memory_errors = 1; \
3586 printf(" %-*s = "format"\n", DUMP_WIDTH, \
3591 catch_memory_errors = 0; \
3592 printf(" %-*s = *** Error reading field.\n", \
3593 DUMP_WIDTH, #field); \
3595 catch_memory_errors = 0; \
3598 #define DUMP_FIELD(obj, format, field) \
3599 DUMP_VALUE(format, field, obj->field)
3601 static void dump_spu_fields(struct spu *spu)
3603 printf("Dumping spu fields at address %p:\n", spu);
3605 DUMP_FIELD(spu, "0x%x", number);
3606 DUMP_FIELD(spu, "%s", name);
3607 DUMP_FIELD(spu, "0x%lx", local_store_phys);
3608 DUMP_FIELD(spu, "0x%p", local_store);
3609 DUMP_FIELD(spu, "0x%lx", ls_size);
3610 DUMP_FIELD(spu, "0x%x", node);
3611 DUMP_FIELD(spu, "0x%lx", flags);
3612 DUMP_FIELD(spu, "%d", class_0_pending);
3613 DUMP_FIELD(spu, "0x%lx", class_0_dar);
3614 DUMP_FIELD(spu, "0x%lx", class_1_dar);
3615 DUMP_FIELD(spu, "0x%lx", class_1_dsisr);
3616 DUMP_FIELD(spu, "0x%lx", irqs[0]);
3617 DUMP_FIELD(spu, "0x%lx", irqs[1]);
3618 DUMP_FIELD(spu, "0x%lx", irqs[2]);
3619 DUMP_FIELD(spu, "0x%x", slb_replace);
3620 DUMP_FIELD(spu, "%d", pid);
3621 DUMP_FIELD(spu, "0x%p", mm);
3622 DUMP_FIELD(spu, "0x%p", ctx);
3623 DUMP_FIELD(spu, "0x%p", rq);
3624 DUMP_FIELD(spu, "0x%p", timestamp);
3625 DUMP_FIELD(spu, "0x%lx", problem_phys);
3626 DUMP_FIELD(spu, "0x%p", problem);
3627 DUMP_VALUE("0x%x", problem->spu_runcntl_RW,
3628 in_be32(&spu->problem->spu_runcntl_RW));
3629 DUMP_VALUE("0x%x", problem->spu_status_R,
3630 in_be32(&spu->problem->spu_status_R));
3631 DUMP_VALUE("0x%x", problem->spu_npc_RW,
3632 in_be32(&spu->problem->spu_npc_RW));
3633 DUMP_FIELD(spu, "0x%p", priv2);
3634 DUMP_FIELD(spu, "0x%p", pdata);
3638 spu_inst_dump(unsigned long adr, long count, int praddr)
3640 return generic_inst_dump(adr, count, praddr, print_insn_spu);
3643 static void dump_spu_ls(unsigned long num, int subcmd)
3645 unsigned long offset, addr, ls_addr;
3647 if (setjmp(bus_error_jmp) == 0) {
3648 catch_memory_errors = 1;
3650 ls_addr = (unsigned long)spu_info[num].spu->local_store;
3654 catch_memory_errors = 0;
3655 printf("*** Error: accessing spu info for spu %d\n", num);
3658 catch_memory_errors = 0;
3660 if (scanhex(&offset))
3661 addr = ls_addr + offset;
3663 addr = spu_info[num].dump_addr;
3665 if (addr >= ls_addr + LS_SIZE) {
3666 printf("*** Error: address outside of local store\n");
3672 addr += spu_inst_dump(addr, 16, 1);
3682 spu_info[num].dump_addr = addr;
3685 static int do_spu_cmd(void)
3687 static unsigned long num = 0;
3688 int cmd, subcmd = 0;
3700 if (isxdigit(subcmd) || subcmd == '\n')
3704 if (num >= XMON_NUM_SPUS || !spu_info[num].spu) {
3705 printf("*** Error: invalid spu number\n");
3711 dump_spu_fields(spu_info[num].spu);
3714 dump_spu_ls(num, subcmd);
3725 #else /* ! CONFIG_SPU_BASE */
3726 static int do_spu_cmd(void)