start.S 46 KB

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