start.S 56 KB

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