start.S 26 KB

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