start.S 25 KB

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