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