xmon.c 86 KB

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