start.S 16 KB

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