start.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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 - 2003 Wolfgang Denk <wd@denx.de>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. /*
  9. * U-Boot - Startup Code for MPC5xxx CPUs
  10. */
  11. #include <asm-offsets.h>
  12. #include <config.h>
  13. #include <mpc5xxx.h>
  14. #include <version.h>
  15. #include <ppc_asm.tmpl>
  16. #include <ppc_defs.h>
  17. #include <asm/cache.h>
  18. #include <asm/mmu.h>
  19. #include <asm/u-boot.h>
  20. /* We don't want the MMU yet.
  21. */
  22. #undef MSR_KERNEL
  23. /* Floating Point enable, Machine Check and Recoverable Interr. */
  24. #ifdef DEBUG
  25. #define MSR_KERNEL (MSR_FP|MSR_RI)
  26. #else
  27. #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
  28. #endif
  29. #ifndef CONFIG_SPL_BUILD
  30. /*
  31. * Set up GOT: Global Offset Table
  32. *
  33. * Use r12 to access the GOT
  34. */
  35. START_GOT
  36. GOT_ENTRY(_GOT2_TABLE_)
  37. GOT_ENTRY(_FIXUP_TABLE_)
  38. GOT_ENTRY(_start)
  39. GOT_ENTRY(_start_of_vectors)
  40. GOT_ENTRY(_end_of_vectors)
  41. GOT_ENTRY(transfer_to_handler)
  42. GOT_ENTRY(__init_end)
  43. GOT_ENTRY(__bss_end)
  44. GOT_ENTRY(__bss_start)
  45. END_GOT
  46. #endif
  47. /*
  48. * Version string
  49. */
  50. .data
  51. .globl version_string
  52. version_string:
  53. .ascii U_BOOT_VERSION_STRING, "\0"
  54. /*
  55. * Exception vectors
  56. */
  57. .text
  58. . = EXC_OFF_SYS_RESET
  59. .globl _start
  60. _start:
  61. #if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
  62. /*
  63. * This is the entry of the real U-Boot from a board port
  64. * that supports SPL booting on the MPC5200. We only need
  65. * to call board_init_f() here. Everything else has already
  66. * been done in the SPL u-boot version.
  67. */
  68. GET_GOT /* initialize GOT access */
  69. bl board_init_f /* run 1st part of board init code (in Flash)*/
  70. /* NOTREACHED - board_init_f() does not return */
  71. #else
  72. mfmsr r5 /* save msr contents */
  73. /* Move CSBoot and adjust instruction pointer */
  74. /*--------------------------------------------------------------*/
  75. #if defined(CONFIG_SYS_LOWBOOT)
  76. # if defined(CONFIG_SYS_RAMBOOT)
  77. # error CONFIG_SYS_LOWBOOT is incompatible with CONFIG_SYS_RAMBOOT
  78. # endif /* CONFIG_SYS_RAMBOOT */
  79. lis r4, CONFIG_SYS_DEFAULT_MBAR@h
  80. lis r3, START_REG(CONFIG_SYS_BOOTCS_START)@h
  81. ori r3, r3, START_REG(CONFIG_SYS_BOOTCS_START)@l
  82. stw r3, 0x4(r4) /* CS0 start */
  83. lis r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@h
  84. ori r3, r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@l
  85. stw r3, 0x8(r4) /* CS0 stop */
  86. lis r3, 0x02010000@h
  87. ori r3, r3, 0x02010000@l
  88. stw r3, 0x54(r4) /* CS0 and Boot enable */
  89. lis r3, lowboot_reentry@h /* jump from bootlow address space (0x0000xxxx) */
  90. ori r3, r3, lowboot_reentry@l /* to the address space the linker used */
  91. mtlr r3
  92. blr
  93. lowboot_reentry:
  94. lis r3, START_REG(CONFIG_SYS_BOOTCS_START)@h
  95. ori r3, r3, START_REG(CONFIG_SYS_BOOTCS_START)@l
  96. stw r3, 0x4c(r4) /* Boot start */
  97. lis r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@h
  98. ori r3, r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@l
  99. stw r3, 0x50(r4) /* Boot stop */
  100. lis r3, 0x02000001@h
  101. ori r3, r3, 0x02000001@l
  102. stw r3, 0x54(r4) /* Boot enable, CS0 disable */
  103. #endif /* CONFIG_SYS_LOWBOOT */
  104. #if defined(CONFIG_SYS_DEFAULT_MBAR) && !defined(CONFIG_SYS_RAMBOOT)
  105. lis r3, CONFIG_SYS_MBAR@h
  106. ori r3, r3, CONFIG_SYS_MBAR@l
  107. /* MBAR is mirrored into the MBAR SPR */
  108. mtspr MBAR,r3
  109. rlwinm r3, r3, 16, 16, 31
  110. lis r4, CONFIG_SYS_DEFAULT_MBAR@h
  111. stw r3, 0(r4)
  112. #endif /* CONFIG_SYS_DEFAULT_MBAR */
  113. /* Initialise the MPC5xxx processor core */
  114. /*--------------------------------------------------------------*/
  115. bl init_5xxx_core
  116. /* initialize some things that are hard to access from C */
  117. /*--------------------------------------------------------------*/
  118. /* set up stack in on-chip SRAM */
  119. lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
  120. ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
  121. ori r1, r3, CONFIG_SYS_INIT_SP_OFFSET
  122. li r0, 0 /* Make room for stack frame header and */
  123. stwu r0, -4(r1) /* clear final stack frame so that */
  124. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  125. /* let the C-code set up the rest */
  126. /* */
  127. /* Be careful to keep code relocatable ! */
  128. /*--------------------------------------------------------------*/
  129. #ifndef CONFIG_SPL_BUILD
  130. GET_GOT /* initialize GOT access */
  131. #endif
  132. /* r3: IMMR */
  133. bl cpu_init_f /* run low-level CPU init code (in Flash)*/
  134. bl board_init_f /* run 1st part of board init code (in Flash)*/
  135. /* NOTREACHED - board_init_f() does not return */
  136. #endif
  137. #ifndef CONFIG_SPL_BUILD
  138. /*
  139. * Vector Table
  140. */
  141. .globl _start_of_vectors
  142. _start_of_vectors:
  143. /* Machine check */
  144. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  145. /* Data Storage exception. */
  146. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  147. /* Instruction Storage exception. */
  148. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  149. /* External Interrupt exception. */
  150. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  151. /* Alignment exception. */
  152. . = 0x600
  153. Alignment:
  154. EXCEPTION_PROLOG(SRR0, SRR1)
  155. mfspr r4,DAR
  156. stw r4,_DAR(r21)
  157. mfspr r5,DSISR
  158. stw r5,_DSISR(r21)
  159. addi r3,r1,STACK_FRAME_OVERHEAD
  160. EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
  161. /* Program check exception */
  162. . = 0x700
  163. ProgramCheck:
  164. EXCEPTION_PROLOG(SRR0, SRR1)
  165. addi r3,r1,STACK_FRAME_OVERHEAD
  166. EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
  167. MSR_KERNEL, COPY_EE)
  168. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  169. /* I guess we could implement decrementer, and may have
  170. * to someday for timekeeping.
  171. */
  172. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  173. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  174. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  175. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  176. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  177. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  178. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  179. STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
  180. STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
  181. STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
  182. #ifdef DEBUG
  183. . = 0x1300
  184. /*
  185. * This exception occurs when the program counter matches the
  186. * Instruction Address Breakpoint Register (IABR).
  187. *
  188. * I want the cpu to halt if this occurs so I can hunt around
  189. * with the debugger and look at things.
  190. *
  191. * When DEBUG is defined, both machine check enable (in the MSR)
  192. * and checkstop reset enable (in the reset mode register) are
  193. * turned off and so a checkstop condition will result in the cpu
  194. * halting.
  195. *
  196. * I force the cpu into a checkstop condition by putting an illegal
  197. * instruction here (at least this is the theory).
  198. *
  199. * well - that didnt work, so just do an infinite loop!
  200. */
  201. 1: b 1b
  202. #else
  203. STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
  204. #endif
  205. STD_EXCEPTION(0x1400, SMI, UnknownException)
  206. STD_EXCEPTION(0x1500, Trap_15, UnknownException)
  207. STD_EXCEPTION(0x1600, Trap_16, UnknownException)
  208. STD_EXCEPTION(0x1700, Trap_17, UnknownException)
  209. STD_EXCEPTION(0x1800, Trap_18, UnknownException)
  210. STD_EXCEPTION(0x1900, Trap_19, UnknownException)
  211. STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
  212. STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
  213. STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
  214. STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
  215. STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
  216. STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
  217. STD_EXCEPTION(0x2000, Trap_20, UnknownException)
  218. STD_EXCEPTION(0x2100, Trap_21, UnknownException)
  219. STD_EXCEPTION(0x2200, Trap_22, UnknownException)
  220. STD_EXCEPTION(0x2300, Trap_23, UnknownException)
  221. STD_EXCEPTION(0x2400, Trap_24, UnknownException)
  222. STD_EXCEPTION(0x2500, Trap_25, UnknownException)
  223. STD_EXCEPTION(0x2600, Trap_26, UnknownException)
  224. STD_EXCEPTION(0x2700, Trap_27, UnknownException)
  225. STD_EXCEPTION(0x2800, Trap_28, UnknownException)
  226. STD_EXCEPTION(0x2900, Trap_29, UnknownException)
  227. STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
  228. STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
  229. STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
  230. STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
  231. STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
  232. STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
  233. .globl _end_of_vectors
  234. _end_of_vectors:
  235. . = 0x3000
  236. /*
  237. * This code finishes saving the registers to the exception frame
  238. * and jumps to the appropriate handler for the exception.
  239. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  240. */
  241. .globl transfer_to_handler
  242. transfer_to_handler:
  243. stw r22,_NIP(r21)
  244. lis r22,MSR_POW@h
  245. andc r23,r23,r22
  246. stw r23,_MSR(r21)
  247. SAVE_GPR(7, r21)
  248. SAVE_4GPRS(8, r21)
  249. SAVE_8GPRS(12, r21)
  250. SAVE_8GPRS(24, r21)
  251. mflr r23
  252. andi. r24,r23,0x3f00 /* get vector offset */
  253. stw r24,TRAP(r21)
  254. li r22,0
  255. stw r22,RESULT(r21)
  256. lwz r24,0(r23) /* virtual address of handler */
  257. lwz r23,4(r23) /* where to go when done */
  258. mtspr SRR0,r24
  259. mtspr SRR1,r20
  260. mtlr r23
  261. SYNC
  262. rfi /* jump to handler, enable MMU */
  263. int_return:
  264. mfmsr r28 /* Disable interrupts */
  265. li r4,0
  266. ori r4,r4,MSR_EE
  267. andc r28,r28,r4
  268. SYNC /* Some chip revs need this... */
  269. mtmsr r28
  270. SYNC
  271. lwz r2,_CTR(r1)
  272. lwz r0,_LINK(r1)
  273. mtctr r2
  274. mtlr r0
  275. lwz r2,_XER(r1)
  276. lwz r0,_CCR(r1)
  277. mtspr XER,r2
  278. mtcrf 0xFF,r0
  279. REST_10GPRS(3, r1)
  280. REST_10GPRS(13, r1)
  281. REST_8GPRS(23, r1)
  282. REST_GPR(31, r1)
  283. lwz r2,_NIP(r1) /* Restore environment */
  284. lwz r0,_MSR(r1)
  285. mtspr SRR0,r2
  286. mtspr SRR1,r0
  287. lwz r0,GPR0(r1)
  288. lwz r2,GPR2(r1)
  289. lwz r1,GPR1(r1)
  290. SYNC
  291. rfi
  292. #endif /* CONFIG_SPL_BUILD */
  293. /*
  294. * This code initialises the MPC5xxx processor core
  295. * (conforms to PowerPC 603e spec)
  296. * Note: expects original MSR contents to be in r5.
  297. */
  298. .globl init_5xx_core
  299. init_5xxx_core:
  300. /* Initialize machine status; enable machine check interrupt */
  301. /*--------------------------------------------------------------*/
  302. li r3, MSR_KERNEL /* Set ME and RI flags */
  303. rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
  304. #ifdef DEBUG
  305. rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
  306. #endif
  307. SYNC /* Some chip revs need this... */
  308. mtmsr r3
  309. SYNC
  310. mtspr SRR1, r3 /* Make SRR1 match MSR */
  311. /* Initialize the Hardware Implementation-dependent Registers */
  312. /* HID0 also contains cache control */
  313. /*--------------------------------------------------------------*/
  314. lis r3, CONFIG_SYS_HID0_INIT@h
  315. ori r3, r3, CONFIG_SYS_HID0_INIT@l
  316. SYNC
  317. mtspr HID0, r3
  318. lis r3, CONFIG_SYS_HID0_FINAL@h
  319. ori r3, r3, CONFIG_SYS_HID0_FINAL@l
  320. SYNC
  321. mtspr HID0, r3
  322. /* clear all BAT's */
  323. /*--------------------------------------------------------------*/
  324. li r0, 0
  325. mtspr DBAT0U, r0
  326. mtspr DBAT0L, r0
  327. mtspr DBAT1U, r0
  328. mtspr DBAT1L, r0
  329. mtspr DBAT2U, r0
  330. mtspr DBAT2L, r0
  331. mtspr DBAT3U, r0
  332. mtspr DBAT3L, r0
  333. mtspr DBAT4U, r0
  334. mtspr DBAT4L, r0
  335. mtspr DBAT5U, r0
  336. mtspr DBAT5L, r0
  337. mtspr DBAT6U, r0
  338. mtspr DBAT6L, r0
  339. mtspr DBAT7U, r0
  340. mtspr DBAT7L, r0
  341. mtspr IBAT0U, r0
  342. mtspr IBAT0L, r0
  343. mtspr IBAT1U, r0
  344. mtspr IBAT1L, r0
  345. mtspr IBAT2U, r0
  346. mtspr IBAT2L, r0
  347. mtspr IBAT3U, r0
  348. mtspr IBAT3L, r0
  349. mtspr IBAT4U, r0
  350. mtspr IBAT4L, r0
  351. mtspr IBAT5U, r0
  352. mtspr IBAT5L, r0
  353. mtspr IBAT6U, r0
  354. mtspr IBAT6L, r0
  355. mtspr IBAT7U, r0
  356. mtspr IBAT7L, r0
  357. SYNC
  358. /* invalidate all tlb's */
  359. /* */
  360. /* From the 603e User Manual: "The 603e provides the ability to */
  361. /* invalidate a TLB entry. The TLB Invalidate Entry (tlbie) */
  362. /* instruction invalidates the TLB entry indexed by the EA, and */
  363. /* operates on both the instruction and data TLBs simultaneously*/
  364. /* invalidating four TLB entries (both sets in each TLB). The */
  365. /* index corresponds to bits 15-19 of the EA. To invalidate all */
  366. /* entries within both TLBs, 32 tlbie instructions should be */
  367. /* issued, incrementing this field by one each time." */
  368. /* */
  369. /* "Note that the tlbia instruction is not implemented on the */
  370. /* 603e." */
  371. /* */
  372. /* bits 15-19 correspond to addresses 0x00000000 to 0x0001F000 */
  373. /* incrementing by 0x1000 each time. The code below is sort of */
  374. /* based on code in "flush_tlbs" from arch/powerpc/kernel/head.S */
  375. /* */
  376. /*--------------------------------------------------------------*/
  377. li r3, 32
  378. mtctr r3
  379. li r3, 0
  380. 1: tlbie r3
  381. addi r3, r3, 0x1000
  382. bdnz 1b
  383. SYNC
  384. /* Done! */
  385. /*--------------------------------------------------------------*/
  386. blr
  387. /* Cache functions.
  388. *
  389. * Note: requires that all cache bits in
  390. * HID0 are in the low half word.
  391. */
  392. .globl icache_enable
  393. icache_enable:
  394. mfspr r3, HID0
  395. ori r3, r3, HID0_ICE
  396. lis r4, 0
  397. ori r4, r4, HID0_ILOCK
  398. andc r3, r3, r4
  399. ori r4, r3, HID0_ICFI
  400. isync
  401. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  402. isync
  403. mtspr HID0, r3 /* clears invalidate */
  404. blr
  405. .globl icache_disable
  406. icache_disable:
  407. mfspr r3, HID0
  408. lis r4, 0
  409. ori r4, r4, HID0_ICE|HID0_ILOCK
  410. andc r3, r3, r4
  411. ori r4, r3, HID0_ICFI
  412. isync
  413. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  414. isync
  415. mtspr HID0, r3 /* clears invalidate */
  416. blr
  417. .globl icache_status
  418. icache_status:
  419. mfspr r3, HID0
  420. rlwinm r3, r3, HID0_ICE_BITPOS + 1, 31, 31
  421. blr
  422. .globl dcache_enable
  423. dcache_enable:
  424. mfspr r3, HID0
  425. ori r3, r3, HID0_DCE
  426. lis r4, 0
  427. ori r4, r4, HID0_DLOCK
  428. andc r3, r3, r4
  429. ori r4, r3, HID0_DCI
  430. sync
  431. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  432. sync
  433. mtspr HID0, r3 /* clears invalidate */
  434. blr
  435. .globl dcache_disable
  436. dcache_disable:
  437. mfspr r3, HID0
  438. lis r4, 0
  439. ori r4, r4, HID0_DCE|HID0_DLOCK
  440. andc r3, r3, r4
  441. ori r4, r3, HID0_DCI
  442. sync
  443. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  444. sync
  445. mtspr HID0, r3 /* clears invalidate */
  446. blr
  447. .globl dcache_status
  448. dcache_status:
  449. mfspr r3, HID0
  450. rlwinm r3, r3, HID0_DCE_BITPOS + 1, 31, 31
  451. blr
  452. .globl get_svr
  453. get_svr:
  454. mfspr r3, SVR
  455. blr
  456. .globl get_pvr
  457. get_pvr:
  458. mfspr r3, PVR
  459. blr
  460. #ifndef CONFIG_SPL_BUILD
  461. /*------------------------------------------------------------------------------*/
  462. /*
  463. * void relocate_code (addr_sp, gd, addr_moni)
  464. *
  465. * This "function" does not return, instead it continues in RAM
  466. * after relocating the monitor code.
  467. *
  468. * r3 = dest
  469. * r4 = src
  470. * r5 = length in bytes
  471. * r6 = cachelinesize
  472. */
  473. .globl relocate_code
  474. relocate_code:
  475. mr r1, r3 /* Set new stack pointer */
  476. mr r9, r4 /* Save copy of Global Data pointer */
  477. mr r10, r5 /* Save copy of Destination Address */
  478. GET_GOT
  479. mr r3, r5 /* Destination Address */
  480. lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  481. ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
  482. lwz r5, GOT(__init_end)
  483. sub r5, r5, r4
  484. li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  485. /*
  486. * Fix GOT pointer:
  487. *
  488. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  489. *
  490. * Offset:
  491. */
  492. sub r15, r10, r4
  493. /* First our own GOT */
  494. add r12, r12, r15
  495. /* then the one used by the C code */
  496. add r30, r30, r15
  497. /*
  498. * Now relocate code
  499. */
  500. cmplw cr1,r3,r4
  501. addi r0,r5,3
  502. srwi. r0,r0,2
  503. beq cr1,4f /* In place copy is not necessary */
  504. beq 7f /* Protect against 0 count */
  505. mtctr r0
  506. bge cr1,2f
  507. la r8,-4(r4)
  508. la r7,-4(r3)
  509. 1: lwzu r0,4(r8)
  510. stwu r0,4(r7)
  511. bdnz 1b
  512. b 4f
  513. 2: slwi r0,r0,2
  514. add r8,r4,r0
  515. add r7,r3,r0
  516. 3: lwzu r0,-4(r8)
  517. stwu r0,-4(r7)
  518. bdnz 3b
  519. /*
  520. * Now flush the cache: note that we must start from a cache aligned
  521. * address. Otherwise we might miss one cache line.
  522. */
  523. 4: cmpwi r6,0
  524. add r5,r3,r5
  525. beq 7f /* Always flush prefetch queue in any case */
  526. subi r0,r6,1
  527. andc r3,r3,r0
  528. mfspr r7,HID0 /* don't do dcbst if dcache is disabled */
  529. rlwinm r7,r7,HID0_DCE_BITPOS+1,31,31
  530. cmpwi r7,0
  531. beq 9f
  532. mr r4,r3
  533. 5: dcbst 0,r4
  534. add r4,r4,r6
  535. cmplw r4,r5
  536. blt 5b
  537. sync /* Wait for all dcbst to complete on bus */
  538. 9: mfspr r7,HID0 /* don't do icbi if icache is disabled */
  539. rlwinm r7,r7,HID0_ICE_BITPOS+1,31,31
  540. cmpwi r7,0
  541. beq 7f
  542. mr r4,r3
  543. 6: icbi 0,r4
  544. add r4,r4,r6
  545. cmplw r4,r5
  546. blt 6b
  547. 7: sync /* Wait for all icbi to complete on bus */
  548. isync
  549. /*
  550. * We are done. Do not return, instead branch to second part of board
  551. * initialization, now running from RAM.
  552. */
  553. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  554. mtlr r0
  555. blr
  556. in_ram:
  557. /*
  558. * Relocation Function, r12 point to got2+0x8000
  559. *
  560. * Adjust got2 pointers, no need to check for 0, this code
  561. * already puts a few entries in the table.
  562. */
  563. li r0,__got2_entries@sectoff@l
  564. la r3,GOT(_GOT2_TABLE_)
  565. lwz r11,GOT(_GOT2_TABLE_)
  566. mtctr r0
  567. sub r11,r3,r11
  568. addi r3,r3,-4
  569. 1: lwzu r0,4(r3)
  570. cmpwi r0,0
  571. beq- 2f
  572. add r0,r0,r11
  573. stw r0,0(r3)
  574. 2: bdnz 1b
  575. /*
  576. * Now adjust the fixups and the pointers to the fixups
  577. * in case we need to move ourselves again.
  578. */
  579. li r0,__fixup_entries@sectoff@l
  580. lwz r3,GOT(_FIXUP_TABLE_)
  581. cmpwi r0,0
  582. mtctr r0
  583. addi r3,r3,-4
  584. beq 4f
  585. 3: lwzu r4,4(r3)
  586. lwzux r0,r4,r11
  587. cmpwi r0,0
  588. add r0,r0,r11
  589. stw r4,0(r3)
  590. beq- 5f
  591. stw r0,0(r4)
  592. 5: bdnz 3b
  593. 4:
  594. clear_bss:
  595. /*
  596. * Now clear BSS segment
  597. */
  598. lwz r3,GOT(__bss_start)
  599. lwz r4,GOT(__bss_end)
  600. cmplw 0, r3, r4
  601. beq 6f
  602. li r0, 0
  603. 5:
  604. stw r0, 0(r3)
  605. addi r3, r3, 4
  606. cmplw 0, r3, r4
  607. bne 5b
  608. 6:
  609. mr r3, r9 /* Global Data pointer */
  610. mr r4, r10 /* Destination Address */
  611. bl board_init_r
  612. /*
  613. * Copy exception vector code to low memory
  614. *
  615. * r3: dest_addr
  616. * r7: source address, r8: end address, r9: target address
  617. */
  618. .globl trap_init
  619. trap_init:
  620. mflr r4 /* save link register */
  621. GET_GOT
  622. lwz r7, GOT(_start)
  623. lwz r8, GOT(_end_of_vectors)
  624. li r9, 0x100 /* reset vector always at 0x100 */
  625. cmplw 0, r7, r8
  626. bgelr /* return if r7>=r8 - just in case */
  627. 1:
  628. lwz r0, 0(r7)
  629. stw r0, 0(r9)
  630. addi r7, r7, 4
  631. addi r9, r9, 4
  632. cmplw 0, r7, r8
  633. bne 1b
  634. /*
  635. * relocate `hdlr' and `int_return' entries
  636. */
  637. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  638. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  639. 2:
  640. bl trap_reloc
  641. addi r7, r7, 0x100 /* next exception vector */
  642. cmplw 0, r7, r8
  643. blt 2b
  644. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  645. bl trap_reloc
  646. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  647. bl trap_reloc
  648. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  649. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  650. 3:
  651. bl trap_reloc
  652. addi r7, r7, 0x100 /* next exception vector */
  653. cmplw 0, r7, r8
  654. blt 3b
  655. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  656. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  657. 4:
  658. bl trap_reloc
  659. addi r7, r7, 0x100 /* next exception vector */
  660. cmplw 0, r7, r8
  661. blt 4b
  662. mfmsr r3 /* now that the vectors have */
  663. lis r7, MSR_IP@h /* relocated into low memory */
  664. ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
  665. andc r3, r3, r7 /* (if it was on) */
  666. SYNC /* Some chip revs need this... */
  667. mtmsr r3
  668. SYNC
  669. mtlr r4 /* restore link register */
  670. blr
  671. #endif /* CONFIG_SPL_BUILD */