start.S 23 KB

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