start.S 44 KB

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