start.S 34 KB

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