start.S 38 KB

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