start.S 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952
  1. /*
  2. * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
  3. * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
  4. * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de>
  5. * Copyright (C) 2007 Stefan Roese <sr@denx.de>, DENX Software Engineering
  6. * Copyright (c) 2008 Nuovation System Designs, LLC
  7. * Grant Erickson <gerickson@nuovations.com>
  8. *
  9. * SPDX-License-Identifier: GPL-2.0 IBM-pibs
  10. */
  11. /*
  12. * Startup code for IBM/AMCC PowerPC 4xx (PPC4xx) based boards
  13. *
  14. * The following description only applies to the NOR flash style booting.
  15. * NAND booting is different. For more details about NAND booting on 4xx
  16. * take a look at doc/README.nand-boot-ppc440.
  17. *
  18. * The CPU starts at address 0xfffffffc (last word in the address space).
  19. * The U-Boot image therefore has to be located in the "upper" area of the
  20. * flash (e.g. 512MiB - 0xfff80000 ... 0xffffffff). The default value for
  21. * the boot chip-select (CS0) is quite big and covers this area. On the
  22. * 405EX this is for example 0xffe00000 ... 0xffffffff. U-Boot will
  23. * reconfigure this CS0 (and other chip-selects as well when configured
  24. * this way) in the boot process to the "correct" values matching the
  25. * board layout.
  26. */
  27. #include <asm-offsets.h>
  28. #include <config.h>
  29. #include <asm/ppc4xx.h>
  30. #include <version.h>
  31. #include <ppc_asm.tmpl>
  32. #include <ppc_defs.h>
  33. #include <asm/cache.h>
  34. #include <asm/mmu.h>
  35. #include <asm/ppc4xx-isram.h>
  36. #ifdef CONFIG_SYS_INIT_DCACHE_CS
  37. # if (CONFIG_SYS_INIT_DCACHE_CS == 0)
  38. # define PBxAP PB1AP
  39. # define PBxCR PB0CR
  40. # if (defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))
  41. # define PBxAP_VAL CONFIG_SYS_EBC_PB0AP
  42. # define PBxCR_VAL CONFIG_SYS_EBC_PB0CR
  43. # endif
  44. # endif
  45. # if (CONFIG_SYS_INIT_DCACHE_CS == 1)
  46. # define PBxAP PB1AP
  47. # define PBxCR PB1CR
  48. # if (defined(CONFIG_SYS_EBC_PB1AP) && defined(CONFIG_SYS_EBC_PB1CR))
  49. # define PBxAP_VAL CONFIG_SYS_EBC_PB1AP
  50. # define PBxCR_VAL CONFIG_SYS_EBC_PB1CR
  51. # endif
  52. # endif
  53. # if (CONFIG_SYS_INIT_DCACHE_CS == 2)
  54. # define PBxAP PB2AP
  55. # define PBxCR PB2CR
  56. # if (defined(CONFIG_SYS_EBC_PB2AP) && defined(CONFIG_SYS_EBC_PB2CR))
  57. # define PBxAP_VAL CONFIG_SYS_EBC_PB2AP
  58. # define PBxCR_VAL CONFIG_SYS_EBC_PB2CR
  59. # endif
  60. # endif
  61. # if (CONFIG_SYS_INIT_DCACHE_CS == 3)
  62. # define PBxAP PB3AP
  63. # define PBxCR PB3CR
  64. # if (defined(CONFIG_SYS_EBC_PB3AP) && defined(CONFIG_SYS_EBC_PB3CR))
  65. # define PBxAP_VAL CONFIG_SYS_EBC_PB3AP
  66. # define PBxCR_VAL CONFIG_SYS_EBC_PB3CR
  67. # endif
  68. # endif
  69. # if (CONFIG_SYS_INIT_DCACHE_CS == 4)
  70. # define PBxAP PB4AP
  71. # define PBxCR PB4CR
  72. # if (defined(CONFIG_SYS_EBC_PB4AP) && defined(CONFIG_SYS_EBC_PB4CR))
  73. # define PBxAP_VAL CONFIG_SYS_EBC_PB4AP
  74. # define PBxCR_VAL CONFIG_SYS_EBC_PB4CR
  75. # endif
  76. # endif
  77. # if (CONFIG_SYS_INIT_DCACHE_CS == 5)
  78. # define PBxAP PB5AP
  79. # define PBxCR PB5CR
  80. # if (defined(CONFIG_SYS_EBC_PB5AP) && defined(CONFIG_SYS_EBC_PB5CR))
  81. # define PBxAP_VAL CONFIG_SYS_EBC_PB5AP
  82. # define PBxCR_VAL CONFIG_SYS_EBC_PB5CR
  83. # endif
  84. # endif
  85. # if (CONFIG_SYS_INIT_DCACHE_CS == 6)
  86. # define PBxAP PB6AP
  87. # define PBxCR PB6CR
  88. # if (defined(CONFIG_SYS_EBC_PB6AP) && defined(CONFIG_SYS_EBC_PB6CR))
  89. # define PBxAP_VAL CONFIG_SYS_EBC_PB6AP
  90. # define PBxCR_VAL CONFIG_SYS_EBC_PB6CR
  91. # endif
  92. # endif
  93. # if (CONFIG_SYS_INIT_DCACHE_CS == 7)
  94. # define PBxAP PB7AP
  95. # define PBxCR PB7CR
  96. # if (defined(CONFIG_SYS_EBC_PB7AP) && defined(CONFIG_SYS_EBC_PB7CR))
  97. # define PBxAP_VAL CONFIG_SYS_EBC_PB7AP
  98. # define PBxCR_VAL CONFIG_SYS_EBC_PB7CR
  99. # endif
  100. # endif
  101. # ifndef PBxAP_VAL
  102. # define PBxAP_VAL 0
  103. # endif
  104. # ifndef PBxCR_VAL
  105. # define PBxCR_VAL 0
  106. # endif
  107. /*
  108. * Memory Bank x (nothingness) initialization CONFIG_SYS_INIT_RAM_ADDR + 64 MiB
  109. * used as temporary stack pointer for the primordial stack
  110. */
  111. # ifndef CONFIG_SYS_INIT_DCACHE_PBxAR
  112. # define CONFIG_SYS_INIT_DCACHE_PBxAR (EBC_BXAP_BME_DISABLED | \
  113. EBC_BXAP_TWT_ENCODE(7) | \
  114. EBC_BXAP_BCE_DISABLE | \
  115. EBC_BXAP_BCT_2TRANS | \
  116. EBC_BXAP_CSN_ENCODE(0) | \
  117. EBC_BXAP_OEN_ENCODE(0) | \
  118. EBC_BXAP_WBN_ENCODE(0) | \
  119. EBC_BXAP_WBF_ENCODE(0) | \
  120. EBC_BXAP_TH_ENCODE(2) | \
  121. EBC_BXAP_RE_DISABLED | \
  122. EBC_BXAP_SOR_NONDELAYED | \
  123. EBC_BXAP_BEM_WRITEONLY | \
  124. EBC_BXAP_PEN_DISABLED)
  125. # endif /* CONFIG_SYS_INIT_DCACHE_PBxAR */
  126. # ifndef CONFIG_SYS_INIT_DCACHE_PBxCR
  127. # define CONFIG_SYS_INIT_DCACHE_PBxCR (EBC_BXCR_BAS_ENCODE(CONFIG_SYS_INIT_RAM_ADDR) | \
  128. EBC_BXCR_BS_64MB | \
  129. EBC_BXCR_BU_RW | \
  130. EBC_BXCR_BW_16BIT)
  131. # endif /* CONFIG_SYS_INIT_DCACHE_PBxCR */
  132. # ifndef CONFIG_SYS_INIT_RAM_PATTERN
  133. # define CONFIG_SYS_INIT_RAM_PATTERN 0xDEADDEAD
  134. # endif
  135. #endif /* CONFIG_SYS_INIT_DCACHE_CS */
  136. #if (defined(CONFIG_SYS_INIT_RAM_DCACHE) && (CONFIG_SYS_INIT_RAM_SIZE > (4 << 10)))
  137. #error Only 4k of init-ram is supported - please adjust CONFIG_SYS_INIT_RAM_SIZE!
  138. #endif
  139. /*
  140. * Unless otherwise overridden, enable two 128MB cachable instruction regions
  141. * at CONFIG_SYS_SDRAM_BASE and another 128MB cacheable instruction region covering
  142. * NOR flash at CONFIG_SYS_FLASH_BASE. Disable all cacheable data regions.
  143. */
  144. #if !defined(CONFIG_SYS_FLASH_BASE)
  145. /* If not already defined, set it to the "last" 128MByte region */
  146. # define CONFIG_SYS_FLASH_BASE 0xf8000000
  147. #endif
  148. #if !defined(CONFIG_SYS_ICACHE_SACR_VALUE)
  149. # define CONFIG_SYS_ICACHE_SACR_VALUE \
  150. (PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + ( 0 << 20)) | \
  151. PPC_128MB_SACR_VALUE(CONFIG_SYS_SDRAM_BASE + (128 << 20)) | \
  152. PPC_128MB_SACR_VALUE(CONFIG_SYS_FLASH_BASE))
  153. #endif /* !defined(CONFIG_SYS_ICACHE_SACR_VALUE) */
  154. #if !defined(CONFIG_SYS_DCACHE_SACR_VALUE)
  155. # define CONFIG_SYS_DCACHE_SACR_VALUE \
  156. (0x00000000)
  157. #endif /* !defined(CONFIG_SYS_DCACHE_SACR_VALUE) */
  158. #if !defined(CONFIG_SYS_TLB_FOR_BOOT_FLASH)
  159. #define CONFIG_SYS_TLB_FOR_BOOT_FLASH 0 /* use TLB 0 as default */
  160. #endif
  161. #define function_prolog(func_name) .text; \
  162. .align 2; \
  163. .globl func_name; \
  164. func_name:
  165. #define function_epilog(func_name) .type func_name,@function; \
  166. .size func_name,.-func_name
  167. /* We don't want the MMU yet.
  168. */
  169. #undef MSR_KERNEL
  170. #define MSR_KERNEL ( MSR_ME ) /* Machine Check */
  171. .extern ext_bus_cntlr_init
  172. /*
  173. * Set up GOT: Global Offset Table
  174. *
  175. * Use r12 to access the GOT
  176. */
  177. #if !defined(CONFIG_SPL_BUILD)
  178. START_GOT
  179. GOT_ENTRY(_GOT2_TABLE_)
  180. GOT_ENTRY(_FIXUP_TABLE_)
  181. GOT_ENTRY(_start)
  182. GOT_ENTRY(_start_of_vectors)
  183. GOT_ENTRY(_end_of_vectors)
  184. GOT_ENTRY(transfer_to_handler)
  185. GOT_ENTRY(__init_end)
  186. GOT_ENTRY(__bss_end)
  187. GOT_ENTRY(__bss_start)
  188. END_GOT
  189. #endif /* CONFIG_SPL_BUILD */
  190. #if defined(CONFIG_SYS_RAMBOOT) || defined(CONFIG_BOOT_FROM_XMD)
  191. /*
  192. * 4xx RAM-booting U-Boot image is started from offset 0
  193. */
  194. .text
  195. bl _start_440
  196. #endif
  197. #if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
  198. /*
  199. * This is the entry of the real U-Boot from a board port
  200. * that supports SPL booting on the PPC4xx. We only need
  201. * to call board_init_f() here. Everything else has already
  202. * been done in the SPL u-boot version.
  203. */
  204. GET_GOT /* initialize GOT access */
  205. bl board_init_f /* run 1st part of board init code (in Flash)*/
  206. /* NOTREACHED - board_init_f() does not return */
  207. #endif
  208. /*
  209. * 440 Startup -- on reset only the top 4k of the effective
  210. * address space is mapped in by an entry in the instruction
  211. * and data shadow TLB. The .bootpg section is located in the
  212. * top 4k & does only what's necessary to map in the the rest
  213. * of the boot rom. Once the boot rom is mapped in we can
  214. * proceed with normal startup.
  215. *
  216. * NOTE: CS0 only covers the top 2MB of the effective address
  217. * space after reset.
  218. */
  219. #if defined(CONFIG_440)
  220. .section .bootpg,"ax"
  221. .globl _start_440
  222. /**************************************************************************/
  223. _start_440:
  224. /*--------------------------------------------------------------------+
  225. | 440EPX BUP Change - Hardware team request
  226. +--------------------------------------------------------------------*/
  227. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  228. sync
  229. nop
  230. nop
  231. #endif
  232. /*----------------------------------------------------------------+
  233. | Core bug fix. Clear the esr
  234. +-----------------------------------------------------------------*/
  235. li r0,0
  236. mtspr SPRN_ESR,r0
  237. /*----------------------------------------------------------------*/
  238. /* Clear and set up some registers. */
  239. /*----------------------------------------------------------------*/
  240. iccci r0,r0 /* NOTE: operands not used for 440 */
  241. dccci r0,r0 /* NOTE: operands not used for 440 */
  242. sync
  243. li r0,0
  244. mtspr SPRN_SRR0,r0
  245. mtspr SPRN_SRR1,r0
  246. mtspr SPRN_CSRR0,r0
  247. mtspr SPRN_CSRR1,r0
  248. /* NOTE: 440GX adds machine check status regs */
  249. #if defined(CONFIG_440) && !defined(CONFIG_440GP)
  250. mtspr SPRN_MCSRR0,r0
  251. mtspr SPRN_MCSRR1,r0
  252. mfspr r1,SPRN_MCSR
  253. mtspr SPRN_MCSR,r1
  254. #endif
  255. /*----------------------------------------------------------------*/
  256. /* CCR0 init */
  257. /*----------------------------------------------------------------*/
  258. /* Disable store gathering & broadcast, guarantee inst/data
  259. * cache block touch, force load/store alignment
  260. * (see errata 1.12: 440_33)
  261. */
  262. lis r1,0x0030 /* store gathering & broadcast disable */
  263. ori r1,r1,0x6000 /* cache touch */
  264. mtspr SPRN_CCR0,r1
  265. /*----------------------------------------------------------------*/
  266. /* Initialize debug */
  267. /*----------------------------------------------------------------*/
  268. mfspr r1,SPRN_DBCR0
  269. andis. r1, r1, 0x8000 /* test DBCR0[EDM] bit */
  270. bne skip_debug_init /* if set, don't clear debug register */
  271. mfspr r1,SPRN_CCR0
  272. ori r1,r1,CCR0_DTB@l /* Disable Trace Broadcast */
  273. mtspr SPRN_CCR0,r1
  274. mtspr SPRN_DBCR0,r0
  275. mtspr SPRN_DBCR1,r0
  276. mtspr SPRN_DBCR2,r0
  277. mtspr SPRN_IAC1,r0
  278. mtspr SPRN_IAC2,r0
  279. mtspr SPRN_IAC3,r0
  280. mtspr SPRN_DAC1,r0
  281. mtspr SPRN_DAC2,r0
  282. mtspr SPRN_DVC1,r0
  283. mtspr SPRN_DVC2,r0
  284. mfspr r1,SPRN_DBSR
  285. mtspr SPRN_DBSR,r1 /* Clear all valid bits */
  286. skip_debug_init:
  287. #if defined (CONFIG_440SPE)
  288. /*----------------------------------------------------------------+
  289. | Initialize Core Configuration Reg1.
  290. | a. ICDPEI: Record even parity. Normal operation.
  291. | b. ICTPEI: Record even parity. Normal operation.
  292. | c. DCTPEI: Record even parity. Normal operation.
  293. | d. DCDPEI: Record even parity. Normal operation.
  294. | e. DCUPEI: Record even parity. Normal operation.
  295. | f. DCMPEI: Record even parity. Normal operation.
  296. | g. FCOM: Normal operation
  297. | h. MMUPEI: Record even parity. Normal operation.
  298. | i. FFF: Flush only as much data as necessary.
  299. | j. TCS: Timebase increments from CPU clock.
  300. +-----------------------------------------------------------------*/
  301. li r0,0
  302. mtspr SPRN_CCR1, r0
  303. /*----------------------------------------------------------------+
  304. | Reset the timebase.
  305. | The previous write to CCR1 sets the timebase source.
  306. +-----------------------------------------------------------------*/
  307. mtspr SPRN_TBWL, r0
  308. mtspr SPRN_TBWU, r0
  309. #endif
  310. /*----------------------------------------------------------------*/
  311. /* Setup interrupt vectors */
  312. /*----------------------------------------------------------------*/
  313. mtspr SPRN_IVPR,r0 /* Vectors start at 0x0000_0000 */
  314. li r1,0x0100
  315. mtspr SPRN_IVOR0,r1 /* Critical input */
  316. li r1,0x0200
  317. mtspr SPRN_IVOR1,r1 /* Machine check */
  318. li r1,0x0300
  319. mtspr SPRN_IVOR2,r1 /* Data storage */
  320. li r1,0x0400
  321. mtspr SPRN_IVOR3,r1 /* Instruction storage */
  322. li r1,0x0500
  323. mtspr SPRN_IVOR4,r1 /* External interrupt */
  324. li r1,0x0600
  325. mtspr SPRN_IVOR5,r1 /* Alignment */
  326. li r1,0x0700
  327. mtspr SPRN_IVOR6,r1 /* Program check */
  328. li r1,0x0800
  329. mtspr SPRN_IVOR7,r1 /* Floating point unavailable */
  330. li r1,0x0c00
  331. mtspr SPRN_IVOR8,r1 /* System call */
  332. li r1,0x0a00
  333. mtspr SPRN_IVOR9,r1 /* Auxiliary Processor unavailable */
  334. li r1,0x0900
  335. mtspr SPRN_IVOR10,r1 /* Decrementer */
  336. li r1,0x1300
  337. mtspr SPRN_IVOR13,r1 /* Data TLB error */
  338. li r1,0x1400
  339. mtspr SPRN_IVOR14,r1 /* Instr TLB error */
  340. li r1,0x2000
  341. mtspr SPRN_IVOR15,r1 /* Debug */
  342. /*----------------------------------------------------------------*/
  343. /* Configure cache regions */
  344. /*----------------------------------------------------------------*/
  345. mtspr SPRN_INV0,r0
  346. mtspr SPRN_INV1,r0
  347. mtspr SPRN_INV2,r0
  348. mtspr SPRN_INV3,r0
  349. mtspr SPRN_DNV0,r0
  350. mtspr SPRN_DNV1,r0
  351. mtspr SPRN_DNV2,r0
  352. mtspr SPRN_DNV3,r0
  353. mtspr SPRN_ITV0,r0
  354. mtspr SPRN_ITV1,r0
  355. mtspr SPRN_ITV2,r0
  356. mtspr SPRN_ITV3,r0
  357. mtspr SPRN_DTV0,r0
  358. mtspr SPRN_DTV1,r0
  359. mtspr SPRN_DTV2,r0
  360. mtspr SPRN_DTV3,r0
  361. /*----------------------------------------------------------------*/
  362. /* Cache victim limits */
  363. /*----------------------------------------------------------------*/
  364. /* floors 0, ceiling max to use the entire cache -- nothing locked
  365. */
  366. lis r1,0x0001
  367. ori r1,r1,0xf800
  368. mtspr SPRN_IVLIM,r1
  369. mtspr SPRN_DVLIM,r1
  370. /*----------------------------------------------------------------+
  371. |Initialize MMUCR[STID] = 0.
  372. +-----------------------------------------------------------------*/
  373. mfspr r0,SPRN_MMUCR
  374. addis r1,0,0xFFFF
  375. ori r1,r1,0xFF00
  376. and r0,r0,r1
  377. mtspr SPRN_MMUCR,r0
  378. /*----------------------------------------------------------------*/
  379. /* Clear all TLB entries -- TID = 0, TS = 0 */
  380. /*----------------------------------------------------------------*/
  381. addis r0,0,0x0000
  382. #ifdef CONFIG_SYS_RAMBOOT
  383. li r4,0 /* Start with TLB #0 */
  384. #else
  385. li r4,1 /* Start with TLB #1 */
  386. #endif
  387. li r1,64 /* 64 TLB entries */
  388. sub r1,r1,r4 /* calculate last TLB # */
  389. mtctr r1
  390. rsttlb:
  391. #ifdef CONFIG_SYS_RAMBOOT
  392. tlbre r3,r4,0 /* Read contents from TLB word #0 to get EPN */
  393. rlwinm. r3,r3,0,0xfffffc00 /* Mask EPN */
  394. beq tlbnxt /* Skip EPN=0 TLB, this is the SDRAM TLB */
  395. #endif
  396. tlbwe r0,r4,0 /* Invalidate all entries (V=0)*/
  397. tlbwe r0,r4,1
  398. tlbwe r0,r4,2
  399. tlbnxt: addi r4,r4,1 /* Next TLB */
  400. bdnz rsttlb
  401. /*----------------------------------------------------------------*/
  402. /* TLB entry setup -- step thru tlbtab */
  403. /*----------------------------------------------------------------*/
  404. #if defined(CONFIG_440SPE_REVA)
  405. /*----------------------------------------------------------------*/
  406. /* We have different TLB tables for revA and rev B of 440SPe */
  407. /*----------------------------------------------------------------*/
  408. mfspr r1, PVR
  409. lis r0,0x5342
  410. ori r0,r0,0x1891
  411. cmpw r7,r1,r0
  412. bne r7,..revA
  413. bl tlbtabB
  414. b ..goon
  415. ..revA:
  416. bl tlbtabA
  417. ..goon:
  418. #else
  419. bl tlbtab /* Get tlbtab pointer */
  420. #endif
  421. mr r5,r0
  422. li r1,0x003f /* 64 TLB entries max */
  423. mtctr r1
  424. li r4,0 /* TLB # */
  425. addi r5,r5,-4
  426. 1:
  427. #ifdef CONFIG_SYS_RAMBOOT
  428. tlbre r3,r4,0 /* Read contents from TLB word #0 */
  429. rlwinm. r3,r3,0,0x00000200 /* Mask V (valid) bit */
  430. bne tlbnx2 /* Skip V=1 TLB, this is the SDRAM TLB */
  431. #endif
  432. lwzu r0,4(r5)
  433. cmpwi r0,0
  434. beq 2f /* 0 marks end */
  435. lwzu r1,4(r5)
  436. lwzu r2,4(r5)
  437. tlbwe r0,r4,0 /* TLB Word 0 */
  438. tlbwe r1,r4,1 /* TLB Word 1 */
  439. tlbwe r2,r4,2 /* TLB Word 2 */
  440. tlbnx2: addi r4,r4,1 /* Next TLB */
  441. bdnz 1b
  442. /*----------------------------------------------------------------*/
  443. /* Continue from 'normal' start */
  444. /*----------------------------------------------------------------*/
  445. 2:
  446. bl 3f
  447. b _start
  448. 3: li r0,0
  449. mtspr SPRN_SRR1,r0 /* Keep things disabled for now */
  450. mflr r1
  451. mtspr SPRN_SRR0,r1
  452. rfi
  453. #endif /* CONFIG_440 */
  454. /*
  455. * r3 - 1st arg to board_init(): IMMP pointer
  456. * r4 - 2nd arg to board_init(): boot flag
  457. */
  458. #if !defined(CONFIG_SPL_BUILD)
  459. .text
  460. .long 0x27051956 /* U-Boot Magic Number */
  461. .globl version_string
  462. version_string:
  463. .ascii U_BOOT_VERSION_STRING, "\0"
  464. . = EXC_OFF_SYS_RESET
  465. .globl _start_of_vectors
  466. _start_of_vectors:
  467. /* Critical input. */
  468. CRIT_EXCEPTION(0x100, CritcalInput, UnknownException)
  469. #ifdef CONFIG_440
  470. /* Machine check */
  471. MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  472. #else
  473. CRIT_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  474. #endif /* CONFIG_440 */
  475. /* Data Storage exception. */
  476. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  477. /* Instruction Storage exception. */
  478. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  479. /* External Interrupt exception. */
  480. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  481. /* Alignment exception. */
  482. . = 0x600
  483. Alignment:
  484. EXCEPTION_PROLOG(SRR0, SRR1)
  485. mfspr r4,DAR
  486. stw r4,_DAR(r21)
  487. mfspr r5,DSISR
  488. stw r5,_DSISR(r21)
  489. addi r3,r1,STACK_FRAME_OVERHEAD
  490. EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
  491. /* Program check exception */
  492. . = 0x700
  493. ProgramCheck:
  494. EXCEPTION_PROLOG(SRR0, SRR1)
  495. addi r3,r1,STACK_FRAME_OVERHEAD
  496. EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
  497. MSR_KERNEL, COPY_EE)
  498. #ifdef CONFIG_440
  499. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  500. STD_EXCEPTION(0x900, Decrementer, DecrementerPITException)
  501. STD_EXCEPTION(0xa00, APU, UnknownException)
  502. #endif
  503. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  504. #ifdef CONFIG_440
  505. STD_EXCEPTION(0x1300, DataTLBError, UnknownException)
  506. STD_EXCEPTION(0x1400, InstructionTLBError, UnknownException)
  507. #else
  508. STD_EXCEPTION(0x1000, PIT, DecrementerPITException)
  509. STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
  510. STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
  511. #endif
  512. CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
  513. .globl _end_of_vectors
  514. _end_of_vectors:
  515. . = _START_OFFSET
  516. #endif
  517. .globl _start
  518. _start:
  519. #if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
  520. /*
  521. * This is the entry of the real U-Boot from a board port
  522. * that supports SPL booting on the PPC4xx. We only need
  523. * to call board_init_f() here. Everything else has already
  524. * been done in the SPL u-boot version.
  525. */
  526. GET_GOT /* initialize GOT access */
  527. bl board_init_f /* run 1st part of board init code (in Flash)*/
  528. /* NOTREACHED - board_init_f() does not return */
  529. #endif
  530. /*****************************************************************************/
  531. #if defined(CONFIG_440)
  532. /*----------------------------------------------------------------*/
  533. /* Clear and set up some registers. */
  534. /*----------------------------------------------------------------*/
  535. li r0,0x0000
  536. lis r1,0xffff
  537. mtspr SPRN_DEC,r0 /* prevent dec exceptions */
  538. mtspr SPRN_TBWL,r0 /* prevent fit & wdt exceptions */
  539. mtspr SPRN_TBWU,r0
  540. mtspr SPRN_TSR,r1 /* clear all timer exception status */
  541. mtspr SPRN_TCR,r0 /* disable all */
  542. mtspr SPRN_ESR,r0 /* clear exception syndrome register */
  543. mtxer r0 /* clear integer exception register */
  544. /*----------------------------------------------------------------*/
  545. /* Debug setup -- some (not very good) ice's need an event*/
  546. /* to establish control :-( Define CONFIG_SYS_INIT_DBCR to the dbsr */
  547. /* value you need in this case 0x8cff 0000 should do the trick */
  548. /*----------------------------------------------------------------*/
  549. #if defined(CONFIG_SYS_INIT_DBCR)
  550. lis r1,0xffff
  551. ori r1,r1,0xffff
  552. mtspr SPRN_DBSR,r1 /* Clear all status bits */
  553. lis r0,CONFIG_SYS_INIT_DBCR@h
  554. ori r0,r0,CONFIG_SYS_INIT_DBCR@l
  555. mtspr SPRN_DBCR0,r0
  556. isync
  557. #endif
  558. /*----------------------------------------------------------------*/
  559. /* Setup the internal SRAM */
  560. /*----------------------------------------------------------------*/
  561. li r0,0
  562. #ifdef CONFIG_SYS_INIT_RAM_DCACHE
  563. /* Clear Dcache to use as RAM */
  564. addis r3,r0,CONFIG_SYS_INIT_RAM_ADDR@h
  565. ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
  566. addis r4,r0,CONFIG_SYS_INIT_RAM_SIZE@h
  567. ori r4,r4,CONFIG_SYS_INIT_RAM_SIZE@l
  568. rlwinm. r5,r4,0,27,31
  569. rlwinm r5,r4,27,5,31
  570. beq ..d_ran
  571. addi r5,r5,0x0001
  572. ..d_ran:
  573. mtctr r5
  574. ..d_ag:
  575. dcbz r0,r3
  576. addi r3,r3,32
  577. bdnz ..d_ag
  578. /*
  579. * Lock the init-ram/stack in d-cache, so that other regions
  580. * may use d-cache as well
  581. * Note, that this current implementation locks exactly 4k
  582. * of d-cache, so please make sure that you don't define a
  583. * bigger init-ram area. Take a look at the lwmon5 440EPx
  584. * implementation as a reference.
  585. */
  586. msync
  587. isync
  588. /* 8. set TFLOOR/NFLOOR to 8 (-> 8*16*32 bytes locked -> 4k) */
  589. lis r1,0x0201
  590. ori r1,r1,0xf808
  591. mtspr SPRN_DVLIM,r1
  592. lis r1,0x0808
  593. ori r1,r1,0x0808
  594. mtspr SPRN_DNV0,r1
  595. mtspr SPRN_DNV1,r1
  596. mtspr SPRN_DNV2,r1
  597. mtspr SPRN_DNV3,r1
  598. mtspr SPRN_DTV0,r1
  599. mtspr SPRN_DTV1,r1
  600. mtspr SPRN_DTV2,r1
  601. mtspr SPRN_DTV3,r1
  602. msync
  603. isync
  604. #endif /* CONFIG_SYS_INIT_RAM_DCACHE */
  605. /* 440EP & 440GR are only 440er PPC's without internal SRAM */
  606. #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR)
  607. /* not all PPC's have internal SRAM usable as L2-cache */
  608. #if defined(CONFIG_440GX) || \
  609. defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
  610. defined(CONFIG_460SX)
  611. mtdcr L2_CACHE_CFG,r0 /* Ensure L2 Cache is off */
  612. #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
  613. lis r1, 0x0000
  614. ori r1,r1,0x0008 /* Set L2_CACHE_CFG[RDBW]=1 */
  615. mtdcr L2_CACHE_CFG,r1
  616. #endif
  617. lis r2,0x7fff
  618. ori r2,r2,0xffff
  619. mfdcr r1,ISRAM0_DPC
  620. and r1,r1,r2 /* Disable parity check */
  621. mtdcr ISRAM0_DPC,r1
  622. mfdcr r1,ISRAM0_PMEG
  623. and r1,r1,r2 /* Disable pwr mgmt */
  624. mtdcr ISRAM0_PMEG,r1
  625. lis r1,0x8000 /* BAS = 8000_0000 */
  626. #if defined(CONFIG_440GX) || defined(CONFIG_440SP)
  627. ori r1,r1,0x0980 /* first 64k */
  628. mtdcr ISRAM0_SB0CR,r1
  629. lis r1,0x8001
  630. ori r1,r1,0x0980 /* second 64k */
  631. mtdcr ISRAM0_SB1CR,r1
  632. lis r1, 0x8002
  633. ori r1,r1, 0x0980 /* third 64k */
  634. mtdcr ISRAM0_SB2CR,r1
  635. lis r1, 0x8003
  636. ori r1,r1, 0x0980 /* fourth 64k */
  637. mtdcr ISRAM0_SB3CR,r1
  638. #elif defined(CONFIG_440SPE) || defined(CONFIG_460EX) || \
  639. defined(CONFIG_460GT)
  640. lis r1,0x0000 /* BAS = X_0000_0000 */
  641. ori r1,r1,0x0984 /* first 64k */
  642. mtdcr ISRAM0_SB0CR,r1
  643. lis r1,0x0001
  644. ori r1,r1,0x0984 /* second 64k */
  645. mtdcr ISRAM0_SB1CR,r1
  646. lis r1, 0x0002
  647. ori r1,r1, 0x0984 /* third 64k */
  648. mtdcr ISRAM0_SB2CR,r1
  649. lis r1, 0x0003
  650. ori r1,r1, 0x0984 /* fourth 64k */
  651. mtdcr ISRAM0_SB3CR,r1
  652. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  653. lis r2,0x7fff
  654. ori r2,r2,0xffff
  655. mfdcr r1,ISRAM1_DPC
  656. and r1,r1,r2 /* Disable parity check */
  657. mtdcr ISRAM1_DPC,r1
  658. mfdcr r1,ISRAM1_PMEG
  659. and r1,r1,r2 /* Disable pwr mgmt */
  660. mtdcr ISRAM1_PMEG,r1
  661. lis r1,0x0004 /* BAS = 4_0004_0000 */
  662. ori r1,r1,ISRAM1_SIZE /* ocm size */
  663. mtdcr ISRAM1_SB0CR,r1
  664. #endif
  665. #elif defined(CONFIG_460SX)
  666. lis r1,0x0000 /* BAS = 0000_0000 */
  667. ori r1,r1,0x0B84 /* first 128k */
  668. mtdcr ISRAM0_SB0CR,r1
  669. lis r1,0x0001
  670. ori r1,r1,0x0B84 /* second 128k */
  671. mtdcr ISRAM0_SB1CR,r1
  672. lis r1, 0x0002
  673. ori r1,r1, 0x0B84 /* third 128k */
  674. mtdcr ISRAM0_SB2CR,r1
  675. lis r1, 0x0003
  676. ori r1,r1, 0x0B84 /* fourth 128k */
  677. mtdcr ISRAM0_SB3CR,r1
  678. #elif defined(CONFIG_440GP)
  679. ori r1,r1,0x0380 /* 8k rw */
  680. mtdcr ISRAM0_SB0CR,r1
  681. mtdcr ISRAM0_SB1CR,r0 /* Disable bank 1 */
  682. #endif
  683. #endif /* #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR) */
  684. /*----------------------------------------------------------------*/
  685. /* Setup the stack in internal SRAM */
  686. /*----------------------------------------------------------------*/
  687. lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@h
  688. ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@l
  689. /*
  690. * Reserve space for globals and store address for initialization
  691. * with board_init_f_init_reserve() in r14
  692. */
  693. mr r3, r1
  694. bl board_init_f_alloc_reserve
  695. mr r1, r3
  696. mr r14, r3
  697. li r0,0
  698. stwu r0,-4(r1)
  699. stwu r0,-4(r1) /* Terminate call chain */
  700. stwu r1,-8(r1) /* Save back chain and move SP */
  701. lis r0,RESET_VECTOR@h /* Address of reset vector */
  702. ori r0,r0, RESET_VECTOR@l
  703. stwu r1,-8(r1) /* Save back chain and move SP */
  704. stw r0,+12(r1) /* Save return addr (underflow vect) */
  705. #ifndef CONFIG_SPL_BUILD
  706. GET_GOT
  707. #endif
  708. bl cpu_init_f /* run low-level CPU init code (from Flash) */
  709. /* address for globals was stored in r14 */
  710. mr r3, r14
  711. bl board_init_f_init_reserve
  712. li r3, 0
  713. bl board_init_f
  714. /* NOTREACHED - board_init_f() does not return */
  715. #endif /* CONFIG_440 */
  716. /*****************************************************************************/
  717. #if defined(CONFIG_405GP) || \
  718. defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
  719. defined(CONFIG_405EX) || defined(CONFIG_405)
  720. /*----------------------------------------------------------------------- */
  721. /* Clear and set up some registers. */
  722. /*----------------------------------------------------------------------- */
  723. addi r4,r0,0x0000
  724. #if !defined(CONFIG_405EX)
  725. mtspr SPRN_SGR,r4
  726. #else
  727. /*
  728. * On 405EX, completely clearing the SGR leads to PPC hangup
  729. * upon PCIe configuration access. The PCIe memory regions
  730. * need to be guarded!
  731. */
  732. lis r3,0x0000
  733. ori r3,r3,0x7FFC
  734. mtspr SPRN_SGR,r3
  735. #endif
  736. mtspr SPRN_DCWR,r4
  737. mtesr r4 /* clear Exception Syndrome Reg */
  738. mttcr r4 /* clear Timer Control Reg */
  739. mtxer r4 /* clear Fixed-Point Exception Reg */
  740. mtevpr r4 /* clear Exception Vector Prefix Reg */
  741. addi r4,r0,(0xFFFF-0x10000) /* set r4 to 0xFFFFFFFF (status in the */
  742. /* dbsr is cleared by setting bits to 1) */
  743. mtdbsr r4 /* clear/reset the dbsr */
  744. /* Invalidate the i- and d-caches. */
  745. bl invalidate_icache
  746. bl invalidate_dcache
  747. /* Set-up icache cacheability. */
  748. lis r4, CONFIG_SYS_ICACHE_SACR_VALUE@h
  749. ori r4, r4, CONFIG_SYS_ICACHE_SACR_VALUE@l
  750. mticcr r4
  751. isync
  752. /* Set-up dcache cacheability. */
  753. lis r4, CONFIG_SYS_DCACHE_SACR_VALUE@h
  754. ori r4, r4, CONFIG_SYS_DCACHE_SACR_VALUE@l
  755. mtdccr r4
  756. #if !(defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))\
  757. && !defined (CONFIG_XILINX_405)
  758. /*----------------------------------------------------------------------- */
  759. /* Tune the speed and size for flash CS0 */
  760. /*----------------------------------------------------------------------- */
  761. bl ext_bus_cntlr_init
  762. #endif
  763. #if !(defined(CONFIG_SYS_INIT_DCACHE_CS) || defined(CONFIG_SYS_TEMP_STACK_OCM))
  764. /*
  765. * For boards that don't have OCM and can't use the data cache
  766. * for their primordial stack, setup stack here directly after the
  767. * SDRAM is initialized in ext_bus_cntlr_init.
  768. */
  769. lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@h
  770. ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@l
  771. /*
  772. * Reserve space for globals and store address for initialization
  773. * with board_init_f_init_reserve() in r14
  774. */
  775. mr r3, r1
  776. bl board_init_f_alloc_reserve
  777. mr r1, r3
  778. mr r14, r3
  779. li r0, 0 /* Make room for stack frame header and */
  780. stwu r0, -4(r1) /* clear final stack frame so that */
  781. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  782. /*
  783. * Set up a dummy frame to store reset vector as return address.
  784. * this causes stack underflow to reset board.
  785. */
  786. stwu r1, -8(r1) /* Save back chain and move SP */
  787. lis r0, RESET_VECTOR@h /* Address of reset vector */
  788. ori r0, r0, RESET_VECTOR@l
  789. stwu r1, -8(r1) /* Save back chain and move SP */
  790. stw r0, +12(r1) /* Save return addr (underflow vect) */
  791. #endif /* !(CONFIG_SYS_INIT_DCACHE_CS || !CONFIG_SYS_TEM_STACK_OCM) */
  792. #if defined(CONFIG_405EP)
  793. /*----------------------------------------------------------------------- */
  794. /* DMA Status, clear to come up clean */
  795. /*----------------------------------------------------------------------- */
  796. addis r3,r0, 0xFFFF /* Clear all existing DMA status */
  797. ori r3,r3, 0xFFFF
  798. mtdcr DMASR, r3
  799. bl ppc405ep_init /* do ppc405ep specific init */
  800. #endif /* CONFIG_405EP */
  801. #if defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE)
  802. #if defined(CONFIG_405EZ)
  803. /********************************************************************
  804. * Setup OCM - On Chip Memory - PPC405EZ uses OCM Controller V2
  805. *******************************************************************/
  806. /*
  807. * We can map the OCM on the PLB3, so map it at
  808. * CONFIG_SYS_OCM_DATA_ADDR + 0x8000
  809. */
  810. lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
  811. ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
  812. ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
  813. mtdcr OCM0_PLBCR1,r3 /* Set PLB Access */
  814. ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
  815. mtdcr OCM0_PLBCR2,r3 /* Set PLB Access */
  816. isync
  817. lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
  818. ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
  819. ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
  820. mtdcr OCM0_DSRC1, r3 /* Set Data Side */
  821. mtdcr OCM0_ISRC1, r3 /* Set Instruction Side */
  822. ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
  823. mtdcr OCM0_DSRC2, r3 /* Set Data Side */
  824. mtdcr OCM0_ISRC2, r3 /* Set Instruction Side */
  825. addis r3,0,0x0800 /* OCM Data Parity Disable - 1 Wait State */
  826. mtdcr OCM0_DISDPC,r3
  827. isync
  828. #else /* CONFIG_405EZ */
  829. /********************************************************************
  830. * Setup OCM - On Chip Memory
  831. *******************************************************************/
  832. /* Setup OCM */
  833. lis r0, 0x7FFF
  834. ori r0, r0, 0xFFFF
  835. mfdcr r3, OCM0_ISCNTL /* get instr-side IRAM config */
  836. mfdcr r4, OCM0_DSCNTL /* get data-side IRAM config */
  837. and r3, r3, r0 /* disable data-side IRAM */
  838. and r4, r4, r0 /* disable data-side IRAM */
  839. mtdcr OCM0_ISCNTL, r3 /* set instr-side IRAM config */
  840. mtdcr OCM0_DSCNTL, r4 /* set data-side IRAM config */
  841. isync
  842. lis r3,CONFIG_SYS_OCM_DATA_ADDR@h /* OCM location */
  843. ori r3,r3,CONFIG_SYS_OCM_DATA_ADDR@l
  844. mtdcr OCM0_DSARC, r3
  845. addis r4, 0, 0xC000 /* OCM data area enabled */
  846. mtdcr OCM0_DSCNTL, r4
  847. isync
  848. #endif /* CONFIG_405EZ */
  849. #endif
  850. /*----------------------------------------------------------------------- */
  851. /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */
  852. /*----------------------------------------------------------------------- */
  853. #ifdef CONFIG_SYS_INIT_DCACHE_CS
  854. li r4, PBxAP
  855. mtdcr EBC0_CFGADDR, r4
  856. lis r4, CONFIG_SYS_INIT_DCACHE_PBxAR@h
  857. ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxAR@l
  858. mtdcr EBC0_CFGDATA, r4
  859. addi r4, 0, PBxCR
  860. mtdcr EBC0_CFGADDR, r4
  861. lis r4, CONFIG_SYS_INIT_DCACHE_PBxCR@h
  862. ori r4, r4, CONFIG_SYS_INIT_DCACHE_PBxCR@l
  863. mtdcr EBC0_CFGDATA, r4
  864. /*
  865. * Enable the data cache for the 128MB storage access control region
  866. * at CONFIG_SYS_INIT_RAM_ADDR.
  867. */
  868. mfdccr r4
  869. oris r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
  870. ori r4, r4, PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
  871. mtdccr r4
  872. /*
  873. * Preallocate data cache lines to be used to avoid a subsequent
  874. * cache miss and an ensuing machine check exception when exceptions
  875. * are enabled.
  876. */
  877. li r0, 0
  878. lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
  879. ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
  880. lis r4, CONFIG_SYS_INIT_RAM_SIZE@h
  881. ori r4, r4, CONFIG_SYS_INIT_RAM_SIZE@l
  882. /*
  883. * Convert the size, in bytes, to the number of cache lines/blocks
  884. * to preallocate.
  885. */
  886. clrlwi. r5, r4, (32 - L1_CACHE_SHIFT)
  887. srwi r5, r4, L1_CACHE_SHIFT
  888. beq ..load_counter
  889. addi r5, r5, 0x0001
  890. ..load_counter:
  891. mtctr r5
  892. /* Preallocate the computed number of cache blocks. */
  893. ..alloc_dcache_block:
  894. dcba r0, r3
  895. addi r3, r3, L1_CACHE_BYTES
  896. bdnz ..alloc_dcache_block
  897. sync
  898. /*
  899. * Load the initial stack pointer and data area and convert the size,
  900. * in bytes, to the number of words to initialize to a known value.
  901. */
  902. lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@h
  903. ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@l
  904. /*
  905. * Reserve space for globals and store address for initialization
  906. * with board_init_f_init_reserve() in r14
  907. */
  908. mr r3, r1
  909. bl board_init_f_alloc_reserve
  910. mr r1, r3
  911. mr r14, r3
  912. lis r4, (CONFIG_SYS_INIT_RAM_SIZE >> 2)@h
  913. ori r4, r4, (CONFIG_SYS_INIT_RAM_SIZE >> 2)@l
  914. mtctr r4
  915. lis r2, CONFIG_SYS_INIT_RAM_ADDR@h
  916. ori r2, r2, CONFIG_SYS_INIT_RAM_SIZE@l
  917. lis r4, CONFIG_SYS_INIT_RAM_PATTERN@h
  918. ori r4, r4, CONFIG_SYS_INIT_RAM_PATTERN@l
  919. ..stackloop:
  920. stwu r4, -4(r2)
  921. bdnz ..stackloop
  922. /*
  923. * Make room for stack frame header and clear final stack frame so
  924. * that stack backtraces terminate cleanly.
  925. */
  926. li r0, 0
  927. stwu r0, -4(r1)
  928. stwu r0, -4(r1)
  929. /*
  930. * Set up a dummy frame to store reset vector as return address.
  931. * this causes stack underflow to reset board.
  932. */
  933. stwu r1, -8(r1) /* Save back chain and move SP */
  934. addis r0, 0, RESET_VECTOR@h /* Address of reset vector */
  935. ori r0, r0, RESET_VECTOR@l
  936. stwu r1, -8(r1) /* Save back chain and move SP */
  937. stw r0, +12(r1) /* Save return addr (underflow vect) */
  938. #elif defined(CONFIG_SYS_TEMP_STACK_OCM) && \
  939. (defined(CONFIG_SYS_OCM_DATA_ADDR) && defined(CONFIG_SYS_OCM_DATA_SIZE))
  940. /*
  941. * Stack in OCM.
  942. */
  943. lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@h
  944. ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@l
  945. /*
  946. * Reserve space for globals and store address for initialization
  947. * with board_init_f_init_reserve() in r14
  948. */
  949. mr r3, r1
  950. bl board_init_f_alloc_reserve
  951. mr r1, r3
  952. mr r14, r3
  953. /* Set up a zeroized stack frame so that backtrace works right */
  954. li r0, 0
  955. stwu r0, -4(r1)
  956. stwu r0, -4(r1)
  957. /*
  958. * Set up a dummy frame to store reset vector as return address.
  959. * this causes stack underflow to reset board.
  960. */
  961. stwu r1, -8(r1) /* Save back chain and move SP */
  962. lis r0, RESET_VECTOR@h /* Address of reset vector */
  963. ori r0, r0, RESET_VECTOR@l
  964. stwu r1, -8(r1) /* Save back chain and move SP */
  965. stw r0, +12(r1) /* Save return addr (underflow vect) */
  966. #endif /* CONFIG_SYS_INIT_DCACHE_CS */
  967. GET_GOT /* initialize GOT access */
  968. bl cpu_init_f /* run low-level CPU init code (from Flash) */
  969. /* address for globals was stored in r14 */
  970. mr r3, r14
  971. bl board_init_f_init_reserve
  972. li r3, 0
  973. bl board_init_f /* run first part of init code (from Flash) */
  974. /* NOTREACHED - board_init_f() does not return */
  975. #endif /* CONFIG_405GP || CONFIG_405 || CONFIG_405EP */
  976. /*----------------------------------------------------------------------- */
  977. #if !defined(CONFIG_SPL_BUILD)
  978. /*
  979. * This code finishes saving the registers to the exception frame
  980. * and jumps to the appropriate handler for the exception.
  981. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  982. */
  983. .globl transfer_to_handler
  984. transfer_to_handler:
  985. stw r22,_NIP(r21)
  986. lis r22,MSR_POW@h
  987. andc r23,r23,r22
  988. stw r23,_MSR(r21)
  989. SAVE_GPR(7, r21)
  990. SAVE_4GPRS(8, r21)
  991. SAVE_8GPRS(12, r21)
  992. SAVE_8GPRS(24, r21)
  993. mflr r23
  994. andi. r24,r23,0x3f00 /* get vector offset */
  995. stw r24,TRAP(r21)
  996. li r22,0
  997. stw r22,RESULT(r21)
  998. mtspr SPRG2,r22 /* r1 is now kernel sp */
  999. lwz r24,0(r23) /* virtual address of handler */
  1000. lwz r23,4(r23) /* where to go when done */
  1001. mtspr SRR0,r24
  1002. mtspr SRR1,r20
  1003. mtlr r23
  1004. SYNC
  1005. rfi /* jump to handler, enable MMU */
  1006. int_return:
  1007. mfmsr r28 /* Disable interrupts */
  1008. li r4,0
  1009. ori r4,r4,MSR_EE
  1010. andc r28,r28,r4
  1011. SYNC /* Some chip revs need this... */
  1012. mtmsr r28
  1013. SYNC
  1014. lwz r2,_CTR(r1)
  1015. lwz r0,_LINK(r1)
  1016. mtctr r2
  1017. mtlr r0
  1018. lwz r2,_XER(r1)
  1019. lwz r0,_CCR(r1)
  1020. mtspr XER,r2
  1021. mtcrf 0xFF,r0
  1022. REST_10GPRS(3, r1)
  1023. REST_10GPRS(13, r1)
  1024. REST_8GPRS(23, r1)
  1025. REST_GPR(31, r1)
  1026. lwz r2,_NIP(r1) /* Restore environment */
  1027. lwz r0,_MSR(r1)
  1028. mtspr SRR0,r2
  1029. mtspr SRR1,r0
  1030. lwz r0,GPR0(r1)
  1031. lwz r2,GPR2(r1)
  1032. lwz r1,GPR1(r1)
  1033. SYNC
  1034. rfi
  1035. crit_return:
  1036. mfmsr r28 /* Disable interrupts */
  1037. li r4,0
  1038. ori r4,r4,MSR_EE
  1039. andc r28,r28,r4
  1040. SYNC /* Some chip revs need this... */
  1041. mtmsr r28
  1042. SYNC
  1043. lwz r2,_CTR(r1)
  1044. lwz r0,_LINK(r1)
  1045. mtctr r2
  1046. mtlr r0
  1047. lwz r2,_XER(r1)
  1048. lwz r0,_CCR(r1)
  1049. mtspr XER,r2
  1050. mtcrf 0xFF,r0
  1051. REST_10GPRS(3, r1)
  1052. REST_10GPRS(13, r1)
  1053. REST_8GPRS(23, r1)
  1054. REST_GPR(31, r1)
  1055. lwz r2,_NIP(r1) /* Restore environment */
  1056. lwz r0,_MSR(r1)
  1057. mtspr SPRN_CSRR0,r2
  1058. mtspr SPRN_CSRR1,r0
  1059. lwz r0,GPR0(r1)
  1060. lwz r2,GPR2(r1)
  1061. lwz r1,GPR1(r1)
  1062. SYNC
  1063. rfci
  1064. #ifdef CONFIG_440
  1065. mck_return:
  1066. mfmsr r28 /* Disable interrupts */
  1067. li r4,0
  1068. ori r4,r4,MSR_EE
  1069. andc r28,r28,r4
  1070. SYNC /* Some chip revs need this... */
  1071. mtmsr r28
  1072. SYNC
  1073. lwz r2,_CTR(r1)
  1074. lwz r0,_LINK(r1)
  1075. mtctr r2
  1076. mtlr r0
  1077. lwz r2,_XER(r1)
  1078. lwz r0,_CCR(r1)
  1079. mtspr XER,r2
  1080. mtcrf 0xFF,r0
  1081. REST_10GPRS(3, r1)
  1082. REST_10GPRS(13, r1)
  1083. REST_8GPRS(23, r1)
  1084. REST_GPR(31, r1)
  1085. lwz r2,_NIP(r1) /* Restore environment */
  1086. lwz r0,_MSR(r1)
  1087. mtspr SPRN_MCSRR0,r2
  1088. mtspr SPRN_MCSRR1,r0
  1089. lwz r0,GPR0(r1)
  1090. lwz r2,GPR2(r1)
  1091. lwz r1,GPR1(r1)
  1092. SYNC
  1093. rfmci
  1094. #endif /* CONFIG_440 */
  1095. .globl get_pvr
  1096. get_pvr:
  1097. mfspr r3, PVR
  1098. blr
  1099. /*------------------------------------------------------------------------------- */
  1100. /* Function: out16 */
  1101. /* Description: Output 16 bits */
  1102. /*------------------------------------------------------------------------------- */
  1103. .globl out16
  1104. out16:
  1105. sth r4,0x0000(r3)
  1106. blr
  1107. /*------------------------------------------------------------------------------- */
  1108. /* Function: out16r */
  1109. /* Description: Byte reverse and output 16 bits */
  1110. /*------------------------------------------------------------------------------- */
  1111. .globl out16r
  1112. out16r:
  1113. sthbrx r4,r0,r3
  1114. blr
  1115. /*------------------------------------------------------------------------------- */
  1116. /* Function: out32r */
  1117. /* Description: Byte reverse and output 32 bits */
  1118. /*------------------------------------------------------------------------------- */
  1119. .globl out32r
  1120. out32r:
  1121. stwbrx r4,r0,r3
  1122. blr
  1123. /*------------------------------------------------------------------------------- */
  1124. /* Function: in16 */
  1125. /* Description: Input 16 bits */
  1126. /*------------------------------------------------------------------------------- */
  1127. .globl in16
  1128. in16:
  1129. lhz r3,0x0000(r3)
  1130. blr
  1131. /*------------------------------------------------------------------------------- */
  1132. /* Function: in16r */
  1133. /* Description: Input 16 bits and byte reverse */
  1134. /*------------------------------------------------------------------------------- */
  1135. .globl in16r
  1136. in16r:
  1137. lhbrx r3,r0,r3
  1138. blr
  1139. /*------------------------------------------------------------------------------- */
  1140. /* Function: in32r */
  1141. /* Description: Input 32 bits and byte reverse */
  1142. /*------------------------------------------------------------------------------- */
  1143. .globl in32r
  1144. in32r:
  1145. lwbrx r3,r0,r3
  1146. blr
  1147. #if !defined(CONFIG_SPL_BUILD)
  1148. /*
  1149. * void relocate_code (addr_sp, gd, addr_moni)
  1150. *
  1151. * This "function" does not return, instead it continues in RAM
  1152. * after relocating the monitor code.
  1153. *
  1154. * r3 = Relocated stack pointer
  1155. * r4 = Relocated global data pointer
  1156. * r5 = Relocated text pointer
  1157. */
  1158. .globl relocate_code
  1159. relocate_code:
  1160. #if defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS)
  1161. /*
  1162. * We need to flush the initial global data (gd_t) and bd_info
  1163. * before the dcache will be invalidated.
  1164. */
  1165. /* Save registers */
  1166. mr r9, r3
  1167. mr r10, r4
  1168. mr r11, r5
  1169. /*
  1170. * Flush complete dcache, this is faster than flushing the
  1171. * ranges for global_data and bd_info instead.
  1172. */
  1173. bl flush_dcache
  1174. #if defined(CONFIG_SYS_INIT_DCACHE_CS)
  1175. /*
  1176. * Undo the earlier data cache set-up for the primordial stack and
  1177. * data area. First, invalidate the data cache and then disable data
  1178. * cacheability for that area. Finally, restore the EBC values, if
  1179. * any.
  1180. */
  1181. /* Invalidate the primordial stack and data area in cache */
  1182. lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
  1183. ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
  1184. lis r4, CONFIG_SYS_INIT_RAM_SIZE@h
  1185. ori r4, r4, CONFIG_SYS_INIT_RAM_SIZE@l
  1186. add r4, r4, r3
  1187. bl invalidate_dcache_range
  1188. /* Disable cacheability for the region */
  1189. mfdccr r3
  1190. lis r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@h
  1191. ori r4, r4, ~PPC_128MB_SACR_VALUE(CONFIG_SYS_INIT_RAM_ADDR)@l
  1192. and r3, r3, r4
  1193. mtdccr r3
  1194. /* Restore the EBC parameters */
  1195. li r3, PBxAP
  1196. mtdcr EBC0_CFGADDR, r3
  1197. lis r3, PBxAP_VAL@h
  1198. ori r3, r3, PBxAP_VAL@l
  1199. mtdcr EBC0_CFGDATA, r3
  1200. li r3, PBxCR
  1201. mtdcr EBC0_CFGADDR, r3
  1202. lis r3, PBxCR_VAL@h
  1203. ori r3, r3, PBxCR_VAL@l
  1204. mtdcr EBC0_CFGDATA, r3
  1205. #endif /* defined(CONFIG_SYS_INIT_DCACHE_CS) */
  1206. /* Restore registers */
  1207. mr r3, r9
  1208. mr r4, r10
  1209. mr r5, r11
  1210. #endif /* defined(CONFIG_4xx_DCACHE) || defined(CONFIG_SYS_INIT_DCACHE_CS) */
  1211. #ifdef CONFIG_SYS_INIT_RAM_DCACHE
  1212. /*
  1213. * Unlock the previously locked d-cache
  1214. */
  1215. msync
  1216. isync
  1217. /* set TFLOOR/NFLOOR to 0 again */
  1218. lis r6,0x0001
  1219. ori r6,r6,0xf800
  1220. mtspr SPRN_DVLIM,r6
  1221. lis r6,0x0000
  1222. ori r6,r6,0x0000
  1223. mtspr SPRN_DNV0,r6
  1224. mtspr SPRN_DNV1,r6
  1225. mtspr SPRN_DNV2,r6
  1226. mtspr SPRN_DNV3,r6
  1227. mtspr SPRN_DTV0,r6
  1228. mtspr SPRN_DTV1,r6
  1229. mtspr SPRN_DTV2,r6
  1230. mtspr SPRN_DTV3,r6
  1231. msync
  1232. isync
  1233. /* Invalidate data cache, now no longer our stack */
  1234. dccci 0,0
  1235. sync
  1236. isync
  1237. #endif /* CONFIG_SYS_INIT_RAM_DCACHE */
  1238. /*
  1239. * On some 440er platforms the cache is enabled in the first TLB (Boot-CS)
  1240. * to speed up the boot process. Now this cache needs to be disabled.
  1241. */
  1242. #if defined(CONFIG_440)
  1243. /* Clear all potential pending exceptions */
  1244. mfspr r1,SPRN_MCSR
  1245. mtspr SPRN_MCSR,r1
  1246. addi r1,r0,CONFIG_SYS_TLB_FOR_BOOT_FLASH /* Use defined TLB */
  1247. tlbre r0,r1,0x0002 /* Read contents */
  1248. ori r0,r0,0x0c00 /* Or in the inhibit, write through bit */
  1249. tlbwe r0,r1,0x0002 /* Save it out */
  1250. sync
  1251. isync
  1252. #endif /* defined(CONFIG_440) */
  1253. mr r1, r3 /* Set new stack pointer */
  1254. mr r9, r4 /* Save copy of Init Data pointer */
  1255. mr r10, r5 /* Save copy of Destination Address */
  1256. GET_GOT
  1257. mr r3, r5 /* Destination Address */
  1258. lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  1259. ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
  1260. lwz r5, GOT(__init_end)
  1261. sub r5, r5, r4
  1262. li r6, L1_CACHE_BYTES /* Cache Line Size */
  1263. /*
  1264. * Fix GOT pointer:
  1265. *
  1266. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  1267. *
  1268. * Offset:
  1269. */
  1270. sub r15, r10, r4
  1271. /* First our own GOT */
  1272. add r12, r12, r15
  1273. /* then the one used by the C code */
  1274. add r30, r30, r15
  1275. /*
  1276. * Now relocate code
  1277. */
  1278. cmplw cr1,r3,r4
  1279. addi r0,r5,3
  1280. srwi. r0,r0,2
  1281. beq cr1,4f /* In place copy is not necessary */
  1282. beq 7f /* Protect against 0 count */
  1283. mtctr r0
  1284. bge cr1,2f
  1285. la r8,-4(r4)
  1286. la r7,-4(r3)
  1287. 1: lwzu r0,4(r8)
  1288. stwu r0,4(r7)
  1289. bdnz 1b
  1290. b 4f
  1291. 2: slwi r0,r0,2
  1292. add r8,r4,r0
  1293. add r7,r3,r0
  1294. 3: lwzu r0,-4(r8)
  1295. stwu r0,-4(r7)
  1296. bdnz 3b
  1297. /*
  1298. * Now flush the cache: note that we must start from a cache aligned
  1299. * address. Otherwise we might miss one cache line.
  1300. */
  1301. 4: cmpwi r6,0
  1302. add r5,r3,r5
  1303. beq 7f /* Always flush prefetch queue in any case */
  1304. subi r0,r6,1
  1305. andc r3,r3,r0
  1306. mr r4,r3
  1307. 5: dcbst 0,r4
  1308. add r4,r4,r6
  1309. cmplw r4,r5
  1310. blt 5b
  1311. sync /* Wait for all dcbst to complete on bus */
  1312. mr r4,r3
  1313. 6: icbi 0,r4
  1314. add r4,r4,r6
  1315. cmplw r4,r5
  1316. blt 6b
  1317. 7: sync /* Wait for all icbi to complete on bus */
  1318. isync
  1319. /*
  1320. * We are done. Do not return, instead branch to second part of board
  1321. * initialization, now running from RAM.
  1322. */
  1323. addi r0, r10, in_ram - _start + _START_OFFSET
  1324. mtlr r0
  1325. blr /* NEVER RETURNS! */
  1326. in_ram:
  1327. /*
  1328. * Relocation Function, r12 point to got2+0x8000
  1329. *
  1330. * Adjust got2 pointers, no need to check for 0, this code
  1331. * already puts a few entries in the table.
  1332. */
  1333. li r0,__got2_entries@sectoff@l
  1334. la r3,GOT(_GOT2_TABLE_)
  1335. lwz r11,GOT(_GOT2_TABLE_)
  1336. mtctr r0
  1337. sub r11,r3,r11
  1338. addi r3,r3,-4
  1339. 1: lwzu r0,4(r3)
  1340. cmpwi r0,0
  1341. beq- 2f
  1342. add r0,r0,r11
  1343. stw r0,0(r3)
  1344. 2: bdnz 1b
  1345. /*
  1346. * Now adjust the fixups and the pointers to the fixups
  1347. * in case we need to move ourselves again.
  1348. */
  1349. li r0,__fixup_entries@sectoff@l
  1350. lwz r3,GOT(_FIXUP_TABLE_)
  1351. cmpwi r0,0
  1352. mtctr r0
  1353. addi r3,r3,-4
  1354. beq 4f
  1355. 3: lwzu r4,4(r3)
  1356. lwzux r0,r4,r11
  1357. cmpwi r0,0
  1358. add r0,r0,r11
  1359. stw r4,0(r3)
  1360. beq- 5f
  1361. stw r0,0(r4)
  1362. 5: bdnz 3b
  1363. 4:
  1364. clear_bss:
  1365. /*
  1366. * Now clear BSS segment
  1367. */
  1368. lwz r3,GOT(__bss_start)
  1369. lwz r4,GOT(__bss_end)
  1370. cmplw 0, r3, r4
  1371. beq 7f
  1372. li r0, 0
  1373. andi. r5, r4, 3
  1374. beq 6f
  1375. sub r4, r4, r5
  1376. mtctr r5
  1377. mr r5, r4
  1378. 5: stb r0, 0(r5)
  1379. addi r5, r5, 1
  1380. bdnz 5b
  1381. 6:
  1382. stw r0, 0(r3)
  1383. addi r3, r3, 4
  1384. cmplw 0, r3, r4
  1385. bne 6b
  1386. 7:
  1387. mr r3, r9 /* Init Data pointer */
  1388. mr r4, r10 /* Destination Address */
  1389. bl board_init_r
  1390. /*
  1391. * Copy exception vector code to low memory
  1392. *
  1393. * r3: dest_addr
  1394. * r7: source address, r8: end address, r9: target address
  1395. */
  1396. .globl trap_init
  1397. trap_init:
  1398. mflr r4 /* save link register */
  1399. GET_GOT
  1400. lwz r7, GOT(_start_of_vectors)
  1401. lwz r8, GOT(_end_of_vectors)
  1402. li r9, 0x100 /* reset vector always at 0x100 */
  1403. cmplw 0, r7, r8
  1404. bgelr /* return if r7>=r8 - just in case */
  1405. 1:
  1406. lwz r0, 0(r7)
  1407. stw r0, 0(r9)
  1408. addi r7, r7, 4
  1409. addi r9, r9, 4
  1410. cmplw 0, r7, r8
  1411. bne 1b
  1412. /*
  1413. * relocate `hdlr' and `int_return' entries
  1414. */
  1415. li r7, .L_MachineCheck - _start + _START_OFFSET
  1416. li r8, Alignment - _start + _START_OFFSET
  1417. 2:
  1418. bl trap_reloc
  1419. addi r7, r7, 0x100 /* next exception vector */
  1420. cmplw 0, r7, r8
  1421. blt 2b
  1422. li r7, .L_Alignment - _start + _START_OFFSET
  1423. bl trap_reloc
  1424. li r7, .L_ProgramCheck - _start + _START_OFFSET
  1425. bl trap_reloc
  1426. #ifdef CONFIG_440
  1427. li r7, .L_FPUnavailable - _start + _START_OFFSET
  1428. bl trap_reloc
  1429. li r7, .L_Decrementer - _start + _START_OFFSET
  1430. bl trap_reloc
  1431. li r7, .L_APU - _start + _START_OFFSET
  1432. bl trap_reloc
  1433. li r7, .L_InstructionTLBError - _start + _START_OFFSET
  1434. bl trap_reloc
  1435. li r7, .L_DataTLBError - _start + _START_OFFSET
  1436. bl trap_reloc
  1437. #else /* CONFIG_440 */
  1438. li r7, .L_PIT - _start + _START_OFFSET
  1439. bl trap_reloc
  1440. li r7, .L_InstructionTLBMiss - _start + _START_OFFSET
  1441. bl trap_reloc
  1442. li r7, .L_DataTLBMiss - _start + _START_OFFSET
  1443. bl trap_reloc
  1444. #endif /* CONFIG_440 */
  1445. li r7, .L_DebugBreakpoint - _start + _START_OFFSET
  1446. bl trap_reloc
  1447. #if !defined(CONFIG_440)
  1448. addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
  1449. oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
  1450. mtmsr r7 /* change MSR */
  1451. #else
  1452. bl __440_msr_set
  1453. b __440_msr_continue
  1454. __440_msr_set:
  1455. addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
  1456. oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
  1457. mtspr SPRN_SRR1,r7
  1458. mflr r7
  1459. mtspr SPRN_SRR0,r7
  1460. rfi
  1461. __440_msr_continue:
  1462. #endif
  1463. mtlr r4 /* restore link register */
  1464. blr
  1465. #endif /* CONFIG_SPL_BUILD */
  1466. #if defined(CONFIG_440)
  1467. /*----------------------------------------------------------------------------+
  1468. | dcbz_area.
  1469. +----------------------------------------------------------------------------*/
  1470. function_prolog(dcbz_area)
  1471. rlwinm. r5,r4,0,27,31
  1472. rlwinm r5,r4,27,5,31
  1473. beq ..d_ra2
  1474. addi r5,r5,0x0001
  1475. ..d_ra2:mtctr r5
  1476. ..d_ag2:dcbz r0,r3
  1477. addi r3,r3,32
  1478. bdnz ..d_ag2
  1479. sync
  1480. blr
  1481. function_epilog(dcbz_area)
  1482. #endif /* CONFIG_440 */
  1483. #endif /* CONFIG_SPL_BUILD */
  1484. /*------------------------------------------------------------------------------- */
  1485. /* Function: in8 */
  1486. /* Description: Input 8 bits */
  1487. /*------------------------------------------------------------------------------- */
  1488. .globl in8
  1489. in8:
  1490. lbz r3,0x0000(r3)
  1491. blr
  1492. /*------------------------------------------------------------------------------- */
  1493. /* Function: out8 */
  1494. /* Description: Output 8 bits */
  1495. /*------------------------------------------------------------------------------- */
  1496. .globl out8
  1497. out8:
  1498. stb r4,0x0000(r3)
  1499. blr
  1500. /*------------------------------------------------------------------------------- */
  1501. /* Function: out32 */
  1502. /* Description: Output 32 bits */
  1503. /*------------------------------------------------------------------------------- */
  1504. .globl out32
  1505. out32:
  1506. stw r4,0x0000(r3)
  1507. blr
  1508. /*------------------------------------------------------------------------------- */
  1509. /* Function: in32 */
  1510. /* Description: Input 32 bits */
  1511. /*------------------------------------------------------------------------------- */
  1512. .globl in32
  1513. in32:
  1514. lwz 3,0x0000(3)
  1515. blr
  1516. /**************************************************************************/
  1517. /* PPC405EP specific stuff */
  1518. /**************************************************************************/
  1519. #ifdef CONFIG_405EP
  1520. ppc405ep_init:
  1521. #ifdef CONFIG_BUBINGA
  1522. /*
  1523. * Initialize EBC chip selects 1 & 4 and GPIO pins (for alternate
  1524. * function) to support FPGA and NVRAM accesses below.
  1525. */
  1526. lis r3,GPIO0_OSRH@h /* config GPIO output select */
  1527. ori r3,r3,GPIO0_OSRH@l
  1528. lis r4,CONFIG_SYS_GPIO0_OSRH@h
  1529. ori r4,r4,CONFIG_SYS_GPIO0_OSRH@l
  1530. stw r4,0(r3)
  1531. lis r3,GPIO0_OSRL@h
  1532. ori r3,r3,GPIO0_OSRL@l
  1533. lis r4,CONFIG_SYS_GPIO0_OSRL@h
  1534. ori r4,r4,CONFIG_SYS_GPIO0_OSRL@l
  1535. stw r4,0(r3)
  1536. lis r3,GPIO0_ISR1H@h /* config GPIO input select */
  1537. ori r3,r3,GPIO0_ISR1H@l
  1538. lis r4,CONFIG_SYS_GPIO0_ISR1H@h
  1539. ori r4,r4,CONFIG_SYS_GPIO0_ISR1H@l
  1540. stw r4,0(r3)
  1541. lis r3,GPIO0_ISR1L@h
  1542. ori r3,r3,GPIO0_ISR1L@l
  1543. lis r4,CONFIG_SYS_GPIO0_ISR1L@h
  1544. ori r4,r4,CONFIG_SYS_GPIO0_ISR1L@l
  1545. stw r4,0(r3)
  1546. lis r3,GPIO0_TSRH@h /* config GPIO three-state select */
  1547. ori r3,r3,GPIO0_TSRH@l
  1548. lis r4,CONFIG_SYS_GPIO0_TSRH@h
  1549. ori r4,r4,CONFIG_SYS_GPIO0_TSRH@l
  1550. stw r4,0(r3)
  1551. lis r3,GPIO0_TSRL@h
  1552. ori r3,r3,GPIO0_TSRL@l
  1553. lis r4,CONFIG_SYS_GPIO0_TSRL@h
  1554. ori r4,r4,CONFIG_SYS_GPIO0_TSRL@l
  1555. stw r4,0(r3)
  1556. lis r3,GPIO0_TCR@h /* config GPIO driver output enables */
  1557. ori r3,r3,GPIO0_TCR@l
  1558. lis r4,CONFIG_SYS_GPIO0_TCR@h
  1559. ori r4,r4,CONFIG_SYS_GPIO0_TCR@l
  1560. stw r4,0(r3)
  1561. li r3,PB1AP /* program EBC bank 1 for RTC access */
  1562. mtdcr EBC0_CFGADDR,r3
  1563. lis r3,CONFIG_SYS_EBC_PB1AP@h
  1564. ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
  1565. mtdcr EBC0_CFGDATA,r3
  1566. li r3,PB1CR
  1567. mtdcr EBC0_CFGADDR,r3
  1568. lis r3,CONFIG_SYS_EBC_PB1CR@h
  1569. ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
  1570. mtdcr EBC0_CFGDATA,r3
  1571. li r3,PB1AP /* program EBC bank 1 for RTC access */
  1572. mtdcr EBC0_CFGADDR,r3
  1573. lis r3,CONFIG_SYS_EBC_PB1AP@h
  1574. ori r3,r3,CONFIG_SYS_EBC_PB1AP@l
  1575. mtdcr EBC0_CFGDATA,r3
  1576. li r3,PB1CR
  1577. mtdcr EBC0_CFGADDR,r3
  1578. lis r3,CONFIG_SYS_EBC_PB1CR@h
  1579. ori r3,r3,CONFIG_SYS_EBC_PB1CR@l
  1580. mtdcr EBC0_CFGDATA,r3
  1581. li r3,PB4AP /* program EBC bank 4 for FPGA access */
  1582. mtdcr EBC0_CFGADDR,r3
  1583. lis r3,CONFIG_SYS_EBC_PB4AP@h
  1584. ori r3,r3,CONFIG_SYS_EBC_PB4AP@l
  1585. mtdcr EBC0_CFGDATA,r3
  1586. li r3,PB4CR
  1587. mtdcr EBC0_CFGADDR,r3
  1588. lis r3,CONFIG_SYS_EBC_PB4CR@h
  1589. ori r3,r3,CONFIG_SYS_EBC_PB4CR@l
  1590. mtdcr EBC0_CFGDATA,r3
  1591. #endif
  1592. /*
  1593. !-----------------------------------------------------------------------
  1594. ! Check to see if chip is in bypass mode.
  1595. ! If so, write stored CPC0_PLLMR0 and CPC0_PLLMR1 values and perform a
  1596. ! CPU reset Otherwise, skip this step and keep going.
  1597. ! Note: Running BIOS in bypass mode is not supported since PLB speed
  1598. ! will not be fast enough for the SDRAM (min 66MHz)
  1599. !-----------------------------------------------------------------------
  1600. */
  1601. mfdcr r5, CPC0_PLLMR1
  1602. rlwinm r4,r5,1,0x1 /* get system clock source (SSCS) */
  1603. cmpi cr0,0,r4,0x1
  1604. beq pll_done /* if SSCS =b'1' then PLL has */
  1605. /* already been set */
  1606. /* and CPU has been reset */
  1607. /* so skip to next section */
  1608. #ifdef CONFIG_BUBINGA
  1609. /*
  1610. !-----------------------------------------------------------------------
  1611. ! Read NVRAM to get value to write in PLLMR.
  1612. ! If value has not been correctly saved, write default value
  1613. ! Default config values (assuming on-board 33MHz SYS_CLK) are above.
  1614. ! See CPU_DEFAULT_200 and CPU_DEFAULT_266 above.
  1615. !
  1616. ! WARNING: This code assumes the first three words in the nvram_t
  1617. ! structure in openbios.h. Changing the beginning of
  1618. ! the structure will break this code.
  1619. !
  1620. !-----------------------------------------------------------------------
  1621. */
  1622. addis r3,0,NVRAM_BASE@h
  1623. addi r3,r3,NVRAM_BASE@l
  1624. lwz r4, 0(r3)
  1625. addis r5,0,NVRVFY1@h
  1626. addi r5,r5,NVRVFY1@l
  1627. cmp cr0,0,r4,r5 /* Compare 1st NVRAM Magic number*/
  1628. bne ..no_pllset
  1629. addi r3,r3,4
  1630. lwz r4, 0(r3)
  1631. addis r5,0,NVRVFY2@h
  1632. addi r5,r5,NVRVFY2@l
  1633. cmp cr0,0,r4,r5 /* Compare 2 NVRAM Magic number */
  1634. bne ..no_pllset
  1635. addi r3,r3,8 /* Skip over conf_size */
  1636. lwz r4, 4(r3) /* Load PLLMR1 value from NVRAM */
  1637. lwz r3, 0(r3) /* Load PLLMR0 value from NVRAM */
  1638. rlwinm r5,r4,1,0x1 /* get system clock source (SSCS) */
  1639. cmpi cr0,0,r5,1 /* See if PLL is locked */
  1640. beq pll_write
  1641. ..no_pllset:
  1642. #endif /* CONFIG_BUBINGA */
  1643. addis r3,0,PLLMR0_DEFAULT@h /* PLLMR0 default value */
  1644. ori r3,r3,PLLMR0_DEFAULT@l /* */
  1645. addis r4,0,PLLMR1_DEFAULT@h /* PLLMR1 default value */
  1646. ori r4,r4,PLLMR1_DEFAULT@l /* */
  1647. 1:
  1648. b pll_write /* Write the CPC0_PLLMR with new value */
  1649. pll_done:
  1650. /*
  1651. !-----------------------------------------------------------------------
  1652. ! Clear Soft Reset Register
  1653. ! This is needed to enable PCI if not booting from serial EPROM
  1654. !-----------------------------------------------------------------------
  1655. */
  1656. addi r3, 0, 0x0
  1657. mtdcr CPC0_SRR, r3
  1658. addis r3,0,0x0010
  1659. mtctr r3
  1660. pci_wait:
  1661. bdnz pci_wait
  1662. blr /* return to main code */
  1663. /*
  1664. !-----------------------------------------------------------------------------
  1665. ! Function: pll_write
  1666. ! Description: Updates the value of the CPC0_PLLMR according to CMOS27E documentation
  1667. ! That is:
  1668. ! 1. Pll is first disabled (de-activated by putting in bypass mode)
  1669. ! 2. PLL is reset
  1670. ! 3. Clock dividers are set while PLL is held in reset and bypassed
  1671. ! 4. PLL Reset is cleared
  1672. ! 5. Wait 100us for PLL to lock
  1673. ! 6. A core reset is performed
  1674. ! Input: r3 = Value to write to CPC0_PLLMR0
  1675. ! Input: r4 = Value to write to CPC0_PLLMR1
  1676. ! Output r3 = none
  1677. !-----------------------------------------------------------------------------
  1678. */
  1679. .globl pll_write
  1680. pll_write:
  1681. mfdcr r5, CPC0_UCR
  1682. andis. r5,r5,0xFFFF
  1683. ori r5,r5,0x0101 /* Stop the UART clocks */
  1684. mtdcr CPC0_UCR,r5 /* Before changing PLL */
  1685. mfdcr r5, CPC0_PLLMR1
  1686. rlwinm r5,r5,0,0x7FFFFFFF /* Disable PLL */
  1687. mtdcr CPC0_PLLMR1,r5
  1688. oris r5,r5,0x4000 /* Set PLL Reset */
  1689. mtdcr CPC0_PLLMR1,r5
  1690. mtdcr CPC0_PLLMR0,r3 /* Set clock dividers */
  1691. rlwinm r5,r4,0,0x3FFFFFFF /* Reset & Bypass new PLL dividers */
  1692. oris r5,r5,0x4000 /* Set PLL Reset */
  1693. mtdcr CPC0_PLLMR1,r5 /* Set clock dividers */
  1694. rlwinm r5,r5,0,0xBFFFFFFF /* Clear PLL Reset */
  1695. mtdcr CPC0_PLLMR1,r5
  1696. /*
  1697. ! Wait min of 100us for PLL to lock.
  1698. ! See CMOS 27E databook for more info.
  1699. ! At 200MHz, that means waiting 20,000 instructions
  1700. */
  1701. addi r3,0,20000 /* 2000 = 0x4e20 */
  1702. mtctr r3
  1703. pll_wait:
  1704. bdnz pll_wait
  1705. oris r5,r5,0x8000 /* Enable PLL */
  1706. mtdcr CPC0_PLLMR1,r5 /* Engage */
  1707. /*
  1708. * Reset CPU to guarantee timings are OK
  1709. * Not sure if this is needed...
  1710. */
  1711. addis r3,0,0x1000
  1712. mtspr SPRN_DBCR0,r3 /* This will cause a CPU core reset, and */
  1713. /* execution will continue from the poweron */
  1714. /* vector of 0xfffffffc */
  1715. #endif /* CONFIG_405EP */
  1716. #if defined(CONFIG_440)
  1717. /*----------------------------------------------------------------------------+
  1718. | mttlb3.
  1719. +----------------------------------------------------------------------------*/
  1720. function_prolog(mttlb3)
  1721. TLBWE(4,3,2)
  1722. blr
  1723. function_epilog(mttlb3)
  1724. /*----------------------------------------------------------------------------+
  1725. | mftlb3.
  1726. +----------------------------------------------------------------------------*/
  1727. function_prolog(mftlb3)
  1728. TLBRE(3,3,2)
  1729. blr
  1730. function_epilog(mftlb3)
  1731. /*----------------------------------------------------------------------------+
  1732. | mttlb2.
  1733. +----------------------------------------------------------------------------*/
  1734. function_prolog(mttlb2)
  1735. TLBWE(4,3,1)
  1736. blr
  1737. function_epilog(mttlb2)
  1738. /*----------------------------------------------------------------------------+
  1739. | mftlb2.
  1740. +----------------------------------------------------------------------------*/
  1741. function_prolog(mftlb2)
  1742. TLBRE(3,3,1)
  1743. blr
  1744. function_epilog(mftlb2)
  1745. /*----------------------------------------------------------------------------+
  1746. | mttlb1.
  1747. +----------------------------------------------------------------------------*/
  1748. function_prolog(mttlb1)
  1749. TLBWE(4,3,0)
  1750. blr
  1751. function_epilog(mttlb1)
  1752. /*----------------------------------------------------------------------------+
  1753. | mftlb1.
  1754. +----------------------------------------------------------------------------*/
  1755. function_prolog(mftlb1)
  1756. TLBRE(3,3,0)
  1757. blr
  1758. function_epilog(mftlb1)
  1759. #endif /* CONFIG_440 */