start.S 18 KB

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