start.S 24 KB

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