start.S 26 KB

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