start.S 44 KB

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