start.S 38 KB

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