start.S 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067
  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,0x1000
  275. mtspr ivor10,r1 /* Decrementer (PIT for 440) */
  276. li r1,0x1400
  277. mtspr ivor13,r1 /* Data TLB error */
  278. li r1,0x1300
  279. mtspr ivor14,r1 /* Instr TLB error */
  280. li r1,0x2000
  281. mtspr ivor15,r1 /* Debug */
  282. /*----------------------------------------------------------------*/
  283. /* Configure cache regions */
  284. /*----------------------------------------------------------------*/
  285. mtspr inv0,r0
  286. mtspr inv1,r0
  287. mtspr inv2,r0
  288. mtspr inv3,r0
  289. mtspr dnv0,r0
  290. mtspr dnv1,r0
  291. mtspr dnv2,r0
  292. mtspr dnv3,r0
  293. mtspr itv0,r0
  294. mtspr itv1,r0
  295. mtspr itv2,r0
  296. mtspr itv3,r0
  297. mtspr dtv0,r0
  298. mtspr dtv1,r0
  299. mtspr dtv2,r0
  300. mtspr dtv3,r0
  301. /*----------------------------------------------------------------*/
  302. /* Cache victim limits */
  303. /*----------------------------------------------------------------*/
  304. /* floors 0, ceiling max to use the entire cache -- nothing locked
  305. */
  306. lis r1,0x0001
  307. ori r1,r1,0xf800
  308. mtspr ivlim,r1
  309. mtspr dvlim,r1
  310. /*----------------------------------------------------------------+
  311. |Initialize MMUCR[STID] = 0.
  312. +-----------------------------------------------------------------*/
  313. mfspr r0,mmucr
  314. addis r1,0,0xFFFF
  315. ori r1,r1,0xFF00
  316. and r0,r0,r1
  317. mtspr mmucr,r0
  318. /*----------------------------------------------------------------*/
  319. /* Clear all TLB entries -- TID = 0, TS = 0 */
  320. /*----------------------------------------------------------------*/
  321. addis r0,0,0x0000
  322. li r1,0x003f /* 64 TLB entries */
  323. mtctr r1
  324. rsttlb: tlbwe r0,r1,0x0000 /* Invalidate all entries (V=0)*/
  325. tlbwe r0,r1,0x0001
  326. tlbwe r0,r1,0x0002
  327. subi r1,r1,0x0001
  328. bdnz rsttlb
  329. /*----------------------------------------------------------------*/
  330. /* TLB entry setup -- step thru tlbtab */
  331. /*----------------------------------------------------------------*/
  332. #if defined(CONFIG_440SPE)
  333. /*----------------------------------------------------------------*/
  334. /* We have different TLB tables for revA and rev B of 440SPe */
  335. /*----------------------------------------------------------------*/
  336. mfspr r1, PVR
  337. lis r0,0x5342
  338. ori r0,r0,0x1891
  339. cmpw r7,r1,r0
  340. bne r7,..revA
  341. bl tlbtabB
  342. b ..goon
  343. ..revA:
  344. bl tlbtabA
  345. ..goon:
  346. #else
  347. bl tlbtab /* Get tlbtab pointer */
  348. #endif
  349. mr r5,r0
  350. li r1,0x003f /* 64 TLB entries max */
  351. mtctr r1
  352. li r4,0 /* TLB # */
  353. addi r5,r5,-4
  354. 1: lwzu r0,4(r5)
  355. cmpwi r0,0
  356. beq 2f /* 0 marks end */
  357. lwzu r1,4(r5)
  358. lwzu r2,4(r5)
  359. tlbwe r0,r4,0 /* TLB Word 0 */
  360. tlbwe r1,r4,1 /* TLB Word 1 */
  361. tlbwe r2,r4,2 /* TLB Word 2 */
  362. addi r4,r4,1 /* Next TLB */
  363. bdnz 1b
  364. /*----------------------------------------------------------------*/
  365. /* Continue from 'normal' start */
  366. /*----------------------------------------------------------------*/
  367. 2:
  368. #if defined(CONFIG_NAND_SPL)
  369. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  370. /*
  371. * Enable internal SRAM (only on 440EPx/GRx, 440EP/GR have no OCM)
  372. */
  373. lis r2,0x7fff
  374. ori r2,r2,0xffff
  375. mfdcr r1,isram0_dpc
  376. and r1,r1,r2 /* Disable parity check */
  377. mtdcr isram0_dpc,r1
  378. mfdcr r1,isram0_pmeg
  379. and r1,r1,r2 /* Disable pwr mgmt */
  380. mtdcr isram0_pmeg,r1
  381. #endif
  382. #if defined(CONFIG_440EP)
  383. /*
  384. * On 440EP with no internal SRAM, we setup SDRAM very early
  385. * and copy the NAND_SPL to SDRAM and jump to it
  386. */
  387. /* Clear Dcache to use as RAM */
  388. addis r3,r0,CFG_INIT_RAM_ADDR@h
  389. ori r3,r3,CFG_INIT_RAM_ADDR@l
  390. addis r4,r0,CFG_INIT_RAM_END@h
  391. ori r4,r4,CFG_INIT_RAM_END@l
  392. rlwinm. r5,r4,0,27,31
  393. rlwinm r5,r4,27,5,31
  394. beq ..d_ran3
  395. addi r5,r5,0x0001
  396. ..d_ran3:
  397. mtctr r5
  398. ..d_ag3:
  399. dcbz r0,r3
  400. addi r3,r3,32
  401. bdnz ..d_ag3
  402. /*----------------------------------------------------------------*/
  403. /* Setup the stack in internal SRAM */
  404. /*----------------------------------------------------------------*/
  405. lis r1,CFG_INIT_RAM_ADDR@h
  406. ori r1,r1,CFG_INIT_SP_OFFSET@l
  407. li r0,0
  408. stwu r0,-4(r1)
  409. stwu r0,-4(r1) /* Terminate call chain */
  410. stwu r1,-8(r1) /* Save back chain and move SP */
  411. lis r0,RESET_VECTOR@h /* Address of reset vector */
  412. ori r0,r0, RESET_VECTOR@l
  413. stwu r1,-8(r1) /* Save back chain and move SP */
  414. stw r0,+12(r1) /* Save return addr (underflow vect) */
  415. sync
  416. bl early_sdram_init
  417. sync
  418. #endif /* CONFIG_440EP */
  419. /*
  420. * Copy SPL from cache into internal SRAM
  421. */
  422. li r4,(CFG_NAND_BOOT_SPL_SIZE >> 2) - 1
  423. mtctr r4
  424. lis r2,CFG_NAND_BOOT_SPL_SRC@h
  425. ori r2,r2,CFG_NAND_BOOT_SPL_SRC@l
  426. lis r3,CFG_NAND_BOOT_SPL_DST@h
  427. ori r3,r3,CFG_NAND_BOOT_SPL_DST@l
  428. spl_loop:
  429. lwzu r4,4(r2)
  430. stwu r4,4(r3)
  431. bdnz spl_loop
  432. /*
  433. * Jump to code in RAM
  434. */
  435. bl 00f
  436. 00: mflr r10
  437. lis r3,(CFG_NAND_BOOT_SPL_SRC - CFG_NAND_BOOT_SPL_DST)@h
  438. ori r3,r3,(CFG_NAND_BOOT_SPL_SRC - CFG_NAND_BOOT_SPL_DST)@l
  439. sub r10,r10,r3
  440. addi r10,r10,28
  441. mtlr r10
  442. blr
  443. start_ram:
  444. sync
  445. isync
  446. #endif /* CONFIG_NAND_SPL */
  447. bl 3f
  448. b _start
  449. 3: li r0,0
  450. mtspr srr1,r0 /* Keep things disabled for now */
  451. mflr r1
  452. mtspr srr0,r1
  453. rfi
  454. #endif /* CONFIG_440 */
  455. /*
  456. * r3 - 1st arg to board_init(): IMMP pointer
  457. * r4 - 2nd arg to board_init(): boot flag
  458. */
  459. #ifndef CONFIG_NAND_SPL
  460. .text
  461. .long 0x27051956 /* U-Boot Magic Number */
  462. .globl version_string
  463. version_string:
  464. .ascii U_BOOT_VERSION
  465. .ascii " (", __DATE__, " - ", __TIME__, ")"
  466. .ascii CONFIG_IDENT_STRING, "\0"
  467. /*
  468. * Maybe this should be moved somewhere else because the current
  469. * location (0x100) is where the CriticalInput Execption should be.
  470. */
  471. . = EXC_OFF_SYS_RESET
  472. #endif
  473. .globl _start
  474. _start:
  475. /*****************************************************************************/
  476. #if defined(CONFIG_440)
  477. /*----------------------------------------------------------------*/
  478. /* Clear and set up some registers. */
  479. /*----------------------------------------------------------------*/
  480. li r0,0x0000
  481. lis r1,0xffff
  482. mtspr dec,r0 /* prevent dec exceptions */
  483. mtspr tbl,r0 /* prevent fit & wdt exceptions */
  484. mtspr tbu,r0
  485. mtspr tsr,r1 /* clear all timer exception status */
  486. mtspr tcr,r0 /* disable all */
  487. mtspr esr,r0 /* clear exception syndrome register */
  488. mtxer r0 /* clear integer exception register */
  489. /*----------------------------------------------------------------*/
  490. /* Debug setup -- some (not very good) ice's need an event*/
  491. /* to establish control :-( Define CFG_INIT_DBCR to the dbsr */
  492. /* value you need in this case 0x8cff 0000 should do the trick */
  493. /*----------------------------------------------------------------*/
  494. #if defined(CFG_INIT_DBCR)
  495. lis r1,0xffff
  496. ori r1,r1,0xffff
  497. mtspr dbsr,r1 /* Clear all status bits */
  498. lis r0,CFG_INIT_DBCR@h
  499. ori r0,r0,CFG_INIT_DBCR@l
  500. mtspr dbcr0,r0
  501. isync
  502. #endif
  503. /*----------------------------------------------------------------*/
  504. /* Setup the internal SRAM */
  505. /*----------------------------------------------------------------*/
  506. li r0,0
  507. #ifdef CFG_INIT_RAM_DCACHE
  508. /* Clear Dcache to use as RAM */
  509. addis r3,r0,CFG_INIT_RAM_ADDR@h
  510. ori r3,r3,CFG_INIT_RAM_ADDR@l
  511. addis r4,r0,CFG_INIT_RAM_END@h
  512. ori r4,r4,CFG_INIT_RAM_END@l
  513. rlwinm. r5,r4,0,27,31
  514. rlwinm r5,r4,27,5,31
  515. beq ..d_ran
  516. addi r5,r5,0x0001
  517. ..d_ran:
  518. mtctr r5
  519. ..d_ag:
  520. dcbz r0,r3
  521. addi r3,r3,32
  522. bdnz ..d_ag
  523. #endif /* CFG_INIT_RAM_DCACHE */
  524. /* 440EP & 440GR are only 440er PPC's without internal SRAM */
  525. #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR)
  526. /* not all PPC's have internal SRAM usable as L2-cache */
  527. #if defined(CONFIG_440GX) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  528. mtdcr l2_cache_cfg,r0 /* Ensure L2 Cache is off */
  529. #endif
  530. lis r2,0x7fff
  531. ori r2,r2,0xffff
  532. mfdcr r1,isram0_dpc
  533. and r1,r1,r2 /* Disable parity check */
  534. mtdcr isram0_dpc,r1
  535. mfdcr r1,isram0_pmeg
  536. and r1,r1,r2 /* Disable pwr mgmt */
  537. mtdcr isram0_pmeg,r1
  538. lis r1,0x8000 /* BAS = 8000_0000 */
  539. #if defined(CONFIG_440GX) || defined(CONFIG_440SP)
  540. ori r1,r1,0x0980 /* first 64k */
  541. mtdcr isram0_sb0cr,r1
  542. lis r1,0x8001
  543. ori r1,r1,0x0980 /* second 64k */
  544. mtdcr isram0_sb1cr,r1
  545. lis r1, 0x8002
  546. ori r1,r1, 0x0980 /* third 64k */
  547. mtdcr isram0_sb2cr,r1
  548. lis r1, 0x8003
  549. ori r1,r1, 0x0980 /* fourth 64k */
  550. mtdcr isram0_sb3cr,r1
  551. #elif defined(CONFIG_440SPE)
  552. lis r1,0x0000 /* BAS = 0000_0000 */
  553. ori r1,r1,0x0984 /* first 64k */
  554. mtdcr isram0_sb0cr,r1
  555. lis r1,0x0001
  556. ori r1,r1,0x0984 /* second 64k */
  557. mtdcr isram0_sb1cr,r1
  558. lis r1, 0x0002
  559. ori r1,r1, 0x0984 /* third 64k */
  560. mtdcr isram0_sb2cr,r1
  561. lis r1, 0x0003
  562. ori r1,r1, 0x0984 /* fourth 64k */
  563. mtdcr isram0_sb3cr,r1
  564. #elif defined(CONFIG_440GP)
  565. ori r1,r1,0x0380 /* 8k rw */
  566. mtdcr isram0_sb0cr,r1
  567. mtdcr isram0_sb1cr,r0 /* Disable bank 1 */
  568. #endif
  569. #endif /* #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR) */
  570. /*----------------------------------------------------------------*/
  571. /* Setup the stack in internal SRAM */
  572. /*----------------------------------------------------------------*/
  573. lis r1,CFG_INIT_RAM_ADDR@h
  574. ori r1,r1,CFG_INIT_SP_OFFSET@l
  575. li r0,0
  576. stwu r0,-4(r1)
  577. stwu r0,-4(r1) /* Terminate call chain */
  578. stwu r1,-8(r1) /* Save back chain and move SP */
  579. lis r0,RESET_VECTOR@h /* Address of reset vector */
  580. ori r0,r0, RESET_VECTOR@l
  581. stwu r1,-8(r1) /* Save back chain and move SP */
  582. stw r0,+12(r1) /* Save return addr (underflow vect) */
  583. #ifdef CONFIG_NAND_SPL
  584. bl nand_boot /* will not return */
  585. #else
  586. GET_GOT
  587. bl cpu_init_f /* run low-level CPU init code (from Flash) */
  588. bl board_init_f
  589. #endif
  590. #endif /* CONFIG_440 */
  591. /*****************************************************************************/
  592. #ifdef CONFIG_IOP480
  593. /*----------------------------------------------------------------------- */
  594. /* Set up some machine state registers. */
  595. /*----------------------------------------------------------------------- */
  596. addi r0,r0,0x0000 /* initialize r0 to zero */
  597. mtspr esr,r0 /* clear Exception Syndrome Reg */
  598. mttcr r0 /* timer control register */
  599. mtexier r0 /* disable all interrupts */
  600. addis r4,r0,0xFFFF /* set r4 to 0xFFFFFFFF (status in the */
  601. ori r4,r4,0xFFFF /* dbsr is cleared by setting bits to 1) */
  602. mtdbsr r4 /* clear/reset the dbsr */
  603. mtexisr r4 /* clear all pending interrupts */
  604. addis r4,r0,0x8000
  605. mtexier r4 /* enable critical exceptions */
  606. addis r4,r0,0x0000 /* assume 403GCX - enable core clk */
  607. ori r4,r4,0x4020 /* dbling (no harm done on GA and GC */
  608. mtiocr r4 /* since bit not used) & DRC to latch */
  609. /* data bus on rising edge of CAS */
  610. /*----------------------------------------------------------------------- */
  611. /* Clear XER. */
  612. /*----------------------------------------------------------------------- */
  613. mtxer r0
  614. /*----------------------------------------------------------------------- */
  615. /* Invalidate i-cache and d-cache TAG arrays. */
  616. /*----------------------------------------------------------------------- */
  617. addi r3,0,1024 /* 1/4 of I-cache size, half of D-cache */
  618. addi r4,0,1024 /* 1/4 of I-cache */
  619. ..cloop:
  620. iccci 0,r3
  621. iccci r4,r3
  622. dccci 0,r3
  623. addic. r3,r3,-16 /* move back one cache line */
  624. bne ..cloop /* loop back to do rest until r3 = 0 */
  625. /* */
  626. /* initialize IOP480 so it can read 1 MB code area for SRAM spaces */
  627. /* this requires enabling MA[17..0], by default only MA[12..0] are enabled. */
  628. /* */
  629. /* first copy IOP480 register base address into r3 */
  630. addis r3,0,0x5000 /* IOP480 register base address hi */
  631. /* ori r3,r3,0x0000 / IOP480 register base address lo */
  632. #ifdef CONFIG_ADCIOP
  633. /* use r4 as the working variable */
  634. /* turn on CS3 (LOCCTL.7) */
  635. lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */
  636. andi. r4,r4,0xff7f /* make bit 7 = 0 -- CS3 mode */
  637. stw r4,0x84(r3) /* LOCTL is at offset 0x84 */
  638. #endif
  639. #ifdef CONFIG_DASA_SIM
  640. /* use r4 as the working variable */
  641. /* turn on MA17 (LOCCTL.7) */
  642. lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */
  643. ori r4,r4,0x80 /* make bit 7 = 1 -- MA17 mode */
  644. stw r4,0x84(r3) /* LOCTL is at offset 0x84 */
  645. #endif
  646. /* turn on MA16..13 (LCS0BRD.12 = 0) */
  647. lwz r4,0x100(r3) /* LCS0BRD is at offset 0x100 */
  648. andi. r4,r4,0xefff /* make bit 12 = 0 */
  649. stw r4,0x100(r3) /* LCS0BRD is at offset 0x100 */
  650. /* make sure above stores all comlete before going on */
  651. sync
  652. /* last thing, set local init status done bit (DEVINIT.31) */
  653. lwz r4,0x80(r3) /* DEVINIT is at offset 0x80 */
  654. oris r4,r4,0x8000 /* make bit 31 = 1 */
  655. stw r4,0x80(r3) /* DEVINIT is at offset 0x80 */
  656. /* clear all pending interrupts and disable all interrupts */
  657. li r4,-1 /* set p1 to 0xffffffff */
  658. stw r4,0x1b0(r3) /* clear all pending interrupts */
  659. stw r4,0x1b8(r3) /* clear all pending interrupts */
  660. li r4,0 /* set r4 to 0 */
  661. stw r4,0x1b4(r3) /* disable all interrupts */
  662. stw r4,0x1bc(r3) /* disable all interrupts */
  663. /* make sure above stores all comlete before going on */
  664. sync
  665. /*----------------------------------------------------------------------- */
  666. /* Enable two 128MB cachable regions. */
  667. /*----------------------------------------------------------------------- */
  668. addis r1,r0,0x8000
  669. addi r1,r1,0x0001
  670. mticcr r1 /* instruction cache */
  671. addis r1,r0,0x0000
  672. addi r1,r1,0x0000
  673. mtdccr r1 /* data cache */
  674. addis r1,r0,CFG_INIT_RAM_ADDR@h
  675. ori r1,r1,CFG_INIT_SP_OFFSET /* set up the stack to SDRAM */
  676. li r0, 0 /* Make room for stack frame header and */
  677. stwu r0, -4(r1) /* clear final stack frame so that */
  678. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  679. GET_GOT /* initialize GOT access */
  680. bl board_init_f /* run first part of init code (from Flash) */
  681. #endif /* CONFIG_IOP480 */
  682. /*****************************************************************************/
  683. #if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
  684. defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
  685. defined(CONFIG_405)
  686. /*----------------------------------------------------------------------- */
  687. /* Clear and set up some registers. */
  688. /*----------------------------------------------------------------------- */
  689. addi r4,r0,0x0000
  690. mtspr sgr,r4
  691. mtspr dcwr,r4
  692. mtesr r4 /* clear Exception Syndrome Reg */
  693. mttcr r4 /* clear Timer Control Reg */
  694. mtxer r4 /* clear Fixed-Point Exception Reg */
  695. mtevpr r4 /* clear Exception Vector Prefix Reg */
  696. addi r4,r0,(0xFFFF-0x10000) /* set r4 to 0xFFFFFFFF (status in the */
  697. /* dbsr is cleared by setting bits to 1) */
  698. mtdbsr r4 /* clear/reset the dbsr */
  699. /*----------------------------------------------------------------------- */
  700. /* Invalidate I and D caches. Enable I cache for defined memory regions */
  701. /* to speed things up. Leave the D cache disabled for now. It will be */
  702. /* enabled/left disabled later based on user selected menu options. */
  703. /* Be aware that the I cache may be disabled later based on the menu */
  704. /* options as well. See miscLib/main.c. */
  705. /*----------------------------------------------------------------------- */
  706. bl invalidate_icache
  707. bl invalidate_dcache
  708. /*----------------------------------------------------------------------- */
  709. /* Enable two 128MB cachable regions. */
  710. /*----------------------------------------------------------------------- */
  711. lis r4,0x8000
  712. ori r4,r4,0x0001
  713. mticcr r4 /* instruction cache */
  714. isync
  715. lis r4,0x0000
  716. ori r4,r4,0x0000
  717. mtdccr r4 /* data cache */
  718. #if !(defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
  719. /*----------------------------------------------------------------------- */
  720. /* Tune the speed and size for flash CS0 */
  721. /*----------------------------------------------------------------------- */
  722. bl ext_bus_cntlr_init
  723. #endif
  724. #if defined(CONFIG_405EP)
  725. /*----------------------------------------------------------------------- */
  726. /* DMA Status, clear to come up clean */
  727. /*----------------------------------------------------------------------- */
  728. addis r3,r0, 0xFFFF /* Clear all existing DMA status */
  729. ori r3,r3, 0xFFFF
  730. mtdcr dmasr, r3
  731. bl ppc405ep_init /* do ppc405ep specific init */
  732. #endif /* CONFIG_405EP */
  733. #if defined(CFG_OCM_DATA_ADDR) && defined(CFG_OCM_DATA_SIZE)
  734. #if defined(CONFIG_405EZ)
  735. /********************************************************************
  736. * Setup OCM - On Chip Memory - PPC405EZ uses OCM Controller V2
  737. *******************************************************************/
  738. /*
  739. * We can map the OCM on the PLB3, so map it at
  740. * CFG_OCM_DATA_ADDR + 0x8000
  741. */
  742. lis r3,CFG_OCM_DATA_ADDR@h /* OCM location */
  743. ori r3,r3,CFG_OCM_DATA_ADDR@l
  744. ori r3,r3,0x8270 /* 32K Offset, 16K for Bank 1, R/W/Enable */
  745. mtdcr ocmplb3cr1,r3 /* Set PLB Access */
  746. ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
  747. mtdcr ocmplb3cr2,r3 /* Set PLB Access */
  748. isync
  749. lis r3,CFG_OCM_DATA_ADDR@h /* OCM location */
  750. ori r3,r3,CFG_OCM_DATA_ADDR@l
  751. ori r3,r3,0x0270 /* 16K for Bank 1, R/W/Enable */
  752. mtdcr ocmdscr1, r3 /* Set Data Side */
  753. mtdcr ocmiscr1, r3 /* Set Instruction Side */
  754. ori r3,r3,0x4000 /* Add 0x4000 for bank 2 */
  755. mtdcr ocmdscr2, r3 /* Set Data Side */
  756. mtdcr ocmiscr2, r3 /* Set Instruction Side */
  757. addis r3,0,0x0800 /* OCM Data Parity Disable - 1 Wait State */
  758. mtdcr ocmdsisdpc,r3
  759. isync
  760. #else /* CONFIG_405EZ */
  761. /********************************************************************
  762. * Setup OCM - On Chip Memory
  763. *******************************************************************/
  764. /* Setup OCM */
  765. lis r0, 0x7FFF
  766. ori r0, r0, 0xFFFF
  767. mfdcr r3, ocmiscntl /* get instr-side IRAM config */
  768. mfdcr r4, ocmdscntl /* get data-side IRAM config */
  769. and r3, r3, r0 /* disable data-side IRAM */
  770. and r4, r4, r0 /* disable data-side IRAM */
  771. mtdcr ocmiscntl, r3 /* set instr-side IRAM config */
  772. mtdcr ocmdscntl, r4 /* set data-side IRAM config */
  773. isync
  774. lis r3,CFG_OCM_DATA_ADDR@h /* OCM location */
  775. ori r3,r3,CFG_OCM_DATA_ADDR@l
  776. mtdcr ocmdsarc, r3
  777. addis r4, 0, 0xC000 /* OCM data area enabled */
  778. mtdcr ocmdscntl, r4
  779. isync
  780. #endif /* CONFIG_405EZ */
  781. #endif
  782. #ifdef CONFIG_NAND_SPL
  783. /*
  784. * Copy SPL from cache into internal SRAM
  785. */
  786. li r4,(CFG_NAND_BOOT_SPL_SIZE >> 2) - 1
  787. mtctr r4
  788. lis r2,CFG_NAND_BOOT_SPL_SRC@h
  789. ori r2,r2,CFG_NAND_BOOT_SPL_SRC@l
  790. lis r3,CFG_NAND_BOOT_SPL_DST@h
  791. ori r3,r3,CFG_NAND_BOOT_SPL_DST@l
  792. spl_loop:
  793. lwzu r4,4(r2)
  794. stwu r4,4(r3)
  795. bdnz spl_loop
  796. /*
  797. * Jump to code in RAM
  798. */
  799. bl 00f
  800. 00: mflr r10
  801. lis r3,(CFG_NAND_BOOT_SPL_SRC - CFG_NAND_BOOT_SPL_DST)@h
  802. ori r3,r3,(CFG_NAND_BOOT_SPL_SRC - CFG_NAND_BOOT_SPL_DST)@l
  803. sub r10,r10,r3
  804. addi r10,r10,28
  805. mtlr r10
  806. blr
  807. start_ram:
  808. sync
  809. isync
  810. #endif /* CONFIG_NAND_SPL */
  811. /*----------------------------------------------------------------------- */
  812. /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */
  813. /*----------------------------------------------------------------------- */
  814. #ifdef CFG_INIT_DCACHE_CS
  815. /*----------------------------------------------------------------------- */
  816. /* Memory Bank x (nothingness) initialization 1GB+64MEG */
  817. /* used as temporary stack pointer for stage0 */
  818. /*----------------------------------------------------------------------- */
  819. li r4,PBxAP
  820. mtdcr ebccfga,r4
  821. lis r4,0x0380
  822. ori r4,r4,0x0480
  823. mtdcr ebccfgd,r4
  824. addi r4,0,PBxCR
  825. mtdcr ebccfga,r4
  826. lis r4,0x400D
  827. ori r4,r4,0xa000
  828. mtdcr ebccfgd,r4
  829. /* turn on data chache for this region */
  830. lis r4,0x0080
  831. mtdccr r4
  832. /* set stack pointer and clear stack to known value */
  833. lis r1,CFG_INIT_RAM_ADDR@h
  834. ori r1,r1,CFG_INIT_SP_OFFSET@l
  835. li r4,2048 /* we store 2048 words to stack */
  836. mtctr r4
  837. lis r2,CFG_INIT_RAM_ADDR@h /* we also clear data area */
  838. ori r2,r2,CFG_INIT_RAM_END@l /* so cant copy value from r1 */
  839. lis r4,0xdead /* we store 0xdeaddead in the stack */
  840. ori r4,r4,0xdead
  841. ..stackloop:
  842. stwu r4,-4(r2)
  843. bdnz ..stackloop
  844. li r0, 0 /* Make room for stack frame header and */
  845. stwu r0, -4(r1) /* clear final stack frame so that */
  846. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  847. /*
  848. * Set up a dummy frame to store reset vector as return address.
  849. * this causes stack underflow to reset board.
  850. */
  851. stwu r1, -8(r1) /* Save back chain and move SP */
  852. addis r0, 0, RESET_VECTOR@h /* Address of reset vector */
  853. ori r0, r0, RESET_VECTOR@l
  854. stwu r1, -8(r1) /* Save back chain and move SP */
  855. stw r0, +12(r1) /* Save return addr (underflow vect) */
  856. #elif defined(CFG_TEMP_STACK_OCM) && \
  857. (defined(CFG_OCM_DATA_ADDR) && defined(CFG_OCM_DATA_SIZE))
  858. /*
  859. * Stack in OCM.
  860. */
  861. /* Set up Stack at top of OCM */
  862. lis r1, (CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET)@h
  863. ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET)@l
  864. /* Set up a zeroized stack frame so that backtrace works right */
  865. li r0, 0
  866. stwu r0, -4(r1)
  867. stwu r0, -4(r1)
  868. /*
  869. * Set up a dummy frame to store reset vector as return address.
  870. * this causes stack underflow to reset board.
  871. */
  872. stwu r1, -8(r1) /* Save back chain and move SP */
  873. lis r0, RESET_VECTOR@h /* Address of reset vector */
  874. ori r0, r0, RESET_VECTOR@l
  875. stwu r1, -8(r1) /* Save back chain and move SP */
  876. stw r0, +12(r1) /* Save return addr (underflow vect) */
  877. #endif /* CFG_INIT_DCACHE_CS */
  878. /*----------------------------------------------------------------------- */
  879. /* Initialize SDRAM Controller */
  880. /*----------------------------------------------------------------------- */
  881. bl sdram_init
  882. /*
  883. * Setup temporary stack pointer only for boards
  884. * that do not use SDRAM SPD I2C stuff since it
  885. * is already initialized to use DCACHE or OCM
  886. * stacks.
  887. */
  888. #if !(defined(CFG_INIT_DCACHE_CS) || defined(CFG_TEMP_STACK_OCM))
  889. lis r1, CFG_INIT_RAM_ADDR@h
  890. ori r1,r1,CFG_INIT_SP_OFFSET /* set up the stack in SDRAM */
  891. li r0, 0 /* Make room for stack frame header and */
  892. stwu r0, -4(r1) /* clear final stack frame so that */
  893. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  894. /*
  895. * Set up a dummy frame to store reset vector as return address.
  896. * this causes stack underflow to reset board.
  897. */
  898. stwu r1, -8(r1) /* Save back chain and move SP */
  899. lis r0, RESET_VECTOR@h /* Address of reset vector */
  900. ori r0, r0, RESET_VECTOR@l
  901. stwu r1, -8(r1) /* Save back chain and move SP */
  902. stw r0, +12(r1) /* Save return addr (underflow vect) */
  903. #endif /* !(CFG_INIT_DCACHE_CS || !CFG_TEM_STACK_OCM) */
  904. #ifdef CONFIG_NAND_SPL
  905. bl nand_boot /* will not return */
  906. #else
  907. GET_GOT /* initialize GOT access */
  908. bl cpu_init_f /* run low-level CPU init code (from Flash) */
  909. /* NEVER RETURNS! */
  910. bl board_init_f /* run first part of init code (from Flash) */
  911. #endif /* CONFIG_NAND_SPL */
  912. #endif /* CONFIG_405GP || CONFIG_405CR || CONFIG_405 || CONFIG_405EP */
  913. /*----------------------------------------------------------------------- */
  914. #ifndef CONFIG_NAND_SPL
  915. /*****************************************************************************/
  916. .globl _start_of_vectors
  917. _start_of_vectors:
  918. #if 0
  919. /*TODO Fixup _start above so we can do this*/
  920. /* Critical input. */
  921. CRIT_EXCEPTION(0x100, CritcalInput, CritcalInputException)
  922. #endif
  923. /* Machine check */
  924. CRIT_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  925. /* Data Storage exception. */
  926. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  927. /* Instruction Storage exception. */
  928. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  929. /* External Interrupt exception. */
  930. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  931. /* Alignment exception. */
  932. . = 0x600
  933. Alignment:
  934. EXCEPTION_PROLOG
  935. mfspr r4,DAR
  936. stw r4,_DAR(r21)
  937. mfspr r5,DSISR
  938. stw r5,_DSISR(r21)
  939. addi r3,r1,STACK_FRAME_OVERHEAD
  940. li r20,MSR_KERNEL
  941. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  942. lwz r6,GOT(transfer_to_handler)
  943. mtlr r6
  944. blrl
  945. .L_Alignment:
  946. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  947. .long int_return - _start + EXC_OFF_SYS_RESET
  948. /* Program check exception */
  949. . = 0x700
  950. ProgramCheck:
  951. EXCEPTION_PROLOG
  952. addi r3,r1,STACK_FRAME_OVERHEAD
  953. li r20,MSR_KERNEL
  954. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  955. lwz r6,GOT(transfer_to_handler)
  956. mtlr r6
  957. blrl
  958. .L_ProgramCheck:
  959. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  960. .long int_return - _start + EXC_OFF_SYS_RESET
  961. /* No FPU on MPC8xx. This exception is not supposed to happen.
  962. */
  963. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  964. /* I guess we could implement decrementer, and may have
  965. * to someday for timekeeping.
  966. */
  967. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  968. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  969. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  970. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  971. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  972. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  973. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  974. /* On the MPC8xx, this is a software emulation interrupt. It occurs
  975. * for all unimplemented and illegal instructions.
  976. */
  977. STD_EXCEPTION(0x1000, PIT, PITException)
  978. STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
  979. STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
  980. STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
  981. STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
  982. STD_EXCEPTION(0x1500, Reserved5, UnknownException)
  983. STD_EXCEPTION(0x1600, Reserved6, UnknownException)
  984. STD_EXCEPTION(0x1700, Reserved7, UnknownException)
  985. STD_EXCEPTION(0x1800, Reserved8, UnknownException)
  986. STD_EXCEPTION(0x1900, Reserved9, UnknownException)
  987. STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
  988. STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
  989. STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
  990. STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
  991. STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
  992. STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
  993. CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
  994. .globl _end_of_vectors
  995. _end_of_vectors:
  996. . = 0x2100
  997. /*
  998. * This code finishes saving the registers to the exception frame
  999. * and jumps to the appropriate handler for the exception.
  1000. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  1001. */
  1002. .globl transfer_to_handler
  1003. transfer_to_handler:
  1004. stw r22,_NIP(r21)
  1005. lis r22,MSR_POW@h
  1006. andc r23,r23,r22
  1007. stw r23,_MSR(r21)
  1008. SAVE_GPR(7, r21)
  1009. SAVE_4GPRS(8, r21)
  1010. SAVE_8GPRS(12, r21)
  1011. SAVE_8GPRS(24, r21)
  1012. #if 0
  1013. andi. r23,r23,MSR_PR
  1014. mfspr r23,SPRG3 /* if from user, fix up tss.regs */
  1015. beq 2f
  1016. addi r24,r1,STACK_FRAME_OVERHEAD
  1017. stw r24,PT_REGS(r23)
  1018. 2: addi r2,r23,-TSS /* set r2 to current */
  1019. tovirt(r2,r2,r23)
  1020. #endif
  1021. mflr r23
  1022. andi. r24,r23,0x3f00 /* get vector offset */
  1023. stw r24,TRAP(r21)
  1024. li r22,0
  1025. stw r22,RESULT(r21)
  1026. mtspr SPRG2,r22 /* r1 is now kernel sp */
  1027. #if 0
  1028. addi r24,r2,TASK_STRUCT_SIZE /* check for kernel stack overflow */
  1029. cmplw 0,r1,r2
  1030. cmplw 1,r1,r24
  1031. crand 1,1,4
  1032. bgt stack_ovf /* if r2 < r1 < r2+TASK_STRUCT_SIZE */
  1033. #endif
  1034. lwz r24,0(r23) /* virtual address of handler */
  1035. lwz r23,4(r23) /* where to go when done */
  1036. mtspr SRR0,r24
  1037. mtspr SRR1,r20
  1038. mtlr r23
  1039. SYNC
  1040. rfi /* jump to handler, enable MMU */
  1041. int_return:
  1042. mfmsr r28 /* Disable interrupts */
  1043. li r4,0
  1044. ori r4,r4,MSR_EE
  1045. andc r28,r28,r4
  1046. SYNC /* Some chip revs need this... */
  1047. mtmsr r28
  1048. SYNC
  1049. lwz r2,_CTR(r1)
  1050. lwz r0,_LINK(r1)
  1051. mtctr r2
  1052. mtlr r0
  1053. lwz r2,_XER(r1)
  1054. lwz r0,_CCR(r1)
  1055. mtspr XER,r2
  1056. mtcrf 0xFF,r0
  1057. REST_10GPRS(3, r1)
  1058. REST_10GPRS(13, r1)
  1059. REST_8GPRS(23, r1)
  1060. REST_GPR(31, r1)
  1061. lwz r2,_NIP(r1) /* Restore environment */
  1062. lwz r0,_MSR(r1)
  1063. mtspr SRR0,r2
  1064. mtspr SRR1,r0
  1065. lwz r0,GPR0(r1)
  1066. lwz r2,GPR2(r1)
  1067. lwz r1,GPR1(r1)
  1068. SYNC
  1069. rfi
  1070. crit_return:
  1071. mfmsr r28 /* Disable interrupts */
  1072. li r4,0
  1073. ori r4,r4,MSR_EE
  1074. andc r28,r28,r4
  1075. SYNC /* Some chip revs need this... */
  1076. mtmsr r28
  1077. SYNC
  1078. lwz r2,_CTR(r1)
  1079. lwz r0,_LINK(r1)
  1080. mtctr r2
  1081. mtlr r0
  1082. lwz r2,_XER(r1)
  1083. lwz r0,_CCR(r1)
  1084. mtspr XER,r2
  1085. mtcrf 0xFF,r0
  1086. REST_10GPRS(3, r1)
  1087. REST_10GPRS(13, r1)
  1088. REST_8GPRS(23, r1)
  1089. REST_GPR(31, r1)
  1090. lwz r2,_NIP(r1) /* Restore environment */
  1091. lwz r0,_MSR(r1)
  1092. mtspr 990,r2 /* SRR2 */
  1093. mtspr 991,r0 /* SRR3 */
  1094. lwz r0,GPR0(r1)
  1095. lwz r2,GPR2(r1)
  1096. lwz r1,GPR1(r1)
  1097. SYNC
  1098. rfci
  1099. /* Cache functions.
  1100. */
  1101. flush_dcache:
  1102. addis r9,r0,0x0002 /* set mask for EE and CE msr bits */
  1103. ori r9,r9,0x8000
  1104. mfmsr r12 /* save msr */
  1105. andc r9,r12,r9
  1106. mtmsr r9 /* disable EE and CE */
  1107. addi r10,r0,0x0001 /* enable data cache for unused memory */
  1108. mfdccr r9 /* region 0xF8000000-0xFFFFFFFF via */
  1109. or r10,r10,r9 /* bit 31 in dccr */
  1110. mtdccr r10
  1111. /* do loop for # of congruence classes. */
  1112. lis r10,(CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)@ha /* TBS: for large cache sizes */
  1113. ori r10,r10,(CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)@l
  1114. lis r11,(CFG_DCACHE_SIZE / 2)@ha /* D cache set size - 2 way sets */
  1115. ori r11,r11,(CFG_DCACHE_SIZE / 2)@l /* D cache set size - 2 way sets */
  1116. mtctr r10
  1117. addi r10,r0,(0xE000-0x10000) /* start at 0xFFFFE000 */
  1118. add r11,r10,r11 /* add to get to other side of cache line */
  1119. ..flush_dcache_loop:
  1120. lwz r3,0(r10) /* least recently used side */
  1121. lwz r3,0(r11) /* the other side */
  1122. dccci r0,r11 /* invalidate both sides */
  1123. addi r10,r10,CFG_CACHELINE_SIZE /* bump to next line */
  1124. addi r11,r11,CFG_CACHELINE_SIZE /* bump to next line */
  1125. bdnz ..flush_dcache_loop
  1126. sync /* allow memory access to complete */
  1127. mtdccr r9 /* restore dccr */
  1128. mtmsr r12 /* restore msr */
  1129. blr
  1130. .globl icache_enable
  1131. icache_enable:
  1132. mflr r8
  1133. bl invalidate_icache
  1134. mtlr r8
  1135. isync
  1136. addis r3,r0, 0x8000 /* set bit 0 */
  1137. mticcr r3
  1138. blr
  1139. .globl icache_disable
  1140. icache_disable:
  1141. addis r3,r0, 0x0000 /* clear bit 0 */
  1142. mticcr r3
  1143. isync
  1144. blr
  1145. .globl icache_status
  1146. icache_status:
  1147. mficcr r3
  1148. srwi r3, r3, 31 /* >>31 => select bit 0 */
  1149. blr
  1150. .globl dcache_enable
  1151. dcache_enable:
  1152. mflr r8
  1153. bl invalidate_dcache
  1154. mtlr r8
  1155. isync
  1156. addis r3,r0, 0x8000 /* set bit 0 */
  1157. mtdccr r3
  1158. blr
  1159. .globl dcache_disable
  1160. dcache_disable:
  1161. mflr r8
  1162. bl flush_dcache
  1163. mtlr r8
  1164. addis r3,r0, 0x0000 /* clear bit 0 */
  1165. mtdccr r3
  1166. blr
  1167. .globl dcache_status
  1168. dcache_status:
  1169. mfdccr r3
  1170. srwi r3, r3, 31 /* >>31 => select bit 0 */
  1171. blr
  1172. .globl get_pvr
  1173. get_pvr:
  1174. mfspr r3, PVR
  1175. blr
  1176. #if !defined(CONFIG_440)
  1177. .globl wr_pit
  1178. wr_pit:
  1179. mtspr pit, r3
  1180. blr
  1181. #endif
  1182. .globl wr_tcr
  1183. wr_tcr:
  1184. mtspr tcr, r3
  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 + EXC_OFF_SYS_RESET
  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)
  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 + EXC_OFF_SYS_RESET
  1444. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  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 + EXC_OFF_SYS_RESET
  1451. bl trap_reloc
  1452. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  1453. bl trap_reloc
  1454. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  1455. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  1456. 3:
  1457. bl trap_reloc
  1458. addi r7, r7, 0x100 /* next exception vector */
  1459. cmplw 0, r7, r8
  1460. blt 3b
  1461. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  1462. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  1463. 4:
  1464. bl trap_reloc
  1465. addi r7, r7, 0x100 /* next exception vector */
  1466. cmplw 0, r7, r8
  1467. blt 4b
  1468. #if !defined(CONFIG_440)
  1469. addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
  1470. oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
  1471. mtmsr r7 /* change MSR */
  1472. #else
  1473. bl __440_msr_set
  1474. b __440_msr_continue
  1475. __440_msr_set:
  1476. addi r7,r0,0x1000 /* set ME bit (Machine Exceptions) */
  1477. oris r7,r7,0x0002 /* set CE bit (Critical Exceptions) */
  1478. mtspr srr1,r7
  1479. mflr r7
  1480. mtspr srr0,r7
  1481. rfi
  1482. __440_msr_continue:
  1483. #endif
  1484. mtlr r4 /* restore link register */
  1485. blr
  1486. /*
  1487. * Function: relocate entries for one exception vector
  1488. */
  1489. trap_reloc:
  1490. lwz r0, 0(r7) /* hdlr ... */
  1491. add r0, r0, r3 /* ... += dest_addr */
  1492. stw r0, 0(r7)
  1493. lwz r0, 4(r7) /* int_return ... */
  1494. add r0, r0, r3 /* ... += dest_addr */
  1495. stw r0, 4(r7)
  1496. blr
  1497. #if defined(CONFIG_440)
  1498. /*----------------------------------------------------------------------------+
  1499. | dcbz_area.
  1500. +----------------------------------------------------------------------------*/
  1501. function_prolog(dcbz_area)
  1502. rlwinm. r5,r4,0,27,31
  1503. rlwinm r5,r4,27,5,31
  1504. beq ..d_ra2
  1505. addi r5,r5,0x0001
  1506. ..d_ra2:mtctr r5
  1507. ..d_ag2:dcbz r0,r3
  1508. addi r3,r3,32
  1509. bdnz ..d_ag2
  1510. sync
  1511. blr
  1512. function_epilog(dcbz_area)
  1513. /*----------------------------------------------------------------------------+
  1514. | dflush. Assume 32K at vector address is cachable.
  1515. +----------------------------------------------------------------------------*/
  1516. function_prolog(dflush)
  1517. mfmsr r9
  1518. rlwinm r8,r9,0,15,13
  1519. rlwinm r8,r8,0,17,15
  1520. mtmsr r8
  1521. addi r3,r0,0x0000
  1522. mtspr dvlim,r3
  1523. mfspr r3,ivpr
  1524. addi r4,r0,1024
  1525. mtctr r4
  1526. ..dflush_loop:
  1527. lwz r6,0x0(r3)
  1528. addi r3,r3,32
  1529. bdnz ..dflush_loop
  1530. addi r3,r3,-32
  1531. mtctr r4
  1532. ..ag: dcbf r0,r3
  1533. addi r3,r3,-32
  1534. bdnz ..ag
  1535. sync
  1536. mtmsr r9
  1537. blr
  1538. function_epilog(dflush)
  1539. #endif /* CONFIG_440 */
  1540. #endif /* CONFIG_NAND_SPL */
  1541. /*------------------------------------------------------------------------------- */
  1542. /* Function: in8 */
  1543. /* Description: Input 8 bits */
  1544. /*------------------------------------------------------------------------------- */
  1545. .globl in8
  1546. in8:
  1547. lbz r3,0x0000(r3)
  1548. blr
  1549. /*------------------------------------------------------------------------------- */
  1550. /* Function: out8 */
  1551. /* Description: Output 8 bits */
  1552. /*------------------------------------------------------------------------------- */
  1553. .globl out8
  1554. out8:
  1555. stb r4,0x0000(r3)
  1556. blr
  1557. /*------------------------------------------------------------------------------- */
  1558. /* Function: out32 */
  1559. /* Description: Output 32 bits */
  1560. /*------------------------------------------------------------------------------- */
  1561. .globl out32
  1562. out32:
  1563. stw r4,0x0000(r3)
  1564. blr
  1565. /*------------------------------------------------------------------------------- */
  1566. /* Function: in32 */
  1567. /* Description: Input 32 bits */
  1568. /*------------------------------------------------------------------------------- */
  1569. .globl in32
  1570. in32:
  1571. lwz 3,0x0000(3)
  1572. blr
  1573. invalidate_icache:
  1574. iccci r0,r0 /* for 405, iccci invalidates the */
  1575. blr /* entire I cache */
  1576. invalidate_dcache:
  1577. addi r6,0,0x0000 /* clear GPR 6 */
  1578. /* Do loop for # of dcache congruence classes. */
  1579. lis r7, (CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)@ha /* TBS for large sized cache */
  1580. ori r7, r7, (CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)@l
  1581. /* NOTE: dccci invalidates both */
  1582. mtctr r7 /* ways in the D cache */
  1583. ..dcloop:
  1584. dccci 0,r6 /* invalidate line */
  1585. addi r6,r6, CFG_CACHELINE_SIZE /* bump to next line */
  1586. bdnz ..dcloop
  1587. blr
  1588. /**************************************************************************/
  1589. /* PPC405EP specific stuff */
  1590. /**************************************************************************/
  1591. #ifdef CONFIG_405EP
  1592. ppc405ep_init:
  1593. #ifdef CONFIG_BUBINGA
  1594. /*
  1595. * Initialize EBC chip selects 1 & 4 and GPIO pins (for alternate
  1596. * function) to support FPGA and NVRAM accesses below.
  1597. */
  1598. lis r3,GPIO0_OSRH@h /* config GPIO output select */
  1599. ori r3,r3,GPIO0_OSRH@l
  1600. lis r4,CFG_GPIO0_OSRH@h
  1601. ori r4,r4,CFG_GPIO0_OSRH@l
  1602. stw r4,0(r3)
  1603. lis r3,GPIO0_OSRL@h
  1604. ori r3,r3,GPIO0_OSRL@l
  1605. lis r4,CFG_GPIO0_OSRL@h
  1606. ori r4,r4,CFG_GPIO0_OSRL@l
  1607. stw r4,0(r3)
  1608. lis r3,GPIO0_ISR1H@h /* config GPIO input select */
  1609. ori r3,r3,GPIO0_ISR1H@l
  1610. lis r4,CFG_GPIO0_ISR1H@h
  1611. ori r4,r4,CFG_GPIO0_ISR1H@l
  1612. stw r4,0(r3)
  1613. lis r3,GPIO0_ISR1L@h
  1614. ori r3,r3,GPIO0_ISR1L@l
  1615. lis r4,CFG_GPIO0_ISR1L@h
  1616. ori r4,r4,CFG_GPIO0_ISR1L@l
  1617. stw r4,0(r3)
  1618. lis r3,GPIO0_TSRH@h /* config GPIO three-state select */
  1619. ori r3,r3,GPIO0_TSRH@l
  1620. lis r4,CFG_GPIO0_TSRH@h
  1621. ori r4,r4,CFG_GPIO0_TSRH@l
  1622. stw r4,0(r3)
  1623. lis r3,GPIO0_TSRL@h
  1624. ori r3,r3,GPIO0_TSRL@l
  1625. lis r4,CFG_GPIO0_TSRL@h
  1626. ori r4,r4,CFG_GPIO0_TSRL@l
  1627. stw r4,0(r3)
  1628. lis r3,GPIO0_TCR@h /* config GPIO driver output enables */
  1629. ori r3,r3,GPIO0_TCR@l
  1630. lis r4,CFG_GPIO0_TCR@h
  1631. ori r4,r4,CFG_GPIO0_TCR@l
  1632. stw r4,0(r3)
  1633. li r3,pb1ap /* program EBC bank 1 for RTC access */
  1634. mtdcr ebccfga,r3
  1635. lis r3,CFG_EBC_PB1AP@h
  1636. ori r3,r3,CFG_EBC_PB1AP@l
  1637. mtdcr ebccfgd,r3
  1638. li r3,pb1cr
  1639. mtdcr ebccfga,r3
  1640. lis r3,CFG_EBC_PB1CR@h
  1641. ori r3,r3,CFG_EBC_PB1CR@l
  1642. mtdcr ebccfgd,r3
  1643. li r3,pb1ap /* program EBC bank 1 for RTC access */
  1644. mtdcr ebccfga,r3
  1645. lis r3,CFG_EBC_PB1AP@h
  1646. ori r3,r3,CFG_EBC_PB1AP@l
  1647. mtdcr ebccfgd,r3
  1648. li r3,pb1cr
  1649. mtdcr ebccfga,r3
  1650. lis r3,CFG_EBC_PB1CR@h
  1651. ori r3,r3,CFG_EBC_PB1CR@l
  1652. mtdcr ebccfgd,r3
  1653. li r3,pb4ap /* program EBC bank 4 for FPGA access */
  1654. mtdcr ebccfga,r3
  1655. lis r3,CFG_EBC_PB4AP@h
  1656. ori r3,r3,CFG_EBC_PB4AP@l
  1657. mtdcr ebccfgd,r3
  1658. li r3,pb4cr
  1659. mtdcr ebccfga,r3
  1660. lis r3,CFG_EBC_PB4CR@h
  1661. ori r3,r3,CFG_EBC_PB4CR@l
  1662. mtdcr ebccfgd,r3
  1663. #endif
  1664. #ifndef CFG_CPC0_PCI
  1665. li r3,CPC0_PCI_HOST_CFG_EN
  1666. #ifdef CONFIG_BUBINGA
  1667. /*
  1668. !-----------------------------------------------------------------------
  1669. ! Check FPGA for PCI internal/external arbitration
  1670. ! If board is set to internal arbitration, update cpc0_pci
  1671. !-----------------------------------------------------------------------
  1672. */
  1673. addis r5,r0,FPGA_REG1@h /* set offset for FPGA_REG1 */
  1674. ori r5,r5,FPGA_REG1@l
  1675. lbz r5,0x0(r5) /* read to get PCI arb selection */
  1676. andi. r6,r5,FPGA_REG1_PCI_INT_ARB /* using internal arbiter ?*/
  1677. beq ..pci_cfg_set /* if not set, then bypass reg write*/
  1678. #endif
  1679. ori r3,r3,CPC0_PCI_ARBIT_EN
  1680. #else /* CFG_CPC0_PCI */
  1681. li r3,CFG_CPC0_PCI
  1682. #endif /* CFG_CPC0_PCI */
  1683. ..pci_cfg_set:
  1684. mtdcr CPC0_PCI, r3 /* Enable internal arbiter*/
  1685. /*
  1686. !-----------------------------------------------------------------------
  1687. ! Check to see if chip is in bypass mode.
  1688. ! If so, write stored CPC0_PLLMR0 and CPC0_PLLMR1 values and perform a
  1689. ! CPU reset Otherwise, skip this step and keep going.
  1690. ! Note: Running BIOS in bypass mode is not supported since PLB speed
  1691. ! will not be fast enough for the SDRAM (min 66MHz)
  1692. !-----------------------------------------------------------------------
  1693. */
  1694. mfdcr r5, CPC0_PLLMR1
  1695. rlwinm r4,r5,1,0x1 /* get system clock source (SSCS) */
  1696. cmpi cr0,0,r4,0x1
  1697. beq pll_done /* if SSCS =b'1' then PLL has */
  1698. /* already been set */
  1699. /* and CPU has been reset */
  1700. /* so skip to next section */
  1701. #ifdef CONFIG_BUBINGA
  1702. /*
  1703. !-----------------------------------------------------------------------
  1704. ! Read NVRAM to get value to write in PLLMR.
  1705. ! If value has not been correctly saved, write default value
  1706. ! Default config values (assuming on-board 33MHz SYS_CLK) are above.
  1707. ! See CPU_DEFAULT_200 and CPU_DEFAULT_266 above.
  1708. !
  1709. ! WARNING: This code assumes the first three words in the nvram_t
  1710. ! structure in openbios.h. Changing the beginning of
  1711. ! the structure will break this code.
  1712. !
  1713. !-----------------------------------------------------------------------
  1714. */
  1715. addis r3,0,NVRAM_BASE@h
  1716. addi r3,r3,NVRAM_BASE@l
  1717. lwz r4, 0(r3)
  1718. addis r5,0,NVRVFY1@h
  1719. addi r5,r5,NVRVFY1@l
  1720. cmp cr0,0,r4,r5 /* Compare 1st NVRAM Magic number*/
  1721. bne ..no_pllset
  1722. addi r3,r3,4
  1723. lwz r4, 0(r3)
  1724. addis r5,0,NVRVFY2@h
  1725. addi r5,r5,NVRVFY2@l
  1726. cmp cr0,0,r4,r5 /* Compare 2 NVRAM Magic number */
  1727. bne ..no_pllset
  1728. addi r3,r3,8 /* Skip over conf_size */
  1729. lwz r4, 4(r3) /* Load PLLMR1 value from NVRAM */
  1730. lwz r3, 0(r3) /* Load PLLMR0 value from NVRAM */
  1731. rlwinm r5,r4,1,0x1 /* get system clock source (SSCS) */
  1732. cmpi cr0,0,r5,1 /* See if PLL is locked */
  1733. beq pll_write
  1734. ..no_pllset:
  1735. #endif /* CONFIG_BUBINGA */
  1736. addis r3,0,PLLMR0_DEFAULT@h /* PLLMR0 default value */
  1737. ori r3,r3,PLLMR0_DEFAULT@l /* */
  1738. addis r4,0,PLLMR1_DEFAULT@h /* PLLMR1 default value */
  1739. ori r4,r4,PLLMR1_DEFAULT@l /* */
  1740. b pll_write /* Write the CPC0_PLLMR with new value */
  1741. pll_done:
  1742. /*
  1743. !-----------------------------------------------------------------------
  1744. ! Clear Soft Reset Register
  1745. ! This is needed to enable PCI if not booting from serial EPROM
  1746. !-----------------------------------------------------------------------
  1747. */
  1748. addi r3, 0, 0x0
  1749. mtdcr CPC0_SRR, r3
  1750. addis r3,0,0x0010
  1751. mtctr r3
  1752. pci_wait:
  1753. bdnz pci_wait
  1754. blr /* return to main code */
  1755. /*
  1756. !-----------------------------------------------------------------------------
  1757. ! Function: pll_write
  1758. ! Description: Updates the value of the CPC0_PLLMR according to CMOS27E documentation
  1759. ! That is:
  1760. ! 1. Pll is first disabled (de-activated by putting in bypass mode)
  1761. ! 2. PLL is reset
  1762. ! 3. Clock dividers are set while PLL is held in reset and bypassed
  1763. ! 4. PLL Reset is cleared
  1764. ! 5. Wait 100us for PLL to lock
  1765. ! 6. A core reset is performed
  1766. ! Input: r3 = Value to write to CPC0_PLLMR0
  1767. ! Input: r4 = Value to write to CPC0_PLLMR1
  1768. ! Output r3 = none
  1769. !-----------------------------------------------------------------------------
  1770. */
  1771. pll_write:
  1772. mfdcr r5, CPC0_UCR
  1773. andis. r5,r5,0xFFFF
  1774. ori r5,r5,0x0101 /* Stop the UART clocks */
  1775. mtdcr CPC0_UCR,r5 /* Before changing PLL */
  1776. mfdcr r5, CPC0_PLLMR1
  1777. rlwinm r5,r5,0,0x7FFFFFFF /* Disable PLL */
  1778. mtdcr CPC0_PLLMR1,r5
  1779. oris r5,r5,0x4000 /* Set PLL Reset */
  1780. mtdcr CPC0_PLLMR1,r5
  1781. mtdcr CPC0_PLLMR0,r3 /* Set clock dividers */
  1782. rlwinm r5,r4,0,0x3FFFFFFF /* Reset & Bypass new PLL dividers */
  1783. oris r5,r5,0x4000 /* Set PLL Reset */
  1784. mtdcr CPC0_PLLMR1,r5 /* Set clock dividers */
  1785. rlwinm r5,r5,0,0xBFFFFFFF /* Clear PLL Reset */
  1786. mtdcr CPC0_PLLMR1,r5
  1787. /*
  1788. ! Wait min of 100us for PLL to lock.
  1789. ! See CMOS 27E databook for more info.
  1790. ! At 200MHz, that means waiting 20,000 instructions
  1791. */
  1792. addi r3,0,20000 /* 2000 = 0x4e20 */
  1793. mtctr r3
  1794. pll_wait:
  1795. bdnz pll_wait
  1796. oris r5,r5,0x8000 /* Enable PLL */
  1797. mtdcr CPC0_PLLMR1,r5 /* Engage */
  1798. /*
  1799. * Reset CPU to guarantee timings are OK
  1800. * Not sure if this is needed...
  1801. */
  1802. addis r3,0,0x1000
  1803. mtspr dbcr0,r3 /* This will cause a CPU core reset, and */
  1804. /* execution will continue from the poweron */
  1805. /* vector of 0xfffffffc */
  1806. #endif /* CONFIG_405EP */
  1807. #if defined(CONFIG_440)
  1808. /*----------------------------------------------------------------------------+
  1809. | mttlb3.
  1810. +----------------------------------------------------------------------------*/
  1811. function_prolog(mttlb3)
  1812. TLBWE(4,3,2)
  1813. blr
  1814. function_epilog(mttlb3)
  1815. /*----------------------------------------------------------------------------+
  1816. | mftlb3.
  1817. +----------------------------------------------------------------------------*/
  1818. function_prolog(mftlb3)
  1819. TLBRE(3,3,2)
  1820. blr
  1821. function_epilog(mftlb3)
  1822. /*----------------------------------------------------------------------------+
  1823. | mttlb2.
  1824. +----------------------------------------------------------------------------*/
  1825. function_prolog(mttlb2)
  1826. TLBWE(4,3,1)
  1827. blr
  1828. function_epilog(mttlb2)
  1829. /*----------------------------------------------------------------------------+
  1830. | mftlb2.
  1831. +----------------------------------------------------------------------------*/
  1832. function_prolog(mftlb2)
  1833. TLBRE(3,3,1)
  1834. blr
  1835. function_epilog(mftlb2)
  1836. /*----------------------------------------------------------------------------+
  1837. | mttlb1.
  1838. +----------------------------------------------------------------------------*/
  1839. function_prolog(mttlb1)
  1840. TLBWE(4,3,0)
  1841. blr
  1842. function_epilog(mttlb1)
  1843. /*----------------------------------------------------------------------------+
  1844. | mftlb1.
  1845. +----------------------------------------------------------------------------*/
  1846. function_prolog(mftlb1)
  1847. TLBRE(3,3,0)
  1848. blr
  1849. function_epilog(mftlb1)
  1850. #endif /* CONFIG_440 */