xmon.c 69 KB

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