start.S 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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,2001,2002 Wolfgang Denk <wd@denx.de>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. /* U-Boot - Startup Code for PowerPC based Embedded Boards
  25. *
  26. *
  27. * The processor starts at 0x00000100 and the code is executed
  28. * from flash. The code is organized to be at an other address
  29. * in memory, but as long we don't jump around before relocating.
  30. * board_init lies at a quite high address and when the cpu has
  31. * jumped there, everything is ok.
  32. * This works because the cpu gives the FLASH (CS0) the whole
  33. * address space at startup, and board_init lies as a echo of
  34. * the flash somewhere up there in the memorymap.
  35. *
  36. * board_init will change CS0 to be positioned at the correct
  37. * address and (s)dram will be positioned at address 0
  38. */
  39. #include <config.h>
  40. #include <mpc8xx.h>
  41. #include <version.h>
  42. #define CONFIG_8xx 1 /* needed for Linux kernel header files */
  43. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  44. #include <ppc_asm.tmpl>
  45. #include <ppc_defs.h>
  46. #include <asm/cache.h>
  47. #include <asm/mmu.h>
  48. #ifndef CONFIG_IDENT_STRING
  49. #define CONFIG_IDENT_STRING ""
  50. #endif
  51. /* We don't want the MMU yet.
  52. */
  53. #undef MSR_KERNEL
  54. #define MSR_KERNEL ( MSR_ME | MSR_RI ) /* Machine Check and Recoverable Interr. */
  55. /*
  56. * Set up GOT: Global Offset Table
  57. *
  58. * Use r14 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. #if defined(CONFIG_FADS) || defined(CONFIG_ICU862)
  71. GOT_ENTRY(environment)
  72. #endif
  73. END_GOT
  74. /*
  75. * r3 - 1st arg to board_init(): IMMP pointer
  76. * r4 - 2nd arg to board_init(): boot flag
  77. */
  78. .text
  79. .long 0x27051956 /* U-Boot Magic Number */
  80. .globl version_string
  81. version_string:
  82. .ascii U_BOOT_VERSION
  83. .ascii " (", __DATE__, " - ", __TIME__, ")"
  84. .ascii CONFIG_IDENT_STRING, "\0"
  85. . = EXC_OFF_SYS_RESET
  86. .globl _start
  87. _start:
  88. lis r3, CFG_IMMR@h /* position IMMR */
  89. mtspr 638, r3
  90. li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
  91. b boot_cold
  92. . = EXC_OFF_SYS_RESET + 0x10
  93. .globl _start_warm
  94. _start_warm:
  95. li r21, BOOTFLAG_WARM /* Software reboot */
  96. b boot_warm
  97. boot_cold:
  98. boot_warm:
  99. /* Initialize machine status; enable machine check interrupt */
  100. /*----------------------------------------------------------------------*/
  101. li r3, MSR_KERNEL /* Set ME, RI flags */
  102. mtmsr r3
  103. mtspr SRR1, r3 /* Make SRR1 match MSR */
  104. mfspr r3, ICR /* clear Interrupt Cause Register */
  105. /* Initialize debug port registers */
  106. /*----------------------------------------------------------------------*/
  107. xor r0, r0, r0 /* Clear R0 */
  108. mtspr LCTRL1, r0 /* Initialize debug port regs */
  109. mtspr LCTRL2, r0
  110. mtspr COUNTA, r0
  111. mtspr COUNTB, r0
  112. /* Reset the caches */
  113. /*----------------------------------------------------------------------*/
  114. mfspr r3, IC_CST /* Clear error bits */
  115. mfspr r3, DC_CST
  116. lis r3, IDC_UNALL@h /* Unlock all */
  117. mtspr IC_CST, r3
  118. mtspr DC_CST, r3
  119. lis r3, IDC_INVALL@h /* Invalidate all */
  120. mtspr IC_CST, r3
  121. mtspr DC_CST, r3
  122. lis r3, IDC_DISABLE@h /* Disable data cache */
  123. mtspr DC_CST, r3
  124. #if !(defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || defined (CONFIG_FLAGADM))
  125. /* On IP860 and PCU E,
  126. * we cannot enable IC yet
  127. */
  128. lis r3, IDC_ENABLE@h /* Enable instruction cache */
  129. #endif
  130. mtspr IC_CST, r3
  131. /* invalidate all tlb's */
  132. /*----------------------------------------------------------------------*/
  133. tlbia
  134. isync
  135. /*
  136. * Calculate absolute address in FLASH and jump there
  137. *----------------------------------------------------------------------*/
  138. lis r3, CFG_MONITOR_BASE@h
  139. ori r3, r3, CFG_MONITOR_BASE@l
  140. addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
  141. mtlr r3
  142. blr
  143. in_flash:
  144. /* initialize some SPRs that are hard to access from C */
  145. /*----------------------------------------------------------------------*/
  146. lis r3, CFG_IMMR@h /* pass IMMR as arg1 to C routine */
  147. ori r1, r3, CFG_INIT_SP_OFFSET /* set up the stack in internal DPRAM */
  148. /* Note: R0 is still 0 here */
  149. stwu r0, -4(r1) /* clear final stack frame so that */
  150. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  151. /*
  152. * Disable serialized ifetch and show cycles
  153. * (i.e. set processor to normal mode).
  154. * This is also a silicon bug workaround, see errata
  155. */
  156. li r2, 0x0007
  157. mtspr ICTRL, r2
  158. /* Set up debug mode entry */
  159. lis r2, CFG_DER@h
  160. ori r2, r2, CFG_DER@l
  161. mtspr DER, r2
  162. /* let the C-code set up the rest */
  163. /* */
  164. /* Be careful to keep code relocatable ! */
  165. /*----------------------------------------------------------------------*/
  166. GET_GOT /* initialize GOT access */
  167. /* r3: IMMR */
  168. bl cpu_init_f /* run low-level CPU init code (from Flash) */
  169. mr r3, r21
  170. /* r3: BOOTFLAG */
  171. bl board_init_f /* run 1st part of board init code (from Flash) */
  172. .globl _start_of_vectors
  173. _start_of_vectors:
  174. /* Machine check */
  175. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  176. /* Data Storage exception. "Never" generated on the 860. */
  177. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  178. /* Instruction Storage exception. "Never" generated on the 860. */
  179. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  180. /* External Interrupt exception. */
  181. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  182. /* Alignment exception. */
  183. . = 0x600
  184. Alignment:
  185. EXCEPTION_PROLOG
  186. mfspr r4,DAR
  187. stw r4,_DAR(r21)
  188. mfspr r5,DSISR
  189. stw r5,_DSISR(r21)
  190. addi r3,r1,STACK_FRAME_OVERHEAD
  191. li r20,MSR_KERNEL
  192. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  193. lwz r6,GOT(transfer_to_handler)
  194. mtlr r6
  195. blrl
  196. .L_Alignment:
  197. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  198. .long int_return - _start + EXC_OFF_SYS_RESET
  199. /* Program check exception */
  200. . = 0x700
  201. ProgramCheck:
  202. EXCEPTION_PROLOG
  203. addi r3,r1,STACK_FRAME_OVERHEAD
  204. li r20,MSR_KERNEL
  205. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  206. lwz r6,GOT(transfer_to_handler)
  207. mtlr r6
  208. blrl
  209. .L_ProgramCheck:
  210. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  211. .long int_return - _start + EXC_OFF_SYS_RESET
  212. /* No FPU on MPC8xx. This exception is not supposed to happen.
  213. */
  214. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  215. /* I guess we could implement decrementer, and may have
  216. * to someday for timekeeping.
  217. */
  218. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  219. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  220. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  221. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  222. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  223. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  224. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  225. /* On the MPC8xx, this is a software emulation interrupt. It occurs
  226. * for all unimplemented and illegal instructions.
  227. */
  228. STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
  229. STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
  230. STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
  231. STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
  232. STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
  233. STD_EXCEPTION(0x1500, Reserved5, UnknownException)
  234. STD_EXCEPTION(0x1600, Reserved6, UnknownException)
  235. STD_EXCEPTION(0x1700, Reserved7, UnknownException)
  236. STD_EXCEPTION(0x1800, Reserved8, UnknownException)
  237. STD_EXCEPTION(0x1900, Reserved9, UnknownException)
  238. STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
  239. STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
  240. STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
  241. STD_EXCEPTION(0x1d00, InstructionBreakpoint, DebugException)
  242. STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
  243. STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
  244. .globl _end_of_vectors
  245. _end_of_vectors:
  246. . = 0x2000
  247. /*
  248. * This code finishes saving the registers to the exception frame
  249. * and jumps to the appropriate handler for the exception.
  250. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  251. */
  252. .globl transfer_to_handler
  253. transfer_to_handler:
  254. stw r22,_NIP(r21)
  255. lis r22,MSR_POW@h
  256. andc r23,r23,r22
  257. stw r23,_MSR(r21)
  258. SAVE_GPR(7, r21)
  259. SAVE_4GPRS(8, r21)
  260. SAVE_8GPRS(12, r21)
  261. SAVE_8GPRS(24, r21)
  262. mflr r23
  263. andi. r24,r23,0x3f00 /* get vector offset */
  264. stw r24,TRAP(r21)
  265. li r22,0
  266. stw r22,RESULT(r21)
  267. mtspr SPRG2,r22 /* r1 is now kernel sp */
  268. lwz r24,0(r23) /* virtual address of handler */
  269. lwz r23,4(r23) /* where to go when done */
  270. mtspr SRR0,r24
  271. mtspr SRR1,r20
  272. mtlr r23
  273. SYNC
  274. rfi /* jump to handler, enable MMU */
  275. int_return:
  276. mfmsr r28 /* Disable interrupts */
  277. li r4,0
  278. ori r4,r4,MSR_EE
  279. andc r28,r28,r4
  280. SYNC /* Some chip revs need this... */
  281. mtmsr r28
  282. SYNC
  283. lwz r2,_CTR(r1)
  284. lwz r0,_LINK(r1)
  285. mtctr r2
  286. mtlr r0
  287. lwz r2,_XER(r1)
  288. lwz r0,_CCR(r1)
  289. mtspr XER,r2
  290. mtcrf 0xFF,r0
  291. REST_10GPRS(3, r1)
  292. REST_10GPRS(13, r1)
  293. REST_8GPRS(23, r1)
  294. REST_GPR(31, r1)
  295. lwz r2,_NIP(r1) /* Restore environment */
  296. lwz r0,_MSR(r1)
  297. mtspr SRR0,r2
  298. mtspr SRR1,r0
  299. lwz r0,GPR0(r1)
  300. lwz r2,GPR2(r1)
  301. lwz r1,GPR1(r1)
  302. SYNC
  303. rfi
  304. /* Cache functions.
  305. */
  306. .globl icache_enable
  307. icache_enable:
  308. SYNC
  309. lis r3, IDC_INVALL@h
  310. mtspr IC_CST, r3
  311. lis r3, IDC_ENABLE@h
  312. mtspr IC_CST, r3
  313. blr
  314. .globl icache_disable
  315. icache_disable:
  316. SYNC
  317. lis r3, IDC_DISABLE@h
  318. mtspr IC_CST, r3
  319. blr
  320. .globl icache_status
  321. icache_status:
  322. mfspr r3, IC_CST
  323. srwi r3, r3, 31 /* >>31 => select bit 0 */
  324. blr
  325. .globl dcache_enable
  326. dcache_enable:
  327. #if 0
  328. SYNC
  329. #endif
  330. #if 1
  331. lis r3, 0x0400 /* Set cache mode with MMU off */
  332. mtspr MD_CTR, r3
  333. #endif
  334. lis r3, IDC_INVALL@h
  335. mtspr DC_CST, r3
  336. #if 0
  337. lis r3, DC_SFWT@h
  338. mtspr DC_CST, r3
  339. #endif
  340. lis r3, IDC_ENABLE@h
  341. mtspr DC_CST, r3
  342. blr
  343. .globl dcache_disable
  344. dcache_disable:
  345. SYNC
  346. lis r3, IDC_DISABLE@h
  347. mtspr DC_CST, r3
  348. lis r3, IDC_INVALL@h
  349. mtspr DC_CST, r3
  350. blr
  351. .globl dcache_status
  352. dcache_status:
  353. mfspr r3, DC_CST
  354. srwi r3, r3, 31 /* >>31 => select bit 0 */
  355. blr
  356. .globl dc_read
  357. dc_read:
  358. mtspr DC_ADR, r3
  359. mfspr r3, DC_DAT
  360. blr
  361. /*
  362. * unsigned int get_immr (unsigned int mask)
  363. *
  364. * return (mask ? (IMMR & mask) : IMMR);
  365. */
  366. .globl get_immr
  367. get_immr:
  368. mr r4,r3 /* save mask */
  369. mfspr r3, IMMR /* IMMR */
  370. cmpwi 0,r4,0 /* mask != 0 ? */
  371. beq 4f
  372. and r3,r3,r4 /* IMMR & mask */
  373. 4:
  374. blr
  375. .globl get_pvr
  376. get_pvr:
  377. mfspr r3, PVR
  378. blr
  379. .globl wr_ic_cst
  380. wr_ic_cst:
  381. mtspr IC_CST, r3
  382. blr
  383. .globl rd_ic_cst
  384. rd_ic_cst:
  385. mfspr r3, IC_CST
  386. blr
  387. .globl wr_ic_adr
  388. wr_ic_adr:
  389. mtspr IC_ADR, r3
  390. blr
  391. .globl wr_dc_cst
  392. wr_dc_cst:
  393. mtspr DC_CST, r3
  394. blr
  395. .globl rd_dc_cst
  396. rd_dc_cst:
  397. mfspr r3, DC_CST
  398. blr
  399. .globl wr_dc_adr
  400. wr_dc_adr:
  401. mtspr DC_ADR, r3
  402. blr
  403. /*------------------------------------------------------------------------------*/
  404. /*
  405. * void relocate_code (addr_sp, gd, addr_moni)
  406. *
  407. * This "function" does not return, instead it continues in RAM
  408. * after relocating the monitor code.
  409. *
  410. * r3 = dest
  411. * r4 = src
  412. * r5 = length in bytes
  413. * r6 = cachelinesize
  414. */
  415. .globl relocate_code
  416. relocate_code:
  417. mr r1, r3 /* Set new stack pointer */
  418. mr r9, r4 /* Save copy of Global Data pointer */
  419. mr r10, r5 /* Save copy of Destination Address */
  420. mr r3, r5 /* Destination Address */
  421. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  422. ori r4, r4, CFG_MONITOR_BASE@l
  423. lwz r5, GOT(__init_end)
  424. sub r5, r5, r4
  425. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  426. /*
  427. * Fix GOT pointer:
  428. *
  429. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
  430. *
  431. * Offset:
  432. */
  433. sub r15, r10, r4
  434. /* First our own GOT */
  435. add r14, r14, r15
  436. /* then the one used by the C code */
  437. add r30, r30, r15
  438. /*
  439. * Now relocate code
  440. */
  441. cmplw cr1,r3,r4
  442. addi r0,r5,3
  443. srwi. r0,r0,2
  444. beq cr1,4f /* In place copy is not necessary */
  445. beq 7f /* Protect against 0 count */
  446. mtctr r0
  447. bge cr1,2f
  448. la r8,-4(r4)
  449. la r7,-4(r3)
  450. 1: lwzu r0,4(r8)
  451. stwu r0,4(r7)
  452. bdnz 1b
  453. b 4f
  454. 2: slwi r0,r0,2
  455. add r8,r4,r0
  456. add r7,r3,r0
  457. 3: lwzu r0,-4(r8)
  458. stwu r0,-4(r7)
  459. bdnz 3b
  460. /*
  461. * Now flush the cache: note that we must start from a cache aligned
  462. * address. Otherwise we might miss one cache line.
  463. */
  464. 4: cmpwi r6,0
  465. add r5,r3,r5
  466. beq 7f /* Always flush prefetch queue in any case */
  467. subi r0,r6,1
  468. andc r3,r3,r0
  469. mr r4,r3
  470. 5: dcbst 0,r4
  471. add r4,r4,r6
  472. cmplw r4,r5
  473. blt 5b
  474. sync /* Wait for all dcbst to complete on bus */
  475. mr r4,r3
  476. 6: icbi 0,r4
  477. add r4,r4,r6
  478. cmplw r4,r5
  479. blt 6b
  480. 7: sync /* Wait for all icbi to complete on bus */
  481. isync
  482. /*
  483. * We are done. Do not return, instead branch to second part of board
  484. * initialization, now running from RAM.
  485. */
  486. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  487. mtlr r0
  488. blr
  489. in_ram:
  490. /*
  491. * Relocation Function, r14 point to got2+0x8000
  492. *
  493. * Adjust got2 pointers, no need to check for 0, this code
  494. * already puts a few entries in the table.
  495. */
  496. li r0,__got2_entries@sectoff@l
  497. la r3,GOT(_GOT2_TABLE_)
  498. lwz r11,GOT(_GOT2_TABLE_)
  499. mtctr r0
  500. sub r11,r3,r11
  501. addi r3,r3,-4
  502. 1: lwzu r0,4(r3)
  503. add r0,r0,r11
  504. stw r0,0(r3)
  505. bdnz 1b
  506. /*
  507. * Now adjust the fixups and the pointers to the fixups
  508. * in case we need to move ourselves again.
  509. */
  510. 2: li r0,__fixup_entries@sectoff@l
  511. lwz r3,GOT(_FIXUP_TABLE_)
  512. cmpwi r0,0
  513. mtctr r0
  514. addi r3,r3,-4
  515. beq 4f
  516. 3: lwzu r4,4(r3)
  517. lwzux r0,r4,r11
  518. add r0,r0,r11
  519. stw r10,0(r3)
  520. stw r0,0(r4)
  521. bdnz 3b
  522. 4:
  523. clear_bss:
  524. /*
  525. * Now clear BSS segment
  526. */
  527. lwz r3,GOT(__bss_start)
  528. #if defined(CONFIG_FADS) || defined(CONFIG_ICU862)
  529. /*
  530. * For the FADS - the environment is the very last item in flash.
  531. * The real .bss stops just before environment starts, so only
  532. * clear up to that point.
  533. */
  534. lwz r4,GOT(environment)
  535. #else
  536. lwz r4,GOT(_end)
  537. #endif
  538. cmplw 0, r3, r4
  539. beq 6f
  540. li r0, 0
  541. 5:
  542. stw r0, 0(r3)
  543. addi r3, r3, 4
  544. cmplw 0, r3, r4
  545. bne 5b
  546. 6:
  547. mr r3, r9 /* Global Data pointer */
  548. mr r4, r10 /* Destination Address */
  549. bl board_init_r
  550. /*
  551. * Copy exception vector code to low memory
  552. *
  553. * r3: dest_addr
  554. * r7: source address, r8: end address, r9: target address
  555. */
  556. .globl trap_init
  557. trap_init:
  558. lwz r7, GOT(_start)
  559. lwz r8, GOT(_end_of_vectors)
  560. li r9, 0x100 /* reset vector always at 0x100 */
  561. cmplw 0, r7, r8
  562. bgelr /* return if r7>=r8 - just in case */
  563. mflr r4 /* save link register */
  564. 1:
  565. lwz r0, 0(r7)
  566. stw r0, 0(r9)
  567. addi r7, r7, 4
  568. addi r9, r9, 4
  569. cmplw 0, r7, r8
  570. bne 1b
  571. /*
  572. * relocate `hdlr' and `int_return' entries
  573. */
  574. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  575. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  576. 2:
  577. bl trap_reloc
  578. addi r7, r7, 0x100 /* next exception vector */
  579. cmplw 0, r7, r8
  580. blt 2b
  581. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  582. bl trap_reloc
  583. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  584. bl trap_reloc
  585. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  586. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  587. 3:
  588. bl trap_reloc
  589. addi r7, r7, 0x100 /* next exception vector */
  590. cmplw 0, r7, r8
  591. blt 3b
  592. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  593. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  594. 4:
  595. bl trap_reloc
  596. addi r7, r7, 0x100 /* next exception vector */
  597. cmplw 0, r7, r8
  598. blt 4b
  599. mtlr r4 /* restore link register */
  600. blr
  601. /*
  602. * Function: relocate entries for one exception vector
  603. */
  604. trap_reloc:
  605. lwz r0, 0(r7) /* hdlr ... */
  606. add r0, r0, r3 /* ... += dest_addr */
  607. stw r0, 0(r7)
  608. lwz r0, 4(r7) /* int_return ... */
  609. add r0, r0, r3 /* ... += dest_addr */
  610. stw r0, 4(r7)
  611. sync
  612. isync
  613. blr