xmon.c 63 KB

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