start.S 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072
  1. /*
  2. * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
  3. * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
  4. * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de>
  5. * Copyright (C) 2007 Stefan Roese <sr@denx.de>, DENX Software Engineering
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. /*------------------------------------------------------------------------------+ */
  26. /* */
  27. /* This source code has been made available to you by IBM on an AS-IS */
  28. /* basis. Anyone receiving this source is licensed under IBM */
  29. /* copyrights to use it in any way he or she deems fit, including */
  30. /* copying it, modifying it, compiling it, and redistributing it either */
  31. /* with or without modifications. No license under IBM patents or */
  32. /* patent applications is to be implied by the copyright license. */
  33. /* */
  34. /* Any user of this software should understand that IBM cannot provide */
  35. /* technical support for this software and will not be responsible for */
  36. /* any consequences resulting from the use of this software. */
  37. /* */
  38. /* Any person who transfers this source code or any derivative work */
  39. /* must include the IBM copyright notice, this paragraph, and the */
  40. /* preceding two paragraphs in the transferred software. */
  41. /* */
  42. /* COPYRIGHT I B M CORPORATION 1995 */
  43. /* LICENSED MATERIAL - PROGRAM PROPERTY OF I B M */
  44. /*------------------------------------------------------------------------------- */
  45. /* U-Boot - Startup Code for AMCC 4xx PowerPC based Embedded Boards
  46. *
  47. *
  48. * The processor starts at 0xfffffffc and the code is executed
  49. * from flash/rom.
  50. * in memory, but as long we don't jump around before relocating.
  51. * board_init lies at a quite high address and when the cpu has
  52. * jumped there, everything is ok.
  53. * This works because the cpu gives the FLASH (CS0) the whole
  54. * address space at startup, and board_init lies as a echo of
  55. * the flash somewhere up there in the memorymap.
  56. *
  57. * board_init will change CS0 to be positioned at the correct
  58. * address and (s)dram will be positioned at address 0
  59. */
  60. #include <config.h>
  61. #include <mpc8xx.h>
  62. #include <ppc4xx.h>
  63. #include <version.h>
  64. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  65. #include <ppc_asm.tmpl>
  66. #include <ppc_defs.h>
  67. #include <asm/cache.h>
  68. #include <asm/mmu.h>
  69. #ifndef CONFIG_IDENT_STRING
  70. #define CONFIG_IDENT_STRING ""
  71. #endif
  72. #ifdef CFG_INIT_DCACHE_CS
  73. # if (CFG_INIT_DCACHE_CS == 0)
  74. # define PBxAP pb0ap
  75. # define PBxCR pb0cr
  76. # endif
  77. # if (CFG_INIT_DCACHE_CS == 1)
  78. # define PBxAP pb1ap
  79. # define PBxCR pb1cr
  80. # endif
  81. # if (CFG_INIT_DCACHE_CS == 2)
  82. # define PBxAP pb2ap
  83. # define PBxCR pb2cr
  84. # endif
  85. # if (CFG_INIT_DCACHE_CS == 3)
  86. # define PBxAP pb3ap
  87. # define PBxCR pb3cr
  88. # endif
  89. # if (CFG_INIT_DCACHE_CS == 4)
  90. # define PBxAP pb4ap
  91. # define PBxCR pb4cr
  92. # endif
  93. # if (CFG_INIT_DCACHE_CS == 5)
  94. # define PBxAP pb5ap
  95. # define PBxCR pb5cr
  96. # endif
  97. # if (CFG_INIT_DCACHE_CS == 6)
  98. # define PBxAP pb6ap
  99. # define PBxCR pb6cr
  100. # endif
  101. # if (CFG_INIT_DCACHE_CS == 7)
  102. # define PBxAP pb7ap
  103. # define PBxCR pb7cr
  104. # endif
  105. #endif /* CFG_INIT_DCACHE_CS */
  106. #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,0x8000
  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_405)
  748. /*----------------------------------------------------------------------- */
  749. /* Clear and set up some registers. */
  750. /*----------------------------------------------------------------------- */
  751. addi r4,r0,0x0000
  752. mtspr sgr,r4
  753. mtspr dcwr,r4
  754. mtesr r4 /* clear Exception Syndrome Reg */
  755. mttcr r4 /* clear Timer Control Reg */
  756. mtxer r4 /* clear Fixed-Point Exception Reg */
  757. mtevpr r4 /* clear Exception Vector Prefix Reg */
  758. addi r4,r0,(0xFFFF-0x10000) /* set r4 to 0xFFFFFFFF (status in the */
  759. /* dbsr is cleared by setting bits to 1) */
  760. mtdbsr r4 /* clear/reset the dbsr */
  761. /*----------------------------------------------------------------------- */
  762. /* Invalidate I and D caches. Enable I cache for defined memory regions */
  763. /* to speed things up. Leave the D cache disabled for now. It will be */
  764. /* enabled/left disabled later based on user selected menu options. */
  765. /* Be aware that the I cache may be disabled later based on the menu */
  766. /* options as well. See miscLib/main.c. */
  767. /*----------------------------------------------------------------------- */
  768. bl invalidate_icache
  769. bl invalidate_dcache
  770. /*----------------------------------------------------------------------- */
  771. /* Enable two 128MB cachable regions. */
  772. /*----------------------------------------------------------------------- */
  773. lis r4,0x8000
  774. ori r4,r4,0x0001
  775. mticcr r4 /* instruction cache */
  776. isync
  777. lis r4,0x0000
  778. ori r4,r4,0x0000
  779. mtdccr r4 /* data cache */
  780. #if !(defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
  781. /*----------------------------------------------------------------------- */
  782. /* Tune the speed and size for flash CS0 */
  783. /*----------------------------------------------------------------------- */
  784. bl ext_bus_cntlr_init
  785. #endif
  786. #if defined(CONFIG_405EP)
  787. /*----------------------------------------------------------------------- */
  788. /* DMA Status, clear to come up clean */
  789. /*----------------------------------------------------------------------- */
  790. addis r3,r0, 0xFFFF /* Clear all existing DMA status */
  791. ori r3,r3, 0xFFFF
  792. mtdcr dmasr, r3
  793. bl ppc405ep_init /* do ppc405ep specific init */
  794. #endif /* CONFIG_405EP */
  795. #if defined(CFG_OCM_DATA_ADDR) && defined(CFG_OCM_DATA_SIZE)
  796. #if defined(CONFIG_405EZ)
  797. /********************************************************************
  798. * Setup OCM - On Chip Memory - PPC405EZ uses OCM Controller V2
  799. *******************************************************************/
  800. /*
  801. * We can map the OCM on the PLB3, so map it at
  802. * CFG_OCM_DATA_ADDR + 0x8000
  803. */
  804. lis r3,CFG_OCM_DATA_ADDR@h /* OCM location */
  805. ori r3,r3,CFG_OCM_DATA_ADDR@l
  806. ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
  807. mtdcr ocmplb3cr1,r3 /* Set PLB Access */
  808. ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
  809. mtdcr ocmplb3cr2,r3 /* Set PLB Access */
  810. isync
  811. lis r3,CFG_OCM_DATA_ADDR@h /* OCM location */
  812. ori r3,r3,CFG_OCM_DATA_ADDR@l
  813. ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
  814. mtdcr ocmdscr1, r3 /* Set Data Side */
  815. mtdcr ocmiscr1, r3 /* Set Instruction Side */
  816. ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
  817. mtdcr ocmdscr2, r3 /* Set Data Side */
  818. mtdcr ocmiscr2, r3 /* Set Instruction Side */
  819. addis r3,0,0x0800 /* OCM Data Parity Disable - 1 Wait State */
  820. mtdcr ocmdsisdpc,r3
  821. isync
  822. #else /* CONFIG_405EZ */
  823. /********************************************************************
  824. * Setup OCM - On Chip Memory
  825. *******************************************************************/
  826. /* Setup OCM */
  827. lis r0, 0x7FFF
  828. ori r0, r0, 0xFFFF
  829. mfdcr r3, ocmiscntl /* get instr-side IRAM config */
  830. mfdcr r4, ocmdscntl /* get data-side IRAM config */
  831. and r3, r3, r0 /* disable data-side IRAM */
  832. and r4, r4, r0 /* disable data-side IRAM */
  833. mtdcr ocmiscntl, r3 /* set instr-side IRAM config */
  834. mtdcr ocmdscntl, r4 /* set data-side IRAM config */
  835. isync
  836. lis r3,CFG_OCM_DATA_ADDR@h /* OCM location */
  837. ori r3,r3,CFG_OCM_DATA_ADDR@l
  838. mtdcr ocmdsarc, r3
  839. addis r4, 0, 0xC000 /* OCM data area enabled */
  840. mtdcr ocmdscntl, r4
  841. isync
  842. #endif /* CONFIG_405EZ */
  843. #endif
  844. #ifdef CONFIG_NAND_SPL
  845. /*
  846. * Copy SPL from cache into internal SRAM
  847. */
  848. li r4,(CFG_NAND_BOOT_SPL_SIZE >> 2) - 1
  849. mtctr r4
  850. lis r2,CFG_NAND_BOOT_SPL_SRC@h
  851. ori r2,r2,CFG_NAND_BOOT_SPL_SRC@l
  852. lis r3,CFG_NAND_BOOT_SPL_DST@h
  853. ori r3,r3,CFG_NAND_BOOT_SPL_DST@l
  854. spl_loop:
  855. lwzu r4,4(r2)
  856. stwu r4,4(r3)
  857. bdnz spl_loop
  858. /*
  859. * Jump to code in RAM
  860. */
  861. bl 00f
  862. 00: mflr r10
  863. lis r3,(CFG_NAND_BOOT_SPL_SRC - CFG_NAND_BOOT_SPL_DST)@h
  864. ori r3,r3,(CFG_NAND_BOOT_SPL_SRC - CFG_NAND_BOOT_SPL_DST)@l
  865. sub r10,r10,r3
  866. addi r10,r10,28
  867. mtlr r10
  868. blr
  869. start_ram:
  870. sync
  871. isync
  872. #endif /* CONFIG_NAND_SPL */
  873. /*----------------------------------------------------------------------- */
  874. /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */
  875. /*----------------------------------------------------------------------- */
  876. #ifdef CFG_INIT_DCACHE_CS
  877. /*----------------------------------------------------------------------- */
  878. /* Memory Bank x (nothingness) initialization 1GB+64MEG */
  879. /* used as temporary stack pointer for stage0 */
  880. /*----------------------------------------------------------------------- */
  881. li r4,PBxAP
  882. mtdcr ebccfga,r4
  883. lis r4,0x0380
  884. ori r4,r4,0x0480
  885. mtdcr ebccfgd,r4
  886. addi r4,0,PBxCR
  887. mtdcr ebccfga,r4
  888. lis r4,0x400D
  889. ori r4,r4,0xa000
  890. mtdcr ebccfgd,r4
  891. /* turn on data chache for this region */
  892. lis r4,0x0080
  893. mtdccr r4
  894. /* set stack pointer and clear stack to known value */
  895. lis r1,CFG_INIT_RAM_ADDR@h
  896. ori r1,r1,CFG_INIT_SP_OFFSET@l
  897. li r4,2048 /* we store 2048 words to stack */
  898. mtctr r4
  899. lis r2,CFG_INIT_RAM_ADDR@h /* we also clear data area */
  900. ori r2,r2,CFG_INIT_RAM_END@l /* so cant copy value from r1 */
  901. lis r4,0xdead /* we store 0xdeaddead in the stack */
  902. ori r4,r4,0xdead
  903. ..stackloop:
  904. stwu r4,-4(r2)
  905. bdnz ..stackloop
  906. li r0, 0 /* Make room for stack frame header and */
  907. stwu r0, -4(r1) /* clear final stack frame so that */
  908. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  909. /*
  910. * Set up a dummy frame to store reset vector as return address.
  911. * this causes stack underflow to reset board.
  912. */
  913. stwu r1, -8(r1) /* Save back chain and move SP */
  914. addis r0, 0, RESET_VECTOR@h /* Address of reset vector */
  915. ori r0, r0, RESET_VECTOR@l
  916. stwu r1, -8(r1) /* Save back chain and move SP */
  917. stw r0, +12(r1) /* Save return addr (underflow vect) */
  918. #elif defined(CFG_TEMP_STACK_OCM) && \
  919. (defined(CFG_OCM_DATA_ADDR) && defined(CFG_OCM_DATA_SIZE))
  920. /*
  921. * Stack in OCM.
  922. */
  923. /* Set up Stack at top of OCM */
  924. lis r1, (CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET)@h
  925. ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET)@l
  926. /* Set up a zeroized stack frame so that backtrace works right */
  927. li r0, 0
  928. stwu r0, -4(r1)
  929. stwu r0, -4(r1)
  930. /*
  931. * Set up a dummy frame to store reset vector as return address.
  932. * this causes stack underflow to reset board.
  933. */
  934. stwu r1, -8(r1) /* Save back chain and move SP */
  935. lis r0, RESET_VECTOR@h /* Address of reset vector */
  936. ori r0, r0, RESET_VECTOR@l
  937. stwu r1, -8(r1) /* Save back chain and move SP */
  938. stw r0, +12(r1) /* Save return addr (underflow vect) */
  939. #endif /* CFG_INIT_DCACHE_CS */
  940. /*----------------------------------------------------------------------- */
  941. /* Initialize SDRAM Controller */
  942. /*----------------------------------------------------------------------- */
  943. bl sdram_init
  944. /*
  945. * Setup temporary stack pointer only for boards
  946. * that do not use SDRAM SPD I2C stuff since it
  947. * is already initialized to use DCACHE or OCM
  948. * stacks.
  949. */
  950. #if !(defined(CFG_INIT_DCACHE_CS) || defined(CFG_TEMP_STACK_OCM))
  951. lis r1, CFG_INIT_RAM_ADDR@h
  952. ori r1,r1,CFG_INIT_SP_OFFSET /* set up the stack in SDRAM */
  953. li r0, 0 /* Make room for stack frame header and */
  954. stwu r0, -4(r1) /* clear final stack frame so that */
  955. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  956. /*
  957. * Set up a dummy frame to store reset vector as return address.
  958. * this causes stack underflow to reset board.
  959. */
  960. stwu r1, -8(r1) /* Save back chain and move SP */
  961. lis r0, RESET_VECTOR@h /* Address of reset vector */
  962. ori r0, r0, RESET_VECTOR@l
  963. stwu r1, -8(r1) /* Save back chain and move SP */
  964. stw r0, +12(r1) /* Save return addr (underflow vect) */
  965. #endif /* !(CFG_INIT_DCACHE_CS || !CFG_TEM_STACK_OCM) */
  966. #ifdef CONFIG_NAND_SPL
  967. bl nand_boot /* will not return */
  968. #else
  969. GET_GOT /* initialize GOT access */
  970. bl cpu_init_f /* run low-level CPU init code (from Flash) */
  971. /* NEVER RETURNS! */
  972. bl board_init_f /* run first part of init code (from Flash) */
  973. #endif /* CONFIG_NAND_SPL */
  974. #endif /* CONFIG_405GP || CONFIG_405CR || CONFIG_405 || CONFIG_405EP */
  975. /*----------------------------------------------------------------------- */
  976. #ifndef CONFIG_NAND_SPL
  977. /*
  978. * This code finishes saving the registers to the exception frame
  979. * and jumps to the appropriate handler for the exception.
  980. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  981. */
  982. .globl transfer_to_handler
  983. transfer_to_handler:
  984. stw r22,_NIP(r21)
  985. lis r22,MSR_POW@h
  986. andc r23,r23,r22
  987. stw r23,_MSR(r21)
  988. SAVE_GPR(7, r21)
  989. SAVE_4GPRS(8, r21)
  990. SAVE_8GPRS(12, r21)
  991. SAVE_8GPRS(24, r21)
  992. mflr r23
  993. andi. r24,r23,0x3f00 /* get vector offset */
  994. stw r24,TRAP(r21)
  995. li r22,0
  996. stw r22,RESULT(r21)
  997. mtspr SPRG2,r22 /* r1 is now kernel sp */
  998. lwz r24,0(r23) /* virtual address of handler */
  999. lwz r23,4(r23) /* where to go when done */
  1000. mtspr SRR0,r24
  1001. mtspr SRR1,r20
  1002. mtlr r23
  1003. SYNC
  1004. rfi /* jump to handler, enable MMU */
  1005. int_return:
  1006. mfmsr r28 /* Disable interrupts */
  1007. li r4,0
  1008. ori r4,r4,MSR_EE
  1009. andc r28,r28,r4
  1010. SYNC /* Some chip revs need this... */
  1011. mtmsr r28
  1012. SYNC
  1013. lwz r2,_CTR(r1)
  1014. lwz r0,_LINK(r1)
  1015. mtctr r2
  1016. mtlr r0
  1017. lwz r2,_XER(r1)
  1018. lwz r0,_CCR(r1)
  1019. mtspr XER,r2
  1020. mtcrf 0xFF,r0
  1021. REST_10GPRS(3, r1)
  1022. REST_10GPRS(13, r1)
  1023. REST_8GPRS(23, r1)
  1024. REST_GPR(31, r1)
  1025. lwz r2,_NIP(r1) /* Restore environment */
  1026. lwz r0,_MSR(r1)
  1027. mtspr SRR0,r2
  1028. mtspr SRR1,r0
  1029. lwz r0,GPR0(r1)
  1030. lwz r2,GPR2(r1)
  1031. lwz r1,GPR1(r1)
  1032. SYNC
  1033. rfi
  1034. crit_return:
  1035. mfmsr r28 /* Disable interrupts */
  1036. li r4,0
  1037. ori r4,r4,MSR_EE
  1038. andc r28,r28,r4
  1039. SYNC /* Some chip revs need this... */
  1040. mtmsr r28
  1041. SYNC
  1042. lwz r2,_CTR(r1)
  1043. lwz r0,_LINK(r1)
  1044. mtctr r2
  1045. mtlr r0
  1046. lwz r2,_XER(r1)
  1047. lwz r0,_CCR(r1)
  1048. mtspr XER,r2
  1049. mtcrf 0xFF,r0
  1050. REST_10GPRS(3, r1)
  1051. REST_10GPRS(13, r1)
  1052. REST_8GPRS(23, r1)
  1053. REST_GPR(31, r1)
  1054. lwz r2,_NIP(r1) /* Restore environment */
  1055. lwz r0,_MSR(r1)
  1056. mtspr csrr0,r2
  1057. mtspr csrr1,r0
  1058. lwz r0,GPR0(r1)
  1059. lwz r2,GPR2(r1)
  1060. lwz r1,GPR1(r1)
  1061. SYNC
  1062. rfci
  1063. #ifdef CONFIG_440
  1064. mck_return:
  1065. mfmsr r28 /* Disable interrupts */
  1066. li r4,0
  1067. ori r4,r4,MSR_EE
  1068. andc r28,r28,r4
  1069. SYNC /* Some chip revs need this... */
  1070. mtmsr r28
  1071. SYNC
  1072. lwz r2,_CTR(r1)
  1073. lwz r0,_LINK(r1)
  1074. mtctr r2
  1075. mtlr r0
  1076. lwz r2,_XER(r1)
  1077. lwz r0,_CCR(r1)
  1078. mtspr XER,r2
  1079. mtcrf 0xFF,r0
  1080. REST_10GPRS(3, r1)
  1081. REST_10GPRS(13, r1)
  1082. REST_8GPRS(23, r1)
  1083. REST_GPR(31, r1)
  1084. lwz r2,_NIP(r1) /* Restore environment */
  1085. lwz r0,_MSR(r1)
  1086. mtspr mcsrr0,r2
  1087. mtspr mcsrr1,r0
  1088. lwz r0,GPR0(r1)
  1089. lwz r2,GPR2(r1)
  1090. lwz r1,GPR1(r1)
  1091. SYNC
  1092. rfmci
  1093. #endif /* CONFIG_440 */
  1094. /*
  1095. * Cache functions.
  1096. *
  1097. * NOTE: currently the 440s run with dcache _disabled_ once relocated to DRAM,
  1098. * although for some cache-ralated calls stubs have to be provided to satisfy
  1099. * symbols resolution.
  1100. *
  1101. */
  1102. #ifdef CONFIG_440
  1103. .globl dcache_disable
  1104. dcache_disable:
  1105. blr
  1106. .globl dcache_status
  1107. dcache_status:
  1108. blr
  1109. #else
  1110. flush_dcache:
  1111. addis r9,r0,0x0002 /* set mask for EE and CE msr bits */
  1112. ori r9,r9,0x8000
  1113. mfmsr r12 /* save msr */
  1114. andc r9,r12,r9
  1115. mtmsr r9 /* disable EE and CE */
  1116. addi r10,r0,0x0001 /* enable data cache for unused memory */
  1117. mfdccr r9 /* region 0xF8000000-0xFFFFFFFF via */
  1118. or r10,r10,r9 /* bit 31 in dccr */
  1119. mtdccr r10
  1120. /* do loop for # of congruence classes. */
  1121. lis r10,(CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)@ha /* TBS: for large cache sizes */
  1122. ori r10,r10,(CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)@l
  1123. lis r11,(CFG_DCACHE_SIZE / 2)@ha /* D cache set size - 2 way sets */
  1124. ori r11,r11,(CFG_DCACHE_SIZE / 2)@l /* D cache set size - 2 way sets */
  1125. mtctr r10
  1126. addi r10,r0,(0xE000-0x10000) /* start at 0xFFFFE000 */
  1127. add r11,r10,r11 /* add to get to other side of cache line */
  1128. ..flush_dcache_loop:
  1129. lwz r3,0(r10) /* least recently used side */
  1130. lwz r3,0(r11) /* the other side */
  1131. dccci r0,r11 /* invalidate both sides */
  1132. addi r10,r10,CFG_CACHELINE_SIZE /* bump to next line */
  1133. addi r11,r11,CFG_CACHELINE_SIZE /* bump to next line */
  1134. bdnz ..flush_dcache_loop
  1135. sync /* allow memory access to complete */
  1136. mtdccr r9 /* restore dccr */
  1137. mtmsr r12 /* restore msr */
  1138. blr
  1139. .globl icache_enable
  1140. icache_enable:
  1141. mflr r8
  1142. bl invalidate_icache
  1143. mtlr r8
  1144. isync
  1145. addis r3,r0, 0x8000 /* set bit 0 */
  1146. mticcr r3
  1147. blr
  1148. .globl icache_disable
  1149. icache_disable:
  1150. addis r3,r0, 0x0000 /* clear bit 0 */
  1151. mticcr r3
  1152. isync
  1153. blr
  1154. .globl icache_status
  1155. icache_status:
  1156. mficcr r3
  1157. srwi r3, r3, 31 /* >>31 => select bit 0 */
  1158. blr
  1159. .globl dcache_enable
  1160. dcache_enable:
  1161. mflr r8
  1162. bl invalidate_dcache
  1163. mtlr r8
  1164. isync
  1165. addis r3,r0, 0x8000 /* set bit 0 */
  1166. mtdccr r3
  1167. blr
  1168. .globl dcache_disable
  1169. dcache_disable:
  1170. mflr r8
  1171. bl flush_dcache
  1172. mtlr r8
  1173. addis r3,r0, 0x0000 /* clear bit 0 */
  1174. mtdccr r3
  1175. blr
  1176. .globl dcache_status
  1177. dcache_status:
  1178. mfdccr r3
  1179. srwi r3, r3, 31 /* >>31 => select bit 0 */
  1180. blr
  1181. #endif
  1182. .globl get_pvr
  1183. get_pvr:
  1184. mfspr r3, PVR
  1185. blr
  1186. /*------------------------------------------------------------------------------- */
  1187. /* Function: out16 */
  1188. /* Description: Output 16 bits */
  1189. /*------------------------------------------------------------------------------- */
  1190. .globl out16
  1191. out16:
  1192. sth r4,0x0000(r3)
  1193. blr
  1194. /*------------------------------------------------------------------------------- */
  1195. /* Function: out16r */
  1196. /* Description: Byte reverse and output 16 bits */
  1197. /*------------------------------------------------------------------------------- */
  1198. .globl out16r
  1199. out16r:
  1200. sthbrx r4,r0,r3
  1201. blr
  1202. /*------------------------------------------------------------------------------- */
  1203. /* Function: out32r */
  1204. /* Description: Byte reverse and output 32 bits */
  1205. /*------------------------------------------------------------------------------- */
  1206. .globl out32r
  1207. out32r:
  1208. stwbrx r4,r0,r3
  1209. blr
  1210. /*------------------------------------------------------------------------------- */
  1211. /* Function: in16 */
  1212. /* Description: Input 16 bits */
  1213. /*------------------------------------------------------------------------------- */
  1214. .globl in16
  1215. in16:
  1216. lhz r3,0x0000(r3)
  1217. blr
  1218. /*------------------------------------------------------------------------------- */
  1219. /* Function: in16r */
  1220. /* Description: Input 16 bits and byte reverse */
  1221. /*------------------------------------------------------------------------------- */
  1222. .globl in16r
  1223. in16r:
  1224. lhbrx r3,r0,r3
  1225. blr
  1226. /*------------------------------------------------------------------------------- */
  1227. /* Function: in32r */
  1228. /* Description: Input 32 bits and byte reverse */
  1229. /*------------------------------------------------------------------------------- */
  1230. .globl in32r
  1231. in32r:
  1232. lwbrx r3,r0,r3
  1233. blr
  1234. /*------------------------------------------------------------------------------- */
  1235. /* Function: ppcDcbf */
  1236. /* Description: Data Cache block flush */
  1237. /* Input: r3 = effective address */
  1238. /* Output: none. */
  1239. /*------------------------------------------------------------------------------- */
  1240. .globl ppcDcbf
  1241. ppcDcbf:
  1242. dcbf r0,r3
  1243. blr
  1244. /*------------------------------------------------------------------------------- */
  1245. /* Function: ppcDcbi */
  1246. /* Description: Data Cache block Invalidate */
  1247. /* Input: r3 = effective address */
  1248. /* Output: none. */
  1249. /*------------------------------------------------------------------------------- */
  1250. .globl ppcDcbi
  1251. ppcDcbi:
  1252. dcbi r0,r3
  1253. blr
  1254. /*------------------------------------------------------------------------------- */
  1255. /* Function: ppcSync */
  1256. /* Description: Processor Synchronize */
  1257. /* Input: none. */
  1258. /* Output: none. */
  1259. /*------------------------------------------------------------------------------- */
  1260. .globl ppcSync
  1261. ppcSync:
  1262. sync
  1263. blr
  1264. /*
  1265. * void relocate_code (addr_sp, gd, addr_moni)
  1266. *
  1267. * This "function" does not return, instead it continues in RAM
  1268. * after relocating the monitor code.
  1269. *
  1270. * r3 = dest
  1271. * r4 = src
  1272. * r5 = length in bytes
  1273. * r6 = cachelinesize
  1274. */
  1275. .globl relocate_code
  1276. relocate_code:
  1277. #if defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
  1278. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  1279. defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  1280. /*
  1281. * On some 440er platforms the cache is enabled in the first TLB (Boot-CS)
  1282. * to speed up the boot process. Now this cache needs to be disabled.
  1283. */
  1284. iccci 0,0 /* Invalidate inst cache */
  1285. dccci 0,0 /* Invalidate data cache, now no longer our stack */
  1286. sync
  1287. isync
  1288. addi r1,r0,0x0000 /* TLB entry #0 */
  1289. tlbre r0,r1,0x0002 /* Read contents */
  1290. ori r0,r0,0x0c00 /* Or in the inhibit, write through bit */
  1291. tlbwe r0,r1,0x0002 /* Save it out */
  1292. sync
  1293. isync
  1294. #endif
  1295. mr r1, r3 /* Set new stack pointer */
  1296. mr r9, r4 /* Save copy of Init Data pointer */
  1297. mr r10, r5 /* Save copy of Destination Address */
  1298. mr r3, r5 /* Destination Address */
  1299. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  1300. ori r4, r4, CFG_MONITOR_BASE@l
  1301. lwz r5, GOT(__init_end)
  1302. sub r5, r5, r4
  1303. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  1304. /*
  1305. * Fix GOT pointer:
  1306. *
  1307. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
  1308. *
  1309. * Offset:
  1310. */
  1311. sub r15, r10, r4
  1312. /* First our own GOT */
  1313. add r14, r14, r15
  1314. /* the the one used by the C code */
  1315. add r30, r30, r15
  1316. /*
  1317. * Now relocate code
  1318. */
  1319. cmplw cr1,r3,r4
  1320. addi r0,r5,3
  1321. srwi. r0,r0,2
  1322. beq cr1,4f /* In place copy is not necessary */
  1323. beq 7f /* Protect against 0 count */
  1324. mtctr r0
  1325. bge cr1,2f
  1326. la r8,-4(r4)
  1327. la r7,-4(r3)
  1328. 1: lwzu r0,4(r8)
  1329. stwu r0,4(r7)
  1330. bdnz 1b
  1331. b 4f
  1332. 2: slwi r0,r0,2
  1333. add r8,r4,r0
  1334. add r7,r3,r0
  1335. 3: lwzu r0,-4(r8)
  1336. stwu r0,-4(r7)
  1337. bdnz 3b
  1338. /*
  1339. * Now flush the cache: note that we must start from a cache aligned
  1340. * address. Otherwise we might miss one cache line.
  1341. */
  1342. 4: cmpwi r6,0
  1343. add r5,r3,r5
  1344. beq 7f /* Always flush prefetch queue in any case */
  1345. subi r0,r6,1
  1346. andc r3,r3,r0
  1347. mr r4,r3
  1348. 5: dcbst 0,r4
  1349. add r4,r4,r6
  1350. cmplw r4,r5
  1351. blt 5b
  1352. sync /* Wait for all dcbst to complete on bus */
  1353. mr r4,r3
  1354. 6: icbi 0,r4
  1355. add r4,r4,r6
  1356. cmplw r4,r5
  1357. blt 6b
  1358. 7: sync /* Wait for all icbi to complete on bus */
  1359. isync
  1360. /*
  1361. * We are done. Do not return, instead branch to second part of board
  1362. * initialization, now running from RAM.
  1363. */
  1364. addi r0, r10, in_ram - _start + _START_OFFSET
  1365. mtlr r0
  1366. blr /* NEVER RETURNS! */
  1367. in_ram:
  1368. /*
  1369. * Relocation Function, r14 point to got2+0x8000
  1370. *
  1371. * Adjust got2 pointers, no need to check for 0, this code
  1372. * already puts a few entries in the table.
  1373. */
  1374. li r0,__got2_entries@sectoff@l
  1375. la r3,GOT(_GOT2_TABLE_)
  1376. lwz r11,GOT(_GOT2_TABLE_)
  1377. mtctr r0
  1378. sub r11,r3,r11
  1379. addi r3,r3,-4
  1380. 1: lwzu r0,4(r3)
  1381. add r0,r0,r11
  1382. stw r0,0(r3)
  1383. bdnz 1b
  1384. /*
  1385. * Now adjust the fixups and the pointers to the fixups
  1386. * in case we need to move ourselves again.
  1387. */
  1388. 2: li r0,__fixup_entries@sectoff@l
  1389. lwz r3,GOT(_FIXUP_TABLE_)
  1390. cmpwi r0,0
  1391. mtctr r0
  1392. addi r3,r3,-4
  1393. beq 4f
  1394. 3: lwzu r4,4(r3)
  1395. lwzux r0,r4,r11
  1396. add r0,r0,r11
  1397. stw r10,0(r3)
  1398. stw r0,0(r4)
  1399. bdnz 3b
  1400. 4:
  1401. clear_bss:
  1402. /*
  1403. * Now clear BSS segment
  1404. */
  1405. lwz r3,GOT(__bss_start)
  1406. lwz r4,GOT(_end)
  1407. cmplw 0, r3, r4
  1408. beq 6f
  1409. li r0, 0
  1410. 5:
  1411. stw r0, 0(r3)
  1412. addi r3, r3, 4
  1413. cmplw 0, r3, r4
  1414. bne 5b
  1415. 6:
  1416. mr r3, r9 /* Init Data pointer */
  1417. mr r4, r10 /* Destination Address */
  1418. bl board_init_r
  1419. /*
  1420. * Copy exception vector code to low memory
  1421. *
  1422. * r3: dest_addr
  1423. * r7: source address, r8: end address, r9: target address
  1424. */
  1425. .globl trap_init
  1426. trap_init:
  1427. lwz r7, GOT(_start_of_vectors)
  1428. lwz r8, GOT(_end_of_vectors)
  1429. li r9, 0x100 /* reset vector always at 0x100 */
  1430. cmplw 0, r7, r8
  1431. bgelr /* return if r7>=r8 - just in case */
  1432. mflr r4 /* save link register */
  1433. 1:
  1434. lwz r0, 0(r7)
  1435. stw r0, 0(r9)
  1436. addi r7, r7, 4
  1437. addi r9, r9, 4
  1438. cmplw 0, r7, r8
  1439. bne 1b
  1440. /*
  1441. * relocate `hdlr' and `int_return' entries
  1442. */
  1443. li r7, .L_MachineCheck - _start + _START_OFFSET
  1444. li r8, Alignment - _start + _START_OFFSET
  1445. 2:
  1446. bl trap_reloc
  1447. addi r7, r7, 0x100 /* next exception vector */
  1448. cmplw 0, r7, r8
  1449. blt 2b
  1450. li r7, .L_Alignment - _start + _START_OFFSET
  1451. bl trap_reloc
  1452. li r7, .L_ProgramCheck - _start + _START_OFFSET
  1453. bl trap_reloc
  1454. #ifdef CONFIG_440
  1455. li r7, .L_FPUnavailable - _start + _START_OFFSET
  1456. bl trap_reloc
  1457. li r7, .L_Decrementer - _start + _START_OFFSET
  1458. bl trap_reloc
  1459. li r7, .L_APU - _start + _START_OFFSET
  1460. bl trap_reloc
  1461. li r7, .L_InstructionTLBError - _start + _START_OFFSET
  1462. bl trap_reloc
  1463. li r7, .L_DataTLBError - _start + _START_OFFSET
  1464. bl trap_reloc
  1465. #else /* CONFIG_440 */
  1466. li r7, .L_PIT - _start + _START_OFFSET
  1467. bl trap_reloc
  1468. li r7, .L_InstructionTLBMiss - _start + _START_OFFSET
  1469. bl trap_reloc
  1470. li r7, .L_DataTLBMiss - _start + _START_OFFSET
  1471. bl trap_reloc
  1472. #endif /* CONFIG_440 */
  1473. li r7, .L_DebugBreakpoint - _start + _START_OFFSET
  1474. bl trap_reloc
  1475. #if !defined(CONFIG_440)
  1476. addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
  1477. oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
  1478. mtmsr r7 /* change MSR */
  1479. #else
  1480. bl __440_msr_set
  1481. b __440_msr_continue
  1482. __440_msr_set:
  1483. addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
  1484. oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
  1485. mtspr srr1,r7
  1486. mflr r7
  1487. mtspr srr0,r7
  1488. rfi
  1489. __440_msr_continue:
  1490. #endif
  1491. mtlr r4 /* restore link register */
  1492. blr
  1493. /*
  1494. * Function: relocate entries for one exception vector
  1495. */
  1496. trap_reloc:
  1497. lwz r0, 0(r7) /* hdlr ... */
  1498. add r0, r0, r3 /* ... += dest_addr */
  1499. stw r0, 0(r7)
  1500. lwz r0, 4(r7) /* int_return ... */
  1501. add r0, r0, r3 /* ... += dest_addr */
  1502. stw r0, 4(r7)
  1503. blr
  1504. #if defined(CONFIG_440)
  1505. /*----------------------------------------------------------------------------+
  1506. | dcbz_area.
  1507. +----------------------------------------------------------------------------*/
  1508. function_prolog(dcbz_area)
  1509. rlwinm. r5,r4,0,27,31
  1510. rlwinm r5,r4,27,5,31
  1511. beq ..d_ra2
  1512. addi r5,r5,0x0001
  1513. ..d_ra2:mtctr r5
  1514. ..d_ag2:dcbz r0,r3
  1515. addi r3,r3,32
  1516. bdnz ..d_ag2
  1517. sync
  1518. blr
  1519. function_epilog(dcbz_area)
  1520. /*----------------------------------------------------------------------------+
  1521. | dflush. Assume 32K at vector address is cachable.
  1522. +----------------------------------------------------------------------------*/
  1523. function_prolog(dflush)
  1524. mfmsr r9
  1525. rlwinm r8,r9,0,15,13
  1526. rlwinm r8,r8,0,17,15
  1527. mtmsr r8
  1528. addi r3,r0,0x0000
  1529. mtspr dvlim,r3
  1530. mfspr r3,ivpr
  1531. addi r4,r0,1024
  1532. mtctr r4
  1533. ..dflush_loop:
  1534. lwz r6,0x0(r3)
  1535. addi r3,r3,32
  1536. bdnz ..dflush_loop
  1537. addi r3,r3,-32
  1538. mtctr r4
  1539. ..ag: dcbf r0,r3
  1540. addi r3,r3,-32
  1541. bdnz ..ag
  1542. sync
  1543. mtmsr r9
  1544. blr
  1545. function_epilog(dflush)
  1546. #endif /* CONFIG_440 */
  1547. #endif /* CONFIG_NAND_SPL */
  1548. /*------------------------------------------------------------------------------- */
  1549. /* Function: in8 */
  1550. /* Description: Input 8 bits */
  1551. /*------------------------------------------------------------------------------- */
  1552. .globl in8
  1553. in8:
  1554. lbz r3,0x0000(r3)
  1555. blr
  1556. /*------------------------------------------------------------------------------- */
  1557. /* Function: out8 */
  1558. /* Description: Output 8 bits */
  1559. /*------------------------------------------------------------------------------- */
  1560. .globl out8
  1561. out8:
  1562. stb r4,0x0000(r3)
  1563. blr
  1564. /*------------------------------------------------------------------------------- */
  1565. /* Function: out32 */
  1566. /* Description: Output 32 bits */
  1567. /*------------------------------------------------------------------------------- */
  1568. .globl out32
  1569. out32:
  1570. stw r4,0x0000(r3)
  1571. blr
  1572. /*------------------------------------------------------------------------------- */
  1573. /* Function: in32 */
  1574. /* Description: Input 32 bits */
  1575. /*------------------------------------------------------------------------------- */
  1576. .globl in32
  1577. in32:
  1578. lwz 3,0x0000(3)
  1579. blr
  1580. invalidate_icache:
  1581. iccci r0,r0 /* for 405, iccci invalidates the */
  1582. blr /* entire I cache */
  1583. invalidate_dcache:
  1584. addi r6,0,0x0000 /* clear GPR 6 */
  1585. /* Do loop for # of dcache congruence classes. */
  1586. lis r7, (CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)@ha /* TBS for large sized cache */
  1587. ori r7, r7, (CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)@l
  1588. /* NOTE: dccci invalidates both */
  1589. mtctr r7 /* ways in the D cache */
  1590. ..dcloop:
  1591. dccci 0,r6 /* invalidate line */
  1592. addi r6,r6, CFG_CACHELINE_SIZE /* bump to next line */
  1593. bdnz ..dcloop
  1594. blr
  1595. /**************************************************************************/
  1596. /* PPC405EP specific stuff */
  1597. /**************************************************************************/
  1598. #ifdef CONFIG_405EP
  1599. ppc405ep_init:
  1600. #ifdef CONFIG_BUBINGA
  1601. /*
  1602. * Initialize EBC chip selects 1 & 4 and GPIO pins (for alternate
  1603. * function) to support FPGA and NVRAM accesses below.
  1604. */
  1605. lis r3,GPIO0_OSRH@h /* config GPIO output select */
  1606. ori r3,r3,GPIO0_OSRH@l
  1607. lis r4,CFG_GPIO0_OSRH@h
  1608. ori r4,r4,CFG_GPIO0_OSRH@l
  1609. stw r4,0(r3)
  1610. lis r3,GPIO0_OSRL@h
  1611. ori r3,r3,GPIO0_OSRL@l
  1612. lis r4,CFG_GPIO0_OSRL@h
  1613. ori r4,r4,CFG_GPIO0_OSRL@l
  1614. stw r4,0(r3)
  1615. lis r3,GPIO0_ISR1H@h /* config GPIO input select */
  1616. ori r3,r3,GPIO0_ISR1H@l
  1617. lis r4,CFG_GPIO0_ISR1H@h
  1618. ori r4,r4,CFG_GPIO0_ISR1H@l
  1619. stw r4,0(r3)
  1620. lis r3,GPIO0_ISR1L@h
  1621. ori r3,r3,GPIO0_ISR1L@l
  1622. lis r4,CFG_GPIO0_ISR1L@h
  1623. ori r4,r4,CFG_GPIO0_ISR1L@l
  1624. stw r4,0(r3)
  1625. lis r3,GPIO0_TSRH@h /* config GPIO three-state select */
  1626. ori r3,r3,GPIO0_TSRH@l
  1627. lis r4,CFG_GPIO0_TSRH@h
  1628. ori r4,r4,CFG_GPIO0_TSRH@l
  1629. stw r4,0(r3)
  1630. lis r3,GPIO0_TSRL@h
  1631. ori r3,r3,GPIO0_TSRL@l
  1632. lis r4,CFG_GPIO0_TSRL@h
  1633. ori r4,r4,CFG_GPIO0_TSRL@l
  1634. stw r4,0(r3)
  1635. lis r3,GPIO0_TCR@h /* config GPIO driver output enables */
  1636. ori r3,r3,GPIO0_TCR@l
  1637. lis r4,CFG_GPIO0_TCR@h
  1638. ori r4,r4,CFG_GPIO0_TCR@l
  1639. stw r4,0(r3)
  1640. li r3,pb1ap /* program EBC bank 1 for RTC access */
  1641. mtdcr ebccfga,r3
  1642. lis r3,CFG_EBC_PB1AP@h
  1643. ori r3,r3,CFG_EBC_PB1AP@l
  1644. mtdcr ebccfgd,r3
  1645. li r3,pb1cr
  1646. mtdcr ebccfga,r3
  1647. lis r3,CFG_EBC_PB1CR@h
  1648. ori r3,r3,CFG_EBC_PB1CR@l
  1649. mtdcr ebccfgd,r3
  1650. li r3,pb1ap /* program EBC bank 1 for RTC access */
  1651. mtdcr ebccfga,r3
  1652. lis r3,CFG_EBC_PB1AP@h
  1653. ori r3,r3,CFG_EBC_PB1AP@l
  1654. mtdcr ebccfgd,r3
  1655. li r3,pb1cr
  1656. mtdcr ebccfga,r3
  1657. lis r3,CFG_EBC_PB1CR@h
  1658. ori r3,r3,CFG_EBC_PB1CR@l
  1659. mtdcr ebccfgd,r3
  1660. li r3,pb4ap /* program EBC bank 4 for FPGA access */
  1661. mtdcr ebccfga,r3
  1662. lis r3,CFG_EBC_PB4AP@h
  1663. ori r3,r3,CFG_EBC_PB4AP@l
  1664. mtdcr ebccfgd,r3
  1665. li r3,pb4cr
  1666. mtdcr ebccfga,r3
  1667. lis r3,CFG_EBC_PB4CR@h
  1668. ori r3,r3,CFG_EBC_PB4CR@l
  1669. mtdcr ebccfgd,r3
  1670. #endif
  1671. #ifndef CFG_CPC0_PCI
  1672. li r3,CPC0_PCI_HOST_CFG_EN
  1673. #ifdef CONFIG_BUBINGA
  1674. /*
  1675. !-----------------------------------------------------------------------
  1676. ! Check FPGA for PCI internal/external arbitration
  1677. ! If board is set to internal arbitration, update cpc0_pci
  1678. !-----------------------------------------------------------------------
  1679. */
  1680. addis r5,r0,FPGA_REG1@h /* set offset for FPGA_REG1 */
  1681. ori r5,r5,FPGA_REG1@l
  1682. lbz r5,0x0(r5) /* read to get PCI arb selection */
  1683. andi. r6,r5,FPGA_REG1_PCI_INT_ARB /* using internal arbiter ?*/
  1684. beq ..pci_cfg_set /* if not set, then bypass reg write*/
  1685. #endif
  1686. ori r3,r3,CPC0_PCI_ARBIT_EN
  1687. #else /* CFG_CPC0_PCI */
  1688. li r3,CFG_CPC0_PCI
  1689. #endif /* CFG_CPC0_PCI */
  1690. ..pci_cfg_set:
  1691. mtdcr CPC0_PCI, r3 /* Enable internal arbiter*/
  1692. /*
  1693. !-----------------------------------------------------------------------
  1694. ! Check to see if chip is in bypass mode.
  1695. ! If so, write stored CPC0_PLLMR0 and CPC0_PLLMR1 values and perform a
  1696. ! CPU reset Otherwise, skip this step and keep going.
  1697. ! Note: Running BIOS in bypass mode is not supported since PLB speed
  1698. ! will not be fast enough for the SDRAM (min 66MHz)
  1699. !-----------------------------------------------------------------------
  1700. */
  1701. mfdcr r5, CPC0_PLLMR1
  1702. rlwinm r4,r5,1,0x1 /* get system clock source (SSCS) */
  1703. cmpi cr0,0,r4,0x1
  1704. beq pll_done /* if SSCS =b'1' then PLL has */
  1705. /* already been set */
  1706. /* and CPU has been reset */
  1707. /* so skip to next section */
  1708. #ifdef CONFIG_BUBINGA
  1709. /*
  1710. !-----------------------------------------------------------------------
  1711. ! Read NVRAM to get value to write in PLLMR.
  1712. ! If value has not been correctly saved, write default value
  1713. ! Default config values (assuming on-board 33MHz SYS_CLK) are above.
  1714. ! See CPU_DEFAULT_200 and CPU_DEFAULT_266 above.
  1715. !
  1716. ! WARNING: This code assumes the first three words in the nvram_t
  1717. ! structure in openbios.h. Changing the beginning of
  1718. ! the structure will break this code.
  1719. !
  1720. !-----------------------------------------------------------------------
  1721. */
  1722. addis r3,0,NVRAM_BASE@h
  1723. addi r3,r3,NVRAM_BASE@l
  1724. lwz r4, 0(r3)
  1725. addis r5,0,NVRVFY1@h
  1726. addi r5,r5,NVRVFY1@l
  1727. cmp cr0,0,r4,r5 /* Compare 1st NVRAM Magic number*/
  1728. bne ..no_pllset
  1729. addi r3,r3,4
  1730. lwz r4, 0(r3)
  1731. addis r5,0,NVRVFY2@h
  1732. addi r5,r5,NVRVFY2@l
  1733. cmp cr0,0,r4,r5 /* Compare 2 NVRAM Magic number */
  1734. bne ..no_pllset
  1735. addi r3,r3,8 /* Skip over conf_size */
  1736. lwz r4, 4(r3) /* Load PLLMR1 value from NVRAM */
  1737. lwz r3, 0(r3) /* Load PLLMR0 value from NVRAM */
  1738. rlwinm r5,r4,1,0x1 /* get system clock source (SSCS) */
  1739. cmpi cr0,0,r5,1 /* See if PLL is locked */
  1740. beq pll_write
  1741. ..no_pllset:
  1742. #endif /* CONFIG_BUBINGA */
  1743. addis r3,0,PLLMR0_DEFAULT@h /* PLLMR0 default value */
  1744. ori r3,r3,PLLMR0_DEFAULT@l /* */
  1745. addis r4,0,PLLMR1_DEFAULT@h /* PLLMR1 default value */
  1746. ori r4,r4,PLLMR1_DEFAULT@l /* */
  1747. b pll_write /* Write the CPC0_PLLMR with new value */
  1748. pll_done:
  1749. /*
  1750. !-----------------------------------------------------------------------
  1751. ! Clear Soft Reset Register
  1752. ! This is needed to enable PCI if not booting from serial EPROM
  1753. !-----------------------------------------------------------------------
  1754. */
  1755. addi r3, 0, 0x0
  1756. mtdcr CPC0_SRR, r3
  1757. addis r3,0,0x0010
  1758. mtctr r3
  1759. pci_wait:
  1760. bdnz pci_wait
  1761. blr /* return to main code */
  1762. /*
  1763. !-----------------------------------------------------------------------------
  1764. ! Function: pll_write
  1765. ! Description: Updates the value of the CPC0_PLLMR according to CMOS27E documentation
  1766. ! That is:
  1767. ! 1. Pll is first disabled (de-activated by putting in bypass mode)
  1768. ! 2. PLL is reset
  1769. ! 3. Clock dividers are set while PLL is held in reset and bypassed
  1770. ! 4. PLL Reset is cleared
  1771. ! 5. Wait 100us for PLL to lock
  1772. ! 6. A core reset is performed
  1773. ! Input: r3 = Value to write to CPC0_PLLMR0
  1774. ! Input: r4 = Value to write to CPC0_PLLMR1
  1775. ! Output r3 = none
  1776. !-----------------------------------------------------------------------------
  1777. */
  1778. pll_write:
  1779. mfdcr r5, CPC0_UCR
  1780. andis. r5,r5,0xFFFF
  1781. ori r5,r5,0x0101 /* Stop the UART clocks */
  1782. mtdcr CPC0_UCR,r5 /* Before changing PLL */
  1783. mfdcr r5, CPC0_PLLMR1
  1784. rlwinm r5,r5,0,0x7FFFFFFF /* Disable PLL */
  1785. mtdcr CPC0_PLLMR1,r5
  1786. oris r5,r5,0x4000 /* Set PLL Reset */
  1787. mtdcr CPC0_PLLMR1,r5
  1788. mtdcr CPC0_PLLMR0,r3 /* Set clock dividers */
  1789. rlwinm r5,r4,0,0x3FFFFFFF /* Reset & Bypass new PLL dividers */
  1790. oris r5,r5,0x4000 /* Set PLL Reset */
  1791. mtdcr CPC0_PLLMR1,r5 /* Set clock dividers */
  1792. rlwinm r5,r5,0,0xBFFFFFFF /* Clear PLL Reset */
  1793. mtdcr CPC0_PLLMR1,r5
  1794. /*
  1795. ! Wait min of 100us for PLL to lock.
  1796. ! See CMOS 27E databook for more info.
  1797. ! At 200MHz, that means waiting 20,000 instructions
  1798. */
  1799. addi r3,0,20000 /* 2000 = 0x4e20 */
  1800. mtctr r3
  1801. pll_wait:
  1802. bdnz pll_wait
  1803. oris r5,r5,0x8000 /* Enable PLL */
  1804. mtdcr CPC0_PLLMR1,r5 /* Engage */
  1805. /*
  1806. * Reset CPU to guarantee timings are OK
  1807. * Not sure if this is needed...
  1808. */
  1809. addis r3,0,0x1000
  1810. mtspr dbcr0,r3 /* This will cause a CPU core reset, and */
  1811. /* execution will continue from the poweron */
  1812. /* vector of 0xfffffffc */
  1813. #endif /* CONFIG_405EP */
  1814. #if defined(CONFIG_440)
  1815. /*----------------------------------------------------------------------------+
  1816. | mttlb3.
  1817. +----------------------------------------------------------------------------*/
  1818. function_prolog(mttlb3)
  1819. TLBWE(4,3,2)
  1820. blr
  1821. function_epilog(mttlb3)
  1822. /*----------------------------------------------------------------------------+
  1823. | mftlb3.
  1824. +----------------------------------------------------------------------------*/
  1825. function_prolog(mftlb3)
  1826. TLBRE(3,3,2)
  1827. blr
  1828. function_epilog(mftlb3)
  1829. /*----------------------------------------------------------------------------+
  1830. | mttlb2.
  1831. +----------------------------------------------------------------------------*/
  1832. function_prolog(mttlb2)
  1833. TLBWE(4,3,1)
  1834. blr
  1835. function_epilog(mttlb2)
  1836. /*----------------------------------------------------------------------------+
  1837. | mftlb2.
  1838. +----------------------------------------------------------------------------*/
  1839. function_prolog(mftlb2)
  1840. TLBRE(3,3,1)
  1841. blr
  1842. function_epilog(mftlb2)
  1843. /*----------------------------------------------------------------------------+
  1844. | mttlb1.
  1845. +----------------------------------------------------------------------------*/
  1846. function_prolog(mttlb1)
  1847. TLBWE(4,3,0)
  1848. blr
  1849. function_epilog(mttlb1)
  1850. /*----------------------------------------------------------------------------+
  1851. | mftlb1.
  1852. +----------------------------------------------------------------------------*/
  1853. function_prolog(mftlb1)
  1854. TLBRE(3,3,0)
  1855. blr
  1856. function_epilog(mftlb1)
  1857. #endif /* CONFIG_440 */