start.S 37 KB

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