xmon.c 75 KB

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