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 <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. #if defined(__pic__) && __pic__ == 1
  221. /* Needed for upcoming -msingle-pic-base */
  222. bl _GLOBAL_OFFSET_TABLE_@local-4
  223. mflr r30
  224. #endif
  225. /* run low-level CPU init code (from Flash) */
  226. bl cpu_init_f
  227. sync
  228. #ifdef RUN_DIAG
  229. /* Load PX_AUX register address in r4 */
  230. lis r4, PIXIS_BASE@h
  231. ori r4, r4, 0x6
  232. /* Load contents of PX_AUX in r3 bits 24 to 31*/
  233. lbz r3, 0(r4)
  234. /* Mask and obtain the bit in r3 */
  235. rlwinm. r3, r3, 0, 24, 24
  236. /* If not zero, jump and continue with u-boot */
  237. bne diag_done
  238. /* Load back contents of PX_AUX in r3 bits 24 to 31 */
  239. lbz r3, 0(r4)
  240. /* Set the MSB of the register value */
  241. ori r3, r3, 0x80
  242. /* Write value in r3 back to PX_AUX */
  243. stb r3, 0(r4)
  244. /* Get the address to jump to in r3*/
  245. lis r3, CONFIG_SYS_DIAG_ADDR@h
  246. ori r3, r3, CONFIG_SYS_DIAG_ADDR@l
  247. /* Load the LR with the branch address */
  248. mtlr r3
  249. /* Branch to diagnostic */
  250. blr
  251. diag_done:
  252. #endif
  253. /* bl l2cache_enable */
  254. /* run 1st part of board init code (from Flash) */
  255. bl board_init_f
  256. sync
  257. /* NOTREACHED - board_init_f() does not return */
  258. .globl invalidate_bats
  259. invalidate_bats:
  260. li r0, 0
  261. /* invalidate BATs */
  262. mtspr IBAT0U, r0
  263. mtspr IBAT1U, r0
  264. mtspr IBAT2U, r0
  265. mtspr IBAT3U, r0
  266. mtspr IBAT4U, r0
  267. mtspr IBAT5U, r0
  268. mtspr IBAT6U, r0
  269. mtspr IBAT7U, r0
  270. isync
  271. mtspr DBAT0U, r0
  272. mtspr DBAT1U, r0
  273. mtspr DBAT2U, r0
  274. mtspr DBAT3U, r0
  275. mtspr DBAT4U, r0
  276. mtspr DBAT5U, r0
  277. mtspr DBAT6U, r0
  278. mtspr DBAT7U, r0
  279. isync
  280. sync
  281. blr
  282. /*
  283. * early_bats:
  284. *
  285. * Set up bats needed early on - this is usually the BAT for the
  286. * stack-in-cache, the Flash, and CCSR space
  287. */
  288. .globl early_bats
  289. early_bats:
  290. /* IBAT 3 */
  291. lis r4, CONFIG_SYS_IBAT3L@h
  292. ori r4, r4, CONFIG_SYS_IBAT3L@l
  293. lis r3, CONFIG_SYS_IBAT3U@h
  294. ori r3, r3, CONFIG_SYS_IBAT3U@l
  295. mtspr IBAT3L, r4
  296. mtspr IBAT3U, r3
  297. isync
  298. /* DBAT 3 */
  299. lis r4, CONFIG_SYS_DBAT3L@h
  300. ori r4, r4, CONFIG_SYS_DBAT3L@l
  301. lis r3, CONFIG_SYS_DBAT3U@h
  302. ori r3, r3, CONFIG_SYS_DBAT3U@l
  303. mtspr DBAT3L, r4
  304. mtspr DBAT3U, r3
  305. isync
  306. /* IBAT 5 */
  307. lis r4, CONFIG_SYS_IBAT5L@h
  308. ori r4, r4, CONFIG_SYS_IBAT5L@l
  309. lis r3, CONFIG_SYS_IBAT5U@h
  310. ori r3, r3, CONFIG_SYS_IBAT5U@l
  311. mtspr IBAT5L, r4
  312. mtspr IBAT5U, r3
  313. isync
  314. /* DBAT 5 */
  315. lis r4, CONFIG_SYS_DBAT5L@h
  316. ori r4, r4, CONFIG_SYS_DBAT5L@l
  317. lis r3, CONFIG_SYS_DBAT5U@h
  318. ori r3, r3, CONFIG_SYS_DBAT5U@l
  319. mtspr DBAT5L, r4
  320. mtspr DBAT5U, r3
  321. isync
  322. /* IBAT 6 */
  323. lis r4, CONFIG_SYS_IBAT6L_EARLY@h
  324. ori r4, r4, CONFIG_SYS_IBAT6L_EARLY@l
  325. lis r3, CONFIG_SYS_IBAT6U_EARLY@h
  326. ori r3, r3, CONFIG_SYS_IBAT6U_EARLY@l
  327. mtspr IBAT6L, r4
  328. mtspr IBAT6U, r3
  329. isync
  330. /* DBAT 6 */
  331. lis r4, CONFIG_SYS_DBAT6L_EARLY@h
  332. ori r4, r4, CONFIG_SYS_DBAT6L_EARLY@l
  333. lis r3, CONFIG_SYS_DBAT6U_EARLY@h
  334. ori r3, r3, CONFIG_SYS_DBAT6U_EARLY@l
  335. mtspr DBAT6L, r4
  336. mtspr DBAT6U, r3
  337. isync
  338. #if(CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR)
  339. /* IBAT 7 */
  340. lis r4, CONFIG_SYS_CCSR_DEFAULT_IBATL@h
  341. ori r4, r4, CONFIG_SYS_CCSR_DEFAULT_IBATL@l
  342. lis r3, CONFIG_SYS_CCSR_DEFAULT_IBATU@h
  343. ori r3, r3, CONFIG_SYS_CCSR_DEFAULT_IBATU@l
  344. mtspr IBAT7L, r4
  345. mtspr IBAT7U, r3
  346. isync
  347. /* DBAT 7 */
  348. lis r4, CONFIG_SYS_CCSR_DEFAULT_DBATL@h
  349. ori r4, r4, CONFIG_SYS_CCSR_DEFAULT_DBATL@l
  350. lis r3, CONFIG_SYS_CCSR_DEFAULT_DBATU@h
  351. ori r3, r3, CONFIG_SYS_CCSR_DEFAULT_DBATU@l
  352. mtspr DBAT7L, r4
  353. mtspr DBAT7U, r3
  354. isync
  355. #endif
  356. blr
  357. .globl clear_tlbs
  358. clear_tlbs:
  359. addis r3, 0, 0x0000
  360. addis r5, 0, 0x4
  361. isync
  362. tlblp:
  363. tlbie r3
  364. sync
  365. addi r3, r3, 0x1000
  366. cmp 0, 0, r3, r5
  367. blt tlblp
  368. blr
  369. .globl disable_addr_trans
  370. disable_addr_trans:
  371. /* disable address translation */
  372. mflr r4
  373. mfmsr r3
  374. andi. r0, r3, (MSR_IR | MSR_DR)
  375. beqlr
  376. andc r3, r3, r0
  377. mtspr SRR0, r4
  378. mtspr SRR1, r3
  379. rfi
  380. /*
  381. * This code finishes saving the registers to the exception frame
  382. * and jumps to the appropriate handler for the exception.
  383. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  384. */
  385. .globl transfer_to_handler
  386. transfer_to_handler:
  387. stw r22,_NIP(r21)
  388. lis r22,MSR_POW@h
  389. andc r23,r23,r22
  390. stw r23,_MSR(r21)
  391. SAVE_GPR(7, r21)
  392. SAVE_4GPRS(8, r21)
  393. SAVE_8GPRS(12, r21)
  394. SAVE_8GPRS(24, r21)
  395. mflr r23
  396. andi. r24,r23,0x3f00 /* get vector offset */
  397. stw r24,TRAP(r21)
  398. li r22,0
  399. stw r22,RESULT(r21)
  400. mtspr SPRG2,r22 /* r1 is now kernel sp */
  401. lwz r24,0(r23) /* virtual address of handler */
  402. lwz r23,4(r23) /* where to go when done */
  403. mtspr SRR0,r24
  404. mtspr SRR1,r20
  405. mtlr r23
  406. SYNC
  407. rfi /* jump to handler, enable MMU */
  408. int_return:
  409. mfmsr r28 /* Disable interrupts */
  410. li r4,0
  411. ori r4,r4,MSR_EE
  412. andc r28,r28,r4
  413. SYNC /* Some chip revs need this... */
  414. mtmsr r28
  415. SYNC
  416. lwz r2,_CTR(r1)
  417. lwz r0,_LINK(r1)
  418. mtctr r2
  419. mtlr r0
  420. lwz r2,_XER(r1)
  421. lwz r0,_CCR(r1)
  422. mtspr XER,r2
  423. mtcrf 0xFF,r0
  424. REST_10GPRS(3, r1)
  425. REST_10GPRS(13, r1)
  426. REST_8GPRS(23, r1)
  427. REST_GPR(31, r1)
  428. lwz r2,_NIP(r1) /* Restore environment */
  429. lwz r0,_MSR(r1)
  430. mtspr SRR0,r2
  431. mtspr SRR1,r0
  432. lwz r0,GPR0(r1)
  433. lwz r2,GPR2(r1)
  434. lwz r1,GPR1(r1)
  435. SYNC
  436. rfi
  437. .globl dc_read
  438. dc_read:
  439. blr
  440. .globl get_pvr
  441. get_pvr:
  442. mfspr r3, PVR
  443. blr
  444. .globl get_svr
  445. get_svr:
  446. mfspr r3, SVR
  447. blr
  448. /*
  449. * Function: in8
  450. * Description: Input 8 bits
  451. */
  452. .globl in8
  453. in8:
  454. lbz r3,0x0000(r3)
  455. blr
  456. /*
  457. * Function: out8
  458. * Description: Output 8 bits
  459. */
  460. .globl out8
  461. out8:
  462. stb r4,0x0000(r3)
  463. blr
  464. /*
  465. * Function: out16
  466. * Description: Output 16 bits
  467. */
  468. .globl out16
  469. out16:
  470. sth r4,0x0000(r3)
  471. blr
  472. /*
  473. * Function: out16r
  474. * Description: Byte reverse and output 16 bits
  475. */
  476. .globl out16r
  477. out16r:
  478. sthbrx r4,r0,r3
  479. blr
  480. /*
  481. * Function: out32
  482. * Description: Output 32 bits
  483. */
  484. .globl out32
  485. out32:
  486. stw r4,0x0000(r3)
  487. blr
  488. /*
  489. * Function: out32r
  490. * Description: Byte reverse and output 32 bits
  491. */
  492. .globl out32r
  493. out32r:
  494. stwbrx r4,r0,r3
  495. blr
  496. /*
  497. * Function: in16
  498. * Description: Input 16 bits
  499. */
  500. .globl in16
  501. in16:
  502. lhz r3,0x0000(r3)
  503. blr
  504. /*
  505. * Function: in16r
  506. * Description: Input 16 bits and byte reverse
  507. */
  508. .globl in16r
  509. in16r:
  510. lhbrx r3,r0,r3
  511. blr
  512. /*
  513. * Function: in32
  514. * Description: Input 32 bits
  515. */
  516. .globl in32
  517. in32:
  518. lwz 3,0x0000(3)
  519. blr
  520. /*
  521. * Function: in32r
  522. * Description: Input 32 bits and byte reverse
  523. */
  524. .globl in32r
  525. in32r:
  526. lwbrx r3,r0,r3
  527. blr
  528. /*
  529. * void relocate_code (addr_sp, gd, addr_moni)
  530. *
  531. * This "function" does not return, instead it continues in RAM
  532. * after relocating the monitor code.
  533. *
  534. * r3 = dest
  535. * r4 = src
  536. * r5 = length in bytes
  537. * r6 = cachelinesize
  538. */
  539. .globl relocate_code
  540. relocate_code:
  541. mr r1, r3 /* Set new stack pointer */
  542. mr r9, r4 /* Save copy of Global Data pointer */
  543. mr r10, r5 /* Save copy of Destination Address */
  544. GET_GOT
  545. #if defined(__pic__) && __pic__ == 1
  546. /* Needed for upcoming -msingle-pic-base */
  547. bl _GLOBAL_OFFSET_TABLE_@local-4
  548. mflr r30
  549. #endif
  550. mr r3, r5 /* Destination Address */
  551. lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  552. ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
  553. lwz r5, GOT(__init_end)
  554. sub r5, r5, r4
  555. li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  556. /*
  557. * Fix GOT pointer:
  558. *
  559. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  560. *
  561. * Offset:
  562. */
  563. sub r15, r10, r4
  564. /* First our own GOT */
  565. add r12, r12, r15
  566. /* then the one used by the C code */
  567. add r30, r30, r15
  568. /*
  569. * Now relocate code
  570. */
  571. cmplw cr1,r3,r4
  572. addi r0,r5,3
  573. srwi. r0,r0,2
  574. beq cr1,4f /* In place copy is not necessary */
  575. beq 7f /* Protect against 0 count */
  576. mtctr r0
  577. bge cr1,2f
  578. la r8,-4(r4)
  579. la r7,-4(r3)
  580. 1: lwzu r0,4(r8)
  581. stwu r0,4(r7)
  582. bdnz 1b
  583. b 4f
  584. 2: slwi r0,r0,2
  585. add r8,r4,r0
  586. add r7,r3,r0
  587. 3: lwzu r0,-4(r8)
  588. stwu r0,-4(r7)
  589. bdnz 3b
  590. /*
  591. * Now flush the cache: note that we must start from a cache aligned
  592. * address. Otherwise we might miss one cache line.
  593. */
  594. 4: cmpwi r6,0
  595. add r5,r3,r5
  596. beq 7f /* Always flush prefetch queue in any case */
  597. subi r0,r6,1
  598. andc r3,r3,r0
  599. mr r4,r3
  600. 5: dcbst 0,r4
  601. add r4,r4,r6
  602. cmplw r4,r5
  603. blt 5b
  604. sync /* Wait for all dcbst to complete on bus */
  605. mr r4,r3
  606. 6: icbi 0,r4
  607. add r4,r4,r6
  608. cmplw r4,r5
  609. blt 6b
  610. 7: sync /* Wait for all icbi to complete on bus */
  611. isync
  612. /*
  613. * We are done. Do not return, instead branch to second part of board
  614. * initialization, now running from RAM.
  615. */
  616. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  617. mtlr r0
  618. blr
  619. in_ram:
  620. /*
  621. * Relocation Function, r12 point to got2+0x8000
  622. *
  623. * Adjust got2 pointers, no need to check for 0, this code
  624. * already puts a few entries in the table.
  625. */
  626. li r0,__got2_entries@sectoff@l
  627. la r3,GOT(_GOT2_TABLE_)
  628. lwz r11,GOT(_GOT2_TABLE_)
  629. mtctr r0
  630. sub r11,r3,r11
  631. addi r3,r3,-4
  632. 1: lwzu r0,4(r3)
  633. cmpwi r0,0
  634. beq- 2f
  635. add r0,r0,r11
  636. stw r0,0(r3)
  637. 2: bdnz 1b
  638. /*
  639. * Now adjust the fixups and the pointers to the fixups
  640. * in case we need to move ourselves again.
  641. */
  642. li r0,__fixup_entries@sectoff@l
  643. lwz r3,GOT(_FIXUP_TABLE_)
  644. cmpwi r0,0
  645. mtctr r0
  646. addi r3,r3,-4
  647. beq 4f
  648. 3: lwzu r4,4(r3)
  649. lwzux r0,r4,r11
  650. cmpwi r0,0
  651. add r0,r0,r11
  652. stw r4,0(r3)
  653. beq- 5f
  654. stw r0,0(r4)
  655. 5: bdnz 3b
  656. 4:
  657. /* clear_bss: */
  658. /*
  659. * Now clear BSS segment
  660. */
  661. lwz r3,GOT(__bss_start)
  662. lwz r4,GOT(__bss_end__)
  663. cmplw 0, r3, r4
  664. beq 6f
  665. li r0, 0
  666. 5:
  667. stw r0, 0(r3)
  668. addi r3, r3, 4
  669. cmplw 0, r3, r4
  670. bne 5b
  671. 6:
  672. mr r3, r9 /* Init Date pointer */
  673. mr r4, r10 /* Destination Address */
  674. bl board_init_r
  675. /* not reached - end relocate_code */
  676. /*-----------------------------------------------------------------------*/
  677. /*
  678. * Copy exception vector code to low memory
  679. *
  680. * r3: dest_addr
  681. * r7: source address, r8: end address, r9: target address
  682. */
  683. .globl trap_init
  684. trap_init:
  685. mflr r4 /* save link register */
  686. GET_GOT
  687. lwz r7, GOT(_start)
  688. lwz r8, GOT(_end_of_vectors)
  689. li r9, 0x100 /* reset vector always at 0x100 */
  690. cmplw 0, r7, r8
  691. bgelr /* return if r7>=r8 - just in case */
  692. 1:
  693. lwz r0, 0(r7)
  694. stw r0, 0(r9)
  695. addi r7, r7, 4
  696. addi r9, r9, 4
  697. cmplw 0, r7, r8
  698. bne 1b
  699. /*
  700. * relocate `hdlr' and `int_return' entries
  701. */
  702. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  703. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  704. 2:
  705. bl trap_reloc
  706. addi r7, r7, 0x100 /* next exception vector */
  707. cmplw 0, r7, r8
  708. blt 2b
  709. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  710. bl trap_reloc
  711. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  712. bl trap_reloc
  713. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  714. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  715. 3:
  716. bl trap_reloc
  717. addi r7, r7, 0x100 /* next exception vector */
  718. cmplw 0, r7, r8
  719. blt 3b
  720. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  721. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  722. 4:
  723. bl trap_reloc
  724. addi r7, r7, 0x100 /* next exception vector */
  725. cmplw 0, r7, r8
  726. blt 4b
  727. /* enable execptions from RAM vectors */
  728. mfmsr r7
  729. li r8,MSR_IP
  730. andc r7,r7,r8
  731. ori r7,r7,MSR_ME /* Enable Machine Check */
  732. mtmsr r7
  733. mtlr r4 /* restore link register */
  734. blr
  735. .globl enable_ext_addr
  736. enable_ext_addr:
  737. mfspr r0, HID0
  738. lis r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@h
  739. ori r0, r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@l
  740. mtspr HID0, r0
  741. sync
  742. isync
  743. blr
  744. #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR)
  745. .globl setup_ccsrbar
  746. setup_ccsrbar:
  747. /* Special sequence needed to update CCSRBAR itself */
  748. lis r4, CONFIG_SYS_CCSRBAR_DEFAULT@h
  749. ori r4, r4, CONFIG_SYS_CCSRBAR_DEFAULT@l
  750. lis r5, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
  751. ori r5, r5, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
  752. srwi r5,r5,12
  753. li r6, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
  754. rlwimi r5,r6,20,8,11
  755. stw r5, 0(r4) /* Store physical value of CCSR */
  756. isync
  757. lis r5, CONFIG_SYS_TEXT_BASE@h
  758. ori r5,r5,CONFIG_SYS_TEXT_BASE@l
  759. lwz r5, 0(r5)
  760. isync
  761. /* Use VA of CCSR to do read */
  762. lis r3, CONFIG_SYS_CCSRBAR@h
  763. lwz r5, CONFIG_SYS_CCSRBAR@l(r3)
  764. isync
  765. blr
  766. #endif
  767. #ifdef CONFIG_SYS_INIT_RAM_LOCK
  768. lock_ram_in_cache:
  769. /* Allocate Initial RAM in data cache.
  770. */
  771. lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
  772. ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
  773. li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
  774. (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
  775. mtctr r4
  776. 1:
  777. dcbz r0, r3
  778. addi r3, r3, 32
  779. bdnz 1b
  780. #if 1
  781. /* Lock the data cache */
  782. mfspr r0, HID0
  783. ori r0, r0, 0x1000
  784. sync
  785. mtspr HID0, r0
  786. sync
  787. blr
  788. #endif
  789. #if 0
  790. /* Lock the first way of the data cache */
  791. mfspr r0, LDSTCR
  792. ori r0, r0, 0x0080
  793. #if defined(CONFIG_ALTIVEC)
  794. dssall
  795. #endif
  796. sync
  797. mtspr LDSTCR, r0
  798. sync
  799. isync
  800. blr
  801. #endif
  802. .globl unlock_ram_in_cache
  803. unlock_ram_in_cache:
  804. /* invalidate the INIT_RAM section */
  805. lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
  806. ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
  807. li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
  808. (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
  809. mtctr r4
  810. 1: icbi r0, r3
  811. addi r3, r3, 32
  812. bdnz 1b
  813. sync /* Wait for all icbi to complete on bus */
  814. isync
  815. #if 1
  816. /* Unlock the data cache and invalidate it */
  817. mfspr r0, HID0
  818. li r3,0x1000
  819. andc r0,r0,r3
  820. li r3,0x0400
  821. or r0,r0,r3
  822. sync
  823. mtspr HID0, r0
  824. sync
  825. blr
  826. #endif
  827. #if 0
  828. /* Unlock the first way of the data cache */
  829. mfspr r0, LDSTCR
  830. li r3,0x0080
  831. andc r0,r0,r3
  832. #ifdef CONFIG_ALTIVEC
  833. dssall
  834. #endif
  835. sync
  836. mtspr LDSTCR, r0
  837. sync
  838. isync
  839. li r3,0x0400
  840. or r0,r0,r3
  841. sync
  842. mtspr HID0, r0
  843. sync
  844. blr
  845. #endif
  846. #endif