start.S 55 KB

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