start.S 56 KB

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