xmon.c 62 KB

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