start.S 23 KB

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