start.S 60 KB

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