start.S 60 KB

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