start.S 57 KB

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