start.S 61 KB

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