start.S 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. /*
  2. * Copyright 2004, 2007 Freescale Semiconductor.
  3. * Copyright (C) 2003 Motorola,Inc.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /* U-Boot Startup Code for Motorola 85xx PowerPC based Embedded Boards
  24. *
  25. * The processor starts at 0xfffffffc and the code is first executed in the
  26. * last 4K page(0xfffff000-0xffffffff) in flash/rom.
  27. *
  28. */
  29. #include <config.h>
  30. #include <mpc85xx.h>
  31. #include <version.h>
  32. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  33. #include <ppc_asm.tmpl>
  34. #include <ppc_defs.h>
  35. #include <asm/cache.h>
  36. #include <asm/mmu.h>
  37. #ifndef CONFIG_IDENT_STRING
  38. #define CONFIG_IDENT_STRING ""
  39. #endif
  40. #undef MSR_KERNEL
  41. #define MSR_KERNEL ( MSR_ME ) /* Machine Check */
  42. /*
  43. * Set up GOT: Global Offset Table
  44. *
  45. * Use r14 to access the GOT
  46. */
  47. START_GOT
  48. GOT_ENTRY(_GOT2_TABLE_)
  49. GOT_ENTRY(_FIXUP_TABLE_)
  50. GOT_ENTRY(_start)
  51. GOT_ENTRY(_start_of_vectors)
  52. GOT_ENTRY(_end_of_vectors)
  53. GOT_ENTRY(transfer_to_handler)
  54. GOT_ENTRY(__init_end)
  55. GOT_ENTRY(_end)
  56. GOT_ENTRY(__bss_start)
  57. END_GOT
  58. /*
  59. * e500 Startup -- after reset only the last 4KB of the effective
  60. * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
  61. * section is located at THIS LAST page and basically does three
  62. * things: clear some registers, set up exception tables and
  63. * add more TLB entries for 'larger spaces'(e.g. the boot rom) to
  64. * continue the boot procedure.
  65. * Once the boot rom is mapped by TLB entries we can proceed
  66. * with normal startup.
  67. *
  68. */
  69. .section .bootpg,"ax"
  70. .globl _start_e500
  71. _start_e500:
  72. /* clear registers/arrays not reset by hardware */
  73. /* L1 */
  74. li r0,2
  75. mtspr L1CSR0,r0 /* invalidate d-cache */
  76. mtspr L1CSR1,r0 /* invalidate i-cache */
  77. mfspr r1,DBSR
  78. mtspr DBSR,r1 /* Clear all valid bits */
  79. /*
  80. * Enable L1 Caches early
  81. *
  82. */
  83. lis r2,L1CSR0_CPE@H /* enable parity */
  84. ori r2,r2,L1CSR0_DCE
  85. mtspr L1CSR0,r2 /* enable L1 Dcache */
  86. isync
  87. mtspr L1CSR1,r2 /* enable L1 Icache */
  88. isync
  89. msync
  90. /* Setup interrupt vectors */
  91. lis r1,TEXT_BASE@h
  92. mtspr IVPR,r1
  93. li r1,0x0100
  94. mtspr IVOR0,r1 /* 0: Critical input */
  95. li r1,0x0200
  96. mtspr IVOR1,r1 /* 1: Machine check */
  97. li r1,0x0300
  98. mtspr IVOR2,r1 /* 2: Data storage */
  99. li r1,0x0400
  100. mtspr IVOR3,r1 /* 3: Instruction storage */
  101. li r1,0x0500
  102. mtspr IVOR4,r1 /* 4: External interrupt */
  103. li r1,0x0600
  104. mtspr IVOR5,r1 /* 5: Alignment */
  105. li r1,0x0700
  106. mtspr IVOR6,r1 /* 6: Program check */
  107. li r1,0x0800
  108. mtspr IVOR7,r1 /* 7: floating point unavailable */
  109. li r1,0x0900
  110. mtspr IVOR8,r1 /* 8: System call */
  111. /* 9: Auxiliary processor unavailable(unsupported) */
  112. li r1,0x0a00
  113. mtspr IVOR10,r1 /* 10: Decrementer */
  114. li r1,0x0b00
  115. mtspr IVOR11,r1 /* 11: Interval timer */
  116. li r1,0x0c00
  117. mtspr IVOR12,r1 /* 12: Watchdog timer */
  118. li r1,0x0d00
  119. mtspr IVOR13,r1 /* 13: Data TLB error */
  120. li r1,0x0e00
  121. mtspr IVOR14,r1 /* 14: Instruction TLB error */
  122. li r1,0x0f00
  123. mtspr IVOR15,r1 /* 15: Debug */
  124. /* Clear and set up some registers. */
  125. li r0,0x0000
  126. lis r1,0xffff
  127. mtspr DEC,r0 /* prevent dec exceptions */
  128. mttbl r0 /* prevent fit & wdt exceptions */
  129. mttbu r0
  130. mtspr TSR,r1 /* clear all timer exception status */
  131. mtspr TCR,r0 /* disable all */
  132. mtspr ESR,r0 /* clear exception syndrome register */
  133. mtspr MCSR,r0 /* machine check syndrome register */
  134. mtxer r0 /* clear integer exception register */
  135. /* Enable Time Base and Select Time Base Clock */
  136. lis r0,HID0_EMCP@h /* Enable machine check */
  137. #if defined(CONFIG_ENABLE_36BIT_PHYS)
  138. ori r0,r0,HID0_ENMAS7@l /* Enable MAS7 */
  139. #endif
  140. ori r0,r0,HID0_TBEN@l /* Enable Timebase */
  141. mtspr HID0,r0
  142. li r0,(HID1_ASTME|HID1_ABE)@l /* Addr streaming & broadcast */
  143. mtspr HID1,r0
  144. /* Enable Branch Prediction */
  145. #if defined(CONFIG_BTB)
  146. li r0,0x201 /* BBFI = 1, BPEN = 1 */
  147. mtspr BUCSR,r0
  148. #endif
  149. #if defined(CONFIG_SYS_INIT_DBCR)
  150. lis r1,0xffff
  151. ori r1,r1,0xffff
  152. mtspr DBSR,r1 /* Clear all status bits */
  153. lis r0,CONFIG_SYS_INIT_DBCR@h /* DBCR0[IDM] must be set */
  154. ori r0,r0,CONFIG_SYS_INIT_DBCR@l
  155. mtspr DBCR0,r0
  156. #endif
  157. /* create a temp mapping in AS=1 to the boot window */
  158. lis r6,FSL_BOOKE_MAS0(1, 15, 0)@h
  159. ori r6,r6,FSL_BOOKE_MAS0(1, 15, 0)@l
  160. lis r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16M)@h
  161. ori r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16M)@l
  162. /* Align the mapping to 16MB */
  163. lis r8,FSL_BOOKE_MAS2(TEXT_BASE & 0xff000000, (MAS2_I|MAS2_G))@h
  164. ori r8,r8,FSL_BOOKE_MAS2(TEXT_BASE & 0xff000000, (MAS2_I|MAS2_G))@l
  165. lis r9,FSL_BOOKE_MAS3(0xff000000, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h
  166. ori r9,r9,FSL_BOOKE_MAS3(0xff000000, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l
  167. mtspr MAS0,r6
  168. mtspr MAS1,r7
  169. mtspr MAS2,r8
  170. mtspr MAS3,r9
  171. isync
  172. msync
  173. tlbwe
  174. /* create a temp mapping in AS=1 to the stack */
  175. lis r6,FSL_BOOKE_MAS0(1, 14, 0)@h
  176. ori r6,r6,FSL_BOOKE_MAS0(1, 14, 0)@l
  177. lis r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16K)@h
  178. ori r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16K)@l
  179. lis r8,FSL_BOOKE_MAS2(CONFIG_SYS_INIT_RAM_ADDR, 0)@h
  180. ori r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_INIT_RAM_ADDR, 0)@l
  181. lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h
  182. ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l
  183. mtspr MAS0,r6
  184. mtspr MAS1,r7
  185. mtspr MAS2,r8
  186. mtspr MAS3,r9
  187. isync
  188. msync
  189. tlbwe
  190. lis r6,MSR_CE|MSR_ME|MSR_DE|MSR_IS|MSR_DS@h
  191. ori r6,r6,MSR_CE|MSR_ME|MSR_DE|MSR_IS|MSR_DS@l
  192. lis r7,switch_as@h
  193. ori r7,r7,switch_as@l
  194. mtspr SPRN_SRR0,r7
  195. mtspr SPRN_SRR1,r6
  196. rfi
  197. switch_as:
  198. /* L1 DCache is used for initial RAM */
  199. /* Allocate Initial RAM in data cache.
  200. */
  201. lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
  202. ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
  203. mfspr r2, L1CFG0
  204. andi. r2, r2, 0x1ff
  205. /* cache size * 1024 / (2 * L1 line size) */
  206. slwi r2, r2, (10 - 1 - L1_CACHE_SHIFT)
  207. mtctr r2
  208. li r0,0
  209. 1:
  210. dcbz r0,r3
  211. dcbtls 0,r0,r3
  212. addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
  213. bdnz 1b
  214. /* Jump out the last 4K page and continue to 'normal' start */
  215. #ifdef CONFIG_SYS_RAMBOOT
  216. b _start_cont
  217. #else
  218. /* Calculate absolute address in FLASH and jump there */
  219. /*--------------------------------------------------------------*/
  220. lis r3,CONFIG_SYS_MONITOR_BASE@h
  221. ori r3,r3,CONFIG_SYS_MONITOR_BASE@l
  222. addi r3,r3,_start_cont - _start + _START_OFFSET
  223. mtlr r3
  224. blr
  225. #endif
  226. .text
  227. .globl _start
  228. _start:
  229. .long 0x27051956 /* U-BOOT Magic Number */
  230. .globl version_string
  231. version_string:
  232. .ascii U_BOOT_VERSION
  233. .ascii " (", __DATE__, " - ", __TIME__, ")"
  234. .ascii CONFIG_IDENT_STRING, "\0"
  235. .align 4
  236. .globl _start_cont
  237. _start_cont:
  238. /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
  239. lis r1,CONFIG_SYS_INIT_RAM_ADDR@h
  240. ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET@l
  241. li r0,0
  242. stwu r0,-4(r1)
  243. stwu r0,-4(r1) /* Terminate call chain */
  244. stwu r1,-8(r1) /* Save back chain and move SP */
  245. lis r0,RESET_VECTOR@h /* Address of reset vector */
  246. ori r0,r0,RESET_VECTOR@l
  247. stwu r1,-8(r1) /* Save back chain and move SP */
  248. stw r0,+12(r1) /* Save return addr (underflow vect) */
  249. GET_GOT
  250. bl cpu_init_early_f
  251. /* switch back to AS = 0 */
  252. lis r3,(MSR_CE|MSR_ME|MSR_DE)@h
  253. ori r3,r3,(MSR_CE|MSR_ME|MSR_DE)@l
  254. mtmsr r3
  255. isync
  256. bl cpu_init_f
  257. bl board_init_f
  258. isync
  259. . = EXC_OFF_SYS_RESET
  260. .globl _start_of_vectors
  261. _start_of_vectors:
  262. /* Critical input. */
  263. CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException)
  264. /* Machine check */
  265. MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  266. /* Data Storage exception. */
  267. STD_EXCEPTION(0x0300, DataStorage, UnknownException)
  268. /* Instruction Storage exception. */
  269. STD_EXCEPTION(0x0400, InstStorage, UnknownException)
  270. /* External Interrupt exception. */
  271. STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException)
  272. /* Alignment exception. */
  273. . = 0x0600
  274. Alignment:
  275. EXCEPTION_PROLOG(SRR0, SRR1)
  276. mfspr r4,DAR
  277. stw r4,_DAR(r21)
  278. mfspr r5,DSISR
  279. stw r5,_DSISR(r21)
  280. addi r3,r1,STACK_FRAME_OVERHEAD
  281. li r20,MSR_KERNEL
  282. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  283. lwz r6,GOT(transfer_to_handler)
  284. mtlr r6
  285. blrl
  286. .L_Alignment:
  287. .long AlignmentException - _start + _START_OFFSET
  288. .long int_return - _start + _START_OFFSET
  289. /* Program check exception */
  290. . = 0x0700
  291. ProgramCheck:
  292. EXCEPTION_PROLOG(SRR0, SRR1)
  293. addi r3,r1,STACK_FRAME_OVERHEAD
  294. li r20,MSR_KERNEL
  295. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  296. lwz r6,GOT(transfer_to_handler)
  297. mtlr r6
  298. blrl
  299. .L_ProgramCheck:
  300. .long ProgramCheckException - _start + _START_OFFSET
  301. .long int_return - _start + _START_OFFSET
  302. /* No FPU on MPC85xx. This exception is not supposed to happen.
  303. */
  304. STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
  305. . = 0x0900
  306. /*
  307. * r0 - SYSCALL number
  308. * r3-... arguments
  309. */
  310. SystemCall:
  311. addis r11,r0,0 /* get functions table addr */
  312. ori r11,r11,0 /* Note: this code is patched in trap_init */
  313. addis r12,r0,0 /* get number of functions */
  314. ori r12,r12,0
  315. cmplw 0,r0,r12
  316. bge 1f
  317. rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
  318. add r11,r11,r0
  319. lwz r11,0(r11)
  320. li r20,0xd00-4 /* Get stack pointer */
  321. lwz r12,0(r20)
  322. subi r12,r12,12 /* Adjust stack pointer */
  323. li r0,0xc00+_end_back-SystemCall
  324. cmplw 0,r0,r12 /* Check stack overflow */
  325. bgt 1f
  326. stw r12,0(r20)
  327. mflr r0
  328. stw r0,0(r12)
  329. mfspr r0,SRR0
  330. stw r0,4(r12)
  331. mfspr r0,SRR1
  332. stw r0,8(r12)
  333. li r12,0xc00+_back-SystemCall
  334. mtlr r12
  335. mtspr SRR0,r11
  336. 1: SYNC
  337. rfi
  338. _back:
  339. mfmsr r11 /* Disable interrupts */
  340. li r12,0
  341. ori r12,r12,MSR_EE
  342. andc r11,r11,r12
  343. SYNC /* Some chip revs need this... */
  344. mtmsr r11
  345. SYNC
  346. li r12,0xd00-4 /* restore regs */
  347. lwz r12,0(r12)
  348. lwz r11,0(r12)
  349. mtlr r11
  350. lwz r11,4(r12)
  351. mtspr SRR0,r11
  352. lwz r11,8(r12)
  353. mtspr SRR1,r11
  354. addi r12,r12,12 /* Adjust stack pointer */
  355. li r20,0xd00-4
  356. stw r12,0(r20)
  357. SYNC
  358. rfi
  359. _end_back:
  360. STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
  361. STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
  362. STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
  363. STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
  364. STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
  365. CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
  366. .globl _end_of_vectors
  367. _end_of_vectors:
  368. . = . + (0x100 - ( . & 0xff )) /* align for debug */
  369. /*
  370. * This code finishes saving the registers to the exception frame
  371. * and jumps to the appropriate handler for the exception.
  372. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  373. */
  374. .globl transfer_to_handler
  375. transfer_to_handler:
  376. stw r22,_NIP(r21)
  377. lis r22,MSR_POW@h
  378. andc r23,r23,r22
  379. stw r23,_MSR(r21)
  380. SAVE_GPR(7, r21)
  381. SAVE_4GPRS(8, r21)
  382. SAVE_8GPRS(12, r21)
  383. SAVE_8GPRS(24, r21)
  384. mflr r23
  385. andi. r24,r23,0x3f00 /* get vector offset */
  386. stw r24,TRAP(r21)
  387. li r22,0
  388. stw r22,RESULT(r21)
  389. mtspr SPRG2,r22 /* r1 is now kernel sp */
  390. lwz r24,0(r23) /* virtual address of handler */
  391. lwz r23,4(r23) /* where to go when done */
  392. mtspr SRR0,r24
  393. mtspr SRR1,r20
  394. mtlr r23
  395. SYNC
  396. rfi /* jump to handler, enable MMU */
  397. int_return:
  398. mfmsr r28 /* Disable interrupts */
  399. li r4,0
  400. ori r4,r4,MSR_EE
  401. andc r28,r28,r4
  402. SYNC /* Some chip revs need this... */
  403. mtmsr r28
  404. SYNC
  405. lwz r2,_CTR(r1)
  406. lwz r0,_LINK(r1)
  407. mtctr r2
  408. mtlr r0
  409. lwz r2,_XER(r1)
  410. lwz r0,_CCR(r1)
  411. mtspr XER,r2
  412. mtcrf 0xFF,r0
  413. REST_10GPRS(3, r1)
  414. REST_10GPRS(13, r1)
  415. REST_8GPRS(23, r1)
  416. REST_GPR(31, r1)
  417. lwz r2,_NIP(r1) /* Restore environment */
  418. lwz r0,_MSR(r1)
  419. mtspr SRR0,r2
  420. mtspr SRR1,r0
  421. lwz r0,GPR0(r1)
  422. lwz r2,GPR2(r1)
  423. lwz r1,GPR1(r1)
  424. SYNC
  425. rfi
  426. crit_return:
  427. mfmsr r28 /* Disable interrupts */
  428. li r4,0
  429. ori r4,r4,MSR_EE
  430. andc r28,r28,r4
  431. SYNC /* Some chip revs need this... */
  432. mtmsr r28
  433. SYNC
  434. lwz r2,_CTR(r1)
  435. lwz r0,_LINK(r1)
  436. mtctr r2
  437. mtlr r0
  438. lwz r2,_XER(r1)
  439. lwz r0,_CCR(r1)
  440. mtspr XER,r2
  441. mtcrf 0xFF,r0
  442. REST_10GPRS(3, r1)
  443. REST_10GPRS(13, r1)
  444. REST_8GPRS(23, r1)
  445. REST_GPR(31, r1)
  446. lwz r2,_NIP(r1) /* Restore environment */
  447. lwz r0,_MSR(r1)
  448. mtspr SPRN_CSRR0,r2
  449. mtspr SPRN_CSRR1,r0
  450. lwz r0,GPR0(r1)
  451. lwz r2,GPR2(r1)
  452. lwz r1,GPR1(r1)
  453. SYNC
  454. rfci
  455. mck_return:
  456. mfmsr r28 /* Disable interrupts */
  457. li r4,0
  458. ori r4,r4,MSR_EE
  459. andc r28,r28,r4
  460. SYNC /* Some chip revs need this... */
  461. mtmsr r28
  462. SYNC
  463. lwz r2,_CTR(r1)
  464. lwz r0,_LINK(r1)
  465. mtctr r2
  466. mtlr r0
  467. lwz r2,_XER(r1)
  468. lwz r0,_CCR(r1)
  469. mtspr XER,r2
  470. mtcrf 0xFF,r0
  471. REST_10GPRS(3, r1)
  472. REST_10GPRS(13, r1)
  473. REST_8GPRS(23, r1)
  474. REST_GPR(31, r1)
  475. lwz r2,_NIP(r1) /* Restore environment */
  476. lwz r0,_MSR(r1)
  477. mtspr SPRN_MCSRR0,r2
  478. mtspr SPRN_MCSRR1,r0
  479. lwz r0,GPR0(r1)
  480. lwz r2,GPR2(r1)
  481. lwz r1,GPR1(r1)
  482. SYNC
  483. rfmci
  484. /* Cache functions.
  485. */
  486. .globl invalidate_icache
  487. invalidate_icache:
  488. mfspr r0,L1CSR1
  489. ori r0,r0,L1CSR1_ICFI
  490. msync
  491. isync
  492. mtspr L1CSR1,r0
  493. isync
  494. blr /* entire I cache */
  495. .globl invalidate_dcache
  496. invalidate_dcache:
  497. mfspr r0,L1CSR0
  498. ori r0,r0,L1CSR0_DCFI
  499. msync
  500. isync
  501. mtspr L1CSR0,r0
  502. isync
  503. blr
  504. .globl icache_enable
  505. icache_enable:
  506. mflr r8
  507. bl invalidate_icache
  508. mtlr r8
  509. isync
  510. mfspr r4,L1CSR1
  511. ori r4,r4,0x0001
  512. oris r4,r4,0x0001
  513. mtspr L1CSR1,r4
  514. isync
  515. blr
  516. .globl icache_disable
  517. icache_disable:
  518. mfspr r0,L1CSR1
  519. lis r3,0
  520. ori r3,r3,L1CSR1_ICE
  521. andc r0,r0,r3
  522. mtspr L1CSR1,r0
  523. isync
  524. blr
  525. .globl icache_status
  526. icache_status:
  527. mfspr r3,L1CSR1
  528. andi. r3,r3,L1CSR1_ICE
  529. blr
  530. .globl dcache_enable
  531. dcache_enable:
  532. mflr r8
  533. bl invalidate_dcache
  534. mtlr r8
  535. isync
  536. mfspr r0,L1CSR0
  537. ori r0,r0,0x0001
  538. oris r0,r0,0x0001
  539. msync
  540. isync
  541. mtspr L1CSR0,r0
  542. isync
  543. blr
  544. .globl dcache_disable
  545. dcache_disable:
  546. mfspr r3,L1CSR0
  547. lis r4,0
  548. ori r4,r4,L1CSR0_DCE
  549. andc r3,r3,r4
  550. mtspr L1CSR0,r0
  551. isync
  552. blr
  553. .globl dcache_status
  554. dcache_status:
  555. mfspr r3,L1CSR0
  556. andi. r3,r3,L1CSR0_DCE
  557. blr
  558. .globl get_pir
  559. get_pir:
  560. mfspr r3,PIR
  561. blr
  562. .globl get_pvr
  563. get_pvr:
  564. mfspr r3,PVR
  565. blr
  566. .globl get_svr
  567. get_svr:
  568. mfspr r3,SVR
  569. blr
  570. .globl wr_tcr
  571. wr_tcr:
  572. mtspr TCR,r3
  573. blr
  574. /*------------------------------------------------------------------------------- */
  575. /* Function: in8 */
  576. /* Description: Input 8 bits */
  577. /*------------------------------------------------------------------------------- */
  578. .globl in8
  579. in8:
  580. lbz r3,0x0000(r3)
  581. blr
  582. /*------------------------------------------------------------------------------- */
  583. /* Function: out8 */
  584. /* Description: Output 8 bits */
  585. /*------------------------------------------------------------------------------- */
  586. .globl out8
  587. out8:
  588. stb r4,0x0000(r3)
  589. sync
  590. blr
  591. /*------------------------------------------------------------------------------- */
  592. /* Function: out16 */
  593. /* Description: Output 16 bits */
  594. /*------------------------------------------------------------------------------- */
  595. .globl out16
  596. out16:
  597. sth r4,0x0000(r3)
  598. sync
  599. blr
  600. /*------------------------------------------------------------------------------- */
  601. /* Function: out16r */
  602. /* Description: Byte reverse and output 16 bits */
  603. /*------------------------------------------------------------------------------- */
  604. .globl out16r
  605. out16r:
  606. sthbrx r4,r0,r3
  607. sync
  608. blr
  609. /*------------------------------------------------------------------------------- */
  610. /* Function: out32 */
  611. /* Description: Output 32 bits */
  612. /*------------------------------------------------------------------------------- */
  613. .globl out32
  614. out32:
  615. stw r4,0x0000(r3)
  616. sync
  617. blr
  618. /*------------------------------------------------------------------------------- */
  619. /* Function: out32r */
  620. /* Description: Byte reverse and output 32 bits */
  621. /*------------------------------------------------------------------------------- */
  622. .globl out32r
  623. out32r:
  624. stwbrx r4,r0,r3
  625. sync
  626. blr
  627. /*------------------------------------------------------------------------------- */
  628. /* Function: in16 */
  629. /* Description: Input 16 bits */
  630. /*------------------------------------------------------------------------------- */
  631. .globl in16
  632. in16:
  633. lhz r3,0x0000(r3)
  634. blr
  635. /*------------------------------------------------------------------------------- */
  636. /* Function: in16r */
  637. /* Description: Input 16 bits and byte reverse */
  638. /*------------------------------------------------------------------------------- */
  639. .globl in16r
  640. in16r:
  641. lhbrx r3,r0,r3
  642. blr
  643. /*------------------------------------------------------------------------------- */
  644. /* Function: in32 */
  645. /* Description: Input 32 bits */
  646. /*------------------------------------------------------------------------------- */
  647. .globl in32
  648. in32:
  649. lwz 3,0x0000(3)
  650. blr
  651. /*------------------------------------------------------------------------------- */
  652. /* Function: in32r */
  653. /* Description: Input 32 bits and byte reverse */
  654. /*------------------------------------------------------------------------------- */
  655. .globl in32r
  656. in32r:
  657. lwbrx r3,r0,r3
  658. blr
  659. /*------------------------------------------------------------------------------*/
  660. /*
  661. * void relocate_code (addr_sp, gd, addr_moni)
  662. *
  663. * This "function" does not return, instead it continues in RAM
  664. * after relocating the monitor code.
  665. *
  666. * r3 = dest
  667. * r4 = src
  668. * r5 = length in bytes
  669. * r6 = cachelinesize
  670. */
  671. .globl relocate_code
  672. relocate_code:
  673. mr r1,r3 /* Set new stack pointer */
  674. mr r9,r4 /* Save copy of Init Data pointer */
  675. mr r10,r5 /* Save copy of Destination Address */
  676. mr r3,r5 /* Destination Address */
  677. lis r4,CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  678. ori r4,r4,CONFIG_SYS_MONITOR_BASE@l
  679. lwz r5,GOT(__init_end)
  680. sub r5,r5,r4
  681. li r6,CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  682. /*
  683. * Fix GOT pointer:
  684. *
  685. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  686. *
  687. * Offset:
  688. */
  689. sub r15,r10,r4
  690. /* First our own GOT */
  691. add r14,r14,r15
  692. /* the the one used by the C code */
  693. add r30,r30,r15
  694. /*
  695. * Now relocate code
  696. */
  697. cmplw cr1,r3,r4
  698. addi r0,r5,3
  699. srwi. r0,r0,2
  700. beq cr1,4f /* In place copy is not necessary */
  701. beq 7f /* Protect against 0 count */
  702. mtctr r0
  703. bge cr1,2f
  704. la r8,-4(r4)
  705. la r7,-4(r3)
  706. 1: lwzu r0,4(r8)
  707. stwu r0,4(r7)
  708. bdnz 1b
  709. b 4f
  710. 2: slwi r0,r0,2
  711. add r8,r4,r0
  712. add r7,r3,r0
  713. 3: lwzu r0,-4(r8)
  714. stwu r0,-4(r7)
  715. bdnz 3b
  716. /*
  717. * Now flush the cache: note that we must start from a cache aligned
  718. * address. Otherwise we might miss one cache line.
  719. */
  720. 4: cmpwi r6,0
  721. add r5,r3,r5
  722. beq 7f /* Always flush prefetch queue in any case */
  723. subi r0,r6,1
  724. andc r3,r3,r0
  725. mr r4,r3
  726. 5: dcbst 0,r4
  727. add r4,r4,r6
  728. cmplw r4,r5
  729. blt 5b
  730. sync /* Wait for all dcbst to complete on bus */
  731. mr r4,r3
  732. 6: icbi 0,r4
  733. add r4,r4,r6
  734. cmplw r4,r5
  735. blt 6b
  736. 7: sync /* Wait for all icbi to complete on bus */
  737. isync
  738. /*
  739. * Re-point the IVPR at RAM
  740. */
  741. mtspr IVPR,r10
  742. /*
  743. * We are done. Do not return, instead branch to second part of board
  744. * initialization, now running from RAM.
  745. */
  746. addi r0,r10,in_ram - _start + _START_OFFSET
  747. mtlr r0
  748. blr /* NEVER RETURNS! */
  749. .globl in_ram
  750. in_ram:
  751. /*
  752. * Relocation Function, r14 point to got2+0x8000
  753. *
  754. * Adjust got2 pointers, no need to check for 0, this code
  755. * already puts a few entries in the table.
  756. */
  757. li r0,__got2_entries@sectoff@l
  758. la r3,GOT(_GOT2_TABLE_)
  759. lwz r11,GOT(_GOT2_TABLE_)
  760. mtctr r0
  761. sub r11,r3,r11
  762. addi r3,r3,-4
  763. 1: lwzu r0,4(r3)
  764. add r0,r0,r11
  765. stw r0,0(r3)
  766. bdnz 1b
  767. /*
  768. * Now adjust the fixups and the pointers to the fixups
  769. * in case we need to move ourselves again.
  770. */
  771. 2: li r0,__fixup_entries@sectoff@l
  772. lwz r3,GOT(_FIXUP_TABLE_)
  773. cmpwi r0,0
  774. mtctr r0
  775. addi r3,r3,-4
  776. beq 4f
  777. 3: lwzu r4,4(r3)
  778. lwzux r0,r4,r11
  779. add r0,r0,r11
  780. stw r10,0(r3)
  781. stw r0,0(r4)
  782. bdnz 3b
  783. 4:
  784. clear_bss:
  785. /*
  786. * Now clear BSS segment
  787. */
  788. lwz r3,GOT(__bss_start)
  789. lwz r4,GOT(_end)
  790. cmplw 0,r3,r4
  791. beq 6f
  792. li r0,0
  793. 5:
  794. stw r0,0(r3)
  795. addi r3,r3,4
  796. cmplw 0,r3,r4
  797. bne 5b
  798. 6:
  799. mr r3,r9 /* Init Data pointer */
  800. mr r4,r10 /* Destination Address */
  801. bl board_init_r
  802. /*
  803. * Copy exception vector code to low memory
  804. *
  805. * r3: dest_addr
  806. * r7: source address, r8: end address, r9: target address
  807. */
  808. .globl trap_init
  809. trap_init:
  810. lwz r7,GOT(_start_of_vectors)
  811. lwz r8,GOT(_end_of_vectors)
  812. li r9,0x100 /* reset vector always at 0x100 */
  813. cmplw 0,r7,r8
  814. bgelr /* return if r7>=r8 - just in case */
  815. mflr r4 /* save link register */
  816. 1:
  817. lwz r0,0(r7)
  818. stw r0,0(r9)
  819. addi r7,r7,4
  820. addi r9,r9,4
  821. cmplw 0,r7,r8
  822. bne 1b
  823. /*
  824. * relocate `hdlr' and `int_return' entries
  825. */
  826. li r7,.L_CriticalInput - _start + _START_OFFSET
  827. bl trap_reloc
  828. li r7,.L_MachineCheck - _start + _START_OFFSET
  829. bl trap_reloc
  830. li r7,.L_DataStorage - _start + _START_OFFSET
  831. bl trap_reloc
  832. li r7,.L_InstStorage - _start + _START_OFFSET
  833. bl trap_reloc
  834. li r7,.L_ExtInterrupt - _start + _START_OFFSET
  835. bl trap_reloc
  836. li r7,.L_Alignment - _start + _START_OFFSET
  837. bl trap_reloc
  838. li r7,.L_ProgramCheck - _start + _START_OFFSET
  839. bl trap_reloc
  840. li r7,.L_FPUnavailable - _start + _START_OFFSET
  841. bl trap_reloc
  842. li r7,.L_Decrementer - _start + _START_OFFSET
  843. bl trap_reloc
  844. li r7,.L_IntervalTimer - _start + _START_OFFSET
  845. li r8,_end_of_vectors - _start + _START_OFFSET
  846. 2:
  847. bl trap_reloc
  848. addi r7,r7,0x100 /* next exception vector */
  849. cmplw 0,r7,r8
  850. blt 2b
  851. lis r7,0x0
  852. mtspr IVPR,r7
  853. mtlr r4 /* restore link register */
  854. blr
  855. /*
  856. * Function: relocate entries for one exception vector
  857. */
  858. trap_reloc:
  859. lwz r0,0(r7) /* hdlr ... */
  860. add r0,r0,r3 /* ... += dest_addr */
  861. stw r0,0(r7)
  862. lwz r0,4(r7) /* int_return ... */
  863. add r0,r0,r3 /* ... += dest_addr */
  864. stw r0,4(r7)
  865. blr
  866. .globl unlock_ram_in_cache
  867. unlock_ram_in_cache:
  868. /* invalidate the INIT_RAM section */
  869. lis r3,(CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
  870. ori r3,r3,(CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
  871. mfspr r4,L1CFG0
  872. andi. r4,r4,0x1ff
  873. slwi r4,r4,(10 - 1 - L1_CACHE_SHIFT)
  874. mtctr r4
  875. 1: dcbi r0,r3
  876. addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
  877. bdnz 1b
  878. sync
  879. /* Invalidate the TLB entries for the cache */
  880. lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
  881. ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
  882. tlbivax 0,r3
  883. addi r3,r3,0x1000
  884. tlbivax 0,r3
  885. addi r3,r3,0x1000
  886. tlbivax 0,r3
  887. addi r3,r3,0x1000
  888. tlbivax 0,r3
  889. isync
  890. blr
  891. .globl flush_dcache
  892. flush_dcache:
  893. mfspr r3,SPRN_L1CFG0
  894. rlwinm r5,r3,9,3 /* Extract cache block size */
  895. twlgti r5,1 /* Only 32 and 64 byte cache blocks
  896. * are currently defined.
  897. */
  898. li r4,32
  899. subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) -
  900. * log2(number of ways)
  901. */
  902. slw r5,r4,r5 /* r5 = cache block size */
  903. rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */
  904. mulli r7,r7,13 /* An 8-way cache will require 13
  905. * loads per set.
  906. */
  907. slw r7,r7,r6
  908. /* save off HID0 and set DCFA */
  909. mfspr r8,SPRN_HID0
  910. ori r9,r8,HID0_DCFA@l
  911. mtspr SPRN_HID0,r9
  912. isync
  913. lis r4,0
  914. mtctr r7
  915. 1: lwz r3,0(r4) /* Load... */
  916. add r4,r4,r5
  917. bdnz 1b
  918. msync
  919. lis r4,0
  920. mtctr r7
  921. 1: dcbf 0,r4 /* ...and flush. */
  922. add r4,r4,r5
  923. bdnz 1b
  924. /* restore HID0 */
  925. mtspr SPRN_HID0,r8
  926. isync
  927. blr