start.S 24 KB

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