start.S 38 KB

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