start.S 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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-2009 Wolfgang Denk <wd@denx.de>
  5. * Copyright Freescale Semiconductor, Inc. 2004, 2006.
  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. * Based on the MPC83xx code.
  26. */
  27. /*
  28. * U-Boot - Startup Code for MPC512x based Embedded Boards
  29. */
  30. #include <asm-offsets.h>
  31. #include <config.h>
  32. #ifndef CONFIG_IDENT_STRING
  33. #define CONFIG_IDENT_STRING "MPC512X"
  34. #endif
  35. #include <version.h>
  36. #define CONFIG_521X 1 /* needed for Linux kernel header files*/
  37. #include <asm/immap_512x.h>
  38. #include "asm-offsets.h"
  39. #include <ppc_asm.tmpl>
  40. #include <ppc_defs.h>
  41. #include <asm/cache.h>
  42. #include <asm/mmu.h>
  43. #include <asm/u-boot.h>
  44. /*
  45. * Floating Point enable, Machine Check and Recoverable Interr.
  46. */
  47. #undef MSR_KERNEL
  48. #ifdef DEBUG
  49. #define MSR_KERNEL (MSR_FP|MSR_RI)
  50. #else
  51. #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
  52. #endif
  53. /* Macros for manipulating CSx_START/STOP */
  54. #define START_REG(start) ((start) >> 16)
  55. #define STOP_REG(start, size) (((start) + (size) - 1) >> 16)
  56. /*
  57. * Set up GOT: Global Offset Table
  58. *
  59. * Use r12 to access the GOT
  60. */
  61. START_GOT
  62. GOT_ENTRY(_GOT2_TABLE_)
  63. GOT_ENTRY(_FIXUP_TABLE_)
  64. GOT_ENTRY(_start)
  65. GOT_ENTRY(_start_of_vectors)
  66. GOT_ENTRY(_end_of_vectors)
  67. GOT_ENTRY(transfer_to_handler)
  68. GOT_ENTRY(__init_end)
  69. GOT_ENTRY(__bss_end__)
  70. GOT_ENTRY(__bss_start)
  71. END_GOT
  72. /*
  73. * Magic number and version string
  74. */
  75. .long 0x27051956 /* U-Boot Magic Number */
  76. .globl version_string
  77. version_string:
  78. .ascii U_BOOT_VERSION_STRING, "\0"
  79. /*
  80. * Vector Table
  81. */
  82. .text
  83. . = EXC_OFF_SYS_RESET
  84. .globl _start
  85. /* Start from here after reset/power on */
  86. _start:
  87. b boot_cold
  88. .globl _start_of_vectors
  89. _start_of_vectors:
  90. /* Machine check */
  91. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  92. /* Data Storage exception. */
  93. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  94. /* Instruction Storage exception. */
  95. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  96. /* External Interrupt exception. */
  97. STD_EXCEPTION(0x500, ExtInterrupt, UnknownException)
  98. /* Alignment exception. */
  99. . = 0x600
  100. Alignment:
  101. EXCEPTION_PROLOG(SRR0, SRR1)
  102. mfspr r4,DAR
  103. stw r4,_DAR(r21)
  104. mfspr r5,DSISR
  105. stw r5,_DSISR(r21)
  106. addi r3,r1,STACK_FRAME_OVERHEAD
  107. EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
  108. /* Program check exception */
  109. . = 0x700
  110. ProgramCheck:
  111. EXCEPTION_PROLOG(SRR0, SRR1)
  112. addi r3,r1,STACK_FRAME_OVERHEAD
  113. EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
  114. MSR_KERNEL, COPY_EE)
  115. /* Floating Point Unit unavailable exception */
  116. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  117. /* Decrementer */
  118. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  119. /* Critical interrupt */
  120. STD_EXCEPTION(0xa00, Critical, UnknownException)
  121. /* System Call */
  122. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  123. /* Trace interrupt */
  124. STD_EXCEPTION(0xd00, Trace, UnknownException)
  125. /* Performance Monitor interrupt */
  126. STD_EXCEPTION(0xf00, PerfMon, UnknownException)
  127. /* Intruction Translation Miss */
  128. STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
  129. /* Data Load Translation Miss */
  130. STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
  131. /* Data Store Translation Miss */
  132. STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
  133. /* Instruction Address Breakpoint */
  134. STD_EXCEPTION(0x1300, InstructionAddrBreakpoint, DebugException)
  135. /* System Management interrupt */
  136. STD_EXCEPTION(0x1400, SystemMgmtInterrupt, UnknownException)
  137. .globl _end_of_vectors
  138. _end_of_vectors:
  139. . = 0x3000
  140. boot_cold:
  141. /* Save msr contents */
  142. mfmsr r5
  143. /* Set IMMR area to our preferred location */
  144. lis r4, CONFIG_DEFAULT_IMMR@h
  145. lis r3, CONFIG_SYS_IMMR@h
  146. ori r3, r3, CONFIG_SYS_IMMR@l
  147. stw r3, IMMRBAR(r4)
  148. mtspr MBAR, r3 /* IMMRBAR is mirrored into the MBAR SPR (311) */
  149. /* Initialise the machine */
  150. bl cpu_early_init
  151. /*
  152. * Set up Local Access Windows:
  153. *
  154. * 1) Boot/CS0 (boot FLASH)
  155. * 2) On-chip SRAM (initial stack purposes)
  156. */
  157. /* Boot CS/CS0 window range */
  158. lis r3, CONFIG_SYS_IMMR@h
  159. ori r3, r3, CONFIG_SYS_IMMR@l
  160. lis r4, START_REG(CONFIG_SYS_FLASH_BASE)
  161. ori r4, r4, STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE)
  162. stw r4, LPCS0AW(r3)
  163. /*
  164. * The SRAM window has a fixed size (256K), so only the start address
  165. * is necessary
  166. */
  167. lis r4, START_REG(CONFIG_SYS_SRAM_BASE) & 0xff00
  168. stw r4, SRAMBAR(r3)
  169. /*
  170. * According to MPC5121e RM, configuring local access windows should
  171. * be followed by a dummy read of the config register that was
  172. * modified last and an isync
  173. */
  174. lwz r4, SRAMBAR(r3)
  175. isync
  176. /*
  177. * Set configuration of the Boot/CS0, the SRAM window does not have a
  178. * config register so no params can be set for it
  179. */
  180. lis r3, (CONFIG_SYS_IMMR + LPC_OFFSET)@h
  181. ori r3, r3, (CONFIG_SYS_IMMR + LPC_OFFSET)@l
  182. lis r4, CONFIG_SYS_CS0_CFG@h
  183. ori r4, r4, CONFIG_SYS_CS0_CFG@l
  184. stw r4, CS0_CONFIG(r3)
  185. /* Master enable all CS's */
  186. lis r4, CS_CTRL_ME@h
  187. ori r4, r4, CS_CTRL_ME@l
  188. stw r4, CS_CTRL(r3)
  189. lis r4, (CONFIG_SYS_MONITOR_BASE)@h
  190. ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l
  191. addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
  192. mtlr r5
  193. blr
  194. in_flash:
  195. lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
  196. ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
  197. li r0, 0 /* Make room for stack frame header and */
  198. stwu r0, -4(r1) /* clear final stack frame so that */
  199. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  200. /* let the C-code set up the rest */
  201. /* */
  202. /* Be careful to keep code relocatable & stack humble */
  203. /*------------------------------------------------------*/
  204. GET_GOT /* initialize GOT access */
  205. /* r3: IMMR */
  206. lis r3, CONFIG_SYS_IMMR@h
  207. /* run low-level CPU init code (in Flash) */
  208. bl cpu_init_f
  209. /* run 1st part of board init code (in Flash) */
  210. bl board_init_f
  211. /* NOTREACHED - board_init_f() does not return */
  212. /*
  213. * This code finishes saving the registers to the exception frame
  214. * and jumps to the appropriate handler for the exception.
  215. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  216. */
  217. .globl transfer_to_handler
  218. transfer_to_handler:
  219. stw r22,_NIP(r21)
  220. lis r22,MSR_POW@h
  221. andc r23,r23,r22
  222. stw r23,_MSR(r21)
  223. SAVE_GPR(7, r21)
  224. SAVE_4GPRS(8, r21)
  225. SAVE_8GPRS(12, r21)
  226. SAVE_8GPRS(24, r21)
  227. mflr r23
  228. andi. r24,r23,0x3f00 /* get vector offset */
  229. stw r24,TRAP(r21)
  230. li r22,0
  231. stw r22,RESULT(r21)
  232. lwz r24,0(r23) /* virtual address of handler */
  233. lwz r23,4(r23) /* where to go when done */
  234. mtspr SRR0,r24
  235. mtspr SRR1,r20
  236. mtlr r23
  237. SYNC
  238. rfi /* jump to handler, enable MMU */
  239. int_return:
  240. mfmsr r28 /* Disable interrupts */
  241. li r4,0
  242. ori r4,r4,MSR_EE
  243. andc r28,r28,r4
  244. SYNC /* Some chip revs need this... */
  245. mtmsr r28
  246. SYNC
  247. lwz r2,_CTR(r1)
  248. lwz r0,_LINK(r1)
  249. mtctr r2
  250. mtlr r0
  251. lwz r2,_XER(r1)
  252. lwz r0,_CCR(r1)
  253. mtspr XER,r2
  254. mtcrf 0xFF,r0
  255. REST_10GPRS(3, r1)
  256. REST_10GPRS(13, r1)
  257. REST_8GPRS(23, r1)
  258. REST_GPR(31, r1)
  259. lwz r2,_NIP(r1) /* Restore environment */
  260. lwz r0,_MSR(r1)
  261. mtspr SRR0,r2
  262. mtspr SRR1,r0
  263. lwz r0,GPR0(r1)
  264. lwz r2,GPR2(r1)
  265. lwz r1,GPR1(r1)
  266. SYNC
  267. rfi
  268. /*
  269. * This code initialises the machine, it expects original MSR contents to be in r5.
  270. */
  271. cpu_early_init:
  272. /* Initialize machine status; enable machine check interrupt */
  273. /*-----------------------------------------------------------*/
  274. li r3, MSR_KERNEL /* Set ME and RI flags */
  275. rlwimi r3, r5, 0, 25, 25 /* preserve IP bit */
  276. #ifdef DEBUG
  277. rlwimi r3, r5, 0, 21, 22 /* debugger might set SE, BE bits */
  278. #endif
  279. mtmsr r3
  280. SYNC
  281. mtspr SRR1, r3 /* Mirror current MSR state in SRR1 */
  282. lis r3, CONFIG_SYS_IMMR@h
  283. #if defined(CONFIG_WATCHDOG)
  284. /* Initialise the watchdog and reset it */
  285. /*--------------------------------------*/
  286. lis r4, CONFIG_SYS_WATCHDOG_VALUE
  287. ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR)
  288. stw r4, SWCRR(r3)
  289. /* reset */
  290. li r4, 0x556C
  291. sth r4, SWSRR@l(r3)
  292. li r4, 0x0
  293. ori r4, r4, 0xAA39
  294. sth r4, SWSRR@l(r3)
  295. #else
  296. /* Disable the watchdog */
  297. /*----------------------*/
  298. lwz r4, SWCRR(r3)
  299. /*
  300. * Check to see if it's enabled for disabling: once disabled by s/w
  301. * it's not possible to re-enable it
  302. */
  303. andi. r4, r4, 0x4
  304. beq 1f
  305. xor r4, r4, r4
  306. stw r4, SWCRR(r3)
  307. 1:
  308. #endif /* CONFIG_WATCHDOG */
  309. /* Initialize the Hardware Implementation-dependent Registers */
  310. /* HID0 also contains cache control */
  311. /*------------------------------------------------------*/
  312. lis r3, CONFIG_SYS_HID0_INIT@h
  313. ori r3, r3, CONFIG_SYS_HID0_INIT@l
  314. SYNC
  315. mtspr HID0, r3
  316. lis r3, CONFIG_SYS_HID0_FINAL@h
  317. ori r3, r3, CONFIG_SYS_HID0_FINAL@l
  318. SYNC
  319. mtspr HID0, r3
  320. lis r3, CONFIG_SYS_HID2@h
  321. ori r3, r3, CONFIG_SYS_HID2@l
  322. SYNC
  323. mtspr HID2, r3
  324. sync
  325. blr
  326. /* Cache functions.
  327. *
  328. * Note: requires that all cache bits in
  329. * HID0 are in the low half word.
  330. */
  331. .globl icache_enable
  332. icache_enable:
  333. mfspr r3, HID0
  334. ori r3, r3, HID0_ICE
  335. lis r4, 0
  336. ori r4, r4, HID0_ILOCK
  337. andc r3, r3, r4
  338. ori r4, r3, HID0_ICFI
  339. isync
  340. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  341. isync
  342. mtspr HID0, r3 /* clears invalidate */
  343. blr
  344. .globl icache_disable
  345. icache_disable:
  346. mfspr r3, HID0
  347. lis r4, 0
  348. ori r4, r4, HID0_ICE|HID0_ILOCK
  349. andc r3, r3, r4
  350. ori r4, r3, HID0_ICFI
  351. isync
  352. mtspr HID0, r4 /* sets invalidate, clears enable and lock*/
  353. isync
  354. mtspr HID0, r3 /* clears invalidate */
  355. blr
  356. .globl icache_status
  357. icache_status:
  358. mfspr r3, HID0
  359. rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31
  360. blr
  361. .globl dcache_enable
  362. dcache_enable:
  363. mfspr r3, HID0
  364. li r5, HID0_DCFI|HID0_DLOCK
  365. andc r3, r3, r5
  366. mtspr HID0, r3 /* no invalidate, unlock */
  367. ori r3, r3, HID0_DCE
  368. ori r5, r3, HID0_DCFI
  369. mtspr HID0, r5 /* enable + invalidate */
  370. mtspr HID0, r3 /* enable */
  371. sync
  372. blr
  373. .globl dcache_disable
  374. dcache_disable:
  375. mfspr r3, HID0
  376. lis r4, 0
  377. ori r4, r4, HID0_DCE|HID0_DLOCK
  378. andc r3, r3, r4
  379. ori r4, r3, HID0_DCI
  380. sync
  381. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  382. sync
  383. mtspr HID0, r3 /* clears invalidate */
  384. blr
  385. .globl dcache_status
  386. dcache_status:
  387. mfspr r3, HID0
  388. rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31
  389. blr
  390. .globl get_pvr
  391. get_pvr:
  392. mfspr r3, PVR
  393. blr
  394. /*-------------------------------------------------------------------*/
  395. /*
  396. * void relocate_code (addr_sp, gd, addr_moni)
  397. *
  398. * This "function" does not return, instead it continues in RAM
  399. * after relocating the monitor code.
  400. *
  401. * r3 = dest
  402. * r4 = src
  403. * r5 = length in bytes
  404. * r6 = cachelinesize
  405. */
  406. .globl relocate_code
  407. relocate_code:
  408. mr r1, r3 /* Set new stack pointer */
  409. mr r9, r4 /* Save copy of Global Data pointer */
  410. mr r10, r5 /* Save copy of Destination Address */
  411. GET_GOT
  412. mr r3, r5 /* Destination Address */
  413. lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  414. ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
  415. lwz r5, GOT(__init_end)
  416. sub r5, r5, r4
  417. li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  418. /*
  419. * Fix GOT pointer:
  420. *
  421. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE)
  422. * + Destination Address
  423. *
  424. * Offset:
  425. */
  426. sub r15, r10, r4
  427. /* First our own GOT */
  428. add r12, r12, r15
  429. /* then the one used by the C code */
  430. add r30, r30, r15
  431. /*
  432. * Now relocate code
  433. */
  434. cmplw cr1,r3,r4
  435. addi r0,r5,3
  436. srwi. r0,r0,2
  437. beq cr1,4f /* In place copy is not necessary */
  438. beq 7f /* Protect against 0 count */
  439. mtctr r0
  440. bge cr1,2f
  441. la r8,-4(r4)
  442. la r7,-4(r3)
  443. /* copy */
  444. 1: lwzu r0,4(r8)
  445. stwu r0,4(r7)
  446. bdnz 1b
  447. addi r0,r5,3
  448. srwi. r0,r0,2
  449. mtctr r0
  450. la r8,-4(r4)
  451. la r7,-4(r3)
  452. /* and compare */
  453. 20: lwzu r20,4(r8)
  454. lwzu r21,4(r7)
  455. xor. r22, r20, r21
  456. bne 30f
  457. bdnz 20b
  458. b 4f
  459. /* compare failed */
  460. 30: li r3, 0
  461. blr
  462. 2: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
  463. add r8,r4,r0
  464. add r7,r3,r0
  465. 3: lwzu r0,-4(r8)
  466. stwu r0,-4(r7)
  467. bdnz 3b
  468. /*
  469. * Now flush the cache: note that we must start from a cache aligned
  470. * address. Otherwise we might miss one cache line.
  471. */
  472. 4: cmpwi r6,0
  473. add r5,r3,r5
  474. beq 7f /* Always flush prefetch queue in any case */
  475. subi r0,r6,1
  476. andc r3,r3,r0
  477. mr r4,r3
  478. 5: dcbst 0,r4
  479. add r4,r4,r6
  480. cmplw r4,r5
  481. blt 5b
  482. sync /* Wait for all dcbst to complete on bus */
  483. mr r4,r3
  484. 6: icbi 0,r4
  485. add r4,r4,r6
  486. cmplw r4,r5
  487. blt 6b
  488. 7: sync /* Wait for all icbi to complete on bus */
  489. isync
  490. /*
  491. * We are done. Do not return, instead branch to second part of board
  492. * initialization, now running from RAM.
  493. */
  494. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  495. mtlr r0
  496. blr
  497. in_ram:
  498. /*
  499. * Relocation Function, r12 point to got2+0x8000
  500. *
  501. * Adjust got2 pointers, no need to check for 0, this code
  502. * already puts a few entries in the table.
  503. */
  504. li r0,__got2_entries@sectoff@l
  505. la r3,GOT(_GOT2_TABLE_)
  506. lwz r11,GOT(_GOT2_TABLE_)
  507. mtctr r0
  508. sub r11,r3,r11
  509. addi r3,r3,-4
  510. 1: lwzu r0,4(r3)
  511. cmpwi r0,0
  512. beq- 2f
  513. add r0,r0,r11
  514. stw r0,0(r3)
  515. 2: bdnz 1b
  516. /*
  517. * Now adjust the fixups and the pointers to the fixups
  518. * in case we need to move ourselves again.
  519. */
  520. li r0,__fixup_entries@sectoff@l
  521. lwz r3,GOT(_FIXUP_TABLE_)
  522. cmpwi r0,0
  523. mtctr r0
  524. addi r3,r3,-4
  525. beq 4f
  526. 3: lwzu r4,4(r3)
  527. lwzux r0,r4,r11
  528. cmpwi r0,0
  529. add r0,r0,r11
  530. stw r4,0(r3)
  531. beq- 5f
  532. stw r0,0(r4)
  533. 5: bdnz 3b
  534. 4:
  535. clear_bss:
  536. /*
  537. * Now clear BSS segment
  538. */
  539. lwz r3,GOT(__bss_start)
  540. lwz r4,GOT(__bss_end__)
  541. cmplw 0, r3, r4
  542. beq 6f
  543. li r0, 0
  544. 5:
  545. stw r0, 0(r3)
  546. addi r3, r3, 4
  547. cmplw 0, r3, r4
  548. bne 5b
  549. 6:
  550. mr r3, r9 /* Global Data pointer */
  551. mr r4, r10 /* Destination Address */
  552. bl board_init_r
  553. /*
  554. * Copy exception vector code to low memory
  555. *
  556. * r3: dest_addr
  557. * r7: source address, r8: end address, r9: target address
  558. */
  559. .globl trap_init
  560. trap_init:
  561. mflr r4 /* save link register */
  562. GET_GOT
  563. lwz r7, GOT(_start)
  564. lwz r8, GOT(_end_of_vectors)
  565. li r9, 0x100 /* reset vector at 0x100 */
  566. cmplw 0, r7, r8
  567. bgelr /* return if r7>=r8 - just in case */
  568. 1:
  569. lwz r0, 0(r7)
  570. stw r0, 0(r9)
  571. addi r7, r7, 4
  572. addi r9, r9, 4
  573. cmplw 0, r7, r8
  574. bne 1b
  575. /*
  576. * relocate `hdlr' and `int_return' entries
  577. */
  578. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  579. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  580. 2:
  581. bl trap_reloc
  582. addi r7, r7, 0x100 /* next exception vector */
  583. cmplw 0, r7, r8
  584. blt 2b
  585. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  586. bl trap_reloc
  587. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  588. bl trap_reloc
  589. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  590. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  591. 3:
  592. bl trap_reloc
  593. addi r7, r7, 0x100 /* next exception vector */
  594. cmplw 0, r7, r8
  595. blt 3b
  596. li r7, .L_Trace - _start + EXC_OFF_SYS_RESET
  597. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  598. 4:
  599. bl trap_reloc
  600. addi r7, r7, 0x100 /* next exception vector */
  601. cmplw 0, r7, r8
  602. blt 4b
  603. mfmsr r3 /* now that the vectors have */
  604. lis r7, MSR_IP@h /* relocated into low memory */
  605. ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
  606. andc r3, r3, r7 /* (if it was on) */
  607. SYNC /* Some chip revs need this... */
  608. mtmsr r3
  609. SYNC
  610. mtlr r4 /* restore link register */
  611. blr