start.S 58 KB

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