start.S 56 KB

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