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 #ifdef CONFIG_PPC_PSERIES
77 static int set_indicator_token = RTAS_UNKNOWN_SERVICE;
79 static unsigned long in_xmon __read_mostly = 0;
81 static unsigned long adrs;
83 #define MAX_DUMP (128 * 1024)
84 static unsigned long ndump = 64;
85 static unsigned long nidump = 16;
86 static unsigned long ncsum = 4096;
88 static char tmpstr[128];
90 static long bus_error_jmp[JMP_BUF_LEN];
91 static int catch_memory_errors;
92 static int catch_spr_faults;
93 static long *xmon_fault_jmp[NR_CPUS];
95 /* Breakpoint stuff */
97 unsigned long address;
98 unsigned int instr[2];
104 /* Bits in bpt.enabled */
110 static struct bpt bpts[NBPTS];
111 static struct bpt dabr;
112 static struct bpt *iabr;
113 static unsigned bpinstr = 0x7fe00008; /* trap */
115 #define BP_NUM(bp) ((bp) - bpts + 1)
118 static int cmds(struct pt_regs *);
119 static int mread(unsigned long, void *, int);
120 static int mwrite(unsigned long, void *, int);
121 static int handle_fault(struct pt_regs *);
122 static void byterev(unsigned char *, int);
123 static void memex(void);
124 static int bsesc(void);
125 static void dump(void);
126 static void prdump(unsigned long, long);
127 static int ppc_inst_dump(unsigned long, long, int);
128 static void dump_log_buf(void);
130 #ifdef CONFIG_PPC_POWERNV
131 static void dump_opal_msglog(void);
133 static inline void dump_opal_msglog(void)
135 printf("Machine is not running OPAL firmware.\n");
139 static void backtrace(struct pt_regs *);
140 static void excprint(struct pt_regs *);
141 static void prregs(struct pt_regs *);
142 static void memops(int);
143 static void memlocate(void);
144 static void memzcan(void);
145 static void memdiffs(unsigned char *, unsigned char *, unsigned, unsigned);
147 int scanhex(unsigned long *valp);
148 static void scannl(void);
149 static int hexdigit(int);
150 void getstring(char *, int);
151 static void flush_input(void);
152 static int inchar(void);
153 static void take_input(char *);
154 static int read_spr(int, unsigned long *);
155 static void write_spr(int, unsigned long);
156 static void super_regs(void);
157 static void remove_bpts(void);
158 static void insert_bpts(void);
159 static void remove_cpu_bpts(void);
160 static void insert_cpu_bpts(void);
161 static struct bpt *at_breakpoint(unsigned long pc);
162 static struct bpt *in_breakpoint_table(unsigned long pc, unsigned long *offp);
163 static int do_step(struct pt_regs *);
164 static void bpt_cmds(void);
165 static void cacheflush(void);
166 static int cpu_cmd(void);
167 static void csum(void);
168 static void bootcmds(void);
169 static void proccall(void);
170 static void show_tasks(void);
171 void dump_segments(void);
172 static void symbol_lookup(void);
173 static void xmon_show_stack(unsigned long sp, unsigned long lr,
175 static void xmon_print_symbol(unsigned long address, const char *mid,
177 static const char *getvecname(unsigned long vec);
179 static int do_spu_cmd(void);
182 static void dump_tlb_44x(void);
184 #ifdef CONFIG_PPC_BOOK3E
185 static void dump_tlb_book3e(void);
188 static int xmon_no_auto_backtrace;
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 di dump instructions\n\
217 df dump float values\n\
218 dd dump double values\n\
219 dl dump the kernel log buffer\n"
220 #ifdef CONFIG_PPC_POWERNV
222 do dump the OPAL message log\n"
226 dp[#] dump paca for current cpu, or cpu #\n\
227 dpa dump paca for all possible cpus\n"
230 dr dump stream of raw bytes\n\
231 e print exception information\n\
233 la lookup symbol+offset of specified address\n\
234 ls lookup address of specified symbol\n\
235 m examine/change memory\n\
236 mm move a block of memory\n\
237 ms set a block of memory\n\
238 md compare two blocks of memory\n\
239 ml locate a block of memory\n\
240 mz zero a block of memory\n\
241 mi show information about memory allocation\n\
242 p call a procedure\n\
243 P list processes/tasks\n\
246 #ifdef CONFIG_SPU_BASE
247 " ss stop execution on all spus\n\
248 sr restore execution on stopped spus\n\
249 sf # dump spu fields for spu # (in hex)\n\
250 sd # dump spu local store for spu # (in hex)\n\
251 sdi # disassemble spu local store for spu # (in hex)\n"
253 " S print special registers\n\
256 Sw #v write v to SPR #\n\
258 x exit monitor and recover\n\
259 X exit monitor and don't recover\n"
260 #if defined(CONFIG_PPC64) && !defined(CONFIG_PPC_BOOK3E)
261 " u dump segment table or SLB\n"
262 #elif defined(CONFIG_PPC_STD_MMU_32)
263 " u dump segment registers\n"
264 #elif defined(CONFIG_44x) || defined(CONFIG_PPC_BOOK3E)
268 " # n limit output to n lines per page (for dp, dpa, dl)\n"
273 static struct pt_regs *xmon_regs;
275 static inline void sync(void)
277 asm volatile("sync; isync");
280 static inline void store_inst(void *p)
282 asm volatile ("dcbst 0,%0; sync; icbi 0,%0; isync" : : "r" (p));
285 static inline void cflush(void *p)
287 asm volatile ("dcbf 0,%0; icbi 0,%0" : : "r" (p));
290 static inline void cinval(void *p)
292 asm volatile ("dcbi 0,%0; icbi 0,%0" : : "r" (p));
296 * write_ciabr() - write the CIABR SPR
297 * @ciabr: The value to write.
299 * This function writes a value to the CIARB register either directly
300 * through mtspr instruction if the kernel is in HV privilege mode or
301 * call a hypervisor function to achieve the same in case the kernel
302 * is in supervisor privilege mode.
304 static void write_ciabr(unsigned long ciabr)
306 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
309 if (cpu_has_feature(CPU_FTR_HVMODE)) {
310 mtspr(SPRN_CIABR, ciabr);
313 plapr_set_ciabr(ciabr);
317 * set_ciabr() - set the CIABR
318 * @addr: The value to set.
320 * This function sets the correct privilege value into the the HW
321 * breakpoint address before writing it up in the CIABR register.
323 static void set_ciabr(unsigned long addr)
327 if (cpu_has_feature(CPU_FTR_HVMODE))
328 addr |= CIABR_PRIV_HYPER;
330 addr |= CIABR_PRIV_SUPER;
335 * Disable surveillance (the service processor watchdog function)
336 * while we are in xmon.
337 * XXX we should re-enable it when we leave. :)
339 #define SURVEILLANCE_TOKEN 9000
341 static inline void disable_surveillance(void)
343 #ifdef CONFIG_PPC_PSERIES
344 /* Since this can't be a module, args should end up below 4GB. */
345 static struct rtas_args args;
348 * At this point we have got all the cpus we can into
349 * xmon, so there is hopefully no other cpu calling RTAS
350 * at the moment, even though we don't take rtas.lock.
351 * If we did try to take rtas.lock there would be a
352 * real possibility of deadlock.
354 if (set_indicator_token == RTAS_UNKNOWN_SERVICE)
357 rtas_call_unlocked(&args, set_indicator_token, 3, 1, NULL,
358 SURVEILLANCE_TOKEN, 0, 0);
360 #endif /* CONFIG_PPC_PSERIES */
364 static int xmon_speaker;
366 static void get_output_lock(void)
368 int me = smp_processor_id() + 0x100;
369 int last_speaker = 0, prev;
372 if (xmon_speaker == me)
376 last_speaker = cmpxchg(&xmon_speaker, 0, me);
377 if (last_speaker == 0)
381 * Wait a full second for the lock, we might be on a slow
382 * console, but check every 100us.
385 while (xmon_speaker == last_speaker) {
391 /* hostile takeover */
392 prev = cmpxchg(&xmon_speaker, last_speaker, me);
393 if (prev == last_speaker)
400 static void release_output_lock(void)
405 int cpus_are_in_xmon(void)
407 return !cpumask_empty(&cpus_in_xmon);
411 static inline int unrecoverable_excp(struct pt_regs *regs)
413 #if defined(CONFIG_4xx) || defined(CONFIG_PPC_BOOK3E)
414 /* We have no MSR_RI bit on 4xx or Book3e, so we simply return false */
417 return ((regs->msr & MSR_RI) == 0);
421 static int xmon_core(struct pt_regs *regs, int fromipi)
425 long recurse_jmp[JMP_BUF_LEN];
426 unsigned long offset;
431 unsigned long timeout;
434 local_irq_save(flags);
437 bp = in_breakpoint_table(regs->nip, &offset);
439 regs->nip = bp->address + offset;
440 atomic_dec(&bp->ref_count);
446 cpu = smp_processor_id();
447 if (cpumask_test_cpu(cpu, &cpus_in_xmon)) {
449 * We catch SPR read/write faults here because the 0x700, 0xf60
450 * etc. handlers don't call debugger_fault_handler().
452 if (catch_spr_faults)
453 longjmp(bus_error_jmp, 1);
456 printf("cpu 0x%x: Exception %lx %s in xmon, "
457 "returning to main loop\n",
458 cpu, regs->trap, getvecname(TRAP(regs)));
459 release_output_lock();
460 longjmp(xmon_fault_jmp[cpu], 1);
463 if (setjmp(recurse_jmp) != 0) {
464 if (!in_xmon || !xmon_gate) {
466 printf("xmon: WARNING: bad recursive fault "
467 "on cpu 0x%x\n", cpu);
468 release_output_lock();
471 secondary = !(xmon_taken && cpu == xmon_owner);
475 xmon_fault_jmp[cpu] = recurse_jmp;
478 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) == (MSR_IR|MSR_64BIT))
479 bp = at_breakpoint(regs->nip);
480 if (bp || unrecoverable_excp(regs))
487 printf("cpu 0x%x stopped at breakpoint 0x%lx (",
489 xmon_print_symbol(regs->nip, " ", ")\n");
491 if (unrecoverable_excp(regs))
492 printf("WARNING: exception is not recoverable, "
494 release_output_lock();
497 cpumask_set_cpu(cpu, &cpus_in_xmon);
501 while (secondary && !xmon_gate) {
505 secondary = test_and_set_bit(0, &in_xmon);
510 if (!secondary && !xmon_gate) {
511 /* we are the first cpu to come in */
512 /* interrupt other cpu(s) */
513 int ncpus = num_online_cpus();
518 smp_send_debugger_break();
519 /* wait for other cpus to come in */
520 for (timeout = 100000000; timeout != 0; --timeout) {
521 if (cpumask_weight(&cpus_in_xmon) >= ncpus)
527 disable_surveillance();
528 /* for breakpoint or single step, print the current instr. */
529 if (bp || TRAP(regs) == 0xd00)
530 ppc_inst_dump(regs->nip, 1, 0);
531 printf("enter ? for help\n");
540 if (cpu == xmon_owner) {
541 if (!test_and_set_bit(0, &xmon_taken)) {
546 while (cpu == xmon_owner)
560 /* have switched to some other cpu */
565 cpumask_clear_cpu(cpu, &cpus_in_xmon);
566 xmon_fault_jmp[cpu] = NULL;
568 /* UP is simple... */
570 printf("Exception %lx %s in xmon, returning to main loop\n",
571 regs->trap, getvecname(TRAP(regs)));
572 longjmp(xmon_fault_jmp[0], 1);
574 if (setjmp(recurse_jmp) == 0) {
575 xmon_fault_jmp[0] = recurse_jmp;
579 bp = at_breakpoint(regs->nip);
581 printf("Stopped at breakpoint %lx (", BP_NUM(bp));
582 xmon_print_symbol(regs->nip, " ", ")\n");
584 if (unrecoverable_excp(regs))
585 printf("WARNING: exception is not recoverable, "
588 disable_surveillance();
589 /* for breakpoint or single step, print the current instr. */
590 if (bp || TRAP(regs) == 0xd00)
591 ppc_inst_dump(regs->nip, 1, 0);
592 printf("enter ? for help\n");
602 if (regs->msr & MSR_DE) {
603 bp = at_breakpoint(regs->nip);
605 regs->nip = (unsigned long) &bp->instr[0];
606 atomic_inc(&bp->ref_count);
610 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) == (MSR_IR|MSR_64BIT)) {
611 bp = at_breakpoint(regs->nip);
613 int stepped = emulate_step(regs, bp->instr[0]);
615 regs->nip = (unsigned long) &bp->instr[0];
616 atomic_inc(&bp->ref_count);
617 } else if (stepped < 0) {
618 printf("Couldn't single-step %s instruction\n",
619 (IS_RFID(bp->instr[0])? "rfid": "mtmsrd"));
626 touch_nmi_watchdog();
627 local_irq_restore(flags);
629 return cmd != 'X' && cmd != EOF;
632 int xmon(struct pt_regs *excp)
637 ppc_save_regs(®s);
641 return xmon_core(excp, 0);
645 irqreturn_t xmon_irq(int irq, void *d)
648 local_irq_save(flags);
649 printf("Keyboard interrupt\n");
650 xmon(get_irq_regs());
651 local_irq_restore(flags);
655 static int xmon_bpt(struct pt_regs *regs)
658 unsigned long offset;
660 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) != (MSR_IR|MSR_64BIT))
663 /* Are we at the trap at bp->instr[1] for some bp? */
664 bp = in_breakpoint_table(regs->nip, &offset);
665 if (bp != NULL && offset == 4) {
666 regs->nip = bp->address + 4;
667 atomic_dec(&bp->ref_count);
671 /* Are we at a breakpoint? */
672 bp = at_breakpoint(regs->nip);
681 static int xmon_sstep(struct pt_regs *regs)
689 static int xmon_break_match(struct pt_regs *regs)
691 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) != (MSR_IR|MSR_64BIT))
693 if (dabr.enabled == 0)
699 static int xmon_iabr_match(struct pt_regs *regs)
701 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) != (MSR_IR|MSR_64BIT))
709 static int xmon_ipi(struct pt_regs *regs)
712 if (in_xmon && !cpumask_test_cpu(smp_processor_id(), &cpus_in_xmon))
718 static int xmon_fault_handler(struct pt_regs *regs)
721 unsigned long offset;
723 if (in_xmon && catch_memory_errors)
724 handle_fault(regs); /* doesn't return */
726 if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) == (MSR_IR|MSR_64BIT)) {
727 bp = in_breakpoint_table(regs->nip, &offset);
729 regs->nip = bp->address + offset;
730 atomic_dec(&bp->ref_count);
737 static struct bpt *at_breakpoint(unsigned long pc)
743 for (i = 0; i < NBPTS; ++i, ++bp)
744 if (bp->enabled && pc == bp->address)
749 static struct bpt *in_breakpoint_table(unsigned long nip, unsigned long *offp)
753 off = nip - (unsigned long) bpts;
754 if (off >= sizeof(bpts))
756 off %= sizeof(struct bpt);
757 if (off != offsetof(struct bpt, instr[0])
758 && off != offsetof(struct bpt, instr[1]))
760 *offp = off - offsetof(struct bpt, instr[0]);
761 return (struct bpt *) (nip - off);
764 static struct bpt *new_breakpoint(unsigned long a)
769 bp = at_breakpoint(a);
773 for (bp = bpts; bp < &bpts[NBPTS]; ++bp) {
774 if (!bp->enabled && atomic_read(&bp->ref_count) == 0) {
776 bp->instr[1] = bpinstr;
777 store_inst(&bp->instr[1]);
782 printf("Sorry, no free breakpoints. Please clear one first.\n");
786 static void insert_bpts(void)
792 for (i = 0; i < NBPTS; ++i, ++bp) {
793 if ((bp->enabled & (BP_TRAP|BP_CIABR)) == 0)
795 if (mread(bp->address, &bp->instr[0], 4) != 4) {
796 printf("Couldn't read instruction at %lx, "
797 "disabling breakpoint there\n", bp->address);
801 if (IS_MTMSRD(bp->instr[0]) || IS_RFID(bp->instr[0])) {
802 printf("Breakpoint at %lx is on an mtmsrd or rfid "
803 "instruction, disabling it\n", bp->address);
807 store_inst(&bp->instr[0]);
808 if (bp->enabled & BP_CIABR)
810 if (mwrite(bp->address, &bpinstr, 4) != 4) {
811 printf("Couldn't write instruction at %lx, "
812 "disabling breakpoint there\n", bp->address);
813 bp->enabled &= ~BP_TRAP;
816 store_inst((void *)bp->address);
820 static void insert_cpu_bpts(void)
822 struct arch_hw_breakpoint brk;
825 brk.address = dabr.address;
826 brk.type = (dabr.enabled & HW_BRK_TYPE_DABR) | HW_BRK_TYPE_PRIV_ALL;
828 __set_breakpoint(&brk);
832 set_ciabr(iabr->address);
835 static void remove_bpts(void)
842 for (i = 0; i < NBPTS; ++i, ++bp) {
843 if ((bp->enabled & (BP_TRAP|BP_CIABR)) != BP_TRAP)
845 if (mread(bp->address, &instr, 4) == 4
847 && mwrite(bp->address, &bp->instr, 4) != 4)
848 printf("Couldn't remove breakpoint at %lx\n",
851 store_inst((void *)bp->address);
855 static void remove_cpu_bpts(void)
857 hw_breakpoint_disable();
861 static void set_lpp_cmd(void)
865 if (!scanhex(&lpp)) {
866 printf("Invalid number.\n");
869 xmon_set_pagination_lpp(lpp);
871 /* Command interpreting routine */
872 static char *last_cmd;
875 cmds(struct pt_regs *excp)
882 if (!xmon_no_auto_backtrace) {
883 xmon_no_auto_backtrace = 1;
884 xmon_show_stack(excp->gpr[1], excp->link, excp->nip);
889 printf("%x:", smp_processor_id());
890 #endif /* CONFIG_SMP */
896 if (last_cmd == NULL)
898 take_input(last_cmd);
932 prregs(excp); /* print regs */
947 if (do_spu_cmd() == 0)
956 printf(" <no input ...>\n");
960 xmon_puts(help_string);
984 #ifdef CONFIG_PPC_STD_MMU
988 #elif defined(CONFIG_44x)
992 #elif defined(CONFIG_PPC_BOOK3E)
998 printf("Unrecognized command: ");
1000 if (' ' < cmd && cmd <= '~')
1003 printf("\\x%x", cmd);
1005 } while (cmd != '\n');
1006 printf(" (type ? for help)\n");
1013 static int do_step(struct pt_regs *regs)
1015 regs->msr |= MSR_DE;
1016 mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) | DBCR0_IC | DBCR0_IDM);
1021 * Step a single instruction.
1022 * Some instructions we emulate, others we execute with MSR_SE set.
1024 static int do_step(struct pt_regs *regs)
1029 /* check we are in 64-bit kernel mode, translation enabled */
1030 if ((regs->msr & (MSR_64BIT|MSR_PR|MSR_IR)) == (MSR_64BIT|MSR_IR)) {
1031 if (mread(regs->nip, &instr, 4) == 4) {
1032 stepped = emulate_step(regs, instr);
1034 printf("Couldn't single-step %s instruction\n",
1035 (IS_RFID(instr)? "rfid": "mtmsrd"));
1039 regs->trap = 0xd00 | (regs->trap & 1);
1040 printf("stepped to ");
1041 xmon_print_symbol(regs->nip, " ", "\n");
1042 ppc_inst_dump(regs->nip, 1, 0);
1047 regs->msr |= MSR_SE;
1052 static void bootcmds(void)
1058 ppc_md.restart(NULL);
1059 else if (cmd == 'h')
1061 else if (cmd == 'p')
1066 static int cpu_cmd(void)
1069 unsigned long cpu, first_cpu, last_cpu;
1072 if (!scanhex(&cpu)) {
1073 /* print cpus waiting or in xmon */
1074 printf("cpus stopped:");
1075 last_cpu = first_cpu = NR_CPUS;
1076 for_each_possible_cpu(cpu) {
1077 if (cpumask_test_cpu(cpu, &cpus_in_xmon)) {
1078 if (cpu == last_cpu + 1) {
1081 if (last_cpu != first_cpu)
1082 printf("-0x%lx", last_cpu);
1083 last_cpu = first_cpu = cpu;
1084 printf(" 0x%lx", cpu);
1088 if (last_cpu != first_cpu)
1089 printf("-0x%lx", last_cpu);
1093 /* try to switch to cpu specified */
1094 if (!cpumask_test_cpu(cpu, &cpus_in_xmon)) {
1095 printf("cpu 0x%x isn't in xmon\n", cpu);
1102 while (!xmon_taken) {
1103 if (--timeout == 0) {
1104 if (test_and_set_bit(0, &xmon_taken))
1106 /* take control back */
1108 xmon_owner = smp_processor_id();
1109 printf("cpu 0x%x didn't take control\n", cpu);
1117 #endif /* CONFIG_SMP */
1120 static unsigned short fcstab[256] = {
1121 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
1122 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
1123 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
1124 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
1125 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
1126 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
1127 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
1128 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
1129 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
1130 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
1131 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
1132 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
1133 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
1134 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
1135 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
1136 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
1137 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
1138 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
1139 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
1140 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
1141 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
1142 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
1143 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
1144 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
1145 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
1146 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
1147 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
1148 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
1149 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
1150 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
1151 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
1152 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
1155 #define FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
1164 if (!scanhex(&adrs))
1166 if (!scanhex(&ncsum))
1169 for (i = 0; i < ncsum; ++i) {
1170 if (mread(adrs+i, &v, 1) == 0) {
1171 printf("csum stopped at "REG"\n", adrs+i);
1176 printf("%x\n", fcs);
1180 * Check if this is a suitable place to put a breakpoint.
1182 static long check_bp_loc(unsigned long addr)
1187 if (!is_kernel_addr(addr)) {
1188 printf("Breakpoints may only be placed at kernel addresses\n");
1191 if (!mread(addr, &instr, sizeof(instr))) {
1192 printf("Can't read instruction at address %lx\n", addr);
1195 if (IS_MTMSRD(instr) || IS_RFID(instr)) {
1196 printf("Breakpoints may not be placed on mtmsrd or rfid "
1203 static char *breakpoint_help_string =
1204 "Breakpoint command usage:\n"
1205 "b show breakpoints\n"
1206 "b <addr> [cnt] set breakpoint at given instr addr\n"
1207 "bc clear all breakpoints\n"
1208 "bc <n/addr> clear breakpoint number n or at addr\n"
1209 "bi <addr> [cnt] set hardware instr breakpoint (POWER8 only)\n"
1210 "bd <addr> [cnt] set hardware data breakpoint\n"
1220 const char badaddr[] = "Only kernel addresses are permitted "
1221 "for breakpoints\n";
1226 case 'd': /* bd - hardware data breakpoint */
1231 else if (cmd == 'w')
1237 if (scanhex(&dabr.address)) {
1238 if (!is_kernel_addr(dabr.address)) {
1242 dabr.address &= ~HW_BRK_TYPE_DABR;
1243 dabr.enabled = mode | BP_DABR;
1247 case 'i': /* bi - hardware instr breakpoint */
1248 if (!cpu_has_feature(CPU_FTR_ARCH_207S)) {
1249 printf("Hardware instruction breakpoint "
1250 "not supported on this cpu\n");
1254 iabr->enabled &= ~BP_CIABR;
1259 if (!check_bp_loc(a))
1261 bp = new_breakpoint(a);
1263 bp->enabled |= BP_CIABR;
1271 /* clear all breakpoints */
1272 for (i = 0; i < NBPTS; ++i)
1273 bpts[i].enabled = 0;
1276 printf("All breakpoints cleared\n");
1280 if (a <= NBPTS && a >= 1) {
1281 /* assume a breakpoint number */
1282 bp = &bpts[a-1]; /* bp nums are 1 based */
1284 /* assume a breakpoint address */
1285 bp = at_breakpoint(a);
1287 printf("No breakpoint at %lx\n", a);
1292 printf("Cleared breakpoint %lx (", BP_NUM(bp));
1293 xmon_print_symbol(bp->address, " ", ")\n");
1301 printf(breakpoint_help_string);
1306 /* print all breakpoints */
1307 printf(" type address\n");
1309 printf(" data "REG" [", dabr.address);
1310 if (dabr.enabled & 1)
1312 if (dabr.enabled & 2)
1316 for (bp = bpts; bp < &bpts[NBPTS]; ++bp) {
1319 printf("%2x %s ", BP_NUM(bp),
1320 (bp->enabled & BP_CIABR) ? "inst": "trap");
1321 xmon_print_symbol(bp->address, " ", "\n");
1326 if (!check_bp_loc(a))
1328 bp = new_breakpoint(a);
1330 bp->enabled |= BP_TRAP;
1335 /* Very cheap human name for vector lookup. */
1337 const char *getvecname(unsigned long vec)
1342 case 0x100: ret = "(System Reset)"; break;
1343 case 0x200: ret = "(Machine Check)"; break;
1344 case 0x300: ret = "(Data Access)"; break;
1345 case 0x380: ret = "(Data SLB Access)"; break;
1346 case 0x400: ret = "(Instruction Access)"; break;
1347 case 0x480: ret = "(Instruction SLB Access)"; break;
1348 case 0x500: ret = "(Hardware Interrupt)"; break;
1349 case 0x600: ret = "(Alignment)"; break;
1350 case 0x700: ret = "(Program Check)"; break;
1351 case 0x800: ret = "(FPU Unavailable)"; break;
1352 case 0x900: ret = "(Decrementer)"; break;
1353 case 0x980: ret = "(Hypervisor Decrementer)"; break;
1354 case 0xa00: ret = "(Doorbell)"; break;
1355 case 0xc00: ret = "(System Call)"; break;
1356 case 0xd00: ret = "(Single Step)"; break;
1357 case 0xe40: ret = "(Emulation Assist)"; break;
1358 case 0xe60: ret = "(HMI)"; break;
1359 case 0xe80: ret = "(Hypervisor Doorbell)"; break;
1360 case 0xf00: ret = "(Performance Monitor)"; break;
1361 case 0xf20: ret = "(Altivec Unavailable)"; break;
1362 case 0x1300: ret = "(Instruction Breakpoint)"; break;
1363 case 0x1500: ret = "(Denormalisation)"; break;
1364 case 0x1700: ret = "(Altivec Assist)"; break;
1370 static void get_function_bounds(unsigned long pc, unsigned long *startp,
1371 unsigned long *endp)
1373 unsigned long size, offset;
1376 *startp = *endp = 0;
1379 if (setjmp(bus_error_jmp) == 0) {
1380 catch_memory_errors = 1;
1382 name = kallsyms_lookup(pc, &size, &offset, NULL, tmpstr);
1384 *startp = pc - offset;
1385 *endp = pc - offset + size;
1389 catch_memory_errors = 0;
1392 #define LRSAVE_OFFSET (STACK_FRAME_LR_SAVE * sizeof(unsigned long))
1393 #define MARKER_OFFSET (STACK_FRAME_MARKER * sizeof(unsigned long))
1395 static void xmon_show_stack(unsigned long sp, unsigned long lr,
1398 int max_to_print = 64;
1400 unsigned long newsp;
1401 unsigned long marker;
1402 struct pt_regs regs;
1404 while (max_to_print--) {
1405 if (sp < PAGE_OFFSET) {
1407 printf("SP (%lx) is in userspace\n", sp);
1411 if (!mread(sp + LRSAVE_OFFSET, &ip, sizeof(unsigned long))
1412 || !mread(sp, &newsp, sizeof(unsigned long))) {
1413 printf("Couldn't read stack frame at %lx\n", sp);
1418 * For the first stack frame, try to work out if
1419 * LR and/or the saved LR value in the bottommost
1420 * stack frame are valid.
1422 if ((pc | lr) != 0) {
1423 unsigned long fnstart, fnend;
1424 unsigned long nextip;
1427 get_function_bounds(pc, &fnstart, &fnend);
1430 mread(newsp + LRSAVE_OFFSET, &nextip,
1431 sizeof(unsigned long));
1433 if (lr < PAGE_OFFSET
1434 || (fnstart <= lr && lr < fnend))
1436 } else if (lr == nextip) {
1438 } else if (lr >= PAGE_OFFSET
1439 && !(fnstart <= lr && lr < fnend)) {
1440 printf("[link register ] ");
1441 xmon_print_symbol(lr, " ", "\n");
1444 printf("["REG"] ", sp);
1445 xmon_print_symbol(ip, " ", " (unreliable)\n");
1450 printf("["REG"] ", sp);
1451 xmon_print_symbol(ip, " ", "\n");
1454 /* Look for "regshere" marker to see if this is
1455 an exception frame. */
1456 if (mread(sp + MARKER_OFFSET, &marker, sizeof(unsigned long))
1457 && marker == STACK_FRAME_REGS_MARKER) {
1458 if (mread(sp + STACK_FRAME_OVERHEAD, ®s, sizeof(regs))
1460 printf("Couldn't read registers at %lx\n",
1461 sp + STACK_FRAME_OVERHEAD);
1464 printf("--- Exception: %lx %s at ", regs.trap,
1465 getvecname(TRAP(®s)));
1468 xmon_print_symbol(pc, " ", "\n");
1478 static void backtrace(struct pt_regs *excp)
1483 xmon_show_stack(sp, 0, 0);
1485 xmon_show_stack(excp->gpr[1], excp->link, excp->nip);
1489 static void print_bug_trap(struct pt_regs *regs)
1492 const struct bug_entry *bug;
1495 if (regs->msr & MSR_PR)
1496 return; /* not in kernel */
1497 addr = regs->nip; /* address of trap instruction */
1498 if (addr < PAGE_OFFSET)
1500 bug = find_bug(regs->nip);
1503 if (is_warning_bug(bug))
1506 #ifdef CONFIG_DEBUG_BUGVERBOSE
1507 printf("kernel BUG at %s:%u!\n",
1508 bug->file, bug->line);
1510 printf("kernel BUG at %p!\n", (void *)bug->bug_addr);
1512 #endif /* CONFIG_BUG */
1515 static void excprint(struct pt_regs *fp)
1520 printf("cpu 0x%x: ", smp_processor_id());
1521 #endif /* CONFIG_SMP */
1524 printf("Vector: %lx %s at [%lx]\n", fp->trap, getvecname(trap), fp);
1526 xmon_print_symbol(fp->nip, ": ", "\n");
1528 printf(" lr: ", fp->link);
1529 xmon_print_symbol(fp->link, ": ", "\n");
1531 printf(" sp: %lx\n", fp->gpr[1]);
1532 printf(" msr: %lx\n", fp->msr);
1534 if (trap == 0x300 || trap == 0x380 || trap == 0x600 || trap == 0x200) {
1535 printf(" dar: %lx\n", fp->dar);
1537 printf(" dsisr: %lx\n", fp->dsisr);
1540 printf(" current = 0x%lx\n", current);
1542 printf(" paca = 0x%lx\t softe: %d\t irq_happened: 0x%02x\n",
1543 local_paca, local_paca->soft_enabled, local_paca->irq_happened);
1546 printf(" pid = %ld, comm = %s\n",
1547 current->pid, current->comm);
1553 printf(linux_banner);
1556 static void prregs(struct pt_regs *fp)
1560 struct pt_regs regs;
1562 if (scanhex(&base)) {
1563 if (setjmp(bus_error_jmp) == 0) {
1564 catch_memory_errors = 1;
1566 regs = *(struct pt_regs *)base;
1570 catch_memory_errors = 0;
1571 printf("*** Error reading registers from "REG"\n",
1575 catch_memory_errors = 0;
1580 if (FULL_REGS(fp)) {
1581 for (n = 0; n < 16; ++n)
1582 printf("R%.2ld = "REG" R%.2ld = "REG"\n",
1583 n, fp->gpr[n], n+16, fp->gpr[n+16]);
1585 for (n = 0; n < 7; ++n)
1586 printf("R%.2ld = "REG" R%.2ld = "REG"\n",
1587 n, fp->gpr[n], n+7, fp->gpr[n+7]);
1590 for (n = 0; n < 32; ++n) {
1591 printf("R%.2d = %.8x%s", n, fp->gpr[n],
1592 (n & 3) == 3? "\n": " ");
1593 if (n == 12 && !FULL_REGS(fp)) {
1600 xmon_print_symbol(fp->nip, " ", "\n");
1601 if (TRAP(fp) != 0xc00 && cpu_has_feature(CPU_FTR_CFAR)) {
1603 xmon_print_symbol(fp->orig_gpr3, " ", "\n");
1606 xmon_print_symbol(fp->link, " ", "\n");
1607 printf("msr = "REG" cr = %.8lx\n", fp->msr, fp->ccr);
1608 printf("ctr = "REG" xer = "REG" trap = %4lx\n",
1609 fp->ctr, fp->xer, fp->trap);
1611 if (trap == 0x300 || trap == 0x380 || trap == 0x600)
1612 printf("dar = "REG" dsisr = %.8lx\n", fp->dar, fp->dsisr);
1615 static void cacheflush(void)
1618 unsigned long nflush;
1623 scanhex((void *)&adrs);
1628 nflush = (nflush + L1_CACHE_BYTES - 1) / L1_CACHE_BYTES;
1629 if (setjmp(bus_error_jmp) == 0) {
1630 catch_memory_errors = 1;
1634 for (; nflush > 0; --nflush, adrs += L1_CACHE_BYTES)
1635 cflush((void *) adrs);
1637 for (; nflush > 0; --nflush, adrs += L1_CACHE_BYTES)
1638 cinval((void *) adrs);
1641 /* wait a little while to see if we get a machine check */
1644 catch_memory_errors = 0;
1647 extern unsigned long xmon_mfspr(int spr, unsigned long default_value);
1648 extern void xmon_mtspr(int spr, unsigned long value);
1651 read_spr(int n, unsigned long *vp)
1653 unsigned long ret = -1UL;
1656 if (setjmp(bus_error_jmp) == 0) {
1657 catch_spr_faults = 1;
1660 ret = xmon_mfspr(n, *vp);
1666 catch_spr_faults = 0;
1672 write_spr(int n, unsigned long val)
1674 if (setjmp(bus_error_jmp) == 0) {
1675 catch_spr_faults = 1;
1682 printf("SPR 0x%03x (%4d) Faulted during write\n", n, n);
1684 catch_spr_faults = 0;
1687 static void dump_206_sprs(void)
1690 if (!cpu_has_feature(CPU_FTR_ARCH_206))
1693 /* Actually some of these pre-date 2.06, but whatevs */
1695 printf("srr0 = %.16x srr1 = %.16x dsisr = %.8x\n",
1696 mfspr(SPRN_SRR0), mfspr(SPRN_SRR1), mfspr(SPRN_DSISR));
1697 printf("dscr = %.16x ppr = %.16x pir = %.8x\n",
1698 mfspr(SPRN_DSCR), mfspr(SPRN_PPR), mfspr(SPRN_PIR));
1700 if (!(mfmsr() & MSR_HV))
1703 printf("sdr1 = %.16x hdar = %.16x hdsisr = %.8x\n",
1704 mfspr(SPRN_SDR1), mfspr(SPRN_HDAR), mfspr(SPRN_HDSISR));
1705 printf("hsrr0 = %.16x hsrr1 = %.16x hdec = %.8x\n",
1706 mfspr(SPRN_HSRR0), mfspr(SPRN_HSRR1), mfspr(SPRN_HDEC));
1707 printf("lpcr = %.16x pcr = %.16x lpidr = %.8x\n",
1708 mfspr(SPRN_LPCR), mfspr(SPRN_PCR), mfspr(SPRN_LPID));
1709 printf("hsprg0 = %.16x hsprg1 = %.16x\n",
1710 mfspr(SPRN_HSPRG0), mfspr(SPRN_HSPRG1));
1711 printf("dabr = %.16x dabrx = %.16x\n",
1712 mfspr(SPRN_DABR), mfspr(SPRN_DABRX));
1716 static void dump_207_sprs(void)
1721 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
1724 printf("dpdes = %.16x tir = %.16x cir = %.8x\n",
1725 mfspr(SPRN_DPDES), mfspr(SPRN_TIR), mfspr(SPRN_CIR));
1727 printf("fscr = %.16x tar = %.16x pspb = %.8x\n",
1728 mfspr(SPRN_FSCR), mfspr(SPRN_TAR), mfspr(SPRN_PSPB));
1732 /* Only if TM has been enabled in the kernel */
1733 printf("tfhar = %.16x tfiar = %.16x texasr = %.16x\n",
1734 mfspr(SPRN_TFHAR), mfspr(SPRN_TFIAR),
1735 mfspr(SPRN_TEXASR));
1738 printf("mmcr0 = %.16x mmcr1 = %.16x mmcr2 = %.16x\n",
1739 mfspr(SPRN_MMCR0), mfspr(SPRN_MMCR1), mfspr(SPRN_MMCR2));
1740 printf("pmc1 = %.8x pmc2 = %.8x pmc3 = %.8x pmc4 = %.8x\n",
1741 mfspr(SPRN_PMC1), mfspr(SPRN_PMC2),
1742 mfspr(SPRN_PMC3), mfspr(SPRN_PMC4));
1743 printf("mmcra = %.16x siar = %.16x pmc5 = %.8x\n",
1744 mfspr(SPRN_MMCRA), mfspr(SPRN_SIAR), mfspr(SPRN_PMC5));
1745 printf("sdar = %.16x sier = %.16x pmc6 = %.8x\n",
1746 mfspr(SPRN_SDAR), mfspr(SPRN_SIER), mfspr(SPRN_PMC6));
1747 printf("ebbhr = %.16x ebbrr = %.16x bescr = %.16x\n",
1748 mfspr(SPRN_EBBHR), mfspr(SPRN_EBBRR), mfspr(SPRN_BESCR));
1750 if (!(msr & MSR_HV))
1753 printf("hfscr = %.16x dhdes = %.16x rpr = %.16x\n",
1754 mfspr(SPRN_HFSCR), mfspr(SPRN_DHDES), mfspr(SPRN_RPR));
1755 printf("dawr = %.16x dawrx = %.16x ciabr = %.16x\n",
1756 mfspr(SPRN_DAWR), mfspr(SPRN_DAWRX), mfspr(SPRN_CIABR));
1760 static void dump_one_spr(int spr, bool show_unimplemented)
1765 if (!read_spr(spr, &val)) {
1766 printf("SPR 0x%03x (%4d) Faulted during read\n", spr, spr);
1770 if (val == 0xdeadbeef) {
1771 /* Looks like read was a nop, confirm */
1773 if (!read_spr(spr, &val)) {
1774 printf("SPR 0x%03x (%4d) Faulted during read\n", spr, spr);
1778 if (val == 0x0badcafe) {
1779 if (show_unimplemented)
1780 printf("SPR 0x%03x (%4d) Unimplemented\n", spr, spr);
1785 printf("SPR 0x%03x (%4d) = 0x%lx\n", spr, spr, val);
1788 static void super_regs(void)
1790 static unsigned long regno;
1798 unsigned long sp, toc;
1799 asm("mr %0,1" : "=r" (sp) :);
1800 asm("mr %0,2" : "=r" (toc) :);
1802 printf("msr = "REG" sprg0 = "REG"\n",
1803 mfmsr(), mfspr(SPRN_SPRG0));
1804 printf("pvr = "REG" sprg1 = "REG"\n",
1805 mfspr(SPRN_PVR), mfspr(SPRN_SPRG1));
1806 printf("dec = "REG" sprg2 = "REG"\n",
1807 mfspr(SPRN_DEC), mfspr(SPRN_SPRG2));
1808 printf("sp = "REG" sprg3 = "REG"\n", sp, mfspr(SPRN_SPRG3));
1809 printf("toc = "REG" dar = "REG"\n", toc, mfspr(SPRN_DAR));
1820 read_spr(regno, &val);
1822 write_spr(regno, val);
1823 dump_one_spr(regno, true);
1828 dump_one_spr(regno, true);
1832 for (spr = 1; spr < 1024; ++spr)
1833 dump_one_spr(spr, false);
1841 * Stuff for reading and writing memory safely
1844 mread(unsigned long adrs, void *buf, int size)
1850 if (setjmp(bus_error_jmp) == 0) {
1851 catch_memory_errors = 1;
1857 *(u16 *)q = *(u16 *)p;
1860 *(u32 *)q = *(u32 *)p;
1863 *(u64 *)q = *(u64 *)p;
1866 for( ; n < size; ++n) {
1872 /* wait a little while to see if we get a machine check */
1876 catch_memory_errors = 0;
1881 mwrite(unsigned long adrs, void *buf, int size)
1887 if (setjmp(bus_error_jmp) == 0) {
1888 catch_memory_errors = 1;
1894 *(u16 *)p = *(u16 *)q;
1897 *(u32 *)p = *(u32 *)q;
1900 *(u64 *)p = *(u64 *)q;
1903 for ( ; n < size; ++n) {
1909 /* wait a little while to see if we get a machine check */
1913 printf("*** Error writing address "REG"\n", adrs + n);
1915 catch_memory_errors = 0;
1919 static int fault_type;
1920 static int fault_except;
1921 static char *fault_chars[] = { "--", "**", "##" };
1923 static int handle_fault(struct pt_regs *regs)
1925 fault_except = TRAP(regs);
1926 switch (TRAP(regs)) {
1938 longjmp(bus_error_jmp, 1);
1943 #define SWAP(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
1946 byterev(unsigned char *val, int size)
1952 SWAP(val[0], val[1], t);
1955 SWAP(val[0], val[3], t);
1956 SWAP(val[1], val[2], t);
1958 case 8: /* is there really any use for this? */
1959 SWAP(val[0], val[7], t);
1960 SWAP(val[1], val[6], t);
1961 SWAP(val[2], val[5], t);
1962 SWAP(val[3], val[4], t);
1970 static char *memex_help_string =
1971 "Memory examine command usage:\n"
1972 "m [addr] [flags] examine/change memory\n"
1973 " addr is optional. will start where left off.\n"
1974 " flags may include chars from this set:\n"
1975 " b modify by bytes (default)\n"
1976 " w modify by words (2 byte)\n"
1977 " l modify by longs (4 byte)\n"
1978 " d modify by doubleword (8 byte)\n"
1979 " r toggle reverse byte order mode\n"
1980 " n do not read memory (for i/o spaces)\n"
1981 " . ok to read (default)\n"
1982 "NOTE: flags are saved as defaults\n"
1985 static char *memex_subcmd_help_string =
1986 "Memory examine subcommands:\n"
1987 " hexval write this val to current location\n"
1988 " 'string' write chars from string to this location\n"
1989 " ' increment address\n"
1990 " ^ decrement address\n"
1991 " / increment addr by 0x10. //=0x100, ///=0x1000, etc\n"
1992 " \\ decrement addr by 0x10. \\\\=0x100, \\\\\\=0x1000, etc\n"
1993 " ` clear no-read flag\n"
1994 " ; stay at this addr\n"
1995 " v change to byte mode\n"
1996 " w change to word (2 byte) mode\n"
1997 " l change to long (4 byte) mode\n"
1998 " u change to doubleword (8 byte) mode\n"
1999 " m addr change current addr\n"
2000 " n toggle no-read flag\n"
2001 " r toggle byte reverse flag\n"
2002 " < count back up count bytes\n"
2003 " > count skip forward count bytes\n"
2004 " x exit this mode\n"
2010 int cmd, inc, i, nslash;
2012 unsigned char val[16];
2014 scanhex((void *)&adrs);
2017 printf(memex_help_string);
2023 while ((cmd = skipbl()) != '\n') {
2025 case 'b': size = 1; break;
2026 case 'w': size = 2; break;
2027 case 'l': size = 4; break;
2028 case 'd': size = 8; break;
2029 case 'r': brev = !brev; break;
2030 case 'n': mnoread = 1; break;
2031 case '.': mnoread = 0; break;
2040 n = mread(adrs, val, size);
2041 printf(REG"%c", adrs, brev? 'r': ' ');
2046 for (i = 0; i < n; ++i)
2047 printf("%.2x", val[i]);
2048 for (; i < size; ++i)
2049 printf("%s", fault_chars[fault_type]);
2056 for (i = 0; i < size; ++i)
2057 val[i] = n >> (i * 8);
2060 mwrite(adrs, val, size);
2073 else if( n == '\'' )
2075 for (i = 0; i < size; ++i)
2076 val[i] = n >> (i * 8);
2079 mwrite(adrs, val, size);
2115 adrs -= 1 << nslash;
2119 adrs += 1 << nslash;
2123 adrs += 1 << -nslash;
2127 adrs -= 1 << -nslash;
2130 scanhex((void *)&adrs);
2149 printf(memex_subcmd_help_string);
2164 case 'n': c = '\n'; break;
2165 case 'r': c = '\r'; break;
2166 case 'b': c = '\b'; break;
2167 case 't': c = '\t'; break;
2172 static void xmon_rawdump (unsigned long adrs, long ndump)
2175 unsigned char temp[16];
2177 for (n = ndump; n > 0;) {
2179 nr = mread(adrs, temp, r);
2181 for (m = 0; m < r; ++m) {
2183 printf("%.2x", temp[m]);
2185 printf("%s", fault_chars[fault_type]);
2195 static void dump_one_paca(int cpu)
2197 struct paca_struct *p;
2198 #ifdef CONFIG_PPC_STD_MMU_64
2202 if (setjmp(bus_error_jmp) != 0) {
2203 printf("*** Error dumping paca for cpu 0x%x!\n", cpu);
2207 catch_memory_errors = 1;
2212 printf("paca for cpu 0x%x @ %p:\n", cpu, p);
2214 printf(" %-*s = %s\n", 20, "possible", cpu_possible(cpu) ? "yes" : "no");
2215 printf(" %-*s = %s\n", 20, "present", cpu_present(cpu) ? "yes" : "no");
2216 printf(" %-*s = %s\n", 20, "online", cpu_online(cpu) ? "yes" : "no");
2218 #define DUMP(paca, name, format) \
2219 printf(" %-*s = %#-*"format"\t(0x%lx)\n", 20, #name, 18, paca->name, \
2220 offsetof(struct paca_struct, name));
2222 DUMP(p, lock_token, "x");
2223 DUMP(p, paca_index, "x");
2224 DUMP(p, kernel_toc, "lx");
2225 DUMP(p, kernelbase, "lx");
2226 DUMP(p, kernel_msr, "lx");
2227 DUMP(p, emergency_sp, "p");
2228 #ifdef CONFIG_PPC_BOOK3S_64
2229 DUMP(p, mc_emergency_sp, "p");
2230 DUMP(p, in_mce, "x");
2231 DUMP(p, hmi_event_available, "x");
2233 DUMP(p, data_offset, "lx");
2234 DUMP(p, hw_cpu_id, "x");
2235 DUMP(p, cpu_start, "x");
2236 DUMP(p, kexec_state, "x");
2237 #ifdef CONFIG_PPC_STD_MMU_64
2238 for (i = 0; i < SLB_NUM_BOLTED; i++) {
2241 if (!p->slb_shadow_ptr)
2244 esid = be64_to_cpu(p->slb_shadow_ptr->save_area[i].esid);
2245 vsid = be64_to_cpu(p->slb_shadow_ptr->save_area[i].vsid);
2248 printf(" slb_shadow[%d]: = 0x%016lx 0x%016lx\n",
2252 DUMP(p, vmalloc_sllp, "x");
2253 DUMP(p, slb_cache_ptr, "x");
2254 for (i = 0; i < SLB_CACHE_ENTRIES; i++)
2255 printf(" slb_cache[%d]: = 0x%016lx\n", i, p->slb_cache[i]);
2257 DUMP(p, dscr_default, "llx");
2258 #ifdef CONFIG_PPC_BOOK3E
2260 DUMP(p, kernel_pgd, "p");
2261 DUMP(p, tcd_ptr, "p");
2262 DUMP(p, mc_kstack, "p");
2263 DUMP(p, crit_kstack, "p");
2264 DUMP(p, dbg_kstack, "p");
2266 DUMP(p, __current, "p");
2267 DUMP(p, kstack, "lx");
2268 DUMP(p, stab_rr, "lx");
2269 DUMP(p, saved_r1, "lx");
2270 DUMP(p, trap_save, "x");
2271 DUMP(p, soft_enabled, "x");
2272 DUMP(p, irq_happened, "x");
2273 DUMP(p, io_sync, "x");
2274 DUMP(p, irq_work_pending, "x");
2275 DUMP(p, nap_state_lost, "x");
2276 DUMP(p, sprg_vdso, "llx");
2278 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
2279 DUMP(p, tm_scratch, "llx");
2282 #ifdef CONFIG_PPC_POWERNV
2283 DUMP(p, core_idle_state_ptr, "p");
2284 DUMP(p, thread_idle_state, "x");
2285 DUMP(p, thread_mask, "x");
2286 DUMP(p, subcore_sibling_mask, "x");
2289 DUMP(p, accounting.user_time, "llx");
2290 DUMP(p, accounting.system_time, "llx");
2291 DUMP(p, accounting.user_time_scaled, "llx");
2292 DUMP(p, accounting.starttime, "llx");
2293 DUMP(p, accounting.starttime_user, "llx");
2294 DUMP(p, accounting.startspurr, "llx");
2295 DUMP(p, accounting.utime_sspurr, "llx");
2296 DUMP(p, stolen_time, "llx");
2299 catch_memory_errors = 0;
2303 static void dump_all_pacas(void)
2307 if (num_possible_cpus() == 0) {
2308 printf("No possible cpus, use 'dp #' to dump individual cpus\n");
2312 for_each_possible_cpu(cpu)
2316 static void dump_pacas(void)
2327 termch = c; /* Put c back, it wasn't 'a' */
2332 dump_one_paca(xmon_owner);
2345 xmon_start_pagination();
2347 xmon_end_pagination();
2352 if ((isxdigit(c) && c != 'f' && c != 'd') || c == '\n')
2354 scanhex((void *)&adrs);
2361 else if (nidump > MAX_DUMP)
2363 adrs += ppc_inst_dump(adrs, nidump, 1);
2365 } else if (c == 'l') {
2367 } else if (c == 'o') {
2369 } else if (c == 'r') {
2373 xmon_rawdump(adrs, ndump);
2380 else if (ndump > MAX_DUMP)
2382 prdump(adrs, ndump);
2389 prdump(unsigned long adrs, long ndump)
2391 long n, m, c, r, nr;
2392 unsigned char temp[16];
2394 for (n = ndump; n > 0;) {
2398 nr = mread(adrs, temp, r);
2400 for (m = 0; m < r; ++m) {
2401 if ((m & (sizeof(long) - 1)) == 0 && m > 0)
2404 printf("%.2x", temp[m]);
2406 printf("%s", fault_chars[fault_type]);
2408 for (; m < 16; ++m) {
2409 if ((m & (sizeof(long) - 1)) == 0)
2414 for (m = 0; m < r; ++m) {
2417 putchar(' ' <= c && c <= '~'? c: '.');
2430 typedef int (*instruction_dump_func)(unsigned long inst, unsigned long addr);
2433 generic_inst_dump(unsigned long adr, long count, int praddr,
2434 instruction_dump_func dump_func)
2437 unsigned long first_adr;
2438 unsigned long inst, last_inst = 0;
2439 unsigned char val[4];
2442 for (first_adr = adr; count > 0; --count, adr += 4) {
2443 nr = mread(adr, val, 4);
2446 const char *x = fault_chars[fault_type];
2447 printf(REG" %s%s%s%s\n", adr, x, x, x, x);
2451 inst = GETWORD(val);
2452 if (adr > first_adr && inst == last_inst) {
2462 printf(REG" %.8x", adr, inst);
2464 dump_func(inst, adr);
2467 return adr - first_adr;
2471 ppc_inst_dump(unsigned long adr, long count, int praddr)
2473 return generic_inst_dump(adr, count, praddr, print_insn_powerpc);
2477 print_address(unsigned long addr)
2479 xmon_print_symbol(addr, "\t# ", "");
2485 struct kmsg_dumper dumper = { .active = 1 };
2486 unsigned char buf[128];
2489 if (setjmp(bus_error_jmp) != 0) {
2490 printf("Error dumping printk buffer!\n");
2494 catch_memory_errors = 1;
2497 kmsg_dump_rewind_nolock(&dumper);
2498 xmon_start_pagination();
2499 while (kmsg_dump_get_line_nolock(&dumper, false, buf, sizeof(buf), &len)) {
2503 xmon_end_pagination();
2506 /* wait a little while to see if we get a machine check */
2508 catch_memory_errors = 0;
2511 #ifdef CONFIG_PPC_POWERNV
2512 static void dump_opal_msglog(void)
2514 unsigned char buf[128];
2518 if (!firmware_has_feature(FW_FEATURE_OPAL)) {
2519 printf("Machine is not running OPAL firmware.\n");
2523 if (setjmp(bus_error_jmp) != 0) {
2524 printf("Error dumping OPAL msglog!\n");
2528 catch_memory_errors = 1;
2531 xmon_start_pagination();
2532 while ((res = opal_msglog_copy(buf, pos, sizeof(buf) - 1))) {
2534 printf("Error dumping OPAL msglog! Error: %zd\n", res);
2541 xmon_end_pagination();
2544 /* wait a little while to see if we get a machine check */
2546 catch_memory_errors = 0;
2551 * Memory operations - move, set, print differences
2553 static unsigned long mdest; /* destination address */
2554 static unsigned long msrc; /* source address */
2555 static unsigned long mval; /* byte value to set memory to */
2556 static unsigned long mcount; /* # bytes to affect */
2557 static unsigned long mdiffs; /* max # differences to print */
2562 scanhex((void *)&mdest);
2563 if( termch != '\n' )
2565 scanhex((void *)(cmd == 's'? &mval: &msrc));
2566 if( termch != '\n' )
2568 scanhex((void *)&mcount);
2571 memmove((void *)mdest, (void *)msrc, mcount);
2574 memset((void *)mdest, mval, mcount);
2577 if( termch != '\n' )
2579 scanhex((void *)&mdiffs);
2580 memdiffs((unsigned char *)mdest, (unsigned char *)msrc, mcount, mdiffs);
2586 memdiffs(unsigned char *p1, unsigned char *p2, unsigned nb, unsigned maxpr)
2591 for( n = nb; n > 0; --n )
2592 if( *p1++ != *p2++ )
2593 if( ++prt <= maxpr )
2594 printf("%.16x %.2x # %.16x %.2x\n", p1 - 1,
2595 p1[-1], p2 - 1, p2[-1]);
2597 printf("Total of %d differences\n", prt);
2600 static unsigned mend;
2601 static unsigned mask;
2607 unsigned char val[4];
2610 scanhex((void *)&mdest);
2611 if (termch != '\n') {
2613 scanhex((void *)&mend);
2614 if (termch != '\n') {
2616 scanhex((void *)&mval);
2618 if (termch != '\n') termch = 0;
2619 scanhex((void *)&mask);
2623 for (a = mdest; a < mend; a += 4) {
2624 if (mread(a, val, 4) == 4
2625 && ((GETWORD(val) ^ mval) & mask) == 0) {
2626 printf("%.16x: %.16x\n", a, GETWORD(val));
2633 static unsigned long mskip = 0x1000;
2634 static unsigned long mlim = 0xffffffff;
2644 if (termch != '\n') termch = 0;
2646 if (termch != '\n') termch = 0;
2649 for (a = mdest; a < mlim; a += mskip) {
2650 ok = mread(a, &v, 1);
2652 printf("%.8x .. ", a);
2653 } else if (!ok && ook)
2654 printf("%.8x\n", a - mskip);
2660 printf("%.8x\n", a - mskip);
2663 static void show_task(struct task_struct *tsk)
2668 * Cloned from kdb_task_state_char(), which is not entirely
2669 * appropriate for calling from xmon. This could be moved
2670 * to a common, generic, routine used by both.
2672 state = (tsk->state == 0) ? 'R' :
2673 (tsk->state < 0) ? 'U' :
2674 (tsk->state & TASK_UNINTERRUPTIBLE) ? 'D' :
2675 (tsk->state & TASK_STOPPED) ? 'T' :
2676 (tsk->state & TASK_TRACED) ? 'C' :
2677 (tsk->exit_state & EXIT_ZOMBIE) ? 'Z' :
2678 (tsk->exit_state & EXIT_DEAD) ? 'E' :
2679 (tsk->state & TASK_INTERRUPTIBLE) ? 'S' : '?';
2681 printf("%p %016lx %6d %6d %c %2d %s\n", tsk,
2683 tsk->pid, tsk->parent->pid,
2684 state, task_thread_info(tsk)->cpu,
2688 static void show_tasks(void)
2691 struct task_struct *tsk = NULL;
2693 printf(" task_struct ->thread.ksp PID PPID S P CMD\n");
2696 tsk = (struct task_struct *)tskv;
2698 if (setjmp(bus_error_jmp) != 0) {
2699 catch_memory_errors = 0;
2700 printf("*** Error dumping task %p\n", tsk);
2704 catch_memory_errors = 1;
2710 for_each_process(tsk)
2715 catch_memory_errors = 0;
2718 static void proccall(void)
2720 unsigned long args[8];
2723 typedef unsigned long (*callfunc_t)(unsigned long, unsigned long,
2724 unsigned long, unsigned long, unsigned long,
2725 unsigned long, unsigned long, unsigned long);
2728 if (!scanhex(&adrs))
2732 for (i = 0; i < 8; ++i)
2734 for (i = 0; i < 8; ++i) {
2735 if (!scanhex(&args[i]) || termch == '\n')
2739 func = (callfunc_t) adrs;
2741 if (setjmp(bus_error_jmp) == 0) {
2742 catch_memory_errors = 1;
2744 ret = func(args[0], args[1], args[2], args[3],
2745 args[4], args[5], args[6], args[7]);
2747 printf("return value is 0x%lx\n", ret);
2749 printf("*** %x exception occurred\n", fault_except);
2751 catch_memory_errors = 0;
2754 /* Input scanning routines */
2765 while( c == ' ' || c == '\t' )
2771 static char *regnames[N_PTREGS] = {
2772 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2773 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
2774 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
2775 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
2776 "pc", "msr", "or3", "ctr", "lr", "xer", "ccr",
2782 "trap", "dar", "dsisr", "res"
2786 scanhex(unsigned long *vp)
2793 /* parse register name */
2797 for (i = 0; i < sizeof(regname) - 1; ++i) {
2806 for (i = 0; i < N_PTREGS; ++i) {
2807 if (strcmp(regnames[i], regname) == 0) {
2808 if (xmon_regs == NULL) {
2809 printf("regs not available\n");
2812 *vp = ((unsigned long *)xmon_regs)[i];
2816 printf("invalid register name '%%%s'\n", regname);
2820 /* skip leading "0x" if any */
2834 } else if (c == '$') {
2836 for (i=0; i<63; i++) {
2838 if (isspace(c) || c == '\0') {
2846 if (setjmp(bus_error_jmp) == 0) {
2847 catch_memory_errors = 1;
2849 *vp = kallsyms_lookup_name(tmpstr);
2852 catch_memory_errors = 0;
2854 printf("unknown symbol '%s'\n", tmpstr);
2887 static int hexdigit(int c)
2889 if( '0' <= c && c <= '9' )
2891 if( 'A' <= c && c <= 'F' )
2892 return c - ('A' - 10);
2893 if( 'a' <= c && c <= 'f' )
2894 return c - ('a' - 10);
2899 getstring(char *s, int size)
2910 } while( c != ' ' && c != '\t' && c != '\n' );
2915 static char line[256];
2916 static char *lineptr;
2927 if (lineptr == NULL || *lineptr == 0) {
2928 if (xmon_gets(line, sizeof(line)) == NULL) {
2938 take_input(char *str)
2947 int type = inchar();
2949 static char tmp[64];
2954 xmon_print_symbol(addr, ": ", "\n");
2959 if (setjmp(bus_error_jmp) == 0) {
2960 catch_memory_errors = 1;
2962 addr = kallsyms_lookup_name(tmp);
2964 printf("%s: %lx\n", tmp, addr);
2966 printf("Symbol '%s' not found.\n", tmp);
2969 catch_memory_errors = 0;
2976 /* Print an address in numeric and symbolic form (if possible) */
2977 static void xmon_print_symbol(unsigned long address, const char *mid,
2981 const char *name = NULL;
2982 unsigned long offset, size;
2984 printf(REG, address);
2985 if (setjmp(bus_error_jmp) == 0) {
2986 catch_memory_errors = 1;
2988 name = kallsyms_lookup(address, &size, &offset, &modname,
2991 /* wait a little while to see if we get a machine check */
2995 catch_memory_errors = 0;
2998 printf("%s%s+%#lx/%#lx", mid, name, offset, size);
3000 printf(" [%s]", modname);
3002 printf("%s", after);
3005 #ifdef CONFIG_PPC_STD_MMU_64
3006 void dump_segments(void)
3009 unsigned long esid,vsid;
3012 printf("SLB contents of cpu 0x%x\n", smp_processor_id());
3014 for (i = 0; i < mmu_slb_size; i++) {
3015 asm volatile("slbmfee %0,%1" : "=r" (esid) : "r" (i));
3016 asm volatile("slbmfev %0,%1" : "=r" (vsid) : "r" (i));
3018 printf("%02d %016lx %016lx", i, esid, vsid);
3019 if (esid & SLB_ESID_V) {
3020 llp = vsid & SLB_VSID_LLP;
3021 if (vsid & SLB_VSID_B_1T) {
3022 printf(" 1T ESID=%9lx VSID=%13lx LLP:%3lx \n",
3024 (vsid & ~SLB_VSID_B) >> SLB_VSID_SHIFT_1T,
3027 printf(" 256M ESID=%9lx VSID=%13lx LLP:%3lx \n",
3029 (vsid & ~SLB_VSID_B) >> SLB_VSID_SHIFT,
3039 #ifdef CONFIG_PPC_STD_MMU_32
3040 void dump_segments(void)
3045 for (i = 0; i < 16; ++i)
3046 printf(" %x", mfsrin(i << 28));
3052 static void dump_tlb_44x(void)
3056 for (i = 0; i < PPC44x_TLB_SIZE; i++) {
3057 unsigned long w0,w1,w2;
3058 asm volatile("tlbre %0,%1,0" : "=r" (w0) : "r" (i));
3059 asm volatile("tlbre %0,%1,1" : "=r" (w1) : "r" (i));
3060 asm volatile("tlbre %0,%1,2" : "=r" (w2) : "r" (i));
3061 printf("[%02x] %08x %08x %08x ", i, w0, w1, w2);
3062 if (w0 & PPC44x_TLB_VALID) {
3063 printf("V %08x -> %01x%08x %c%c%c%c%c",
3064 w0 & PPC44x_TLB_EPN_MASK,
3065 w1 & PPC44x_TLB_ERPN_MASK,
3066 w1 & PPC44x_TLB_RPN_MASK,
3067 (w2 & PPC44x_TLB_W) ? 'W' : 'w',
3068 (w2 & PPC44x_TLB_I) ? 'I' : 'i',
3069 (w2 & PPC44x_TLB_M) ? 'M' : 'm',
3070 (w2 & PPC44x_TLB_G) ? 'G' : 'g',
3071 (w2 & PPC44x_TLB_E) ? 'E' : 'e');
3076 #endif /* CONFIG_44x */
3078 #ifdef CONFIG_PPC_BOOK3E
3079 static void dump_tlb_book3e(void)
3081 u32 mmucfg, pidmask, lpidmask;
3083 int i, tlb, ntlbs, pidsz, lpidsz, rasz, lrat = 0;
3085 static const char *pgsz_names[] = {
3120 /* Gather some infos about the MMU */
3121 mmucfg = mfspr(SPRN_MMUCFG);
3122 mmu_version = (mmucfg & 3) + 1;
3123 ntlbs = ((mmucfg >> 2) & 3) + 1;
3124 pidsz = ((mmucfg >> 6) & 0x1f) + 1;
3125 lpidsz = (mmucfg >> 24) & 0xf;
3126 rasz = (mmucfg >> 16) & 0x7f;
3127 if ((mmu_version > 1) && (mmucfg & 0x10000))
3129 printf("Book3E MMU MAV=%d.0,%d TLBs,%d-bit PID,%d-bit LPID,%d-bit RA\n",
3130 mmu_version, ntlbs, pidsz, lpidsz, rasz);
3131 pidmask = (1ul << pidsz) - 1;
3132 lpidmask = (1ul << lpidsz) - 1;
3133 ramask = (1ull << rasz) - 1;
3135 for (tlb = 0; tlb < ntlbs; tlb++) {
3137 int nent, assoc, new_cc = 1;
3138 printf("TLB %d:\n------\n", tlb);
3141 tlbcfg = mfspr(SPRN_TLB0CFG);
3144 tlbcfg = mfspr(SPRN_TLB1CFG);
3147 tlbcfg = mfspr(SPRN_TLB2CFG);
3150 tlbcfg = mfspr(SPRN_TLB3CFG);
3153 printf("Unsupported TLB number !\n");
3156 nent = tlbcfg & 0xfff;
3157 assoc = (tlbcfg >> 24) & 0xff;
3158 for (i = 0; i < nent; i++) {
3159 u32 mas0 = MAS0_TLBSEL(tlb);
3160 u32 mas1 = MAS1_TSIZE(BOOK3E_PAGESZ_4K);
3163 int esel = i, cc = i;
3171 mas0 |= MAS0_ESEL(esel);
3172 mtspr(SPRN_MAS0, mas0);
3173 mtspr(SPRN_MAS1, mas1);
3174 mtspr(SPRN_MAS2, mas2);
3175 asm volatile("tlbre 0,0,0" : : : "memory");
3176 mas1 = mfspr(SPRN_MAS1);
3177 mas2 = mfspr(SPRN_MAS2);
3178 mas7_mas3 = mfspr(SPRN_MAS7_MAS3);
3179 if (assoc && (i % assoc) == 0)
3181 if (!(mas1 & MAS1_VALID))
3184 printf("%04x- ", i);
3186 printf("%04x-%c", cc, 'A' + esel);
3188 printf(" |%c", 'A' + esel);
3190 printf(" %016llx %04x %s %c%c AS%c",
3192 (mas1 >> 16) & 0x3fff,
3193 pgsz_names[(mas1 >> 7) & 0x1f],
3194 mas1 & MAS1_IND ? 'I' : ' ',
3195 mas1 & MAS1_IPROT ? 'P' : ' ',
3196 mas1 & MAS1_TS ? '1' : '0');
3197 printf(" %c%c%c%c%c%c%c",
3198 mas2 & MAS2_X0 ? 'a' : ' ',
3199 mas2 & MAS2_X1 ? 'v' : ' ',
3200 mas2 & MAS2_W ? 'w' : ' ',
3201 mas2 & MAS2_I ? 'i' : ' ',
3202 mas2 & MAS2_M ? 'm' : ' ',
3203 mas2 & MAS2_G ? 'g' : ' ',
3204 mas2 & MAS2_E ? 'e' : ' ');
3205 printf(" %016llx", mas7_mas3 & ramask & ~0x7ffull);
3206 if (mas1 & MAS1_IND)
3208 pgsz_names[(mas7_mas3 >> 1) & 0x1f]);
3210 printf(" U%c%c%c S%c%c%c\n",
3211 mas7_mas3 & MAS3_UX ? 'x' : ' ',
3212 mas7_mas3 & MAS3_UW ? 'w' : ' ',
3213 mas7_mas3 & MAS3_UR ? 'r' : ' ',
3214 mas7_mas3 & MAS3_SX ? 'x' : ' ',
3215 mas7_mas3 & MAS3_SW ? 'w' : ' ',
3216 mas7_mas3 & MAS3_SR ? 'r' : ' ');
3220 #endif /* CONFIG_PPC_BOOK3E */
3222 static void xmon_init(int enable)
3226 __debugger_ipi = xmon_ipi;
3227 __debugger_bpt = xmon_bpt;
3228 __debugger_sstep = xmon_sstep;
3229 __debugger_iabr_match = xmon_iabr_match;
3230 __debugger_break_match = xmon_break_match;
3231 __debugger_fault_handler = xmon_fault_handler;
3233 #ifdef CONFIG_PPC_PSERIES
3235 * Get the token here to avoid trying to get a lock
3236 * during the crash, causing a deadlock.
3238 set_indicator_token = rtas_token("set-indicator");
3242 __debugger_ipi = NULL;
3243 __debugger_bpt = NULL;
3244 __debugger_sstep = NULL;
3245 __debugger_iabr_match = NULL;
3246 __debugger_break_match = NULL;
3247 __debugger_fault_handler = NULL;
3251 #ifdef CONFIG_MAGIC_SYSRQ
3252 static void sysrq_handle_xmon(int key)
3254 /* ensure xmon is enabled */
3256 debugger(get_irq_regs());
3259 static struct sysrq_key_op sysrq_xmon_op = {
3260 .handler = sysrq_handle_xmon,
3261 .help_msg = "xmon(x)",
3262 .action_msg = "Entering xmon",
3265 static int __init setup_xmon_sysrq(void)
3267 register_sysrq_key('x', &sysrq_xmon_op);
3270 __initcall(setup_xmon_sysrq);
3271 #endif /* CONFIG_MAGIC_SYSRQ */
3273 static int __initdata xmon_early, xmon_off;
3275 static int __init early_parse_xmon(char *p)
3277 if (!p || strncmp(p, "early", 5) == 0) {
3278 /* just "xmon" is equivalent to "xmon=early" */
3281 } else if (strncmp(p, "on", 2) == 0)
3283 else if (strncmp(p, "off", 3) == 0)
3285 else if (strncmp(p, "nobt", 4) == 0)
3286 xmon_no_auto_backtrace = 1;
3292 early_param("xmon", early_parse_xmon);
3294 void __init xmon_setup(void)
3296 #ifdef CONFIG_XMON_DEFAULT
3304 #ifdef CONFIG_SPU_BASE
3308 u64 saved_mfc_sr1_RW;
3309 u32 saved_spu_runcntl_RW;
3310 unsigned long dump_addr;
3314 #define XMON_NUM_SPUS 16 /* Enough for current hardware */
3316 static struct spu_info spu_info[XMON_NUM_SPUS];
3318 void xmon_register_spus(struct list_head *list)
3322 list_for_each_entry(spu, list, full_list) {
3323 if (spu->number >= XMON_NUM_SPUS) {
3328 spu_info[spu->number].spu = spu;
3329 spu_info[spu->number].stopped_ok = 0;
3330 spu_info[spu->number].dump_addr = (unsigned long)
3331 spu_info[spu->number].spu->local_store;
3335 static void stop_spus(void)
3341 for (i = 0; i < XMON_NUM_SPUS; i++) {
3342 if (!spu_info[i].spu)
3345 if (setjmp(bus_error_jmp) == 0) {
3346 catch_memory_errors = 1;
3349 spu = spu_info[i].spu;
3351 spu_info[i].saved_spu_runcntl_RW =
3352 in_be32(&spu->problem->spu_runcntl_RW);
3354 tmp = spu_mfc_sr1_get(spu);
3355 spu_info[i].saved_mfc_sr1_RW = tmp;
3357 tmp &= ~MFC_STATE1_MASTER_RUN_CONTROL_MASK;
3358 spu_mfc_sr1_set(spu, tmp);
3363 spu_info[i].stopped_ok = 1;
3365 printf("Stopped spu %.2d (was %s)\n", i,
3366 spu_info[i].saved_spu_runcntl_RW ?
3367 "running" : "stopped");
3369 catch_memory_errors = 0;
3370 printf("*** Error stopping spu %.2d\n", i);
3372 catch_memory_errors = 0;
3376 static void restart_spus(void)
3381 for (i = 0; i < XMON_NUM_SPUS; i++) {
3382 if (!spu_info[i].spu)
3385 if (!spu_info[i].stopped_ok) {
3386 printf("*** Error, spu %d was not successfully stopped"
3387 ", not restarting\n", i);
3391 if (setjmp(bus_error_jmp) == 0) {
3392 catch_memory_errors = 1;
3395 spu = spu_info[i].spu;
3396 spu_mfc_sr1_set(spu, spu_info[i].saved_mfc_sr1_RW);
3397 out_be32(&spu->problem->spu_runcntl_RW,
3398 spu_info[i].saved_spu_runcntl_RW);
3403 printf("Restarted spu %.2d\n", i);
3405 catch_memory_errors = 0;
3406 printf("*** Error restarting spu %.2d\n", i);
3408 catch_memory_errors = 0;
3412 #define DUMP_WIDTH 23
3413 #define DUMP_VALUE(format, field, value) \
3415 if (setjmp(bus_error_jmp) == 0) { \
3416 catch_memory_errors = 1; \
3418 printf(" %-*s = "format"\n", DUMP_WIDTH, \
3423 catch_memory_errors = 0; \
3424 printf(" %-*s = *** Error reading field.\n", \
3425 DUMP_WIDTH, #field); \
3427 catch_memory_errors = 0; \
3430 #define DUMP_FIELD(obj, format, field) \
3431 DUMP_VALUE(format, field, obj->field)
3433 static void dump_spu_fields(struct spu *spu)
3435 printf("Dumping spu fields at address %p:\n", spu);
3437 DUMP_FIELD(spu, "0x%x", number);
3438 DUMP_FIELD(spu, "%s", name);
3439 DUMP_FIELD(spu, "0x%lx", local_store_phys);
3440 DUMP_FIELD(spu, "0x%p", local_store);
3441 DUMP_FIELD(spu, "0x%lx", ls_size);
3442 DUMP_FIELD(spu, "0x%x", node);
3443 DUMP_FIELD(spu, "0x%lx", flags);
3444 DUMP_FIELD(spu, "%d", class_0_pending);
3445 DUMP_FIELD(spu, "0x%lx", class_0_dar);
3446 DUMP_FIELD(spu, "0x%lx", class_1_dar);
3447 DUMP_FIELD(spu, "0x%lx", class_1_dsisr);
3448 DUMP_FIELD(spu, "0x%lx", irqs[0]);
3449 DUMP_FIELD(spu, "0x%lx", irqs[1]);
3450 DUMP_FIELD(spu, "0x%lx", irqs[2]);
3451 DUMP_FIELD(spu, "0x%x", slb_replace);
3452 DUMP_FIELD(spu, "%d", pid);
3453 DUMP_FIELD(spu, "0x%p", mm);
3454 DUMP_FIELD(spu, "0x%p", ctx);
3455 DUMP_FIELD(spu, "0x%p", rq);
3456 DUMP_FIELD(spu, "0x%p", timestamp);
3457 DUMP_FIELD(spu, "0x%lx", problem_phys);
3458 DUMP_FIELD(spu, "0x%p", problem);
3459 DUMP_VALUE("0x%x", problem->spu_runcntl_RW,
3460 in_be32(&spu->problem->spu_runcntl_RW));
3461 DUMP_VALUE("0x%x", problem->spu_status_R,
3462 in_be32(&spu->problem->spu_status_R));
3463 DUMP_VALUE("0x%x", problem->spu_npc_RW,
3464 in_be32(&spu->problem->spu_npc_RW));
3465 DUMP_FIELD(spu, "0x%p", priv2);
3466 DUMP_FIELD(spu, "0x%p", pdata);
3470 spu_inst_dump(unsigned long adr, long count, int praddr)
3472 return generic_inst_dump(adr, count, praddr, print_insn_spu);
3475 static void dump_spu_ls(unsigned long num, int subcmd)
3477 unsigned long offset, addr, ls_addr;
3479 if (setjmp(bus_error_jmp) == 0) {
3480 catch_memory_errors = 1;
3482 ls_addr = (unsigned long)spu_info[num].spu->local_store;
3486 catch_memory_errors = 0;
3487 printf("*** Error: accessing spu info for spu %d\n", num);
3490 catch_memory_errors = 0;
3492 if (scanhex(&offset))
3493 addr = ls_addr + offset;
3495 addr = spu_info[num].dump_addr;
3497 if (addr >= ls_addr + LS_SIZE) {
3498 printf("*** Error: address outside of local store\n");
3504 addr += spu_inst_dump(addr, 16, 1);
3514 spu_info[num].dump_addr = addr;
3517 static int do_spu_cmd(void)
3519 static unsigned long num = 0;
3520 int cmd, subcmd = 0;
3532 if (isxdigit(subcmd) || subcmd == '\n')
3536 if (num >= XMON_NUM_SPUS || !spu_info[num].spu) {
3537 printf("*** Error: invalid spu number\n");
3543 dump_spu_fields(spu_info[num].spu);
3546 dump_spu_ls(num, subcmd);
3557 #else /* ! CONFIG_SPU_BASE */
3558 static int do_spu_cmd(void)