start.S 60 KB

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