xmon.c 76 KB

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