start.S 45 KB

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