start.S 51 KB

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