start.S 19 KB

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