start.S 38 KB

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