start.S 19 KB

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