start.S 33 KB

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