start.S 49 KB

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