start.S 57 KB

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