start.S 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974
  1. /*
  2. * Copyright 2004, 2007-2012 Freescale Semiconductor, Inc.
  3. * Copyright (C) 2003 Motorola,Inc.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /* U-Boot Startup Code for Motorola 85xx PowerPC based Embedded Boards
  8. *
  9. * The processor starts at 0xfffffffc and the code is first executed in the
  10. * last 4K page(0xfffff000-0xffffffff) in flash/rom.
  11. *
  12. */
  13. #include <asm-offsets.h>
  14. #include <config.h>
  15. #include <mpc85xx.h>
  16. #include <version.h>
  17. #include <ppc_asm.tmpl>
  18. #include <ppc_defs.h>
  19. #include <asm/cache.h>
  20. #include <asm/mmu.h>
  21. #undef MSR_KERNEL
  22. #define MSR_KERNEL ( MSR_ME ) /* Machine Check */
  23. #if defined(CONFIG_NAND_SPL) || \
  24. (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_INIT_MINIMAL))
  25. #define MINIMAL_SPL
  26. #endif
  27. #if !defined(CONFIG_SPL) && !defined(CONFIG_SYS_RAMBOOT) && \
  28. !defined(CONFIG_SECURE_BOOT) && !defined(CONFIG_SRIO_PCIE_BOOT_SLAVE)
  29. #define NOR_BOOT
  30. #endif
  31. /*
  32. * Set up GOT: Global Offset Table
  33. *
  34. * Use r12 to access the GOT
  35. */
  36. START_GOT
  37. GOT_ENTRY(_GOT2_TABLE_)
  38. GOT_ENTRY(_FIXUP_TABLE_)
  39. #ifndef MINIMAL_SPL
  40. GOT_ENTRY(_start)
  41. GOT_ENTRY(_start_of_vectors)
  42. GOT_ENTRY(_end_of_vectors)
  43. GOT_ENTRY(transfer_to_handler)
  44. #endif
  45. GOT_ENTRY(__init_end)
  46. GOT_ENTRY(__bss_end)
  47. GOT_ENTRY(__bss_start)
  48. END_GOT
  49. /*
  50. * e500 Startup -- after reset only the last 4KB of the effective
  51. * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
  52. * section is located at THIS LAST page and basically does three
  53. * things: clear some registers, set up exception tables and
  54. * add more TLB entries for 'larger spaces'(e.g. the boot rom) to
  55. * continue the boot procedure.
  56. * Once the boot rom is mapped by TLB entries we can proceed
  57. * with normal startup.
  58. *
  59. */
  60. .section .bootpg,"ax"
  61. .globl _start_e500
  62. _start_e500:
  63. /* Enable debug exception */
  64. li r1,MSR_DE
  65. mtmsr r1
  66. #ifdef CONFIG_SYS_FSL_ERRATUM_A004510
  67. mfspr r3,SPRN_SVR
  68. rlwinm r3,r3,0,0xff
  69. li r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV
  70. cmpw r3,r4
  71. beq 1f
  72. #ifdef CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
  73. li r4,CONFIG_SYS_FSL_ERRATUM_A004510_SVR_REV2
  74. cmpw r3,r4
  75. beq 1f
  76. #endif
  77. /* Not a supported revision affected by erratum */
  78. li r27,0
  79. b 2f
  80. 1: li r27,1 /* Remember for later that we have the erratum */
  81. /* Erratum says set bits 55:60 to 001001 */
  82. msync
  83. isync
  84. mfspr r3,SPRN_HDBCR0
  85. li r4,0x48
  86. rlwimi r3,r4,0,0x1f8
  87. mtspr SPRN_HDBCR0,r3
  88. isync
  89. 2:
  90. #endif
  91. #ifdef CONFIG_SYS_FSL_ERRATUM_A005125
  92. msync
  93. isync
  94. mfspr r3, SPRN_HDBCR0
  95. oris r3, r3, 0x0080
  96. mtspr SPRN_HDBCR0, r3
  97. #endif
  98. #if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_E500MC)
  99. /* ISBC uses L2 as stack.
  100. * Disable L2 cache here so that u-boot can enable it later
  101. * as part of it's normal flow
  102. */
  103. /* Check if L2 is enabled */
  104. mfspr r3, SPRN_L2CSR0
  105. lis r2, L2CSR0_L2E@h
  106. ori r2, r2, L2CSR0_L2E@l
  107. and. r4, r3, r2
  108. beq l2_disabled
  109. mfspr r3, SPRN_L2CSR0
  110. /* Flush L2 cache */
  111. lis r2,(L2CSR0_L2FL)@h
  112. ori r2, r2, (L2CSR0_L2FL)@l
  113. or r3, r2, r3
  114. sync
  115. isync
  116. mtspr SPRN_L2CSR0,r3
  117. isync
  118. 1:
  119. mfspr r3, SPRN_L2CSR0
  120. and. r1, r3, r2
  121. bne 1b
  122. mfspr r3, SPRN_L2CSR0
  123. lis r2, L2CSR0_L2E@h
  124. ori r2, r2, L2CSR0_L2E@l
  125. andc r4, r3, r2
  126. sync
  127. isync
  128. mtspr SPRN_L2CSR0,r4
  129. isync
  130. l2_disabled:
  131. #endif
  132. /* clear registers/arrays not reset by hardware */
  133. /* L1 */
  134. li r0,2
  135. mtspr L1CSR0,r0 /* invalidate d-cache */
  136. mtspr L1CSR1,r0 /* invalidate i-cache */
  137. mfspr r1,DBSR
  138. mtspr DBSR,r1 /* Clear all valid bits */
  139. .macro create_tlb1_entry esel ts tsize epn wimg rpn perm phy_high scratch
  140. lis \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@h
  141. ori \scratch, \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@l
  142. mtspr MAS0, \scratch
  143. lis \scratch, FSL_BOOKE_MAS1(1, 1, 0, \ts, \tsize)@h
  144. ori \scratch, \scratch, FSL_BOOKE_MAS1(1, 1, 0, \ts, \tsize)@l
  145. mtspr MAS1, \scratch
  146. lis \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@h
  147. ori \scratch, \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@l
  148. mtspr MAS2, \scratch
  149. lis \scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@h
  150. ori \scratch, \scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@l
  151. mtspr MAS3, \scratch
  152. lis \scratch, \phy_high@h
  153. ori \scratch, \scratch, \phy_high@l
  154. mtspr MAS7, \scratch
  155. isync
  156. msync
  157. tlbwe
  158. isync
  159. .endm
  160. .macro create_tlb0_entry esel ts tsize epn wimg rpn perm phy_high scratch
  161. lis \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@h
  162. ori \scratch, \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@l
  163. mtspr MAS0, \scratch
  164. lis \scratch, FSL_BOOKE_MAS1(1, 0, 0, \ts, \tsize)@h
  165. ori \scratch, \scratch, FSL_BOOKE_MAS1(1, 0, 0, \ts, \tsize)@l
  166. mtspr MAS1, \scratch
  167. lis \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@h
  168. ori \scratch, \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@l
  169. mtspr MAS2, \scratch
  170. lis \scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@h
  171. ori \scratch, \scratch, FSL_BOOKE_MAS3(\rpn, 0, \perm)@l
  172. mtspr MAS3, \scratch
  173. lis \scratch, \phy_high@h
  174. ori \scratch, \scratch, \phy_high@l
  175. mtspr MAS7, \scratch
  176. isync
  177. msync
  178. tlbwe
  179. isync
  180. .endm
  181. .macro delete_tlb1_entry esel scratch
  182. lis \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@h
  183. ori \scratch, \scratch, FSL_BOOKE_MAS0(1, \esel, 0)@l
  184. mtspr MAS0, \scratch
  185. li \scratch, 0
  186. mtspr MAS1, \scratch
  187. isync
  188. msync
  189. tlbwe
  190. isync
  191. .endm
  192. .macro delete_tlb0_entry esel epn wimg scratch
  193. lis \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@h
  194. ori \scratch, \scratch, FSL_BOOKE_MAS0(0, \esel, 0)@l
  195. mtspr MAS0, \scratch
  196. li \scratch, 0
  197. mtspr MAS1, \scratch
  198. lis \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@h
  199. ori \scratch, \scratch, FSL_BOOKE_MAS2(\epn, \wimg)@l
  200. mtspr MAS2, \scratch
  201. isync
  202. msync
  203. tlbwe
  204. isync
  205. .endm
  206. /* Interrupt vectors do not fit in minimal SPL. */
  207. #if !defined(MINIMAL_SPL)
  208. /* Setup interrupt vectors */
  209. lis r1,CONFIG_SYS_MONITOR_BASE@h
  210. mtspr IVPR,r1
  211. lis r3,(CONFIG_SYS_MONITOR_BASE & 0xffff)@h
  212. ori r3,r3,(CONFIG_SYS_MONITOR_BASE & 0xffff)@l
  213. addi r4,r3,CriticalInput - _start + _START_OFFSET
  214. mtspr IVOR0,r4 /* 0: Critical input */
  215. addi r4,r3,MachineCheck - _start + _START_OFFSET
  216. mtspr IVOR1,r4 /* 1: Machine check */
  217. addi r4,r3,DataStorage - _start + _START_OFFSET
  218. mtspr IVOR2,r4 /* 2: Data storage */
  219. addi r4,r3,InstStorage - _start + _START_OFFSET
  220. mtspr IVOR3,r4 /* 3: Instruction storage */
  221. addi r4,r3,ExtInterrupt - _start + _START_OFFSET
  222. mtspr IVOR4,r4 /* 4: External interrupt */
  223. addi r4,r3,Alignment - _start + _START_OFFSET
  224. mtspr IVOR5,r4 /* 5: Alignment */
  225. addi r4,r3,ProgramCheck - _start + _START_OFFSET
  226. mtspr IVOR6,r4 /* 6: Program check */
  227. addi r4,r3,FPUnavailable - _start + _START_OFFSET
  228. mtspr IVOR7,r4 /* 7: floating point unavailable */
  229. addi r4,r3,SystemCall - _start + _START_OFFSET
  230. mtspr IVOR8,r4 /* 8: System call */
  231. /* 9: Auxiliary processor unavailable(unsupported) */
  232. addi r4,r3,Decrementer - _start + _START_OFFSET
  233. mtspr IVOR10,r4 /* 10: Decrementer */
  234. addi r4,r3,IntervalTimer - _start + _START_OFFSET
  235. mtspr IVOR11,r4 /* 11: Interval timer */
  236. addi r4,r3,WatchdogTimer - _start + _START_OFFSET
  237. mtspr IVOR12,r4 /* 12: Watchdog timer */
  238. addi r4,r3,DataTLBError - _start + _START_OFFSET
  239. mtspr IVOR13,r4 /* 13: Data TLB error */
  240. addi r4,r3,InstructionTLBError - _start + _START_OFFSET
  241. mtspr IVOR14,r4 /* 14: Instruction TLB error */
  242. addi r4,r3,DebugBreakpoint - _start + _START_OFFSET
  243. mtspr IVOR15,r4 /* 15: Debug */
  244. #endif
  245. /* Clear and set up some registers. */
  246. li r0,0x0000
  247. lis r1,0xffff
  248. mtspr DEC,r0 /* prevent dec exceptions */
  249. mttbl r0 /* prevent fit & wdt exceptions */
  250. mttbu r0
  251. mtspr TSR,r1 /* clear all timer exception status */
  252. mtspr TCR,r0 /* disable all */
  253. mtspr ESR,r0 /* clear exception syndrome register */
  254. mtspr MCSR,r0 /* machine check syndrome register */
  255. mtxer r0 /* clear integer exception register */
  256. #ifdef CONFIG_SYS_BOOK3E_HV
  257. mtspr MAS8,r0 /* make sure MAS8 is clear */
  258. #endif
  259. /* Enable Time Base and Select Time Base Clock */
  260. lis r0,HID0_EMCP@h /* Enable machine check */
  261. #if defined(CONFIG_ENABLE_36BIT_PHYS)
  262. ori r0,r0,HID0_ENMAS7@l /* Enable MAS7 */
  263. #endif
  264. #ifndef CONFIG_E500MC
  265. ori r0,r0,HID0_TBEN@l /* Enable Timebase */
  266. #endif
  267. mtspr HID0,r0
  268. #ifndef CONFIG_E500MC
  269. li r0,(HID1_ASTME|HID1_ABE)@l /* Addr streaming & broadcast */
  270. mfspr r3,PVR
  271. andi. r3,r3, 0xff
  272. cmpwi r3,0x50@l /* if we are rev 5.0 or greater set MBDD */
  273. blt 1f
  274. /* Set MBDD bit also */
  275. ori r0, r0, HID1_MBDD@l
  276. 1:
  277. mtspr HID1,r0
  278. #endif
  279. #ifdef CONFIG_SYS_FSL_ERRATUM_CPU_A003999
  280. mfspr r3,SPRN_HDBCR1
  281. oris r3,r3,0x0100
  282. mtspr SPRN_HDBCR1,r3
  283. #endif
  284. /* Enable Branch Prediction */
  285. #if defined(CONFIG_BTB)
  286. lis r0,BUCSR_ENABLE@h
  287. ori r0,r0,BUCSR_ENABLE@l
  288. mtspr SPRN_BUCSR,r0
  289. #endif
  290. #if defined(CONFIG_SYS_INIT_DBCR)
  291. lis r1,0xffff
  292. ori r1,r1,0xffff
  293. mtspr DBSR,r1 /* Clear all status bits */
  294. lis r0,CONFIG_SYS_INIT_DBCR@h /* DBCR0[IDM] must be set */
  295. ori r0,r0,CONFIG_SYS_INIT_DBCR@l
  296. mtspr DBCR0,r0
  297. #endif
  298. #ifdef CONFIG_MPC8569
  299. #define CONFIG_SYS_LBC_ADDR (CONFIG_SYS_CCSRBAR_DEFAULT + 0x5000)
  300. #define CONFIG_SYS_LBCR_ADDR (CONFIG_SYS_LBC_ADDR + 0xd0)
  301. /* MPC8569 Rev.0 silcon needs to set bit 13 of LBCR to allow elBC to
  302. * use address space which is more than 12bits, and it must be done in
  303. * the 4K boot page. So we set this bit here.
  304. */
  305. /* create a temp mapping TLB0[0] for LBCR */
  306. create_tlb0_entry 0, \
  307. 0, BOOKE_PAGESZ_4K, \
  308. CONFIG_SYS_LBC_ADDR, MAS2_I|MAS2_G, \
  309. CONFIG_SYS_LBC_ADDR, MAS3_SW|MAS3_SR, \
  310. 0, r6
  311. /* Set LBCR register */
  312. lis r4,CONFIG_SYS_LBCR_ADDR@h
  313. ori r4,r4,CONFIG_SYS_LBCR_ADDR@l
  314. lis r5,CONFIG_SYS_LBC_LBCR@h
  315. ori r5,r5,CONFIG_SYS_LBC_LBCR@l
  316. stw r5,0(r4)
  317. isync
  318. /* invalidate this temp TLB */
  319. lis r4,CONFIG_SYS_LBC_ADDR@h
  320. ori r4,r4,CONFIG_SYS_LBC_ADDR@l
  321. tlbivax 0,r4
  322. isync
  323. #endif /* CONFIG_MPC8569 */
  324. /*
  325. * Search for the TLB that covers the code we're executing, and shrink it
  326. * so that it covers only this 4K page. That will ensure that any other
  327. * TLB we create won't interfere with it. We assume that the TLB exists,
  328. * which is why we don't check the Valid bit of MAS1. We also assume
  329. * it is in TLB1.
  330. *
  331. * This is necessary, for example, when booting from the on-chip ROM,
  332. * which (oddly) creates a single 4GB TLB that covers CCSR and DDR.
  333. */
  334. bl nexti /* Find our address */
  335. nexti: mflr r1 /* R1 = our PC */
  336. li r2, 0
  337. mtspr MAS6, r2 /* Assume the current PID and AS are 0 */
  338. isync
  339. msync
  340. tlbsx 0, r1 /* This must succeed */
  341. mfspr r14, MAS0 /* Save ESEL for later */
  342. rlwinm r14, r14, 16, 0xfff
  343. /* Set the size of the TLB to 4KB */
  344. mfspr r3, MAS1
  345. li r2, 0xF80
  346. andc r3, r3, r2 /* Clear the TSIZE bits */
  347. ori r3, r3, MAS1_TSIZE(BOOKE_PAGESZ_4K)@l
  348. oris r3, r3, MAS1_IPROT@h
  349. mtspr MAS1, r3
  350. /*
  351. * Set the base address of the TLB to our PC. We assume that
  352. * virtual == physical. We also assume that MAS2_EPN == MAS3_RPN.
  353. */
  354. lis r3, MAS2_EPN@h
  355. ori r3, r3, MAS2_EPN@l /* R3 = MAS2_EPN */
  356. and r1, r1, r3 /* Our PC, rounded down to the nearest page */
  357. mfspr r2, MAS2
  358. andc r2, r2, r3
  359. or r2, r2, r1
  360. #ifdef CONFIG_SYS_FSL_ERRATUM_A004510
  361. cmpwi r27,0
  362. beq 1f
  363. andi. r15, r2, MAS2_I|MAS2_G /* save the old I/G for later */
  364. rlwinm r2, r2, 0, ~MAS2_I
  365. ori r2, r2, MAS2_G
  366. 1:
  367. #endif
  368. mtspr MAS2, r2 /* Set the EPN to our PC base address */
  369. mfspr r2, MAS3
  370. andc r2, r2, r3
  371. or r2, r2, r1
  372. mtspr MAS3, r2 /* Set the RPN to our PC base address */
  373. isync
  374. msync
  375. tlbwe
  376. /*
  377. * Clear out any other TLB entries that may exist, to avoid conflicts.
  378. * Our TLB entry is in r14.
  379. */
  380. li r0, TLBIVAX_ALL | TLBIVAX_TLB0
  381. tlbivax 0, r0
  382. tlbsync
  383. mfspr r4, SPRN_TLB1CFG
  384. rlwinm r4, r4, 0, TLBnCFG_NENTRY_MASK
  385. li r3, 0
  386. mtspr MAS1, r3
  387. 1: cmpw r3, r14
  388. rlwinm r5, r3, 16, MAS0_ESEL_MSK
  389. addi r3, r3, 1
  390. beq 2f /* skip the entry we're executing from */
  391. oris r5, r5, MAS0_TLBSEL(1)@h
  392. mtspr MAS0, r5
  393. isync
  394. tlbwe
  395. isync
  396. msync
  397. 2: cmpw r3, r4
  398. blt 1b
  399. #if defined(CONFIG_SYS_PPC_E500_DEBUG_TLB) && !defined(MINIMAL_SPL)
  400. /*
  401. * TLB entry for debuggging in AS1
  402. * Create temporary TLB entry in AS0 to handle debug exception
  403. * As on debug exception MSR is cleared i.e. Address space is changed
  404. * to 0. A TLB entry (in AS0) is required to handle debug exception generated
  405. * in AS1.
  406. */
  407. #ifdef NOR_BOOT
  408. /*
  409. * TLB entry is created for IVPR + IVOR15 to map on valid OP code address
  410. * bacause flash's virtual address maps to 0xff800000 - 0xffffffff.
  411. * and this window is outside of 4K boot window.
  412. */
  413. create_tlb1_entry CONFIG_SYS_PPC_E500_DEBUG_TLB, \
  414. 0, BOOKE_PAGESZ_4M, \
  415. CONFIG_SYS_MONITOR_BASE & 0xffc00000, MAS2_I|MAS2_G, \
  416. 0xffc00000, MAS3_SX|MAS3_SW|MAS3_SR, \
  417. 0, r6
  418. #elif !defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SECURE_BOOT)
  419. create_tlb1_entry CONFIG_SYS_PPC_E500_DEBUG_TLB, \
  420. 0, BOOKE_PAGESZ_1M, \
  421. CONFIG_SYS_MONITOR_BASE, MAS2_I|MAS2_G, \
  422. CONFIG_SYS_PBI_FLASH_WINDOW, MAS3_SX|MAS3_SW|MAS3_SR, \
  423. 0, r6
  424. #else
  425. /*
  426. * TLB entry is created for IVPR + IVOR15 to map on valid OP code address
  427. * because "nexti" will resize TLB to 4K
  428. */
  429. create_tlb1_entry CONFIG_SYS_PPC_E500_DEBUG_TLB, \
  430. 0, BOOKE_PAGESZ_256K, \
  431. CONFIG_SYS_MONITOR_BASE & 0xfffc0000, MAS2_I, \
  432. CONFIG_SYS_MONITOR_BASE & 0xfffc0000, MAS3_SX|MAS3_SW|MAS3_SR, \
  433. 0, r6
  434. #endif
  435. #endif
  436. /*
  437. * Relocate CCSR, if necessary. We relocate CCSR if (obviously) the default
  438. * location is not where we want it. This typically happens on a 36-bit
  439. * system, where we want to move CCSR to near the top of 36-bit address space.
  440. *
  441. * To move CCSR, we create two temporary TLBs, one for the old location, and
  442. * another for the new location. On CoreNet systems, we also need to create
  443. * a special, temporary LAW.
  444. *
  445. * As a general rule, TLB0 is used for short-term TLBs, and TLB1 is used for
  446. * long-term TLBs, so we use TLB0 here.
  447. */
  448. #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS)
  449. #if !defined(CONFIG_SYS_CCSRBAR_PHYS_HIGH) || !defined(CONFIG_SYS_CCSRBAR_PHYS_LOW)
  450. #error "CONFIG_SYS_CCSRBAR_PHYS_HIGH and CONFIG_SYS_CCSRBAR_PHYS_LOW) must be defined."
  451. #endif
  452. create_ccsr_new_tlb:
  453. /*
  454. * Create a TLB for the new location of CCSR. Register R8 is reserved
  455. * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR).
  456. */
  457. lis r8, CONFIG_SYS_CCSRBAR@h
  458. ori r8, r8, CONFIG_SYS_CCSRBAR@l
  459. lis r9, (CONFIG_SYS_CCSRBAR + 0x1000)@h
  460. ori r9, r9, (CONFIG_SYS_CCSRBAR + 0x1000)@l
  461. create_tlb0_entry 0, \
  462. 0, BOOKE_PAGESZ_4K, \
  463. CONFIG_SYS_CCSRBAR, MAS2_I|MAS2_G, \
  464. CONFIG_SYS_CCSRBAR_PHYS_LOW, MAS3_SW|MAS3_SR, \
  465. CONFIG_SYS_CCSRBAR_PHYS_HIGH, r3
  466. /*
  467. * Create a TLB for the current location of CCSR. Register R9 is reserved
  468. * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR + 0x1000).
  469. */
  470. create_ccsr_old_tlb:
  471. create_tlb0_entry 1, \
  472. 0, BOOKE_PAGESZ_4K, \
  473. CONFIG_SYS_CCSRBAR + 0x1000, MAS2_I|MAS2_G, \
  474. CONFIG_SYS_CCSRBAR_DEFAULT, MAS3_SW|MAS3_SR, \
  475. 0, r3 /* The default CCSR address is always a 32-bit number */
  476. /*
  477. * We have a TLB for what we think is the current (old) CCSR. Let's
  478. * verify that, otherwise we won't be able to move it.
  479. * CONFIG_SYS_CCSRBAR_DEFAULT is always a 32-bit number, so we only
  480. * need to compare the lower 32 bits of CCSRBAR on CoreNet systems.
  481. */
  482. verify_old_ccsr:
  483. lis r0, CONFIG_SYS_CCSRBAR_DEFAULT@h
  484. ori r0, r0, CONFIG_SYS_CCSRBAR_DEFAULT@l
  485. #ifdef CONFIG_FSL_CORENET
  486. lwz r1, 4(r9) /* CCSRBARL */
  487. #else
  488. lwz r1, 0(r9) /* CCSRBAR, shifted right by 12 */
  489. slwi r1, r1, 12
  490. #endif
  491. cmpl 0, r0, r1
  492. /*
  493. * If the value we read from CCSRBARL is not what we expect, then
  494. * enter an infinite loop. This will at least allow a debugger to
  495. * halt execution and examine TLBs, etc. There's no point in going
  496. * on.
  497. */
  498. infinite_debug_loop:
  499. bne infinite_debug_loop
  500. #ifdef CONFIG_FSL_CORENET
  501. #define CCSR_LAWBARH0 (CONFIG_SYS_CCSRBAR + 0x1000)
  502. #define LAW_EN 0x80000000
  503. #define LAW_SIZE_4K 0xb
  504. #define CCSRBAR_LAWAR (LAW_EN | (0x1e << 20) | LAW_SIZE_4K)
  505. #define CCSRAR_C 0x80000000 /* Commit */
  506. create_temp_law:
  507. /*
  508. * On CoreNet systems, we create the temporary LAW using a special LAW
  509. * target ID of 0x1e. LAWBARH is at offset 0xc00 in CCSR.
  510. */
  511. lis r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
  512. ori r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
  513. lis r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
  514. ori r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
  515. lis r2, CCSRBAR_LAWAR@h
  516. ori r2, r2, CCSRBAR_LAWAR@l
  517. stw r0, 0xc00(r9) /* LAWBARH0 */
  518. stw r1, 0xc04(r9) /* LAWBARL0 */
  519. sync
  520. stw r2, 0xc08(r9) /* LAWAR0 */
  521. /*
  522. * Read back from LAWAR to ensure the update is complete. e500mc
  523. * cores also require an isync.
  524. */
  525. lwz r0, 0xc08(r9) /* LAWAR0 */
  526. isync
  527. /*
  528. * Read the current CCSRBARH and CCSRBARL using load word instructions.
  529. * Follow this with an isync instruction. This forces any outstanding
  530. * accesses to configuration space to completion.
  531. */
  532. read_old_ccsrbar:
  533. lwz r0, 0(r9) /* CCSRBARH */
  534. lwz r0, 4(r9) /* CCSRBARL */
  535. isync
  536. /*
  537. * Write the new values for CCSRBARH and CCSRBARL to their old
  538. * locations. The CCSRBARH has a shadow register. When the CCSRBARH
  539. * has a new value written it loads a CCSRBARH shadow register. When
  540. * the CCSRBARL is written, the CCSRBARH shadow register contents
  541. * along with the CCSRBARL value are loaded into the CCSRBARH and
  542. * CCSRBARL registers, respectively. Follow this with a sync
  543. * instruction.
  544. */
  545. write_new_ccsrbar:
  546. lis r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
  547. ori r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
  548. lis r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
  549. ori r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
  550. lis r2, CCSRAR_C@h
  551. ori r2, r2, CCSRAR_C@l
  552. stw r0, 0(r9) /* Write to CCSRBARH */
  553. sync /* Make sure we write to CCSRBARH first */
  554. stw r1, 4(r9) /* Write to CCSRBARL */
  555. sync
  556. /*
  557. * Write a 1 to the commit bit (C) of CCSRAR at the old location.
  558. * Follow this with a sync instruction.
  559. */
  560. stw r2, 8(r9)
  561. sync
  562. /* Delete the temporary LAW */
  563. delete_temp_law:
  564. li r1, 0
  565. stw r1, 0xc08(r8)
  566. sync
  567. stw r1, 0xc00(r8)
  568. stw r1, 0xc04(r8)
  569. sync
  570. #else /* #ifdef CONFIG_FSL_CORENET */
  571. write_new_ccsrbar:
  572. /*
  573. * Read the current value of CCSRBAR using a load word instruction
  574. * followed by an isync. This forces all accesses to configuration
  575. * space to complete.
  576. */
  577. sync
  578. lwz r0, 0(r9)
  579. isync
  580. /* CONFIG_SYS_CCSRBAR_PHYS right shifted by 12 */
  581. #define CCSRBAR_PHYS_RS12 ((CONFIG_SYS_CCSRBAR_PHYS_HIGH << 20) | \
  582. (CONFIG_SYS_CCSRBAR_PHYS_LOW >> 12))
  583. /* Write the new value to CCSRBAR. */
  584. lis r0, CCSRBAR_PHYS_RS12@h
  585. ori r0, r0, CCSRBAR_PHYS_RS12@l
  586. stw r0, 0(r9)
  587. sync
  588. /*
  589. * The manual says to perform a load of an address that does not
  590. * access configuration space or the on-chip SRAM using an existing TLB,
  591. * but that doesn't appear to be necessary. We will do the isync,
  592. * though.
  593. */
  594. isync
  595. /*
  596. * Read the contents of CCSRBAR from its new location, followed by
  597. * another isync.
  598. */
  599. lwz r0, 0(r8)
  600. isync
  601. #endif /* #ifdef CONFIG_FSL_CORENET */
  602. /* Delete the temporary TLBs */
  603. delete_temp_tlbs:
  604. delete_tlb0_entry 0, CONFIG_SYS_CCSRBAR, MAS2_I|MAS2_G, r3
  605. delete_tlb0_entry 1, CONFIG_SYS_CCSRBAR + 0x1000, MAS2_I|MAS2_G, r3
  606. #endif /* #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS) */
  607. #if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
  608. create_ccsr_l2_tlb:
  609. /*
  610. * Create a TLB for the MMR location of CCSR
  611. * to access L2CSR0 register
  612. */
  613. create_tlb0_entry 0, \
  614. 0, BOOKE_PAGESZ_4K, \
  615. CONFIG_SYS_CCSRBAR + 0xC20000, MAS2_I|MAS2_G, \
  616. CONFIG_SYS_CCSRBAR_PHYS_LOW + 0xC20000, MAS3_SW|MAS3_SR, \
  617. CONFIG_SYS_CCSRBAR_PHYS_HIGH, r3
  618. enable_l2_cluster_l2:
  619. /* enable L2 cache */
  620. lis r3, (CONFIG_SYS_CCSRBAR + 0xC20000)@h
  621. ori r3, r3, (CONFIG_SYS_CCSRBAR + 0xC20000)@l
  622. li r4, 33 /* stash id */
  623. stw r4, 4(r3)
  624. lis r4, (L2CSR0_L2FI|L2CSR0_L2LFC)@h
  625. ori r4, r4, (L2CSR0_L2FI|L2CSR0_L2LFC)@l
  626. sync
  627. stw r4, 0(r3) /* invalidate L2 */
  628. 1: sync
  629. lwz r0, 0(r3)
  630. twi 0, r0, 0
  631. isync
  632. and. r1, r0, r4
  633. bne 1b
  634. lis r4, (L2CSR0_L2E|L2CSR0_L2PE)@h
  635. ori r4, r4, (L2CSR0_L2REP_MODE)@l
  636. sync
  637. stw r4, 0(r3) /* enable L2 */
  638. delete_ccsr_l2_tlb:
  639. delete_tlb0_entry 0, CONFIG_SYS_CCSRBAR + 0xC20000, MAS2_I|MAS2_G, r3
  640. #endif
  641. /*
  642. * Enable the L1. On e6500, this has to be done
  643. * after the L2 is up.
  644. */
  645. #ifdef CONFIG_SYS_CACHE_STASHING
  646. /* set stash id to (coreID) * 2 + 32 + L1 CT (0) */
  647. li r2,(32 + 0)
  648. mtspr L1CSR2,r2
  649. #endif
  650. /* Enable/invalidate the I-Cache */
  651. lis r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
  652. ori r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
  653. mtspr SPRN_L1CSR1,r2
  654. 1:
  655. mfspr r3,SPRN_L1CSR1
  656. and. r1,r3,r2
  657. bne 1b
  658. lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h
  659. ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
  660. mtspr SPRN_L1CSR1,r3
  661. isync
  662. 2:
  663. mfspr r3,SPRN_L1CSR1
  664. andi. r1,r3,L1CSR1_ICE@l
  665. beq 2b
  666. /* Enable/invalidate the D-Cache */
  667. lis r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h
  668. ori r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l
  669. mtspr SPRN_L1CSR0,r2
  670. 1:
  671. mfspr r3,SPRN_L1CSR0
  672. and. r1,r3,r2
  673. bne 1b
  674. lis r3,(L1CSR0_CPE|L1CSR0_DCE)@h
  675. ori r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l
  676. mtspr SPRN_L1CSR0,r3
  677. isync
  678. 2:
  679. mfspr r3,SPRN_L1CSR0
  680. andi. r1,r3,L1CSR0_DCE@l
  681. beq 2b
  682. #ifdef CONFIG_SYS_FSL_ERRATUM_A004510
  683. #define DCSR_LAWBARH0 (CONFIG_SYS_CCSRBAR + 0x1000)
  684. #define LAW_SIZE_1M 0x13
  685. #define DCSRBAR_LAWAR (LAW_EN | (0x1d << 20) | LAW_SIZE_1M)
  686. cmpwi r27,0
  687. beq 9f
  688. /*
  689. * Create a TLB entry for CCSR
  690. *
  691. * We're executing out of TLB1 entry in r14, and that's the only
  692. * TLB entry that exists. To allocate some TLB entries for our
  693. * own use, flip a bit high enough that we won't flip it again
  694. * via incrementing.
  695. */
  696. xori r8, r14, 32
  697. lis r0, MAS0_TLBSEL(1)@h
  698. rlwimi r0, r8, 16, MAS0_ESEL_MSK
  699. lis r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_16M)@h
  700. ori r1, r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_16M)@l
  701. lis r7, CONFIG_SYS_CCSRBAR@h
  702. ori r7, r7, CONFIG_SYS_CCSRBAR@l
  703. ori r2, r7, MAS2_I|MAS2_G
  704. lis r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@h
  705. ori r3, r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@l
  706. lis r4, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
  707. ori r4, r4, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
  708. mtspr MAS0, r0
  709. mtspr MAS1, r1
  710. mtspr MAS2, r2
  711. mtspr MAS3, r3
  712. mtspr MAS7, r4
  713. isync
  714. tlbwe
  715. isync
  716. msync
  717. /* Map DCSR temporarily to physical address zero */
  718. li r0, 0
  719. lis r3, DCSRBAR_LAWAR@h
  720. ori r3, r3, DCSRBAR_LAWAR@l
  721. stw r0, 0xc00(r7) /* LAWBARH0 */
  722. stw r0, 0xc04(r7) /* LAWBARL0 */
  723. sync
  724. stw r3, 0xc08(r7) /* LAWAR0 */
  725. /* Read back from LAWAR to ensure the update is complete. */
  726. lwz r3, 0xc08(r7) /* LAWAR0 */
  727. isync
  728. /* Create a TLB entry for DCSR at zero */
  729. addi r9, r8, 1
  730. lis r0, MAS0_TLBSEL(1)@h
  731. rlwimi r0, r9, 16, MAS0_ESEL_MSK
  732. lis r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_1M)@h
  733. ori r1, r1, FSL_BOOKE_MAS1(1, 1, 0, 0, BOOKE_PAGESZ_1M)@l
  734. li r6, 0 /* DCSR effective address */
  735. ori r2, r6, MAS2_I|MAS2_G
  736. li r3, MAS3_SW|MAS3_SR
  737. li r4, 0
  738. mtspr MAS0, r0
  739. mtspr MAS1, r1
  740. mtspr MAS2, r2
  741. mtspr MAS3, r3
  742. mtspr MAS7, r4
  743. isync
  744. tlbwe
  745. isync
  746. msync
  747. /* enable the timebase */
  748. #define CTBENR 0xe2084
  749. li r3, 1
  750. addis r4, r7, CTBENR@ha
  751. stw r3, CTBENR@l(r4)
  752. lwz r3, CTBENR@l(r4)
  753. twi 0,r3,0
  754. isync
  755. .macro erratum_set_ccsr offset value
  756. addis r3, r7, \offset@ha
  757. lis r4, \value@h
  758. addi r3, r3, \offset@l
  759. ori r4, r4, \value@l
  760. bl erratum_set_value
  761. .endm
  762. .macro erratum_set_dcsr offset value
  763. addis r3, r6, \offset@ha
  764. lis r4, \value@h
  765. addi r3, r3, \offset@l
  766. ori r4, r4, \value@l
  767. bl erratum_set_value
  768. .endm
  769. erratum_set_dcsr 0xb0e08 0xe0201800
  770. erratum_set_dcsr 0xb0e18 0xe0201800
  771. erratum_set_dcsr 0xb0e38 0xe0400000
  772. erratum_set_dcsr 0xb0008 0x00900000
  773. erratum_set_dcsr 0xb0e40 0xe00a0000
  774. erratum_set_ccsr 0x18600 CONFIG_SYS_FSL_CORENET_SNOOPVEC_COREONLY
  775. #ifdef CONFIG_RAMBOOT_PBL
  776. erratum_set_ccsr 0x10f00 0x495e5000
  777. #else
  778. erratum_set_ccsr 0x10f00 0x415e5000
  779. #endif
  780. erratum_set_ccsr 0x11f00 0x415e5000
  781. /* Make temp mapping uncacheable again, if it was initially */
  782. bl 2f
  783. 2: mflr r3
  784. tlbsx 0, r3
  785. mfspr r4, MAS2
  786. rlwimi r4, r15, 0, MAS2_I
  787. rlwimi r4, r15, 0, MAS2_G
  788. mtspr MAS2, r4
  789. isync
  790. tlbwe
  791. isync
  792. msync
  793. /* Clear the cache */
  794. lis r3,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
  795. ori r3,r3,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
  796. sync
  797. isync
  798. mtspr SPRN_L1CSR1,r3
  799. isync
  800. 2: sync
  801. mfspr r4,SPRN_L1CSR1
  802. and. r4,r4,r3
  803. bne 2b
  804. lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h
  805. ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
  806. sync
  807. isync
  808. mtspr SPRN_L1CSR1,r3
  809. isync
  810. 2: sync
  811. mfspr r4,SPRN_L1CSR1
  812. and. r4,r4,r3
  813. beq 2b
  814. /* Remove temporary mappings */
  815. lis r0, MAS0_TLBSEL(1)@h
  816. rlwimi r0, r9, 16, MAS0_ESEL_MSK
  817. li r3, 0
  818. mtspr MAS0, r0
  819. mtspr MAS1, r3
  820. isync
  821. tlbwe
  822. isync
  823. msync
  824. li r3, 0
  825. stw r3, 0xc08(r7) /* LAWAR0 */
  826. lwz r3, 0xc08(r7)
  827. isync
  828. lis r0, MAS0_TLBSEL(1)@h
  829. rlwimi r0, r8, 16, MAS0_ESEL_MSK
  830. li r3, 0
  831. mtspr MAS0, r0
  832. mtspr MAS1, r3
  833. isync
  834. tlbwe
  835. isync
  836. msync
  837. b 9f
  838. /* r3 = addr, r4 = value, clobbers r5, r11, r12 */
  839. erratum_set_value:
  840. /* Lock two cache lines into I-Cache */
  841. sync
  842. mfspr r11, SPRN_L1CSR1
  843. rlwinm r11, r11, 0, ~L1CSR1_ICUL
  844. sync
  845. isync
  846. mtspr SPRN_L1CSR1, r11
  847. isync
  848. mflr r12
  849. bl 5f
  850. 5: mflr r5
  851. addi r5, r5, 2f - 5b
  852. icbtls 0, 0, r5
  853. addi r5, r5, 64
  854. sync
  855. mfspr r11, SPRN_L1CSR1
  856. 3: andi. r11, r11, L1CSR1_ICUL
  857. bne 3b
  858. icbtls 0, 0, r5
  859. addi r5, r5, 64
  860. sync
  861. mfspr r11, SPRN_L1CSR1
  862. 3: andi. r11, r11, L1CSR1_ICUL
  863. bne 3b
  864. b 2f
  865. .align 6
  866. /* Inside a locked cacheline, wait a while, write, then wait a while */
  867. 2: sync
  868. mfspr r5, SPRN_TBRL
  869. addis r11, r5, 0x10000@h /* wait 65536 timebase ticks */
  870. 4: mfspr r5, SPRN_TBRL
  871. subf. r5, r5, r11
  872. bgt 4b
  873. stw r4, 0(r3)
  874. mfspr r5, SPRN_TBRL
  875. addis r11, r5, 0x10000@h /* wait 65536 timebase ticks */
  876. 4: mfspr r5, SPRN_TBRL
  877. subf. r5, r5, r11
  878. bgt 4b
  879. sync
  880. /*
  881. * Fill out the rest of this cache line and the next with nops,
  882. * to ensure that nothing outside the locked area will be
  883. * fetched due to a branch.
  884. */
  885. .rept 19
  886. nop
  887. .endr
  888. sync
  889. mfspr r11, SPRN_L1CSR1
  890. rlwinm r11, r11, 0, ~L1CSR1_ICUL
  891. sync
  892. isync
  893. mtspr SPRN_L1CSR1, r11
  894. isync
  895. mtlr r12
  896. blr
  897. 9:
  898. #endif
  899. create_init_ram_area:
  900. lis r6,FSL_BOOKE_MAS0(1, 15, 0)@h
  901. ori r6,r6,FSL_BOOKE_MAS0(1, 15, 0)@l
  902. #ifdef NOR_BOOT
  903. /* create a temp mapping in AS=1 to the 4M boot window */
  904. create_tlb1_entry 15, \
  905. 1, BOOKE_PAGESZ_4M, \
  906. CONFIG_SYS_MONITOR_BASE & 0xffc00000, MAS2_I|MAS2_G, \
  907. 0xffc00000, MAS3_SX|MAS3_SW|MAS3_SR, \
  908. 0, r6
  909. #elif !defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SECURE_BOOT)
  910. /* create a temp mapping in AS = 1 for Flash mapping
  911. * created by PBL for ISBC code
  912. */
  913. create_tlb1_entry 15, \
  914. 1, BOOKE_PAGESZ_1M, \
  915. CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS2_I|MAS2_G, \
  916. CONFIG_SYS_PBI_FLASH_WINDOW & 0xfff00000, MAS3_SX|MAS3_SW|MAS3_SR, \
  917. 0, r6
  918. #else
  919. /*
  920. * create a temp mapping in AS=1 to the 1M CONFIG_SYS_MONITOR_BASE space, the main
  921. * image has been relocated to CONFIG_SYS_MONITOR_BASE on the second stage.
  922. */
  923. create_tlb1_entry 15, \
  924. 1, BOOKE_PAGESZ_1M, \
  925. CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS2_I|MAS2_G, \
  926. CONFIG_SYS_MONITOR_BASE & 0xfff00000, MAS3_SX|MAS3_SW|MAS3_SR, \
  927. 0, r6
  928. #endif
  929. /* create a temp mapping in AS=1 to the stack */
  930. #if defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW) && \
  931. defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH)
  932. create_tlb1_entry 14, \
  933. 1, BOOKE_PAGESZ_16K, \
  934. CONFIG_SYS_INIT_RAM_ADDR, 0, \
  935. CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW, MAS3_SX|MAS3_SW|MAS3_SR, \
  936. CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH, r6
  937. #else
  938. create_tlb1_entry 14, \
  939. 1, BOOKE_PAGESZ_16K, \
  940. CONFIG_SYS_INIT_RAM_ADDR, 0, \
  941. CONFIG_SYS_INIT_RAM_ADDR, MAS3_SX|MAS3_SW|MAS3_SR, \
  942. 0, r6
  943. #endif
  944. lis r6,MSR_IS|MSR_DS|MSR_DE@h
  945. ori r6,r6,MSR_IS|MSR_DS|MSR_DE@l
  946. lis r7,switch_as@h
  947. ori r7,r7,switch_as@l
  948. mtspr SPRN_SRR0,r7
  949. mtspr SPRN_SRR1,r6
  950. rfi
  951. switch_as:
  952. /* L1 DCache is used for initial RAM */
  953. /* Allocate Initial RAM in data cache.
  954. */
  955. lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
  956. ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
  957. mfspr r2, L1CFG0
  958. andi. r2, r2, 0x1ff
  959. /* cache size * 1024 / (2 * L1 line size) */
  960. slwi r2, r2, (10 - 1 - L1_CACHE_SHIFT)
  961. mtctr r2
  962. li r0,0
  963. 1:
  964. dcbz r0,r3
  965. dcbtls 0,r0,r3
  966. addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
  967. bdnz 1b
  968. /* Jump out the last 4K page and continue to 'normal' start */
  969. #if defined(CONFIG_SYS_RAMBOOT) || defined(CONFIG_SPL)
  970. /* We assume that we're already running at the address we're linked at */
  971. b _start_cont
  972. #else
  973. /* Calculate absolute address in FLASH and jump there */
  974. /*--------------------------------------------------------------*/
  975. lis r3,CONFIG_SYS_MONITOR_BASE@h
  976. ori r3,r3,CONFIG_SYS_MONITOR_BASE@l
  977. addi r3,r3,_start_cont - _start + _START_OFFSET
  978. mtlr r3
  979. blr
  980. #endif
  981. .text
  982. .globl _start
  983. _start:
  984. .long 0x27051956 /* U-BOOT Magic Number */
  985. .globl version_string
  986. version_string:
  987. .ascii U_BOOT_VERSION_STRING, "\0"
  988. .align 4
  989. .globl _start_cont
  990. _start_cont:
  991. /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
  992. lis r3,(CONFIG_SYS_INIT_RAM_ADDR)@h
  993. ori r3,r3,((CONFIG_SYS_INIT_SP_OFFSET-16)&~0xf)@l /* Align to 16 */
  994. li r0,0
  995. stw r0,0(r3) /* Terminate Back Chain */
  996. stw r0,+4(r3) /* NULL return address. */
  997. mr r1,r3 /* Transfer to SP(r1) */
  998. GET_GOT
  999. bl cpu_init_early_f
  1000. /* switch back to AS = 0 */
  1001. lis r3,(MSR_CE|MSR_ME|MSR_DE)@h
  1002. ori r3,r3,(MSR_CE|MSR_ME|MSR_DE)@l
  1003. mtmsr r3
  1004. isync
  1005. bl cpu_init_f
  1006. bl board_init_f
  1007. isync
  1008. /* NOTREACHED - board_init_f() does not return */
  1009. #ifndef MINIMAL_SPL
  1010. . = EXC_OFF_SYS_RESET
  1011. .globl _start_of_vectors
  1012. _start_of_vectors:
  1013. /* Critical input. */
  1014. CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException)
  1015. /* Machine check */
  1016. MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  1017. /* Data Storage exception. */
  1018. STD_EXCEPTION(0x0300, DataStorage, UnknownException)
  1019. /* Instruction Storage exception. */
  1020. STD_EXCEPTION(0x0400, InstStorage, UnknownException)
  1021. /* External Interrupt exception. */
  1022. STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException)
  1023. /* Alignment exception. */
  1024. . = 0x0600
  1025. Alignment:
  1026. EXCEPTION_PROLOG(SRR0, SRR1)
  1027. mfspr r4,DAR
  1028. stw r4,_DAR(r21)
  1029. mfspr r5,DSISR
  1030. stw r5,_DSISR(r21)
  1031. addi r3,r1,STACK_FRAME_OVERHEAD
  1032. EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
  1033. /* Program check exception */
  1034. . = 0x0700
  1035. ProgramCheck:
  1036. EXCEPTION_PROLOG(SRR0, SRR1)
  1037. addi r3,r1,STACK_FRAME_OVERHEAD
  1038. EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
  1039. MSR_KERNEL, COPY_EE)
  1040. /* No FPU on MPC85xx. This exception is not supposed to happen.
  1041. */
  1042. STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
  1043. . = 0x0900
  1044. /*
  1045. * r0 - SYSCALL number
  1046. * r3-... arguments
  1047. */
  1048. SystemCall:
  1049. addis r11,r0,0 /* get functions table addr */
  1050. ori r11,r11,0 /* Note: this code is patched in trap_init */
  1051. addis r12,r0,0 /* get number of functions */
  1052. ori r12,r12,0
  1053. cmplw 0,r0,r12
  1054. bge 1f
  1055. rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
  1056. add r11,r11,r0
  1057. lwz r11,0(r11)
  1058. li r20,0xd00-4 /* Get stack pointer */
  1059. lwz r12,0(r20)
  1060. subi r12,r12,12 /* Adjust stack pointer */
  1061. li r0,0xc00+_end_back-SystemCall
  1062. cmplw 0,r0,r12 /* Check stack overflow */
  1063. bgt 1f
  1064. stw r12,0(r20)
  1065. mflr r0
  1066. stw r0,0(r12)
  1067. mfspr r0,SRR0
  1068. stw r0,4(r12)
  1069. mfspr r0,SRR1
  1070. stw r0,8(r12)
  1071. li r12,0xc00+_back-SystemCall
  1072. mtlr r12
  1073. mtspr SRR0,r11
  1074. 1: SYNC
  1075. rfi
  1076. _back:
  1077. mfmsr r11 /* Disable interrupts */
  1078. li r12,0
  1079. ori r12,r12,MSR_EE
  1080. andc r11,r11,r12
  1081. SYNC /* Some chip revs need this... */
  1082. mtmsr r11
  1083. SYNC
  1084. li r12,0xd00-4 /* restore regs */
  1085. lwz r12,0(r12)
  1086. lwz r11,0(r12)
  1087. mtlr r11
  1088. lwz r11,4(r12)
  1089. mtspr SRR0,r11
  1090. lwz r11,8(r12)
  1091. mtspr SRR1,r11
  1092. addi r12,r12,12 /* Adjust stack pointer */
  1093. li r20,0xd00-4
  1094. stw r12,0(r20)
  1095. SYNC
  1096. rfi
  1097. _end_back:
  1098. STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
  1099. STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
  1100. STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
  1101. STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
  1102. STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
  1103. CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
  1104. .globl _end_of_vectors
  1105. _end_of_vectors:
  1106. . = . + (0x100 - ( . & 0xff )) /* align for debug */
  1107. /*
  1108. * This code finishes saving the registers to the exception frame
  1109. * and jumps to the appropriate handler for the exception.
  1110. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  1111. */
  1112. .globl transfer_to_handler
  1113. transfer_to_handler:
  1114. stw r22,_NIP(r21)
  1115. lis r22,MSR_POW@h
  1116. andc r23,r23,r22
  1117. stw r23,_MSR(r21)
  1118. SAVE_GPR(7, r21)
  1119. SAVE_4GPRS(8, r21)
  1120. SAVE_8GPRS(12, r21)
  1121. SAVE_8GPRS(24, r21)
  1122. mflr r23
  1123. andi. r24,r23,0x3f00 /* get vector offset */
  1124. stw r24,TRAP(r21)
  1125. li r22,0
  1126. stw r22,RESULT(r21)
  1127. mtspr SPRG2,r22 /* r1 is now kernel sp */
  1128. lwz r24,0(r23) /* virtual address of handler */
  1129. lwz r23,4(r23) /* where to go when done */
  1130. mtspr SRR0,r24
  1131. mtspr SRR1,r20
  1132. mtlr r23
  1133. SYNC
  1134. rfi /* jump to handler, enable MMU */
  1135. int_return:
  1136. mfmsr r28 /* Disable interrupts */
  1137. li r4,0
  1138. ori r4,r4,MSR_EE
  1139. andc r28,r28,r4
  1140. SYNC /* Some chip revs need this... */
  1141. mtmsr r28
  1142. SYNC
  1143. lwz r2,_CTR(r1)
  1144. lwz r0,_LINK(r1)
  1145. mtctr r2
  1146. mtlr r0
  1147. lwz r2,_XER(r1)
  1148. lwz r0,_CCR(r1)
  1149. mtspr XER,r2
  1150. mtcrf 0xFF,r0
  1151. REST_10GPRS(3, r1)
  1152. REST_10GPRS(13, r1)
  1153. REST_8GPRS(23, r1)
  1154. REST_GPR(31, r1)
  1155. lwz r2,_NIP(r1) /* Restore environment */
  1156. lwz r0,_MSR(r1)
  1157. mtspr SRR0,r2
  1158. mtspr SRR1,r0
  1159. lwz r0,GPR0(r1)
  1160. lwz r2,GPR2(r1)
  1161. lwz r1,GPR1(r1)
  1162. SYNC
  1163. rfi
  1164. crit_return:
  1165. mfmsr r28 /* Disable interrupts */
  1166. li r4,0
  1167. ori r4,r4,MSR_EE
  1168. andc r28,r28,r4
  1169. SYNC /* Some chip revs need this... */
  1170. mtmsr r28
  1171. SYNC
  1172. lwz r2,_CTR(r1)
  1173. lwz r0,_LINK(r1)
  1174. mtctr r2
  1175. mtlr r0
  1176. lwz r2,_XER(r1)
  1177. lwz r0,_CCR(r1)
  1178. mtspr XER,r2
  1179. mtcrf 0xFF,r0
  1180. REST_10GPRS(3, r1)
  1181. REST_10GPRS(13, r1)
  1182. REST_8GPRS(23, r1)
  1183. REST_GPR(31, r1)
  1184. lwz r2,_NIP(r1) /* Restore environment */
  1185. lwz r0,_MSR(r1)
  1186. mtspr SPRN_CSRR0,r2
  1187. mtspr SPRN_CSRR1,r0
  1188. lwz r0,GPR0(r1)
  1189. lwz r2,GPR2(r1)
  1190. lwz r1,GPR1(r1)
  1191. SYNC
  1192. rfci
  1193. mck_return:
  1194. mfmsr r28 /* Disable interrupts */
  1195. li r4,0
  1196. ori r4,r4,MSR_EE
  1197. andc r28,r28,r4
  1198. SYNC /* Some chip revs need this... */
  1199. mtmsr r28
  1200. SYNC
  1201. lwz r2,_CTR(r1)
  1202. lwz r0,_LINK(r1)
  1203. mtctr r2
  1204. mtlr r0
  1205. lwz r2,_XER(r1)
  1206. lwz r0,_CCR(r1)
  1207. mtspr XER,r2
  1208. mtcrf 0xFF,r0
  1209. REST_10GPRS(3, r1)
  1210. REST_10GPRS(13, r1)
  1211. REST_8GPRS(23, r1)
  1212. REST_GPR(31, r1)
  1213. lwz r2,_NIP(r1) /* Restore environment */
  1214. lwz r0,_MSR(r1)
  1215. mtspr SPRN_MCSRR0,r2
  1216. mtspr SPRN_MCSRR1,r0
  1217. lwz r0,GPR0(r1)
  1218. lwz r2,GPR2(r1)
  1219. lwz r1,GPR1(r1)
  1220. SYNC
  1221. rfmci
  1222. /* Cache functions.
  1223. */
  1224. .globl flush_icache
  1225. flush_icache:
  1226. .globl invalidate_icache
  1227. invalidate_icache:
  1228. mfspr r0,L1CSR1
  1229. ori r0,r0,L1CSR1_ICFI
  1230. msync
  1231. isync
  1232. mtspr L1CSR1,r0
  1233. isync
  1234. blr /* entire I cache */
  1235. .globl invalidate_dcache
  1236. invalidate_dcache:
  1237. mfspr r0,L1CSR0
  1238. ori r0,r0,L1CSR0_DCFI
  1239. msync
  1240. isync
  1241. mtspr L1CSR0,r0
  1242. isync
  1243. blr
  1244. .globl icache_enable
  1245. icache_enable:
  1246. mflr r8
  1247. bl invalidate_icache
  1248. mtlr r8
  1249. isync
  1250. mfspr r4,L1CSR1
  1251. ori r4,r4,0x0001
  1252. oris r4,r4,0x0001
  1253. mtspr L1CSR1,r4
  1254. isync
  1255. blr
  1256. .globl icache_disable
  1257. icache_disable:
  1258. mfspr r0,L1CSR1
  1259. lis r3,0
  1260. ori r3,r3,L1CSR1_ICE
  1261. andc r0,r0,r3
  1262. mtspr L1CSR1,r0
  1263. isync
  1264. blr
  1265. .globl icache_status
  1266. icache_status:
  1267. mfspr r3,L1CSR1
  1268. andi. r3,r3,L1CSR1_ICE
  1269. blr
  1270. .globl dcache_enable
  1271. dcache_enable:
  1272. mflr r8
  1273. bl invalidate_dcache
  1274. mtlr r8
  1275. isync
  1276. mfspr r0,L1CSR0
  1277. ori r0,r0,0x0001
  1278. oris r0,r0,0x0001
  1279. msync
  1280. isync
  1281. mtspr L1CSR0,r0
  1282. isync
  1283. blr
  1284. .globl dcache_disable
  1285. dcache_disable:
  1286. mfspr r3,L1CSR0
  1287. lis r4,0
  1288. ori r4,r4,L1CSR0_DCE
  1289. andc r3,r3,r4
  1290. mtspr L1CSR0,r3
  1291. isync
  1292. blr
  1293. .globl dcache_status
  1294. dcache_status:
  1295. mfspr r3,L1CSR0
  1296. andi. r3,r3,L1CSR0_DCE
  1297. blr
  1298. .globl get_pir
  1299. get_pir:
  1300. mfspr r3,PIR
  1301. blr
  1302. .globl get_pvr
  1303. get_pvr:
  1304. mfspr r3,PVR
  1305. blr
  1306. .globl get_svr
  1307. get_svr:
  1308. mfspr r3,SVR
  1309. blr
  1310. .globl wr_tcr
  1311. wr_tcr:
  1312. mtspr TCR,r3
  1313. blr
  1314. /*------------------------------------------------------------------------------- */
  1315. /* Function: in8 */
  1316. /* Description: Input 8 bits */
  1317. /*------------------------------------------------------------------------------- */
  1318. .globl in8
  1319. in8:
  1320. lbz r3,0x0000(r3)
  1321. blr
  1322. /*------------------------------------------------------------------------------- */
  1323. /* Function: out8 */
  1324. /* Description: Output 8 bits */
  1325. /*------------------------------------------------------------------------------- */
  1326. .globl out8
  1327. out8:
  1328. stb r4,0x0000(r3)
  1329. sync
  1330. blr
  1331. /*------------------------------------------------------------------------------- */
  1332. /* Function: out16 */
  1333. /* Description: Output 16 bits */
  1334. /*------------------------------------------------------------------------------- */
  1335. .globl out16
  1336. out16:
  1337. sth r4,0x0000(r3)
  1338. sync
  1339. blr
  1340. /*------------------------------------------------------------------------------- */
  1341. /* Function: out16r */
  1342. /* Description: Byte reverse and output 16 bits */
  1343. /*------------------------------------------------------------------------------- */
  1344. .globl out16r
  1345. out16r:
  1346. sthbrx r4,r0,r3
  1347. sync
  1348. blr
  1349. /*------------------------------------------------------------------------------- */
  1350. /* Function: out32 */
  1351. /* Description: Output 32 bits */
  1352. /*------------------------------------------------------------------------------- */
  1353. .globl out32
  1354. out32:
  1355. stw r4,0x0000(r3)
  1356. sync
  1357. blr
  1358. /*------------------------------------------------------------------------------- */
  1359. /* Function: out32r */
  1360. /* Description: Byte reverse and output 32 bits */
  1361. /*------------------------------------------------------------------------------- */
  1362. .globl out32r
  1363. out32r:
  1364. stwbrx r4,r0,r3
  1365. sync
  1366. blr
  1367. /*------------------------------------------------------------------------------- */
  1368. /* Function: in16 */
  1369. /* Description: Input 16 bits */
  1370. /*------------------------------------------------------------------------------- */
  1371. .globl in16
  1372. in16:
  1373. lhz r3,0x0000(r3)
  1374. blr
  1375. /*------------------------------------------------------------------------------- */
  1376. /* Function: in16r */
  1377. /* Description: Input 16 bits and byte reverse */
  1378. /*------------------------------------------------------------------------------- */
  1379. .globl in16r
  1380. in16r:
  1381. lhbrx r3,r0,r3
  1382. blr
  1383. /*------------------------------------------------------------------------------- */
  1384. /* Function: in32 */
  1385. /* Description: Input 32 bits */
  1386. /*------------------------------------------------------------------------------- */
  1387. .globl in32
  1388. in32:
  1389. lwz 3,0x0000(3)
  1390. blr
  1391. /*------------------------------------------------------------------------------- */
  1392. /* Function: in32r */
  1393. /* Description: Input 32 bits and byte reverse */
  1394. /*------------------------------------------------------------------------------- */
  1395. .globl in32r
  1396. in32r:
  1397. lwbrx r3,r0,r3
  1398. blr
  1399. #endif /* !MINIMAL_SPL */
  1400. /*------------------------------------------------------------------------------*/
  1401. /*
  1402. * void write_tlb(mas0, mas1, mas2, mas3, mas7)
  1403. */
  1404. .globl write_tlb
  1405. write_tlb:
  1406. mtspr MAS0,r3
  1407. mtspr MAS1,r4
  1408. mtspr MAS2,r5
  1409. mtspr MAS3,r6
  1410. #ifdef CONFIG_ENABLE_36BIT_PHYS
  1411. mtspr MAS7,r7
  1412. #endif
  1413. li r3,0
  1414. #ifdef CONFIG_SYS_BOOK3E_HV
  1415. mtspr MAS8,r3
  1416. #endif
  1417. isync
  1418. tlbwe
  1419. msync
  1420. isync
  1421. blr
  1422. /*
  1423. * void relocate_code (addr_sp, gd, addr_moni)
  1424. *
  1425. * This "function" does not return, instead it continues in RAM
  1426. * after relocating the monitor code.
  1427. *
  1428. * r3 = dest
  1429. * r4 = src
  1430. * r5 = length in bytes
  1431. * r6 = cachelinesize
  1432. */
  1433. .globl relocate_code
  1434. relocate_code:
  1435. mr r1,r3 /* Set new stack pointer */
  1436. mr r9,r4 /* Save copy of Init Data pointer */
  1437. mr r10,r5 /* Save copy of Destination Address */
  1438. GET_GOT
  1439. mr r3,r5 /* Destination Address */
  1440. lis r4,CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  1441. ori r4,r4,CONFIG_SYS_MONITOR_BASE@l
  1442. lwz r5,GOT(__init_end)
  1443. sub r5,r5,r4
  1444. li r6,CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  1445. /*
  1446. * Fix GOT pointer:
  1447. *
  1448. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  1449. *
  1450. * Offset:
  1451. */
  1452. sub r15,r10,r4
  1453. /* First our own GOT */
  1454. add r12,r12,r15
  1455. /* the the one used by the C code */
  1456. add r30,r30,r15
  1457. /*
  1458. * Now relocate code
  1459. */
  1460. cmplw cr1,r3,r4
  1461. addi r0,r5,3
  1462. srwi. r0,r0,2
  1463. beq cr1,4f /* In place copy is not necessary */
  1464. beq 7f /* Protect against 0 count */
  1465. mtctr r0
  1466. bge cr1,2f
  1467. la r8,-4(r4)
  1468. la r7,-4(r3)
  1469. 1: lwzu r0,4(r8)
  1470. stwu r0,4(r7)
  1471. bdnz 1b
  1472. b 4f
  1473. 2: slwi r0,r0,2
  1474. add r8,r4,r0
  1475. add r7,r3,r0
  1476. 3: lwzu r0,-4(r8)
  1477. stwu r0,-4(r7)
  1478. bdnz 3b
  1479. /*
  1480. * Now flush the cache: note that we must start from a cache aligned
  1481. * address. Otherwise we might miss one cache line.
  1482. */
  1483. 4: cmpwi r6,0
  1484. add r5,r3,r5
  1485. beq 7f /* Always flush prefetch queue in any case */
  1486. subi r0,r6,1
  1487. andc r3,r3,r0
  1488. mr r4,r3
  1489. 5: dcbst 0,r4
  1490. add r4,r4,r6
  1491. cmplw r4,r5
  1492. blt 5b
  1493. sync /* Wait for all dcbst to complete on bus */
  1494. mr r4,r3
  1495. 6: icbi 0,r4
  1496. add r4,r4,r6
  1497. cmplw r4,r5
  1498. blt 6b
  1499. 7: sync /* Wait for all icbi to complete on bus */
  1500. isync
  1501. /*
  1502. * We are done. Do not return, instead branch to second part of board
  1503. * initialization, now running from RAM.
  1504. */
  1505. addi r0,r10,in_ram - _start + _START_OFFSET
  1506. /*
  1507. * As IVPR is going to point RAM address,
  1508. * Make sure IVOR15 has valid opcode to support debugger
  1509. */
  1510. mtspr IVOR15,r0
  1511. /*
  1512. * Re-point the IVPR at RAM
  1513. */
  1514. mtspr IVPR,r10
  1515. mtlr r0
  1516. blr /* NEVER RETURNS! */
  1517. .globl in_ram
  1518. in_ram:
  1519. /*
  1520. * Relocation Function, r12 point to got2+0x8000
  1521. *
  1522. * Adjust got2 pointers, no need to check for 0, this code
  1523. * already puts a few entries in the table.
  1524. */
  1525. li r0,__got2_entries@sectoff@l
  1526. la r3,GOT(_GOT2_TABLE_)
  1527. lwz r11,GOT(_GOT2_TABLE_)
  1528. mtctr r0
  1529. sub r11,r3,r11
  1530. addi r3,r3,-4
  1531. 1: lwzu r0,4(r3)
  1532. cmpwi r0,0
  1533. beq- 2f
  1534. add r0,r0,r11
  1535. stw r0,0(r3)
  1536. 2: bdnz 1b
  1537. /*
  1538. * Now adjust the fixups and the pointers to the fixups
  1539. * in case we need to move ourselves again.
  1540. */
  1541. li r0,__fixup_entries@sectoff@l
  1542. lwz r3,GOT(_FIXUP_TABLE_)
  1543. cmpwi r0,0
  1544. mtctr r0
  1545. addi r3,r3,-4
  1546. beq 4f
  1547. 3: lwzu r4,4(r3)
  1548. lwzux r0,r4,r11
  1549. cmpwi r0,0
  1550. add r0,r0,r11
  1551. stw r4,0(r3)
  1552. beq- 5f
  1553. stw r0,0(r4)
  1554. 5: bdnz 3b
  1555. 4:
  1556. clear_bss:
  1557. /*
  1558. * Now clear BSS segment
  1559. */
  1560. lwz r3,GOT(__bss_start)
  1561. lwz r4,GOT(__bss_end)
  1562. cmplw 0,r3,r4
  1563. beq 6f
  1564. li r0,0
  1565. 5:
  1566. stw r0,0(r3)
  1567. addi r3,r3,4
  1568. cmplw 0,r3,r4
  1569. blt 5b
  1570. 6:
  1571. mr r3,r9 /* Init Data pointer */
  1572. mr r4,r10 /* Destination Address */
  1573. bl board_init_r
  1574. #ifndef MINIMAL_SPL
  1575. /*
  1576. * Copy exception vector code to low memory
  1577. *
  1578. * r3: dest_addr
  1579. * r7: source address, r8: end address, r9: target address
  1580. */
  1581. .globl trap_init
  1582. trap_init:
  1583. mflr r4 /* save link register */
  1584. GET_GOT
  1585. lwz r7,GOT(_start_of_vectors)
  1586. lwz r8,GOT(_end_of_vectors)
  1587. li r9,0x100 /* reset vector always at 0x100 */
  1588. cmplw 0,r7,r8
  1589. bgelr /* return if r7>=r8 - just in case */
  1590. 1:
  1591. lwz r0,0(r7)
  1592. stw r0,0(r9)
  1593. addi r7,r7,4
  1594. addi r9,r9,4
  1595. cmplw 0,r7,r8
  1596. bne 1b
  1597. /*
  1598. * relocate `hdlr' and `int_return' entries
  1599. */
  1600. li r7,.L_CriticalInput - _start + _START_OFFSET
  1601. bl trap_reloc
  1602. li r7,.L_MachineCheck - _start + _START_OFFSET
  1603. bl trap_reloc
  1604. li r7,.L_DataStorage - _start + _START_OFFSET
  1605. bl trap_reloc
  1606. li r7,.L_InstStorage - _start + _START_OFFSET
  1607. bl trap_reloc
  1608. li r7,.L_ExtInterrupt - _start + _START_OFFSET
  1609. bl trap_reloc
  1610. li r7,.L_Alignment - _start + _START_OFFSET
  1611. bl trap_reloc
  1612. li r7,.L_ProgramCheck - _start + _START_OFFSET
  1613. bl trap_reloc
  1614. li r7,.L_FPUnavailable - _start + _START_OFFSET
  1615. bl trap_reloc
  1616. li r7,.L_Decrementer - _start + _START_OFFSET
  1617. bl trap_reloc
  1618. li r7,.L_IntervalTimer - _start + _START_OFFSET
  1619. li r8,_end_of_vectors - _start + _START_OFFSET
  1620. 2:
  1621. bl trap_reloc
  1622. addi r7,r7,0x100 /* next exception vector */
  1623. cmplw 0,r7,r8
  1624. blt 2b
  1625. /* Update IVORs as per relocated vector table address */
  1626. li r7,0x0100
  1627. mtspr IVOR0,r7 /* 0: Critical input */
  1628. li r7,0x0200
  1629. mtspr IVOR1,r7 /* 1: Machine check */
  1630. li r7,0x0300
  1631. mtspr IVOR2,r7 /* 2: Data storage */
  1632. li r7,0x0400
  1633. mtspr IVOR3,r7 /* 3: Instruction storage */
  1634. li r7,0x0500
  1635. mtspr IVOR4,r7 /* 4: External interrupt */
  1636. li r7,0x0600
  1637. mtspr IVOR5,r7 /* 5: Alignment */
  1638. li r7,0x0700
  1639. mtspr IVOR6,r7 /* 6: Program check */
  1640. li r7,0x0800
  1641. mtspr IVOR7,r7 /* 7: floating point unavailable */
  1642. li r7,0x0900
  1643. mtspr IVOR8,r7 /* 8: System call */
  1644. /* 9: Auxiliary processor unavailable(unsupported) */
  1645. li r7,0x0a00
  1646. mtspr IVOR10,r7 /* 10: Decrementer */
  1647. li r7,0x0b00
  1648. mtspr IVOR11,r7 /* 11: Interval timer */
  1649. li r7,0x0c00
  1650. mtspr IVOR12,r7 /* 12: Watchdog timer */
  1651. li r7,0x0d00
  1652. mtspr IVOR13,r7 /* 13: Data TLB error */
  1653. li r7,0x0e00
  1654. mtspr IVOR14,r7 /* 14: Instruction TLB error */
  1655. li r7,0x0f00
  1656. mtspr IVOR15,r7 /* 15: Debug */
  1657. lis r7,0x0
  1658. mtspr IVPR,r7
  1659. mtlr r4 /* restore link register */
  1660. blr
  1661. .globl unlock_ram_in_cache
  1662. unlock_ram_in_cache:
  1663. /* invalidate the INIT_RAM section */
  1664. lis r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@h
  1665. ori r3,r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@l
  1666. mfspr r4,L1CFG0
  1667. andi. r4,r4,0x1ff
  1668. slwi r4,r4,(10 - 1 - L1_CACHE_SHIFT)
  1669. mtctr r4
  1670. 1: dcbi r0,r3
  1671. dcblc r0,r3
  1672. addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
  1673. bdnz 1b
  1674. sync
  1675. /* Invalidate the TLB entries for the cache */
  1676. lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
  1677. ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
  1678. tlbivax 0,r3
  1679. addi r3,r3,0x1000
  1680. tlbivax 0,r3
  1681. addi r3,r3,0x1000
  1682. tlbivax 0,r3
  1683. addi r3,r3,0x1000
  1684. tlbivax 0,r3
  1685. isync
  1686. blr
  1687. .globl flush_dcache
  1688. flush_dcache:
  1689. mfspr r3,SPRN_L1CFG0
  1690. rlwinm r5,r3,9,3 /* Extract cache block size */
  1691. twlgti r5,1 /* Only 32 and 64 byte cache blocks
  1692. * are currently defined.
  1693. */
  1694. li r4,32
  1695. subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) -
  1696. * log2(number of ways)
  1697. */
  1698. slw r5,r4,r5 /* r5 = cache block size */
  1699. rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */
  1700. mulli r7,r7,13 /* An 8-way cache will require 13
  1701. * loads per set.
  1702. */
  1703. slw r7,r7,r6
  1704. /* save off HID0 and set DCFA */
  1705. mfspr r8,SPRN_HID0
  1706. ori r9,r8,HID0_DCFA@l
  1707. mtspr SPRN_HID0,r9
  1708. isync
  1709. lis r4,0
  1710. mtctr r7
  1711. 1: lwz r3,0(r4) /* Load... */
  1712. add r4,r4,r5
  1713. bdnz 1b
  1714. msync
  1715. lis r4,0
  1716. mtctr r7
  1717. 1: dcbf 0,r4 /* ...and flush. */
  1718. add r4,r4,r5
  1719. bdnz 1b
  1720. /* restore HID0 */
  1721. mtspr SPRN_HID0,r8
  1722. isync
  1723. blr
  1724. .globl setup_ivors
  1725. setup_ivors:
  1726. #include "fixed_ivor.S"
  1727. blr
  1728. #endif /* !MINIMAL_SPL */