start.S 23 KB

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