start.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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 - 2003 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. /*
  25. * U-Boot - Startup Code for MPC8220 CPUs
  26. */
  27. #include <asm-offsets.h>
  28. #include <config.h>
  29. #include <mpc8220.h>
  30. #include <timestamp.h>
  31. #include <version.h>
  32. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  33. #include <ppc_asm.tmpl>
  34. #include <ppc_defs.h>
  35. #include <asm/cache.h>
  36. #include <asm/mmu.h>
  37. #include <asm/u-boot.h>
  38. #ifndef CONFIG_IDENT_STRING
  39. #define CONFIG_IDENT_STRING ""
  40. #endif
  41. /* We don't want the MMU yet.
  42. */
  43. #undef MSR_KERNEL
  44. /* Floating Point enable, Machine Check and Recoverable Interr. */
  45. #ifdef DEBUG
  46. #define MSR_KERNEL (MSR_FP|MSR_RI)
  47. #else
  48. #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
  49. #endif
  50. /*
  51. * Set up GOT: Global Offset Table
  52. *
  53. * Use r12 to access the GOT
  54. */
  55. START_GOT
  56. GOT_ENTRY(_GOT2_TABLE_)
  57. GOT_ENTRY(_FIXUP_TABLE_)
  58. GOT_ENTRY(_start)
  59. GOT_ENTRY(_start_of_vectors)
  60. GOT_ENTRY(_end_of_vectors)
  61. GOT_ENTRY(transfer_to_handler)
  62. GOT_ENTRY(__init_end)
  63. GOT_ENTRY(_end)
  64. GOT_ENTRY(__bss_start)
  65. END_GOT
  66. /*
  67. * Version string
  68. */
  69. .data
  70. .globl version_string
  71. version_string:
  72. .ascii U_BOOT_VERSION
  73. .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  74. .ascii CONFIG_IDENT_STRING, "\0"
  75. /*
  76. * Exception vectors
  77. */
  78. .text
  79. . = EXC_OFF_SYS_RESET
  80. .globl _start
  81. _start:
  82. mfmsr r5 /* save msr contents */
  83. /* replace default MBAR base address from 0x80000000
  84. to 0xf0000000 */
  85. #if defined(CONFIG_SYS_DEFAULT_MBAR) && !defined(CONFIG_SYS_RAMBOOT)
  86. lis r3, CONFIG_SYS_MBAR@h
  87. ori r3, r3, CONFIG_SYS_MBAR@l
  88. /* MBAR is mirrored into the MBAR SPR */
  89. mtspr MBAR,r3
  90. mtspr SPRN_SPRG7W,r3
  91. lis r4, CONFIG_SYS_DEFAULT_MBAR@h
  92. stw r3, 0(r4)
  93. #endif /* CONFIG_SYS_DEFAULT_MBAR */
  94. /* Initialise the MPC8220 processor core */
  95. /*--------------------------------------------------------------*/
  96. bl init_8220_core
  97. /* initialize some things that are hard to access from C */
  98. /*--------------------------------------------------------------*/
  99. /* set up stack in on-chip SRAM */
  100. lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
  101. ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
  102. ori r1, r3, CONFIG_SYS_INIT_SP_OFFSET
  103. li r0, 0 /* Make room for stack frame header and */
  104. stwu r0, -4(r1) /* clear final stack frame so that */
  105. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  106. /* let the C-code set up the rest */
  107. /* */
  108. /* Be careful to keep code relocatable ! */
  109. /*--------------------------------------------------------------*/
  110. GET_GOT /* initialize GOT access */
  111. /* r3: IMMR */
  112. bl cpu_init_f /* run low-level CPU init code (in Flash)*/
  113. bl board_init_f /* run 1st part of board init code (in Flash)*/
  114. /* NOTREACHED - board_init_f() does not return */
  115. /*
  116. * Vector Table
  117. */
  118. .globl _start_of_vectors
  119. _start_of_vectors:
  120. /* Machine check */
  121. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  122. /* Data Storage exception. */
  123. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  124. /* Instruction Storage exception. */
  125. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  126. /* External Interrupt exception. */
  127. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  128. /* Alignment exception. */
  129. . = 0x600
  130. Alignment:
  131. EXCEPTION_PROLOG(SRR0, SRR1)
  132. mfspr r4,DAR
  133. stw r4,_DAR(r21)
  134. mfspr r5,DSISR
  135. stw r5,_DSISR(r21)
  136. addi r3,r1,STACK_FRAME_OVERHEAD
  137. EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
  138. /* Program check exception */
  139. . = 0x700
  140. ProgramCheck:
  141. EXCEPTION_PROLOG(SRR0, SRR1)
  142. addi r3,r1,STACK_FRAME_OVERHEAD
  143. EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
  144. MSR_KERNEL, COPY_EE)
  145. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  146. /* I guess we could implement decrementer, and may have
  147. * to someday for timekeeping.
  148. */
  149. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  150. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  151. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  152. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  153. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  154. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  155. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  156. STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
  157. STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
  158. STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
  159. #ifdef DEBUG
  160. . = 0x1300
  161. /*
  162. * This exception occurs when the program counter matches the
  163. * Instruction Address Breakpoint Register (IABR).
  164. *
  165. * I want the cpu to halt if this occurs so I can hunt around
  166. * with the debugger and look at things.
  167. *
  168. * When DEBUG is defined, both machine check enable (in the MSR)
  169. * and checkstop reset enable (in the reset mode register) are
  170. * turned off and so a checkstop condition will result in the cpu
  171. * halting.
  172. *
  173. * I force the cpu into a checkstop condition by putting an illegal
  174. * instruction here (at least this is the theory).
  175. *
  176. * well - that didnt work, so just do an infinite loop!
  177. */
  178. 1: b 1b
  179. #else
  180. STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
  181. #endif
  182. STD_EXCEPTION(0x1400, SMI, UnknownException)
  183. STD_EXCEPTION(0x1500, Trap_15, UnknownException)
  184. STD_EXCEPTION(0x1600, Trap_16, UnknownException)
  185. STD_EXCEPTION(0x1700, Trap_17, UnknownException)
  186. STD_EXCEPTION(0x1800, Trap_18, UnknownException)
  187. STD_EXCEPTION(0x1900, Trap_19, UnknownException)
  188. STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
  189. STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
  190. STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
  191. STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
  192. STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
  193. STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
  194. STD_EXCEPTION(0x2000, Trap_20, UnknownException)
  195. STD_EXCEPTION(0x2100, Trap_21, UnknownException)
  196. STD_EXCEPTION(0x2200, Trap_22, UnknownException)
  197. STD_EXCEPTION(0x2300, Trap_23, UnknownException)
  198. STD_EXCEPTION(0x2400, Trap_24, UnknownException)
  199. STD_EXCEPTION(0x2500, Trap_25, UnknownException)
  200. STD_EXCEPTION(0x2600, Trap_26, UnknownException)
  201. STD_EXCEPTION(0x2700, Trap_27, UnknownException)
  202. STD_EXCEPTION(0x2800, Trap_28, UnknownException)
  203. STD_EXCEPTION(0x2900, Trap_29, UnknownException)
  204. STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
  205. STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
  206. STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
  207. STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
  208. STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
  209. STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
  210. .globl _end_of_vectors
  211. _end_of_vectors:
  212. . = 0x3000
  213. /*
  214. * This code finishes saving the registers to the exception frame
  215. * and jumps to the appropriate handler for the exception.
  216. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  217. */
  218. .globl transfer_to_handler
  219. transfer_to_handler:
  220. stw r22,_NIP(r21)
  221. lis r22,MSR_POW@h
  222. andc r23,r23,r22
  223. stw r23,_MSR(r21)
  224. SAVE_GPR(7, r21)
  225. SAVE_4GPRS(8, r21)
  226. SAVE_8GPRS(12, r21)
  227. SAVE_8GPRS(24, r21)
  228. mflr r23
  229. andi. r24,r23,0x3f00 /* get vector offset */
  230. stw r24,TRAP(r21)
  231. li r22,0
  232. stw r22,RESULT(r21)
  233. lwz r24,0(r23) /* virtual address of handler */
  234. lwz r23,4(r23) /* where to go when done */
  235. mtspr SRR0,r24
  236. mtspr SRR1,r20
  237. mtlr r23
  238. SYNC
  239. rfi /* jump to handler, enable MMU */
  240. int_return:
  241. mfmsr r28 /* Disable interrupts */
  242. li r4,0
  243. ori r4,r4,MSR_EE
  244. andc r28,r28,r4
  245. SYNC /* Some chip revs need this... */
  246. mtmsr r28
  247. SYNC
  248. lwz r2,_CTR(r1)
  249. lwz r0,_LINK(r1)
  250. mtctr r2
  251. mtlr r0
  252. lwz r2,_XER(r1)
  253. lwz r0,_CCR(r1)
  254. mtspr XER,r2
  255. mtcrf 0xFF,r0
  256. REST_10GPRS(3, r1)
  257. REST_10GPRS(13, r1)
  258. REST_8GPRS(23, r1)
  259. REST_GPR(31, r1)
  260. lwz r2,_NIP(r1) /* Restore environment */
  261. lwz r0,_MSR(r1)
  262. mtspr SRR0,r2
  263. mtspr SRR1,r0
  264. lwz r0,GPR0(r1)
  265. lwz r2,GPR2(r1)
  266. lwz r1,GPR1(r1)
  267. SYNC
  268. rfi
  269. /*
  270. * This code initialises the MPC8220 processor core
  271. * (conforms to PowerPC 603e spec)
  272. * Note: expects original MSR contents to be in r5.
  273. */
  274. .globl init_8220_core
  275. init_8220_core:
  276. /* Initialize machine status; enable machine check interrupt */
  277. /*--------------------------------------------------------------*/
  278. li r3, MSR_KERNEL /* Set ME and RI flags */
  279. rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
  280. #ifdef DEBUG
  281. rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
  282. #endif
  283. SYNC /* Some chip revs need this... */
  284. mtmsr r3
  285. SYNC
  286. mtspr SRR1, r3 /* Make SRR1 match MSR */
  287. /* Initialize the Hardware Implementation-dependent Registers */
  288. /* HID0 also contains cache control */
  289. /*--------------------------------------------------------------*/
  290. lis r3, CONFIG_SYS_HID0_INIT@h
  291. ori r3, r3, CONFIG_SYS_HID0_INIT@l
  292. SYNC
  293. mtspr HID0, r3
  294. lis r3, CONFIG_SYS_HID0_FINAL@h
  295. ori r3, r3, CONFIG_SYS_HID0_FINAL@l
  296. SYNC
  297. mtspr HID0, r3
  298. /* Enable Extra BATs */
  299. mfspr r3, 1011 /* HID2 */
  300. lis r4, 0x0004
  301. ori r4, r4, 0x0000
  302. or r4, r4, r3
  303. mtspr 1011, r4
  304. sync
  305. /* clear all BAT's */
  306. /*--------------------------------------------------------------*/
  307. li r0, 0
  308. mtspr DBAT0U, r0
  309. mtspr DBAT0L, r0
  310. mtspr DBAT1U, r0
  311. mtspr DBAT1L, r0
  312. mtspr DBAT2U, r0
  313. mtspr DBAT2L, r0
  314. mtspr DBAT3U, r0
  315. mtspr DBAT3L, r0
  316. mtspr DBAT4U, r0
  317. mtspr DBAT4L, r0
  318. mtspr DBAT5U, r0
  319. mtspr DBAT5L, r0
  320. mtspr DBAT6U, r0
  321. mtspr DBAT6L, r0
  322. mtspr DBAT7U, r0
  323. mtspr DBAT7L, r0
  324. mtspr IBAT0U, r0
  325. mtspr IBAT0L, r0
  326. mtspr IBAT1U, r0
  327. mtspr IBAT1L, r0
  328. mtspr IBAT2U, r0
  329. mtspr IBAT2L, r0
  330. mtspr IBAT3U, r0
  331. mtspr IBAT3L, r0
  332. mtspr IBAT4U, r0
  333. mtspr IBAT4L, r0
  334. mtspr IBAT5U, r0
  335. mtspr IBAT5L, r0
  336. mtspr IBAT6U, r0
  337. mtspr IBAT6L, r0
  338. mtspr IBAT7U, r0
  339. mtspr IBAT7L, r0
  340. SYNC
  341. /* invalidate all tlb's */
  342. /* */
  343. /* From the 603e User Manual: "The 603e provides the ability to */
  344. /* invalidate a TLB entry. The TLB Invalidate Entry (tlbie) */
  345. /* instruction invalidates the TLB entry indexed by the EA, and */
  346. /* operates on both the instruction and data TLBs simultaneously*/
  347. /* invalidating four TLB entries (both sets in each TLB). The */
  348. /* index corresponds to bits 15-19 of the EA. To invalidate all */
  349. /* entries within both TLBs, 32 tlbie instructions should be */
  350. /* issued, incrementing this field by one each time." */
  351. /* */
  352. /* "Note that the tlbia instruction is not implemented on the */
  353. /* 603e." */
  354. /* */
  355. /* bits 15-19 correspond to addresses 0x00000000 to 0x0001F000 */
  356. /* incrementing by 0x1000 each time. The code below is sort of */
  357. /* based on code in "flush_tlbs" from arch/powerpc/kernel/head.S */
  358. /* */
  359. /*--------------------------------------------------------------*/
  360. li r3, 32
  361. mtctr r3
  362. li r3, 0
  363. 1: tlbie r3
  364. addi r3, r3, 0x1000
  365. bdnz 1b
  366. SYNC
  367. /* Done! */
  368. /*--------------------------------------------------------------*/
  369. blr
  370. /* Cache functions.
  371. *
  372. * Note: requires that all cache bits in
  373. * HID0 are in the low half word.
  374. */
  375. .globl icache_enable
  376. icache_enable:
  377. lis r4, 0
  378. ori r4, r4, CONFIG_SYS_HID0_INIT /* set ICE & ICFI bit */
  379. rlwinm r3, r4, 0, 21, 19 /* clear the ICFI bit */
  380. /*
  381. * The setting of the instruction cache enable (ICE) bit must be
  382. * preceded by an isync instruction to prevent the cache from being
  383. * enabled or disabled while an instruction access is in progress.
  384. */
  385. isync
  386. mtspr HID0, r4 /* Enable Instr Cache & Inval cache */
  387. mtspr HID0, r3 /* using 2 consec instructions */
  388. isync
  389. blr
  390. .globl icache_disable
  391. icache_disable:
  392. mfspr r3, HID0
  393. rlwinm r3, r3, 0, 17, 15 /* clear the ICE bit */
  394. mtspr HID0, r3
  395. isync
  396. blr
  397. .globl icache_status
  398. icache_status:
  399. mfspr r3, HID0
  400. rlwinm r3, r3, HID0_ICE_BITPOS + 1, 31, 31
  401. blr
  402. .globl dcache_enable
  403. dcache_enable:
  404. lis r4, 0
  405. ori r4, r4, HID0_DCE|HID0_DCFI /* set DCE & DCFI bit */
  406. rlwinm r3, r4, 0, 22, 20 /* clear the DCFI bit */
  407. /* Enable address translation in MSR bit */
  408. mfmsr r5
  409. ori r5, r5, 0x
  410. /*
  411. * The setting of the instruction cache enable (ICE) bit must be
  412. * preceded by an isync instruction to prevent the cache from being
  413. * enabled or disabled while an instruction access is in progress.
  414. */
  415. isync
  416. mtspr HID0, r4 /* Enable Data Cache & Inval cache*/
  417. mtspr HID0, r3 /* using 2 consec instructions */
  418. isync
  419. blr
  420. .globl dcache_disable
  421. dcache_disable:
  422. mfspr r3, HID0
  423. rlwinm r3, r3, 0, 18, 16 /* clear the DCE bit */
  424. mtspr HID0, r3
  425. isync
  426. blr
  427. .globl dcache_status
  428. dcache_status:
  429. mfspr r3, HID0
  430. rlwinm r3, r3, HID0_DCE_BITPOS + 1, 31, 31
  431. blr
  432. .globl get_pvr
  433. get_pvr:
  434. mfspr r3, PVR
  435. blr
  436. /*------------------------------------------------------------------------------*/
  437. /*
  438. * void relocate_code (addr_sp, gd, addr_moni)
  439. *
  440. * This "function" does not return, instead it continues in RAM
  441. * after relocating the monitor code.
  442. *
  443. * r3 = dest
  444. * r4 = src
  445. * r5 = length in bytes
  446. * r6 = cachelinesize
  447. */
  448. .globl relocate_code
  449. relocate_code:
  450. mr r1, r3 /* Set new stack pointer */
  451. mr r9, r4 /* Save copy of Global Data pointer */
  452. mr r10, r5 /* Save copy of Destination Address */
  453. GET_GOT
  454. mr r3, r5 /* Destination Address */
  455. lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  456. ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
  457. lwz r5, GOT(__init_end)
  458. sub r5, r5, r4
  459. li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  460. /*
  461. * Fix GOT pointer:
  462. *
  463. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  464. *
  465. * Offset:
  466. */
  467. sub r15, r10, r4
  468. /* First our own GOT */
  469. add r12, r12, r15
  470. /* then the one used by the C code */
  471. add r30, r30, r15
  472. /*
  473. * Now relocate code
  474. */
  475. cmplw cr1,r3,r4
  476. addi r0,r5,3
  477. srwi. r0,r0,2
  478. beq cr1,4f /* In place copy is not necessary */
  479. beq 7f /* Protect against 0 count */
  480. mtctr r0
  481. bge cr1,2f
  482. la r8,-4(r4)
  483. la r7,-4(r3)
  484. 1: lwzu r0,4(r8)
  485. stwu r0,4(r7)
  486. bdnz 1b
  487. b 4f
  488. 2: slwi r0,r0,2
  489. add r8,r4,r0
  490. add r7,r3,r0
  491. 3: lwzu r0,-4(r8)
  492. stwu r0,-4(r7)
  493. bdnz 3b
  494. /*
  495. * Now flush the cache: note that we must start from a cache aligned
  496. * address. Otherwise we might miss one cache line.
  497. */
  498. 4: cmpwi r6,0
  499. add r5,r3,r5
  500. beq 7f /* Always flush prefetch queue in any case */
  501. subi r0,r6,1
  502. andc r3,r3,r0
  503. mfspr r7,HID0 /* don't do dcbst if dcache is disabled */
  504. rlwinm r7,r7,HID0_DCE_BITPOS+1,31,31
  505. cmpwi r7,0
  506. beq 9f
  507. mr r4,r3
  508. 5: dcbst 0,r4
  509. add r4,r4,r6
  510. cmplw r4,r5
  511. blt 5b
  512. sync /* Wait for all dcbst to complete on bus */
  513. 9: mfspr r7,HID0 /* don't do icbi if icache is disabled */
  514. rlwinm r7,r7,HID0_ICE_BITPOS+1,31,31
  515. cmpwi r7,0
  516. beq 7f
  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, r12 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. cmpwi r0,0
  546. beq- 2f
  547. add r0,r0,r11
  548. stw r0,0(r3)
  549. 2: bdnz 1b
  550. /*
  551. * Now adjust the fixups and the pointers to the fixups
  552. * in case we need to move ourselves again.
  553. */
  554. li r0,__fixup_entries@sectoff@l
  555. lwz r3,GOT(_FIXUP_TABLE_)
  556. cmpwi r0,0
  557. mtctr r0
  558. addi r3,r3,-4
  559. beq 4f
  560. 3: lwzu r4,4(r3)
  561. lwzux r0,r4,r11
  562. cmpwi r0,0
  563. add r0,r0,r11
  564. stw r4,0(r3)
  565. beq- 5f
  566. stw r0,0(r4)
  567. 5: bdnz 3b
  568. 4:
  569. clear_bss:
  570. /*
  571. * Now clear BSS segment
  572. */
  573. lwz r3,GOT(__bss_start)
  574. lwz r4,GOT(_end)
  575. cmplw 0, r3, r4
  576. beq 6f
  577. li r0, 0
  578. 5:
  579. stw r0, 0(r3)
  580. addi r3, r3, 4
  581. cmplw 0, r3, r4
  582. bne 5b
  583. 6:
  584. mr r3, r9 /* Global Data pointer */
  585. mr r4, r10 /* Destination Address */
  586. bl board_init_r
  587. /*
  588. * Copy exception vector code to low memory
  589. *
  590. * r3: dest_addr
  591. * r7: source address, r8: end address, r9: target address
  592. */
  593. .globl trap_init
  594. trap_init:
  595. mflr r4 /* save link register */
  596. GET_GOT
  597. lwz r7, GOT(_start)
  598. lwz r8, GOT(_end_of_vectors)
  599. li r9, 0x100 /* reset vector always at 0x100 */
  600. cmplw 0, r7, r8
  601. bgelr /* return if r7>=r8 - just in case */
  602. 1:
  603. lwz r0, 0(r7)
  604. stw r0, 0(r9)
  605. addi r7, r7, 4
  606. addi r9, r9, 4
  607. cmplw 0, r7, r8
  608. bne 1b
  609. /*
  610. * relocate `hdlr' and `int_return' entries
  611. */
  612. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  613. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  614. 2:
  615. bl trap_reloc
  616. addi r7, r7, 0x100 /* next exception vector */
  617. cmplw 0, r7, r8
  618. blt 2b
  619. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  620. bl trap_reloc
  621. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  622. bl trap_reloc
  623. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  624. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  625. 3:
  626. bl trap_reloc
  627. addi r7, r7, 0x100 /* next exception vector */
  628. cmplw 0, r7, r8
  629. blt 3b
  630. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  631. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  632. 4:
  633. bl trap_reloc
  634. addi r7, r7, 0x100 /* next exception vector */
  635. cmplw 0, r7, r8
  636. blt 4b
  637. mfmsr r3 /* now that the vectors have */
  638. lis r7, MSR_IP@h /* relocated into low memory */
  639. ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
  640. andc r3, r3, r7 /* (if it was on) */
  641. SYNC /* Some chip revs need this... */
  642. mtmsr r3
  643. SYNC
  644. mtlr r4 /* restore link register */
  645. blr