start.S 25 KB

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