start.S 16 KB

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