start.S 20 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  1. /*
  2. * Copyright 2004, 2007 Freescale Semiconductor.
  3. * Srikanth Srinivasan <srikanth.srinivaan@freescale.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 86xx PowerPC based Embedded Boards
  24. *
  25. *
  26. * The processor starts at 0xfff00100 and the code is executed
  27. * from flash. The code is organized to be at an other address
  28. * in memory, but as long we don't jump around before relocating.
  29. * board_init lies at a quite high address and when the cpu has
  30. * jumped there, everything is ok.
  31. */
  32. #include <config.h>
  33. #include <mpc86xx.h>
  34. #include <version.h>
  35. #include <ppc_asm.tmpl>
  36. #include <ppc_defs.h>
  37. #include <asm/cache.h>
  38. #include <asm/mmu.h>
  39. #ifndef CONFIG_IDENT_STRING
  40. #define CONFIG_IDENT_STRING ""
  41. #endif
  42. /*
  43. * Need MSR_DR | MSR_IR enabled to access I/O (printf) in exceptions
  44. */
  45. /*
  46. * Set up GOT: Global Offset Table
  47. *
  48. * Use r14 to access the GOT
  49. */
  50. START_GOT
  51. GOT_ENTRY(_GOT2_TABLE_)
  52. GOT_ENTRY(_FIXUP_TABLE_)
  53. GOT_ENTRY(_start)
  54. GOT_ENTRY(_start_of_vectors)
  55. GOT_ENTRY(_end_of_vectors)
  56. GOT_ENTRY(transfer_to_handler)
  57. GOT_ENTRY(__init_end)
  58. GOT_ENTRY(_end)
  59. GOT_ENTRY(__bss_start)
  60. END_GOT
  61. /*
  62. * r3 - 1st arg to board_init(): IMMP pointer
  63. * r4 - 2nd arg to board_init(): boot flag
  64. */
  65. .text
  66. .long 0x27051956 /* U-Boot Magic Number */
  67. .globl version_string
  68. version_string:
  69. .ascii U_BOOT_VERSION
  70. .ascii " (", __DATE__, " - ", __TIME__, ")"
  71. .ascii CONFIG_IDENT_STRING, "\0"
  72. . = EXC_OFF_SYS_RESET
  73. .globl _start
  74. _start:
  75. li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
  76. b boot_cold
  77. sync
  78. . = EXC_OFF_SYS_RESET + 0x10
  79. .globl _start_warm
  80. _start_warm:
  81. li r21, BOOTFLAG_WARM /* Software reboot */
  82. b boot_warm
  83. sync
  84. /* the boot code is located below the exception table */
  85. .globl _start_of_vectors
  86. _start_of_vectors:
  87. /* Machine check */
  88. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  89. /* Data Storage exception. */
  90. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  91. /* Instruction Storage exception. */
  92. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  93. /* External Interrupt exception. */
  94. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  95. /* Alignment exception. */
  96. . = 0x600
  97. Alignment:
  98. EXCEPTION_PROLOG(SRR0, SRR1)
  99. mfspr r4,DAR
  100. stw r4,_DAR(r21)
  101. mfspr r5,DSISR
  102. stw r5,_DSISR(r21)
  103. addi r3,r1,STACK_FRAME_OVERHEAD
  104. li r20,MSR_KERNEL
  105. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  106. lwz r6,GOT(transfer_to_handler)
  107. mtlr r6
  108. blrl
  109. .L_Alignment:
  110. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  111. .long int_return - _start + EXC_OFF_SYS_RESET
  112. /* Program check exception */
  113. . = 0x700
  114. ProgramCheck:
  115. EXCEPTION_PROLOG(SRR0, SRR1)
  116. addi r3,r1,STACK_FRAME_OVERHEAD
  117. li r20,MSR_KERNEL
  118. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  119. lwz r6,GOT(transfer_to_handler)
  120. mtlr r6
  121. blrl
  122. .L_ProgramCheck:
  123. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  124. .long int_return - _start + EXC_OFF_SYS_RESET
  125. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  126. /* I guess we could implement decrementer, and may have
  127. * to someday for timekeeping.
  128. */
  129. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  130. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  131. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  132. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  133. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  134. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  135. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  136. STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
  137. STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
  138. STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
  139. STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
  140. STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
  141. STD_EXCEPTION(0x1500, Reserved5, UnknownException)
  142. STD_EXCEPTION(0x1600, Reserved6, UnknownException)
  143. STD_EXCEPTION(0x1700, Reserved7, UnknownException)
  144. STD_EXCEPTION(0x1800, Reserved8, UnknownException)
  145. STD_EXCEPTION(0x1900, Reserved9, UnknownException)
  146. STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
  147. STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
  148. STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
  149. STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
  150. STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
  151. STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
  152. .globl _end_of_vectors
  153. _end_of_vectors:
  154. . = 0x2000
  155. boot_cold:
  156. boot_warm:
  157. /* if this is a multi-core system we need to check which cpu
  158. * this is, if it is not cpu 0 send the cpu to the linux reset
  159. * vector */
  160. #if (CONFIG_NUM_CPUS > 1)
  161. mfspr r0, MSSCR0
  162. andi. r0, r0, 0x0020
  163. rlwinm r0,r0,27,31,31
  164. mtspr PIR, r0
  165. beq 1f
  166. bl secondary_cpu_setup
  167. #endif
  168. 1:
  169. #ifdef CFG_RAMBOOT
  170. /* disable everything */
  171. li r0, 0
  172. mtspr HID0, r0
  173. sync
  174. mtmsr 0
  175. #endif
  176. bl invalidate_bats
  177. sync
  178. #ifdef CFG_L2
  179. /* init the L2 cache */
  180. lis r3, L2_INIT@h
  181. ori r3, r3, L2_INIT@l
  182. mtspr l2cr, r3
  183. /* invalidate the L2 cache */
  184. bl l2cache_invalidate
  185. sync
  186. #endif
  187. /*
  188. * Calculate absolute address in FLASH and jump there
  189. *------------------------------------------------------*/
  190. lis r3, CFG_MONITOR_BASE@h
  191. ori r3, r3, CFG_MONITOR_BASE@l
  192. addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
  193. mtlr r3
  194. blr
  195. in_flash:
  196. /* let the C-code set up the rest */
  197. /* */
  198. /* Be careful to keep code relocatable ! */
  199. /*------------------------------------------------------*/
  200. /* perform low-level init */
  201. /* enable extended addressing */
  202. bl enable_ext_addr
  203. /* setup the bats */
  204. bl early_bats
  205. /*
  206. * Cache must be enabled here for stack-in-cache trick.
  207. * This means we need to enable the BATS.
  208. * Cache should be turned on after BATs, since by default
  209. * everything is write-through.
  210. */
  211. /* enable address translation */
  212. bl enable_addr_trans
  213. sync
  214. /* enable and invalidate the data cache */
  215. /* bl l1dcache_enable */
  216. bl dcache_enable
  217. sync
  218. #if 1
  219. bl icache_enable
  220. #endif
  221. #ifdef CFG_INIT_RAM_LOCK
  222. bl lock_ram_in_cache
  223. sync
  224. #endif
  225. /* set up the stack pointer in our newly created
  226. * cache-ram (r1) */
  227. lis r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@h
  228. ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@l
  229. li r0, 0 /* Make room for stack frame header and */
  230. stwu r0, -4(r1) /* clear final stack frame so that */
  231. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  232. GET_GOT /* initialize GOT access */
  233. /* setup the rest of the bats */
  234. bl setup_bats
  235. bl clear_tlbs
  236. sync
  237. #if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
  238. /* setup ccsrbar */
  239. bl setup_ccsrbar
  240. #endif
  241. /* run low-level CPU init code (from Flash) */
  242. bl cpu_init_f
  243. sync
  244. #ifdef RUN_DIAG
  245. /* Load PX_AUX register address in r4 */
  246. lis r4, 0xf810
  247. ori r4, r4, 0x6
  248. /* Load contents of PX_AUX in r3 bits 24 to 31*/
  249. lbz r3, 0(r4)
  250. /* Mask and obtain the bit in r3 */
  251. rlwinm. r3, r3, 0, 24, 24
  252. /* If not zero, jump and continue with u-boot */
  253. bne diag_done
  254. /* Load back contents of PX_AUX in r3 bits 24 to 31 */
  255. lbz r3, 0(r4)
  256. /* Set the MSB of the register value */
  257. ori r3, r3, 0x80
  258. /* Write value in r3 back to PX_AUX */
  259. stb r3, 0(r4)
  260. /* Get the address to jump to in r3*/
  261. lis r3, CFG_DIAG_ADDR@h
  262. ori r3, r3, CFG_DIAG_ADDR@l
  263. /* Load the LR with the branch address */
  264. mtlr r3
  265. /* Branch to diagnostic */
  266. blr
  267. diag_done:
  268. #endif
  269. /* bl l2cache_enable */
  270. mr r3, r21
  271. /* r3: BOOTFLAG */
  272. /* run 1st part of board init code (from Flash) */
  273. bl board_init_f
  274. sync
  275. /* NOTREACHED */
  276. .globl invalidate_bats
  277. invalidate_bats:
  278. li r0, 0
  279. /* invalidate BATs */
  280. mtspr IBAT0U, r0
  281. mtspr IBAT1U, r0
  282. mtspr IBAT2U, r0
  283. mtspr IBAT3U, r0
  284. mtspr IBAT4U, r0
  285. mtspr IBAT5U, r0
  286. mtspr IBAT6U, r0
  287. mtspr IBAT7U, r0
  288. isync
  289. mtspr DBAT0U, r0
  290. mtspr DBAT1U, r0
  291. mtspr DBAT2U, r0
  292. mtspr DBAT3U, r0
  293. mtspr DBAT4U, r0
  294. mtspr DBAT5U, r0
  295. mtspr DBAT6U, r0
  296. mtspr DBAT7U, r0
  297. isync
  298. sync
  299. blr
  300. /*
  301. * early_bats:
  302. *
  303. * Set up bats needed early on - this is usually the BAT for the
  304. * stack-in-cache and the Flash
  305. */
  306. .globl early_bats
  307. early_bats:
  308. /* IBAT 5 */
  309. lis r4, CFG_IBAT5L@h
  310. ori r4, r4, CFG_IBAT5L@l
  311. lis r3, CFG_IBAT5U@h
  312. ori r3, r3, CFG_IBAT5U@l
  313. mtspr IBAT5L, r4
  314. mtspr IBAT5U, r3
  315. isync
  316. /* DBAT 5 */
  317. lis r4, CFG_DBAT5L@h
  318. ori r4, r4, CFG_DBAT5L@l
  319. lis r3, CFG_DBAT5U@h
  320. ori r3, r3, CFG_DBAT5U@l
  321. mtspr DBAT5L, r4
  322. mtspr DBAT5U, r3
  323. isync
  324. /* IBAT 6 */
  325. lis r4, CFG_IBAT6L@h
  326. ori r4, r4, CFG_IBAT6L@l
  327. lis r3, CFG_IBAT6U@h
  328. ori r3, r3, CFG_IBAT6U@l
  329. mtspr IBAT6L, r4
  330. mtspr IBAT6U, r3
  331. isync
  332. /* DBAT 6 */
  333. lis r4, CFG_DBAT6L@h
  334. ori r4, r4, CFG_DBAT6L@l
  335. lis r3, CFG_DBAT6U@h
  336. ori r3, r3, CFG_DBAT6U@l
  337. mtspr DBAT6L, r4
  338. mtspr DBAT6U, r3
  339. isync
  340. blr
  341. .globl clear_tlbs
  342. clear_tlbs:
  343. addis r3, 0, 0x0000
  344. addis r5, 0, 0x4
  345. isync
  346. tlblp:
  347. tlbie r3
  348. sync
  349. addi r3, r3, 0x1000
  350. cmp 0, 0, r3, r5
  351. blt tlblp
  352. blr
  353. .globl enable_addr_trans
  354. enable_addr_trans:
  355. /* enable address translation */
  356. mfmsr r5
  357. ori r5, r5, (MSR_IR | MSR_DR)
  358. mtmsr r5
  359. isync
  360. blr
  361. .globl disable_addr_trans
  362. disable_addr_trans:
  363. /* disable address translation */
  364. mflr r4
  365. mfmsr r3
  366. andi. r0, r3, (MSR_IR | MSR_DR)
  367. beqlr
  368. andc r3, r3, r0
  369. mtspr SRR0, r4
  370. mtspr SRR1, r3
  371. rfi
  372. /*
  373. * This code finishes saving the registers to the exception frame
  374. * and jumps to the appropriate handler for the exception.
  375. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  376. */
  377. .globl transfer_to_handler
  378. transfer_to_handler:
  379. stw r22,_NIP(r21)
  380. lis r22,MSR_POW@h
  381. andc r23,r23,r22
  382. stw r23,_MSR(r21)
  383. SAVE_GPR(7, r21)
  384. SAVE_4GPRS(8, r21)
  385. SAVE_8GPRS(12, r21)
  386. SAVE_8GPRS(24, r21)
  387. mflr r23
  388. andi. r24,r23,0x3f00 /* get vector offset */
  389. stw r24,TRAP(r21)
  390. li r22,0
  391. stw r22,RESULT(r21)
  392. mtspr SPRG2,r22 /* r1 is now kernel sp */
  393. lwz r24,0(r23) /* virtual address of handler */
  394. lwz r23,4(r23) /* where to go when done */
  395. mtspr SRR0,r24
  396. mtspr SRR1,r20
  397. mtlr r23
  398. SYNC
  399. rfi /* jump to handler, enable MMU */
  400. int_return:
  401. mfmsr r28 /* Disable interrupts */
  402. li r4,0
  403. ori r4,r4,MSR_EE
  404. andc r28,r28,r4
  405. SYNC /* Some chip revs need this... */
  406. mtmsr r28
  407. SYNC
  408. lwz r2,_CTR(r1)
  409. lwz r0,_LINK(r1)
  410. mtctr r2
  411. mtlr r0
  412. lwz r2,_XER(r1)
  413. lwz r0,_CCR(r1)
  414. mtspr XER,r2
  415. mtcrf 0xFF,r0
  416. REST_10GPRS(3, r1)
  417. REST_10GPRS(13, r1)
  418. REST_8GPRS(23, r1)
  419. REST_GPR(31, r1)
  420. lwz r2,_NIP(r1) /* Restore environment */
  421. lwz r0,_MSR(r1)
  422. mtspr SRR0,r2
  423. mtspr SRR1,r0
  424. lwz r0,GPR0(r1)
  425. lwz r2,GPR2(r1)
  426. lwz r1,GPR1(r1)
  427. SYNC
  428. rfi
  429. .globl dc_read
  430. dc_read:
  431. blr
  432. .globl get_pvr
  433. get_pvr:
  434. mfspr r3, PVR
  435. blr
  436. .globl get_svr
  437. get_svr:
  438. mfspr r3, SVR
  439. blr
  440. /*
  441. * Function: in8
  442. * Description: Input 8 bits
  443. */
  444. .globl in8
  445. in8:
  446. lbz r3,0x0000(r3)
  447. blr
  448. /*
  449. * Function: out8
  450. * Description: Output 8 bits
  451. */
  452. .globl out8
  453. out8:
  454. stb r4,0x0000(r3)
  455. blr
  456. /*
  457. * Function: out16
  458. * Description: Output 16 bits
  459. */
  460. .globl out16
  461. out16:
  462. sth r4,0x0000(r3)
  463. blr
  464. /*
  465. * Function: out16r
  466. * Description: Byte reverse and output 16 bits
  467. */
  468. .globl out16r
  469. out16r:
  470. sthbrx r4,r0,r3
  471. blr
  472. /*
  473. * Function: out32
  474. * Description: Output 32 bits
  475. */
  476. .globl out32
  477. out32:
  478. stw r4,0x0000(r3)
  479. blr
  480. /*
  481. * Function: out32r
  482. * Description: Byte reverse and output 32 bits
  483. */
  484. .globl out32r
  485. out32r:
  486. stwbrx r4,r0,r3
  487. blr
  488. /*
  489. * Function: in16
  490. * Description: Input 16 bits
  491. */
  492. .globl in16
  493. in16:
  494. lhz r3,0x0000(r3)
  495. blr
  496. /*
  497. * Function: in16r
  498. * Description: Input 16 bits and byte reverse
  499. */
  500. .globl in16r
  501. in16r:
  502. lhbrx r3,r0,r3
  503. blr
  504. /*
  505. * Function: in32
  506. * Description: Input 32 bits
  507. */
  508. .globl in32
  509. in32:
  510. lwz 3,0x0000(3)
  511. blr
  512. /*
  513. * Function: in32r
  514. * Description: Input 32 bits and byte reverse
  515. */
  516. .globl in32r
  517. in32r:
  518. lwbrx r3,r0,r3
  519. blr
  520. /*
  521. * void relocate_code (addr_sp, gd, addr_moni)
  522. *
  523. * This "function" does not return, instead it continues in RAM
  524. * after relocating the monitor code.
  525. *
  526. * r3 = dest
  527. * r4 = src
  528. * r5 = length in bytes
  529. * r6 = cachelinesize
  530. */
  531. .globl relocate_code
  532. relocate_code:
  533. mr r1, r3 /* Set new stack pointer */
  534. mr r9, r4 /* Save copy of Global Data pointer */
  535. mr r2, r9 /* Save for DECLARE_GLOBAL_DATA_PTR */
  536. mr r10, r5 /* Save copy of Destination Address */
  537. mr r3, r5 /* Destination Address */
  538. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  539. ori r4, r4, CFG_MONITOR_BASE@l
  540. lwz r5, GOT(__init_end)
  541. sub r5, r5, r4
  542. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  543. /*
  544. * Fix GOT pointer:
  545. *
  546. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
  547. *
  548. * Offset:
  549. */
  550. sub r15, r10, r4
  551. /* First our own GOT */
  552. add r14, r14, r15
  553. /* then the one used by the C code */
  554. add r30, r30, r15
  555. /*
  556. * Now relocate code
  557. */
  558. #ifdef CONFIG_ECC
  559. bl board_relocate_rom
  560. sync
  561. mr r3, r10 /* Destination Address */
  562. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  563. ori r4, r4, CFG_MONITOR_BASE@l
  564. lwz r5, GOT(__init_end)
  565. sub r5, r5, r4
  566. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  567. #else
  568. cmplw cr1,r3,r4
  569. addi r0,r5,3
  570. srwi. r0,r0,2
  571. beq cr1,4f /* In place copy is not necessary */
  572. beq 7f /* Protect against 0 count */
  573. mtctr r0
  574. bge cr1,2f
  575. la r8,-4(r4)
  576. la r7,-4(r3)
  577. 1: lwzu r0,4(r8)
  578. stwu r0,4(r7)
  579. bdnz 1b
  580. b 4f
  581. 2: slwi r0,r0,2
  582. add r8,r4,r0
  583. add r7,r3,r0
  584. 3: lwzu r0,-4(r8)
  585. stwu r0,-4(r7)
  586. bdnz 3b
  587. #endif
  588. /*
  589. * Now flush the cache: note that we must start from a cache aligned
  590. * address. Otherwise we might miss one cache line.
  591. */
  592. 4: cmpwi r6,0
  593. add r5,r3,r5
  594. beq 7f /* Always flush prefetch queue in any case */
  595. subi r0,r6,1
  596. andc r3,r3,r0
  597. mr r4,r3
  598. 5: dcbst 0,r4
  599. add r4,r4,r6
  600. cmplw r4,r5
  601. blt 5b
  602. sync /* Wait for all dcbst to complete on bus */
  603. mr r4,r3
  604. 6: icbi 0,r4
  605. add r4,r4,r6
  606. cmplw r4,r5
  607. blt 6b
  608. 7: sync /* Wait for all icbi to complete on bus */
  609. isync
  610. /*
  611. * We are done. Do not return, instead branch to second part of board
  612. * initialization, now running from RAM.
  613. */
  614. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  615. mtlr r0
  616. blr
  617. in_ram:
  618. #ifdef CONFIG_ECC
  619. bl board_init_ecc
  620. #endif
  621. /*
  622. * Relocation Function, r14 point to got2+0x8000
  623. *
  624. * Adjust got2 pointers, no need to check for 0, this code
  625. * already puts a few entries in the table.
  626. */
  627. li r0,__got2_entries@sectoff@l
  628. la r3,GOT(_GOT2_TABLE_)
  629. lwz r11,GOT(_GOT2_TABLE_)
  630. mtctr r0
  631. sub r11,r3,r11
  632. addi r3,r3,-4
  633. 1: lwzu r0,4(r3)
  634. add r0,r0,r11
  635. stw r0,0(r3)
  636. bdnz 1b
  637. /*
  638. * Now adjust the fixups and the pointers to the fixups
  639. * in case we need to move ourselves again.
  640. */
  641. 2: li r0,__fixup_entries@sectoff@l
  642. lwz r3,GOT(_FIXUP_TABLE_)
  643. cmpwi r0,0
  644. mtctr r0
  645. addi r3,r3,-4
  646. beq 4f
  647. 3: lwzu r4,4(r3)
  648. lwzux r0,r4,r11
  649. add r0,r0,r11
  650. stw r10,0(r3)
  651. stw r0,0(r4)
  652. bdnz 3b
  653. 4:
  654. /* clear_bss: */
  655. /*
  656. * Now clear BSS segment
  657. */
  658. lwz r3,GOT(__bss_start)
  659. lwz r4,GOT(_end)
  660. cmplw 0, r3, r4
  661. beq 6f
  662. li r0, 0
  663. 5:
  664. stw r0, 0(r3)
  665. addi r3, r3, 4
  666. cmplw 0, r3, r4
  667. bne 5b
  668. 6:
  669. mr r3, r9 /* Init Date pointer */
  670. mr r4, r10 /* Destination Address */
  671. bl board_init_r
  672. /* not reached - end relocate_code */
  673. /*-----------------------------------------------------------------------*/
  674. /*
  675. * Copy exception vector code to low memory
  676. *
  677. * r3: dest_addr
  678. * r7: source address, r8: end address, r9: target address
  679. */
  680. .globl trap_init
  681. trap_init:
  682. lwz r7, GOT(_start)
  683. lwz r8, GOT(_end_of_vectors)
  684. li r9, 0x100 /* reset vector always at 0x100 */
  685. cmplw 0, r7, r8
  686. bgelr /* return if r7>=r8 - just in case */
  687. mflr r4 /* save link register */
  688. 1:
  689. lwz r0, 0(r7)
  690. stw r0, 0(r9)
  691. addi r7, r7, 4
  692. addi r9, r9, 4
  693. cmplw 0, r7, r8
  694. bne 1b
  695. /*
  696. * relocate `hdlr' and `int_return' entries
  697. */
  698. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  699. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  700. 2:
  701. bl trap_reloc
  702. addi r7, r7, 0x100 /* next exception vector */
  703. cmplw 0, r7, r8
  704. blt 2b
  705. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  706. bl trap_reloc
  707. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  708. bl trap_reloc
  709. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  710. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  711. 3:
  712. bl trap_reloc
  713. addi r7, r7, 0x100 /* next exception vector */
  714. cmplw 0, r7, r8
  715. blt 3b
  716. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  717. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  718. 4:
  719. bl trap_reloc
  720. addi r7, r7, 0x100 /* next exception vector */
  721. cmplw 0, r7, r8
  722. blt 4b
  723. /* enable execptions from RAM vectors */
  724. mfmsr r7
  725. li r8,MSR_IP
  726. andc r7,r7,r8
  727. ori r7,r7,MSR_ME /* Enable Machine Check */
  728. mtmsr r7
  729. mtlr r4 /* restore link register */
  730. blr
  731. /*
  732. * Function: relocate entries for one exception vector
  733. */
  734. trap_reloc:
  735. lwz r0, 0(r7) /* hdlr ... */
  736. add r0, r0, r3 /* ... += dest_addr */
  737. stw r0, 0(r7)
  738. lwz r0, 4(r7) /* int_return ... */
  739. add r0, r0, r3 /* ... += dest_addr */
  740. stw r0, 4(r7)
  741. sync
  742. isync
  743. blr
  744. .globl enable_ext_addr
  745. enable_ext_addr:
  746. mfspr r0, HID0
  747. lis r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@h
  748. ori r0, r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@l
  749. mtspr HID0, r0
  750. sync
  751. isync
  752. blr
  753. #if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
  754. .globl setup_ccsrbar
  755. setup_ccsrbar:
  756. /* Special sequence needed to update CCSRBAR itself */
  757. lis r4, CFG_CCSRBAR_DEFAULT@h
  758. ori r4, r4, CFG_CCSRBAR_DEFAULT@l
  759. lis r5, CFG_CCSRBAR@h
  760. ori r5, r5, CFG_CCSRBAR@l
  761. srwi r6,r5,12
  762. stw r6, 0(r4)
  763. isync
  764. lis r5, 0xffff
  765. ori r5,r5,0xf000
  766. lwz r5, 0(r5)
  767. isync
  768. lis r3, CFG_CCSRBAR@h
  769. lwz r5, CFG_CCSRBAR@l(r3)
  770. isync
  771. blr
  772. #endif
  773. #ifdef CFG_INIT_RAM_LOCK
  774. lock_ram_in_cache:
  775. /* Allocate Initial RAM in data cache.
  776. */
  777. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  778. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  779. li r2, ((CFG_INIT_RAM_END & ~31) + \
  780. (CFG_INIT_RAM_ADDR & 31) + 31) / 32
  781. mtctr r2
  782. 1:
  783. dcbz r0, r3
  784. addi r3, r3, 32
  785. bdnz 1b
  786. #if 1
  787. /* Lock the data cache */
  788. mfspr r0, HID0
  789. ori r0, r0, 0x1000
  790. sync
  791. mtspr HID0, r0
  792. sync
  793. blr
  794. #endif
  795. #if 0
  796. /* Lock the first way of the data cache */
  797. mfspr r0, LDSTCR
  798. ori r0, r0, 0x0080
  799. #if defined(CONFIG_ALTIVEC)
  800. dssall
  801. #endif
  802. sync
  803. mtspr LDSTCR, r0
  804. sync
  805. isync
  806. blr
  807. #endif
  808. .globl unlock_ram_in_cache
  809. unlock_ram_in_cache:
  810. /* invalidate the INIT_RAM section */
  811. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  812. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  813. li r2, ((CFG_INIT_RAM_END & ~31) + \
  814. (CFG_INIT_RAM_ADDR & 31) + 31) / 32
  815. mtctr r2
  816. 1: icbi r0, r3
  817. addi r3, r3, 32
  818. bdnz 1b
  819. sync /* Wait for all icbi to complete on bus */
  820. isync
  821. #if 1
  822. /* Unlock the data cache and invalidate it */
  823. mfspr r0, HID0
  824. li r3,0x1000
  825. andc r0,r0,r3
  826. li r3,0x0400
  827. or r0,r0,r3
  828. sync
  829. mtspr HID0, r0
  830. sync
  831. blr
  832. #endif
  833. #if 0
  834. /* Unlock the first way of the data cache */
  835. mfspr r0, LDSTCR
  836. li r3,0x0080
  837. andc r0,r0,r3
  838. #ifdef CONFIG_ALTIVEC
  839. dssall
  840. #endif
  841. sync
  842. mtspr LDSTCR, r0
  843. sync
  844. isync
  845. li r3,0x0400
  846. or r0,r0,r3
  847. sync
  848. mtspr HID0, r0
  849. sync
  850. blr
  851. #endif
  852. #endif
  853. /* If this is a multi-cpu system then we need to handle the
  854. * 2nd cpu. The assumption is that the 2nd cpu is being
  855. * held in boot holdoff mode until the 1st cpu unlocks it
  856. * from Linux. We'll do some basic cpu init and then pass
  857. * it to the Linux Reset Vector.
  858. * Sri: Much of this initialization is not required. Linux
  859. * rewrites the bats, and the sprs and also enables the L1 cache.
  860. */
  861. #if (CONFIG_NUM_CPUS > 1)
  862. .globl secondary_cpu_setup
  863. secondary_cpu_setup:
  864. /* Do only core setup on all cores except cpu0 */
  865. bl invalidate_bats
  866. sync
  867. bl enable_ext_addr
  868. #ifdef CFG_L2
  869. /* init the L2 cache */
  870. addis r3, r0, L2_INIT@h
  871. ori r3, r3, L2_INIT@l
  872. sync
  873. mtspr l2cr, r3
  874. #ifdef CONFIG_ALTIVEC
  875. dssall
  876. #endif
  877. /* invalidate the L2 cache */
  878. bl l2cache_invalidate
  879. sync
  880. #endif
  881. /* enable and invalidate the data cache */
  882. bl dcache_enable
  883. sync
  884. /* enable and invalidate the instruction cache*/
  885. bl icache_enable
  886. sync
  887. /* TBEN in HID0 */
  888. mfspr r4, HID0
  889. oris r4, r4, 0x0400
  890. mtspr HID0, r4
  891. sync
  892. isync
  893. /* MCP|SYNCBE|ABE in HID1 */
  894. mfspr r4, HID1
  895. oris r4, r4, 0x8000
  896. ori r4, r4, 0x0C00
  897. mtspr HID1, r4
  898. sync
  899. isync
  900. lis r3, CONFIG_LINUX_RESET_VEC@h
  901. ori r3, r3, CONFIG_LINUX_RESET_VEC@l
  902. mtlr r3
  903. blr
  904. /* Never Returns, Running in Linux Now */
  905. #endif