start.S 23 KB

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