start.S 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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. #if defined(__pic__) && __pic__ == 1
  209. /* Needed for upcoming -msingle-pic-base */
  210. bl _GLOBAL_OFFSET_TABLE_@local-4
  211. mflr r30
  212. #endif
  213. /* r3: IMMR */
  214. lis r3, CONFIG_SYS_IMMR@h
  215. /* run low-level CPU init code (in Flash) */
  216. bl cpu_init_f
  217. /* run 1st part of board init code (in Flash) */
  218. bl board_init_f
  219. /* NOTREACHED - board_init_f() does not return */
  220. /*
  221. * This code finishes saving the registers to the exception frame
  222. * and jumps to the appropriate handler for the exception.
  223. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  224. */
  225. .globl transfer_to_handler
  226. transfer_to_handler:
  227. stw r22,_NIP(r21)
  228. lis r22,MSR_POW@h
  229. andc r23,r23,r22
  230. stw r23,_MSR(r21)
  231. SAVE_GPR(7, r21)
  232. SAVE_4GPRS(8, r21)
  233. SAVE_8GPRS(12, r21)
  234. SAVE_8GPRS(24, r21)
  235. mflr r23
  236. andi. r24,r23,0x3f00 /* get vector offset */
  237. stw r24,TRAP(r21)
  238. li r22,0
  239. stw r22,RESULT(r21)
  240. lwz r24,0(r23) /* virtual address of handler */
  241. lwz r23,4(r23) /* where to go when done */
  242. mtspr SRR0,r24
  243. mtspr SRR1,r20
  244. mtlr r23
  245. SYNC
  246. rfi /* jump to handler, enable MMU */
  247. int_return:
  248. mfmsr r28 /* Disable interrupts */
  249. li r4,0
  250. ori r4,r4,MSR_EE
  251. andc r28,r28,r4
  252. SYNC /* Some chip revs need this... */
  253. mtmsr r28
  254. SYNC
  255. lwz r2,_CTR(r1)
  256. lwz r0,_LINK(r1)
  257. mtctr r2
  258. mtlr r0
  259. lwz r2,_XER(r1)
  260. lwz r0,_CCR(r1)
  261. mtspr XER,r2
  262. mtcrf 0xFF,r0
  263. REST_10GPRS(3, r1)
  264. REST_10GPRS(13, r1)
  265. REST_8GPRS(23, r1)
  266. REST_GPR(31, r1)
  267. lwz r2,_NIP(r1) /* Restore environment */
  268. lwz r0,_MSR(r1)
  269. mtspr SRR0,r2
  270. mtspr SRR1,r0
  271. lwz r0,GPR0(r1)
  272. lwz r2,GPR2(r1)
  273. lwz r1,GPR1(r1)
  274. SYNC
  275. rfi
  276. /*
  277. * This code initialises the machine, it expects original MSR contents to be in r5.
  278. */
  279. cpu_early_init:
  280. /* Initialize machine status; enable machine check interrupt */
  281. /*-----------------------------------------------------------*/
  282. li r3, MSR_KERNEL /* Set ME and RI flags */
  283. rlwimi r3, r5, 0, 25, 25 /* preserve IP bit */
  284. #ifdef DEBUG
  285. rlwimi r3, r5, 0, 21, 22 /* debugger might set SE, BE bits */
  286. #endif
  287. mtmsr r3
  288. SYNC
  289. mtspr SRR1, r3 /* Mirror current MSR state in SRR1 */
  290. lis r3, CONFIG_SYS_IMMR@h
  291. #if defined(CONFIG_WATCHDOG)
  292. /* Initialise the watchdog and reset it */
  293. /*--------------------------------------*/
  294. lis r4, CONFIG_SYS_WATCHDOG_VALUE
  295. ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR)
  296. stw r4, SWCRR(r3)
  297. /* reset */
  298. li r4, 0x556C
  299. sth r4, SWSRR@l(r3)
  300. li r4, 0x0
  301. ori r4, r4, 0xAA39
  302. sth r4, SWSRR@l(r3)
  303. #else
  304. /* Disable the watchdog */
  305. /*----------------------*/
  306. lwz r4, SWCRR(r3)
  307. /*
  308. * Check to see if it's enabled for disabling: once disabled by s/w
  309. * it's not possible to re-enable it
  310. */
  311. andi. r4, r4, 0x4
  312. beq 1f
  313. xor r4, r4, r4
  314. stw r4, SWCRR(r3)
  315. 1:
  316. #endif /* CONFIG_WATCHDOG */
  317. /* Initialize the Hardware Implementation-dependent Registers */
  318. /* HID0 also contains cache control */
  319. /*------------------------------------------------------*/
  320. lis r3, CONFIG_SYS_HID0_INIT@h
  321. ori r3, r3, CONFIG_SYS_HID0_INIT@l
  322. SYNC
  323. mtspr HID0, r3
  324. lis r3, CONFIG_SYS_HID0_FINAL@h
  325. ori r3, r3, CONFIG_SYS_HID0_FINAL@l
  326. SYNC
  327. mtspr HID0, r3
  328. lis r3, CONFIG_SYS_HID2@h
  329. ori r3, r3, CONFIG_SYS_HID2@l
  330. SYNC
  331. mtspr HID2, r3
  332. sync
  333. blr
  334. /* Cache functions.
  335. *
  336. * Note: requires that all cache bits in
  337. * HID0 are in the low half word.
  338. */
  339. .globl icache_enable
  340. icache_enable:
  341. mfspr r3, HID0
  342. ori r3, r3, HID0_ICE
  343. lis r4, 0
  344. ori r4, r4, HID0_ILOCK
  345. andc r3, r3, r4
  346. ori r4, r3, HID0_ICFI
  347. isync
  348. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  349. isync
  350. mtspr HID0, r3 /* clears invalidate */
  351. blr
  352. .globl icache_disable
  353. icache_disable:
  354. mfspr r3, HID0
  355. lis r4, 0
  356. ori r4, r4, HID0_ICE|HID0_ILOCK
  357. andc r3, r3, r4
  358. ori r4, r3, HID0_ICFI
  359. isync
  360. mtspr HID0, r4 /* sets invalidate, clears enable and lock*/
  361. isync
  362. mtspr HID0, r3 /* clears invalidate */
  363. blr
  364. .globl icache_status
  365. icache_status:
  366. mfspr r3, HID0
  367. rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31
  368. blr
  369. .globl dcache_enable
  370. dcache_enable:
  371. mfspr r3, HID0
  372. li r5, HID0_DCFI|HID0_DLOCK
  373. andc r3, r3, r5
  374. mtspr HID0, r3 /* no invalidate, unlock */
  375. ori r3, r3, HID0_DCE
  376. ori r5, r3, HID0_DCFI
  377. mtspr HID0, r5 /* enable + invalidate */
  378. mtspr HID0, r3 /* enable */
  379. sync
  380. blr
  381. .globl dcache_disable
  382. dcache_disable:
  383. mfspr r3, HID0
  384. lis r4, 0
  385. ori r4, r4, HID0_DCE|HID0_DLOCK
  386. andc r3, r3, r4
  387. ori r4, r3, HID0_DCI
  388. sync
  389. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  390. sync
  391. mtspr HID0, r3 /* clears invalidate */
  392. blr
  393. .globl dcache_status
  394. dcache_status:
  395. mfspr r3, HID0
  396. rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31
  397. blr
  398. .globl get_pvr
  399. get_pvr:
  400. mfspr r3, PVR
  401. blr
  402. /*-------------------------------------------------------------------*/
  403. /*
  404. * void relocate_code (addr_sp, gd, addr_moni)
  405. *
  406. * This "function" does not return, instead it continues in RAM
  407. * after relocating the monitor code.
  408. *
  409. * r3 = dest
  410. * r4 = src
  411. * r5 = length in bytes
  412. * r6 = cachelinesize
  413. */
  414. .globl relocate_code
  415. relocate_code:
  416. mr r1, r3 /* Set new stack pointer */
  417. mr r9, r4 /* Save copy of Global Data pointer */
  418. mr r10, r5 /* Save copy of Destination Address */
  419. GET_GOT
  420. #if defined(__pic__) && __pic__ == 1
  421. /* Needed for upcoming -msingle-pic-base */
  422. bl _GLOBAL_OFFSET_TABLE_@local-4
  423. mflr r30
  424. #endif
  425. mr r3, r5 /* Destination Address */
  426. lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  427. ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
  428. lwz r5, GOT(__init_end)
  429. sub r5, r5, r4
  430. li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  431. /*
  432. * Fix GOT pointer:
  433. *
  434. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE)
  435. * + Destination Address
  436. *
  437. * Offset:
  438. */
  439. sub r15, r10, r4
  440. /* First our own GOT */
  441. add r12, r12, r15
  442. /* then the one used by the C code */
  443. add r30, r30, r15
  444. /*
  445. * Now relocate code
  446. */
  447. cmplw cr1,r3,r4
  448. addi r0,r5,3
  449. srwi. r0,r0,2
  450. beq cr1,4f /* In place copy is not necessary */
  451. beq 7f /* Protect against 0 count */
  452. mtctr r0
  453. bge cr1,2f
  454. la r8,-4(r4)
  455. la r7,-4(r3)
  456. /* copy */
  457. 1: lwzu r0,4(r8)
  458. stwu r0,4(r7)
  459. bdnz 1b
  460. addi r0,r5,3
  461. srwi. r0,r0,2
  462. mtctr r0
  463. la r8,-4(r4)
  464. la r7,-4(r3)
  465. /* and compare */
  466. 20: lwzu r20,4(r8)
  467. lwzu r21,4(r7)
  468. xor. r22, r20, r21
  469. bne 30f
  470. bdnz 20b
  471. b 4f
  472. /* compare failed */
  473. 30: li r3, 0
  474. blr
  475. 2: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
  476. add r8,r4,r0
  477. add r7,r3,r0
  478. 3: lwzu r0,-4(r8)
  479. stwu r0,-4(r7)
  480. bdnz 3b
  481. /*
  482. * Now flush the cache: note that we must start from a cache aligned
  483. * address. Otherwise we might miss one cache line.
  484. */
  485. 4: cmpwi r6,0
  486. add r5,r3,r5
  487. beq 7f /* Always flush prefetch queue in any case */
  488. subi r0,r6,1
  489. andc r3,r3,r0
  490. mr r4,r3
  491. 5: dcbst 0,r4
  492. add r4,r4,r6
  493. cmplw r4,r5
  494. blt 5b
  495. sync /* Wait for all dcbst to complete on bus */
  496. mr r4,r3
  497. 6: icbi 0,r4
  498. add r4,r4,r6
  499. cmplw r4,r5
  500. blt 6b
  501. 7: sync /* Wait for all icbi to complete on bus */
  502. isync
  503. /*
  504. * We are done. Do not return, instead branch to second part of board
  505. * initialization, now running from RAM.
  506. */
  507. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  508. mtlr r0
  509. blr
  510. in_ram:
  511. /*
  512. * Relocation Function, r12 point to got2+0x8000
  513. *
  514. * Adjust got2 pointers, no need to check for 0, this code
  515. * already puts a few entries in the table.
  516. */
  517. li r0,__got2_entries@sectoff@l
  518. la r3,GOT(_GOT2_TABLE_)
  519. lwz r11,GOT(_GOT2_TABLE_)
  520. mtctr r0
  521. sub r11,r3,r11
  522. addi r3,r3,-4
  523. 1: lwzu r0,4(r3)
  524. cmpwi r0,0
  525. beq- 2f
  526. add r0,r0,r11
  527. stw r0,0(r3)
  528. 2: bdnz 1b
  529. /*
  530. * Now adjust the fixups and the pointers to the fixups
  531. * in case we need to move ourselves again.
  532. */
  533. li r0,__fixup_entries@sectoff@l
  534. lwz r3,GOT(_FIXUP_TABLE_)
  535. cmpwi r0,0
  536. mtctr r0
  537. addi r3,r3,-4
  538. beq 4f
  539. 3: lwzu r4,4(r3)
  540. lwzux r0,r4,r11
  541. cmpwi r0,0
  542. add r0,r0,r11
  543. stw r4,0(r3)
  544. beq- 5f
  545. stw r0,0(r4)
  546. 5: bdnz 3b
  547. 4:
  548. clear_bss:
  549. /*
  550. * Now clear BSS segment
  551. */
  552. lwz r3,GOT(__bss_start)
  553. lwz r4,GOT(__bss_end__)
  554. cmplw 0, r3, r4
  555. beq 6f
  556. li r0, 0
  557. 5:
  558. stw r0, 0(r3)
  559. addi r3, r3, 4
  560. cmplw 0, r3, r4
  561. bne 5b
  562. 6:
  563. mr r3, r9 /* Global Data pointer */
  564. mr r4, r10 /* Destination Address */
  565. bl board_init_r
  566. /*
  567. * Copy exception vector code to low memory
  568. *
  569. * r3: dest_addr
  570. * r7: source address, r8: end address, r9: target address
  571. */
  572. .globl trap_init
  573. trap_init:
  574. mflr r4 /* save link register */
  575. GET_GOT
  576. lwz r7, GOT(_start)
  577. lwz r8, GOT(_end_of_vectors)
  578. li r9, 0x100 /* reset vector at 0x100 */
  579. cmplw 0, r7, r8
  580. bgelr /* return if r7>=r8 - just in case */
  581. 1:
  582. lwz r0, 0(r7)
  583. stw r0, 0(r9)
  584. addi r7, r7, 4
  585. addi r9, r9, 4
  586. cmplw 0, r7, r8
  587. bne 1b
  588. /*
  589. * relocate `hdlr' and `int_return' entries
  590. */
  591. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  592. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  593. 2:
  594. bl trap_reloc
  595. addi r7, r7, 0x100 /* next exception vector */
  596. cmplw 0, r7, r8
  597. blt 2b
  598. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  599. bl trap_reloc
  600. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  601. bl trap_reloc
  602. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  603. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  604. 3:
  605. bl trap_reloc
  606. addi r7, r7, 0x100 /* next exception vector */
  607. cmplw 0, r7, r8
  608. blt 3b
  609. li r7, .L_Trace - _start + EXC_OFF_SYS_RESET
  610. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  611. 4:
  612. bl trap_reloc
  613. addi r7, r7, 0x100 /* next exception vector */
  614. cmplw 0, r7, r8
  615. blt 4b
  616. mfmsr r3 /* now that the vectors have */
  617. lis r7, MSR_IP@h /* relocated into low memory */
  618. ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
  619. andc r3, r3, r7 /* (if it was on) */
  620. SYNC /* Some chip revs need this... */
  621. mtmsr r3
  622. SYNC
  623. mtlr r4 /* restore link register */
  624. blr