xmon.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837
  1. /*
  2. * Routines providing a simple monitor for use on the PowerMac.
  3. *
  4. * Copyright (C) 1996-2005 Paul Mackerras.
  5. * Copyright (C) 2001 PPC64 Team, IBM Corp
  6. * Copyrignt (C) 2006 Michael Ellerman, IBM Corp
  7. *
  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.
  12. */
  13. #include <linux/errno.h>
  14. #include <linux/sched.h>
  15. #include <linux/smp.h>
  16. #include <linux/mm.h>
  17. #include <linux/reboot.h>
  18. #include <linux/delay.h>
  19. #include <linux/kallsyms.h>
  20. #include <linux/cpumask.h>
  21. #include <linux/module.h>
  22. #include <linux/sysrq.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <asm/ptrace.h>
  26. #include <asm/string.h>
  27. #include <asm/prom.h>
  28. #include <asm/machdep.h>
  29. #include <asm/xmon.h>
  30. #include <asm/processor.h>
  31. #include <asm/pgtable.h>
  32. #include <asm/mmu.h>
  33. #include <asm/mmu_context.h>
  34. #include <asm/cputable.h>
  35. #include <asm/rtas.h>
  36. #include <asm/sstep.h>
  37. #include <asm/bug.h>
  38. #include <asm/irq_regs.h>
  39. #include <asm/spu.h>
  40. #include <asm/spu_priv1.h>
  41. #include <asm/firmware.h>
  42. #ifdef CONFIG_PPC64
  43. #include <asm/hvcall.h>
  44. #include <asm/paca.h>
  45. #endif
  46. #include "nonstdio.h"
  47. #define scanhex xmon_scanhex
  48. #define skipbl xmon_skipbl
  49. #ifdef CONFIG_SMP
  50. cpumask_t cpus_in_xmon = CPU_MASK_NONE;
  51. static unsigned long xmon_taken = 1;
  52. static int xmon_owner;
  53. static int xmon_gate;
  54. #endif /* CONFIG_SMP */
  55. static unsigned long in_xmon = 0;
  56. static unsigned long adrs;
  57. static int size = 1;
  58. #define MAX_DUMP (128 * 1024)
  59. static unsigned long ndump = 64;
  60. static unsigned long nidump = 16;
  61. static unsigned long ncsum = 4096;
  62. static int termch;
  63. static char tmpstr[128];
  64. #define JMP_BUF_LEN 23
  65. static long bus_error_jmp[JMP_BUF_LEN];
  66. static int catch_memory_errors;
  67. static long *xmon_fault_jmp[NR_CPUS];
  68. #define setjmp xmon_setjmp
  69. #define longjmp xmon_longjmp
  70. /* Breakpoint stuff */
  71. struct bpt {
  72. unsigned long address;
  73. unsigned int instr[2];
  74. atomic_t ref_count;
  75. int enabled;
  76. unsigned long pad;
  77. };
  78. /* Bits in bpt.enabled */
  79. #define BP_IABR_TE 1 /* IABR translation enabled */
  80. #define BP_IABR 2
  81. #define BP_TRAP 8
  82. #define BP_DABR 0x10
  83. #define NBPTS 256
  84. static struct bpt bpts[NBPTS];
  85. static struct bpt dabr;
  86. static struct bpt *iabr;
  87. static unsigned bpinstr = 0x7fe00008; /* trap */
  88. #define BP_NUM(bp) ((bp) - bpts + 1)
  89. /* Prototypes */
  90. static int cmds(struct pt_regs *);
  91. static int mread(unsigned long, void *, int);
  92. static int mwrite(unsigned long, void *, int);
  93. static int handle_fault(struct pt_regs *);
  94. static void byterev(unsigned char *, int);
  95. static void memex(void);
  96. static int bsesc(void);
  97. static void dump(void);
  98. static void prdump(unsigned long, long);
  99. static int ppc_inst_dump(unsigned long, long, int);
  100. void print_address(unsigned long);
  101. static void backtrace(struct pt_regs *);
  102. static void excprint(struct pt_regs *);
  103. static void prregs(struct pt_regs *);
  104. static void memops(int);
  105. static void memlocate(void);
  106. static void memzcan(void);
  107. static void memdiffs(unsigned char *, unsigned char *, unsigned, unsigned);
  108. int skipbl(void);
  109. int scanhex(unsigned long *valp);
  110. static void scannl(void);
  111. static int hexdigit(int);
  112. void getstring(char *, int);
  113. static void flush_input(void);
  114. static int inchar(void);
  115. static void take_input(char *);
  116. static unsigned long read_spr(int);
  117. static void write_spr(int, unsigned long);
  118. static void super_regs(void);
  119. static void remove_bpts(void);
  120. static void insert_bpts(void);
  121. static void remove_cpu_bpts(void);
  122. static void insert_cpu_bpts(void);
  123. static struct bpt *at_breakpoint(unsigned long pc);
  124. static struct bpt *in_breakpoint_table(unsigned long pc, unsigned long *offp);
  125. static int do_step(struct pt_regs *);
  126. static void bpt_cmds(void);
  127. static void cacheflush(void);
  128. static int cpu_cmd(void);
  129. static void csum(void);
  130. static void bootcmds(void);
  131. static void proccall(void);
  132. void dump_segments(void);
  133. static void symbol_lookup(void);
  134. static void xmon_show_stack(unsigned long sp, unsigned long lr,
  135. unsigned long pc);
  136. static void xmon_print_symbol(unsigned long address, const char *mid,
  137. const char *after);
  138. static const char *getvecname(unsigned long vec);
  139. static int do_spu_cmd(void);
  140. int xmon_no_auto_backtrace;
  141. extern int print_insn_powerpc(unsigned long, unsigned long, int);
  142. extern void xmon_enter(void);
  143. extern void xmon_leave(void);
  144. extern long setjmp(long *);
  145. extern void longjmp(long *, long);
  146. extern void xmon_save_regs(struct pt_regs *);
  147. #ifdef CONFIG_PPC64
  148. #define REG "%.16lx"
  149. #define REGS_PER_LINE 4
  150. #define LAST_VOLATILE 13
  151. #else
  152. #define REG "%.8lx"
  153. #define REGS_PER_LINE 8
  154. #define LAST_VOLATILE 12
  155. #endif
  156. #define GETWORD(v) (((v)[0] << 24) + ((v)[1] << 16) + ((v)[2] << 8) + (v)[3])
  157. #define isxdigit(c) (('0' <= (c) && (c) <= '9') \
  158. || ('a' <= (c) && (c) <= 'f') \
  159. || ('A' <= (c) && (c) <= 'F'))
  160. #define isalnum(c) (('0' <= (c) && (c) <= '9') \
  161. || ('a' <= (c) && (c) <= 'z') \
  162. || ('A' <= (c) && (c) <= 'Z'))
  163. #define isspace(c) (c == ' ' || c == '\t' || c == 10 || c == 13 || c == 0)
  164. static char *help_string = "\
  165. Commands:\n\
  166. b show breakpoints\n\
  167. bd set data breakpoint\n\
  168. bi set instruction breakpoint\n\
  169. bc clear breakpoint\n"
  170. #ifdef CONFIG_SMP
  171. "\
  172. c print cpus stopped in xmon\n\
  173. c# try to switch to cpu number h (in hex)\n"
  174. #endif
  175. "\
  176. C checksum\n\
  177. d dump bytes\n\
  178. di dump instructions\n\
  179. df dump float values\n\
  180. dd dump double values\n\
  181. dr dump stream of raw bytes\n\
  182. e print exception information\n\
  183. f flush cache\n\
  184. la lookup symbol+offset of specified address\n\
  185. ls lookup address of specified symbol\n\
  186. m examine/change memory\n\
  187. mm move a block of memory\n\
  188. ms set a block of memory\n\
  189. md compare two blocks of memory\n\
  190. ml locate a block of memory\n\
  191. mz zero a block of memory\n\
  192. mi show information about memory allocation\n\
  193. p call a procedure\n\
  194. r print registers\n\
  195. s single step\n"
  196. #ifdef CONFIG_PPC_CELL
  197. " ss stop execution on all spus\n\
  198. sr restore execution on stopped spus\n\
  199. sf # dump spu fields for spu # (in hex)\n"
  200. #endif
  201. " S print special registers\n\
  202. t print backtrace\n\
  203. x exit monitor and recover\n\
  204. X exit monitor and dont recover\n"
  205. #ifdef CONFIG_PPC64
  206. " u dump segment table or SLB\n"
  207. #endif
  208. #ifdef CONFIG_PPC_STD_MMU_32
  209. " u dump segment registers\n"
  210. #endif
  211. " ? help\n"
  212. " zr reboot\n\
  213. zh halt\n"
  214. ;
  215. static struct pt_regs *xmon_regs;
  216. static inline void sync(void)
  217. {
  218. asm volatile("sync; isync");
  219. }
  220. static inline void store_inst(void *p)
  221. {
  222. asm volatile ("dcbst 0,%0; sync; icbi 0,%0; isync" : : "r" (p));
  223. }
  224. static inline void cflush(void *p)
  225. {
  226. asm volatile ("dcbf 0,%0; icbi 0,%0" : : "r" (p));
  227. }
  228. static inline void cinval(void *p)
  229. {
  230. asm volatile ("dcbi 0,%0; icbi 0,%0" : : "r" (p));
  231. }
  232. /*
  233. * Disable surveillance (the service processor watchdog function)
  234. * while we are in xmon.
  235. * XXX we should re-enable it when we leave. :)
  236. */
  237. #define SURVEILLANCE_TOKEN 9000
  238. static inline void disable_surveillance(void)
  239. {
  240. #ifdef CONFIG_PPC_PSERIES
  241. /* Since this can't be a module, args should end up below 4GB. */
  242. static struct rtas_args args;
  243. /*
  244. * At this point we have got all the cpus we can into
  245. * xmon, so there is hopefully no other cpu calling RTAS
  246. * at the moment, even though we don't take rtas.lock.
  247. * If we did try to take rtas.lock there would be a
  248. * real possibility of deadlock.
  249. */
  250. args.token = rtas_token("set-indicator");
  251. if (args.token == RTAS_UNKNOWN_SERVICE)
  252. return;
  253. args.nargs = 3;
  254. args.nret = 1;
  255. args.rets = &args.args[3];
  256. args.args[0] = SURVEILLANCE_TOKEN;
  257. args.args[1] = 0;
  258. args.args[2] = 0;
  259. enter_rtas(__pa(&args));
  260. #endif /* CONFIG_PPC_PSERIES */
  261. }
  262. #ifdef CONFIG_SMP
  263. static int xmon_speaker;
  264. static void get_output_lock(void)
  265. {
  266. int me = smp_processor_id() + 0x100;
  267. int last_speaker = 0, prev;
  268. long timeout;
  269. if (xmon_speaker == me)
  270. return;
  271. for (;;) {
  272. if (xmon_speaker == 0) {
  273. last_speaker = cmpxchg(&xmon_speaker, 0, me);
  274. if (last_speaker == 0)
  275. return;
  276. }
  277. timeout = 10000000;
  278. while (xmon_speaker == last_speaker) {
  279. if (--timeout > 0)
  280. continue;
  281. /* hostile takeover */
  282. prev = cmpxchg(&xmon_speaker, last_speaker, me);
  283. if (prev == last_speaker)
  284. return;
  285. break;
  286. }
  287. }
  288. }
  289. static void release_output_lock(void)
  290. {
  291. xmon_speaker = 0;
  292. }
  293. #endif
  294. static int xmon_core(struct pt_regs *regs, int fromipi)
  295. {
  296. int cmd = 0;
  297. unsigned long msr;
  298. struct bpt *bp;
  299. long recurse_jmp[JMP_BUF_LEN];
  300. unsigned long offset;
  301. #ifdef CONFIG_SMP
  302. int cpu;
  303. int secondary;
  304. unsigned long timeout;
  305. #endif
  306. msr = mfmsr();
  307. mtmsr(msr & ~MSR_EE); /* disable interrupts */
  308. bp = in_breakpoint_table(regs->nip, &offset);
  309. if (bp != NULL) {
  310. regs->nip = bp->address + offset;
  311. atomic_dec(&bp->ref_count);
  312. }
  313. remove_cpu_bpts();
  314. #ifdef CONFIG_SMP
  315. cpu = smp_processor_id();
  316. if (cpu_isset(cpu, cpus_in_xmon)) {
  317. get_output_lock();
  318. excprint(regs);
  319. printf("cpu 0x%x: Exception %lx %s in xmon, "
  320. "returning to main loop\n",
  321. cpu, regs->trap, getvecname(TRAP(regs)));
  322. release_output_lock();
  323. longjmp(xmon_fault_jmp[cpu], 1);
  324. }
  325. if (setjmp(recurse_jmp) != 0) {
  326. if (!in_xmon || !xmon_gate) {
  327. get_output_lock();
  328. printf("xmon: WARNING: bad recursive fault "
  329. "on cpu 0x%x\n", cpu);
  330. release_output_lock();
  331. goto waiting;
  332. }
  333. secondary = !(xmon_taken && cpu == xmon_owner);
  334. goto cmdloop;
  335. }
  336. xmon_fault_jmp[cpu] = recurse_jmp;
  337. cpu_set(cpu, cpus_in_xmon);
  338. bp = NULL;
  339. if ((regs->msr & (MSR_IR|MSR_PR|MSR_SF)) == (MSR_IR|MSR_SF))
  340. bp = at_breakpoint(regs->nip);
  341. if (bp || (regs->msr & MSR_RI) == 0)
  342. fromipi = 0;
  343. if (!fromipi) {
  344. get_output_lock();
  345. excprint(regs);
  346. if (bp) {
  347. printf("cpu 0x%x stopped at breakpoint 0x%x (",
  348. cpu, BP_NUM(bp));
  349. xmon_print_symbol(regs->nip, " ", ")\n");
  350. }
  351. if ((regs->msr & MSR_RI) == 0)
  352. printf("WARNING: exception is not recoverable, "
  353. "can't continue\n");
  354. release_output_lock();
  355. }
  356. waiting:
  357. secondary = 1;
  358. while (secondary && !xmon_gate) {
  359. if (in_xmon == 0) {
  360. if (fromipi)
  361. goto leave;
  362. secondary = test_and_set_bit(0, &in_xmon);
  363. }
  364. barrier();
  365. }
  366. if (!secondary && !xmon_gate) {
  367. /* we are the first cpu to come in */
  368. /* interrupt other cpu(s) */
  369. int ncpus = num_online_cpus();
  370. xmon_owner = cpu;
  371. mb();
  372. if (ncpus > 1) {
  373. smp_send_debugger_break(MSG_ALL_BUT_SELF);
  374. /* wait for other cpus to come in */
  375. for (timeout = 100000000; timeout != 0; --timeout) {
  376. if (cpus_weight(cpus_in_xmon) >= ncpus)
  377. break;
  378. barrier();
  379. }
  380. }
  381. remove_bpts();
  382. disable_surveillance();
  383. /* for breakpoint or single step, print the current instr. */
  384. if (bp || TRAP(regs) == 0xd00)
  385. ppc_inst_dump(regs->nip, 1, 0);
  386. printf("enter ? for help\n");
  387. mb();
  388. xmon_gate = 1;
  389. barrier();
  390. }
  391. cmdloop:
  392. while (in_xmon) {
  393. if (secondary) {
  394. if (cpu == xmon_owner) {
  395. if (!test_and_set_bit(0, &xmon_taken)) {
  396. secondary = 0;
  397. continue;
  398. }
  399. /* missed it */
  400. while (cpu == xmon_owner)
  401. barrier();
  402. }
  403. barrier();
  404. } else {
  405. cmd = cmds(regs);
  406. if (cmd != 0) {
  407. /* exiting xmon */
  408. insert_bpts();
  409. xmon_gate = 0;
  410. wmb();
  411. in_xmon = 0;
  412. break;
  413. }
  414. /* have switched to some other cpu */
  415. secondary = 1;
  416. }
  417. }
  418. leave:
  419. cpu_clear(cpu, cpus_in_xmon);
  420. xmon_fault_jmp[cpu] = NULL;
  421. #else
  422. /* UP is simple... */
  423. if (in_xmon) {
  424. printf("Exception %lx %s in xmon, returning to main loop\n",
  425. regs->trap, getvecname(TRAP(regs)));
  426. longjmp(xmon_fault_jmp[0], 1);
  427. }
  428. if (setjmp(recurse_jmp) == 0) {
  429. xmon_fault_jmp[0] = recurse_jmp;
  430. in_xmon = 1;
  431. excprint(regs);
  432. bp = at_breakpoint(regs->nip);
  433. if (bp) {
  434. printf("Stopped at breakpoint %x (", BP_NUM(bp));
  435. xmon_print_symbol(regs->nip, " ", ")\n");
  436. }
  437. if ((regs->msr & MSR_RI) == 0)
  438. printf("WARNING: exception is not recoverable, "
  439. "can't continue\n");
  440. remove_bpts();
  441. disable_surveillance();
  442. /* for breakpoint or single step, print the current instr. */
  443. if (bp || TRAP(regs) == 0xd00)
  444. ppc_inst_dump(regs->nip, 1, 0);
  445. printf("enter ? for help\n");
  446. }
  447. cmd = cmds(regs);
  448. insert_bpts();
  449. in_xmon = 0;
  450. #endif
  451. if ((regs->msr & (MSR_IR|MSR_PR|MSR_SF)) == (MSR_IR|MSR_SF)) {
  452. bp = at_breakpoint(regs->nip);
  453. if (bp != NULL) {
  454. int stepped = emulate_step(regs, bp->instr[0]);
  455. if (stepped == 0) {
  456. regs->nip = (unsigned long) &bp->instr[0];
  457. atomic_inc(&bp->ref_count);
  458. } else if (stepped < 0) {
  459. printf("Couldn't single-step %s instruction\n",
  460. (IS_RFID(bp->instr[0])? "rfid": "mtmsrd"));
  461. }
  462. }
  463. }
  464. insert_cpu_bpts();
  465. mtmsr(msr); /* restore interrupt enable */
  466. return cmd != 'X' && cmd != EOF;
  467. }
  468. int xmon(struct pt_regs *excp)
  469. {
  470. struct pt_regs regs;
  471. if (excp == NULL) {
  472. xmon_save_regs(&regs);
  473. excp = &regs;
  474. }
  475. return xmon_core(excp, 0);
  476. }
  477. EXPORT_SYMBOL(xmon);
  478. irqreturn_t xmon_irq(int irq, void *d)
  479. {
  480. unsigned long flags;
  481. local_irq_save(flags);
  482. printf("Keyboard interrupt\n");
  483. xmon(get_irq_regs());
  484. local_irq_restore(flags);
  485. return IRQ_HANDLED;
  486. }
  487. static int xmon_bpt(struct pt_regs *regs)
  488. {
  489. struct bpt *bp;
  490. unsigned long offset;
  491. if ((regs->msr & (MSR_IR|MSR_PR|MSR_SF)) != (MSR_IR|MSR_SF))
  492. return 0;
  493. /* Are we at the trap at bp->instr[1] for some bp? */
  494. bp = in_breakpoint_table(regs->nip, &offset);
  495. if (bp != NULL && offset == 4) {
  496. regs->nip = bp->address + 4;
  497. atomic_dec(&bp->ref_count);
  498. return 1;
  499. }
  500. /* Are we at a breakpoint? */
  501. bp = at_breakpoint(regs->nip);
  502. if (!bp)
  503. return 0;
  504. xmon_core(regs, 0);
  505. return 1;
  506. }
  507. static int xmon_sstep(struct pt_regs *regs)
  508. {
  509. if (user_mode(regs))
  510. return 0;
  511. xmon_core(regs, 0);
  512. return 1;
  513. }
  514. static int xmon_dabr_match(struct pt_regs *regs)
  515. {
  516. if ((regs->msr & (MSR_IR|MSR_PR|MSR_SF)) != (MSR_IR|MSR_SF))
  517. return 0;
  518. if (dabr.enabled == 0)
  519. return 0;
  520. xmon_core(regs, 0);
  521. return 1;
  522. }
  523. static int xmon_iabr_match(struct pt_regs *regs)
  524. {
  525. if ((regs->msr & (MSR_IR|MSR_PR|MSR_SF)) != (MSR_IR|MSR_SF))
  526. return 0;
  527. if (iabr == 0)
  528. return 0;
  529. xmon_core(regs, 0);
  530. return 1;
  531. }
  532. static int xmon_ipi(struct pt_regs *regs)
  533. {
  534. #ifdef CONFIG_SMP
  535. if (in_xmon && !cpu_isset(smp_processor_id(), cpus_in_xmon))
  536. xmon_core(regs, 1);
  537. #endif
  538. return 0;
  539. }
  540. static int xmon_fault_handler(struct pt_regs *regs)
  541. {
  542. struct bpt *bp;
  543. unsigned long offset;
  544. if (in_xmon && catch_memory_errors)
  545. handle_fault(regs); /* doesn't return */
  546. if ((regs->msr & (MSR_IR|MSR_PR|MSR_SF)) == (MSR_IR|MSR_SF)) {
  547. bp = in_breakpoint_table(regs->nip, &offset);
  548. if (bp != NULL) {
  549. regs->nip = bp->address + offset;
  550. atomic_dec(&bp->ref_count);
  551. }
  552. }
  553. return 0;
  554. }
  555. static struct bpt *at_breakpoint(unsigned long pc)
  556. {
  557. int i;
  558. struct bpt *bp;
  559. bp = bpts;
  560. for (i = 0; i < NBPTS; ++i, ++bp)
  561. if (bp->enabled && pc == bp->address)
  562. return bp;
  563. return NULL;
  564. }
  565. static struct bpt *in_breakpoint_table(unsigned long nip, unsigned long *offp)
  566. {
  567. unsigned long off;
  568. off = nip - (unsigned long) bpts;
  569. if (off >= sizeof(bpts))
  570. return NULL;
  571. off %= sizeof(struct bpt);
  572. if (off != offsetof(struct bpt, instr[0])
  573. && off != offsetof(struct bpt, instr[1]))
  574. return NULL;
  575. *offp = off - offsetof(struct bpt, instr[0]);
  576. return (struct bpt *) (nip - off);
  577. }
  578. static struct bpt *new_breakpoint(unsigned long a)
  579. {
  580. struct bpt *bp;
  581. a &= ~3UL;
  582. bp = at_breakpoint(a);
  583. if (bp)
  584. return bp;
  585. for (bp = bpts; bp < &bpts[NBPTS]; ++bp) {
  586. if (!bp->enabled && atomic_read(&bp->ref_count) == 0) {
  587. bp->address = a;
  588. bp->instr[1] = bpinstr;
  589. store_inst(&bp->instr[1]);
  590. return bp;
  591. }
  592. }
  593. printf("Sorry, no free breakpoints. Please clear one first.\n");
  594. return NULL;
  595. }
  596. static void insert_bpts(void)
  597. {
  598. int i;
  599. struct bpt *bp;
  600. bp = bpts;
  601. for (i = 0; i < NBPTS; ++i, ++bp) {
  602. if ((bp->enabled & (BP_TRAP|BP_IABR)) == 0)
  603. continue;
  604. if (mread(bp->address, &bp->instr[0], 4) != 4) {
  605. printf("Couldn't read instruction at %lx, "
  606. "disabling breakpoint there\n", bp->address);
  607. bp->enabled = 0;
  608. continue;
  609. }
  610. if (IS_MTMSRD(bp->instr[0]) || IS_RFID(bp->instr[0])) {
  611. printf("Breakpoint at %lx is on an mtmsrd or rfid "
  612. "instruction, disabling it\n", bp->address);
  613. bp->enabled = 0;
  614. continue;
  615. }
  616. store_inst(&bp->instr[0]);
  617. if (bp->enabled & BP_IABR)
  618. continue;
  619. if (mwrite(bp->address, &bpinstr, 4) != 4) {
  620. printf("Couldn't write instruction at %lx, "
  621. "disabling breakpoint there\n", bp->address);
  622. bp->enabled &= ~BP_TRAP;
  623. continue;
  624. }
  625. store_inst((void *)bp->address);
  626. }
  627. }
  628. static void insert_cpu_bpts(void)
  629. {
  630. if (dabr.enabled)
  631. set_dabr(dabr.address | (dabr.enabled & 7));
  632. if (iabr && cpu_has_feature(CPU_FTR_IABR))
  633. mtspr(SPRN_IABR, iabr->address
  634. | (iabr->enabled & (BP_IABR|BP_IABR_TE)));
  635. }
  636. static void remove_bpts(void)
  637. {
  638. int i;
  639. struct bpt *bp;
  640. unsigned instr;
  641. bp = bpts;
  642. for (i = 0; i < NBPTS; ++i, ++bp) {
  643. if ((bp->enabled & (BP_TRAP|BP_IABR)) != BP_TRAP)
  644. continue;
  645. if (mread(bp->address, &instr, 4) == 4
  646. && instr == bpinstr
  647. && mwrite(bp->address, &bp->instr, 4) != 4)
  648. printf("Couldn't remove breakpoint at %lx\n",
  649. bp->address);
  650. else
  651. store_inst((void *)bp->address);
  652. }
  653. }
  654. static void remove_cpu_bpts(void)
  655. {
  656. set_dabr(0);
  657. if (cpu_has_feature(CPU_FTR_IABR))
  658. mtspr(SPRN_IABR, 0);
  659. }
  660. /* Command interpreting routine */
  661. static char *last_cmd;
  662. static int
  663. cmds(struct pt_regs *excp)
  664. {
  665. int cmd = 0;
  666. last_cmd = NULL;
  667. xmon_regs = excp;
  668. if (!xmon_no_auto_backtrace) {
  669. xmon_no_auto_backtrace = 1;
  670. xmon_show_stack(excp->gpr[1], excp->link, excp->nip);
  671. }
  672. for(;;) {
  673. #ifdef CONFIG_SMP
  674. printf("%x:", smp_processor_id());
  675. #endif /* CONFIG_SMP */
  676. printf("mon> ");
  677. flush_input();
  678. termch = 0;
  679. cmd = skipbl();
  680. if( cmd == '\n' ) {
  681. if (last_cmd == NULL)
  682. continue;
  683. take_input(last_cmd);
  684. last_cmd = NULL;
  685. cmd = inchar();
  686. }
  687. switch (cmd) {
  688. case 'm':
  689. cmd = inchar();
  690. switch (cmd) {
  691. case 'm':
  692. case 's':
  693. case 'd':
  694. memops(cmd);
  695. break;
  696. case 'l':
  697. memlocate();
  698. break;
  699. case 'z':
  700. memzcan();
  701. break;
  702. case 'i':
  703. show_mem();
  704. break;
  705. default:
  706. termch = cmd;
  707. memex();
  708. }
  709. break;
  710. case 'd':
  711. dump();
  712. break;
  713. case 'l':
  714. symbol_lookup();
  715. break;
  716. case 'r':
  717. prregs(excp); /* print regs */
  718. break;
  719. case 'e':
  720. excprint(excp);
  721. break;
  722. case 'S':
  723. super_regs();
  724. break;
  725. case 't':
  726. backtrace(excp);
  727. break;
  728. case 'f':
  729. cacheflush();
  730. break;
  731. case 's':
  732. if (do_spu_cmd() == 0)
  733. break;
  734. if (do_step(excp))
  735. return cmd;
  736. break;
  737. case 'x':
  738. case 'X':
  739. return cmd;
  740. case EOF:
  741. printf(" <no input ...>\n");
  742. mdelay(2000);
  743. return cmd;
  744. case '?':
  745. printf(help_string);
  746. break;
  747. case 'b':
  748. bpt_cmds();
  749. break;
  750. case 'C':
  751. csum();
  752. break;
  753. case 'c':
  754. if (cpu_cmd())
  755. return 0;
  756. break;
  757. case 'z':
  758. bootcmds();
  759. break;
  760. case 'p':
  761. proccall();
  762. break;
  763. #ifdef CONFIG_PPC_STD_MMU
  764. case 'u':
  765. dump_segments();
  766. break;
  767. #endif
  768. default:
  769. printf("Unrecognized command: ");
  770. do {
  771. if (' ' < cmd && cmd <= '~')
  772. putchar(cmd);
  773. else
  774. printf("\\x%x", cmd);
  775. cmd = inchar();
  776. } while (cmd != '\n');
  777. printf(" (type ? for help)\n");
  778. break;
  779. }
  780. }
  781. }
  782. /*
  783. * Step a single instruction.
  784. * Some instructions we emulate, others we execute with MSR_SE set.
  785. */
  786. static int do_step(struct pt_regs *regs)
  787. {
  788. unsigned int instr;
  789. int stepped;
  790. /* check we are in 64-bit kernel mode, translation enabled */
  791. if ((regs->msr & (MSR_SF|MSR_PR|MSR_IR)) == (MSR_SF|MSR_IR)) {
  792. if (mread(regs->nip, &instr, 4) == 4) {
  793. stepped = emulate_step(regs, instr);
  794. if (stepped < 0) {
  795. printf("Couldn't single-step %s instruction\n",
  796. (IS_RFID(instr)? "rfid": "mtmsrd"));
  797. return 0;
  798. }
  799. if (stepped > 0) {
  800. regs->trap = 0xd00 | (regs->trap & 1);
  801. printf("stepped to ");
  802. xmon_print_symbol(regs->nip, " ", "\n");
  803. ppc_inst_dump(regs->nip, 1, 0);
  804. return 0;
  805. }
  806. }
  807. }
  808. regs->msr |= MSR_SE;
  809. return 1;
  810. }
  811. static void bootcmds(void)
  812. {
  813. int cmd;
  814. cmd = inchar();
  815. if (cmd == 'r')
  816. ppc_md.restart(NULL);
  817. else if (cmd == 'h')
  818. ppc_md.halt();
  819. else if (cmd == 'p')
  820. ppc_md.power_off();
  821. }
  822. static int cpu_cmd(void)
  823. {
  824. #ifdef CONFIG_SMP
  825. unsigned long cpu;
  826. int timeout;
  827. int count;
  828. if (!scanhex(&cpu)) {
  829. /* print cpus waiting or in xmon */
  830. printf("cpus stopped:");
  831. count = 0;
  832. for (cpu = 0; cpu < NR_CPUS; ++cpu) {
  833. if (cpu_isset(cpu, cpus_in_xmon)) {
  834. if (count == 0)
  835. printf(" %x", cpu);
  836. ++count;
  837. } else {
  838. if (count > 1)
  839. printf("-%x", cpu - 1);
  840. count = 0;
  841. }
  842. }
  843. if (count > 1)
  844. printf("-%x", NR_CPUS - 1);
  845. printf("\n");
  846. return 0;
  847. }
  848. /* try to switch to cpu specified */
  849. if (!cpu_isset(cpu, cpus_in_xmon)) {
  850. printf("cpu 0x%x isn't in xmon\n", cpu);
  851. return 0;
  852. }
  853. xmon_taken = 0;
  854. mb();
  855. xmon_owner = cpu;
  856. timeout = 10000000;
  857. while (!xmon_taken) {
  858. if (--timeout == 0) {
  859. if (test_and_set_bit(0, &xmon_taken))
  860. break;
  861. /* take control back */
  862. mb();
  863. xmon_owner = smp_processor_id();
  864. printf("cpu %u didn't take control\n", cpu);
  865. return 0;
  866. }
  867. barrier();
  868. }
  869. return 1;
  870. #else
  871. return 0;
  872. #endif /* CONFIG_SMP */
  873. }
  874. static unsigned short fcstab[256] = {
  875. 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
  876. 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
  877. 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
  878. 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
  879. 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
  880. 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
  881. 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
  882. 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
  883. 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
  884. 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
  885. 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
  886. 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
  887. 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
  888. 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
  889. 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
  890. 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
  891. 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
  892. 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
  893. 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
  894. 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
  895. 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
  896. 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
  897. 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
  898. 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
  899. 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
  900. 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
  901. 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
  902. 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
  903. 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
  904. 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
  905. 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
  906. 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
  907. };
  908. #define FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
  909. static void
  910. csum(void)
  911. {
  912. unsigned int i;
  913. unsigned short fcs;
  914. unsigned char v;
  915. if (!scanhex(&adrs))
  916. return;
  917. if (!scanhex(&ncsum))
  918. return;
  919. fcs = 0xffff;
  920. for (i = 0; i < ncsum; ++i) {
  921. if (mread(adrs+i, &v, 1) == 0) {
  922. printf("csum stopped at %x\n", adrs+i);
  923. break;
  924. }
  925. fcs = FCS(fcs, v);
  926. }
  927. printf("%x\n", fcs);
  928. }
  929. /*
  930. * Check if this is a suitable place to put a breakpoint.
  931. */
  932. static long check_bp_loc(unsigned long addr)
  933. {
  934. unsigned int instr;
  935. addr &= ~3;
  936. if (!is_kernel_addr(addr)) {
  937. printf("Breakpoints may only be placed at kernel addresses\n");
  938. return 0;
  939. }
  940. if (!mread(addr, &instr, sizeof(instr))) {
  941. printf("Can't read instruction at address %lx\n", addr);
  942. return 0;
  943. }
  944. if (IS_MTMSRD(instr) || IS_RFID(instr)) {
  945. printf("Breakpoints may not be placed on mtmsrd or rfid "
  946. "instructions\n");
  947. return 0;
  948. }
  949. return 1;
  950. }
  951. static char *breakpoint_help_string =
  952. "Breakpoint command usage:\n"
  953. "b show breakpoints\n"
  954. "b <addr> [cnt] set breakpoint at given instr addr\n"
  955. "bc clear all breakpoints\n"
  956. "bc <n/addr> clear breakpoint number n or at addr\n"
  957. "bi <addr> [cnt] set hardware instr breakpoint (POWER3/RS64 only)\n"
  958. "bd <addr> [cnt] set hardware data breakpoint\n"
  959. "";
  960. static void
  961. bpt_cmds(void)
  962. {
  963. int cmd;
  964. unsigned long a;
  965. int mode, i;
  966. struct bpt *bp;
  967. const char badaddr[] = "Only kernel addresses are permitted "
  968. "for breakpoints\n";
  969. cmd = inchar();
  970. switch (cmd) {
  971. #ifndef CONFIG_8xx
  972. case 'd': /* bd - hardware data breakpoint */
  973. mode = 7;
  974. cmd = inchar();
  975. if (cmd == 'r')
  976. mode = 5;
  977. else if (cmd == 'w')
  978. mode = 6;
  979. else
  980. termch = cmd;
  981. dabr.address = 0;
  982. dabr.enabled = 0;
  983. if (scanhex(&dabr.address)) {
  984. if (!is_kernel_addr(dabr.address)) {
  985. printf(badaddr);
  986. break;
  987. }
  988. dabr.address &= ~7;
  989. dabr.enabled = mode | BP_DABR;
  990. }
  991. break;
  992. case 'i': /* bi - hardware instr breakpoint */
  993. if (!cpu_has_feature(CPU_FTR_IABR)) {
  994. printf("Hardware instruction breakpoint "
  995. "not supported on this cpu\n");
  996. break;
  997. }
  998. if (iabr) {
  999. iabr->enabled &= ~(BP_IABR | BP_IABR_TE);
  1000. iabr = NULL;
  1001. }
  1002. if (!scanhex(&a))
  1003. break;
  1004. if (!check_bp_loc(a))
  1005. break;
  1006. bp = new_breakpoint(a);
  1007. if (bp != NULL) {
  1008. bp->enabled |= BP_IABR | BP_IABR_TE;
  1009. iabr = bp;
  1010. }
  1011. break;
  1012. #endif
  1013. case 'c':
  1014. if (!scanhex(&a)) {
  1015. /* clear all breakpoints */
  1016. for (i = 0; i < NBPTS; ++i)
  1017. bpts[i].enabled = 0;
  1018. iabr = NULL;
  1019. dabr.enabled = 0;
  1020. printf("All breakpoints cleared\n");
  1021. break;
  1022. }
  1023. if (a <= NBPTS && a >= 1) {
  1024. /* assume a breakpoint number */
  1025. bp = &bpts[a-1]; /* bp nums are 1 based */
  1026. } else {
  1027. /* assume a breakpoint address */
  1028. bp = at_breakpoint(a);
  1029. if (bp == 0) {
  1030. printf("No breakpoint at %x\n", a);
  1031. break;
  1032. }
  1033. }
  1034. printf("Cleared breakpoint %x (", BP_NUM(bp));
  1035. xmon_print_symbol(bp->address, " ", ")\n");
  1036. bp->enabled = 0;
  1037. break;
  1038. default:
  1039. termch = cmd;
  1040. cmd = skipbl();
  1041. if (cmd == '?') {
  1042. printf(breakpoint_help_string);
  1043. break;
  1044. }
  1045. termch = cmd;
  1046. if (!scanhex(&a)) {
  1047. /* print all breakpoints */
  1048. printf(" type address\n");
  1049. if (dabr.enabled) {
  1050. printf(" data "REG" [", dabr.address);
  1051. if (dabr.enabled & 1)
  1052. printf("r");
  1053. if (dabr.enabled & 2)
  1054. printf("w");
  1055. printf("]\n");
  1056. }
  1057. for (bp = bpts; bp < &bpts[NBPTS]; ++bp) {
  1058. if (!bp->enabled)
  1059. continue;
  1060. printf("%2x %s ", BP_NUM(bp),
  1061. (bp->enabled & BP_IABR)? "inst": "trap");
  1062. xmon_print_symbol(bp->address, " ", "\n");
  1063. }
  1064. break;
  1065. }
  1066. if (!check_bp_loc(a))
  1067. break;
  1068. bp = new_breakpoint(a);
  1069. if (bp != NULL)
  1070. bp->enabled |= BP_TRAP;
  1071. break;
  1072. }
  1073. }
  1074. /* Very cheap human name for vector lookup. */
  1075. static
  1076. const char *getvecname(unsigned long vec)
  1077. {
  1078. char *ret;
  1079. switch (vec) {
  1080. case 0x100: ret = "(System Reset)"; break;
  1081. case 0x200: ret = "(Machine Check)"; break;
  1082. case 0x300: ret = "(Data Access)"; break;
  1083. case 0x380: ret = "(Data SLB Access)"; break;
  1084. case 0x400: ret = "(Instruction Access)"; break;
  1085. case 0x480: ret = "(Instruction SLB Access)"; break;
  1086. case 0x500: ret = "(Hardware Interrupt)"; break;
  1087. case 0x600: ret = "(Alignment)"; break;
  1088. case 0x700: ret = "(Program Check)"; break;
  1089. case 0x800: ret = "(FPU Unavailable)"; break;
  1090. case 0x900: ret = "(Decrementer)"; break;
  1091. case 0xc00: ret = "(System Call)"; break;
  1092. case 0xd00: ret = "(Single Step)"; break;
  1093. case 0xf00: ret = "(Performance Monitor)"; break;
  1094. case 0xf20: ret = "(Altivec Unavailable)"; break;
  1095. case 0x1300: ret = "(Instruction Breakpoint)"; break;
  1096. default: ret = "";
  1097. }
  1098. return ret;
  1099. }
  1100. static void get_function_bounds(unsigned long pc, unsigned long *startp,
  1101. unsigned long *endp)
  1102. {
  1103. unsigned long size, offset;
  1104. const char *name;
  1105. char *modname;
  1106. *startp = *endp = 0;
  1107. if (pc == 0)
  1108. return;
  1109. if (setjmp(bus_error_jmp) == 0) {
  1110. catch_memory_errors = 1;
  1111. sync();
  1112. name = kallsyms_lookup(pc, &size, &offset, &modname, tmpstr);
  1113. if (name != NULL) {
  1114. *startp = pc - offset;
  1115. *endp = pc - offset + size;
  1116. }
  1117. sync();
  1118. }
  1119. catch_memory_errors = 0;
  1120. }
  1121. static int xmon_depth_to_print = 64;
  1122. #ifdef CONFIG_PPC64
  1123. #define LRSAVE_OFFSET 0x10
  1124. #define REG_FRAME_MARKER 0x7265677368657265ul /* "regshere" */
  1125. #define MARKER_OFFSET 0x60
  1126. #define REGS_OFFSET 0x70
  1127. #else
  1128. #define LRSAVE_OFFSET 4
  1129. #define REG_FRAME_MARKER 0x72656773
  1130. #define MARKER_OFFSET 8
  1131. #define REGS_OFFSET 16
  1132. #endif
  1133. static void xmon_show_stack(unsigned long sp, unsigned long lr,
  1134. unsigned long pc)
  1135. {
  1136. unsigned long ip;
  1137. unsigned long newsp;
  1138. unsigned long marker;
  1139. int count = 0;
  1140. struct pt_regs regs;
  1141. do {
  1142. if (sp < PAGE_OFFSET) {
  1143. if (sp != 0)
  1144. printf("SP (%lx) is in userspace\n", sp);
  1145. break;
  1146. }
  1147. if (!mread(sp + LRSAVE_OFFSET, &ip, sizeof(unsigned long))
  1148. || !mread(sp, &newsp, sizeof(unsigned long))) {
  1149. printf("Couldn't read stack frame at %lx\n", sp);
  1150. break;
  1151. }
  1152. /*
  1153. * For the first stack frame, try to work out if
  1154. * LR and/or the saved LR value in the bottommost
  1155. * stack frame are valid.
  1156. */
  1157. if ((pc | lr) != 0) {
  1158. unsigned long fnstart, fnend;
  1159. unsigned long nextip;
  1160. int printip = 1;
  1161. get_function_bounds(pc, &fnstart, &fnend);
  1162. nextip = 0;
  1163. if (newsp > sp)
  1164. mread(newsp + LRSAVE_OFFSET, &nextip,
  1165. sizeof(unsigned long));
  1166. if (lr == ip) {
  1167. if (lr < PAGE_OFFSET
  1168. || (fnstart <= lr && lr < fnend))
  1169. printip = 0;
  1170. } else if (lr == nextip) {
  1171. printip = 0;
  1172. } else if (lr >= PAGE_OFFSET
  1173. && !(fnstart <= lr && lr < fnend)) {
  1174. printf("[link register ] ");
  1175. xmon_print_symbol(lr, " ", "\n");
  1176. }
  1177. if (printip) {
  1178. printf("["REG"] ", sp);
  1179. xmon_print_symbol(ip, " ", " (unreliable)\n");
  1180. }
  1181. pc = lr = 0;
  1182. } else {
  1183. printf("["REG"] ", sp);
  1184. xmon_print_symbol(ip, " ", "\n");
  1185. }
  1186. /* Look for "regshere" marker to see if this is
  1187. an exception frame. */
  1188. if (mread(sp + MARKER_OFFSET, &marker, sizeof(unsigned long))
  1189. && marker == REG_FRAME_MARKER) {
  1190. if (mread(sp + REGS_OFFSET, &regs, sizeof(regs))
  1191. != sizeof(regs)) {
  1192. printf("Couldn't read registers at %lx\n",
  1193. sp + REGS_OFFSET);
  1194. break;
  1195. }
  1196. printf("--- Exception: %lx %s at ", regs.trap,
  1197. getvecname(TRAP(&regs)));
  1198. pc = regs.nip;
  1199. lr = regs.link;
  1200. xmon_print_symbol(pc, " ", "\n");
  1201. }
  1202. if (newsp == 0)
  1203. break;
  1204. sp = newsp;
  1205. } while (count++ < xmon_depth_to_print);
  1206. }
  1207. static void backtrace(struct pt_regs *excp)
  1208. {
  1209. unsigned long sp;
  1210. if (scanhex(&sp))
  1211. xmon_show_stack(sp, 0, 0);
  1212. else
  1213. xmon_show_stack(excp->gpr[1], excp->link, excp->nip);
  1214. scannl();
  1215. }
  1216. static void print_bug_trap(struct pt_regs *regs)
  1217. {
  1218. struct bug_entry *bug;
  1219. unsigned long addr;
  1220. if (regs->msr & MSR_PR)
  1221. return; /* not in kernel */
  1222. addr = regs->nip; /* address of trap instruction */
  1223. if (addr < PAGE_OFFSET)
  1224. return;
  1225. bug = find_bug(regs->nip);
  1226. if (bug == NULL)
  1227. return;
  1228. if (bug->line & BUG_WARNING_TRAP)
  1229. return;
  1230. printf("kernel BUG in %s at %s:%d!\n",
  1231. bug->function, bug->file, (unsigned int)bug->line);
  1232. }
  1233. void excprint(struct pt_regs *fp)
  1234. {
  1235. unsigned long trap;
  1236. #ifdef CONFIG_SMP
  1237. printf("cpu 0x%x: ", smp_processor_id());
  1238. #endif /* CONFIG_SMP */
  1239. trap = TRAP(fp);
  1240. printf("Vector: %lx %s at [%lx]\n", fp->trap, getvecname(trap), fp);
  1241. printf(" pc: ");
  1242. xmon_print_symbol(fp->nip, ": ", "\n");
  1243. printf(" lr: ", fp->link);
  1244. xmon_print_symbol(fp->link, ": ", "\n");
  1245. printf(" sp: %lx\n", fp->gpr[1]);
  1246. printf(" msr: %lx\n", fp->msr);
  1247. if (trap == 0x300 || trap == 0x380 || trap == 0x600) {
  1248. printf(" dar: %lx\n", fp->dar);
  1249. if (trap != 0x380)
  1250. printf(" dsisr: %lx\n", fp->dsisr);
  1251. }
  1252. printf(" current = 0x%lx\n", current);
  1253. #ifdef CONFIG_PPC64
  1254. printf(" paca = 0x%lx\n", get_paca());
  1255. #endif
  1256. if (current) {
  1257. printf(" pid = %ld, comm = %s\n",
  1258. current->pid, current->comm);
  1259. }
  1260. if (trap == 0x700)
  1261. print_bug_trap(fp);
  1262. }
  1263. void prregs(struct pt_regs *fp)
  1264. {
  1265. int n, trap;
  1266. unsigned long base;
  1267. struct pt_regs regs;
  1268. if (scanhex(&base)) {
  1269. if (setjmp(bus_error_jmp) == 0) {
  1270. catch_memory_errors = 1;
  1271. sync();
  1272. regs = *(struct pt_regs *)base;
  1273. sync();
  1274. __delay(200);
  1275. } else {
  1276. catch_memory_errors = 0;
  1277. printf("*** Error reading registers from "REG"\n",
  1278. base);
  1279. return;
  1280. }
  1281. catch_memory_errors = 0;
  1282. fp = &regs;
  1283. }
  1284. #ifdef CONFIG_PPC64
  1285. if (FULL_REGS(fp)) {
  1286. for (n = 0; n < 16; ++n)
  1287. printf("R%.2ld = "REG" R%.2ld = "REG"\n",
  1288. n, fp->gpr[n], n+16, fp->gpr[n+16]);
  1289. } else {
  1290. for (n = 0; n < 7; ++n)
  1291. printf("R%.2ld = "REG" R%.2ld = "REG"\n",
  1292. n, fp->gpr[n], n+7, fp->gpr[n+7]);
  1293. }
  1294. #else
  1295. for (n = 0; n < 32; ++n) {
  1296. printf("R%.2d = %.8x%s", n, fp->gpr[n],
  1297. (n & 3) == 3? "\n": " ");
  1298. if (n == 12 && !FULL_REGS(fp)) {
  1299. printf("\n");
  1300. break;
  1301. }
  1302. }
  1303. #endif
  1304. printf("pc = ");
  1305. xmon_print_symbol(fp->nip, " ", "\n");
  1306. printf("lr = ");
  1307. xmon_print_symbol(fp->link, " ", "\n");
  1308. printf("msr = "REG" cr = %.8lx\n", fp->msr, fp->ccr);
  1309. printf("ctr = "REG" xer = "REG" trap = %4lx\n",
  1310. fp->ctr, fp->xer, fp->trap);
  1311. trap = TRAP(fp);
  1312. if (trap == 0x300 || trap == 0x380 || trap == 0x600)
  1313. printf("dar = "REG" dsisr = %.8lx\n", fp->dar, fp->dsisr);
  1314. }
  1315. void cacheflush(void)
  1316. {
  1317. int cmd;
  1318. unsigned long nflush;
  1319. cmd = inchar();
  1320. if (cmd != 'i')
  1321. termch = cmd;
  1322. scanhex((void *)&adrs);
  1323. if (termch != '\n')
  1324. termch = 0;
  1325. nflush = 1;
  1326. scanhex(&nflush);
  1327. nflush = (nflush + L1_CACHE_BYTES - 1) / L1_CACHE_BYTES;
  1328. if (setjmp(bus_error_jmp) == 0) {
  1329. catch_memory_errors = 1;
  1330. sync();
  1331. if (cmd != 'i') {
  1332. for (; nflush > 0; --nflush, adrs += L1_CACHE_BYTES)
  1333. cflush((void *) adrs);
  1334. } else {
  1335. for (; nflush > 0; --nflush, adrs += L1_CACHE_BYTES)
  1336. cinval((void *) adrs);
  1337. }
  1338. sync();
  1339. /* wait a little while to see if we get a machine check */
  1340. __delay(200);
  1341. }
  1342. catch_memory_errors = 0;
  1343. }
  1344. unsigned long
  1345. read_spr(int n)
  1346. {
  1347. unsigned int instrs[2];
  1348. unsigned long (*code)(void);
  1349. unsigned long ret = -1UL;
  1350. #ifdef CONFIG_PPC64
  1351. unsigned long opd[3];
  1352. opd[0] = (unsigned long)instrs;
  1353. opd[1] = 0;
  1354. opd[2] = 0;
  1355. code = (unsigned long (*)(void)) opd;
  1356. #else
  1357. code = (unsigned long (*)(void)) instrs;
  1358. #endif
  1359. /* mfspr r3,n; blr */
  1360. instrs[0] = 0x7c6002a6 + ((n & 0x1F) << 16) + ((n & 0x3e0) << 6);
  1361. instrs[1] = 0x4e800020;
  1362. store_inst(instrs);
  1363. store_inst(instrs+1);
  1364. if (setjmp(bus_error_jmp) == 0) {
  1365. catch_memory_errors = 1;
  1366. sync();
  1367. ret = code();
  1368. sync();
  1369. /* wait a little while to see if we get a machine check */
  1370. __delay(200);
  1371. n = size;
  1372. }
  1373. return ret;
  1374. }
  1375. void
  1376. write_spr(int n, unsigned long val)
  1377. {
  1378. unsigned int instrs[2];
  1379. unsigned long (*code)(unsigned long);
  1380. #ifdef CONFIG_PPC64
  1381. unsigned long opd[3];
  1382. opd[0] = (unsigned long)instrs;
  1383. opd[1] = 0;
  1384. opd[2] = 0;
  1385. code = (unsigned long (*)(unsigned long)) opd;
  1386. #else
  1387. code = (unsigned long (*)(unsigned long)) instrs;
  1388. #endif
  1389. instrs[0] = 0x7c6003a6 + ((n & 0x1F) << 16) + ((n & 0x3e0) << 6);
  1390. instrs[1] = 0x4e800020;
  1391. store_inst(instrs);
  1392. store_inst(instrs+1);
  1393. if (setjmp(bus_error_jmp) == 0) {
  1394. catch_memory_errors = 1;
  1395. sync();
  1396. code(val);
  1397. sync();
  1398. /* wait a little while to see if we get a machine check */
  1399. __delay(200);
  1400. n = size;
  1401. }
  1402. }
  1403. static unsigned long regno;
  1404. extern char exc_prolog;
  1405. extern char dec_exc;
  1406. void super_regs(void)
  1407. {
  1408. int cmd;
  1409. unsigned long val;
  1410. cmd = skipbl();
  1411. if (cmd == '\n') {
  1412. unsigned long sp, toc;
  1413. asm("mr %0,1" : "=r" (sp) :);
  1414. asm("mr %0,2" : "=r" (toc) :);
  1415. printf("msr = "REG" sprg0= "REG"\n",
  1416. mfmsr(), mfspr(SPRN_SPRG0));
  1417. printf("pvr = "REG" sprg1= "REG"\n",
  1418. mfspr(SPRN_PVR), mfspr(SPRN_SPRG1));
  1419. printf("dec = "REG" sprg2= "REG"\n",
  1420. mfspr(SPRN_DEC), mfspr(SPRN_SPRG2));
  1421. printf("sp = "REG" sprg3= "REG"\n", sp, mfspr(SPRN_SPRG3));
  1422. printf("toc = "REG" dar = "REG"\n", toc, mfspr(SPRN_DAR));
  1423. #ifdef CONFIG_PPC_ISERIES
  1424. if (firmware_has_feature(FW_FEATURE_ISERIES)) {
  1425. struct paca_struct *ptrPaca;
  1426. struct lppaca *ptrLpPaca;
  1427. struct ItLpRegSave *ptrLpRegSave;
  1428. /* Dump out relevant Paca data areas. */
  1429. printf("Paca: \n");
  1430. ptrPaca = get_paca();
  1431. printf(" Local Processor Control Area (LpPaca): \n");
  1432. ptrLpPaca = ptrPaca->lppaca_ptr;
  1433. printf(" Saved Srr0=%.16lx Saved Srr1=%.16lx \n",
  1434. ptrLpPaca->saved_srr0, ptrLpPaca->saved_srr1);
  1435. printf(" Saved Gpr3=%.16lx Saved Gpr4=%.16lx \n",
  1436. ptrLpPaca->saved_gpr3, ptrLpPaca->saved_gpr4);
  1437. printf(" Saved Gpr5=%.16lx \n", ptrLpPaca->saved_gpr5);
  1438. printf(" Local Processor Register Save Area (LpRegSave): \n");
  1439. ptrLpRegSave = ptrPaca->reg_save_ptr;
  1440. printf(" Saved Sprg0=%.16lx Saved Sprg1=%.16lx \n",
  1441. ptrLpRegSave->xSPRG0, ptrLpRegSave->xSPRG0);
  1442. printf(" Saved Sprg2=%.16lx Saved Sprg3=%.16lx \n",
  1443. ptrLpRegSave->xSPRG2, ptrLpRegSave->xSPRG3);
  1444. printf(" Saved Msr =%.16lx Saved Nia =%.16lx \n",
  1445. ptrLpRegSave->xMSR, ptrLpRegSave->xNIA);
  1446. }
  1447. #endif
  1448. return;
  1449. }
  1450. scanhex(&regno);
  1451. switch (cmd) {
  1452. case 'w':
  1453. val = read_spr(regno);
  1454. scanhex(&val);
  1455. write_spr(regno, val);
  1456. /* fall through */
  1457. case 'r':
  1458. printf("spr %lx = %lx\n", regno, read_spr(regno));
  1459. break;
  1460. }
  1461. scannl();
  1462. }
  1463. /*
  1464. * Stuff for reading and writing memory safely
  1465. */
  1466. int
  1467. mread(unsigned long adrs, void *buf, int size)
  1468. {
  1469. volatile int n;
  1470. char *p, *q;
  1471. n = 0;
  1472. if (setjmp(bus_error_jmp) == 0) {
  1473. catch_memory_errors = 1;
  1474. sync();
  1475. p = (char *)adrs;
  1476. q = (char *)buf;
  1477. switch (size) {
  1478. case 2:
  1479. *(u16 *)q = *(u16 *)p;
  1480. break;
  1481. case 4:
  1482. *(u32 *)q = *(u32 *)p;
  1483. break;
  1484. case 8:
  1485. *(u64 *)q = *(u64 *)p;
  1486. break;
  1487. default:
  1488. for( ; n < size; ++n) {
  1489. *q++ = *p++;
  1490. sync();
  1491. }
  1492. }
  1493. sync();
  1494. /* wait a little while to see if we get a machine check */
  1495. __delay(200);
  1496. n = size;
  1497. }
  1498. catch_memory_errors = 0;
  1499. return n;
  1500. }
  1501. int
  1502. mwrite(unsigned long adrs, void *buf, int size)
  1503. {
  1504. volatile int n;
  1505. char *p, *q;
  1506. n = 0;
  1507. if (setjmp(bus_error_jmp) == 0) {
  1508. catch_memory_errors = 1;
  1509. sync();
  1510. p = (char *) adrs;
  1511. q = (char *) buf;
  1512. switch (size) {
  1513. case 2:
  1514. *(u16 *)p = *(u16 *)q;
  1515. break;
  1516. case 4:
  1517. *(u32 *)p = *(u32 *)q;
  1518. break;
  1519. case 8:
  1520. *(u64 *)p = *(u64 *)q;
  1521. break;
  1522. default:
  1523. for ( ; n < size; ++n) {
  1524. *p++ = *q++;
  1525. sync();
  1526. }
  1527. }
  1528. sync();
  1529. /* wait a little while to see if we get a machine check */
  1530. __delay(200);
  1531. n = size;
  1532. } else {
  1533. printf("*** Error writing address %x\n", adrs + n);
  1534. }
  1535. catch_memory_errors = 0;
  1536. return n;
  1537. }
  1538. static int fault_type;
  1539. static int fault_except;
  1540. static char *fault_chars[] = { "--", "**", "##" };
  1541. static int handle_fault(struct pt_regs *regs)
  1542. {
  1543. fault_except = TRAP(regs);
  1544. switch (TRAP(regs)) {
  1545. case 0x200:
  1546. fault_type = 0;
  1547. break;
  1548. case 0x300:
  1549. case 0x380:
  1550. fault_type = 1;
  1551. break;
  1552. default:
  1553. fault_type = 2;
  1554. }
  1555. longjmp(bus_error_jmp, 1);
  1556. return 0;
  1557. }
  1558. #define SWAP(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
  1559. void
  1560. byterev(unsigned char *val, int size)
  1561. {
  1562. int t;
  1563. switch (size) {
  1564. case 2:
  1565. SWAP(val[0], val[1], t);
  1566. break;
  1567. case 4:
  1568. SWAP(val[0], val[3], t);
  1569. SWAP(val[1], val[2], t);
  1570. break;
  1571. case 8: /* is there really any use for this? */
  1572. SWAP(val[0], val[7], t);
  1573. SWAP(val[1], val[6], t);
  1574. SWAP(val[2], val[5], t);
  1575. SWAP(val[3], val[4], t);
  1576. break;
  1577. }
  1578. }
  1579. static int brev;
  1580. static int mnoread;
  1581. static char *memex_help_string =
  1582. "Memory examine command usage:\n"
  1583. "m [addr] [flags] examine/change memory\n"
  1584. " addr is optional. will start where left off.\n"
  1585. " flags may include chars from this set:\n"
  1586. " b modify by bytes (default)\n"
  1587. " w modify by words (2 byte)\n"
  1588. " l modify by longs (4 byte)\n"
  1589. " d modify by doubleword (8 byte)\n"
  1590. " r toggle reverse byte order mode\n"
  1591. " n do not read memory (for i/o spaces)\n"
  1592. " . ok to read (default)\n"
  1593. "NOTE: flags are saved as defaults\n"
  1594. "";
  1595. static char *memex_subcmd_help_string =
  1596. "Memory examine subcommands:\n"
  1597. " hexval write this val to current location\n"
  1598. " 'string' write chars from string to this location\n"
  1599. " ' increment address\n"
  1600. " ^ decrement address\n"
  1601. " / increment addr by 0x10. //=0x100, ///=0x1000, etc\n"
  1602. " \\ decrement addr by 0x10. \\\\=0x100, \\\\\\=0x1000, etc\n"
  1603. " ` clear no-read flag\n"
  1604. " ; stay at this addr\n"
  1605. " v change to byte mode\n"
  1606. " w change to word (2 byte) mode\n"
  1607. " l change to long (4 byte) mode\n"
  1608. " u change to doubleword (8 byte) mode\n"
  1609. " m addr change current addr\n"
  1610. " n toggle no-read flag\n"
  1611. " r toggle byte reverse flag\n"
  1612. " < count back up count bytes\n"
  1613. " > count skip forward count bytes\n"
  1614. " x exit this mode\n"
  1615. "";
  1616. void
  1617. memex(void)
  1618. {
  1619. int cmd, inc, i, nslash;
  1620. unsigned long n;
  1621. unsigned char val[16];
  1622. scanhex((void *)&adrs);
  1623. cmd = skipbl();
  1624. if (cmd == '?') {
  1625. printf(memex_help_string);
  1626. return;
  1627. } else {
  1628. termch = cmd;
  1629. }
  1630. last_cmd = "m\n";
  1631. while ((cmd = skipbl()) != '\n') {
  1632. switch( cmd ){
  1633. case 'b': size = 1; break;
  1634. case 'w': size = 2; break;
  1635. case 'l': size = 4; break;
  1636. case 'd': size = 8; break;
  1637. case 'r': brev = !brev; break;
  1638. case 'n': mnoread = 1; break;
  1639. case '.': mnoread = 0; break;
  1640. }
  1641. }
  1642. if( size <= 0 )
  1643. size = 1;
  1644. else if( size > 8 )
  1645. size = 8;
  1646. for(;;){
  1647. if (!mnoread)
  1648. n = mread(adrs, val, size);
  1649. printf(REG"%c", adrs, brev? 'r': ' ');
  1650. if (!mnoread) {
  1651. if (brev)
  1652. byterev(val, size);
  1653. putchar(' ');
  1654. for (i = 0; i < n; ++i)
  1655. printf("%.2x", val[i]);
  1656. for (; i < size; ++i)
  1657. printf("%s", fault_chars[fault_type]);
  1658. }
  1659. putchar(' ');
  1660. inc = size;
  1661. nslash = 0;
  1662. for(;;){
  1663. if( scanhex(&n) ){
  1664. for (i = 0; i < size; ++i)
  1665. val[i] = n >> (i * 8);
  1666. if (!brev)
  1667. byterev(val, size);
  1668. mwrite(adrs, val, size);
  1669. inc = size;
  1670. }
  1671. cmd = skipbl();
  1672. if (cmd == '\n')
  1673. break;
  1674. inc = 0;
  1675. switch (cmd) {
  1676. case '\'':
  1677. for(;;){
  1678. n = inchar();
  1679. if( n == '\\' )
  1680. n = bsesc();
  1681. else if( n == '\'' )
  1682. break;
  1683. for (i = 0; i < size; ++i)
  1684. val[i] = n >> (i * 8);
  1685. if (!brev)
  1686. byterev(val, size);
  1687. mwrite(adrs, val, size);
  1688. adrs += size;
  1689. }
  1690. adrs -= size;
  1691. inc = size;
  1692. break;
  1693. case ',':
  1694. adrs += size;
  1695. break;
  1696. case '.':
  1697. mnoread = 0;
  1698. break;
  1699. case ';':
  1700. break;
  1701. case 'x':
  1702. case EOF:
  1703. scannl();
  1704. return;
  1705. case 'b':
  1706. case 'v':
  1707. size = 1;
  1708. break;
  1709. case 'w':
  1710. size = 2;
  1711. break;
  1712. case 'l':
  1713. size = 4;
  1714. break;
  1715. case 'u':
  1716. size = 8;
  1717. break;
  1718. case '^':
  1719. adrs -= size;
  1720. break;
  1721. break;
  1722. case '/':
  1723. if (nslash > 0)
  1724. adrs -= 1 << nslash;
  1725. else
  1726. nslash = 0;
  1727. nslash += 4;
  1728. adrs += 1 << nslash;
  1729. break;
  1730. case '\\':
  1731. if (nslash < 0)
  1732. adrs += 1 << -nslash;
  1733. else
  1734. nslash = 0;
  1735. nslash -= 4;
  1736. adrs -= 1 << -nslash;
  1737. break;
  1738. case 'm':
  1739. scanhex((void *)&adrs);
  1740. break;
  1741. case 'n':
  1742. mnoread = 1;
  1743. break;
  1744. case 'r':
  1745. brev = !brev;
  1746. break;
  1747. case '<':
  1748. n = size;
  1749. scanhex(&n);
  1750. adrs -= n;
  1751. break;
  1752. case '>':
  1753. n = size;
  1754. scanhex(&n);
  1755. adrs += n;
  1756. break;
  1757. case '?':
  1758. printf(memex_subcmd_help_string);
  1759. break;
  1760. }
  1761. }
  1762. adrs += inc;
  1763. }
  1764. }
  1765. int
  1766. bsesc(void)
  1767. {
  1768. int c;
  1769. c = inchar();
  1770. switch( c ){
  1771. case 'n': c = '\n'; break;
  1772. case 'r': c = '\r'; break;
  1773. case 'b': c = '\b'; break;
  1774. case 't': c = '\t'; break;
  1775. }
  1776. return c;
  1777. }
  1778. static void xmon_rawdump (unsigned long adrs, long ndump)
  1779. {
  1780. long n, m, r, nr;
  1781. unsigned char temp[16];
  1782. for (n = ndump; n > 0;) {
  1783. r = n < 16? n: 16;
  1784. nr = mread(adrs, temp, r);
  1785. adrs += nr;
  1786. for (m = 0; m < r; ++m) {
  1787. if (m < nr)
  1788. printf("%.2x", temp[m]);
  1789. else
  1790. printf("%s", fault_chars[fault_type]);
  1791. }
  1792. n -= r;
  1793. if (nr < r)
  1794. break;
  1795. }
  1796. printf("\n");
  1797. }
  1798. #define isxdigit(c) (('0' <= (c) && (c) <= '9') \
  1799. || ('a' <= (c) && (c) <= 'f') \
  1800. || ('A' <= (c) && (c) <= 'F'))
  1801. void
  1802. dump(void)
  1803. {
  1804. int c;
  1805. c = inchar();
  1806. if ((isxdigit(c) && c != 'f' && c != 'd') || c == '\n')
  1807. termch = c;
  1808. scanhex((void *)&adrs);
  1809. if (termch != '\n')
  1810. termch = 0;
  1811. if (c == 'i') {
  1812. scanhex(&nidump);
  1813. if (nidump == 0)
  1814. nidump = 16;
  1815. else if (nidump > MAX_DUMP)
  1816. nidump = MAX_DUMP;
  1817. adrs += ppc_inst_dump(adrs, nidump, 1);
  1818. last_cmd = "di\n";
  1819. } else if (c == 'r') {
  1820. scanhex(&ndump);
  1821. if (ndump == 0)
  1822. ndump = 64;
  1823. xmon_rawdump(adrs, ndump);
  1824. adrs += ndump;
  1825. last_cmd = "dr\n";
  1826. } else {
  1827. scanhex(&ndump);
  1828. if (ndump == 0)
  1829. ndump = 64;
  1830. else if (ndump > MAX_DUMP)
  1831. ndump = MAX_DUMP;
  1832. prdump(adrs, ndump);
  1833. adrs += ndump;
  1834. last_cmd = "d\n";
  1835. }
  1836. }
  1837. void
  1838. prdump(unsigned long adrs, long ndump)
  1839. {
  1840. long n, m, c, r, nr;
  1841. unsigned char temp[16];
  1842. for (n = ndump; n > 0;) {
  1843. printf(REG, adrs);
  1844. putchar(' ');
  1845. r = n < 16? n: 16;
  1846. nr = mread(adrs, temp, r);
  1847. adrs += nr;
  1848. for (m = 0; m < r; ++m) {
  1849. if ((m & (sizeof(long) - 1)) == 0 && m > 0)
  1850. putchar(' ');
  1851. if (m < nr)
  1852. printf("%.2x", temp[m]);
  1853. else
  1854. printf("%s", fault_chars[fault_type]);
  1855. }
  1856. for (; m < 16; ++m) {
  1857. if ((m & (sizeof(long) - 1)) == 0)
  1858. putchar(' ');
  1859. printf(" ");
  1860. }
  1861. printf(" |");
  1862. for (m = 0; m < r; ++m) {
  1863. if (m < nr) {
  1864. c = temp[m];
  1865. putchar(' ' <= c && c <= '~'? c: '.');
  1866. } else
  1867. putchar(' ');
  1868. }
  1869. n -= r;
  1870. for (; m < 16; ++m)
  1871. putchar(' ');
  1872. printf("|\n");
  1873. if (nr < r)
  1874. break;
  1875. }
  1876. }
  1877. int
  1878. ppc_inst_dump(unsigned long adr, long count, int praddr)
  1879. {
  1880. int nr, dotted;
  1881. unsigned long first_adr;
  1882. unsigned long inst, last_inst = 0;
  1883. unsigned char val[4];
  1884. dotted = 0;
  1885. for (first_adr = adr; count > 0; --count, adr += 4) {
  1886. nr = mread(adr, val, 4);
  1887. if (nr == 0) {
  1888. if (praddr) {
  1889. const char *x = fault_chars[fault_type];
  1890. printf(REG" %s%s%s%s\n", adr, x, x, x, x);
  1891. }
  1892. break;
  1893. }
  1894. inst = GETWORD(val);
  1895. if (adr > first_adr && inst == last_inst) {
  1896. if (!dotted) {
  1897. printf(" ...\n");
  1898. dotted = 1;
  1899. }
  1900. continue;
  1901. }
  1902. dotted = 0;
  1903. last_inst = inst;
  1904. if (praddr)
  1905. printf(REG" %.8x", adr, inst);
  1906. printf("\t");
  1907. print_insn_powerpc(inst, adr, 0); /* always returns 4 */
  1908. printf("\n");
  1909. }
  1910. return adr - first_adr;
  1911. }
  1912. void
  1913. print_address(unsigned long addr)
  1914. {
  1915. xmon_print_symbol(addr, "\t# ", "");
  1916. }
  1917. /*
  1918. * Memory operations - move, set, print differences
  1919. */
  1920. static unsigned long mdest; /* destination address */
  1921. static unsigned long msrc; /* source address */
  1922. static unsigned long mval; /* byte value to set memory to */
  1923. static unsigned long mcount; /* # bytes to affect */
  1924. static unsigned long mdiffs; /* max # differences to print */
  1925. void
  1926. memops(int cmd)
  1927. {
  1928. scanhex((void *)&mdest);
  1929. if( termch != '\n' )
  1930. termch = 0;
  1931. scanhex((void *)(cmd == 's'? &mval: &msrc));
  1932. if( termch != '\n' )
  1933. termch = 0;
  1934. scanhex((void *)&mcount);
  1935. switch( cmd ){
  1936. case 'm':
  1937. memmove((void *)mdest, (void *)msrc, mcount);
  1938. break;
  1939. case 's':
  1940. memset((void *)mdest, mval, mcount);
  1941. break;
  1942. case 'd':
  1943. if( termch != '\n' )
  1944. termch = 0;
  1945. scanhex((void *)&mdiffs);
  1946. memdiffs((unsigned char *)mdest, (unsigned char *)msrc, mcount, mdiffs);
  1947. break;
  1948. }
  1949. }
  1950. void
  1951. memdiffs(unsigned char *p1, unsigned char *p2, unsigned nb, unsigned maxpr)
  1952. {
  1953. unsigned n, prt;
  1954. prt = 0;
  1955. for( n = nb; n > 0; --n )
  1956. if( *p1++ != *p2++ )
  1957. if( ++prt <= maxpr )
  1958. printf("%.16x %.2x # %.16x %.2x\n", p1 - 1,
  1959. p1[-1], p2 - 1, p2[-1]);
  1960. if( prt > maxpr )
  1961. printf("Total of %d differences\n", prt);
  1962. }
  1963. static unsigned mend;
  1964. static unsigned mask;
  1965. void
  1966. memlocate(void)
  1967. {
  1968. unsigned a, n;
  1969. unsigned char val[4];
  1970. last_cmd = "ml";
  1971. scanhex((void *)&mdest);
  1972. if (termch != '\n') {
  1973. termch = 0;
  1974. scanhex((void *)&mend);
  1975. if (termch != '\n') {
  1976. termch = 0;
  1977. scanhex((void *)&mval);
  1978. mask = ~0;
  1979. if (termch != '\n') termch = 0;
  1980. scanhex((void *)&mask);
  1981. }
  1982. }
  1983. n = 0;
  1984. for (a = mdest; a < mend; a += 4) {
  1985. if (mread(a, val, 4) == 4
  1986. && ((GETWORD(val) ^ mval) & mask) == 0) {
  1987. printf("%.16x: %.16x\n", a, GETWORD(val));
  1988. if (++n >= 10)
  1989. break;
  1990. }
  1991. }
  1992. }
  1993. static unsigned long mskip = 0x1000;
  1994. static unsigned long mlim = 0xffffffff;
  1995. void
  1996. memzcan(void)
  1997. {
  1998. unsigned char v;
  1999. unsigned a;
  2000. int ok, ook;
  2001. scanhex(&mdest);
  2002. if (termch != '\n') termch = 0;
  2003. scanhex(&mskip);
  2004. if (termch != '\n') termch = 0;
  2005. scanhex(&mlim);
  2006. ook = 0;
  2007. for (a = mdest; a < mlim; a += mskip) {
  2008. ok = mread(a, &v, 1);
  2009. if (ok && !ook) {
  2010. printf("%.8x .. ", a);
  2011. } else if (!ok && ook)
  2012. printf("%.8x\n", a - mskip);
  2013. ook = ok;
  2014. if (a + mskip < a)
  2015. break;
  2016. }
  2017. if (ook)
  2018. printf("%.8x\n", a - mskip);
  2019. }
  2020. void proccall(void)
  2021. {
  2022. unsigned long args[8];
  2023. unsigned long ret;
  2024. int i;
  2025. typedef unsigned long (*callfunc_t)(unsigned long, unsigned long,
  2026. unsigned long, unsigned long, unsigned long,
  2027. unsigned long, unsigned long, unsigned long);
  2028. callfunc_t func;
  2029. if (!scanhex(&adrs))
  2030. return;
  2031. if (termch != '\n')
  2032. termch = 0;
  2033. for (i = 0; i < 8; ++i)
  2034. args[i] = 0;
  2035. for (i = 0; i < 8; ++i) {
  2036. if (!scanhex(&args[i]) || termch == '\n')
  2037. break;
  2038. termch = 0;
  2039. }
  2040. func = (callfunc_t) adrs;
  2041. ret = 0;
  2042. if (setjmp(bus_error_jmp) == 0) {
  2043. catch_memory_errors = 1;
  2044. sync();
  2045. ret = func(args[0], args[1], args[2], args[3],
  2046. args[4], args[5], args[6], args[7]);
  2047. sync();
  2048. printf("return value is %x\n", ret);
  2049. } else {
  2050. printf("*** %x exception occurred\n", fault_except);
  2051. }
  2052. catch_memory_errors = 0;
  2053. }
  2054. /* Input scanning routines */
  2055. int
  2056. skipbl(void)
  2057. {
  2058. int c;
  2059. if( termch != 0 ){
  2060. c = termch;
  2061. termch = 0;
  2062. } else
  2063. c = inchar();
  2064. while( c == ' ' || c == '\t' )
  2065. c = inchar();
  2066. return c;
  2067. }
  2068. #define N_PTREGS 44
  2069. static char *regnames[N_PTREGS] = {
  2070. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  2071. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  2072. "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
  2073. "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
  2074. "pc", "msr", "or3", "ctr", "lr", "xer", "ccr",
  2075. #ifdef CONFIG_PPC64
  2076. "softe",
  2077. #else
  2078. "mq",
  2079. #endif
  2080. "trap", "dar", "dsisr", "res"
  2081. };
  2082. int
  2083. scanhex(unsigned long *vp)
  2084. {
  2085. int c, d;
  2086. unsigned long v;
  2087. c = skipbl();
  2088. if (c == '%') {
  2089. /* parse register name */
  2090. char regname[8];
  2091. int i;
  2092. for (i = 0; i < sizeof(regname) - 1; ++i) {
  2093. c = inchar();
  2094. if (!isalnum(c)) {
  2095. termch = c;
  2096. break;
  2097. }
  2098. regname[i] = c;
  2099. }
  2100. regname[i] = 0;
  2101. for (i = 0; i < N_PTREGS; ++i) {
  2102. if (strcmp(regnames[i], regname) == 0) {
  2103. if (xmon_regs == NULL) {
  2104. printf("regs not available\n");
  2105. return 0;
  2106. }
  2107. *vp = ((unsigned long *)xmon_regs)[i];
  2108. return 1;
  2109. }
  2110. }
  2111. printf("invalid register name '%%%s'\n", regname);
  2112. return 0;
  2113. }
  2114. /* skip leading "0x" if any */
  2115. if (c == '0') {
  2116. c = inchar();
  2117. if (c == 'x') {
  2118. c = inchar();
  2119. } else {
  2120. d = hexdigit(c);
  2121. if (d == EOF) {
  2122. termch = c;
  2123. *vp = 0;
  2124. return 1;
  2125. }
  2126. }
  2127. } else if (c == '$') {
  2128. int i;
  2129. for (i=0; i<63; i++) {
  2130. c = inchar();
  2131. if (isspace(c)) {
  2132. termch = c;
  2133. break;
  2134. }
  2135. tmpstr[i] = c;
  2136. }
  2137. tmpstr[i++] = 0;
  2138. *vp = 0;
  2139. if (setjmp(bus_error_jmp) == 0) {
  2140. catch_memory_errors = 1;
  2141. sync();
  2142. *vp = kallsyms_lookup_name(tmpstr);
  2143. sync();
  2144. }
  2145. catch_memory_errors = 0;
  2146. if (!(*vp)) {
  2147. printf("unknown symbol '%s'\n", tmpstr);
  2148. return 0;
  2149. }
  2150. return 1;
  2151. }
  2152. d = hexdigit(c);
  2153. if (d == EOF) {
  2154. termch = c;
  2155. return 0;
  2156. }
  2157. v = 0;
  2158. do {
  2159. v = (v << 4) + d;
  2160. c = inchar();
  2161. d = hexdigit(c);
  2162. } while (d != EOF);
  2163. termch = c;
  2164. *vp = v;
  2165. return 1;
  2166. }
  2167. void
  2168. scannl(void)
  2169. {
  2170. int c;
  2171. c = termch;
  2172. termch = 0;
  2173. while( c != '\n' )
  2174. c = inchar();
  2175. }
  2176. int hexdigit(int c)
  2177. {
  2178. if( '0' <= c && c <= '9' )
  2179. return c - '0';
  2180. if( 'A' <= c && c <= 'F' )
  2181. return c - ('A' - 10);
  2182. if( 'a' <= c && c <= 'f' )
  2183. return c - ('a' - 10);
  2184. return EOF;
  2185. }
  2186. void
  2187. getstring(char *s, int size)
  2188. {
  2189. int c;
  2190. c = skipbl();
  2191. do {
  2192. if( size > 1 ){
  2193. *s++ = c;
  2194. --size;
  2195. }
  2196. c = inchar();
  2197. } while( c != ' ' && c != '\t' && c != '\n' );
  2198. termch = c;
  2199. *s = 0;
  2200. }
  2201. static char line[256];
  2202. static char *lineptr;
  2203. void
  2204. flush_input(void)
  2205. {
  2206. lineptr = NULL;
  2207. }
  2208. int
  2209. inchar(void)
  2210. {
  2211. if (lineptr == NULL || *lineptr == 0) {
  2212. if (xmon_gets(line, sizeof(line)) == NULL) {
  2213. lineptr = NULL;
  2214. return EOF;
  2215. }
  2216. lineptr = line;
  2217. }
  2218. return *lineptr++;
  2219. }
  2220. void
  2221. take_input(char *str)
  2222. {
  2223. lineptr = str;
  2224. }
  2225. static void
  2226. symbol_lookup(void)
  2227. {
  2228. int type = inchar();
  2229. unsigned long addr;
  2230. static char tmp[64];
  2231. switch (type) {
  2232. case 'a':
  2233. if (scanhex(&addr))
  2234. xmon_print_symbol(addr, ": ", "\n");
  2235. termch = 0;
  2236. break;
  2237. case 's':
  2238. getstring(tmp, 64);
  2239. if (setjmp(bus_error_jmp) == 0) {
  2240. catch_memory_errors = 1;
  2241. sync();
  2242. addr = kallsyms_lookup_name(tmp);
  2243. if (addr)
  2244. printf("%s: %lx\n", tmp, addr);
  2245. else
  2246. printf("Symbol '%s' not found.\n", tmp);
  2247. sync();
  2248. }
  2249. catch_memory_errors = 0;
  2250. termch = 0;
  2251. break;
  2252. }
  2253. }
  2254. /* Print an address in numeric and symbolic form (if possible) */
  2255. static void xmon_print_symbol(unsigned long address, const char *mid,
  2256. const char *after)
  2257. {
  2258. char *modname;
  2259. const char *name = NULL;
  2260. unsigned long offset, size;
  2261. printf(REG, address);
  2262. if (setjmp(bus_error_jmp) == 0) {
  2263. catch_memory_errors = 1;
  2264. sync();
  2265. name = kallsyms_lookup(address, &size, &offset, &modname,
  2266. tmpstr);
  2267. sync();
  2268. /* wait a little while to see if we get a machine check */
  2269. __delay(200);
  2270. }
  2271. catch_memory_errors = 0;
  2272. if (name) {
  2273. printf("%s%s+%#lx/%#lx", mid, name, offset, size);
  2274. if (modname)
  2275. printf(" [%s]", modname);
  2276. }
  2277. printf("%s", after);
  2278. }
  2279. #ifdef CONFIG_PPC64
  2280. static void dump_slb(void)
  2281. {
  2282. int i;
  2283. unsigned long tmp;
  2284. printf("SLB contents of cpu %x\n", smp_processor_id());
  2285. for (i = 0; i < SLB_NUM_ENTRIES; i++) {
  2286. asm volatile("slbmfee %0,%1" : "=r" (tmp) : "r" (i));
  2287. printf("%02d %016lx ", i, tmp);
  2288. asm volatile("slbmfev %0,%1" : "=r" (tmp) : "r" (i));
  2289. printf("%016lx\n", tmp);
  2290. }
  2291. }
  2292. static void dump_stab(void)
  2293. {
  2294. int i;
  2295. unsigned long *tmp = (unsigned long *)get_paca()->stab_addr;
  2296. printf("Segment table contents of cpu %x\n", smp_processor_id());
  2297. for (i = 0; i < PAGE_SIZE/16; i++) {
  2298. unsigned long a, b;
  2299. a = *tmp++;
  2300. b = *tmp++;
  2301. if (a || b) {
  2302. printf("%03d %016lx ", i, a);
  2303. printf("%016lx\n", b);
  2304. }
  2305. }
  2306. }
  2307. void dump_segments(void)
  2308. {
  2309. if (cpu_has_feature(CPU_FTR_SLB))
  2310. dump_slb();
  2311. else
  2312. dump_stab();
  2313. }
  2314. #endif
  2315. #ifdef CONFIG_PPC_STD_MMU_32
  2316. void dump_segments(void)
  2317. {
  2318. int i;
  2319. printf("sr0-15 =");
  2320. for (i = 0; i < 16; ++i)
  2321. printf(" %x", mfsrin(i));
  2322. printf("\n");
  2323. }
  2324. #endif
  2325. void xmon_init(int enable)
  2326. {
  2327. if (enable) {
  2328. __debugger = xmon;
  2329. __debugger_ipi = xmon_ipi;
  2330. __debugger_bpt = xmon_bpt;
  2331. __debugger_sstep = xmon_sstep;
  2332. __debugger_iabr_match = xmon_iabr_match;
  2333. __debugger_dabr_match = xmon_dabr_match;
  2334. __debugger_fault_handler = xmon_fault_handler;
  2335. } else {
  2336. __debugger = NULL;
  2337. __debugger_ipi = NULL;
  2338. __debugger_bpt = NULL;
  2339. __debugger_sstep = NULL;
  2340. __debugger_iabr_match = NULL;
  2341. __debugger_dabr_match = NULL;
  2342. __debugger_fault_handler = NULL;
  2343. }
  2344. xmon_map_scc();
  2345. }
  2346. #ifdef CONFIG_MAGIC_SYSRQ
  2347. static void sysrq_handle_xmon(int key, struct tty_struct *tty)
  2348. {
  2349. /* ensure xmon is enabled */
  2350. xmon_init(1);
  2351. debugger(get_irq_regs());
  2352. }
  2353. static struct sysrq_key_op sysrq_xmon_op =
  2354. {
  2355. .handler = sysrq_handle_xmon,
  2356. .help_msg = "Xmon",
  2357. .action_msg = "Entering xmon",
  2358. };
  2359. static int __init setup_xmon_sysrq(void)
  2360. {
  2361. register_sysrq_key('x', &sysrq_xmon_op);
  2362. return 0;
  2363. }
  2364. __initcall(setup_xmon_sysrq);
  2365. #endif /* CONFIG_MAGIC_SYSRQ */
  2366. int __initdata xmon_early, xmon_off;
  2367. static int __init early_parse_xmon(char *p)
  2368. {
  2369. if (!p || strncmp(p, "early", 5) == 0) {
  2370. /* just "xmon" is equivalent to "xmon=early" */
  2371. xmon_init(1);
  2372. xmon_early = 1;
  2373. } else if (strncmp(p, "on", 2) == 0)
  2374. xmon_init(1);
  2375. else if (strncmp(p, "off", 3) == 0)
  2376. xmon_off = 1;
  2377. else if (strncmp(p, "nobt", 4) == 0)
  2378. xmon_no_auto_backtrace = 1;
  2379. else
  2380. return 1;
  2381. return 0;
  2382. }
  2383. early_param("xmon", early_parse_xmon);
  2384. void __init xmon_setup(void)
  2385. {
  2386. #ifdef CONFIG_XMON_DEFAULT
  2387. if (!xmon_off)
  2388. xmon_init(1);
  2389. #endif
  2390. if (xmon_early)
  2391. debugger(NULL);
  2392. }
  2393. #ifdef CONFIG_PPC_CELL
  2394. struct spu_info {
  2395. struct spu *spu;
  2396. u64 saved_mfc_sr1_RW;
  2397. u32 saved_spu_runcntl_RW;
  2398. u8 stopped_ok;
  2399. };
  2400. #define XMON_NUM_SPUS 16 /* Enough for current hardware */
  2401. static struct spu_info spu_info[XMON_NUM_SPUS];
  2402. void xmon_register_spus(struct list_head *list)
  2403. {
  2404. struct spu *spu;
  2405. list_for_each_entry(spu, list, full_list) {
  2406. if (spu->number >= XMON_NUM_SPUS) {
  2407. WARN_ON(1);
  2408. continue;
  2409. }
  2410. spu_info[spu->number].spu = spu;
  2411. spu_info[spu->number].stopped_ok = 0;
  2412. }
  2413. }
  2414. static void stop_spus(void)
  2415. {
  2416. struct spu *spu;
  2417. int i;
  2418. u64 tmp;
  2419. for (i = 0; i < XMON_NUM_SPUS; i++) {
  2420. if (!spu_info[i].spu)
  2421. continue;
  2422. if (setjmp(bus_error_jmp) == 0) {
  2423. catch_memory_errors = 1;
  2424. sync();
  2425. spu = spu_info[i].spu;
  2426. spu_info[i].saved_spu_runcntl_RW =
  2427. in_be32(&spu->problem->spu_runcntl_RW);
  2428. tmp = spu_mfc_sr1_get(spu);
  2429. spu_info[i].saved_mfc_sr1_RW = tmp;
  2430. tmp &= ~MFC_STATE1_MASTER_RUN_CONTROL_MASK;
  2431. spu_mfc_sr1_set(spu, tmp);
  2432. sync();
  2433. __delay(200);
  2434. spu_info[i].stopped_ok = 1;
  2435. printf("Stopped spu %.2d\n", i);
  2436. } else {
  2437. catch_memory_errors = 0;
  2438. printf("*** Error stopping spu %.2d\n", i);
  2439. }
  2440. catch_memory_errors = 0;
  2441. }
  2442. }
  2443. static void restart_spus(void)
  2444. {
  2445. struct spu *spu;
  2446. int i;
  2447. for (i = 0; i < XMON_NUM_SPUS; i++) {
  2448. if (!spu_info[i].spu)
  2449. continue;
  2450. if (!spu_info[i].stopped_ok) {
  2451. printf("*** Error, spu %d was not successfully stopped"
  2452. ", not restarting\n", i);
  2453. continue;
  2454. }
  2455. if (setjmp(bus_error_jmp) == 0) {
  2456. catch_memory_errors = 1;
  2457. sync();
  2458. spu = spu_info[i].spu;
  2459. spu_mfc_sr1_set(spu, spu_info[i].saved_mfc_sr1_RW);
  2460. out_be32(&spu->problem->spu_runcntl_RW,
  2461. spu_info[i].saved_spu_runcntl_RW);
  2462. sync();
  2463. __delay(200);
  2464. printf("Restarted spu %.2d\n", i);
  2465. } else {
  2466. catch_memory_errors = 0;
  2467. printf("*** Error restarting spu %.2d\n", i);
  2468. }
  2469. catch_memory_errors = 0;
  2470. }
  2471. }
  2472. #define DUMP_WIDTH 23
  2473. #define DUMP_FIELD(obj, format, field) \
  2474. do { \
  2475. if (setjmp(bus_error_jmp) == 0) { \
  2476. catch_memory_errors = 1; \
  2477. sync(); \
  2478. printf(" %-*s = "format"\n", DUMP_WIDTH, \
  2479. #field, obj->field); \
  2480. sync(); \
  2481. __delay(200); \
  2482. } else { \
  2483. catch_memory_errors = 0; \
  2484. printf(" %-*s = *** Error reading field.\n", \
  2485. DUMP_WIDTH, #field); \
  2486. } \
  2487. catch_memory_errors = 0; \
  2488. } while (0)
  2489. static void dump_spu_fields(struct spu *spu)
  2490. {
  2491. printf("Dumping spu fields at address %p:\n", spu);
  2492. DUMP_FIELD(spu, "0x%x", number);
  2493. DUMP_FIELD(spu, "%s", name);
  2494. DUMP_FIELD(spu, "%s", devnode->full_name);
  2495. DUMP_FIELD(spu, "0x%x", nid);
  2496. DUMP_FIELD(spu, "0x%lx", local_store_phys);
  2497. DUMP_FIELD(spu, "0x%p", local_store);
  2498. DUMP_FIELD(spu, "0x%lx", ls_size);
  2499. DUMP_FIELD(spu, "0x%x", node);
  2500. DUMP_FIELD(spu, "0x%lx", flags);
  2501. DUMP_FIELD(spu, "0x%lx", dar);
  2502. DUMP_FIELD(spu, "0x%lx", dsisr);
  2503. DUMP_FIELD(spu, "%d", class_0_pending);
  2504. DUMP_FIELD(spu, "0x%lx", irqs[0]);
  2505. DUMP_FIELD(spu, "0x%lx", irqs[1]);
  2506. DUMP_FIELD(spu, "0x%lx", irqs[2]);
  2507. DUMP_FIELD(spu, "0x%x", slb_replace);
  2508. DUMP_FIELD(spu, "%d", pid);
  2509. DUMP_FIELD(spu, "%d", prio);
  2510. DUMP_FIELD(spu, "0x%p", mm);
  2511. DUMP_FIELD(spu, "0x%p", ctx);
  2512. DUMP_FIELD(spu, "0x%p", rq);
  2513. DUMP_FIELD(spu, "0x%p", timestamp);
  2514. DUMP_FIELD(spu, "0x%lx", problem_phys);
  2515. DUMP_FIELD(spu, "0x%p", problem);
  2516. DUMP_FIELD(spu, "0x%x", problem->spu_runcntl_RW);
  2517. DUMP_FIELD(spu, "0x%x", problem->spu_status_R);
  2518. DUMP_FIELD(spu, "0x%x", problem->spu_npc_RW);
  2519. DUMP_FIELD(spu, "0x%p", priv1);
  2520. if (spu->priv1)
  2521. DUMP_FIELD(spu, "0x%lx", priv1->mfc_sr1_RW);
  2522. DUMP_FIELD(spu, "0x%p", priv2);
  2523. }
  2524. static int do_spu_cmd(void)
  2525. {
  2526. unsigned long num = 0;
  2527. int cmd;
  2528. cmd = inchar();
  2529. switch (cmd) {
  2530. case 's':
  2531. stop_spus();
  2532. break;
  2533. case 'r':
  2534. restart_spus();
  2535. break;
  2536. case 'f':
  2537. if (scanhex(&num) && num < XMON_NUM_SPUS && spu_info[num].spu)
  2538. dump_spu_fields(spu_info[num].spu);
  2539. else
  2540. printf("*** Error: invalid spu number\n");
  2541. break;
  2542. default:
  2543. return -1;
  2544. }
  2545. return 0;
  2546. }
  2547. #else /* ! CONFIG_PPC_CELL */
  2548. static int do_spu_cmd(void)
  2549. {
  2550. return -1;
  2551. }
  2552. #endif