start.S 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  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(_end)
  124. GOT_ENTRY(__bss_start)
  125. END_GOT
  126. /*
  127. * 440 Startup -- on reset only the top 4k of the effective
  128. * address space is mapped in by an entry in the instruction
  129. * and data shadow TLB. The .bootpg section is located in the
  130. * top 4k & does only what's necessary to map in the the rest
  131. * of the boot rom. Once the boot rom is mapped in we can
  132. * proceed with normal startup.
  133. *
  134. * NOTE: CS0 only covers the top 2MB of the effective address
  135. * space after reset.
  136. */
  137. #if defined(CONFIG_440)
  138. .section .bootpg,"ax"
  139. .globl _start_440
  140. /**************************************************************************/
  141. _start_440:
  142. /*----------------------------------------------------------------*/
  143. /* Clear and set up some registers. */
  144. /*----------------------------------------------------------------*/
  145. iccci r0,r0 /* NOTE: operands not used for 440 */
  146. dccci r0,r0 /* NOTE: operands not used for 440 */
  147. sync
  148. li r0,0
  149. mtspr srr0,r0
  150. mtspr srr1,r0
  151. mtspr csrr0,r0
  152. mtspr csrr1,r0
  153. /*----------------------------------------------------------------*/
  154. /* Initialize debug */
  155. /*----------------------------------------------------------------*/
  156. mtspr dbcr0,r0
  157. mtspr dbcr1,r0
  158. mtspr dbcr2,r0
  159. mtspr iac1,r0
  160. mtspr iac2,r0
  161. mtspr iac3,r0
  162. mtspr dac1,r0
  163. mtspr dac2,r0
  164. mtspr dvc1,r0
  165. mtspr dvc2,r0
  166. mfspr r1,dbsr
  167. mtspr dbsr,r1 /* Clear all valid bits */
  168. /*----------------------------------------------------------------*/
  169. /* CCR0 init */
  170. /*----------------------------------------------------------------*/
  171. /* Disable store gathering & broadcast, guarantee inst/data
  172. * cache block touch, force load/store alignment
  173. * (see errata 1.12: 440_33)
  174. */
  175. lis r1,0x0030 /* store gathering & broadcast disable */
  176. ori r1,r1,0x6000 /* cache touch */
  177. mtspr ccr0,r1
  178. /*----------------------------------------------------------------*/
  179. /* Setup interrupt vectors */
  180. /*----------------------------------------------------------------*/
  181. mtspr ivpr,r0 /* Vectors start at 0x0000_0000 */
  182. li r1,0x0100
  183. mtspr ivor0,r1 /* Critical input */
  184. li r1,0x0200
  185. mtspr ivor1,r1 /* Machine check */
  186. li r1,0x0300
  187. mtspr ivor2,r1 /* Data storage */
  188. li r1,0x0400
  189. mtspr ivor3,r1 /* Instruction storage */
  190. li r1,0x0500
  191. mtspr ivor4,r1 /* External interrupt */
  192. li r1,0x0600
  193. mtspr ivor5,r1 /* Alignment */
  194. li r1,0x0700
  195. mtspr ivor6,r1 /* Program check */
  196. li r1,0x0800
  197. mtspr ivor7,r1 /* Floating point unavailable */
  198. li r1,0x0c00
  199. mtspr ivor8,r1 /* System call */
  200. li r1,0x1000
  201. mtspr ivor10,r1 /* Decrementer (PIT for 440) */
  202. li r1,0x1400
  203. mtspr ivor13,r1 /* Data TLB error */
  204. li r1,0x1300
  205. mtspr ivor14,r1 /* Instr TLB error */
  206. li r1,0x2000
  207. mtspr ivor15,r1 /* Debug */
  208. /*----------------------------------------------------------------*/
  209. /* Configure cache regions */
  210. /*----------------------------------------------------------------*/
  211. mtspr inv0,r0
  212. mtspr inv1,r0
  213. mtspr inv2,r0
  214. mtspr inv3,r0
  215. mtspr dnv0,r0
  216. mtspr dnv1,r0
  217. mtspr dnv2,r0
  218. mtspr dnv3,r0
  219. mtspr itv0,r0
  220. mtspr itv1,r0
  221. mtspr itv2,r0
  222. mtspr itv3,r0
  223. mtspr dtv0,r0
  224. mtspr dtv1,r0
  225. mtspr dtv2,r0
  226. mtspr dtv3,r0
  227. /*----------------------------------------------------------------*/
  228. /* Cache victim limits */
  229. /*----------------------------------------------------------------*/
  230. /* floors 0, ceiling max to use the entire cache -- nothing locked
  231. */
  232. lis r1,0x0001
  233. ori r1,r1,0xf800
  234. mtspr ivlim,r1
  235. mtspr dvlim,r1
  236. /*----------------------------------------------------------------*/
  237. /* Clear all TLB entries -- TID = 0, TS = 0 */
  238. /*----------------------------------------------------------------*/
  239. mtspr mmucr,r0
  240. li r1,0x003f /* 64 TLB entries */
  241. mtctr r1
  242. 0: tlbwe r0,r1,0x0000 /* Invalidate all entries (V=0)*/
  243. subi r1,r1,0x0001
  244. bdnz 0b
  245. /*----------------------------------------------------------------*/
  246. /* TLB entry setup -- step thru tlbtab */
  247. /*----------------------------------------------------------------*/
  248. bl tlbtab /* Get tlbtab pointer */
  249. mr r5,r0
  250. li r1,0x003f /* 64 TLB entries max */
  251. mtctr r1
  252. li r4,0 /* TLB # */
  253. addi r5,r5,-4
  254. 1: lwzu r0,4(r5)
  255. cmpwi r0,0
  256. beq 2f /* 0 marks end */
  257. lwzu r1,4(r5)
  258. lwzu r2,4(r5)
  259. tlbwe r0,r4,0 /* TLB Word 0 */
  260. tlbwe r1,r4,1 /* TLB Word 1 */
  261. tlbwe r2,r4,2 /* TLB Word 2 */
  262. addi r4,r4,1 /* Next TLB */
  263. bdnz 1b
  264. /*----------------------------------------------------------------*/
  265. /* Continue from 'normal' start */
  266. /*----------------------------------------------------------------*/
  267. 2: bl 3f
  268. b _start
  269. 3: li r0,0
  270. mtspr srr1,r0 /* Keep things disabled for now */
  271. mflr r1
  272. mtspr srr0,r1
  273. rfi
  274. #endif
  275. /*
  276. * r3 - 1st arg to board_init(): IMMP pointer
  277. * r4 - 2nd arg to board_init(): boot flag
  278. */
  279. .text
  280. .long 0x27051956 /* U-Boot Magic Number */
  281. .globl version_string
  282. version_string:
  283. .ascii U_BOOT_VERSION
  284. .ascii " (", __DATE__, " - ", __TIME__, ")"
  285. .ascii CONFIG_IDENT_STRING, "\0"
  286. /*
  287. * Maybe this should be moved somewhere else because the current
  288. * location (0x100) is where the CriticalInput Execption should be.
  289. */
  290. . = EXC_OFF_SYS_RESET
  291. .globl _start
  292. _start:
  293. /*****************************************************************************/
  294. #if defined(CONFIG_440)
  295. /*----------------------------------------------------------------*/
  296. /* Clear and set up some registers. */
  297. /*----------------------------------------------------------------*/
  298. li r0,0x0000
  299. lis r1,0xffff
  300. mtspr dec,r0 /* prevent dec exceptions */
  301. mtspr tbl,r0 /* prevent fit & wdt exceptions */
  302. mtspr tbu,r0
  303. mtspr tsr,r1 /* clear all timer exception status */
  304. mtspr tcr,r0 /* disable all */
  305. mtspr esr,r0 /* clear exception syndrome register */
  306. mtxer r0 /* clear integer exception register */
  307. lis r1,0x0002 /* set CE bit (Critical Exceptions) */
  308. ori r1,r1,0x1000 /* set ME bit (Machine Exceptions) */
  309. mtmsr r1 /* change MSR */
  310. /*----------------------------------------------------------------*/
  311. /* Debug setup -- some (not very good) ice's need an event*/
  312. /* to establish control :-( Define CFG_INIT_DBCR to the dbsr */
  313. /* value you need in this case 0x8cff 0000 should do the trick */
  314. /*----------------------------------------------------------------*/
  315. #if defined(CFG_INIT_DBCR)
  316. lis r1,0xffff
  317. ori r1,r1,0xffff
  318. mtspr dbsr,r1 /* Clear all status bits */
  319. lis r0,CFG_INIT_DBCR@h
  320. ori r0,r0,CFG_INIT_DBCR@l
  321. mtspr dbcr0,r0
  322. isync
  323. #endif
  324. /*----------------------------------------------------------------*/
  325. /* Setup the internal SRAM */
  326. /*----------------------------------------------------------------*/
  327. li r0,0
  328. mtdcr isram0_sb1cr,r0 /* Disable bank 1 */
  329. li r2,0x7fff
  330. ori r2,r2,0xffff
  331. mfdcr r1,isram0_dpc
  332. and r1,r1,r2 /* Disable parity check */
  333. mtdcr isram0_dpc,r1
  334. mfdcr r1,isram0_pmeg
  335. andis. r1,r1,r2 /* Disable pwr mgmt */
  336. mtdcr isram0_pmeg,r1
  337. lis r1,0x8000 /* BAS = 8000_0000 */
  338. ori r1,r1,0x0380 /* 8k rw */
  339. mtdcr isram0_sb0cr,r1
  340. /*----------------------------------------------------------------*/
  341. /* Setup the stack in internal SRAM */
  342. /*----------------------------------------------------------------*/
  343. lis r1,CFG_INIT_RAM_ADDR@h
  344. ori r1,r1,CFG_INIT_SP_OFFSET@l
  345. li r0,0
  346. stwu r0,-4(r1)
  347. stwu r0,-4(r1) /* Terminate call chain */
  348. stwu r1,-8(r1) /* Save back chain and move SP */
  349. lis r0,RESET_VECTOR@h /* Address of reset vector */
  350. ori r0,r0, RESET_VECTOR@l
  351. stwu r1,-8(r1) /* Save back chain and move SP */
  352. stw r0,+12(r1) /* Save return addr (underflow vect) */
  353. GET_GOT
  354. bl board_init_f
  355. #endif /* CONFIG_440 */
  356. /*****************************************************************************/
  357. #ifdef CONFIG_IOP480
  358. /*----------------------------------------------------------------------- */
  359. /* Set up some machine state registers. */
  360. /*----------------------------------------------------------------------- */
  361. addi r0,r0,0x0000 /* initialize r0 to zero */
  362. mtspr esr,r0 /* clear Exception Syndrome Reg */
  363. mttcr r0 /* timer control register */
  364. mtexier r0 /* disable all interrupts */
  365. addi r4,r0,0x1000 /* set ME bit (Machine Exceptions) */
  366. oris r4,r4,0x2 /* set CE bit (Critical Exceptions) */
  367. mtmsr r4 /* change MSR */
  368. addis r4,r0,0xFFFF /* set r4 to 0xFFFFFFFF (status in the */
  369. ori r4,r4,0xFFFF /* dbsr is cleared by setting bits to 1) */
  370. mtdbsr r4 /* clear/reset the dbsr */
  371. mtexisr r4 /* clear all pending interrupts */
  372. addis r4,r0,0x8000
  373. mtexier r4 /* enable critical exceptions */
  374. addis r4,r0,0x0000 /* assume 403GCX - enable core clk */
  375. ori r4,r4,0x4020 /* dbling (no harm done on GA and GC */
  376. mtiocr r4 /* since bit not used) & DRC to latch */
  377. /* data bus on rising edge of CAS */
  378. /*----------------------------------------------------------------------- */
  379. /* Clear XER. */
  380. /*----------------------------------------------------------------------- */
  381. mtxer r0
  382. /*----------------------------------------------------------------------- */
  383. /* Invalidate i-cache and d-cache TAG arrays. */
  384. /*----------------------------------------------------------------------- */
  385. addi r3,0,1024 /* 1/4 of I-cache size, half of D-cache */
  386. addi r4,0,1024 /* 1/4 of I-cache */
  387. ..cloop:
  388. iccci 0,r3
  389. iccci r4,r3
  390. dccci 0,r3
  391. addic. r3,r3,-16 /* move back one cache line */
  392. bne ..cloop /* loop back to do rest until r3 = 0 */
  393. /* */
  394. /* initialize IOP480 so it can read 1 MB code area for SRAM spaces */
  395. /* this requires enabling MA[17..0], by default only MA[12..0] are enabled. */
  396. /* */
  397. /* first copy IOP480 register base address into r3 */
  398. addis r3,0,0x5000 /* IOP480 register base address hi */
  399. /* ori r3,r3,0x0000 / IOP480 register base address lo */
  400. #ifdef CONFIG_ADCIOP
  401. /* use r4 as the working variable */
  402. /* turn on CS3 (LOCCTL.7) */
  403. lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */
  404. andi. r4,r4,0xff7f /* make bit 7 = 0 -- CS3 mode */
  405. stw r4,0x84(r3) /* LOCTL is at offset 0x84 */
  406. #endif
  407. #ifdef CONFIG_DASA_SIM
  408. /* use r4 as the working variable */
  409. /* turn on MA17 (LOCCTL.7) */
  410. lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */
  411. ori r4,r4,0x80 /* make bit 7 = 1 -- MA17 mode */
  412. stw r4,0x84(r3) /* LOCTL is at offset 0x84 */
  413. #endif
  414. /* turn on MA16..13 (LCS0BRD.12 = 0) */
  415. lwz r4,0x100(r3) /* LCS0BRD is at offset 0x100 */
  416. andi. r4,r4,0xefff /* make bit 12 = 0 */
  417. stw r4,0x100(r3) /* LCS0BRD is at offset 0x100 */
  418. /* make sure above stores all comlete before going on */
  419. sync
  420. /* last thing, set local init status done bit (DEVINIT.31) */
  421. lwz r4,0x80(r3) /* DEVINIT is at offset 0x80 */
  422. oris r4,r4,0x8000 /* make bit 31 = 1 */
  423. stw r4,0x80(r3) /* DEVINIT is at offset 0x80 */
  424. /* clear all pending interrupts and disable all interrupts */
  425. li r4,-1 /* set p1 to 0xffffffff */
  426. stw r4,0x1b0(r3) /* clear all pending interrupts */
  427. stw r4,0x1b8(r3) /* clear all pending interrupts */
  428. li r4,0 /* set r4 to 0 */
  429. stw r4,0x1b4(r3) /* disable all interrupts */
  430. stw r4,0x1bc(r3) /* disable all interrupts */
  431. /* make sure above stores all comlete before going on */
  432. sync
  433. /*----------------------------------------------------------------------- */
  434. /* Enable two 128MB cachable regions. */
  435. /*----------------------------------------------------------------------- */
  436. addis r1,r0,0x8000
  437. addi r1,r1,0x0001
  438. mticcr r1 /* instruction cache */
  439. addis r1,r0,0x0000
  440. addi r1,r1,0x0000
  441. mtdccr r1 /* data cache */
  442. addis r1,r0,CFG_INIT_RAM_ADDR@h
  443. ori r1,r1,CFG_INIT_SP_OFFSET /* set up the stack to SDRAM */
  444. li r0, 0 /* Make room for stack frame header and */
  445. stwu r0, -4(r1) /* clear final stack frame so that */
  446. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  447. GET_GOT /* initialize GOT access */
  448. bl board_init_f /* run first part of init code (from Flash) */
  449. #endif /* CONFIG_IOP480 */
  450. /*****************************************************************************/
  451. #if defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_405)
  452. /*----------------------------------------------------------------------- */
  453. /* Clear and set up some registers. */
  454. /*----------------------------------------------------------------------- */
  455. addi r4,r0,0x0000
  456. mtspr sgr,r4
  457. mtspr dcwr,r4
  458. mtesr r4 /* clear Exception Syndrome Reg */
  459. mttcr r4 /* clear Timer Control Reg */
  460. mtxer r4 /* clear Fixed-Point Exception Reg */
  461. mtevpr r4 /* clear Exception Vector Prefix Reg */
  462. addi r4,r0,0x1000 /* set ME bit (Machine Exceptions) */
  463. oris r4,r4,0x0002 /* set CE bit (Critical Exceptions) */
  464. mtmsr r4 /* change MSR */
  465. addi r4,r0,(0xFFFF-0x10000) /* set r4 to 0xFFFFFFFF (status in the */
  466. /* dbsr is cleared by setting bits to 1) */
  467. mtdbsr r4 /* clear/reset the dbsr */
  468. /*----------------------------------------------------------------------- */
  469. /* Invalidate I and D caches. Enable I cache for defined memory regions */
  470. /* to speed things up. Leave the D cache disabled for now. It will be */
  471. /* enabled/left disabled later based on user selected menu options. */
  472. /* Be aware that the I cache may be disabled later based on the menu */
  473. /* options as well. See miscLib/main.c. */
  474. /*----------------------------------------------------------------------- */
  475. bl invalidate_icache
  476. bl invalidate_dcache
  477. /*----------------------------------------------------------------------- */
  478. /* Enable two 128MB cachable regions. */
  479. /*----------------------------------------------------------------------- */
  480. addis r4,r0,0x8000
  481. addi r4,r4,0x0001
  482. mticcr r4 /* instruction cache */
  483. isync
  484. addis r4,r0,0x0000
  485. addi r4,r4,0x0000
  486. mtdccr r4 /* data cache */
  487. #if !(defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
  488. /*----------------------------------------------------------------------- */
  489. /* Tune the speed and size for flash CS0 */
  490. /*----------------------------------------------------------------------- */
  491. bl ext_bus_cntlr_init
  492. #endif
  493. #if defined(CFG_OCM_DATA_ADDR) && defined(CFG_OCM_DATA_SIZE)
  494. /********************************************************************
  495. * Setup OCM - On Chip Memory
  496. *******************************************************************/
  497. /* Setup OCM */
  498. lis r0, 0x7FFF
  499. ori r0, r0, 0xFFFF
  500. mfdcr r3, ocmiscntl /* get instr-side IRAM config */
  501. mfdcr r4, ocmdscntl /* get data-side IRAM config */
  502. and r3, r3, r0 /* disable data-side IRAM */
  503. and r4, r4, r0 /* disable data-side IRAM */
  504. mtdcr ocmiscntl, r3 /* set instr-side IRAM config */
  505. mtdcr ocmdscntl, r4 /* set data-side IRAM config */
  506. isync
  507. addis r3, 0, CFG_OCM_DATA_ADDR@h /* OCM location */
  508. mtdcr ocmdsarc, r3
  509. addis r4, 0, 0xC000 /* OCM data area enabled */
  510. mtdcr ocmdscntl, r4
  511. isync
  512. #endif
  513. /*----------------------------------------------------------------------- */
  514. /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */
  515. /*----------------------------------------------------------------------- */
  516. #ifdef CFG_INIT_DCACHE_CS
  517. /*----------------------------------------------------------------------- */
  518. /* Memory Bank x (nothingness) initialization 1GB+64MEG */
  519. /* used as temporary stack pointer for stage0 */
  520. /*----------------------------------------------------------------------- */
  521. li r4,PBxAP
  522. mtdcr ebccfga,r4
  523. lis r4,0x0380
  524. ori r4,r4,0x0480
  525. mtdcr ebccfgd,r4
  526. addi r4,0,PBxCR
  527. mtdcr ebccfga,r4
  528. lis r4,0x400D
  529. ori r4,r4,0xa000
  530. mtdcr ebccfgd,r4
  531. /* turn on data chache for this region */
  532. lis r4,0x0080
  533. mtdccr r4
  534. /* set stack pointer and clear stack to known value */
  535. lis r1,CFG_INIT_RAM_ADDR@h
  536. ori r1,r1,CFG_INIT_SP_OFFSET@l
  537. li r4,2048 /* we store 2048 words to stack */
  538. mtctr r4
  539. lis r2,CFG_INIT_RAM_ADDR@h /* we also clear data area */
  540. ori r2,r2,CFG_INIT_RAM_END@l /* so cant copy value from r1 */
  541. lis r4,0xdead /* we store 0xdeaddead in the stack */
  542. ori r4,r4,0xdead
  543. ..stackloop:
  544. stwu r4,-4(r2)
  545. bdnz ..stackloop
  546. li r0, 0 /* Make room for stack frame header and */
  547. stwu r0, -4(r1) /* clear final stack frame so that */
  548. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  549. /*
  550. * Set up a dummy frame to store reset vector as return address.
  551. * this causes stack underflow to reset board.
  552. */
  553. stwu r1, -8(r1) /* Save back chain and move SP */
  554. addis r0, 0, RESET_VECTOR@h /* Address of reset vector */
  555. ori r0, r0, RESET_VECTOR@l
  556. stwu r1, -8(r1) /* Save back chain and move SP */
  557. stw r0, +12(r1) /* Save return addr (underflow vect) */
  558. #elif defined(CFG_TEMP_STACK_OCM) && \
  559. (defined(CFG_OCM_DATA_ADDR) && defined(CFG_OCM_DATA_SIZE))
  560. /*
  561. * Stack in OCM.
  562. */
  563. /* Set up Stack at top of OCM */
  564. lis r1, (CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET)@h
  565. ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET)@l
  566. /* Set up a zeroized stack frame so that backtrace works right */
  567. li r0, 0
  568. stwu r0, -4(r1)
  569. stwu r0, -4(r1)
  570. /*
  571. * Set up a dummy frame to store reset vector as return address.
  572. * this causes stack underflow to reset board.
  573. */
  574. stwu r1, -8(r1) /* Save back chain and move SP */
  575. lis r0, RESET_VECTOR@h /* Address of reset vector */
  576. ori r0, r0, RESET_VECTOR@l
  577. stwu r1, -8(r1) /* Save back chain and move SP */
  578. stw r0, +12(r1) /* Save return addr (underflow vect) */
  579. #endif /* CFG_INIT_DCACHE_CS */
  580. /*----------------------------------------------------------------------- */
  581. /* Initialize SDRAM Controller */
  582. /*----------------------------------------------------------------------- */
  583. bl sdram_init
  584. /*
  585. * Setup temporary stack pointer only for boards
  586. * that do not use SDRAM SPD I2C stuff since it
  587. * is already initialized to use DCACHE or OCM
  588. * stacks.
  589. */
  590. #if !(defined(CFG_INIT_DCACHE_CS) || defined(CFG_TEMP_STACK_OCM))
  591. lis r1, CFG_INIT_RAM_ADDR@h
  592. ori r1,r1,CFG_INIT_SP_OFFSET /* set up the stack in SDRAM */
  593. li r0, 0 /* Make room for stack frame header and */
  594. stwu r0, -4(r1) /* clear final stack frame so that */
  595. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  596. /*
  597. * Set up a dummy frame to store reset vector as return address.
  598. * this causes stack underflow to reset board.
  599. */
  600. stwu r1, -8(r1) /* Save back chain and move SP */
  601. lis r0, RESET_VECTOR@h /* Address of reset vector */
  602. ori r0, r0, RESET_VECTOR@l
  603. stwu r1, -8(r1) /* Save back chain and move SP */
  604. stw r0, +12(r1) /* Save return addr (underflow vect) */
  605. #endif /* !(CFG_INIT_DCACHE_CS || !CFG_TEM_STACK_OCM) */
  606. GET_GOT /* initialize GOT access */
  607. bl cpu_init_f /* run low-level CPU init code (from Flash) */
  608. /* NEVER RETURNS! */
  609. bl board_init_f /* run first part of init code (from Flash) */
  610. #endif /* CONFIG_405GP || CONFIG_405CR */
  611. .globl _start_of_vectors
  612. _start_of_vectors:
  613. #if 0
  614. /*TODO Fixup _start above so we can do this*/
  615. /* Critical input. */
  616. CRIT_EXCEPTION(0x100, CritcalInput, CritcalInputException)
  617. #endif
  618. /* Machine check */
  619. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  620. /* Data Storage exception. */
  621. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  622. /* Instruction Storage exception. */
  623. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  624. /* External Interrupt exception. */
  625. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  626. /* Alignment exception. */
  627. . = 0x600
  628. Alignment:
  629. EXCEPTION_PROLOG
  630. mfspr r4,DAR
  631. stw r4,_DAR(r21)
  632. mfspr r5,DSISR
  633. stw r5,_DSISR(r21)
  634. addi r3,r1,STACK_FRAME_OVERHEAD
  635. li r20,MSR_KERNEL
  636. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  637. lwz r6,GOT(transfer_to_handler)
  638. mtlr r6
  639. blrl
  640. .L_Alignment:
  641. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  642. .long int_return - _start + EXC_OFF_SYS_RESET
  643. /* Program check exception */
  644. . = 0x700
  645. ProgramCheck:
  646. EXCEPTION_PROLOG
  647. addi r3,r1,STACK_FRAME_OVERHEAD
  648. li r20,MSR_KERNEL
  649. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  650. lwz r6,GOT(transfer_to_handler)
  651. mtlr r6
  652. blrl
  653. .L_ProgramCheck:
  654. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  655. .long int_return - _start + EXC_OFF_SYS_RESET
  656. /* No FPU on MPC8xx. This exception is not supposed to happen.
  657. */
  658. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  659. /* I guess we could implement decrementer, and may have
  660. * to someday for timekeeping.
  661. */
  662. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  663. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  664. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  665. . = 0xc00
  666. /*
  667. * r0 - SYSCALL number
  668. * r3-... arguments
  669. */
  670. SystemCall:
  671. addis r11,r0,0 /* get functions table addr */
  672. ori r11,r11,0 /* Note: this code is patched in trap_init */
  673. addis r12,r0,0 /* get number of functions */
  674. ori r12,r12,0
  675. cmplw 0, r0, r12
  676. bge 1f
  677. rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
  678. add r11,r11,r0
  679. lwz r11,0(r11)
  680. li r20,0xd00-4 /* Get stack pointer */
  681. lwz r12,0(r20)
  682. subi r12,r12,12 /* Adjust stack pointer */
  683. li r0,0xc00+_end_back-SystemCall
  684. cmplw 0, r0, r12 /* Check stack overflow */
  685. bgt 1f
  686. stw r12,0(r20)
  687. mflr r0
  688. stw r0,0(r12)
  689. mfspr r0,SRR0
  690. stw r0,4(r12)
  691. mfspr r0,SRR1
  692. stw r0,8(r12)
  693. li r12,0xc00+_back-SystemCall
  694. mtlr r12
  695. mtspr SRR0,r11
  696. 1: SYNC
  697. rfi
  698. _back:
  699. mfmsr r11 /* Disable interrupts */
  700. li r12,0
  701. ori r12,r12,MSR_EE
  702. andc r11,r11,r12
  703. SYNC /* Some chip revs need this... */
  704. mtmsr r11
  705. SYNC
  706. li r12,0xd00-4 /* restore regs */
  707. lwz r12,0(r12)
  708. lwz r11,0(r12)
  709. mtlr r11
  710. lwz r11,4(r12)
  711. mtspr SRR0,r11
  712. lwz r11,8(r12)
  713. mtspr SRR1,r11
  714. addi r12,r12,12 /* Adjust stack pointer */
  715. li r20,0xd00-4
  716. stw r12,0(r20)
  717. SYNC
  718. rfi
  719. _end_back:
  720. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  721. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  722. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  723. /* On the MPC8xx, this is a software emulation interrupt. It occurs
  724. * for all unimplemented and illegal instructions.
  725. */
  726. STD_EXCEPTION(0x1000, PIT, PITException)
  727. STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
  728. STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
  729. STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
  730. STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
  731. STD_EXCEPTION(0x1500, Reserved5, UnknownException)
  732. STD_EXCEPTION(0x1600, Reserved6, UnknownException)
  733. STD_EXCEPTION(0x1700, Reserved7, UnknownException)
  734. STD_EXCEPTION(0x1800, Reserved8, UnknownException)
  735. STD_EXCEPTION(0x1900, Reserved9, UnknownException)
  736. STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
  737. STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
  738. STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
  739. STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
  740. STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
  741. STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
  742. CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
  743. .globl _end_of_vectors
  744. _end_of_vectors:
  745. . = 0x2100
  746. /*
  747. * This code finishes saving the registers to the exception frame
  748. * and jumps to the appropriate handler for the exception.
  749. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  750. */
  751. .globl transfer_to_handler
  752. transfer_to_handler:
  753. stw r22,_NIP(r21)
  754. lis r22,MSR_POW@h
  755. andc r23,r23,r22
  756. stw r23,_MSR(r21)
  757. SAVE_GPR(7, r21)
  758. SAVE_4GPRS(8, r21)
  759. SAVE_8GPRS(12, r21)
  760. SAVE_8GPRS(24, r21)
  761. #if 0
  762. andi. r23,r23,MSR_PR
  763. mfspr r23,SPRG3 /* if from user, fix up tss.regs */
  764. beq 2f
  765. addi r24,r1,STACK_FRAME_OVERHEAD
  766. stw r24,PT_REGS(r23)
  767. 2: addi r2,r23,-TSS /* set r2 to current */
  768. tovirt(r2,r2,r23)
  769. #endif
  770. mflr r23
  771. andi. r24,r23,0x3f00 /* get vector offset */
  772. stw r24,TRAP(r21)
  773. li r22,0
  774. stw r22,RESULT(r21)
  775. mtspr SPRG2,r22 /* r1 is now kernel sp */
  776. #if 0
  777. addi r24,r2,TASK_STRUCT_SIZE /* check for kernel stack overflow */
  778. cmplw 0,r1,r2
  779. cmplw 1,r1,r24
  780. crand 1,1,4
  781. bgt stack_ovf /* if r2 < r1 < r2+TASK_STRUCT_SIZE */
  782. #endif
  783. lwz r24,0(r23) /* virtual address of handler */
  784. lwz r23,4(r23) /* where to go when done */
  785. mtspr SRR0,r24
  786. mtspr SRR1,r20
  787. mtlr r23
  788. SYNC
  789. rfi /* jump to handler, enable MMU */
  790. int_return:
  791. mfmsr r28 /* Disable interrupts */
  792. li r4,0
  793. ori r4,r4,MSR_EE
  794. andc r28,r28,r4
  795. SYNC /* Some chip revs need this... */
  796. mtmsr r28
  797. SYNC
  798. lwz r2,_CTR(r1)
  799. lwz r0,_LINK(r1)
  800. mtctr r2
  801. mtlr r0
  802. lwz r2,_XER(r1)
  803. lwz r0,_CCR(r1)
  804. mtspr XER,r2
  805. mtcrf 0xFF,r0
  806. REST_10GPRS(3, r1)
  807. REST_10GPRS(13, r1)
  808. REST_8GPRS(23, r1)
  809. REST_GPR(31, r1)
  810. lwz r2,_NIP(r1) /* Restore environment */
  811. lwz r0,_MSR(r1)
  812. mtspr SRR0,r2
  813. mtspr SRR1,r0
  814. lwz r0,GPR0(r1)
  815. lwz r2,GPR2(r1)
  816. lwz r1,GPR1(r1)
  817. SYNC
  818. rfi
  819. crit_return:
  820. mfmsr r28 /* Disable interrupts */
  821. li r4,0
  822. ori r4,r4,MSR_EE
  823. andc r28,r28,r4
  824. SYNC /* Some chip revs need this... */
  825. mtmsr r28
  826. SYNC
  827. lwz r2,_CTR(r1)
  828. lwz r0,_LINK(r1)
  829. mtctr r2
  830. mtlr r0
  831. lwz r2,_XER(r1)
  832. lwz r0,_CCR(r1)
  833. mtspr XER,r2
  834. mtcrf 0xFF,r0
  835. REST_10GPRS(3, r1)
  836. REST_10GPRS(13, r1)
  837. REST_8GPRS(23, r1)
  838. REST_GPR(31, r1)
  839. lwz r2,_NIP(r1) /* Restore environment */
  840. lwz r0,_MSR(r1)
  841. mtspr 990,r2 /* SRR2 */
  842. mtspr 991,r0 /* SRR3 */
  843. lwz r0,GPR0(r1)
  844. lwz r2,GPR2(r1)
  845. lwz r1,GPR1(r1)
  846. SYNC
  847. rfci
  848. /* Cache functions.
  849. */
  850. invalidate_icache:
  851. iccci r0,r0 /* for 405, iccci invalidates the */
  852. blr /* entire I cache */
  853. invalidate_dcache:
  854. addi r6,0,0x0000 /* clear GPR 6 */
  855. /* Do loop for # of dcache congruence classes. */
  856. addi r7,r0, (CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)
  857. /* NOTE: dccci invalidates both */
  858. mtctr r7 /* ways in the D cache */
  859. ..dcloop:
  860. dccci 0,r6 /* invalidate line */
  861. addi r6,r6, CFG_CACHELINE_SIZE /* bump to next line */
  862. bdnz ..dcloop
  863. blr
  864. flush_dcache:
  865. addis r9,r0,0x0002 /* set mask for EE and CE msr bits */
  866. ori r9,r9,0x8000
  867. mfmsr r12 /* save msr */
  868. andc r9,r12,r9
  869. mtmsr r9 /* disable EE and CE */
  870. addi r10,r0,0x0001 /* enable data cache for unused memory */
  871. mfdccr r9 /* region 0xF8000000-0xFFFFFFFF via */
  872. or r10,r10,r9 /* bit 31 in dccr */
  873. mtdccr r10
  874. /* do loop for # of congruence classes. */
  875. addi r10,r0,(CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)
  876. addi r11,r0,(CFG_DCACHE_SIZE / 2) /* D cache set size - 2 way sets */
  877. mtctr r10
  878. addi r10,r0,(0xE000-0x10000) /* start at 0xFFFFE000 */
  879. add r11,r10,r11 /* add to get to other side of cache line */
  880. ..flush_dcache_loop:
  881. lwz r3,0(r10) /* least recently used side */
  882. lwz r3,0(r11) /* the other side */
  883. dccci r0,r11 /* invalidate both sides */
  884. addi r10,r10,CFG_CACHELINE_SIZE /* bump to next line */
  885. addi r11,r11,CFG_CACHELINE_SIZE /* bump to next line */
  886. bdnz ..flush_dcache_loop
  887. sync /* allow memory access to complete */
  888. mtdccr r9 /* restore dccr */
  889. mtmsr r12 /* restore msr */
  890. blr
  891. .globl icache_enable
  892. icache_enable:
  893. mflr r8
  894. bl invalidate_icache
  895. mtlr r8
  896. isync
  897. addis r3,r0, 0x8000 /* set bit 0 */
  898. mticcr r3
  899. blr
  900. .globl icache_disable
  901. icache_disable:
  902. addis r3,r0, 0x0000 /* clear bit 0 */
  903. mticcr r3
  904. isync
  905. blr
  906. .globl icache_status
  907. icache_status:
  908. mficcr r3
  909. srwi r3, r3, 31 /* >>31 => select bit 0 */
  910. blr
  911. .globl dcache_enable
  912. dcache_enable:
  913. mflr r8
  914. bl invalidate_dcache
  915. mtlr r8
  916. isync
  917. addis r3,r0, 0x8000 /* set bit 0 */
  918. mtdccr r3
  919. blr
  920. .globl dcache_disable
  921. dcache_disable:
  922. mflr r8
  923. bl flush_dcache
  924. mtlr r8
  925. addis r3,r0, 0x0000 /* clear bit 0 */
  926. mtdccr r3
  927. blr
  928. .globl dcache_status
  929. dcache_status:
  930. mfdccr r3
  931. srwi r3, r3, 31 /* >>31 => select bit 0 */
  932. blr
  933. .globl get_pvr
  934. get_pvr:
  935. mfspr r3, PVR
  936. blr
  937. #if !defined(CONFIG_440)
  938. .globl wr_pit
  939. wr_pit:
  940. mtspr pit, r3
  941. blr
  942. #endif
  943. .globl wr_tcr
  944. wr_tcr:
  945. mtspr tcr, r3
  946. blr
  947. /*------------------------------------------------------------------------------- */
  948. /* Function: in8 */
  949. /* Description: Input 8 bits */
  950. /*------------------------------------------------------------------------------- */
  951. .globl in8
  952. in8:
  953. lbz r3,0x0000(r3)
  954. blr
  955. /*------------------------------------------------------------------------------- */
  956. /* Function: out8 */
  957. /* Description: Output 8 bits */
  958. /*------------------------------------------------------------------------------- */
  959. .globl out8
  960. out8:
  961. stb r4,0x0000(r3)
  962. blr
  963. /*------------------------------------------------------------------------------- */
  964. /* Function: out16 */
  965. /* Description: Output 16 bits */
  966. /*------------------------------------------------------------------------------- */
  967. .globl out16
  968. out16:
  969. sth r4,0x0000(r3)
  970. blr
  971. /*------------------------------------------------------------------------------- */
  972. /* Function: out16r */
  973. /* Description: Byte reverse and output 16 bits */
  974. /*------------------------------------------------------------------------------- */
  975. .globl out16r
  976. out16r:
  977. sthbrx r4,r0,r3
  978. blr
  979. /*------------------------------------------------------------------------------- */
  980. /* Function: out32 */
  981. /* Description: Output 32 bits */
  982. /*------------------------------------------------------------------------------- */
  983. .globl out32
  984. out32:
  985. stw r4,0x0000(r3)
  986. blr
  987. /*------------------------------------------------------------------------------- */
  988. /* Function: out32r */
  989. /* Description: Byte reverse and output 32 bits */
  990. /*------------------------------------------------------------------------------- */
  991. .globl out32r
  992. out32r:
  993. stwbrx r4,r0,r3
  994. blr
  995. /*------------------------------------------------------------------------------- */
  996. /* Function: in16 */
  997. /* Description: Input 16 bits */
  998. /*------------------------------------------------------------------------------- */
  999. .globl in16
  1000. in16:
  1001. lhz r3,0x0000(r3)
  1002. blr
  1003. /*------------------------------------------------------------------------------- */
  1004. /* Function: in16r */
  1005. /* Description: Input 16 bits and byte reverse */
  1006. /*------------------------------------------------------------------------------- */
  1007. .globl in16r
  1008. in16r:
  1009. lhbrx r3,r0,r3
  1010. blr
  1011. /*------------------------------------------------------------------------------- */
  1012. /* Function: in32 */
  1013. /* Description: Input 32 bits */
  1014. /*------------------------------------------------------------------------------- */
  1015. .globl in32
  1016. in32:
  1017. lwz 3,0x0000(3)
  1018. blr
  1019. /*------------------------------------------------------------------------------- */
  1020. /* Function: in32r */
  1021. /* Description: Input 32 bits and byte reverse */
  1022. /*------------------------------------------------------------------------------- */
  1023. .globl in32r
  1024. in32r:
  1025. lwbrx r3,r0,r3
  1026. blr
  1027. /*------------------------------------------------------------------------------- */
  1028. /* Function: ppcDcbf */
  1029. /* Description: Data Cache block flush */
  1030. /* Input: r3 = effective address */
  1031. /* Output: none. */
  1032. /*------------------------------------------------------------------------------- */
  1033. .globl ppcDcbf
  1034. ppcDcbf:
  1035. dcbf r0,r3
  1036. blr
  1037. /*------------------------------------------------------------------------------- */
  1038. /* Function: ppcDcbi */
  1039. /* Description: Data Cache block Invalidate */
  1040. /* Input: r3 = effective address */
  1041. /* Output: none. */
  1042. /*------------------------------------------------------------------------------- */
  1043. .globl ppcDcbi
  1044. ppcDcbi:
  1045. dcbi r0,r3
  1046. blr
  1047. /*------------------------------------------------------------------------------- */
  1048. /* Function: ppcSync */
  1049. /* Description: Processor Synchronize */
  1050. /* Input: none. */
  1051. /* Output: none. */
  1052. /*------------------------------------------------------------------------------- */
  1053. .globl ppcSync
  1054. ppcSync:
  1055. sync
  1056. blr
  1057. /*------------------------------------------------------------------------------*/
  1058. /*
  1059. * void relocate_code (addr_sp, gd, addr_moni)
  1060. *
  1061. * This "function" does not return, instead it continues in RAM
  1062. * after relocating the monitor code.
  1063. *
  1064. * r3 = dest
  1065. * r4 = src
  1066. * r5 = length in bytes
  1067. * r6 = cachelinesize
  1068. */
  1069. .globl relocate_code
  1070. relocate_code:
  1071. mr r1, r3 /* Set new stack pointer */
  1072. mr r9, r4 /* Save copy of Init Data pointer */
  1073. mr r10, r5 /* Save copy of Destination Address */
  1074. mr r3, r5 /* Destination Address */
  1075. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  1076. ori r4, r4, CFG_MONITOR_BASE@l
  1077. lis r5, CFG_MONITOR_LEN@h /* Length in Bytes */
  1078. ori r5, r5, CFG_MONITOR_LEN@l
  1079. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  1080. /*
  1081. * Fix GOT pointer:
  1082. *
  1083. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
  1084. *
  1085. * Offset:
  1086. */
  1087. sub r15, r10, r4
  1088. /* First our own GOT */
  1089. add r14, r14, r15
  1090. /* the the one used by the C code */
  1091. add r30, r30, r15
  1092. /*
  1093. * Now relocate code
  1094. */
  1095. cmplw cr1,r3,r4
  1096. addi r0,r5,3
  1097. srwi. r0,r0,2
  1098. beq cr1,4f /* In place copy is not necessary */
  1099. beq 7f /* Protect against 0 count */
  1100. mtctr r0
  1101. bge cr1,2f
  1102. la r8,-4(r4)
  1103. la r7,-4(r3)
  1104. 1: lwzu r0,4(r8)
  1105. stwu r0,4(r7)
  1106. bdnz 1b
  1107. b 4f
  1108. 2: slwi r0,r0,2
  1109. add r8,r4,r0
  1110. add r7,r3,r0
  1111. 3: lwzu r0,-4(r8)
  1112. stwu r0,-4(r7)
  1113. bdnz 3b
  1114. /*
  1115. * Now flush the cache: note that we must start from a cache aligned
  1116. * address. Otherwise we might miss one cache line.
  1117. */
  1118. 4: cmpwi r6,0
  1119. add r5,r3,r5
  1120. beq 7f /* Always flush prefetch queue in any case */
  1121. subi r0,r6,1
  1122. andc r3,r3,r0
  1123. mr r4,r3
  1124. 5: dcbst 0,r4
  1125. add r4,r4,r6
  1126. cmplw r4,r5
  1127. blt 5b
  1128. sync /* Wait for all dcbst to complete on bus */
  1129. mr r4,r3
  1130. 6: icbi 0,r4
  1131. add r4,r4,r6
  1132. cmplw r4,r5
  1133. blt 6b
  1134. 7: sync /* Wait for all icbi to complete on bus */
  1135. isync
  1136. /*
  1137. * We are done. Do not return, instead branch to second part of board
  1138. * initialization, now running from RAM.
  1139. */
  1140. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  1141. mtlr r0
  1142. blr /* NEVER RETURNS! */
  1143. in_ram:
  1144. /*
  1145. * Relocation Function, r14 point to got2+0x8000
  1146. *
  1147. * Adjust got2 pointers, no need to check for 0, this code
  1148. * already puts a few entries in the table.
  1149. */
  1150. li r0,__got2_entries@sectoff@l
  1151. la r3,GOT(_GOT2_TABLE_)
  1152. lwz r11,GOT(_GOT2_TABLE_)
  1153. mtctr r0
  1154. sub r11,r3,r11
  1155. addi r3,r3,-4
  1156. 1: lwzu r0,4(r3)
  1157. add r0,r0,r11
  1158. stw r0,0(r3)
  1159. bdnz 1b
  1160. /*
  1161. * Now adjust the fixups and the pointers to the fixups
  1162. * in case we need to move ourselves again.
  1163. */
  1164. 2: li r0,__fixup_entries@sectoff@l
  1165. lwz r3,GOT(_FIXUP_TABLE_)
  1166. cmpwi r0,0
  1167. mtctr r0
  1168. addi r3,r3,-4
  1169. beq 4f
  1170. 3: lwzu r4,4(r3)
  1171. lwzux r0,r4,r11
  1172. add r0,r0,r11
  1173. stw r10,0(r3)
  1174. stw r0,0(r4)
  1175. bdnz 3b
  1176. 4:
  1177. clear_bss:
  1178. /*
  1179. * Now clear BSS segment
  1180. */
  1181. lwz r3,GOT(__bss_start)
  1182. lwz r4,GOT(_end)
  1183. cmplw 0, r3, r4
  1184. beq 6f
  1185. li r0, 0
  1186. 5:
  1187. stw r0, 0(r3)
  1188. addi r3, r3, 4
  1189. cmplw 0, r3, r4
  1190. bne 5b
  1191. 6:
  1192. mr r3, r9 /* Init Data pointer */
  1193. mr r4, r10 /* Destination Address */
  1194. bl board_init_r
  1195. /* Problems accessing "end" in C, so do it here */
  1196. .globl get_endaddr
  1197. get_endaddr:
  1198. lwz r3,GOT(_end)
  1199. blr
  1200. /*
  1201. * Copy exception vector code to low memory
  1202. *
  1203. * r3: dest_addr
  1204. * r7: source address, r8: end address, r9: target address
  1205. */
  1206. .globl trap_init
  1207. trap_init:
  1208. lwz r7, GOT(_start)
  1209. lwz r8, GOT(_end_of_vectors)
  1210. rlwinm r9, r7, 0, 18, 31 /* _start & 0x3FFF */
  1211. cmplw 0, r7, r8
  1212. bgelr /* return if r7>=r8 - just in case */
  1213. mflr r4 /* save link register */
  1214. 1:
  1215. lwz r0, 0(r7)
  1216. stw r0, 0(r9)
  1217. addi r7, r7, 4
  1218. addi r9, r9, 4
  1219. cmplw 0, r7, r8
  1220. bne 1b
  1221. /*
  1222. * relocate `hdlr' and `int_return' entries
  1223. */
  1224. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  1225. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  1226. 2:
  1227. bl trap_reloc
  1228. addi r7, r7, 0x100 /* next exception vector */
  1229. cmplw 0, r7, r8
  1230. blt 2b
  1231. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  1232. bl trap_reloc
  1233. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  1234. bl trap_reloc
  1235. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  1236. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  1237. 3:
  1238. bl trap_reloc
  1239. addi r7, r7, 0x100 /* next exception vector */
  1240. cmplw 0, r7, r8
  1241. blt 3b
  1242. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  1243. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  1244. 4:
  1245. bl trap_reloc
  1246. addi r7, r7, 0x100 /* next exception vector */
  1247. cmplw 0, r7, r8
  1248. blt 4b
  1249. mtlr r4 /* restore link register */
  1250. blr
  1251. /*
  1252. * Function: relocate entries for one exception vector
  1253. */
  1254. trap_reloc:
  1255. lwz r0, 0(r7) /* hdlr ... */
  1256. add r0, r0, r3 /* ... += dest_addr */
  1257. stw r0, 0(r7)
  1258. lwz r0, 4(r7) /* int_return ... */
  1259. add r0, r0, r3 /* ... += dest_addr */
  1260. stw r0, 4(r7)
  1261. blr