start.S 45 KB

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