xmon.c 69 KB

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