start.S 60 KB

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