start.S 55 KB

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