start.S 55 KB

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