start.S 60 KB

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