start.S 15 KB

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