start.S 19 KB

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