xmon.c 69 KB

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