start.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. /*
  2. * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
  3. * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
  4. * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de>
  5. * Copyright (C) 2001 Josh Huber <huber@mclx.com>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. /* U-Boot - Startup Code for PowerPC based Embedded Boards
  26. *
  27. *
  28. * The processor starts at 0xfff00100 and the code is executed
  29. * from flash. The code is organized to be at an other address
  30. * in memory, but as long we don't jump around before relocating.
  31. * board_init lies at a quite high address and when the cpu has
  32. * jumped there, everything is ok.
  33. */
  34. #include <config.h>
  35. #include <74xx_7xx.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 <galileo/gt64260R.h>
  42. #ifndef CONFIG_IDENT_STRING
  43. #define CONFIG_IDENT_STRING ""
  44. #endif
  45. /* We don't want the MMU yet.
  46. */
  47. #undef MSR_KERNEL
  48. /* Machine Check and Recoverable Interr. */
  49. #define MSR_KERNEL ( MSR_ME | MSR_RI )
  50. /*
  51. * Set up GOT: Global Offset Table
  52. *
  53. * Use r14 to access the GOT
  54. */
  55. START_GOT
  56. GOT_ENTRY(_GOT2_TABLE_)
  57. GOT_ENTRY(_FIXUP_TABLE_)
  58. GOT_ENTRY(_start)
  59. GOT_ENTRY(_start_of_vectors)
  60. GOT_ENTRY(_end_of_vectors)
  61. GOT_ENTRY(transfer_to_handler)
  62. GOT_ENTRY(_end)
  63. GOT_ENTRY(.bss)
  64. END_GOT
  65. /*
  66. * r3 - 1st arg to board_init(): IMMP pointer
  67. * r4 - 2nd arg to board_init(): boot flag
  68. */
  69. .text
  70. .long 0x27051956 /* U-Boot Magic Number */
  71. .globl version_string
  72. version_string:
  73. .ascii U_BOOT_VERSION
  74. .ascii " (", __DATE__, " - ", __TIME__, ")"
  75. .ascii CONFIG_IDENT_STRING, "\0"
  76. . = EXC_OFF_SYS_RESET
  77. .globl _start
  78. _start:
  79. li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
  80. b boot_cold
  81. sync
  82. . = EXC_OFF_SYS_RESET + 0x10
  83. .globl _start_warm
  84. _start_warm:
  85. li r21, BOOTFLAG_WARM /* Software reboot */
  86. b boot_warm
  87. sync
  88. /* the boot code is located below the exception table */
  89. .globl _start_of_vectors
  90. _start_of_vectors:
  91. /* Machine check */
  92. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  93. /* Data Storage exception. "Never" generated on the 860. */
  94. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  95. /* Instruction Storage exception. "Never" generated on the 860. */
  96. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  97. /* External Interrupt exception. */
  98. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  99. /* Alignment exception. */
  100. . = 0x600
  101. Alignment:
  102. EXCEPTION_PROLOG
  103. mfspr r4,DAR
  104. stw r4,_DAR(r21)
  105. mfspr r5,DSISR
  106. stw r5,_DSISR(r21)
  107. addi r3,r1,STACK_FRAME_OVERHEAD
  108. li r20,MSR_KERNEL
  109. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  110. lwz r6,GOT(transfer_to_handler)
  111. mtlr r6
  112. blrl
  113. .L_Alignment:
  114. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  115. .long int_return - _start + EXC_OFF_SYS_RESET
  116. /* Program check exception */
  117. . = 0x700
  118. ProgramCheck:
  119. EXCEPTION_PROLOG
  120. addi r3,r1,STACK_FRAME_OVERHEAD
  121. li r20,MSR_KERNEL
  122. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  123. lwz r6,GOT(transfer_to_handler)
  124. mtlr r6
  125. blrl
  126. .L_ProgramCheck:
  127. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  128. .long int_return - _start + EXC_OFF_SYS_RESET
  129. /* No FPU on MPC8xx. This exception is not supposed to happen.
  130. */
  131. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  132. /* I guess we could implement decrementer, and may have
  133. * to someday for timekeeping.
  134. */
  135. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  136. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  137. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  138. . = 0xc00
  139. /*
  140. * r0 - SYSCALL number
  141. * r3-... arguments
  142. */
  143. SystemCall:
  144. addis r11,r0,0 /* get functions table addr */
  145. ori r11,r11,0 /* Note: this code is patched in trap_init */
  146. addis r12,r0,0 /* get number of functions */
  147. ori r12,r12,0
  148. cmplw 0, r0, r12
  149. bge 1f
  150. rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
  151. add r11,r11,r0
  152. lwz r11,0(r11)
  153. li r12,0xd00-4*3 /* save LR & SRRx */
  154. mflr r0
  155. stw r0,0(r12)
  156. mfspr r0,SRR0
  157. stw r0,4(r12)
  158. mfspr r0,SRR1
  159. stw r0,8(r12)
  160. li r12,0xc00+_back-SystemCall
  161. mtlr r12
  162. mtspr SRR0,r11
  163. 1: SYNC
  164. rfi
  165. _back:
  166. mfmsr r11 /* Disable interrupts */
  167. li r12,0
  168. ori r12,r12,MSR_EE
  169. andc r11,r11,r12
  170. SYNC /* Some chip revs need this... */
  171. mtmsr r11
  172. SYNC
  173. li r12,0xd00-4*3 /* restore regs */
  174. lwz r11,0(r12)
  175. mtlr r11
  176. lwz r11,4(r12)
  177. mtspr SRR0,r11
  178. lwz r11,8(r12)
  179. mtspr SRR1,r11
  180. SYNC
  181. rfi
  182. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  183. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  184. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  185. /*
  186. * On the MPC8xx, this is a software emulation interrupt. It
  187. * occurs for all unimplemented and illegal instructions.
  188. */
  189. STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
  190. STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
  191. STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
  192. STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
  193. STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
  194. STD_EXCEPTION(0x1500, Reserved5, UnknownException)
  195. STD_EXCEPTION(0x1600, Reserved6, UnknownException)
  196. STD_EXCEPTION(0x1700, Reserved7, UnknownException)
  197. STD_EXCEPTION(0x1800, Reserved8, UnknownException)
  198. STD_EXCEPTION(0x1900, Reserved9, UnknownException)
  199. STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
  200. STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
  201. STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
  202. STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
  203. STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
  204. STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
  205. .globl _end_of_vectors
  206. _end_of_vectors:
  207. . = 0x2000
  208. boot_cold:
  209. boot_warm:
  210. /* disable everything */
  211. li r0, 0
  212. mtspr HID0, r0
  213. sync
  214. mtmsr 0
  215. bl invalidate_bats
  216. sync
  217. #ifdef CFG_L2
  218. /* init the L2 cache */
  219. addis r3, r0, L2_INIT@h
  220. ori r3, r3, L2_INIT@l
  221. sync
  222. mtspr l2cr, r3
  223. #endif
  224. #if defined(CONFIG_ALTIVEC) && defined(CONFIG_74xx)
  225. .long 0x7e00066c
  226. /*
  227. * dssall instruction, gas doesn't have it yet
  228. * ...for altivec, data stream stop all this probably
  229. * isn't needed unless we warm (software) reboot U-Boot
  230. */
  231. #endif
  232. #ifdef CFG_L2
  233. /* invalidate the L2 cache */
  234. bl l2cache_invalidate
  235. sync
  236. #endif
  237. #ifdef CFG_BOARD_ASM_INIT
  238. /* do early init */
  239. bl board_asm_init
  240. #endif
  241. /*
  242. * Calculate absolute address in FLASH and jump there
  243. *------------------------------------------------------*/
  244. lis r3, CFG_MONITOR_BASE@h
  245. ori r3, r3, CFG_MONITOR_BASE@l
  246. addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
  247. mtlr r3
  248. blr
  249. in_flash:
  250. /* let the C-code set up the rest */
  251. /* */
  252. /* Be careful to keep code relocatable ! */
  253. /*------------------------------------------------------*/
  254. /* perform low-level init */
  255. /* sdram init, galileo init, etc */
  256. /* r3: NHR bit from HID0 */
  257. /* setup the bats */
  258. bl setup_bats
  259. sync
  260. /*
  261. * Cache must be enabled here for stack-in-cache trick.
  262. * This means we need to enable the BATS.
  263. * This means:
  264. * 1) for the EVB, original gt regs need to be mapped
  265. * 2) need to have an IBAT for the 0xf region,
  266. * we are running there!
  267. * Cache should be turned on after BATs, since by default
  268. * everything is write-through.
  269. * The init-mem BAT can be reused after reloc. The old
  270. * gt-regs BAT can be reused after board_init_f calls
  271. * board_pre_init (EVB only).
  272. */
  273. #if !defined(CONFIG_BAB7xx) && !defined(CONFIG_ELPPC)
  274. /* enable address translation */
  275. bl enable_addr_trans
  276. sync
  277. /* enable and invalidate the data cache */
  278. bl l1dcache_enable
  279. sync
  280. #endif
  281. #ifdef CFG_INIT_RAM_LOCK
  282. bl lock_ram_in_cache
  283. sync
  284. #endif
  285. /* set up the stack pointer in our newly created
  286. * cache-ram (r1) */
  287. lis r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@h
  288. ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@l
  289. li r0, 0 /* Make room for stack frame header and */
  290. stwu r0, -4(r1) /* clear final stack frame so that */
  291. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  292. GET_GOT /* initialize GOT access */
  293. /* run low-level CPU init code (from Flash) */
  294. bl cpu_init_f
  295. sync
  296. mr r3, r21
  297. /* r3: BOOTFLAG */
  298. /* run 1st part of board init code (from Flash) */
  299. bl board_init_f
  300. sync
  301. /* NOTREACHED */
  302. .globl invalidate_bats
  303. invalidate_bats:
  304. /* invalidate BATs */
  305. mtspr IBAT0U, r0
  306. mtspr IBAT1U, r0
  307. mtspr IBAT2U, r0
  308. mtspr IBAT3U, r0
  309. isync
  310. mtspr DBAT0U, r0
  311. mtspr DBAT1U, r0
  312. mtspr DBAT2U, r0
  313. mtspr DBAT3U, r0
  314. isync
  315. sync
  316. blr
  317. /* setup_bats - set them up to some initial state */
  318. .globl setup_bats
  319. setup_bats:
  320. addis r0, r0, 0x0000
  321. /* IBAT 0 */
  322. addis r4, r0, CFG_IBAT0L@h
  323. ori r4, r4, CFG_IBAT0L@l
  324. addis r3, r0, CFG_IBAT0U@h
  325. ori r3, r3, CFG_IBAT0U@l
  326. mtspr IBAT0L, r4
  327. mtspr IBAT0U, r3
  328. isync
  329. /* DBAT 0 */
  330. addis r4, r0, CFG_DBAT0L@h
  331. ori r4, r4, CFG_DBAT0L@l
  332. addis r3, r0, CFG_DBAT0U@h
  333. ori r3, r3, CFG_DBAT0U@l
  334. mtspr DBAT0L, r4
  335. mtspr DBAT0U, r3
  336. isync
  337. /* IBAT 1 */
  338. addis r4, r0, CFG_IBAT1L@h
  339. ori r4, r4, CFG_IBAT1L@l
  340. addis r3, r0, CFG_IBAT1U@h
  341. ori r3, r3, CFG_IBAT1U@l
  342. mtspr IBAT1L, r4
  343. mtspr IBAT1U, r3
  344. isync
  345. /* DBAT 1 */
  346. addis r4, r0, CFG_DBAT1L@h
  347. ori r4, r4, CFG_DBAT1L@l
  348. addis r3, r0, CFG_DBAT1U@h
  349. ori r3, r3, CFG_DBAT1U@l
  350. mtspr DBAT1L, r4
  351. mtspr DBAT1U, r3
  352. isync
  353. /* IBAT 2 */
  354. addis r4, r0, CFG_IBAT2L@h
  355. ori r4, r4, CFG_IBAT2L@l
  356. addis r3, r0, CFG_IBAT2U@h
  357. ori r3, r3, CFG_IBAT2U@l
  358. mtspr IBAT2L, r4
  359. mtspr IBAT2U, r3
  360. isync
  361. /* DBAT 2 */
  362. addis r4, r0, CFG_DBAT2L@h
  363. ori r4, r4, CFG_DBAT2L@l
  364. addis r3, r0, CFG_DBAT2U@h
  365. ori r3, r3, CFG_DBAT2U@l
  366. mtspr DBAT2L, r4
  367. mtspr DBAT2U, r3
  368. isync
  369. /* IBAT 3 */
  370. addis r4, r0, CFG_IBAT3L@h
  371. ori r4, r4, CFG_IBAT3L@l
  372. addis r3, r0, CFG_IBAT3U@h
  373. ori r3, r3, CFG_IBAT3U@l
  374. mtspr IBAT3L, r4
  375. mtspr IBAT3U, r3
  376. isync
  377. /* DBAT 3 */
  378. addis r4, r0, CFG_DBAT3L@h
  379. ori r4, r4, CFG_DBAT3L@l
  380. addis r3, r0, CFG_DBAT3U@h
  381. ori r3, r3, CFG_DBAT3U@l
  382. mtspr DBAT3L, r4
  383. mtspr DBAT3U, r3
  384. isync
  385. /* bats are done, now invalidate the TLBs */
  386. addis r3, 0, 0x0000
  387. addis r5, 0, 0x4 /* upper bound of 0x00040000 for 7400/750 */
  388. isync
  389. tlblp:
  390. tlbie r3
  391. sync
  392. addi r3, r3, 0x1000
  393. cmp 0, 0, r3, r5
  394. blt tlblp
  395. blr
  396. .globl enable_addr_trans
  397. enable_addr_trans:
  398. /* enable address translation */
  399. mfmsr r5
  400. ori r5, r5, (MSR_IR | MSR_DR)
  401. mtmsr r5
  402. isync
  403. blr
  404. .globl disable_addr_trans
  405. disable_addr_trans:
  406. /* disable address translation */
  407. mflr r4
  408. mfmsr r3
  409. andi. r0, r3, (MSR_IR | MSR_DR)
  410. beqlr
  411. andc r3, r3, r0
  412. mtspr SRR0, r4
  413. mtspr SRR1, r3
  414. rfi
  415. /*
  416. * This code finishes saving the registers to the exception frame
  417. * and jumps to the appropriate handler for the exception.
  418. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  419. */
  420. .globl transfer_to_handler
  421. transfer_to_handler:
  422. stw r22,_NIP(r21)
  423. lis r22,MSR_POW@h
  424. andc r23,r23,r22
  425. stw r23,_MSR(r21)
  426. SAVE_GPR(7, r21)
  427. SAVE_4GPRS(8, r21)
  428. SAVE_8GPRS(12, r21)
  429. SAVE_8GPRS(24, r21)
  430. mflr r23
  431. andi. r24,r23,0x3f00 /* get vector offset */
  432. stw r24,TRAP(r21)
  433. li r22,0
  434. stw r22,RESULT(r21)
  435. mtspr SPRG2,r22 /* r1 is now kernel sp */
  436. lwz r24,0(r23) /* virtual address of handler */
  437. lwz r23,4(r23) /* where to go when done */
  438. mtspr SRR0,r24
  439. mtspr SRR1,r20
  440. mtlr r23
  441. SYNC
  442. rfi /* jump to handler, enable MMU */
  443. int_return:
  444. mfmsr r28 /* Disable interrupts */
  445. li r4,0
  446. ori r4,r4,MSR_EE
  447. andc r28,r28,r4
  448. SYNC /* Some chip revs need this... */
  449. mtmsr r28
  450. SYNC
  451. lwz r2,_CTR(r1)
  452. lwz r0,_LINK(r1)
  453. mtctr r2
  454. mtlr r0
  455. lwz r2,_XER(r1)
  456. lwz r0,_CCR(r1)
  457. mtspr XER,r2
  458. mtcrf 0xFF,r0
  459. REST_10GPRS(3, r1)
  460. REST_10GPRS(13, r1)
  461. REST_8GPRS(23, r1)
  462. REST_GPR(31, r1)
  463. lwz r2,_NIP(r1) /* Restore environment */
  464. lwz r0,_MSR(r1)
  465. mtspr SRR0,r2
  466. mtspr SRR1,r0
  467. lwz r0,GPR0(r1)
  468. lwz r2,GPR2(r1)
  469. lwz r1,GPR1(r1)
  470. SYNC
  471. rfi
  472. .globl dc_read
  473. dc_read:
  474. blr
  475. .globl get_pvr
  476. get_pvr:
  477. mfspr r3, PVR
  478. blr
  479. /*-----------------------------------------------------------------------*/
  480. /*
  481. * void relocate_code (addr_sp, gd, addr_moni)
  482. *
  483. * This "function" does not return, instead it continues in RAM
  484. * after relocating the monitor code.
  485. *
  486. * r3 = dest
  487. * r4 = src
  488. * r5 = length in bytes
  489. * r6 = cachelinesize
  490. */
  491. .globl relocate_code
  492. relocate_code:
  493. mr r1, r3 /* Set new stack pointer */
  494. mr r9, r4 /* Save copy of Global Data pointer */
  495. mr r10, r5 /* Save copy of Destination Address */
  496. mr r3, r5 /* Destination Address */
  497. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  498. ori r4, r4, CFG_MONITOR_BASE@l
  499. lis r5, CFG_MONITOR_LEN@h /* Length in Bytes */
  500. ori r5, r5, CFG_MONITOR_LEN@l
  501. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  502. /*
  503. * Fix GOT pointer:
  504. *
  505. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
  506. *
  507. * Offset:
  508. */
  509. sub r15, r10, r4
  510. /* First our own GOT */
  511. add r14, r14, r15
  512. /* then the one used by the C code */
  513. add r30, r30, r15
  514. /*
  515. * Now relocate code
  516. */
  517. #ifdef CONFIG_ECC
  518. bl board_relocate_rom
  519. sync
  520. mr r3, r10 /* Destination Address */
  521. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  522. ori r4, r4, CFG_MONITOR_BASE@l
  523. lis r5, CFG_MONITOR_LEN@h /* Length in Bytes */
  524. ori r5, r5, CFG_MONITOR_LEN@l
  525. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  526. #else
  527. cmplw cr1,r3,r4
  528. addi r0,r5,3
  529. srwi. r0,r0,2
  530. beq cr1,4f /* In place copy is not necessary */
  531. beq 7f /* Protect against 0 count */
  532. mtctr r0
  533. bge cr1,2f
  534. la r8,-4(r4)
  535. la r7,-4(r3)
  536. 1: lwzu r0,4(r8)
  537. stwu r0,4(r7)
  538. bdnz 1b
  539. b 4f
  540. 2: slwi r0,r0,2
  541. add r8,r4,r0
  542. add r7,r3,r0
  543. 3: lwzu r0,-4(r8)
  544. stwu r0,-4(r7)
  545. bdnz 3b
  546. #endif
  547. /*
  548. * Now flush the cache: note that we must start from a cache aligned
  549. * address. Otherwise we might miss one cache line.
  550. */
  551. 4: cmpwi r6,0
  552. add r5,r3,r5
  553. beq 7f /* Always flush prefetch queue in any case */
  554. subi r0,r6,1
  555. andc r3,r3,r0
  556. mr r4,r3
  557. 5: dcbst 0,r4
  558. add r4,r4,r6
  559. cmplw r4,r5
  560. blt 5b
  561. sync /* Wait for all dcbst to complete on bus */
  562. mr r4,r3
  563. 6: icbi 0,r4
  564. add r4,r4,r6
  565. cmplw r4,r5
  566. blt 6b
  567. 7: sync /* Wait for all icbi to complete on bus */
  568. isync
  569. /*
  570. * We are done. Do not return, instead branch to second part of board
  571. * initialization, now running from RAM.
  572. */
  573. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  574. mtlr r0
  575. blr
  576. in_ram:
  577. #ifdef CONFIG_ECC
  578. bl board_init_ecc
  579. #endif
  580. /*
  581. * Relocation Function, r14 point to got2+0x8000
  582. *
  583. * Adjust got2 pointers, no need to check for 0, this code
  584. * already puts a few entries in the table.
  585. */
  586. li r0,__got2_entries@sectoff@l
  587. la r3,GOT(_GOT2_TABLE_)
  588. lwz r11,GOT(_GOT2_TABLE_)
  589. mtctr r0
  590. sub r11,r3,r11
  591. addi r3,r3,-4
  592. 1: lwzu r0,4(r3)
  593. add r0,r0,r11
  594. stw r0,0(r3)
  595. bdnz 1b
  596. /*
  597. * Now adjust the fixups and the pointers to the fixups
  598. * in case we need to move ourselves again.
  599. */
  600. 2: li r0,__fixup_entries@sectoff@l
  601. lwz r3,GOT(_FIXUP_TABLE_)
  602. cmpwi r0,0
  603. mtctr r0
  604. addi r3,r3,-4
  605. beq 4f
  606. 3: lwzu r4,4(r3)
  607. lwzux r0,r4,r11
  608. add r0,r0,r11
  609. stw r10,0(r3)
  610. stw r0,0(r4)
  611. bdnz 3b
  612. 4:
  613. /* clear_bss: */
  614. /*
  615. * Now clear BSS segment
  616. */
  617. lwz r3,GOT(.bss)
  618. lwz r4,GOT(_end)
  619. cmplw 0, r3, r4
  620. beq 6f
  621. li r0, 0
  622. 5:
  623. stw r0, 0(r3)
  624. addi r3, r3, 4
  625. cmplw 0, r3, r4
  626. bne 5b
  627. 6:
  628. mr r3, r10 /* Destination Address */
  629. bl after_reloc
  630. /* not reached - end relocate_code */
  631. /*-----------------------------------------------------------------------*/
  632. /* Problems accessing "end" in C, so do it here */
  633. .globl get_endaddr
  634. get_endaddr:
  635. lwz r3,GOT(_end)
  636. blr
  637. /*
  638. * Copy exception vector code to low memory
  639. *
  640. * r3: dest_addr
  641. * r7: source address, r8: end address, r9: target address
  642. */
  643. .globl trap_init
  644. trap_init:
  645. lwz r7, GOT(_start)
  646. lwz r8, GOT(_end_of_vectors)
  647. rlwinm r9, r7, 0, 18, 31 /* _start & 0x3FFF */
  648. cmplw 0, r7, r8
  649. bgelr /* return if r7>=r8 - just in case */
  650. mflr r4 /* save link register */
  651. 1:
  652. lwz r0, 0(r7)
  653. stw r0, 0(r9)
  654. addi r7, r7, 4
  655. addi r9, r9, 4
  656. cmplw 0, r7, r8
  657. bne 1b
  658. /*
  659. * relocate `hdlr' and `int_return' entries
  660. */
  661. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  662. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  663. 2:
  664. bl trap_reloc
  665. addi r7, r7, 0x100 /* next exception vector */
  666. cmplw 0, r7, r8
  667. blt 2b
  668. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  669. bl trap_reloc
  670. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  671. bl trap_reloc
  672. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  673. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  674. 3:
  675. bl trap_reloc
  676. addi r7, r7, 0x100 /* next exception vector */
  677. cmplw 0, r7, r8
  678. blt 3b
  679. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  680. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  681. 4:
  682. bl trap_reloc
  683. addi r7, r7, 0x100 /* next exception vector */
  684. cmplw 0, r7, r8
  685. blt 4b
  686. /* enable execptions from RAM vectors */
  687. mfmsr r7
  688. li r8,MSR_IP
  689. andc r7,r7,r8
  690. mtmsr r7
  691. mtlr r4 /* restore link register */
  692. blr
  693. /*
  694. * Function: relocate entries for one exception vector
  695. */
  696. trap_reloc:
  697. lwz r0, 0(r7) /* hdlr ... */
  698. add r0, r0, r3 /* ... += dest_addr */
  699. stw r0, 0(r7)
  700. lwz r0, 4(r7) /* int_return ... */
  701. add r0, r0, r3 /* ... += dest_addr */
  702. stw r0, 4(r7)
  703. sync
  704. isync
  705. blr
  706. #ifdef CFG_INIT_RAM_LOCK
  707. lock_ram_in_cache:
  708. /* Allocate Initial RAM in data cache.
  709. */
  710. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  711. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  712. li r2, ((CFG_INIT_RAM_END & ~31) + \
  713. (CFG_INIT_RAM_ADDR & 31) + 31) / 32
  714. mtctr r2
  715. 1:
  716. dcbz r0, r3
  717. addi r3, r3, 32
  718. bdnz 1b
  719. /* Lock the data cache */
  720. mfspr r0, HID0
  721. ori r0, r0, 0x1000
  722. sync
  723. mtspr HID0, r0
  724. sync
  725. blr
  726. .globl unlock_ram_in_cache
  727. unlock_ram_in_cache:
  728. /* invalidate the INIT_RAM section */
  729. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  730. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  731. li r2, ((CFG_INIT_RAM_END & ~31) + \
  732. (CFG_INIT_RAM_ADDR & 31) + 31) / 32
  733. mtctr r2
  734. 1: icbi r0, r3
  735. addi r3, r3, 32
  736. bdnz 1b
  737. sync /* Wait for all icbi to complete on bus */
  738. isync
  739. /* Unlock the data cache and invalidate it */
  740. mfspr r0, HID0
  741. li r3,0x1000
  742. andc r0,r0,r3
  743. li r3,0x0400
  744. or r0,r0,r3
  745. sync
  746. mtspr HID0, r0
  747. sync
  748. blr
  749. #endif