xmon.c 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558
  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/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/sched.h>
  16. #include <linux/smp.h>
  17. #include <linux/mm.h>
  18. #include <linux/reboot.h>
  19. #include <linux/delay.h>
  20. #include <linux/kallsyms.h>
  21. #include <linux/kmsg_dump.h>
  22. #include <linux/cpumask.h>
  23. #include <linux/export.h>
  24. #include <linux/sysrq.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/irq.h>
  27. #include <linux/bug.h>
  28. #include <linux/nmi.h>
  29. #include <linux/ctype.h>
  30. #include <asm/ptrace.h>
  31. #include <asm/string.h>
  32. #include <asm/prom.h>
  33. #include <asm/machdep.h>
  34. #include <asm/xmon.h>
  35. #include <asm/processor.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/mmu.h>
  38. #include <asm/mmu_context.h>
  39. #include <asm/cputable.h>
  40. #include <asm/rtas.h>
  41. #include <asm/sstep.h>
  42. #include <asm/irq_regs.h>
  43. #include <asm/spu.h>
  44. #include <asm/spu_priv1.h>
  45. #include <asm/setjmp.h>
  46. #include <asm/reg.h>
  47. #include <asm/debug.h>
  48. #include <asm/hw_breakpoint.h>
  49. #include <asm/opal.h>
  50. #include <asm/firmware.h>
  51. #ifdef CONFIG_PPC64
  52. #include <asm/hvcall.h>
  53. #include <asm/paca.h>
  54. #endif
  55. #if defined(CONFIG_PPC_SPLPAR)
  56. #include <asm/plpar_wrappers.h>
  57. #else
  58. static inline long plapr_set_ciabr(unsigned long ciabr) {return 0; };
  59. #endif
  60. #include "nonstdio.h"
  61. #include "dis-asm.h"
  62. #ifdef CONFIG_SMP
  63. static cpumask_t cpus_in_xmon = CPU_MASK_NONE;
  64. static unsigned long xmon_taken = 1;
  65. static int xmon_owner;
  66. static int xmon_gate;
  67. #else
  68. #define xmon_owner 0
  69. #endif /* CONFIG_SMP */
  70. static unsigned long in_xmon __read_mostly = 0;
  71. static unsigned long adrs;
  72. static int size = 1;
  73. #define MAX_DUMP (128 * 1024)
  74. static unsigned long ndump = 64;
  75. static unsigned long nidump = 16;
  76. static unsigned long ncsum = 4096;
  77. static int termch;
  78. static char tmpstr[128];
  79. static long bus_error_jmp[JMP_BUF_LEN];
  80. static int catch_memory_errors;
  81. static int catch_spr_faults;
  82. static long *xmon_fault_jmp[NR_CPUS];
  83. /* Breakpoint stuff */
  84. struct bpt {
  85. unsigned long address;
  86. unsigned int instr[2];
  87. atomic_t ref_count;
  88. int enabled;
  89. unsigned long pad;
  90. };
  91. /* Bits in bpt.enabled */
  92. #define BP_CIABR 1
  93. #define BP_TRAP 2
  94. #define BP_DABR 4
  95. #define NBPTS 256
  96. static struct bpt bpts[NBPTS];
  97. static struct bpt dabr;
  98. static struct bpt *iabr;
  99. static unsigned bpinstr = 0x7fe00008; /* trap */
  100. #define BP_NUM(bp) ((bp) - bpts + 1)
  101. /* Prototypes */
  102. static int cmds(struct pt_regs *);
  103. static int mread(unsigned long, void *, int);
  104. static int mwrite(unsigned long, void *, int);
  105. static int handle_fault(struct pt_regs *);
  106. static void byterev(unsigned char *, int);
  107. static void memex(void);
  108. static int bsesc(void);
  109. static void dump(void);
  110. static void prdump(unsigned long, long);
  111. static int ppc_inst_dump(unsigned long, long, int);
  112. static void dump_log_buf(void);
  113. #ifdef CONFIG_PPC_POWERNV
  114. static void dump_opal_msglog(void);
  115. #else
  116. static inline void dump_opal_msglog(void)
  117. {
  118. printf("Machine is not running OPAL firmware.\n");
  119. }
  120. #endif
  121. static void backtrace(struct pt_regs *);
  122. static void excprint(struct pt_regs *);
  123. static void prregs(struct pt_regs *);
  124. static void memops(int);
  125. static void memlocate(void);
  126. static void memzcan(void);
  127. static void memdiffs(unsigned char *, unsigned char *, unsigned, unsigned);
  128. int skipbl(void);
  129. int scanhex(unsigned long *valp);
  130. static void scannl(void);
  131. static int hexdigit(int);
  132. void getstring(char *, int);
  133. static void flush_input(void);
  134. static int inchar(void);
  135. static void take_input(char *);
  136. static int read_spr(int, unsigned long *);
  137. static void write_spr(int, unsigned long);
  138. static void super_regs(void);
  139. static void remove_bpts(void);
  140. static void insert_bpts(void);
  141. static void remove_cpu_bpts(void);
  142. static void insert_cpu_bpts(void);
  143. static struct bpt *at_breakpoint(unsigned long pc);
  144. static struct bpt *in_breakpoint_table(unsigned long pc, unsigned long *offp);
  145. static int do_step(struct pt_regs *);
  146. static void bpt_cmds(void);
  147. static void cacheflush(void);
  148. static int cpu_cmd(void);
  149. static void csum(void);
  150. static void bootcmds(void);
  151. static void proccall(void);
  152. static void show_tasks(void);
  153. void dump_segments(void);
  154. static void symbol_lookup(void);
  155. static void xmon_show_stack(unsigned long sp, unsigned long lr,
  156. unsigned long pc);
  157. static void xmon_print_symbol(unsigned long address, const char *mid,
  158. const char *after);
  159. static const char *getvecname(unsigned long vec);
  160. static int do_spu_cmd(void);
  161. #ifdef CONFIG_44x
  162. static void dump_tlb_44x(void);
  163. #endif
  164. #ifdef CONFIG_PPC_BOOK3E
  165. static void dump_tlb_book3e(void);
  166. #endif
  167. static int xmon_no_auto_backtrace;
  168. #ifdef CONFIG_PPC64
  169. #define REG "%.16lx"
  170. #else
  171. #define REG "%.8lx"
  172. #endif
  173. #ifdef __LITTLE_ENDIAN__
  174. #define GETWORD(v) (((v)[3] << 24) + ((v)[2] << 16) + ((v)[1] << 8) + (v)[0])
  175. #else
  176. #define GETWORD(v) (((v)[0] << 24) + ((v)[1] << 16) + ((v)[2] << 8) + (v)[3])
  177. #endif
  178. static char *help_string = "\
  179. Commands:\n\
  180. b show breakpoints\n\
  181. bd set data breakpoint\n\
  182. bi set instruction breakpoint\n\
  183. bc clear breakpoint\n"
  184. #ifdef CONFIG_SMP
  185. "\
  186. c print cpus stopped in xmon\n\
  187. c# try to switch to cpu number h (in hex)\n"
  188. #endif
  189. "\
  190. C checksum\n\
  191. d dump bytes\n\
  192. di dump instructions\n\
  193. df dump float values\n\
  194. dd dump double values\n\
  195. dl dump the kernel log buffer\n"
  196. #ifdef CONFIG_PPC_POWERNV
  197. "\
  198. do dump the OPAL message log\n"
  199. #endif
  200. #ifdef CONFIG_PPC64
  201. "\
  202. dp[#] dump paca for current cpu, or cpu #\n\
  203. dpa dump paca for all possible cpus\n"
  204. #endif
  205. "\
  206. dr dump stream of raw bytes\n\
  207. dt dump the tracing buffers (uses printk)\n\
  208. e print exception information\n\
  209. f flush cache\n\
  210. la lookup symbol+offset of specified address\n\
  211. ls lookup address of specified symbol\n\
  212. m examine/change memory\n\
  213. mm move a block of memory\n\
  214. ms set a block of memory\n\
  215. md compare two blocks of memory\n\
  216. ml locate a block of memory\n\
  217. mz zero a block of memory\n\
  218. mi show information about memory allocation\n\
  219. p call a procedure\n\
  220. P list processes/tasks\n\
  221. r print registers\n\
  222. s single step\n"
  223. #ifdef CONFIG_SPU_BASE
  224. " ss stop execution on all spus\n\
  225. sr restore execution on stopped spus\n\
  226. sf # dump spu fields for spu # (in hex)\n\
  227. sd # dump spu local store for spu # (in hex)\n\
  228. sdi # disassemble spu local store for spu # (in hex)\n"
  229. #endif
  230. " S print special registers\n\
  231. Sa print all SPRs\n\
  232. Sr # read SPR #\n\
  233. Sw #v write v to SPR #\n\
  234. t print backtrace\n\
  235. x exit monitor and recover\n\
  236. X exit monitor and don't recover\n"
  237. #if defined(CONFIG_PPC64) && !defined(CONFIG_PPC_BOOK3E)
  238. " u dump segment table or SLB\n"
  239. #elif defined(CONFIG_PPC_STD_MMU_32)
  240. " u dump segment registers\n"
  241. #elif defined(CONFIG_44x) || defined(CONFIG_PPC_BOOK3E)
  242. " u dump TLB\n"
  243. #endif
  244. " ? help\n"
  245. " # n limit output to n lines per page (for dp, dpa, dl)\n"
  246. " zr reboot\n\
  247. zh halt\n"
  248. ;
  249. static struct pt_regs *xmon_regs;
  250. static inline void sync(void)
  251. {
  252. asm volatile("sync; isync");
  253. }
  254. static inline void store_inst(void *p)
  255. {
  256. asm volatile ("dcbst 0,%0; sync; icbi 0,%0; isync" : : "r" (p));
  257. }
  258. static inline void cflush(void *p)
  259. {
  260. asm volatile ("dcbf 0,%0; icbi 0,%0" : : "r" (p));
  261. }
  262. static inline void cinval(void *p)
  263. {
  264. asm volatile ("dcbi 0,%0; icbi 0,%0" : : "r" (p));
  265. }
  266. /**
  267. * write_ciabr() - write the CIABR SPR
  268. * @ciabr: The value to write.
  269. *
  270. * This function writes a value to the CIARB register either directly
  271. * through mtspr instruction if the kernel is in HV privilege mode or
  272. * call a hypervisor function to achieve the same in case the kernel
  273. * is in supervisor privilege mode.
  274. */
  275. static void write_ciabr(unsigned long ciabr)
  276. {
  277. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  278. return;
  279. if (cpu_has_feature(CPU_FTR_HVMODE)) {
  280. mtspr(SPRN_CIABR, ciabr);
  281. return;
  282. }
  283. plapr_set_ciabr(ciabr);
  284. }
  285. /**
  286. * set_ciabr() - set the CIABR
  287. * @addr: The value to set.
  288. *
  289. * This function sets the correct privilege value into the the HW
  290. * breakpoint address before writing it up in the CIABR register.
  291. */
  292. static void set_ciabr(unsigned long addr)
  293. {
  294. addr &= ~CIABR_PRIV;
  295. if (cpu_has_feature(CPU_FTR_HVMODE))
  296. addr |= CIABR_PRIV_HYPER;
  297. else
  298. addr |= CIABR_PRIV_SUPER;
  299. write_ciabr(addr);
  300. }
  301. /*
  302. * Disable surveillance (the service processor watchdog function)
  303. * while we are in xmon.
  304. * XXX we should re-enable it when we leave. :)
  305. */
  306. #define SURVEILLANCE_TOKEN 9000
  307. static inline void disable_surveillance(void)
  308. {
  309. #ifdef CONFIG_PPC_PSERIES
  310. /* Since this can't be a module, args should end up below 4GB. */
  311. static struct rtas_args args;
  312. int token;
  313. /*
  314. * At this point we have got all the cpus we can into
  315. * xmon, so there is hopefully no other cpu calling RTAS
  316. * at the moment, even though we don't take rtas.lock.
  317. * If we did try to take rtas.lock there would be a
  318. * real possibility of deadlock.
  319. */
  320. token = rtas_token("set-indicator");
  321. if (token == RTAS_UNKNOWN_SERVICE)
  322. return;
  323. rtas_call_unlocked(&args, token, 3, 1, NULL, SURVEILLANCE_TOKEN, 0, 0);
  324. #endif /* CONFIG_PPC_PSERIES */
  325. }
  326. #ifdef CONFIG_SMP
  327. static int xmon_speaker;
  328. static void get_output_lock(void)
  329. {
  330. int me = smp_processor_id() + 0x100;
  331. int last_speaker = 0, prev;
  332. long timeout;
  333. if (xmon_speaker == me)
  334. return;
  335. for (;;) {
  336. last_speaker = cmpxchg(&xmon_speaker, 0, me);
  337. if (last_speaker == 0)
  338. return;
  339. /*
  340. * Wait a full second for the lock, we might be on a slow
  341. * console, but check every 100us.
  342. */
  343. timeout = 10000;
  344. while (xmon_speaker == last_speaker) {
  345. if (--timeout > 0) {
  346. udelay(100);
  347. continue;
  348. }
  349. /* hostile takeover */
  350. prev = cmpxchg(&xmon_speaker, last_speaker, me);
  351. if (prev == last_speaker)
  352. return;
  353. break;
  354. }
  355. }
  356. }
  357. static void release_output_lock(void)
  358. {
  359. xmon_speaker = 0;
  360. }
  361. int cpus_are_in_xmon(void)
  362. {
  363. return !cpumask_empty(&cpus_in_xmon);
  364. }
  365. #endif
  366. static inline int unrecoverable_excp(struct pt_regs *regs)
  367. {
  368. #if defined(CONFIG_4xx) || defined(CONFIG_PPC_BOOK3E)
  369. /* We have no MSR_RI bit on 4xx or Book3e, so we simply return false */
  370. return 0;
  371. #else
  372. return ((regs->msr & MSR_RI) == 0);
  373. #endif
  374. }
  375. static int xmon_core(struct pt_regs *regs, int fromipi)
  376. {
  377. int cmd = 0;
  378. struct bpt *bp;
  379. long recurse_jmp[JMP_BUF_LEN];
  380. unsigned long offset;
  381. unsigned long flags;
  382. #ifdef CONFIG_SMP
  383. int cpu;
  384. int secondary;
  385. unsigned long timeout;
  386. #endif
  387. local_irq_save(flags);
  388. hard_irq_disable();
  389. bp = in_breakpoint_table(regs->nip, &offset);
  390. if (bp != NULL) {
  391. regs->nip = bp->address + offset;
  392. atomic_dec(&bp->ref_count);
  393. }
  394. remove_cpu_bpts();
  395. #ifdef CONFIG_SMP
  396. cpu = smp_processor_id();
  397. if (cpumask_test_cpu(cpu, &cpus_in_xmon)) {
  398. /*
  399. * We catch SPR read/write faults here because the 0x700, 0xf60
  400. * etc. handlers don't call debugger_fault_handler().
  401. */
  402. if (catch_spr_faults)
  403. longjmp(bus_error_jmp, 1);
  404. get_output_lock();
  405. excprint(regs);
  406. printf("cpu 0x%x: Exception %lx %s in xmon, "
  407. "returning to main loop\n",
  408. cpu, regs->trap, getvecname(TRAP(regs)));
  409. release_output_lock();
  410. longjmp(xmon_fault_jmp[cpu], 1);
  411. }
  412. if (setjmp(recurse_jmp) != 0) {
  413. if (!in_xmon || !xmon_gate) {
  414. get_output_lock();
  415. printf("xmon: WARNING: bad recursive fault "
  416. "on cpu 0x%x\n", cpu);
  417. release_output_lock();
  418. goto waiting;
  419. }
  420. secondary = !(xmon_taken && cpu == xmon_owner);
  421. goto cmdloop;
  422. }
  423. xmon_fault_jmp[cpu] = recurse_jmp;
  424. bp = NULL;
  425. if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) == (MSR_IR|MSR_64BIT))
  426. bp = at_breakpoint(regs->nip);
  427. if (bp || unrecoverable_excp(regs))
  428. fromipi = 0;
  429. if (!fromipi) {
  430. get_output_lock();
  431. excprint(regs);
  432. if (bp) {
  433. printf("cpu 0x%x stopped at breakpoint 0x%lx (",
  434. cpu, BP_NUM(bp));
  435. xmon_print_symbol(regs->nip, " ", ")\n");
  436. }
  437. if (unrecoverable_excp(regs))
  438. printf("WARNING: exception is not recoverable, "
  439. "can't continue\n");
  440. release_output_lock();
  441. }
  442. cpumask_set_cpu(cpu, &cpus_in_xmon);
  443. waiting:
  444. secondary = 1;
  445. while (secondary && !xmon_gate) {
  446. if (in_xmon == 0) {
  447. if (fromipi)
  448. goto leave;
  449. secondary = test_and_set_bit(0, &in_xmon);
  450. }
  451. barrier();
  452. }
  453. if (!secondary && !xmon_gate) {
  454. /* we are the first cpu to come in */
  455. /* interrupt other cpu(s) */
  456. int ncpus = num_online_cpus();
  457. xmon_owner = cpu;
  458. mb();
  459. if (ncpus > 1) {
  460. smp_send_debugger_break();
  461. /* wait for other cpus to come in */
  462. for (timeout = 100000000; timeout != 0; --timeout) {
  463. if (cpumask_weight(&cpus_in_xmon) >= ncpus)
  464. break;
  465. barrier();
  466. }
  467. }
  468. remove_bpts();
  469. disable_surveillance();
  470. /* for breakpoint or single step, print the current instr. */
  471. if (bp || TRAP(regs) == 0xd00)
  472. ppc_inst_dump(regs->nip, 1, 0);
  473. printf("enter ? for help\n");
  474. mb();
  475. xmon_gate = 1;
  476. barrier();
  477. }
  478. cmdloop:
  479. while (in_xmon) {
  480. if (secondary) {
  481. if (cpu == xmon_owner) {
  482. if (!test_and_set_bit(0, &xmon_taken)) {
  483. secondary = 0;
  484. continue;
  485. }
  486. /* missed it */
  487. while (cpu == xmon_owner)
  488. barrier();
  489. }
  490. barrier();
  491. } else {
  492. cmd = cmds(regs);
  493. if (cmd != 0) {
  494. /* exiting xmon */
  495. insert_bpts();
  496. xmon_gate = 0;
  497. wmb();
  498. in_xmon = 0;
  499. break;
  500. }
  501. /* have switched to some other cpu */
  502. secondary = 1;
  503. }
  504. }
  505. leave:
  506. cpumask_clear_cpu(cpu, &cpus_in_xmon);
  507. xmon_fault_jmp[cpu] = NULL;
  508. #else
  509. /* UP is simple... */
  510. if (in_xmon) {
  511. printf("Exception %lx %s in xmon, returning to main loop\n",
  512. regs->trap, getvecname(TRAP(regs)));
  513. longjmp(xmon_fault_jmp[0], 1);
  514. }
  515. if (setjmp(recurse_jmp) == 0) {
  516. xmon_fault_jmp[0] = recurse_jmp;
  517. in_xmon = 1;
  518. excprint(regs);
  519. bp = at_breakpoint(regs->nip);
  520. if (bp) {
  521. printf("Stopped at breakpoint %lx (", BP_NUM(bp));
  522. xmon_print_symbol(regs->nip, " ", ")\n");
  523. }
  524. if (unrecoverable_excp(regs))
  525. printf("WARNING: exception is not recoverable, "
  526. "can't continue\n");
  527. remove_bpts();
  528. disable_surveillance();
  529. /* for breakpoint or single step, print the current instr. */
  530. if (bp || TRAP(regs) == 0xd00)
  531. ppc_inst_dump(regs->nip, 1, 0);
  532. printf("enter ? for help\n");
  533. }
  534. cmd = cmds(regs);
  535. insert_bpts();
  536. in_xmon = 0;
  537. #endif
  538. #ifdef CONFIG_BOOKE
  539. if (regs->msr & MSR_DE) {
  540. bp = at_breakpoint(regs->nip);
  541. if (bp != NULL) {
  542. regs->nip = (unsigned long) &bp->instr[0];
  543. atomic_inc(&bp->ref_count);
  544. }
  545. }
  546. #else
  547. if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) == (MSR_IR|MSR_64BIT)) {
  548. bp = at_breakpoint(regs->nip);
  549. if (bp != NULL) {
  550. int stepped = emulate_step(regs, bp->instr[0]);
  551. if (stepped == 0) {
  552. regs->nip = (unsigned long) &bp->instr[0];
  553. atomic_inc(&bp->ref_count);
  554. } else if (stepped < 0) {
  555. printf("Couldn't single-step %s instruction\n",
  556. (IS_RFID(bp->instr[0])? "rfid": "mtmsrd"));
  557. }
  558. }
  559. }
  560. #endif
  561. insert_cpu_bpts();
  562. touch_nmi_watchdog();
  563. local_irq_restore(flags);
  564. return cmd != 'X' && cmd != EOF;
  565. }
  566. int xmon(struct pt_regs *excp)
  567. {
  568. struct pt_regs regs;
  569. if (excp == NULL) {
  570. ppc_save_regs(&regs);
  571. excp = &regs;
  572. }
  573. return xmon_core(excp, 0);
  574. }
  575. EXPORT_SYMBOL(xmon);
  576. irqreturn_t xmon_irq(int irq, void *d)
  577. {
  578. unsigned long flags;
  579. local_irq_save(flags);
  580. printf("Keyboard interrupt\n");
  581. xmon(get_irq_regs());
  582. local_irq_restore(flags);
  583. return IRQ_HANDLED;
  584. }
  585. static int xmon_bpt(struct pt_regs *regs)
  586. {
  587. struct bpt *bp;
  588. unsigned long offset;
  589. if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) != (MSR_IR|MSR_64BIT))
  590. return 0;
  591. /* Are we at the trap at bp->instr[1] for some bp? */
  592. bp = in_breakpoint_table(regs->nip, &offset);
  593. if (bp != NULL && offset == 4) {
  594. regs->nip = bp->address + 4;
  595. atomic_dec(&bp->ref_count);
  596. return 1;
  597. }
  598. /* Are we at a breakpoint? */
  599. bp = at_breakpoint(regs->nip);
  600. if (!bp)
  601. return 0;
  602. xmon_core(regs, 0);
  603. return 1;
  604. }
  605. static int xmon_sstep(struct pt_regs *regs)
  606. {
  607. if (user_mode(regs))
  608. return 0;
  609. xmon_core(regs, 0);
  610. return 1;
  611. }
  612. static int xmon_break_match(struct pt_regs *regs)
  613. {
  614. if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) != (MSR_IR|MSR_64BIT))
  615. return 0;
  616. if (dabr.enabled == 0)
  617. return 0;
  618. xmon_core(regs, 0);
  619. return 1;
  620. }
  621. static int xmon_iabr_match(struct pt_regs *regs)
  622. {
  623. if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) != (MSR_IR|MSR_64BIT))
  624. return 0;
  625. if (iabr == NULL)
  626. return 0;
  627. xmon_core(regs, 0);
  628. return 1;
  629. }
  630. static int xmon_ipi(struct pt_regs *regs)
  631. {
  632. #ifdef CONFIG_SMP
  633. if (in_xmon && !cpumask_test_cpu(smp_processor_id(), &cpus_in_xmon))
  634. xmon_core(regs, 1);
  635. #endif
  636. return 0;
  637. }
  638. static int xmon_fault_handler(struct pt_regs *regs)
  639. {
  640. struct bpt *bp;
  641. unsigned long offset;
  642. if (in_xmon && catch_memory_errors)
  643. handle_fault(regs); /* doesn't return */
  644. if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) == (MSR_IR|MSR_64BIT)) {
  645. bp = in_breakpoint_table(regs->nip, &offset);
  646. if (bp != NULL) {
  647. regs->nip = bp->address + offset;
  648. atomic_dec(&bp->ref_count);
  649. }
  650. }
  651. return 0;
  652. }
  653. static struct bpt *at_breakpoint(unsigned long pc)
  654. {
  655. int i;
  656. struct bpt *bp;
  657. bp = bpts;
  658. for (i = 0; i < NBPTS; ++i, ++bp)
  659. if (bp->enabled && pc == bp->address)
  660. return bp;
  661. return NULL;
  662. }
  663. static struct bpt *in_breakpoint_table(unsigned long nip, unsigned long *offp)
  664. {
  665. unsigned long off;
  666. off = nip - (unsigned long) bpts;
  667. if (off >= sizeof(bpts))
  668. return NULL;
  669. off %= sizeof(struct bpt);
  670. if (off != offsetof(struct bpt, instr[0])
  671. && off != offsetof(struct bpt, instr[1]))
  672. return NULL;
  673. *offp = off - offsetof(struct bpt, instr[0]);
  674. return (struct bpt *) (nip - off);
  675. }
  676. static struct bpt *new_breakpoint(unsigned long a)
  677. {
  678. struct bpt *bp;
  679. a &= ~3UL;
  680. bp = at_breakpoint(a);
  681. if (bp)
  682. return bp;
  683. for (bp = bpts; bp < &bpts[NBPTS]; ++bp) {
  684. if (!bp->enabled && atomic_read(&bp->ref_count) == 0) {
  685. bp->address = a;
  686. bp->instr[1] = bpinstr;
  687. store_inst(&bp->instr[1]);
  688. return bp;
  689. }
  690. }
  691. printf("Sorry, no free breakpoints. Please clear one first.\n");
  692. return NULL;
  693. }
  694. static void insert_bpts(void)
  695. {
  696. int i;
  697. struct bpt *bp;
  698. bp = bpts;
  699. for (i = 0; i < NBPTS; ++i, ++bp) {
  700. if ((bp->enabled & (BP_TRAP|BP_CIABR)) == 0)
  701. continue;
  702. if (mread(bp->address, &bp->instr[0], 4) != 4) {
  703. printf("Couldn't read instruction at %lx, "
  704. "disabling breakpoint there\n", bp->address);
  705. bp->enabled = 0;
  706. continue;
  707. }
  708. if (IS_MTMSRD(bp->instr[0]) || IS_RFID(bp->instr[0])) {
  709. printf("Breakpoint at %lx is on an mtmsrd or rfid "
  710. "instruction, disabling it\n", bp->address);
  711. bp->enabled = 0;
  712. continue;
  713. }
  714. store_inst(&bp->instr[0]);
  715. if (bp->enabled & BP_CIABR)
  716. continue;
  717. if (mwrite(bp->address, &bpinstr, 4) != 4) {
  718. printf("Couldn't write instruction at %lx, "
  719. "disabling breakpoint there\n", bp->address);
  720. bp->enabled &= ~BP_TRAP;
  721. continue;
  722. }
  723. store_inst((void *)bp->address);
  724. }
  725. }
  726. static void insert_cpu_bpts(void)
  727. {
  728. struct arch_hw_breakpoint brk;
  729. if (dabr.enabled) {
  730. brk.address = dabr.address;
  731. brk.type = (dabr.enabled & HW_BRK_TYPE_DABR) | HW_BRK_TYPE_PRIV_ALL;
  732. brk.len = 8;
  733. __set_breakpoint(&brk);
  734. }
  735. if (iabr)
  736. set_ciabr(iabr->address);
  737. }
  738. static void remove_bpts(void)
  739. {
  740. int i;
  741. struct bpt *bp;
  742. unsigned instr;
  743. bp = bpts;
  744. for (i = 0; i < NBPTS; ++i, ++bp) {
  745. if ((bp->enabled & (BP_TRAP|BP_CIABR)) != BP_TRAP)
  746. continue;
  747. if (mread(bp->address, &instr, 4) == 4
  748. && instr == bpinstr
  749. && mwrite(bp->address, &bp->instr, 4) != 4)
  750. printf("Couldn't remove breakpoint at %lx\n",
  751. bp->address);
  752. else
  753. store_inst((void *)bp->address);
  754. }
  755. }
  756. static void remove_cpu_bpts(void)
  757. {
  758. hw_breakpoint_disable();
  759. write_ciabr(0);
  760. }
  761. static void set_lpp_cmd(void)
  762. {
  763. unsigned long lpp;
  764. if (!scanhex(&lpp)) {
  765. printf("Invalid number.\n");
  766. lpp = 0;
  767. }
  768. xmon_set_pagination_lpp(lpp);
  769. }
  770. /* Command interpreting routine */
  771. static char *last_cmd;
  772. static int
  773. cmds(struct pt_regs *excp)
  774. {
  775. int cmd = 0;
  776. last_cmd = NULL;
  777. xmon_regs = excp;
  778. if (!xmon_no_auto_backtrace) {
  779. xmon_no_auto_backtrace = 1;
  780. xmon_show_stack(excp->gpr[1], excp->link, excp->nip);
  781. }
  782. for(;;) {
  783. #ifdef CONFIG_SMP
  784. printf("%x:", smp_processor_id());
  785. #endif /* CONFIG_SMP */
  786. printf("mon> ");
  787. flush_input();
  788. termch = 0;
  789. cmd = skipbl();
  790. if( cmd == '\n' ) {
  791. if (last_cmd == NULL)
  792. continue;
  793. take_input(last_cmd);
  794. last_cmd = NULL;
  795. cmd = inchar();
  796. }
  797. switch (cmd) {
  798. case 'm':
  799. cmd = inchar();
  800. switch (cmd) {
  801. case 'm':
  802. case 's':
  803. case 'd':
  804. memops(cmd);
  805. break;
  806. case 'l':
  807. memlocate();
  808. break;
  809. case 'z':
  810. memzcan();
  811. break;
  812. case 'i':
  813. show_mem(0);
  814. break;
  815. default:
  816. termch = cmd;
  817. memex();
  818. }
  819. break;
  820. case 'd':
  821. dump();
  822. break;
  823. case 'l':
  824. symbol_lookup();
  825. break;
  826. case 'r':
  827. prregs(excp); /* print regs */
  828. break;
  829. case 'e':
  830. excprint(excp);
  831. break;
  832. case 'S':
  833. super_regs();
  834. break;
  835. case 't':
  836. backtrace(excp);
  837. break;
  838. case 'f':
  839. cacheflush();
  840. break;
  841. case 's':
  842. if (do_spu_cmd() == 0)
  843. break;
  844. if (do_step(excp))
  845. return cmd;
  846. break;
  847. case 'x':
  848. case 'X':
  849. return cmd;
  850. case EOF:
  851. printf(" <no input ...>\n");
  852. mdelay(2000);
  853. return cmd;
  854. case '?':
  855. xmon_puts(help_string);
  856. break;
  857. case '#':
  858. set_lpp_cmd();
  859. break;
  860. case 'b':
  861. bpt_cmds();
  862. break;
  863. case 'C':
  864. csum();
  865. break;
  866. case 'c':
  867. if (cpu_cmd())
  868. return 0;
  869. break;
  870. case 'z':
  871. bootcmds();
  872. break;
  873. case 'p':
  874. proccall();
  875. break;
  876. case 'P':
  877. show_tasks();
  878. break;
  879. #ifdef CONFIG_PPC_STD_MMU
  880. case 'u':
  881. dump_segments();
  882. break;
  883. #elif defined(CONFIG_44x)
  884. case 'u':
  885. dump_tlb_44x();
  886. break;
  887. #elif defined(CONFIG_PPC_BOOK3E)
  888. case 'u':
  889. dump_tlb_book3e();
  890. break;
  891. #endif
  892. default:
  893. printf("Unrecognized command: ");
  894. do {
  895. if (' ' < cmd && cmd <= '~')
  896. putchar(cmd);
  897. else
  898. printf("\\x%x", cmd);
  899. cmd = inchar();
  900. } while (cmd != '\n');
  901. printf(" (type ? for help)\n");
  902. break;
  903. }
  904. }
  905. }
  906. #ifdef CONFIG_BOOKE
  907. static int do_step(struct pt_regs *regs)
  908. {
  909. regs->msr |= MSR_DE;
  910. mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) | DBCR0_IC | DBCR0_IDM);
  911. return 1;
  912. }
  913. #else
  914. /*
  915. * Step a single instruction.
  916. * Some instructions we emulate, others we execute with MSR_SE set.
  917. */
  918. static int do_step(struct pt_regs *regs)
  919. {
  920. unsigned int instr;
  921. int stepped;
  922. /* check we are in 64-bit kernel mode, translation enabled */
  923. if ((regs->msr & (MSR_64BIT|MSR_PR|MSR_IR)) == (MSR_64BIT|MSR_IR)) {
  924. if (mread(regs->nip, &instr, 4) == 4) {
  925. stepped = emulate_step(regs, instr);
  926. if (stepped < 0) {
  927. printf("Couldn't single-step %s instruction\n",
  928. (IS_RFID(instr)? "rfid": "mtmsrd"));
  929. return 0;
  930. }
  931. if (stepped > 0) {
  932. regs->trap = 0xd00 | (regs->trap & 1);
  933. printf("stepped to ");
  934. xmon_print_symbol(regs->nip, " ", "\n");
  935. ppc_inst_dump(regs->nip, 1, 0);
  936. return 0;
  937. }
  938. }
  939. }
  940. regs->msr |= MSR_SE;
  941. return 1;
  942. }
  943. #endif
  944. static void bootcmds(void)
  945. {
  946. int cmd;
  947. cmd = inchar();
  948. if (cmd == 'r')
  949. ppc_md.restart(NULL);
  950. else if (cmd == 'h')
  951. ppc_md.halt();
  952. else if (cmd == 'p')
  953. if (pm_power_off)
  954. pm_power_off();
  955. }
  956. static int cpu_cmd(void)
  957. {
  958. #ifdef CONFIG_SMP
  959. unsigned long cpu, first_cpu, last_cpu;
  960. int timeout;
  961. if (!scanhex(&cpu)) {
  962. /* print cpus waiting or in xmon */
  963. printf("cpus stopped:");
  964. last_cpu = first_cpu = NR_CPUS;
  965. for_each_possible_cpu(cpu) {
  966. if (cpumask_test_cpu(cpu, &cpus_in_xmon)) {
  967. if (cpu == last_cpu + 1) {
  968. last_cpu = cpu;
  969. } else {
  970. if (last_cpu != first_cpu)
  971. printf("-0x%lx", last_cpu);
  972. last_cpu = first_cpu = cpu;
  973. printf(" 0x%lx", cpu);
  974. }
  975. }
  976. }
  977. if (last_cpu != first_cpu)
  978. printf("-0x%lx", last_cpu);
  979. printf("\n");
  980. return 0;
  981. }
  982. /* try to switch to cpu specified */
  983. if (!cpumask_test_cpu(cpu, &cpus_in_xmon)) {
  984. printf("cpu 0x%x isn't in xmon\n", cpu);
  985. return 0;
  986. }
  987. xmon_taken = 0;
  988. mb();
  989. xmon_owner = cpu;
  990. timeout = 10000000;
  991. while (!xmon_taken) {
  992. if (--timeout == 0) {
  993. if (test_and_set_bit(0, &xmon_taken))
  994. break;
  995. /* take control back */
  996. mb();
  997. xmon_owner = smp_processor_id();
  998. printf("cpu 0x%x didn't take control\n", cpu);
  999. return 0;
  1000. }
  1001. barrier();
  1002. }
  1003. return 1;
  1004. #else
  1005. return 0;
  1006. #endif /* CONFIG_SMP */
  1007. }
  1008. static unsigned short fcstab[256] = {
  1009. 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
  1010. 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
  1011. 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
  1012. 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
  1013. 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
  1014. 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
  1015. 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
  1016. 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
  1017. 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
  1018. 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
  1019. 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
  1020. 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
  1021. 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
  1022. 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
  1023. 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
  1024. 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
  1025. 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
  1026. 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
  1027. 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
  1028. 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
  1029. 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
  1030. 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
  1031. 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
  1032. 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
  1033. 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
  1034. 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
  1035. 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
  1036. 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
  1037. 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
  1038. 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
  1039. 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
  1040. 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
  1041. };
  1042. #define FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
  1043. static void
  1044. csum(void)
  1045. {
  1046. unsigned int i;
  1047. unsigned short fcs;
  1048. unsigned char v;
  1049. if (!scanhex(&adrs))
  1050. return;
  1051. if (!scanhex(&ncsum))
  1052. return;
  1053. fcs = 0xffff;
  1054. for (i = 0; i < ncsum; ++i) {
  1055. if (mread(adrs+i, &v, 1) == 0) {
  1056. printf("csum stopped at "REG"\n", adrs+i);
  1057. break;
  1058. }
  1059. fcs = FCS(fcs, v);
  1060. }
  1061. printf("%x\n", fcs);
  1062. }
  1063. /*
  1064. * Check if this is a suitable place to put a breakpoint.
  1065. */
  1066. static long check_bp_loc(unsigned long addr)
  1067. {
  1068. unsigned int instr;
  1069. addr &= ~3;
  1070. if (!is_kernel_addr(addr)) {
  1071. printf("Breakpoints may only be placed at kernel addresses\n");
  1072. return 0;
  1073. }
  1074. if (!mread(addr, &instr, sizeof(instr))) {
  1075. printf("Can't read instruction at address %lx\n", addr);
  1076. return 0;
  1077. }
  1078. if (IS_MTMSRD(instr) || IS_RFID(instr)) {
  1079. printf("Breakpoints may not be placed on mtmsrd or rfid "
  1080. "instructions\n");
  1081. return 0;
  1082. }
  1083. return 1;
  1084. }
  1085. static char *breakpoint_help_string =
  1086. "Breakpoint command usage:\n"
  1087. "b show breakpoints\n"
  1088. "b <addr> [cnt] set breakpoint at given instr addr\n"
  1089. "bc clear all breakpoints\n"
  1090. "bc <n/addr> clear breakpoint number n or at addr\n"
  1091. "bi <addr> [cnt] set hardware instr breakpoint (POWER8 only)\n"
  1092. "bd <addr> [cnt] set hardware data breakpoint\n"
  1093. "";
  1094. static void
  1095. bpt_cmds(void)
  1096. {
  1097. int cmd;
  1098. unsigned long a;
  1099. int mode, i;
  1100. struct bpt *bp;
  1101. const char badaddr[] = "Only kernel addresses are permitted "
  1102. "for breakpoints\n";
  1103. cmd = inchar();
  1104. switch (cmd) {
  1105. #ifndef CONFIG_8xx
  1106. case 'd': /* bd - hardware data breakpoint */
  1107. mode = 7;
  1108. cmd = inchar();
  1109. if (cmd == 'r')
  1110. mode = 5;
  1111. else if (cmd == 'w')
  1112. mode = 6;
  1113. else
  1114. termch = cmd;
  1115. dabr.address = 0;
  1116. dabr.enabled = 0;
  1117. if (scanhex(&dabr.address)) {
  1118. if (!is_kernel_addr(dabr.address)) {
  1119. printf(badaddr);
  1120. break;
  1121. }
  1122. dabr.address &= ~HW_BRK_TYPE_DABR;
  1123. dabr.enabled = mode | BP_DABR;
  1124. }
  1125. break;
  1126. case 'i': /* bi - hardware instr breakpoint */
  1127. if (!cpu_has_feature(CPU_FTR_ARCH_207S)) {
  1128. printf("Hardware instruction breakpoint "
  1129. "not supported on this cpu\n");
  1130. break;
  1131. }
  1132. if (iabr) {
  1133. iabr->enabled &= ~BP_CIABR;
  1134. iabr = NULL;
  1135. }
  1136. if (!scanhex(&a))
  1137. break;
  1138. if (!check_bp_loc(a))
  1139. break;
  1140. bp = new_breakpoint(a);
  1141. if (bp != NULL) {
  1142. bp->enabled |= BP_CIABR;
  1143. iabr = bp;
  1144. }
  1145. break;
  1146. #endif
  1147. case 'c':
  1148. if (!scanhex(&a)) {
  1149. /* clear all breakpoints */
  1150. for (i = 0; i < NBPTS; ++i)
  1151. bpts[i].enabled = 0;
  1152. iabr = NULL;
  1153. dabr.enabled = 0;
  1154. printf("All breakpoints cleared\n");
  1155. break;
  1156. }
  1157. if (a <= NBPTS && a >= 1) {
  1158. /* assume a breakpoint number */
  1159. bp = &bpts[a-1]; /* bp nums are 1 based */
  1160. } else {
  1161. /* assume a breakpoint address */
  1162. bp = at_breakpoint(a);
  1163. if (bp == NULL) {
  1164. printf("No breakpoint at %lx\n", a);
  1165. break;
  1166. }
  1167. }
  1168. printf("Cleared breakpoint %lx (", BP_NUM(bp));
  1169. xmon_print_symbol(bp->address, " ", ")\n");
  1170. bp->enabled = 0;
  1171. break;
  1172. default:
  1173. termch = cmd;
  1174. cmd = skipbl();
  1175. if (cmd == '?') {
  1176. printf(breakpoint_help_string);
  1177. break;
  1178. }
  1179. termch = cmd;
  1180. if (!scanhex(&a)) {
  1181. /* print all breakpoints */
  1182. printf(" type address\n");
  1183. if (dabr.enabled) {
  1184. printf(" data "REG" [", dabr.address);
  1185. if (dabr.enabled & 1)
  1186. printf("r");
  1187. if (dabr.enabled & 2)
  1188. printf("w");
  1189. printf("]\n");
  1190. }
  1191. for (bp = bpts; bp < &bpts[NBPTS]; ++bp) {
  1192. if (!bp->enabled)
  1193. continue;
  1194. printf("%2x %s ", BP_NUM(bp),
  1195. (bp->enabled & BP_CIABR) ? "inst": "trap");
  1196. xmon_print_symbol(bp->address, " ", "\n");
  1197. }
  1198. break;
  1199. }
  1200. if (!check_bp_loc(a))
  1201. break;
  1202. bp = new_breakpoint(a);
  1203. if (bp != NULL)
  1204. bp->enabled |= BP_TRAP;
  1205. break;
  1206. }
  1207. }
  1208. /* Very cheap human name for vector lookup. */
  1209. static
  1210. const char *getvecname(unsigned long vec)
  1211. {
  1212. char *ret;
  1213. switch (vec) {
  1214. case 0x100: ret = "(System Reset)"; break;
  1215. case 0x200: ret = "(Machine Check)"; break;
  1216. case 0x300: ret = "(Data Access)"; break;
  1217. case 0x380: ret = "(Data SLB Access)"; break;
  1218. case 0x400: ret = "(Instruction Access)"; break;
  1219. case 0x480: ret = "(Instruction SLB Access)"; break;
  1220. case 0x500: ret = "(Hardware Interrupt)"; break;
  1221. case 0x600: ret = "(Alignment)"; break;
  1222. case 0x700: ret = "(Program Check)"; break;
  1223. case 0x800: ret = "(FPU Unavailable)"; break;
  1224. case 0x900: ret = "(Decrementer)"; break;
  1225. case 0x980: ret = "(Hypervisor Decrementer)"; break;
  1226. case 0xa00: ret = "(Doorbell)"; break;
  1227. case 0xc00: ret = "(System Call)"; break;
  1228. case 0xd00: ret = "(Single Step)"; break;
  1229. case 0xe40: ret = "(Emulation Assist)"; break;
  1230. case 0xe60: ret = "(HMI)"; break;
  1231. case 0xe80: ret = "(Hypervisor Doorbell)"; break;
  1232. case 0xf00: ret = "(Performance Monitor)"; break;
  1233. case 0xf20: ret = "(Altivec Unavailable)"; break;
  1234. case 0x1300: ret = "(Instruction Breakpoint)"; break;
  1235. case 0x1500: ret = "(Denormalisation)"; break;
  1236. case 0x1700: ret = "(Altivec Assist)"; break;
  1237. default: ret = "";
  1238. }
  1239. return ret;
  1240. }
  1241. static void get_function_bounds(unsigned long pc, unsigned long *startp,
  1242. unsigned long *endp)
  1243. {
  1244. unsigned long size, offset;
  1245. const char *name;
  1246. *startp = *endp = 0;
  1247. if (pc == 0)
  1248. return;
  1249. if (setjmp(bus_error_jmp) == 0) {
  1250. catch_memory_errors = 1;
  1251. sync();
  1252. name = kallsyms_lookup(pc, &size, &offset, NULL, tmpstr);
  1253. if (name != NULL) {
  1254. *startp = pc - offset;
  1255. *endp = pc - offset + size;
  1256. }
  1257. sync();
  1258. }
  1259. catch_memory_errors = 0;
  1260. }
  1261. #define LRSAVE_OFFSET (STACK_FRAME_LR_SAVE * sizeof(unsigned long))
  1262. #define MARKER_OFFSET (STACK_FRAME_MARKER * sizeof(unsigned long))
  1263. static void xmon_show_stack(unsigned long sp, unsigned long lr,
  1264. unsigned long pc)
  1265. {
  1266. int max_to_print = 64;
  1267. unsigned long ip;
  1268. unsigned long newsp;
  1269. unsigned long marker;
  1270. struct pt_regs regs;
  1271. while (max_to_print--) {
  1272. if (sp < PAGE_OFFSET) {
  1273. if (sp != 0)
  1274. printf("SP (%lx) is in userspace\n", sp);
  1275. break;
  1276. }
  1277. if (!mread(sp + LRSAVE_OFFSET, &ip, sizeof(unsigned long))
  1278. || !mread(sp, &newsp, sizeof(unsigned long))) {
  1279. printf("Couldn't read stack frame at %lx\n", sp);
  1280. break;
  1281. }
  1282. /*
  1283. * For the first stack frame, try to work out if
  1284. * LR and/or the saved LR value in the bottommost
  1285. * stack frame are valid.
  1286. */
  1287. if ((pc | lr) != 0) {
  1288. unsigned long fnstart, fnend;
  1289. unsigned long nextip;
  1290. int printip = 1;
  1291. get_function_bounds(pc, &fnstart, &fnend);
  1292. nextip = 0;
  1293. if (newsp > sp)
  1294. mread(newsp + LRSAVE_OFFSET, &nextip,
  1295. sizeof(unsigned long));
  1296. if (lr == ip) {
  1297. if (lr < PAGE_OFFSET
  1298. || (fnstart <= lr && lr < fnend))
  1299. printip = 0;
  1300. } else if (lr == nextip) {
  1301. printip = 0;
  1302. } else if (lr >= PAGE_OFFSET
  1303. && !(fnstart <= lr && lr < fnend)) {
  1304. printf("[link register ] ");
  1305. xmon_print_symbol(lr, " ", "\n");
  1306. }
  1307. if (printip) {
  1308. printf("["REG"] ", sp);
  1309. xmon_print_symbol(ip, " ", " (unreliable)\n");
  1310. }
  1311. pc = lr = 0;
  1312. } else {
  1313. printf("["REG"] ", sp);
  1314. xmon_print_symbol(ip, " ", "\n");
  1315. }
  1316. /* Look for "regshere" marker to see if this is
  1317. an exception frame. */
  1318. if (mread(sp + MARKER_OFFSET, &marker, sizeof(unsigned long))
  1319. && marker == STACK_FRAME_REGS_MARKER) {
  1320. if (mread(sp + STACK_FRAME_OVERHEAD, &regs, sizeof(regs))
  1321. != sizeof(regs)) {
  1322. printf("Couldn't read registers at %lx\n",
  1323. sp + STACK_FRAME_OVERHEAD);
  1324. break;
  1325. }
  1326. printf("--- Exception: %lx %s at ", regs.trap,
  1327. getvecname(TRAP(&regs)));
  1328. pc = regs.nip;
  1329. lr = regs.link;
  1330. xmon_print_symbol(pc, " ", "\n");
  1331. }
  1332. if (newsp == 0)
  1333. break;
  1334. sp = newsp;
  1335. }
  1336. }
  1337. static void backtrace(struct pt_regs *excp)
  1338. {
  1339. unsigned long sp;
  1340. if (scanhex(&sp))
  1341. xmon_show_stack(sp, 0, 0);
  1342. else
  1343. xmon_show_stack(excp->gpr[1], excp->link, excp->nip);
  1344. scannl();
  1345. }
  1346. static void print_bug_trap(struct pt_regs *regs)
  1347. {
  1348. #ifdef CONFIG_BUG
  1349. const struct bug_entry *bug;
  1350. unsigned long addr;
  1351. if (regs->msr & MSR_PR)
  1352. return; /* not in kernel */
  1353. addr = regs->nip; /* address of trap instruction */
  1354. if (addr < PAGE_OFFSET)
  1355. return;
  1356. bug = find_bug(regs->nip);
  1357. if (bug == NULL)
  1358. return;
  1359. if (is_warning_bug(bug))
  1360. return;
  1361. #ifdef CONFIG_DEBUG_BUGVERBOSE
  1362. printf("kernel BUG at %s:%u!\n",
  1363. bug->file, bug->line);
  1364. #else
  1365. printf("kernel BUG at %p!\n", (void *)bug->bug_addr);
  1366. #endif
  1367. #endif /* CONFIG_BUG */
  1368. }
  1369. static void excprint(struct pt_regs *fp)
  1370. {
  1371. unsigned long trap;
  1372. #ifdef CONFIG_SMP
  1373. printf("cpu 0x%x: ", smp_processor_id());
  1374. #endif /* CONFIG_SMP */
  1375. trap = TRAP(fp);
  1376. printf("Vector: %lx %s at [%lx]\n", fp->trap, getvecname(trap), fp);
  1377. printf(" pc: ");
  1378. xmon_print_symbol(fp->nip, ": ", "\n");
  1379. printf(" lr: ", fp->link);
  1380. xmon_print_symbol(fp->link, ": ", "\n");
  1381. printf(" sp: %lx\n", fp->gpr[1]);
  1382. printf(" msr: %lx\n", fp->msr);
  1383. if (trap == 0x300 || trap == 0x380 || trap == 0x600 || trap == 0x200) {
  1384. printf(" dar: %lx\n", fp->dar);
  1385. if (trap != 0x380)
  1386. printf(" dsisr: %lx\n", fp->dsisr);
  1387. }
  1388. printf(" current = 0x%lx\n", current);
  1389. #ifdef CONFIG_PPC64
  1390. printf(" paca = 0x%lx\t softe: %d\t irq_happened: 0x%02x\n",
  1391. local_paca, local_paca->soft_enabled, local_paca->irq_happened);
  1392. #endif
  1393. if (current) {
  1394. printf(" pid = %ld, comm = %s\n",
  1395. current->pid, current->comm);
  1396. }
  1397. if (trap == 0x700)
  1398. print_bug_trap(fp);
  1399. printf(linux_banner);
  1400. }
  1401. static void prregs(struct pt_regs *fp)
  1402. {
  1403. int n, trap;
  1404. unsigned long base;
  1405. struct pt_regs regs;
  1406. if (scanhex(&base)) {
  1407. if (setjmp(bus_error_jmp) == 0) {
  1408. catch_memory_errors = 1;
  1409. sync();
  1410. regs = *(struct pt_regs *)base;
  1411. sync();
  1412. __delay(200);
  1413. } else {
  1414. catch_memory_errors = 0;
  1415. printf("*** Error reading registers from "REG"\n",
  1416. base);
  1417. return;
  1418. }
  1419. catch_memory_errors = 0;
  1420. fp = &regs;
  1421. }
  1422. #ifdef CONFIG_PPC64
  1423. if (FULL_REGS(fp)) {
  1424. for (n = 0; n < 16; ++n)
  1425. printf("R%.2ld = "REG" R%.2ld = "REG"\n",
  1426. n, fp->gpr[n], n+16, fp->gpr[n+16]);
  1427. } else {
  1428. for (n = 0; n < 7; ++n)
  1429. printf("R%.2ld = "REG" R%.2ld = "REG"\n",
  1430. n, fp->gpr[n], n+7, fp->gpr[n+7]);
  1431. }
  1432. #else
  1433. for (n = 0; n < 32; ++n) {
  1434. printf("R%.2d = %.8x%s", n, fp->gpr[n],
  1435. (n & 3) == 3? "\n": " ");
  1436. if (n == 12 && !FULL_REGS(fp)) {
  1437. printf("\n");
  1438. break;
  1439. }
  1440. }
  1441. #endif
  1442. printf("pc = ");
  1443. xmon_print_symbol(fp->nip, " ", "\n");
  1444. if (TRAP(fp) != 0xc00 && cpu_has_feature(CPU_FTR_CFAR)) {
  1445. printf("cfar= ");
  1446. xmon_print_symbol(fp->orig_gpr3, " ", "\n");
  1447. }
  1448. printf("lr = ");
  1449. xmon_print_symbol(fp->link, " ", "\n");
  1450. printf("msr = "REG" cr = %.8lx\n", fp->msr, fp->ccr);
  1451. printf("ctr = "REG" xer = "REG" trap = %4lx\n",
  1452. fp->ctr, fp->xer, fp->trap);
  1453. trap = TRAP(fp);
  1454. if (trap == 0x300 || trap == 0x380 || trap == 0x600)
  1455. printf("dar = "REG" dsisr = %.8lx\n", fp->dar, fp->dsisr);
  1456. }
  1457. static void cacheflush(void)
  1458. {
  1459. int cmd;
  1460. unsigned long nflush;
  1461. cmd = inchar();
  1462. if (cmd != 'i')
  1463. termch = cmd;
  1464. scanhex((void *)&adrs);
  1465. if (termch != '\n')
  1466. termch = 0;
  1467. nflush = 1;
  1468. scanhex(&nflush);
  1469. nflush = (nflush + L1_CACHE_BYTES - 1) / L1_CACHE_BYTES;
  1470. if (setjmp(bus_error_jmp) == 0) {
  1471. catch_memory_errors = 1;
  1472. sync();
  1473. if (cmd != 'i') {
  1474. for (; nflush > 0; --nflush, adrs += L1_CACHE_BYTES)
  1475. cflush((void *) adrs);
  1476. } else {
  1477. for (; nflush > 0; --nflush, adrs += L1_CACHE_BYTES)
  1478. cinval((void *) adrs);
  1479. }
  1480. sync();
  1481. /* wait a little while to see if we get a machine check */
  1482. __delay(200);
  1483. }
  1484. catch_memory_errors = 0;
  1485. }
  1486. extern unsigned long xmon_mfspr(int spr, unsigned long default_value);
  1487. extern void xmon_mtspr(int spr, unsigned long value);
  1488. static int
  1489. read_spr(int n, unsigned long *vp)
  1490. {
  1491. unsigned long ret = -1UL;
  1492. int ok = 0;
  1493. if (setjmp(bus_error_jmp) == 0) {
  1494. catch_spr_faults = 1;
  1495. sync();
  1496. ret = xmon_mfspr(n, *vp);
  1497. sync();
  1498. *vp = ret;
  1499. ok = 1;
  1500. }
  1501. catch_spr_faults = 0;
  1502. return ok;
  1503. }
  1504. static void
  1505. write_spr(int n, unsigned long val)
  1506. {
  1507. if (setjmp(bus_error_jmp) == 0) {
  1508. catch_spr_faults = 1;
  1509. sync();
  1510. xmon_mtspr(n, val);
  1511. sync();
  1512. } else {
  1513. printf("SPR 0x%03x (%4d) Faulted during write\n", n, n);
  1514. }
  1515. catch_spr_faults = 0;
  1516. }
  1517. static void dump_206_sprs(void)
  1518. {
  1519. #ifdef CONFIG_PPC64
  1520. if (!cpu_has_feature(CPU_FTR_ARCH_206))
  1521. return;
  1522. /* Actually some of these pre-date 2.06, but whatevs */
  1523. printf("srr0 = %.16x srr1 = %.16x dsisr = %.8x\n",
  1524. mfspr(SPRN_SRR0), mfspr(SPRN_SRR1), mfspr(SPRN_DSISR));
  1525. printf("dscr = %.16x ppr = %.16x pir = %.8x\n",
  1526. mfspr(SPRN_DSCR), mfspr(SPRN_PPR), mfspr(SPRN_PIR));
  1527. if (!(mfmsr() & MSR_HV))
  1528. return;
  1529. printf("sdr1 = %.16x hdar = %.16x hdsisr = %.8x\n",
  1530. mfspr(SPRN_SDR1), mfspr(SPRN_HDAR), mfspr(SPRN_HDSISR));
  1531. printf("hsrr0 = %.16x hsrr1 = %.16x hdec = %.8x\n",
  1532. mfspr(SPRN_HSRR0), mfspr(SPRN_HSRR1), mfspr(SPRN_HDEC));
  1533. printf("lpcr = %.16x pcr = %.16x lpidr = %.8x\n",
  1534. mfspr(SPRN_LPCR), mfspr(SPRN_PCR), mfspr(SPRN_LPID));
  1535. printf("hsprg0 = %.16x hsprg1 = %.16x\n",
  1536. mfspr(SPRN_HSPRG0), mfspr(SPRN_HSPRG1));
  1537. printf("dabr = %.16x dabrx = %.16x\n",
  1538. mfspr(SPRN_DABR), mfspr(SPRN_DABRX));
  1539. #endif
  1540. }
  1541. static void dump_207_sprs(void)
  1542. {
  1543. #ifdef CONFIG_PPC64
  1544. unsigned long msr;
  1545. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  1546. return;
  1547. printf("dpdes = %.16x tir = %.16x cir = %.8x\n",
  1548. mfspr(SPRN_DPDES), mfspr(SPRN_TIR), mfspr(SPRN_CIR));
  1549. printf("fscr = %.16x tar = %.16x pspb = %.8x\n",
  1550. mfspr(SPRN_FSCR), mfspr(SPRN_TAR), mfspr(SPRN_PSPB));
  1551. msr = mfmsr();
  1552. if (msr & MSR_TM) {
  1553. /* Only if TM has been enabled in the kernel */
  1554. printf("tfhar = %.16x tfiar = %.16x texasr = %.16x\n",
  1555. mfspr(SPRN_TFHAR), mfspr(SPRN_TFIAR),
  1556. mfspr(SPRN_TEXASR));
  1557. }
  1558. printf("mmcr0 = %.16x mmcr1 = %.16x mmcr2 = %.16x\n",
  1559. mfspr(SPRN_MMCR0), mfspr(SPRN_MMCR1), mfspr(SPRN_MMCR2));
  1560. printf("pmc1 = %.8x pmc2 = %.8x pmc3 = %.8x pmc4 = %.8x\n",
  1561. mfspr(SPRN_PMC1), mfspr(SPRN_PMC2),
  1562. mfspr(SPRN_PMC3), mfspr(SPRN_PMC4));
  1563. printf("mmcra = %.16x siar = %.16x pmc5 = %.8x\n",
  1564. mfspr(SPRN_MMCRA), mfspr(SPRN_SIAR), mfspr(SPRN_PMC5));
  1565. printf("sdar = %.16x sier = %.16x pmc6 = %.8x\n",
  1566. mfspr(SPRN_SDAR), mfspr(SPRN_SIER), mfspr(SPRN_PMC6));
  1567. printf("ebbhr = %.16x ebbrr = %.16x bescr = %.16x\n",
  1568. mfspr(SPRN_EBBHR), mfspr(SPRN_EBBRR), mfspr(SPRN_BESCR));
  1569. if (!(msr & MSR_HV))
  1570. return;
  1571. printf("hfscr = %.16x dhdes = %.16x rpr = %.16x\n",
  1572. mfspr(SPRN_HFSCR), mfspr(SPRN_DHDES), mfspr(SPRN_RPR));
  1573. printf("dawr = %.16x dawrx = %.16x ciabr = %.16x\n",
  1574. mfspr(SPRN_DAWR), mfspr(SPRN_DAWRX), mfspr(SPRN_CIABR));
  1575. #endif
  1576. }
  1577. static void dump_one_spr(int spr, bool show_unimplemented)
  1578. {
  1579. unsigned long val;
  1580. val = 0xdeadbeef;
  1581. if (!read_spr(spr, &val)) {
  1582. printf("SPR 0x%03x (%4d) Faulted during read\n", spr, spr);
  1583. return;
  1584. }
  1585. if (val == 0xdeadbeef) {
  1586. /* Looks like read was a nop, confirm */
  1587. val = 0x0badcafe;
  1588. if (!read_spr(spr, &val)) {
  1589. printf("SPR 0x%03x (%4d) Faulted during read\n", spr, spr);
  1590. return;
  1591. }
  1592. if (val == 0x0badcafe) {
  1593. if (show_unimplemented)
  1594. printf("SPR 0x%03x (%4d) Unimplemented\n", spr, spr);
  1595. return;
  1596. }
  1597. }
  1598. printf("SPR 0x%03x (%4d) = 0x%lx\n", spr, spr, val);
  1599. }
  1600. static void super_regs(void)
  1601. {
  1602. static unsigned long regno;
  1603. int cmd;
  1604. int spr;
  1605. cmd = skipbl();
  1606. switch (cmd) {
  1607. case '\n': {
  1608. unsigned long sp, toc;
  1609. asm("mr %0,1" : "=r" (sp) :);
  1610. asm("mr %0,2" : "=r" (toc) :);
  1611. printf("msr = "REG" sprg0 = "REG"\n",
  1612. mfmsr(), mfspr(SPRN_SPRG0));
  1613. printf("pvr = "REG" sprg1 = "REG"\n",
  1614. mfspr(SPRN_PVR), mfspr(SPRN_SPRG1));
  1615. printf("dec = "REG" sprg2 = "REG"\n",
  1616. mfspr(SPRN_DEC), mfspr(SPRN_SPRG2));
  1617. printf("sp = "REG" sprg3 = "REG"\n", sp, mfspr(SPRN_SPRG3));
  1618. printf("toc = "REG" dar = "REG"\n", toc, mfspr(SPRN_DAR));
  1619. dump_206_sprs();
  1620. dump_207_sprs();
  1621. return;
  1622. }
  1623. case 'w': {
  1624. unsigned long val;
  1625. scanhex(&regno);
  1626. val = 0;
  1627. read_spr(regno, &val);
  1628. scanhex(&val);
  1629. write_spr(regno, val);
  1630. dump_one_spr(regno, true);
  1631. break;
  1632. }
  1633. case 'r':
  1634. scanhex(&regno);
  1635. dump_one_spr(regno, true);
  1636. break;
  1637. case 'a':
  1638. /* dump ALL SPRs */
  1639. for (spr = 1; spr < 1024; ++spr)
  1640. dump_one_spr(spr, false);
  1641. break;
  1642. }
  1643. scannl();
  1644. }
  1645. /*
  1646. * Stuff for reading and writing memory safely
  1647. */
  1648. static int
  1649. mread(unsigned long adrs, void *buf, int size)
  1650. {
  1651. volatile int n;
  1652. char *p, *q;
  1653. n = 0;
  1654. if (setjmp(bus_error_jmp) == 0) {
  1655. catch_memory_errors = 1;
  1656. sync();
  1657. p = (char *)adrs;
  1658. q = (char *)buf;
  1659. switch (size) {
  1660. case 2:
  1661. *(u16 *)q = *(u16 *)p;
  1662. break;
  1663. case 4:
  1664. *(u32 *)q = *(u32 *)p;
  1665. break;
  1666. case 8:
  1667. *(u64 *)q = *(u64 *)p;
  1668. break;
  1669. default:
  1670. for( ; n < size; ++n) {
  1671. *q++ = *p++;
  1672. sync();
  1673. }
  1674. }
  1675. sync();
  1676. /* wait a little while to see if we get a machine check */
  1677. __delay(200);
  1678. n = size;
  1679. }
  1680. catch_memory_errors = 0;
  1681. return n;
  1682. }
  1683. static int
  1684. mwrite(unsigned long adrs, void *buf, int size)
  1685. {
  1686. volatile int n;
  1687. char *p, *q;
  1688. n = 0;
  1689. if (setjmp(bus_error_jmp) == 0) {
  1690. catch_memory_errors = 1;
  1691. sync();
  1692. p = (char *) adrs;
  1693. q = (char *) buf;
  1694. switch (size) {
  1695. case 2:
  1696. *(u16 *)p = *(u16 *)q;
  1697. break;
  1698. case 4:
  1699. *(u32 *)p = *(u32 *)q;
  1700. break;
  1701. case 8:
  1702. *(u64 *)p = *(u64 *)q;
  1703. break;
  1704. default:
  1705. for ( ; n < size; ++n) {
  1706. *p++ = *q++;
  1707. sync();
  1708. }
  1709. }
  1710. sync();
  1711. /* wait a little while to see if we get a machine check */
  1712. __delay(200);
  1713. n = size;
  1714. } else {
  1715. printf("*** Error writing address "REG"\n", adrs + n);
  1716. }
  1717. catch_memory_errors = 0;
  1718. return n;
  1719. }
  1720. static int fault_type;
  1721. static int fault_except;
  1722. static char *fault_chars[] = { "--", "**", "##" };
  1723. static int handle_fault(struct pt_regs *regs)
  1724. {
  1725. fault_except = TRAP(regs);
  1726. switch (TRAP(regs)) {
  1727. case 0x200:
  1728. fault_type = 0;
  1729. break;
  1730. case 0x300:
  1731. case 0x380:
  1732. fault_type = 1;
  1733. break;
  1734. default:
  1735. fault_type = 2;
  1736. }
  1737. longjmp(bus_error_jmp, 1);
  1738. return 0;
  1739. }
  1740. #define SWAP(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
  1741. static void
  1742. byterev(unsigned char *val, int size)
  1743. {
  1744. int t;
  1745. switch (size) {
  1746. case 2:
  1747. SWAP(val[0], val[1], t);
  1748. break;
  1749. case 4:
  1750. SWAP(val[0], val[3], t);
  1751. SWAP(val[1], val[2], t);
  1752. break;
  1753. case 8: /* is there really any use for this? */
  1754. SWAP(val[0], val[7], t);
  1755. SWAP(val[1], val[6], t);
  1756. SWAP(val[2], val[5], t);
  1757. SWAP(val[3], val[4], t);
  1758. break;
  1759. }
  1760. }
  1761. static int brev;
  1762. static int mnoread;
  1763. static char *memex_help_string =
  1764. "Memory examine command usage:\n"
  1765. "m [addr] [flags] examine/change memory\n"
  1766. " addr is optional. will start where left off.\n"
  1767. " flags may include chars from this set:\n"
  1768. " b modify by bytes (default)\n"
  1769. " w modify by words (2 byte)\n"
  1770. " l modify by longs (4 byte)\n"
  1771. " d modify by doubleword (8 byte)\n"
  1772. " r toggle reverse byte order mode\n"
  1773. " n do not read memory (for i/o spaces)\n"
  1774. " . ok to read (default)\n"
  1775. "NOTE: flags are saved as defaults\n"
  1776. "";
  1777. static char *memex_subcmd_help_string =
  1778. "Memory examine subcommands:\n"
  1779. " hexval write this val to current location\n"
  1780. " 'string' write chars from string to this location\n"
  1781. " ' increment address\n"
  1782. " ^ decrement address\n"
  1783. " / increment addr by 0x10. //=0x100, ///=0x1000, etc\n"
  1784. " \\ decrement addr by 0x10. \\\\=0x100, \\\\\\=0x1000, etc\n"
  1785. " ` clear no-read flag\n"
  1786. " ; stay at this addr\n"
  1787. " v change to byte mode\n"
  1788. " w change to word (2 byte) mode\n"
  1789. " l change to long (4 byte) mode\n"
  1790. " u change to doubleword (8 byte) mode\n"
  1791. " m addr change current addr\n"
  1792. " n toggle no-read flag\n"
  1793. " r toggle byte reverse flag\n"
  1794. " < count back up count bytes\n"
  1795. " > count skip forward count bytes\n"
  1796. " x exit this mode\n"
  1797. "";
  1798. static void
  1799. memex(void)
  1800. {
  1801. int cmd, inc, i, nslash;
  1802. unsigned long n;
  1803. unsigned char val[16];
  1804. scanhex((void *)&adrs);
  1805. cmd = skipbl();
  1806. if (cmd == '?') {
  1807. printf(memex_help_string);
  1808. return;
  1809. } else {
  1810. termch = cmd;
  1811. }
  1812. last_cmd = "m\n";
  1813. while ((cmd = skipbl()) != '\n') {
  1814. switch( cmd ){
  1815. case 'b': size = 1; break;
  1816. case 'w': size = 2; break;
  1817. case 'l': size = 4; break;
  1818. case 'd': size = 8; break;
  1819. case 'r': brev = !brev; break;
  1820. case 'n': mnoread = 1; break;
  1821. case '.': mnoread = 0; break;
  1822. }
  1823. }
  1824. if( size <= 0 )
  1825. size = 1;
  1826. else if( size > 8 )
  1827. size = 8;
  1828. for(;;){
  1829. if (!mnoread)
  1830. n = mread(adrs, val, size);
  1831. printf(REG"%c", adrs, brev? 'r': ' ');
  1832. if (!mnoread) {
  1833. if (brev)
  1834. byterev(val, size);
  1835. putchar(' ');
  1836. for (i = 0; i < n; ++i)
  1837. printf("%.2x", val[i]);
  1838. for (; i < size; ++i)
  1839. printf("%s", fault_chars[fault_type]);
  1840. }
  1841. putchar(' ');
  1842. inc = size;
  1843. nslash = 0;
  1844. for(;;){
  1845. if( scanhex(&n) ){
  1846. for (i = 0; i < size; ++i)
  1847. val[i] = n >> (i * 8);
  1848. if (!brev)
  1849. byterev(val, size);
  1850. mwrite(adrs, val, size);
  1851. inc = size;
  1852. }
  1853. cmd = skipbl();
  1854. if (cmd == '\n')
  1855. break;
  1856. inc = 0;
  1857. switch (cmd) {
  1858. case '\'':
  1859. for(;;){
  1860. n = inchar();
  1861. if( n == '\\' )
  1862. n = bsesc();
  1863. else if( n == '\'' )
  1864. break;
  1865. for (i = 0; i < size; ++i)
  1866. val[i] = n >> (i * 8);
  1867. if (!brev)
  1868. byterev(val, size);
  1869. mwrite(adrs, val, size);
  1870. adrs += size;
  1871. }
  1872. adrs -= size;
  1873. inc = size;
  1874. break;
  1875. case ',':
  1876. adrs += size;
  1877. break;
  1878. case '.':
  1879. mnoread = 0;
  1880. break;
  1881. case ';':
  1882. break;
  1883. case 'x':
  1884. case EOF:
  1885. scannl();
  1886. return;
  1887. case 'b':
  1888. case 'v':
  1889. size = 1;
  1890. break;
  1891. case 'w':
  1892. size = 2;
  1893. break;
  1894. case 'l':
  1895. size = 4;
  1896. break;
  1897. case 'u':
  1898. size = 8;
  1899. break;
  1900. case '^':
  1901. adrs -= size;
  1902. break;
  1903. case '/':
  1904. if (nslash > 0)
  1905. adrs -= 1 << nslash;
  1906. else
  1907. nslash = 0;
  1908. nslash += 4;
  1909. adrs += 1 << nslash;
  1910. break;
  1911. case '\\':
  1912. if (nslash < 0)
  1913. adrs += 1 << -nslash;
  1914. else
  1915. nslash = 0;
  1916. nslash -= 4;
  1917. adrs -= 1 << -nslash;
  1918. break;
  1919. case 'm':
  1920. scanhex((void *)&adrs);
  1921. break;
  1922. case 'n':
  1923. mnoread = 1;
  1924. break;
  1925. case 'r':
  1926. brev = !brev;
  1927. break;
  1928. case '<':
  1929. n = size;
  1930. scanhex(&n);
  1931. adrs -= n;
  1932. break;
  1933. case '>':
  1934. n = size;
  1935. scanhex(&n);
  1936. adrs += n;
  1937. break;
  1938. case '?':
  1939. printf(memex_subcmd_help_string);
  1940. break;
  1941. }
  1942. }
  1943. adrs += inc;
  1944. }
  1945. }
  1946. static int
  1947. bsesc(void)
  1948. {
  1949. int c;
  1950. c = inchar();
  1951. switch( c ){
  1952. case 'n': c = '\n'; break;
  1953. case 'r': c = '\r'; break;
  1954. case 'b': c = '\b'; break;
  1955. case 't': c = '\t'; break;
  1956. }
  1957. return c;
  1958. }
  1959. static void xmon_rawdump (unsigned long adrs, long ndump)
  1960. {
  1961. long n, m, r, nr;
  1962. unsigned char temp[16];
  1963. for (n = ndump; n > 0;) {
  1964. r = n < 16? n: 16;
  1965. nr = mread(adrs, temp, r);
  1966. adrs += nr;
  1967. for (m = 0; m < r; ++m) {
  1968. if (m < nr)
  1969. printf("%.2x", temp[m]);
  1970. else
  1971. printf("%s", fault_chars[fault_type]);
  1972. }
  1973. n -= r;
  1974. if (nr < r)
  1975. break;
  1976. }
  1977. printf("\n");
  1978. }
  1979. #ifdef CONFIG_PPC64
  1980. static void dump_one_paca(int cpu)
  1981. {
  1982. struct paca_struct *p;
  1983. #ifdef CONFIG_PPC_STD_MMU_64
  1984. int i = 0;
  1985. #endif
  1986. if (setjmp(bus_error_jmp) != 0) {
  1987. printf("*** Error dumping paca for cpu 0x%x!\n", cpu);
  1988. return;
  1989. }
  1990. catch_memory_errors = 1;
  1991. sync();
  1992. p = &paca[cpu];
  1993. printf("paca for cpu 0x%x @ %p:\n", cpu, p);
  1994. printf(" %-*s = %s\n", 20, "possible", cpu_possible(cpu) ? "yes" : "no");
  1995. printf(" %-*s = %s\n", 20, "present", cpu_present(cpu) ? "yes" : "no");
  1996. printf(" %-*s = %s\n", 20, "online", cpu_online(cpu) ? "yes" : "no");
  1997. #define DUMP(paca, name, format) \
  1998. printf(" %-*s = %#-*"format"\t(0x%lx)\n", 20, #name, 18, paca->name, \
  1999. offsetof(struct paca_struct, name));
  2000. DUMP(p, lock_token, "x");
  2001. DUMP(p, paca_index, "x");
  2002. DUMP(p, kernel_toc, "lx");
  2003. DUMP(p, kernelbase, "lx");
  2004. DUMP(p, kernel_msr, "lx");
  2005. DUMP(p, emergency_sp, "p");
  2006. #ifdef CONFIG_PPC_BOOK3S_64
  2007. DUMP(p, mc_emergency_sp, "p");
  2008. DUMP(p, in_mce, "x");
  2009. DUMP(p, hmi_event_available, "x");
  2010. #endif
  2011. DUMP(p, data_offset, "lx");
  2012. DUMP(p, hw_cpu_id, "x");
  2013. DUMP(p, cpu_start, "x");
  2014. DUMP(p, kexec_state, "x");
  2015. #ifdef CONFIG_PPC_STD_MMU_64
  2016. for (i = 0; i < SLB_NUM_BOLTED; i++) {
  2017. u64 esid, vsid;
  2018. if (!p->slb_shadow_ptr)
  2019. continue;
  2020. esid = be64_to_cpu(p->slb_shadow_ptr->save_area[i].esid);
  2021. vsid = be64_to_cpu(p->slb_shadow_ptr->save_area[i].vsid);
  2022. if (esid || vsid) {
  2023. printf(" slb_shadow[%d]: = 0x%016lx 0x%016lx\n",
  2024. i, esid, vsid);
  2025. }
  2026. }
  2027. DUMP(p, vmalloc_sllp, "x");
  2028. DUMP(p, slb_cache_ptr, "x");
  2029. for (i = 0; i < SLB_CACHE_ENTRIES; i++)
  2030. printf(" slb_cache[%d]: = 0x%016lx\n", i, p->slb_cache[i]);
  2031. #endif
  2032. DUMP(p, dscr_default, "llx");
  2033. #ifdef CONFIG_PPC_BOOK3E
  2034. DUMP(p, pgd, "p");
  2035. DUMP(p, kernel_pgd, "p");
  2036. DUMP(p, tcd_ptr, "p");
  2037. DUMP(p, mc_kstack, "p");
  2038. DUMP(p, crit_kstack, "p");
  2039. DUMP(p, dbg_kstack, "p");
  2040. #endif
  2041. DUMP(p, __current, "p");
  2042. DUMP(p, kstack, "lx");
  2043. DUMP(p, stab_rr, "lx");
  2044. DUMP(p, saved_r1, "lx");
  2045. DUMP(p, trap_save, "x");
  2046. DUMP(p, soft_enabled, "x");
  2047. DUMP(p, irq_happened, "x");
  2048. DUMP(p, io_sync, "x");
  2049. DUMP(p, irq_work_pending, "x");
  2050. DUMP(p, nap_state_lost, "x");
  2051. DUMP(p, sprg_vdso, "llx");
  2052. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  2053. DUMP(p, tm_scratch, "llx");
  2054. #endif
  2055. #ifdef CONFIG_PPC_POWERNV
  2056. DUMP(p, core_idle_state_ptr, "p");
  2057. DUMP(p, thread_idle_state, "x");
  2058. DUMP(p, thread_mask, "x");
  2059. DUMP(p, subcore_sibling_mask, "x");
  2060. #endif
  2061. DUMP(p, accounting.user_time, "llx");
  2062. DUMP(p, accounting.system_time, "llx");
  2063. DUMP(p, accounting.user_time_scaled, "llx");
  2064. DUMP(p, accounting.starttime, "llx");
  2065. DUMP(p, accounting.starttime_user, "llx");
  2066. DUMP(p, accounting.startspurr, "llx");
  2067. DUMP(p, accounting.utime_sspurr, "llx");
  2068. DUMP(p, stolen_time, "llx");
  2069. #undef DUMP
  2070. catch_memory_errors = 0;
  2071. sync();
  2072. }
  2073. static void dump_all_pacas(void)
  2074. {
  2075. int cpu;
  2076. if (num_possible_cpus() == 0) {
  2077. printf("No possible cpus, use 'dp #' to dump individual cpus\n");
  2078. return;
  2079. }
  2080. for_each_possible_cpu(cpu)
  2081. dump_one_paca(cpu);
  2082. }
  2083. static void dump_pacas(void)
  2084. {
  2085. unsigned long num;
  2086. int c;
  2087. c = inchar();
  2088. if (c == 'a') {
  2089. dump_all_pacas();
  2090. return;
  2091. }
  2092. termch = c; /* Put c back, it wasn't 'a' */
  2093. if (scanhex(&num))
  2094. dump_one_paca(num);
  2095. else
  2096. dump_one_paca(xmon_owner);
  2097. }
  2098. #endif
  2099. static void
  2100. dump(void)
  2101. {
  2102. int c;
  2103. c = inchar();
  2104. #ifdef CONFIG_PPC64
  2105. if (c == 'p') {
  2106. xmon_start_pagination();
  2107. dump_pacas();
  2108. xmon_end_pagination();
  2109. return;
  2110. }
  2111. #endif
  2112. if ((isxdigit(c) && c != 'f' && c != 'd') || c == '\n')
  2113. termch = c;
  2114. scanhex((void *)&adrs);
  2115. if (termch != '\n')
  2116. termch = 0;
  2117. if (c == 'i') {
  2118. scanhex(&nidump);
  2119. if (nidump == 0)
  2120. nidump = 16;
  2121. else if (nidump > MAX_DUMP)
  2122. nidump = MAX_DUMP;
  2123. adrs += ppc_inst_dump(adrs, nidump, 1);
  2124. last_cmd = "di\n";
  2125. } else if (c == 'l') {
  2126. dump_log_buf();
  2127. } else if (c == 'o') {
  2128. dump_opal_msglog();
  2129. } else if (c == 't') {
  2130. ftrace_dump(DUMP_ALL);
  2131. tracing_on();
  2132. } else if (c == 'r') {
  2133. scanhex(&ndump);
  2134. if (ndump == 0)
  2135. ndump = 64;
  2136. xmon_rawdump(adrs, ndump);
  2137. adrs += ndump;
  2138. last_cmd = "dr\n";
  2139. } else {
  2140. scanhex(&ndump);
  2141. if (ndump == 0)
  2142. ndump = 64;
  2143. else if (ndump > MAX_DUMP)
  2144. ndump = MAX_DUMP;
  2145. prdump(adrs, ndump);
  2146. adrs += ndump;
  2147. last_cmd = "d\n";
  2148. }
  2149. }
  2150. static void
  2151. prdump(unsigned long adrs, long ndump)
  2152. {
  2153. long n, m, c, r, nr;
  2154. unsigned char temp[16];
  2155. for (n = ndump; n > 0;) {
  2156. printf(REG, adrs);
  2157. putchar(' ');
  2158. r = n < 16? n: 16;
  2159. nr = mread(adrs, temp, r);
  2160. adrs += nr;
  2161. for (m = 0; m < r; ++m) {
  2162. if ((m & (sizeof(long) - 1)) == 0 && m > 0)
  2163. putchar(' ');
  2164. if (m < nr)
  2165. printf("%.2x", temp[m]);
  2166. else
  2167. printf("%s", fault_chars[fault_type]);
  2168. }
  2169. for (; m < 16; ++m) {
  2170. if ((m & (sizeof(long) - 1)) == 0)
  2171. putchar(' ');
  2172. printf(" ");
  2173. }
  2174. printf(" |");
  2175. for (m = 0; m < r; ++m) {
  2176. if (m < nr) {
  2177. c = temp[m];
  2178. putchar(' ' <= c && c <= '~'? c: '.');
  2179. } else
  2180. putchar(' ');
  2181. }
  2182. n -= r;
  2183. for (; m < 16; ++m)
  2184. putchar(' ');
  2185. printf("|\n");
  2186. if (nr < r)
  2187. break;
  2188. }
  2189. }
  2190. typedef int (*instruction_dump_func)(unsigned long inst, unsigned long addr);
  2191. static int
  2192. generic_inst_dump(unsigned long adr, long count, int praddr,
  2193. instruction_dump_func dump_func)
  2194. {
  2195. int nr, dotted;
  2196. unsigned long first_adr;
  2197. unsigned long inst, last_inst = 0;
  2198. unsigned char val[4];
  2199. dotted = 0;
  2200. for (first_adr = adr; count > 0; --count, adr += 4) {
  2201. nr = mread(adr, val, 4);
  2202. if (nr == 0) {
  2203. if (praddr) {
  2204. const char *x = fault_chars[fault_type];
  2205. printf(REG" %s%s%s%s\n", adr, x, x, x, x);
  2206. }
  2207. break;
  2208. }
  2209. inst = GETWORD(val);
  2210. if (adr > first_adr && inst == last_inst) {
  2211. if (!dotted) {
  2212. printf(" ...\n");
  2213. dotted = 1;
  2214. }
  2215. continue;
  2216. }
  2217. dotted = 0;
  2218. last_inst = inst;
  2219. if (praddr)
  2220. printf(REG" %.8x", adr, inst);
  2221. printf("\t");
  2222. dump_func(inst, adr);
  2223. printf("\n");
  2224. }
  2225. return adr - first_adr;
  2226. }
  2227. static int
  2228. ppc_inst_dump(unsigned long adr, long count, int praddr)
  2229. {
  2230. return generic_inst_dump(adr, count, praddr, print_insn_powerpc);
  2231. }
  2232. void
  2233. print_address(unsigned long addr)
  2234. {
  2235. xmon_print_symbol(addr, "\t# ", "");
  2236. }
  2237. void
  2238. dump_log_buf(void)
  2239. {
  2240. struct kmsg_dumper dumper = { .active = 1 };
  2241. unsigned char buf[128];
  2242. size_t len;
  2243. if (setjmp(bus_error_jmp) != 0) {
  2244. printf("Error dumping printk buffer!\n");
  2245. return;
  2246. }
  2247. catch_memory_errors = 1;
  2248. sync();
  2249. kmsg_dump_rewind_nolock(&dumper);
  2250. xmon_start_pagination();
  2251. while (kmsg_dump_get_line_nolock(&dumper, false, buf, sizeof(buf), &len)) {
  2252. buf[len] = '\0';
  2253. printf("%s", buf);
  2254. }
  2255. xmon_end_pagination();
  2256. sync();
  2257. /* wait a little while to see if we get a machine check */
  2258. __delay(200);
  2259. catch_memory_errors = 0;
  2260. }
  2261. #ifdef CONFIG_PPC_POWERNV
  2262. static void dump_opal_msglog(void)
  2263. {
  2264. unsigned char buf[128];
  2265. ssize_t res;
  2266. loff_t pos = 0;
  2267. if (!firmware_has_feature(FW_FEATURE_OPAL)) {
  2268. printf("Machine is not running OPAL firmware.\n");
  2269. return;
  2270. }
  2271. if (setjmp(bus_error_jmp) != 0) {
  2272. printf("Error dumping OPAL msglog!\n");
  2273. return;
  2274. }
  2275. catch_memory_errors = 1;
  2276. sync();
  2277. xmon_start_pagination();
  2278. while ((res = opal_msglog_copy(buf, pos, sizeof(buf) - 1))) {
  2279. if (res < 0) {
  2280. printf("Error dumping OPAL msglog! Error: %zd\n", res);
  2281. break;
  2282. }
  2283. buf[res] = '\0';
  2284. printf("%s", buf);
  2285. pos += res;
  2286. }
  2287. xmon_end_pagination();
  2288. sync();
  2289. /* wait a little while to see if we get a machine check */
  2290. __delay(200);
  2291. catch_memory_errors = 0;
  2292. }
  2293. #endif
  2294. /*
  2295. * Memory operations - move, set, print differences
  2296. */
  2297. static unsigned long mdest; /* destination address */
  2298. static unsigned long msrc; /* source address */
  2299. static unsigned long mval; /* byte value to set memory to */
  2300. static unsigned long mcount; /* # bytes to affect */
  2301. static unsigned long mdiffs; /* max # differences to print */
  2302. static void
  2303. memops(int cmd)
  2304. {
  2305. scanhex((void *)&mdest);
  2306. if( termch != '\n' )
  2307. termch = 0;
  2308. scanhex((void *)(cmd == 's'? &mval: &msrc));
  2309. if( termch != '\n' )
  2310. termch = 0;
  2311. scanhex((void *)&mcount);
  2312. switch( cmd ){
  2313. case 'm':
  2314. memmove((void *)mdest, (void *)msrc, mcount);
  2315. break;
  2316. case 's':
  2317. memset((void *)mdest, mval, mcount);
  2318. break;
  2319. case 'd':
  2320. if( termch != '\n' )
  2321. termch = 0;
  2322. scanhex((void *)&mdiffs);
  2323. memdiffs((unsigned char *)mdest, (unsigned char *)msrc, mcount, mdiffs);
  2324. break;
  2325. }
  2326. }
  2327. static void
  2328. memdiffs(unsigned char *p1, unsigned char *p2, unsigned nb, unsigned maxpr)
  2329. {
  2330. unsigned n, prt;
  2331. prt = 0;
  2332. for( n = nb; n > 0; --n )
  2333. if( *p1++ != *p2++ )
  2334. if( ++prt <= maxpr )
  2335. printf("%.16x %.2x # %.16x %.2x\n", p1 - 1,
  2336. p1[-1], p2 - 1, p2[-1]);
  2337. if( prt > maxpr )
  2338. printf("Total of %d differences\n", prt);
  2339. }
  2340. static unsigned mend;
  2341. static unsigned mask;
  2342. static void
  2343. memlocate(void)
  2344. {
  2345. unsigned a, n;
  2346. unsigned char val[4];
  2347. last_cmd = "ml";
  2348. scanhex((void *)&mdest);
  2349. if (termch != '\n') {
  2350. termch = 0;
  2351. scanhex((void *)&mend);
  2352. if (termch != '\n') {
  2353. termch = 0;
  2354. scanhex((void *)&mval);
  2355. mask = ~0;
  2356. if (termch != '\n') termch = 0;
  2357. scanhex((void *)&mask);
  2358. }
  2359. }
  2360. n = 0;
  2361. for (a = mdest; a < mend; a += 4) {
  2362. if (mread(a, val, 4) == 4
  2363. && ((GETWORD(val) ^ mval) & mask) == 0) {
  2364. printf("%.16x: %.16x\n", a, GETWORD(val));
  2365. if (++n >= 10)
  2366. break;
  2367. }
  2368. }
  2369. }
  2370. static unsigned long mskip = 0x1000;
  2371. static unsigned long mlim = 0xffffffff;
  2372. static void
  2373. memzcan(void)
  2374. {
  2375. unsigned char v;
  2376. unsigned a;
  2377. int ok, ook;
  2378. scanhex(&mdest);
  2379. if (termch != '\n') termch = 0;
  2380. scanhex(&mskip);
  2381. if (termch != '\n') termch = 0;
  2382. scanhex(&mlim);
  2383. ook = 0;
  2384. for (a = mdest; a < mlim; a += mskip) {
  2385. ok = mread(a, &v, 1);
  2386. if (ok && !ook) {
  2387. printf("%.8x .. ", a);
  2388. } else if (!ok && ook)
  2389. printf("%.8x\n", a - mskip);
  2390. ook = ok;
  2391. if (a + mskip < a)
  2392. break;
  2393. }
  2394. if (ook)
  2395. printf("%.8x\n", a - mskip);
  2396. }
  2397. static void show_task(struct task_struct *tsk)
  2398. {
  2399. char state;
  2400. /*
  2401. * Cloned from kdb_task_state_char(), which is not entirely
  2402. * appropriate for calling from xmon. This could be moved
  2403. * to a common, generic, routine used by both.
  2404. */
  2405. state = (tsk->state == 0) ? 'R' :
  2406. (tsk->state < 0) ? 'U' :
  2407. (tsk->state & TASK_UNINTERRUPTIBLE) ? 'D' :
  2408. (tsk->state & TASK_STOPPED) ? 'T' :
  2409. (tsk->state & TASK_TRACED) ? 'C' :
  2410. (tsk->exit_state & EXIT_ZOMBIE) ? 'Z' :
  2411. (tsk->exit_state & EXIT_DEAD) ? 'E' :
  2412. (tsk->state & TASK_INTERRUPTIBLE) ? 'S' : '?';
  2413. printf("%p %016lx %6d %6d %c %2d %s\n", tsk,
  2414. tsk->thread.ksp,
  2415. tsk->pid, tsk->parent->pid,
  2416. state, task_thread_info(tsk)->cpu,
  2417. tsk->comm);
  2418. }
  2419. static void show_tasks(void)
  2420. {
  2421. unsigned long tskv;
  2422. struct task_struct *tsk = NULL;
  2423. printf(" task_struct ->thread.ksp PID PPID S P CMD\n");
  2424. if (scanhex(&tskv))
  2425. tsk = (struct task_struct *)tskv;
  2426. if (setjmp(bus_error_jmp) != 0) {
  2427. catch_memory_errors = 0;
  2428. printf("*** Error dumping task %p\n", tsk);
  2429. return;
  2430. }
  2431. catch_memory_errors = 1;
  2432. sync();
  2433. if (tsk)
  2434. show_task(tsk);
  2435. else
  2436. for_each_process(tsk)
  2437. show_task(tsk);
  2438. sync();
  2439. __delay(200);
  2440. catch_memory_errors = 0;
  2441. }
  2442. static void proccall(void)
  2443. {
  2444. unsigned long args[8];
  2445. unsigned long ret;
  2446. int i;
  2447. typedef unsigned long (*callfunc_t)(unsigned long, unsigned long,
  2448. unsigned long, unsigned long, unsigned long,
  2449. unsigned long, unsigned long, unsigned long);
  2450. callfunc_t func;
  2451. if (!scanhex(&adrs))
  2452. return;
  2453. if (termch != '\n')
  2454. termch = 0;
  2455. for (i = 0; i < 8; ++i)
  2456. args[i] = 0;
  2457. for (i = 0; i < 8; ++i) {
  2458. if (!scanhex(&args[i]) || termch == '\n')
  2459. break;
  2460. termch = 0;
  2461. }
  2462. func = (callfunc_t) adrs;
  2463. ret = 0;
  2464. if (setjmp(bus_error_jmp) == 0) {
  2465. catch_memory_errors = 1;
  2466. sync();
  2467. ret = func(args[0], args[1], args[2], args[3],
  2468. args[4], args[5], args[6], args[7]);
  2469. sync();
  2470. printf("return value is 0x%lx\n", ret);
  2471. } else {
  2472. printf("*** %x exception occurred\n", fault_except);
  2473. }
  2474. catch_memory_errors = 0;
  2475. }
  2476. /* Input scanning routines */
  2477. int
  2478. skipbl(void)
  2479. {
  2480. int c;
  2481. if( termch != 0 ){
  2482. c = termch;
  2483. termch = 0;
  2484. } else
  2485. c = inchar();
  2486. while( c == ' ' || c == '\t' )
  2487. c = inchar();
  2488. return c;
  2489. }
  2490. #define N_PTREGS 44
  2491. static char *regnames[N_PTREGS] = {
  2492. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  2493. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  2494. "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
  2495. "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
  2496. "pc", "msr", "or3", "ctr", "lr", "xer", "ccr",
  2497. #ifdef CONFIG_PPC64
  2498. "softe",
  2499. #else
  2500. "mq",
  2501. #endif
  2502. "trap", "dar", "dsisr", "res"
  2503. };
  2504. int
  2505. scanhex(unsigned long *vp)
  2506. {
  2507. int c, d;
  2508. unsigned long v;
  2509. c = skipbl();
  2510. if (c == '%') {
  2511. /* parse register name */
  2512. char regname[8];
  2513. int i;
  2514. for (i = 0; i < sizeof(regname) - 1; ++i) {
  2515. c = inchar();
  2516. if (!isalnum(c)) {
  2517. termch = c;
  2518. break;
  2519. }
  2520. regname[i] = c;
  2521. }
  2522. regname[i] = 0;
  2523. for (i = 0; i < N_PTREGS; ++i) {
  2524. if (strcmp(regnames[i], regname) == 0) {
  2525. if (xmon_regs == NULL) {
  2526. printf("regs not available\n");
  2527. return 0;
  2528. }
  2529. *vp = ((unsigned long *)xmon_regs)[i];
  2530. return 1;
  2531. }
  2532. }
  2533. printf("invalid register name '%%%s'\n", regname);
  2534. return 0;
  2535. }
  2536. /* skip leading "0x" if any */
  2537. if (c == '0') {
  2538. c = inchar();
  2539. if (c == 'x') {
  2540. c = inchar();
  2541. } else {
  2542. d = hexdigit(c);
  2543. if (d == EOF) {
  2544. termch = c;
  2545. *vp = 0;
  2546. return 1;
  2547. }
  2548. }
  2549. } else if (c == '$') {
  2550. int i;
  2551. for (i=0; i<63; i++) {
  2552. c = inchar();
  2553. if (isspace(c) || c == '\0') {
  2554. termch = c;
  2555. break;
  2556. }
  2557. tmpstr[i] = c;
  2558. }
  2559. tmpstr[i++] = 0;
  2560. *vp = 0;
  2561. if (setjmp(bus_error_jmp) == 0) {
  2562. catch_memory_errors = 1;
  2563. sync();
  2564. *vp = kallsyms_lookup_name(tmpstr);
  2565. sync();
  2566. }
  2567. catch_memory_errors = 0;
  2568. if (!(*vp)) {
  2569. printf("unknown symbol '%s'\n", tmpstr);
  2570. return 0;
  2571. }
  2572. return 1;
  2573. }
  2574. d = hexdigit(c);
  2575. if (d == EOF) {
  2576. termch = c;
  2577. return 0;
  2578. }
  2579. v = 0;
  2580. do {
  2581. v = (v << 4) + d;
  2582. c = inchar();
  2583. d = hexdigit(c);
  2584. } while (d != EOF);
  2585. termch = c;
  2586. *vp = v;
  2587. return 1;
  2588. }
  2589. static void
  2590. scannl(void)
  2591. {
  2592. int c;
  2593. c = termch;
  2594. termch = 0;
  2595. while( c != '\n' )
  2596. c = inchar();
  2597. }
  2598. static int hexdigit(int c)
  2599. {
  2600. if( '0' <= c && c <= '9' )
  2601. return c - '0';
  2602. if( 'A' <= c && c <= 'F' )
  2603. return c - ('A' - 10);
  2604. if( 'a' <= c && c <= 'f' )
  2605. return c - ('a' - 10);
  2606. return EOF;
  2607. }
  2608. void
  2609. getstring(char *s, int size)
  2610. {
  2611. int c;
  2612. c = skipbl();
  2613. do {
  2614. if( size > 1 ){
  2615. *s++ = c;
  2616. --size;
  2617. }
  2618. c = inchar();
  2619. } while( c != ' ' && c != '\t' && c != '\n' );
  2620. termch = c;
  2621. *s = 0;
  2622. }
  2623. static char line[256];
  2624. static char *lineptr;
  2625. static void
  2626. flush_input(void)
  2627. {
  2628. lineptr = NULL;
  2629. }
  2630. static int
  2631. inchar(void)
  2632. {
  2633. if (lineptr == NULL || *lineptr == 0) {
  2634. if (xmon_gets(line, sizeof(line)) == NULL) {
  2635. lineptr = NULL;
  2636. return EOF;
  2637. }
  2638. lineptr = line;
  2639. }
  2640. return *lineptr++;
  2641. }
  2642. static void
  2643. take_input(char *str)
  2644. {
  2645. lineptr = str;
  2646. }
  2647. static void
  2648. symbol_lookup(void)
  2649. {
  2650. int type = inchar();
  2651. unsigned long addr;
  2652. static char tmp[64];
  2653. switch (type) {
  2654. case 'a':
  2655. if (scanhex(&addr))
  2656. xmon_print_symbol(addr, ": ", "\n");
  2657. termch = 0;
  2658. break;
  2659. case 's':
  2660. getstring(tmp, 64);
  2661. if (setjmp(bus_error_jmp) == 0) {
  2662. catch_memory_errors = 1;
  2663. sync();
  2664. addr = kallsyms_lookup_name(tmp);
  2665. if (addr)
  2666. printf("%s: %lx\n", tmp, addr);
  2667. else
  2668. printf("Symbol '%s' not found.\n", tmp);
  2669. sync();
  2670. }
  2671. catch_memory_errors = 0;
  2672. termch = 0;
  2673. break;
  2674. }
  2675. }
  2676. /* Print an address in numeric and symbolic form (if possible) */
  2677. static void xmon_print_symbol(unsigned long address, const char *mid,
  2678. const char *after)
  2679. {
  2680. char *modname;
  2681. const char *name = NULL;
  2682. unsigned long offset, size;
  2683. printf(REG, address);
  2684. if (setjmp(bus_error_jmp) == 0) {
  2685. catch_memory_errors = 1;
  2686. sync();
  2687. name = kallsyms_lookup(address, &size, &offset, &modname,
  2688. tmpstr);
  2689. sync();
  2690. /* wait a little while to see if we get a machine check */
  2691. __delay(200);
  2692. }
  2693. catch_memory_errors = 0;
  2694. if (name) {
  2695. printf("%s%s+%#lx/%#lx", mid, name, offset, size);
  2696. if (modname)
  2697. printf(" [%s]", modname);
  2698. }
  2699. printf("%s", after);
  2700. }
  2701. #ifdef CONFIG_PPC_STD_MMU_64
  2702. void dump_segments(void)
  2703. {
  2704. int i;
  2705. unsigned long esid,vsid;
  2706. unsigned long llp;
  2707. printf("SLB contents of cpu 0x%x\n", smp_processor_id());
  2708. for (i = 0; i < mmu_slb_size; i++) {
  2709. asm volatile("slbmfee %0,%1" : "=r" (esid) : "r" (i));
  2710. asm volatile("slbmfev %0,%1" : "=r" (vsid) : "r" (i));
  2711. if (esid || vsid) {
  2712. printf("%02d %016lx %016lx", i, esid, vsid);
  2713. if (esid & SLB_ESID_V) {
  2714. llp = vsid & SLB_VSID_LLP;
  2715. if (vsid & SLB_VSID_B_1T) {
  2716. printf(" 1T ESID=%9lx VSID=%13lx LLP:%3lx \n",
  2717. GET_ESID_1T(esid),
  2718. (vsid & ~SLB_VSID_B) >> SLB_VSID_SHIFT_1T,
  2719. llp);
  2720. } else {
  2721. printf(" 256M ESID=%9lx VSID=%13lx LLP:%3lx \n",
  2722. GET_ESID(esid),
  2723. (vsid & ~SLB_VSID_B) >> SLB_VSID_SHIFT,
  2724. llp);
  2725. }
  2726. } else
  2727. printf("\n");
  2728. }
  2729. }
  2730. }
  2731. #endif
  2732. #ifdef CONFIG_PPC_STD_MMU_32
  2733. void dump_segments(void)
  2734. {
  2735. int i;
  2736. printf("sr0-15 =");
  2737. for (i = 0; i < 16; ++i)
  2738. printf(" %x", mfsrin(i));
  2739. printf("\n");
  2740. }
  2741. #endif
  2742. #ifdef CONFIG_44x
  2743. static void dump_tlb_44x(void)
  2744. {
  2745. int i;
  2746. for (i = 0; i < PPC44x_TLB_SIZE; i++) {
  2747. unsigned long w0,w1,w2;
  2748. asm volatile("tlbre %0,%1,0" : "=r" (w0) : "r" (i));
  2749. asm volatile("tlbre %0,%1,1" : "=r" (w1) : "r" (i));
  2750. asm volatile("tlbre %0,%1,2" : "=r" (w2) : "r" (i));
  2751. printf("[%02x] %08x %08x %08x ", i, w0, w1, w2);
  2752. if (w0 & PPC44x_TLB_VALID) {
  2753. printf("V %08x -> %01x%08x %c%c%c%c%c",
  2754. w0 & PPC44x_TLB_EPN_MASK,
  2755. w1 & PPC44x_TLB_ERPN_MASK,
  2756. w1 & PPC44x_TLB_RPN_MASK,
  2757. (w2 & PPC44x_TLB_W) ? 'W' : 'w',
  2758. (w2 & PPC44x_TLB_I) ? 'I' : 'i',
  2759. (w2 & PPC44x_TLB_M) ? 'M' : 'm',
  2760. (w2 & PPC44x_TLB_G) ? 'G' : 'g',
  2761. (w2 & PPC44x_TLB_E) ? 'E' : 'e');
  2762. }
  2763. printf("\n");
  2764. }
  2765. }
  2766. #endif /* CONFIG_44x */
  2767. #ifdef CONFIG_PPC_BOOK3E
  2768. static void dump_tlb_book3e(void)
  2769. {
  2770. u32 mmucfg, pidmask, lpidmask;
  2771. u64 ramask;
  2772. int i, tlb, ntlbs, pidsz, lpidsz, rasz, lrat = 0;
  2773. int mmu_version;
  2774. static const char *pgsz_names[] = {
  2775. " 1K",
  2776. " 2K",
  2777. " 4K",
  2778. " 8K",
  2779. " 16K",
  2780. " 32K",
  2781. " 64K",
  2782. "128K",
  2783. "256K",
  2784. "512K",
  2785. " 1M",
  2786. " 2M",
  2787. " 4M",
  2788. " 8M",
  2789. " 16M",
  2790. " 32M",
  2791. " 64M",
  2792. "128M",
  2793. "256M",
  2794. "512M",
  2795. " 1G",
  2796. " 2G",
  2797. " 4G",
  2798. " 8G",
  2799. " 16G",
  2800. " 32G",
  2801. " 64G",
  2802. "128G",
  2803. "256G",
  2804. "512G",
  2805. " 1T",
  2806. " 2T",
  2807. };
  2808. /* Gather some infos about the MMU */
  2809. mmucfg = mfspr(SPRN_MMUCFG);
  2810. mmu_version = (mmucfg & 3) + 1;
  2811. ntlbs = ((mmucfg >> 2) & 3) + 1;
  2812. pidsz = ((mmucfg >> 6) & 0x1f) + 1;
  2813. lpidsz = (mmucfg >> 24) & 0xf;
  2814. rasz = (mmucfg >> 16) & 0x7f;
  2815. if ((mmu_version > 1) && (mmucfg & 0x10000))
  2816. lrat = 1;
  2817. printf("Book3E MMU MAV=%d.0,%d TLBs,%d-bit PID,%d-bit LPID,%d-bit RA\n",
  2818. mmu_version, ntlbs, pidsz, lpidsz, rasz);
  2819. pidmask = (1ul << pidsz) - 1;
  2820. lpidmask = (1ul << lpidsz) - 1;
  2821. ramask = (1ull << rasz) - 1;
  2822. for (tlb = 0; tlb < ntlbs; tlb++) {
  2823. u32 tlbcfg;
  2824. int nent, assoc, new_cc = 1;
  2825. printf("TLB %d:\n------\n", tlb);
  2826. switch(tlb) {
  2827. case 0:
  2828. tlbcfg = mfspr(SPRN_TLB0CFG);
  2829. break;
  2830. case 1:
  2831. tlbcfg = mfspr(SPRN_TLB1CFG);
  2832. break;
  2833. case 2:
  2834. tlbcfg = mfspr(SPRN_TLB2CFG);
  2835. break;
  2836. case 3:
  2837. tlbcfg = mfspr(SPRN_TLB3CFG);
  2838. break;
  2839. default:
  2840. printf("Unsupported TLB number !\n");
  2841. continue;
  2842. }
  2843. nent = tlbcfg & 0xfff;
  2844. assoc = (tlbcfg >> 24) & 0xff;
  2845. for (i = 0; i < nent; i++) {
  2846. u32 mas0 = MAS0_TLBSEL(tlb);
  2847. u32 mas1 = MAS1_TSIZE(BOOK3E_PAGESZ_4K);
  2848. u64 mas2 = 0;
  2849. u64 mas7_mas3;
  2850. int esel = i, cc = i;
  2851. if (assoc != 0) {
  2852. cc = i / assoc;
  2853. esel = i % assoc;
  2854. mas2 = cc * 0x1000;
  2855. }
  2856. mas0 |= MAS0_ESEL(esel);
  2857. mtspr(SPRN_MAS0, mas0);
  2858. mtspr(SPRN_MAS1, mas1);
  2859. mtspr(SPRN_MAS2, mas2);
  2860. asm volatile("tlbre 0,0,0" : : : "memory");
  2861. mas1 = mfspr(SPRN_MAS1);
  2862. mas2 = mfspr(SPRN_MAS2);
  2863. mas7_mas3 = mfspr(SPRN_MAS7_MAS3);
  2864. if (assoc && (i % assoc) == 0)
  2865. new_cc = 1;
  2866. if (!(mas1 & MAS1_VALID))
  2867. continue;
  2868. if (assoc == 0)
  2869. printf("%04x- ", i);
  2870. else if (new_cc)
  2871. printf("%04x-%c", cc, 'A' + esel);
  2872. else
  2873. printf(" |%c", 'A' + esel);
  2874. new_cc = 0;
  2875. printf(" %016llx %04x %s %c%c AS%c",
  2876. mas2 & ~0x3ffull,
  2877. (mas1 >> 16) & 0x3fff,
  2878. pgsz_names[(mas1 >> 7) & 0x1f],
  2879. mas1 & MAS1_IND ? 'I' : ' ',
  2880. mas1 & MAS1_IPROT ? 'P' : ' ',
  2881. mas1 & MAS1_TS ? '1' : '0');
  2882. printf(" %c%c%c%c%c%c%c",
  2883. mas2 & MAS2_X0 ? 'a' : ' ',
  2884. mas2 & MAS2_X1 ? 'v' : ' ',
  2885. mas2 & MAS2_W ? 'w' : ' ',
  2886. mas2 & MAS2_I ? 'i' : ' ',
  2887. mas2 & MAS2_M ? 'm' : ' ',
  2888. mas2 & MAS2_G ? 'g' : ' ',
  2889. mas2 & MAS2_E ? 'e' : ' ');
  2890. printf(" %016llx", mas7_mas3 & ramask & ~0x7ffull);
  2891. if (mas1 & MAS1_IND)
  2892. printf(" %s\n",
  2893. pgsz_names[(mas7_mas3 >> 1) & 0x1f]);
  2894. else
  2895. printf(" U%c%c%c S%c%c%c\n",
  2896. mas7_mas3 & MAS3_UX ? 'x' : ' ',
  2897. mas7_mas3 & MAS3_UW ? 'w' : ' ',
  2898. mas7_mas3 & MAS3_UR ? 'r' : ' ',
  2899. mas7_mas3 & MAS3_SX ? 'x' : ' ',
  2900. mas7_mas3 & MAS3_SW ? 'w' : ' ',
  2901. mas7_mas3 & MAS3_SR ? 'r' : ' ');
  2902. }
  2903. }
  2904. }
  2905. #endif /* CONFIG_PPC_BOOK3E */
  2906. static void xmon_init(int enable)
  2907. {
  2908. if (enable) {
  2909. __debugger = xmon;
  2910. __debugger_ipi = xmon_ipi;
  2911. __debugger_bpt = xmon_bpt;
  2912. __debugger_sstep = xmon_sstep;
  2913. __debugger_iabr_match = xmon_iabr_match;
  2914. __debugger_break_match = xmon_break_match;
  2915. __debugger_fault_handler = xmon_fault_handler;
  2916. } else {
  2917. __debugger = NULL;
  2918. __debugger_ipi = NULL;
  2919. __debugger_bpt = NULL;
  2920. __debugger_sstep = NULL;
  2921. __debugger_iabr_match = NULL;
  2922. __debugger_break_match = NULL;
  2923. __debugger_fault_handler = NULL;
  2924. }
  2925. }
  2926. #ifdef CONFIG_MAGIC_SYSRQ
  2927. static void sysrq_handle_xmon(int key)
  2928. {
  2929. /* ensure xmon is enabled */
  2930. xmon_init(1);
  2931. debugger(get_irq_regs());
  2932. }
  2933. static struct sysrq_key_op sysrq_xmon_op = {
  2934. .handler = sysrq_handle_xmon,
  2935. .help_msg = "xmon(x)",
  2936. .action_msg = "Entering xmon",
  2937. };
  2938. static int __init setup_xmon_sysrq(void)
  2939. {
  2940. register_sysrq_key('x', &sysrq_xmon_op);
  2941. return 0;
  2942. }
  2943. __initcall(setup_xmon_sysrq);
  2944. #endif /* CONFIG_MAGIC_SYSRQ */
  2945. static int __initdata xmon_early, xmon_off;
  2946. static int __init early_parse_xmon(char *p)
  2947. {
  2948. if (!p || strncmp(p, "early", 5) == 0) {
  2949. /* just "xmon" is equivalent to "xmon=early" */
  2950. xmon_init(1);
  2951. xmon_early = 1;
  2952. } else if (strncmp(p, "on", 2) == 0)
  2953. xmon_init(1);
  2954. else if (strncmp(p, "off", 3) == 0)
  2955. xmon_off = 1;
  2956. else if (strncmp(p, "nobt", 4) == 0)
  2957. xmon_no_auto_backtrace = 1;
  2958. else
  2959. return 1;
  2960. return 0;
  2961. }
  2962. early_param("xmon", early_parse_xmon);
  2963. void __init xmon_setup(void)
  2964. {
  2965. #ifdef CONFIG_XMON_DEFAULT
  2966. if (!xmon_off)
  2967. xmon_init(1);
  2968. #endif
  2969. if (xmon_early)
  2970. debugger(NULL);
  2971. }
  2972. #ifdef CONFIG_SPU_BASE
  2973. struct spu_info {
  2974. struct spu *spu;
  2975. u64 saved_mfc_sr1_RW;
  2976. u32 saved_spu_runcntl_RW;
  2977. unsigned long dump_addr;
  2978. u8 stopped_ok;
  2979. };
  2980. #define XMON_NUM_SPUS 16 /* Enough for current hardware */
  2981. static struct spu_info spu_info[XMON_NUM_SPUS];
  2982. void xmon_register_spus(struct list_head *list)
  2983. {
  2984. struct spu *spu;
  2985. list_for_each_entry(spu, list, full_list) {
  2986. if (spu->number >= XMON_NUM_SPUS) {
  2987. WARN_ON(1);
  2988. continue;
  2989. }
  2990. spu_info[spu->number].spu = spu;
  2991. spu_info[spu->number].stopped_ok = 0;
  2992. spu_info[spu->number].dump_addr = (unsigned long)
  2993. spu_info[spu->number].spu->local_store;
  2994. }
  2995. }
  2996. static void stop_spus(void)
  2997. {
  2998. struct spu *spu;
  2999. int i;
  3000. u64 tmp;
  3001. for (i = 0; i < XMON_NUM_SPUS; i++) {
  3002. if (!spu_info[i].spu)
  3003. continue;
  3004. if (setjmp(bus_error_jmp) == 0) {
  3005. catch_memory_errors = 1;
  3006. sync();
  3007. spu = spu_info[i].spu;
  3008. spu_info[i].saved_spu_runcntl_RW =
  3009. in_be32(&spu->problem->spu_runcntl_RW);
  3010. tmp = spu_mfc_sr1_get(spu);
  3011. spu_info[i].saved_mfc_sr1_RW = tmp;
  3012. tmp &= ~MFC_STATE1_MASTER_RUN_CONTROL_MASK;
  3013. spu_mfc_sr1_set(spu, tmp);
  3014. sync();
  3015. __delay(200);
  3016. spu_info[i].stopped_ok = 1;
  3017. printf("Stopped spu %.2d (was %s)\n", i,
  3018. spu_info[i].saved_spu_runcntl_RW ?
  3019. "running" : "stopped");
  3020. } else {
  3021. catch_memory_errors = 0;
  3022. printf("*** Error stopping spu %.2d\n", i);
  3023. }
  3024. catch_memory_errors = 0;
  3025. }
  3026. }
  3027. static void restart_spus(void)
  3028. {
  3029. struct spu *spu;
  3030. int i;
  3031. for (i = 0; i < XMON_NUM_SPUS; i++) {
  3032. if (!spu_info[i].spu)
  3033. continue;
  3034. if (!spu_info[i].stopped_ok) {
  3035. printf("*** Error, spu %d was not successfully stopped"
  3036. ", not restarting\n", i);
  3037. continue;
  3038. }
  3039. if (setjmp(bus_error_jmp) == 0) {
  3040. catch_memory_errors = 1;
  3041. sync();
  3042. spu = spu_info[i].spu;
  3043. spu_mfc_sr1_set(spu, spu_info[i].saved_mfc_sr1_RW);
  3044. out_be32(&spu->problem->spu_runcntl_RW,
  3045. spu_info[i].saved_spu_runcntl_RW);
  3046. sync();
  3047. __delay(200);
  3048. printf("Restarted spu %.2d\n", i);
  3049. } else {
  3050. catch_memory_errors = 0;
  3051. printf("*** Error restarting spu %.2d\n", i);
  3052. }
  3053. catch_memory_errors = 0;
  3054. }
  3055. }
  3056. #define DUMP_WIDTH 23
  3057. #define DUMP_VALUE(format, field, value) \
  3058. do { \
  3059. if (setjmp(bus_error_jmp) == 0) { \
  3060. catch_memory_errors = 1; \
  3061. sync(); \
  3062. printf(" %-*s = "format"\n", DUMP_WIDTH, \
  3063. #field, value); \
  3064. sync(); \
  3065. __delay(200); \
  3066. } else { \
  3067. catch_memory_errors = 0; \
  3068. printf(" %-*s = *** Error reading field.\n", \
  3069. DUMP_WIDTH, #field); \
  3070. } \
  3071. catch_memory_errors = 0; \
  3072. } while (0)
  3073. #define DUMP_FIELD(obj, format, field) \
  3074. DUMP_VALUE(format, field, obj->field)
  3075. static void dump_spu_fields(struct spu *spu)
  3076. {
  3077. printf("Dumping spu fields at address %p:\n", spu);
  3078. DUMP_FIELD(spu, "0x%x", number);
  3079. DUMP_FIELD(spu, "%s", name);
  3080. DUMP_FIELD(spu, "0x%lx", local_store_phys);
  3081. DUMP_FIELD(spu, "0x%p", local_store);
  3082. DUMP_FIELD(spu, "0x%lx", ls_size);
  3083. DUMP_FIELD(spu, "0x%x", node);
  3084. DUMP_FIELD(spu, "0x%lx", flags);
  3085. DUMP_FIELD(spu, "%d", class_0_pending);
  3086. DUMP_FIELD(spu, "0x%lx", class_0_dar);
  3087. DUMP_FIELD(spu, "0x%lx", class_1_dar);
  3088. DUMP_FIELD(spu, "0x%lx", class_1_dsisr);
  3089. DUMP_FIELD(spu, "0x%lx", irqs[0]);
  3090. DUMP_FIELD(spu, "0x%lx", irqs[1]);
  3091. DUMP_FIELD(spu, "0x%lx", irqs[2]);
  3092. DUMP_FIELD(spu, "0x%x", slb_replace);
  3093. DUMP_FIELD(spu, "%d", pid);
  3094. DUMP_FIELD(spu, "0x%p", mm);
  3095. DUMP_FIELD(spu, "0x%p", ctx);
  3096. DUMP_FIELD(spu, "0x%p", rq);
  3097. DUMP_FIELD(spu, "0x%p", timestamp);
  3098. DUMP_FIELD(spu, "0x%lx", problem_phys);
  3099. DUMP_FIELD(spu, "0x%p", problem);
  3100. DUMP_VALUE("0x%x", problem->spu_runcntl_RW,
  3101. in_be32(&spu->problem->spu_runcntl_RW));
  3102. DUMP_VALUE("0x%x", problem->spu_status_R,
  3103. in_be32(&spu->problem->spu_status_R));
  3104. DUMP_VALUE("0x%x", problem->spu_npc_RW,
  3105. in_be32(&spu->problem->spu_npc_RW));
  3106. DUMP_FIELD(spu, "0x%p", priv2);
  3107. DUMP_FIELD(spu, "0x%p", pdata);
  3108. }
  3109. int
  3110. spu_inst_dump(unsigned long adr, long count, int praddr)
  3111. {
  3112. return generic_inst_dump(adr, count, praddr, print_insn_spu);
  3113. }
  3114. static void dump_spu_ls(unsigned long num, int subcmd)
  3115. {
  3116. unsigned long offset, addr, ls_addr;
  3117. if (setjmp(bus_error_jmp) == 0) {
  3118. catch_memory_errors = 1;
  3119. sync();
  3120. ls_addr = (unsigned long)spu_info[num].spu->local_store;
  3121. sync();
  3122. __delay(200);
  3123. } else {
  3124. catch_memory_errors = 0;
  3125. printf("*** Error: accessing spu info for spu %d\n", num);
  3126. return;
  3127. }
  3128. catch_memory_errors = 0;
  3129. if (scanhex(&offset))
  3130. addr = ls_addr + offset;
  3131. else
  3132. addr = spu_info[num].dump_addr;
  3133. if (addr >= ls_addr + LS_SIZE) {
  3134. printf("*** Error: address outside of local store\n");
  3135. return;
  3136. }
  3137. switch (subcmd) {
  3138. case 'i':
  3139. addr += spu_inst_dump(addr, 16, 1);
  3140. last_cmd = "sdi\n";
  3141. break;
  3142. default:
  3143. prdump(addr, 64);
  3144. addr += 64;
  3145. last_cmd = "sd\n";
  3146. break;
  3147. }
  3148. spu_info[num].dump_addr = addr;
  3149. }
  3150. static int do_spu_cmd(void)
  3151. {
  3152. static unsigned long num = 0;
  3153. int cmd, subcmd = 0;
  3154. cmd = inchar();
  3155. switch (cmd) {
  3156. case 's':
  3157. stop_spus();
  3158. break;
  3159. case 'r':
  3160. restart_spus();
  3161. break;
  3162. case 'd':
  3163. subcmd = inchar();
  3164. if (isxdigit(subcmd) || subcmd == '\n')
  3165. termch = subcmd;
  3166. case 'f':
  3167. scanhex(&num);
  3168. if (num >= XMON_NUM_SPUS || !spu_info[num].spu) {
  3169. printf("*** Error: invalid spu number\n");
  3170. return 0;
  3171. }
  3172. switch (cmd) {
  3173. case 'f':
  3174. dump_spu_fields(spu_info[num].spu);
  3175. break;
  3176. default:
  3177. dump_spu_ls(num, subcmd);
  3178. break;
  3179. }
  3180. break;
  3181. default:
  3182. return -1;
  3183. }
  3184. return 0;
  3185. }
  3186. #else /* ! CONFIG_SPU_BASE */
  3187. static int do_spu_cmd(void)
  3188. {
  3189. return -1;
  3190. }
  3191. #endif