start.S 19 KB

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