start.S 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  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. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. /*------------------------------------------------------------------------------+ */
  25. /* */
  26. /* This source code has been made available to you by IBM on an AS-IS */
  27. /* basis. Anyone receiving this source is licensed under IBM */
  28. /* copyrights to use it in any way he or she deems fit, including */
  29. /* copying it, modifying it, compiling it, and redistributing it either */
  30. /* with or without modifications. No license under IBM patents or */
  31. /* patent applications is to be implied by the copyright license. */
  32. /* */
  33. /* Any user of this software should understand that IBM cannot provide */
  34. /* technical support for this software and will not be responsible for */
  35. /* any consequences resulting from the use of this software. */
  36. /* */
  37. /* Any person who transfers this source code or any derivative work */
  38. /* must include the IBM copyright notice, this paragraph, and the */
  39. /* preceding two paragraphs in the transferred software. */
  40. /* */
  41. /* COPYRIGHT I B M CORPORATION 1995 */
  42. /* LICENSED MATERIAL - PROGRAM PROPERTY OF I B M */
  43. /*------------------------------------------------------------------------------- */
  44. /* U-Boot - Startup Code for IBM 4xx PowerPC based Embedded Boards
  45. *
  46. *
  47. * The processor starts at 0xfffffffc and the code is executed
  48. * from flash/rom.
  49. * in memory, but as long we don't jump around before relocating.
  50. * board_init lies at a quite high address and when the cpu has
  51. * jumped there, everything is ok.
  52. * This works because the cpu gives the FLASH (CS0) the whole
  53. * address space at startup, and board_init lies as a echo of
  54. * the flash somewhere up there in the memorymap.
  55. *
  56. * board_init will change CS0 to be positioned at the correct
  57. * address and (s)dram will be positioned at address 0
  58. */
  59. #include <config.h>
  60. #include <mpc8xx.h>
  61. #include <ppc4xx.h>
  62. #include <version.h>
  63. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  64. #include <ppc_asm.tmpl>
  65. #include <ppc_defs.h>
  66. #include <asm/cache.h>
  67. #include <asm/mmu.h>
  68. #ifndef CONFIG_IDENT_STRING
  69. #define CONFIG_IDENT_STRING ""
  70. #endif
  71. #ifdef CFG_INIT_DCACHE_CS
  72. # if (CFG_INIT_DCACHE_CS == 0)
  73. # define PBxAP pb0ap
  74. # define PBxCR pb0cr
  75. # endif
  76. # if (CFG_INIT_DCACHE_CS == 1)
  77. # define PBxAP pb1ap
  78. # define PBxCR pb1cr
  79. # endif
  80. # if (CFG_INIT_DCACHE_CS == 2)
  81. # define PBxAP pb2ap
  82. # define PBxCR pb2cr
  83. # endif
  84. # if (CFG_INIT_DCACHE_CS == 3)
  85. # define PBxAP pb3ap
  86. # define PBxCR pb3cr
  87. # endif
  88. # if (CFG_INIT_DCACHE_CS == 4)
  89. # define PBxAP pb4ap
  90. # define PBxCR pb4cr
  91. # endif
  92. # if (CFG_INIT_DCACHE_CS == 5)
  93. # define PBxAP pb5ap
  94. # define PBxCR pb5cr
  95. # endif
  96. # if (CFG_INIT_DCACHE_CS == 6)
  97. # define PBxAP pb6ap
  98. # define PBxCR pb6cr
  99. # endif
  100. # if (CFG_INIT_DCACHE_CS == 7)
  101. # define PBxAP pb7ap
  102. # define PBxCR pb7cr
  103. # endif
  104. #endif /* CFG_INIT_DCACHE_CS */
  105. /* We don't want the MMU yet.
  106. */
  107. #undef MSR_KERNEL
  108. #define MSR_KERNEL ( MSR_ME ) /* Machine Check */
  109. .extern ext_bus_cntlr_init
  110. .extern sdram_init
  111. /*
  112. * Set up GOT: Global Offset Table
  113. *
  114. * Use r14 to access the GOT
  115. */
  116. START_GOT
  117. GOT_ENTRY(_GOT2_TABLE_)
  118. GOT_ENTRY(_FIXUP_TABLE_)
  119. GOT_ENTRY(_start)
  120. GOT_ENTRY(_start_of_vectors)
  121. GOT_ENTRY(_end_of_vectors)
  122. GOT_ENTRY(transfer_to_handler)
  123. GOT_ENTRY(__init_end)
  124. GOT_ENTRY(_end)
  125. GOT_ENTRY(__bss_start)
  126. END_GOT
  127. /*
  128. * 440 Startup -- on reset only the top 4k of the effective
  129. * address space is mapped in by an entry in the instruction
  130. * and data shadow TLB. The .bootpg section is located in the
  131. * top 4k & does only what's necessary to map in the the rest
  132. * of the boot rom. Once the boot rom is mapped in we can
  133. * proceed with normal startup.
  134. *
  135. * NOTE: CS0 only covers the top 2MB of the effective address
  136. * space after reset.
  137. */
  138. #if defined(CONFIG_440)
  139. .section .bootpg,"ax"
  140. .globl _start_440
  141. /**************************************************************************/
  142. _start_440:
  143. /*----------------------------------------------------------------*/
  144. /* Clear and set up some registers. */
  145. /*----------------------------------------------------------------*/
  146. iccci r0,r0 /* NOTE: operands not used for 440 */
  147. dccci r0,r0 /* NOTE: operands not used for 440 */
  148. sync
  149. li r0,0
  150. mtspr srr0,r0
  151. mtspr srr1,r0
  152. mtspr csrr0,r0
  153. mtspr csrr1,r0
  154. /*----------------------------------------------------------------*/
  155. /* Initialize debug */
  156. /*----------------------------------------------------------------*/
  157. mtspr dbcr0,r0
  158. mtspr dbcr1,r0
  159. mtspr dbcr2,r0
  160. mtspr iac1,r0
  161. mtspr iac2,r0
  162. mtspr iac3,r0
  163. mtspr dac1,r0
  164. mtspr dac2,r0
  165. mtspr dvc1,r0
  166. mtspr dvc2,r0
  167. mfspr r1,dbsr
  168. mtspr dbsr,r1 /* Clear all valid bits */
  169. /*----------------------------------------------------------------*/
  170. /* CCR0 init */
  171. /*----------------------------------------------------------------*/
  172. /* Disable store gathering & broadcast, guarantee inst/data
  173. * cache block touch, force load/store alignment
  174. * (see errata 1.12: 440_33)
  175. */
  176. lis r1,0x0030 /* store gathering & broadcast disable */
  177. ori r1,r1,0x6000 /* cache touch */
  178. mtspr ccr0,r1
  179. /*----------------------------------------------------------------*/
  180. /* Setup interrupt vectors */
  181. /*----------------------------------------------------------------*/
  182. mtspr ivpr,r0 /* Vectors start at 0x0000_0000 */
  183. li r1,0x0100
  184. mtspr ivor0,r1 /* Critical input */
  185. li r1,0x0200
  186. mtspr ivor1,r1 /* Machine check */
  187. li r1,0x0300
  188. mtspr ivor2,r1 /* Data storage */
  189. li r1,0x0400
  190. mtspr ivor3,r1 /* Instruction storage */
  191. li r1,0x0500
  192. mtspr ivor4,r1 /* External interrupt */
  193. li r1,0x0600
  194. mtspr ivor5,r1 /* Alignment */
  195. li r1,0x0700
  196. mtspr ivor6,r1 /* Program check */
  197. li r1,0x0800
  198. mtspr ivor7,r1 /* Floating point unavailable */
  199. li r1,0x0c00
  200. mtspr ivor8,r1 /* System call */
  201. li r1,0x1000
  202. mtspr ivor10,r1 /* Decrementer (PIT for 440) */
  203. li r1,0x1400
  204. mtspr ivor13,r1 /* Data TLB error */
  205. li r1,0x1300
  206. mtspr ivor14,r1 /* Instr TLB error */
  207. li r1,0x2000
  208. mtspr ivor15,r1 /* Debug */
  209. /*----------------------------------------------------------------*/
  210. /* Configure cache regions */
  211. /*----------------------------------------------------------------*/
  212. mtspr inv0,r0
  213. mtspr inv1,r0
  214. mtspr inv2,r0
  215. mtspr inv3,r0
  216. mtspr dnv0,r0
  217. mtspr dnv1,r0
  218. mtspr dnv2,r0
  219. mtspr dnv3,r0
  220. mtspr itv0,r0
  221. mtspr itv1,r0
  222. mtspr itv2,r0
  223. mtspr itv3,r0
  224. mtspr dtv0,r0
  225. mtspr dtv1,r0
  226. mtspr dtv2,r0
  227. mtspr dtv3,r0
  228. /*----------------------------------------------------------------*/
  229. /* Cache victim limits */
  230. /*----------------------------------------------------------------*/
  231. /* floors 0, ceiling max to use the entire cache -- nothing locked
  232. */
  233. lis r1,0x0001
  234. ori r1,r1,0xf800
  235. mtspr ivlim,r1
  236. mtspr dvlim,r1
  237. /*----------------------------------------------------------------*/
  238. /* Clear all TLB entries -- TID = 0, TS = 0 */
  239. /*----------------------------------------------------------------*/
  240. mtspr mmucr,r0
  241. li r1,0x003f /* 64 TLB entries */
  242. mtctr r1
  243. 0: tlbwe r0,r1,0x0000 /* Invalidate all entries (V=0)*/
  244. subi r1,r1,0x0001
  245. bdnz 0b
  246. /*----------------------------------------------------------------*/
  247. /* TLB entry setup -- step thru tlbtab */
  248. /*----------------------------------------------------------------*/
  249. bl tlbtab /* Get tlbtab pointer */
  250. mr r5,r0
  251. li r1,0x003f /* 64 TLB entries max */
  252. mtctr r1
  253. li r4,0 /* TLB # */
  254. addi r5,r5,-4
  255. 1: lwzu r0,4(r5)
  256. cmpwi r0,0
  257. beq 2f /* 0 marks end */
  258. lwzu r1,4(r5)
  259. lwzu r2,4(r5)
  260. tlbwe r0,r4,0 /* TLB Word 0 */
  261. tlbwe r1,r4,1 /* TLB Word 1 */
  262. tlbwe r2,r4,2 /* TLB Word 2 */
  263. addi r4,r4,1 /* Next TLB */
  264. bdnz 1b
  265. /*----------------------------------------------------------------*/
  266. /* Continue from 'normal' start */
  267. /*----------------------------------------------------------------*/
  268. 2: bl 3f
  269. b _start
  270. 3: li r0,0
  271. mtspr srr1,r0 /* Keep things disabled for now */
  272. mflr r1
  273. mtspr srr0,r1
  274. rfi
  275. #endif /* CONFIG_440 */
  276. /*
  277. * r3 - 1st arg to board_init(): IMMP pointer
  278. * r4 - 2nd arg to board_init(): boot flag
  279. */
  280. .text
  281. .long 0x27051956 /* U-Boot Magic Number */
  282. .globl version_string
  283. version_string:
  284. .ascii U_BOOT_VERSION
  285. .ascii " (", __DATE__, " - ", __TIME__, ")"
  286. .ascii CONFIG_IDENT_STRING, "\0"
  287. /*
  288. * Maybe this should be moved somewhere else because the current
  289. * location (0x100) is where the CriticalInput Execption should be.
  290. */
  291. . = EXC_OFF_SYS_RESET
  292. .globl _start
  293. _start:
  294. /*****************************************************************************/
  295. #if defined(CONFIG_440)
  296. /*----------------------------------------------------------------*/
  297. /* Clear and set up some registers. */
  298. /*----------------------------------------------------------------*/
  299. li r0,0x0000
  300. lis r1,0xffff
  301. mtspr dec,r0 /* prevent dec exceptions */
  302. mtspr tbl,r0 /* prevent fit & wdt exceptions */
  303. mtspr tbu,r0
  304. mtspr tsr,r1 /* clear all timer exception status */
  305. mtspr tcr,r0 /* disable all */
  306. mtspr esr,r0 /* clear exception syndrome register */
  307. mtxer r0 /* clear integer exception register */
  308. lis r1,0x0002 /* set CE bit (Critical Exceptions) */
  309. ori r1,r1,0x1000 /* set ME bit (Machine Exceptions) */
  310. mtmsr r1 /* change MSR */
  311. /*----------------------------------------------------------------*/
  312. /* Debug setup -- some (not very good) ice's need an event*/
  313. /* to establish control :-( Define CFG_INIT_DBCR to the dbsr */
  314. /* value you need in this case 0x8cff 0000 should do the trick */
  315. /*----------------------------------------------------------------*/
  316. #if defined(CFG_INIT_DBCR)
  317. lis r1,0xffff
  318. ori r1,r1,0xffff
  319. mtspr dbsr,r1 /* Clear all status bits */
  320. lis r0,CFG_INIT_DBCR@h
  321. ori r0,r0,CFG_INIT_DBCR@l
  322. mtspr dbcr0,r0
  323. isync
  324. #endif
  325. /*----------------------------------------------------------------*/
  326. /* Setup the internal SRAM */
  327. /*----------------------------------------------------------------*/
  328. li r0,0
  329. mtdcr isram0_sb1cr,r0 /* Disable bank 1 */
  330. li r2,0x7fff
  331. ori r2,r2,0xffff
  332. mfdcr r1,isram0_dpc
  333. and r1,r1,r2 /* Disable parity check */
  334. mtdcr isram0_dpc,r1
  335. mfdcr r1,isram0_pmeg
  336. andis. r1,r1,r2 /* Disable pwr mgmt */
  337. mtdcr isram0_pmeg,r1
  338. lis r1,0x8000 /* BAS = 8000_0000 */
  339. ori r1,r1,0x0380 /* 8k rw */
  340. mtdcr isram0_sb0cr,r1
  341. /*----------------------------------------------------------------*/
  342. /* Setup the stack in internal SRAM */
  343. /*----------------------------------------------------------------*/
  344. lis r1,CFG_INIT_RAM_ADDR@h
  345. ori r1,r1,CFG_INIT_SP_OFFSET@l
  346. li r0,0
  347. stwu r0,-4(r1)
  348. stwu r0,-4(r1) /* Terminate call chain */
  349. stwu r1,-8(r1) /* Save back chain and move SP */
  350. lis r0,RESET_VECTOR@h /* Address of reset vector */
  351. ori r0,r0, RESET_VECTOR@l
  352. stwu r1,-8(r1) /* Save back chain and move SP */
  353. stw r0,+12(r1) /* Save return addr (underflow vect) */
  354. GET_GOT
  355. bl board_init_f
  356. #endif /* CONFIG_440 */
  357. /*****************************************************************************/
  358. #ifdef CONFIG_IOP480
  359. /*----------------------------------------------------------------------- */
  360. /* Set up some machine state registers. */
  361. /*----------------------------------------------------------------------- */
  362. addi r0,r0,0x0000 /* initialize r0 to zero */
  363. mtspr esr,r0 /* clear Exception Syndrome Reg */
  364. mttcr r0 /* timer control register */
  365. mtexier r0 /* disable all interrupts */
  366. addi r4,r0,0x1000 /* set ME bit (Machine Exceptions) */
  367. oris r4,r4,0x2 /* set CE bit (Critical Exceptions) */
  368. mtmsr r4 /* change MSR */
  369. addis r4,r0,0xFFFF /* set r4 to 0xFFFFFFFF (status in the */
  370. ori r4,r4,0xFFFF /* dbsr is cleared by setting bits to 1) */
  371. mtdbsr r4 /* clear/reset the dbsr */
  372. mtexisr r4 /* clear all pending interrupts */
  373. addis r4,r0,0x8000
  374. mtexier r4 /* enable critical exceptions */
  375. addis r4,r0,0x0000 /* assume 403GCX - enable core clk */
  376. ori r4,r4,0x4020 /* dbling (no harm done on GA and GC */
  377. mtiocr r4 /* since bit not used) & DRC to latch */
  378. /* data bus on rising edge of CAS */
  379. /*----------------------------------------------------------------------- */
  380. /* Clear XER. */
  381. /*----------------------------------------------------------------------- */
  382. mtxer r0
  383. /*----------------------------------------------------------------------- */
  384. /* Invalidate i-cache and d-cache TAG arrays. */
  385. /*----------------------------------------------------------------------- */
  386. addi r3,0,1024 /* 1/4 of I-cache size, half of D-cache */
  387. addi r4,0,1024 /* 1/4 of I-cache */
  388. ..cloop:
  389. iccci 0,r3
  390. iccci r4,r3
  391. dccci 0,r3
  392. addic. r3,r3,-16 /* move back one cache line */
  393. bne ..cloop /* loop back to do rest until r3 = 0 */
  394. /* */
  395. /* initialize IOP480 so it can read 1 MB code area for SRAM spaces */
  396. /* this requires enabling MA[17..0], by default only MA[12..0] are enabled. */
  397. /* */
  398. /* first copy IOP480 register base address into r3 */
  399. addis r3,0,0x5000 /* IOP480 register base address hi */
  400. /* ori r3,r3,0x0000 / IOP480 register base address lo */
  401. #ifdef CONFIG_ADCIOP
  402. /* use r4 as the working variable */
  403. /* turn on CS3 (LOCCTL.7) */
  404. lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */
  405. andi. r4,r4,0xff7f /* make bit 7 = 0 -- CS3 mode */
  406. stw r4,0x84(r3) /* LOCTL is at offset 0x84 */
  407. #endif
  408. #ifdef CONFIG_DASA_SIM
  409. /* use r4 as the working variable */
  410. /* turn on MA17 (LOCCTL.7) */
  411. lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */
  412. ori r4,r4,0x80 /* make bit 7 = 1 -- MA17 mode */
  413. stw r4,0x84(r3) /* LOCTL is at offset 0x84 */
  414. #endif
  415. /* turn on MA16..13 (LCS0BRD.12 = 0) */
  416. lwz r4,0x100(r3) /* LCS0BRD is at offset 0x100 */
  417. andi. r4,r4,0xefff /* make bit 12 = 0 */
  418. stw r4,0x100(r3) /* LCS0BRD is at offset 0x100 */
  419. /* make sure above stores all comlete before going on */
  420. sync
  421. /* last thing, set local init status done bit (DEVINIT.31) */
  422. lwz r4,0x80(r3) /* DEVINIT is at offset 0x80 */
  423. oris r4,r4,0x8000 /* make bit 31 = 1 */
  424. stw r4,0x80(r3) /* DEVINIT is at offset 0x80 */
  425. /* clear all pending interrupts and disable all interrupts */
  426. li r4,-1 /* set p1 to 0xffffffff */
  427. stw r4,0x1b0(r3) /* clear all pending interrupts */
  428. stw r4,0x1b8(r3) /* clear all pending interrupts */
  429. li r4,0 /* set r4 to 0 */
  430. stw r4,0x1b4(r3) /* disable all interrupts */
  431. stw r4,0x1bc(r3) /* disable all interrupts */
  432. /* make sure above stores all comlete before going on */
  433. sync
  434. /*----------------------------------------------------------------------- */
  435. /* Enable two 128MB cachable regions. */
  436. /*----------------------------------------------------------------------- */
  437. addis r1,r0,0x8000
  438. addi r1,r1,0x0001
  439. mticcr r1 /* instruction cache */
  440. addis r1,r0,0x0000
  441. addi r1,r1,0x0000
  442. mtdccr r1 /* data cache */
  443. addis r1,r0,CFG_INIT_RAM_ADDR@h
  444. ori r1,r1,CFG_INIT_SP_OFFSET /* set up the stack to SDRAM */
  445. li r0, 0 /* Make room for stack frame header and */
  446. stwu r0, -4(r1) /* clear final stack frame so that */
  447. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  448. GET_GOT /* initialize GOT access */
  449. bl board_init_f /* run first part of init code (from Flash) */
  450. #endif /* CONFIG_IOP480 */
  451. /*****************************************************************************/
  452. #if defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_405) || defined(CONFIG_405EP)
  453. /*----------------------------------------------------------------------- */
  454. /* Clear and set up some registers. */
  455. /*----------------------------------------------------------------------- */
  456. addi r4,r0,0x0000
  457. mtspr sgr,r4
  458. mtspr dcwr,r4
  459. mtesr r4 /* clear Exception Syndrome Reg */
  460. mttcr r4 /* clear Timer Control Reg */
  461. mtxer r4 /* clear Fixed-Point Exception Reg */
  462. mtevpr r4 /* clear Exception Vector Prefix Reg */
  463. addi r4,r0,0x1000 /* set ME bit (Machine Exceptions) */
  464. oris r4,r4,0x0002 /* set CE bit (Critical Exceptions) */
  465. mtmsr r4 /* change MSR */
  466. addi r4,r0,(0xFFFF-0x10000) /* set r4 to 0xFFFFFFFF (status in the */
  467. /* dbsr is cleared by setting bits to 1) */
  468. mtdbsr r4 /* clear/reset the dbsr */
  469. /*----------------------------------------------------------------------- */
  470. /* Invalidate I and D caches. Enable I cache for defined memory regions */
  471. /* to speed things up. Leave the D cache disabled for now. It will be */
  472. /* enabled/left disabled later based on user selected menu options. */
  473. /* Be aware that the I cache may be disabled later based on the menu */
  474. /* options as well. See miscLib/main.c. */
  475. /*----------------------------------------------------------------------- */
  476. bl invalidate_icache
  477. bl invalidate_dcache
  478. /*----------------------------------------------------------------------- */
  479. /* Enable two 128MB cachable regions. */
  480. /*----------------------------------------------------------------------- */
  481. addis r4,r0,0x8000
  482. addi r4,r4,0x0001
  483. mticcr r4 /* instruction cache */
  484. isync
  485. addis r4,r0,0x0000
  486. addi r4,r4,0x0000
  487. mtdccr r4 /* data cache */
  488. #if !(defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
  489. /*----------------------------------------------------------------------- */
  490. /* Tune the speed and size for flash CS0 */
  491. /*----------------------------------------------------------------------- */
  492. bl ext_bus_cntlr_init
  493. #endif
  494. #if defined(CONFIG_405EP)
  495. /*----------------------------------------------------------------------- */
  496. /* DMA Status, clear to come up clean */
  497. /*----------------------------------------------------------------------- */
  498. addis r3,r0, 0xFFFF /* Clear all existing DMA status */
  499. ori r3,r3, 0xFFFF
  500. mtdcr dmasr, r3
  501. bl ppc405ep_init /* do ppc405ep specific init */
  502. #endif /* CONFIG_405EP */
  503. #if defined(CFG_OCM_DATA_ADDR) && defined(CFG_OCM_DATA_SIZE)
  504. /********************************************************************
  505. * Setup OCM - On Chip Memory
  506. *******************************************************************/
  507. /* Setup OCM */
  508. lis r0, 0x7FFF
  509. ori r0, r0, 0xFFFF
  510. mfdcr r3, ocmiscntl /* get instr-side IRAM config */
  511. mfdcr r4, ocmdscntl /* get data-side IRAM config */
  512. and r3, r3, r0 /* disable data-side IRAM */
  513. and r4, r4, r0 /* disable data-side IRAM */
  514. mtdcr ocmiscntl, r3 /* set instr-side IRAM config */
  515. mtdcr ocmdscntl, r4 /* set data-side IRAM config */
  516. isync
  517. addis r3, 0, CFG_OCM_DATA_ADDR@h /* OCM location */
  518. mtdcr ocmdsarc, r3
  519. addis r4, 0, 0xC000 /* OCM data area enabled */
  520. mtdcr ocmdscntl, r4
  521. isync
  522. #endif
  523. /*----------------------------------------------------------------------- */
  524. /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */
  525. /*----------------------------------------------------------------------- */
  526. #ifdef CFG_INIT_DCACHE_CS
  527. /*----------------------------------------------------------------------- */
  528. /* Memory Bank x (nothingness) initialization 1GB+64MEG */
  529. /* used as temporary stack pointer for stage0 */
  530. /*----------------------------------------------------------------------- */
  531. li r4,PBxAP
  532. mtdcr ebccfga,r4
  533. lis r4,0x0380
  534. ori r4,r4,0x0480
  535. mtdcr ebccfgd,r4
  536. addi r4,0,PBxCR
  537. mtdcr ebccfga,r4
  538. lis r4,0x400D
  539. ori r4,r4,0xa000
  540. mtdcr ebccfgd,r4
  541. /* turn on data chache for this region */
  542. lis r4,0x0080
  543. mtdccr r4
  544. /* set stack pointer and clear stack to known value */
  545. lis r1,CFG_INIT_RAM_ADDR@h
  546. ori r1,r1,CFG_INIT_SP_OFFSET@l
  547. li r4,2048 /* we store 2048 words to stack */
  548. mtctr r4
  549. lis r2,CFG_INIT_RAM_ADDR@h /* we also clear data area */
  550. ori r2,r2,CFG_INIT_RAM_END@l /* so cant copy value from r1 */
  551. lis r4,0xdead /* we store 0xdeaddead in the stack */
  552. ori r4,r4,0xdead
  553. ..stackloop:
  554. stwu r4,-4(r2)
  555. bdnz ..stackloop
  556. li r0, 0 /* Make room for stack frame header and */
  557. stwu r0, -4(r1) /* clear final stack frame so that */
  558. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  559. /*
  560. * Set up a dummy frame to store reset vector as return address.
  561. * this causes stack underflow to reset board.
  562. */
  563. stwu r1, -8(r1) /* Save back chain and move SP */
  564. addis r0, 0, RESET_VECTOR@h /* Address of reset vector */
  565. ori r0, r0, RESET_VECTOR@l
  566. stwu r1, -8(r1) /* Save back chain and move SP */
  567. stw r0, +12(r1) /* Save return addr (underflow vect) */
  568. #elif defined(CFG_TEMP_STACK_OCM) && \
  569. (defined(CFG_OCM_DATA_ADDR) && defined(CFG_OCM_DATA_SIZE))
  570. /*
  571. * Stack in OCM.
  572. */
  573. /* Set up Stack at top of OCM */
  574. lis r1, (CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET)@h
  575. ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET)@l
  576. /* Set up a zeroized stack frame so that backtrace works right */
  577. li r0, 0
  578. stwu r0, -4(r1)
  579. stwu r0, -4(r1)
  580. /*
  581. * Set up a dummy frame to store reset vector as return address.
  582. * this causes stack underflow to reset board.
  583. */
  584. stwu r1, -8(r1) /* Save back chain and move SP */
  585. lis r0, RESET_VECTOR@h /* Address of reset vector */
  586. ori r0, r0, RESET_VECTOR@l
  587. stwu r1, -8(r1) /* Save back chain and move SP */
  588. stw r0, +12(r1) /* Save return addr (underflow vect) */
  589. #endif /* CFG_INIT_DCACHE_CS */
  590. /*----------------------------------------------------------------------- */
  591. /* Initialize SDRAM Controller */
  592. /*----------------------------------------------------------------------- */
  593. bl sdram_init
  594. /*
  595. * Setup temporary stack pointer only for boards
  596. * that do not use SDRAM SPD I2C stuff since it
  597. * is already initialized to use DCACHE or OCM
  598. * stacks.
  599. */
  600. #if !(defined(CFG_INIT_DCACHE_CS) || defined(CFG_TEMP_STACK_OCM))
  601. lis r1, CFG_INIT_RAM_ADDR@h
  602. ori r1,r1,CFG_INIT_SP_OFFSET /* set up the stack in SDRAM */
  603. li r0, 0 /* Make room for stack frame header and */
  604. stwu r0, -4(r1) /* clear final stack frame so that */
  605. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  606. /*
  607. * Set up a dummy frame to store reset vector as return address.
  608. * this causes stack underflow to reset board.
  609. */
  610. stwu r1, -8(r1) /* Save back chain and move SP */
  611. lis r0, RESET_VECTOR@h /* Address of reset vector */
  612. ori r0, r0, RESET_VECTOR@l
  613. stwu r1, -8(r1) /* Save back chain and move SP */
  614. stw r0, +12(r1) /* Save return addr (underflow vect) */
  615. #endif /* !(CFG_INIT_DCACHE_CS || !CFG_TEM_STACK_OCM) */
  616. GET_GOT /* initialize GOT access */
  617. bl cpu_init_f /* run low-level CPU init code (from Flash) */
  618. /* NEVER RETURNS! */
  619. bl board_init_f /* run first part of init code (from Flash) */
  620. #endif /* CONFIG_405GP || CONFIG_405CR */
  621. /*****************************************************************************/
  622. .globl _start_of_vectors
  623. _start_of_vectors:
  624. #if 0
  625. /*TODO Fixup _start above so we can do this*/
  626. /* Critical input. */
  627. CRIT_EXCEPTION(0x100, CritcalInput, CritcalInputException)
  628. #endif
  629. /* Machine check */
  630. CRIT_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  631. /* Data Storage exception. */
  632. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  633. /* Instruction Storage exception. */
  634. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  635. /* External Interrupt exception. */
  636. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  637. /* Alignment exception. */
  638. . = 0x600
  639. Alignment:
  640. EXCEPTION_PROLOG
  641. mfspr r4,DAR
  642. stw r4,_DAR(r21)
  643. mfspr r5,DSISR
  644. stw r5,_DSISR(r21)
  645. addi r3,r1,STACK_FRAME_OVERHEAD
  646. li r20,MSR_KERNEL
  647. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  648. lwz r6,GOT(transfer_to_handler)
  649. mtlr r6
  650. blrl
  651. .L_Alignment:
  652. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  653. .long int_return - _start + EXC_OFF_SYS_RESET
  654. /* Program check exception */
  655. . = 0x700
  656. ProgramCheck:
  657. EXCEPTION_PROLOG
  658. addi r3,r1,STACK_FRAME_OVERHEAD
  659. li r20,MSR_KERNEL
  660. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  661. lwz r6,GOT(transfer_to_handler)
  662. mtlr r6
  663. blrl
  664. .L_ProgramCheck:
  665. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  666. .long int_return - _start + EXC_OFF_SYS_RESET
  667. /* No FPU on MPC8xx. This exception is not supposed to happen.
  668. */
  669. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  670. /* I guess we could implement decrementer, and may have
  671. * to someday for timekeeping.
  672. */
  673. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  674. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  675. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  676. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  677. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  678. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  679. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  680. /* On the MPC8xx, this is a software emulation interrupt. It occurs
  681. * for all unimplemented and illegal instructions.
  682. */
  683. STD_EXCEPTION(0x1000, PIT, PITException)
  684. STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
  685. STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
  686. STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
  687. STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
  688. STD_EXCEPTION(0x1500, Reserved5, UnknownException)
  689. STD_EXCEPTION(0x1600, Reserved6, UnknownException)
  690. STD_EXCEPTION(0x1700, Reserved7, UnknownException)
  691. STD_EXCEPTION(0x1800, Reserved8, UnknownException)
  692. STD_EXCEPTION(0x1900, Reserved9, UnknownException)
  693. STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
  694. STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
  695. STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
  696. STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
  697. STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
  698. STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
  699. CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
  700. .globl _end_of_vectors
  701. _end_of_vectors:
  702. . = 0x2100
  703. /*
  704. * This code finishes saving the registers to the exception frame
  705. * and jumps to the appropriate handler for the exception.
  706. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  707. */
  708. .globl transfer_to_handler
  709. transfer_to_handler:
  710. stw r22,_NIP(r21)
  711. lis r22,MSR_POW@h
  712. andc r23,r23,r22
  713. stw r23,_MSR(r21)
  714. SAVE_GPR(7, r21)
  715. SAVE_4GPRS(8, r21)
  716. SAVE_8GPRS(12, r21)
  717. SAVE_8GPRS(24, r21)
  718. #if 0
  719. andi. r23,r23,MSR_PR
  720. mfspr r23,SPRG3 /* if from user, fix up tss.regs */
  721. beq 2f
  722. addi r24,r1,STACK_FRAME_OVERHEAD
  723. stw r24,PT_REGS(r23)
  724. 2: addi r2,r23,-TSS /* set r2 to current */
  725. tovirt(r2,r2,r23)
  726. #endif
  727. mflr r23
  728. andi. r24,r23,0x3f00 /* get vector offset */
  729. stw r24,TRAP(r21)
  730. li r22,0
  731. stw r22,RESULT(r21)
  732. mtspr SPRG2,r22 /* r1 is now kernel sp */
  733. #if 0
  734. addi r24,r2,TASK_STRUCT_SIZE /* check for kernel stack overflow */
  735. cmplw 0,r1,r2
  736. cmplw 1,r1,r24
  737. crand 1,1,4
  738. bgt stack_ovf /* if r2 < r1 < r2+TASK_STRUCT_SIZE */
  739. #endif
  740. lwz r24,0(r23) /* virtual address of handler */
  741. lwz r23,4(r23) /* where to go when done */
  742. mtspr SRR0,r24
  743. mtspr SRR1,r20
  744. mtlr r23
  745. SYNC
  746. rfi /* jump to handler, enable MMU */
  747. int_return:
  748. mfmsr r28 /* Disable interrupts */
  749. li r4,0
  750. ori r4,r4,MSR_EE
  751. andc r28,r28,r4
  752. SYNC /* Some chip revs need this... */
  753. mtmsr r28
  754. SYNC
  755. lwz r2,_CTR(r1)
  756. lwz r0,_LINK(r1)
  757. mtctr r2
  758. mtlr r0
  759. lwz r2,_XER(r1)
  760. lwz r0,_CCR(r1)
  761. mtspr XER,r2
  762. mtcrf 0xFF,r0
  763. REST_10GPRS(3, r1)
  764. REST_10GPRS(13, r1)
  765. REST_8GPRS(23, r1)
  766. REST_GPR(31, r1)
  767. lwz r2,_NIP(r1) /* Restore environment */
  768. lwz r0,_MSR(r1)
  769. mtspr SRR0,r2
  770. mtspr SRR1,r0
  771. lwz r0,GPR0(r1)
  772. lwz r2,GPR2(r1)
  773. lwz r1,GPR1(r1)
  774. SYNC
  775. rfi
  776. crit_return:
  777. mfmsr r28 /* Disable interrupts */
  778. li r4,0
  779. ori r4,r4,MSR_EE
  780. andc r28,r28,r4
  781. SYNC /* Some chip revs need this... */
  782. mtmsr r28
  783. SYNC
  784. lwz r2,_CTR(r1)
  785. lwz r0,_LINK(r1)
  786. mtctr r2
  787. mtlr r0
  788. lwz r2,_XER(r1)
  789. lwz r0,_CCR(r1)
  790. mtspr XER,r2
  791. mtcrf 0xFF,r0
  792. REST_10GPRS(3, r1)
  793. REST_10GPRS(13, r1)
  794. REST_8GPRS(23, r1)
  795. REST_GPR(31, r1)
  796. lwz r2,_NIP(r1) /* Restore environment */
  797. lwz r0,_MSR(r1)
  798. mtspr 990,r2 /* SRR2 */
  799. mtspr 991,r0 /* SRR3 */
  800. lwz r0,GPR0(r1)
  801. lwz r2,GPR2(r1)
  802. lwz r1,GPR1(r1)
  803. SYNC
  804. rfci
  805. /* Cache functions.
  806. */
  807. invalidate_icache:
  808. iccci r0,r0 /* for 405, iccci invalidates the */
  809. blr /* entire I cache */
  810. invalidate_dcache:
  811. addi r6,0,0x0000 /* clear GPR 6 */
  812. /* Do loop for # of dcache congruence classes. */
  813. addi r7,r0, (CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)
  814. /* NOTE: dccci invalidates both */
  815. mtctr r7 /* ways in the D cache */
  816. ..dcloop:
  817. dccci 0,r6 /* invalidate line */
  818. addi r6,r6, CFG_CACHELINE_SIZE /* bump to next line */
  819. bdnz ..dcloop
  820. blr
  821. flush_dcache:
  822. addis r9,r0,0x0002 /* set mask for EE and CE msr bits */
  823. ori r9,r9,0x8000
  824. mfmsr r12 /* save msr */
  825. andc r9,r12,r9
  826. mtmsr r9 /* disable EE and CE */
  827. addi r10,r0,0x0001 /* enable data cache for unused memory */
  828. mfdccr r9 /* region 0xF8000000-0xFFFFFFFF via */
  829. or r10,r10,r9 /* bit 31 in dccr */
  830. mtdccr r10
  831. /* do loop for # of congruence classes. */
  832. addi r10,r0,(CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)
  833. addi r11,r0,(CFG_DCACHE_SIZE / 2) /* D cache set size - 2 way sets */
  834. mtctr r10
  835. addi r10,r0,(0xE000-0x10000) /* start at 0xFFFFE000 */
  836. add r11,r10,r11 /* add to get to other side of cache line */
  837. ..flush_dcache_loop:
  838. lwz r3,0(r10) /* least recently used side */
  839. lwz r3,0(r11) /* the other side */
  840. dccci r0,r11 /* invalidate both sides */
  841. addi r10,r10,CFG_CACHELINE_SIZE /* bump to next line */
  842. addi r11,r11,CFG_CACHELINE_SIZE /* bump to next line */
  843. bdnz ..flush_dcache_loop
  844. sync /* allow memory access to complete */
  845. mtdccr r9 /* restore dccr */
  846. mtmsr r12 /* restore msr */
  847. blr
  848. .globl icache_enable
  849. icache_enable:
  850. mflr r8
  851. bl invalidate_icache
  852. mtlr r8
  853. isync
  854. addis r3,r0, 0x8000 /* set bit 0 */
  855. mticcr r3
  856. blr
  857. .globl icache_disable
  858. icache_disable:
  859. addis r3,r0, 0x0000 /* clear bit 0 */
  860. mticcr r3
  861. isync
  862. blr
  863. .globl icache_status
  864. icache_status:
  865. mficcr r3
  866. srwi r3, r3, 31 /* >>31 => select bit 0 */
  867. blr
  868. .globl dcache_enable
  869. dcache_enable:
  870. mflr r8
  871. bl invalidate_dcache
  872. mtlr r8
  873. isync
  874. addis r3,r0, 0x8000 /* set bit 0 */
  875. mtdccr r3
  876. blr
  877. .globl dcache_disable
  878. dcache_disable:
  879. mflr r8
  880. bl flush_dcache
  881. mtlr r8
  882. addis r3,r0, 0x0000 /* clear bit 0 */
  883. mtdccr r3
  884. blr
  885. .globl dcache_status
  886. dcache_status:
  887. mfdccr r3
  888. srwi r3, r3, 31 /* >>31 => select bit 0 */
  889. blr
  890. .globl get_pvr
  891. get_pvr:
  892. mfspr r3, PVR
  893. blr
  894. #if !defined(CONFIG_440)
  895. .globl wr_pit
  896. wr_pit:
  897. mtspr pit, r3
  898. blr
  899. #endif
  900. .globl wr_tcr
  901. wr_tcr:
  902. mtspr tcr, r3
  903. blr
  904. /*------------------------------------------------------------------------------- */
  905. /* Function: in8 */
  906. /* Description: Input 8 bits */
  907. /*------------------------------------------------------------------------------- */
  908. .globl in8
  909. in8:
  910. lbz r3,0x0000(r3)
  911. blr
  912. /*------------------------------------------------------------------------------- */
  913. /* Function: out8 */
  914. /* Description: Output 8 bits */
  915. /*------------------------------------------------------------------------------- */
  916. .globl out8
  917. out8:
  918. stb r4,0x0000(r3)
  919. blr
  920. /*------------------------------------------------------------------------------- */
  921. /* Function: out16 */
  922. /* Description: Output 16 bits */
  923. /*------------------------------------------------------------------------------- */
  924. .globl out16
  925. out16:
  926. sth r4,0x0000(r3)
  927. blr
  928. /*------------------------------------------------------------------------------- */
  929. /* Function: out16r */
  930. /* Description: Byte reverse and output 16 bits */
  931. /*------------------------------------------------------------------------------- */
  932. .globl out16r
  933. out16r:
  934. sthbrx r4,r0,r3
  935. blr
  936. /*------------------------------------------------------------------------------- */
  937. /* Function: out32 */
  938. /* Description: Output 32 bits */
  939. /*------------------------------------------------------------------------------- */
  940. .globl out32
  941. out32:
  942. stw r4,0x0000(r3)
  943. blr
  944. /*------------------------------------------------------------------------------- */
  945. /* Function: out32r */
  946. /* Description: Byte reverse and output 32 bits */
  947. /*------------------------------------------------------------------------------- */
  948. .globl out32r
  949. out32r:
  950. stwbrx r4,r0,r3
  951. blr
  952. /*------------------------------------------------------------------------------- */
  953. /* Function: in16 */
  954. /* Description: Input 16 bits */
  955. /*------------------------------------------------------------------------------- */
  956. .globl in16
  957. in16:
  958. lhz r3,0x0000(r3)
  959. blr
  960. /*------------------------------------------------------------------------------- */
  961. /* Function: in16r */
  962. /* Description: Input 16 bits and byte reverse */
  963. /*------------------------------------------------------------------------------- */
  964. .globl in16r
  965. in16r:
  966. lhbrx r3,r0,r3
  967. blr
  968. /*------------------------------------------------------------------------------- */
  969. /* Function: in32 */
  970. /* Description: Input 32 bits */
  971. /*------------------------------------------------------------------------------- */
  972. .globl in32
  973. in32:
  974. lwz 3,0x0000(3)
  975. blr
  976. /*------------------------------------------------------------------------------- */
  977. /* Function: in32r */
  978. /* Description: Input 32 bits and byte reverse */
  979. /*------------------------------------------------------------------------------- */
  980. .globl in32r
  981. in32r:
  982. lwbrx r3,r0,r3
  983. blr
  984. /*------------------------------------------------------------------------------- */
  985. /* Function: ppcDcbf */
  986. /* Description: Data Cache block flush */
  987. /* Input: r3 = effective address */
  988. /* Output: none. */
  989. /*------------------------------------------------------------------------------- */
  990. .globl ppcDcbf
  991. ppcDcbf:
  992. dcbf r0,r3
  993. blr
  994. /*------------------------------------------------------------------------------- */
  995. /* Function: ppcDcbi */
  996. /* Description: Data Cache block Invalidate */
  997. /* Input: r3 = effective address */
  998. /* Output: none. */
  999. /*------------------------------------------------------------------------------- */
  1000. .globl ppcDcbi
  1001. ppcDcbi:
  1002. dcbi r0,r3
  1003. blr
  1004. /*------------------------------------------------------------------------------- */
  1005. /* Function: ppcSync */
  1006. /* Description: Processor Synchronize */
  1007. /* Input: none. */
  1008. /* Output: none. */
  1009. /*------------------------------------------------------------------------------- */
  1010. .globl ppcSync
  1011. ppcSync:
  1012. sync
  1013. blr
  1014. /*------------------------------------------------------------------------------*/
  1015. /*
  1016. * void relocate_code (addr_sp, gd, addr_moni)
  1017. *
  1018. * This "function" does not return, instead it continues in RAM
  1019. * after relocating the monitor code.
  1020. *
  1021. * r3 = dest
  1022. * r4 = src
  1023. * r5 = length in bytes
  1024. * r6 = cachelinesize
  1025. */
  1026. .globl relocate_code
  1027. relocate_code:
  1028. mr r1, r3 /* Set new stack pointer */
  1029. mr r9, r4 /* Save copy of Init Data pointer */
  1030. mr r10, r5 /* Save copy of Destination Address */
  1031. mr r3, r5 /* Destination Address */
  1032. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  1033. ori r4, r4, CFG_MONITOR_BASE@l
  1034. lwz r5, GOT(__init_end)
  1035. sub r5, r5, r4
  1036. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  1037. /*
  1038. * Fix GOT pointer:
  1039. *
  1040. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
  1041. *
  1042. * Offset:
  1043. */
  1044. sub r15, r10, r4
  1045. /* First our own GOT */
  1046. add r14, r14, r15
  1047. /* the the one used by the C code */
  1048. add r30, r30, r15
  1049. /*
  1050. * Now relocate code
  1051. */
  1052. cmplw cr1,r3,r4
  1053. addi r0,r5,3
  1054. srwi. r0,r0,2
  1055. beq cr1,4f /* In place copy is not necessary */
  1056. beq 7f /* Protect against 0 count */
  1057. mtctr r0
  1058. bge cr1,2f
  1059. la r8,-4(r4)
  1060. la r7,-4(r3)
  1061. 1: lwzu r0,4(r8)
  1062. stwu r0,4(r7)
  1063. bdnz 1b
  1064. b 4f
  1065. 2: slwi r0,r0,2
  1066. add r8,r4,r0
  1067. add r7,r3,r0
  1068. 3: lwzu r0,-4(r8)
  1069. stwu r0,-4(r7)
  1070. bdnz 3b
  1071. /*
  1072. * Now flush the cache: note that we must start from a cache aligned
  1073. * address. Otherwise we might miss one cache line.
  1074. */
  1075. 4: cmpwi r6,0
  1076. add r5,r3,r5
  1077. beq 7f /* Always flush prefetch queue in any case */
  1078. subi r0,r6,1
  1079. andc r3,r3,r0
  1080. mr r4,r3
  1081. 5: dcbst 0,r4
  1082. add r4,r4,r6
  1083. cmplw r4,r5
  1084. blt 5b
  1085. sync /* Wait for all dcbst to complete on bus */
  1086. mr r4,r3
  1087. 6: icbi 0,r4
  1088. add r4,r4,r6
  1089. cmplw r4,r5
  1090. blt 6b
  1091. 7: sync /* Wait for all icbi to complete on bus */
  1092. isync
  1093. /*
  1094. * We are done. Do not return, instead branch to second part of board
  1095. * initialization, now running from RAM.
  1096. */
  1097. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  1098. mtlr r0
  1099. blr /* NEVER RETURNS! */
  1100. in_ram:
  1101. /*
  1102. * Relocation Function, r14 point to got2+0x8000
  1103. *
  1104. * Adjust got2 pointers, no need to check for 0, this code
  1105. * already puts a few entries in the table.
  1106. */
  1107. li r0,__got2_entries@sectoff@l
  1108. la r3,GOT(_GOT2_TABLE_)
  1109. lwz r11,GOT(_GOT2_TABLE_)
  1110. mtctr r0
  1111. sub r11,r3,r11
  1112. addi r3,r3,-4
  1113. 1: lwzu r0,4(r3)
  1114. add r0,r0,r11
  1115. stw r0,0(r3)
  1116. bdnz 1b
  1117. /*
  1118. * Now adjust the fixups and the pointers to the fixups
  1119. * in case we need to move ourselves again.
  1120. */
  1121. 2: li r0,__fixup_entries@sectoff@l
  1122. lwz r3,GOT(_FIXUP_TABLE_)
  1123. cmpwi r0,0
  1124. mtctr r0
  1125. addi r3,r3,-4
  1126. beq 4f
  1127. 3: lwzu r4,4(r3)
  1128. lwzux r0,r4,r11
  1129. add r0,r0,r11
  1130. stw r10,0(r3)
  1131. stw r0,0(r4)
  1132. bdnz 3b
  1133. 4:
  1134. clear_bss:
  1135. /*
  1136. * Now clear BSS segment
  1137. */
  1138. lwz r3,GOT(__bss_start)
  1139. lwz r4,GOT(_end)
  1140. cmplw 0, r3, r4
  1141. beq 6f
  1142. li r0, 0
  1143. 5:
  1144. stw r0, 0(r3)
  1145. addi r3, r3, 4
  1146. cmplw 0, r3, r4
  1147. bne 5b
  1148. 6:
  1149. mr r3, r9 /* Init Data pointer */
  1150. mr r4, r10 /* Destination Address */
  1151. bl board_init_r
  1152. /*
  1153. * Copy exception vector code to low memory
  1154. *
  1155. * r3: dest_addr
  1156. * r7: source address, r8: end address, r9: target address
  1157. */
  1158. .globl trap_init
  1159. trap_init:
  1160. lwz r7, GOT(_start)
  1161. lwz r8, GOT(_end_of_vectors)
  1162. li r9, 0x100 /* reset vector always at 0x100 */
  1163. cmplw 0, r7, r8
  1164. bgelr /* return if r7>=r8 - just in case */
  1165. mflr r4 /* save link register */
  1166. 1:
  1167. lwz r0, 0(r7)
  1168. stw r0, 0(r9)
  1169. addi r7, r7, 4
  1170. addi r9, r9, 4
  1171. cmplw 0, r7, r8
  1172. bne 1b
  1173. /*
  1174. * relocate `hdlr' and `int_return' entries
  1175. */
  1176. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  1177. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  1178. 2:
  1179. bl trap_reloc
  1180. addi r7, r7, 0x100 /* next exception vector */
  1181. cmplw 0, r7, r8
  1182. blt 2b
  1183. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  1184. bl trap_reloc
  1185. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  1186. bl trap_reloc
  1187. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  1188. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  1189. 3:
  1190. bl trap_reloc
  1191. addi r7, r7, 0x100 /* next exception vector */
  1192. cmplw 0, r7, r8
  1193. blt 3b
  1194. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  1195. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  1196. 4:
  1197. bl trap_reloc
  1198. addi r7, r7, 0x100 /* next exception vector */
  1199. cmplw 0, r7, r8
  1200. blt 4b
  1201. mtlr r4 /* restore link register */
  1202. blr
  1203. /*
  1204. * Function: relocate entries for one exception vector
  1205. */
  1206. trap_reloc:
  1207. lwz r0, 0(r7) /* hdlr ... */
  1208. add r0, r0, r3 /* ... += dest_addr */
  1209. stw r0, 0(r7)
  1210. lwz r0, 4(r7) /* int_return ... */
  1211. add r0, r0, r3 /* ... += dest_addr */
  1212. stw r0, 4(r7)
  1213. blr
  1214. /**************************************************************************/
  1215. /* PPC405EP specific stuff */
  1216. /**************************************************************************/
  1217. #ifdef CONFIG_405EP
  1218. ppc405ep_init:
  1219. /*
  1220. !-----------------------------------------------------------------------
  1221. ! Check FPGA for PCI internal/external arbitration
  1222. ! If board is set to internal arbitration, update cpc0_pci
  1223. !-----------------------------------------------------------------------
  1224. */
  1225. addi r3,0,CPC0_PCI_HOST_CFG_EN
  1226. #ifdef CONFIG_BUBINGA405EP
  1227. addis r5,r0,FPGA_REG1@h /* set offset for FPGA_REG1 */
  1228. ori r5,r5,FPGA_REG1@l
  1229. lbz r5,0x0(r5) /* read to get PCI arb selection */
  1230. andi. r6,r5,FPGA_REG1_PCI_INT_ARB /* using internal arbiter ?*/
  1231. beq ..pci_cfg_set /* if not set, then bypass reg write*/
  1232. #endif
  1233. ori r3,r3,CPC0_PCI_ARBIT_EN
  1234. ..pci_cfg_set:
  1235. mtdcr CPC0_PCI, r3 /* Enable internal arbiter*/
  1236. /*
  1237. !-----------------------------------------------------------------------
  1238. ! Check to see if chip is in bypass mode.
  1239. ! If so, write stored CPC0_PLLMR0 and CPC0_PLLMR1 values and perform a
  1240. ! CPU reset Otherwise, skip this step and keep going.
  1241. ! Note: Running BIOS in bypass mode is not supported since PLB speed
  1242. ! will not be fast enough for the SDRAM (min 66MHz)
  1243. !-----------------------------------------------------------------------
  1244. */
  1245. mfdcr r5, CPC0_PLLMR1
  1246. rlwinm r4,r5,1,0x1 /* get system clock source (SSCS) */
  1247. cmpi cr0,0,r4,0x1
  1248. beq pll_done /* if SSCS =b'1' then PLL has */
  1249. /* already been set */
  1250. /* and CPU has been reset */
  1251. /* so skip to next section */
  1252. #ifdef CONFIG_BUBINGA405EP
  1253. /*
  1254. !-----------------------------------------------------------------------
  1255. ! Read NVRAM to get value to write in PLLMR.
  1256. ! If value has not been correctly saved, write default value
  1257. ! Default config values (assuming on-board 33MHz SYS_CLK) are above.
  1258. ! See CPU_DEFAULT_200 and CPU_DEFAULT_266 above.
  1259. !
  1260. ! WARNING: This code assumes the first three words in the nvram_t
  1261. ! structure in openbios.h. Changing the beginning of
  1262. ! the structure will break this code.
  1263. !
  1264. !-----------------------------------------------------------------------
  1265. */
  1266. addis r3,0,NVRAM_BASE@h
  1267. addi r3,r3,NVRAM_BASE@l
  1268. lwz r4, 0(r3)
  1269. addis r5,0,NVRVFY1@h
  1270. addi r5,r5,NVRVFY1@l
  1271. cmp cr0,0,r4,r5 /* Compare 1st NVRAM Magic number*/
  1272. bne ..no_pllset
  1273. addi r3,r3,4
  1274. lwz r4, 0(r3)
  1275. addis r5,0,NVRVFY2@h
  1276. addi r5,r5,NVRVFY2@l
  1277. cmp cr0,0,r4,r5 /* Compare 2 NVRAM Magic number */
  1278. bne ..no_pllset
  1279. addi r3,r3,8 /* Skip over conf_size */
  1280. lwz r4, 4(r3) /* Load PLLMR1 value from NVRAM */
  1281. lwz r3, 0(r3) /* Load PLLMR0 value from NVRAM */
  1282. rlwinm r5,r4,1,0x1 /* get system clock source (SSCS) */
  1283. cmpi cr0,0,r5,1 /* See if PLL is locked */
  1284. beq pll_write
  1285. ..no_pllset:
  1286. #endif /* CONFIG_BUBINGA405EP */
  1287. addis r3,0,PLLMR0_DEFAULT@h /* PLLMR0 default value */
  1288. ori r3,r3,PLLMR0_DEFAULT@l /* */
  1289. addis r4,0,PLLMR1_DEFAULT@h /* PLLMR1 default value */
  1290. ori r4,r4,PLLMR1_DEFAULT@l /* */
  1291. b pll_write /* Write the CPC0_PLLMR with new value */
  1292. pll_done:
  1293. /*
  1294. !-----------------------------------------------------------------------
  1295. ! Clear Soft Reset Register
  1296. ! This is needed to enable PCI if not booting from serial EPROM
  1297. !-----------------------------------------------------------------------
  1298. */
  1299. addi r3, 0, 0x0
  1300. mtdcr CPC0_SRR, r3
  1301. addis r3,0,0x0010
  1302. mtctr r3
  1303. pci_wait:
  1304. bdnz pci_wait
  1305. blr /* return to main code */
  1306. /*
  1307. !-----------------------------------------------------------------------------
  1308. ! Function: pll_write
  1309. ! Description: Updates the value of the CPC0_PLLMR according to CMOS27E documentation
  1310. ! That is:
  1311. ! 1. Pll is first disabled (de-activated by putting in bypass mode)
  1312. ! 2. PLL is reset
  1313. ! 3. Clock dividers are set while PLL is held in reset and bypassed
  1314. ! 4. PLL Reset is cleared
  1315. ! 5. Wait 100us for PLL to lock
  1316. ! 6. A core reset is performed
  1317. ! Input: r3 = Value to write to CPC0_PLLMR0
  1318. ! Input: r4 = Value to write to CPC0_PLLMR1
  1319. ! Output r3 = none
  1320. !-----------------------------------------------------------------------------
  1321. */
  1322. pll_write:
  1323. mfdcr r5, CPC0_UCR
  1324. andis. r5,r5,0xFFFF
  1325. ori r5,r5,0x0101 /* Stop the UART clocks */
  1326. mtdcr CPC0_UCR,r5 /* Before changing PLL */
  1327. mfdcr r5, CPC0_PLLMR1
  1328. rlwinm r5,r5,0,0x7FFFFFFF /* Disable PLL */
  1329. mtdcr CPC0_PLLMR1,r5
  1330. oris r5,r5,0x4000 /* Set PLL Reset */
  1331. mtdcr CPC0_PLLMR1,r5
  1332. mtdcr CPC0_PLLMR0,r3 /* Set clock dividers */
  1333. rlwinm r5,r4,0,0x3FFFFFFF /* Reset & Bypass new PLL dividers */
  1334. oris r5,r5,0x4000 /* Set PLL Reset */
  1335. mtdcr CPC0_PLLMR1,r5 /* Set clock dividers */
  1336. rlwinm r5,r5,0,0xBFFFFFFF /* Clear PLL Reset */
  1337. mtdcr CPC0_PLLMR1,r5
  1338. /*
  1339. ! Wait min of 100us for PLL to lock.
  1340. ! See CMOS 27E databook for more info.
  1341. ! At 200MHz, that means waiting 20,000 instructions
  1342. */
  1343. addi r3,0,20000 /* 2000 = 0x4e20 */
  1344. mtctr r3
  1345. pll_wait:
  1346. bdnz pll_wait
  1347. oris r5,r5,0x8000 /* Enable PLL */
  1348. mtdcr CPC0_PLLMR1,r5 /* Engage */
  1349. /*
  1350. * Reset CPU to guarantee timings are OK
  1351. * Not sure if this is needed...
  1352. */
  1353. addis r3,0,0x1000
  1354. mtspr dbcr0,r3 /* This will cause a CPU core reset, and */
  1355. /* execution will continue from the poweron */
  1356. /* vector of 0xfffffffc */
  1357. #endif /* CONFIG_405EP */