xmon.c 84 KB

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