start.S 41 KB

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