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