start.S 61 KB

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