start.S 54 KB

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