start.S 26 KB

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