start.S 15 KB

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