start.S 34 KB

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