start.S 44 KB

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