start.S 17 KB

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