start.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  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. * Copyright (C) 2001 Josh Huber <huber@mclx.com>
  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. /* U-Boot - Startup Code for PowerPC based Embedded Boards
  26. *
  27. *
  28. * The processor starts at 0xfff00100 and the code is executed
  29. * from flash. The code is organized to be at an other address
  30. * in memory, but as long we don't jump around before relocating.
  31. * board_init lies at a quite high address and when the cpu has
  32. * jumped there, everything is ok.
  33. */
  34. #include <config.h>
  35. #include <74xx_7xx.h>
  36. #include <version.h>
  37. #include <ppc_asm.tmpl>
  38. #include <ppc_defs.h>
  39. #include <asm/cache.h>
  40. #include <asm/mmu.h>
  41. #include <galileo/gt64260R.h>
  42. #ifndef CONFIG_IDENT_STRING
  43. #define CONFIG_IDENT_STRING ""
  44. #endif
  45. /* We don't want the MMU yet.
  46. */
  47. #undef MSR_KERNEL
  48. /* Machine Check and Recoverable Interr. */
  49. #define MSR_KERNEL ( MSR_ME | MSR_RI )
  50. /*
  51. * Set up GOT: Global Offset Table
  52. *
  53. * Use r14 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. * r3 - 1st arg to board_init(): IMMP pointer
  68. * r4 - 2nd arg to board_init(): boot flag
  69. */
  70. .text
  71. .long 0x27051956 /* U-Boot Magic Number */
  72. .globl version_string
  73. version_string:
  74. .ascii U_BOOT_VERSION
  75. .ascii " (", __DATE__, " - ", __TIME__, ")"
  76. .ascii CONFIG_IDENT_STRING, "\0"
  77. . = EXC_OFF_SYS_RESET
  78. .globl _start
  79. _start:
  80. li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
  81. b boot_cold
  82. sync
  83. . = EXC_OFF_SYS_RESET + 0x10
  84. .globl _start_warm
  85. _start_warm:
  86. li r21, BOOTFLAG_WARM /* Software reboot */
  87. b boot_warm
  88. sync
  89. /* the boot code is located below the exception table */
  90. .globl _start_of_vectors
  91. _start_of_vectors:
  92. /* Machine check */
  93. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  94. /* Data Storage exception. "Never" generated on the 860. */
  95. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  96. /* Instruction Storage exception. "Never" generated on the 860. */
  97. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  98. /* External Interrupt exception. */
  99. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  100. /* Alignment exception. */
  101. . = 0x600
  102. Alignment:
  103. EXCEPTION_PROLOG
  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. lwz r6,GOT(transfer_to_handler)
  112. mtlr r6
  113. blrl
  114. .L_Alignment:
  115. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  116. .long int_return - _start + EXC_OFF_SYS_RESET
  117. /* Program check exception */
  118. . = 0x700
  119. ProgramCheck:
  120. EXCEPTION_PROLOG
  121. addi r3,r1,STACK_FRAME_OVERHEAD
  122. li r20,MSR_KERNEL
  123. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  124. lwz r6,GOT(transfer_to_handler)
  125. mtlr r6
  126. blrl
  127. .L_ProgramCheck:
  128. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  129. .long int_return - _start + EXC_OFF_SYS_RESET
  130. /* No FPU on MPC8xx. This exception is not supposed to happen.
  131. */
  132. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  133. /* I guess we could implement decrementer, and may have
  134. * to someday for timekeeping.
  135. */
  136. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  137. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  138. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  139. . = 0xc00
  140. /*
  141. * r0 - SYSCALL number
  142. * r3-... arguments
  143. */
  144. SystemCall:
  145. addis r11,r0,0 /* get functions table addr */
  146. ori r11,r11,0 /* Note: this code is patched in trap_init */
  147. addis r12,r0,0 /* get number of functions */
  148. ori r12,r12,0
  149. cmplw 0, r0, r12
  150. bge 1f
  151. rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
  152. add r11,r11,r0
  153. lwz r11,0(r11)
  154. li r20,0xd00-4 /* Get stack pointer */
  155. lwz r12,0(r20)
  156. subi r12,r12,12 /* Adjust stack pointer */
  157. li r0,0xc00+_end_back-SystemCall
  158. cmplw 0, r0, r12 /* Check stack overflow */
  159. bgt 1f
  160. stw r12,0(r20)
  161. mflr r0
  162. stw r0,0(r12)
  163. mfspr r0,SRR0
  164. stw r0,4(r12)
  165. mfspr r0,SRR1
  166. stw r0,8(r12)
  167. li r12,0xc00+_back-SystemCall
  168. mtlr r12
  169. mtspr SRR0,r11
  170. 1: SYNC
  171. rfi
  172. _back:
  173. mfmsr r11 /* Disable interrupts */
  174. li r12,0
  175. ori r12,r12,MSR_EE
  176. andc r11,r11,r12
  177. SYNC /* Some chip revs need this... */
  178. mtmsr r11
  179. SYNC
  180. li r12,0xd00-4 /* restore regs */
  181. lwz r12,0(r12)
  182. lwz r11,0(r12)
  183. mtlr r11
  184. lwz r11,4(r12)
  185. mtspr SRR0,r11
  186. lwz r11,8(r12)
  187. mtspr SRR1,r11
  188. addi r12,r12,12 /* Adjust stack pointer */
  189. li r20,0xd00-4
  190. stw r12,0(r20)
  191. SYNC
  192. rfi
  193. _end_back:
  194. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  195. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  196. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  197. /*
  198. * On the MPC8xx, this is a software emulation interrupt. It
  199. * occurs for all unimplemented and illegal instructions.
  200. */
  201. STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
  202. STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
  203. STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
  204. STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
  205. STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
  206. STD_EXCEPTION(0x1500, Reserved5, UnknownException)
  207. STD_EXCEPTION(0x1600, Reserved6, UnknownException)
  208. STD_EXCEPTION(0x1700, Reserved7, UnknownException)
  209. STD_EXCEPTION(0x1800, Reserved8, UnknownException)
  210. STD_EXCEPTION(0x1900, Reserved9, UnknownException)
  211. STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
  212. STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
  213. STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
  214. STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
  215. STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
  216. STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
  217. .globl _end_of_vectors
  218. _end_of_vectors:
  219. . = 0x2000
  220. boot_cold:
  221. boot_warm:
  222. /* disable everything */
  223. li r0, 0
  224. mtspr HID0, r0
  225. sync
  226. mtmsr 0
  227. bl invalidate_bats
  228. sync
  229. #ifdef CFG_L2
  230. /* init the L2 cache */
  231. addis r3, r0, L2_INIT@h
  232. ori r3, r3, L2_INIT@l
  233. sync
  234. mtspr l2cr, r3
  235. #endif
  236. #if defined(CONFIG_ALTIVEC) && defined(CONFIG_74xx)
  237. .long 0x7e00066c
  238. /*
  239. * dssall instruction, gas doesn't have it yet
  240. * ...for altivec, data stream stop all this probably
  241. * isn't needed unless we warm (software) reboot U-Boot
  242. */
  243. #endif
  244. #ifdef CFG_L2
  245. /* invalidate the L2 cache */
  246. bl l2cache_invalidate
  247. sync
  248. #endif
  249. #ifdef CFG_BOARD_ASM_INIT
  250. /* do early init */
  251. bl board_asm_init
  252. #endif
  253. /*
  254. * Calculate absolute address in FLASH and jump there
  255. *------------------------------------------------------*/
  256. lis r3, CFG_MONITOR_BASE@h
  257. ori r3, r3, CFG_MONITOR_BASE@l
  258. addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
  259. mtlr r3
  260. blr
  261. in_flash:
  262. /* let the C-code set up the rest */
  263. /* */
  264. /* Be careful to keep code relocatable ! */
  265. /*------------------------------------------------------*/
  266. /* perform low-level init */
  267. /* sdram init, galileo init, etc */
  268. /* r3: NHR bit from HID0 */
  269. /* setup the bats */
  270. bl setup_bats
  271. sync
  272. /*
  273. * Cache must be enabled here for stack-in-cache trick.
  274. * This means we need to enable the BATS.
  275. * This means:
  276. * 1) for the EVB, original gt regs need to be mapped
  277. * 2) need to have an IBAT for the 0xf region,
  278. * we are running there!
  279. * Cache should be turned on after BATs, since by default
  280. * everything is write-through.
  281. * The init-mem BAT can be reused after reloc. The old
  282. * gt-regs BAT can be reused after board_init_f calls
  283. * board_pre_init (EVB only).
  284. */
  285. #if !defined(CONFIG_BAB7xx) && !defined(CONFIG_ELPPC)
  286. /* enable address translation */
  287. bl enable_addr_trans
  288. sync
  289. /* enable and invalidate the data cache */
  290. bl l1dcache_enable
  291. sync
  292. #endif
  293. #ifdef CFG_INIT_RAM_LOCK
  294. bl lock_ram_in_cache
  295. sync
  296. #endif
  297. /* set up the stack pointer in our newly created
  298. * cache-ram (r1) */
  299. lis r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@h
  300. ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@l
  301. li r0, 0 /* Make room for stack frame header and */
  302. stwu r0, -4(r1) /* clear final stack frame so that */
  303. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  304. GET_GOT /* initialize GOT access */
  305. /* run low-level CPU init code (from Flash) */
  306. bl cpu_init_f
  307. sync
  308. mr r3, r21
  309. /* r3: BOOTFLAG */
  310. /* run 1st part of board init code (from Flash) */
  311. bl board_init_f
  312. sync
  313. /* NOTREACHED */
  314. .globl invalidate_bats
  315. invalidate_bats:
  316. /* invalidate BATs */
  317. mtspr IBAT0U, r0
  318. mtspr IBAT1U, r0
  319. mtspr IBAT2U, r0
  320. mtspr IBAT3U, r0
  321. isync
  322. mtspr DBAT0U, r0
  323. mtspr DBAT1U, r0
  324. mtspr DBAT2U, r0
  325. mtspr DBAT3U, r0
  326. isync
  327. sync
  328. blr
  329. /* setup_bats - set them up to some initial state */
  330. .globl setup_bats
  331. setup_bats:
  332. addis r0, r0, 0x0000
  333. /* IBAT 0 */
  334. addis r4, r0, CFG_IBAT0L@h
  335. ori r4, r4, CFG_IBAT0L@l
  336. addis r3, r0, CFG_IBAT0U@h
  337. ori r3, r3, CFG_IBAT0U@l
  338. mtspr IBAT0L, r4
  339. mtspr IBAT0U, r3
  340. isync
  341. /* DBAT 0 */
  342. addis r4, r0, CFG_DBAT0L@h
  343. ori r4, r4, CFG_DBAT0L@l
  344. addis r3, r0, CFG_DBAT0U@h
  345. ori r3, r3, CFG_DBAT0U@l
  346. mtspr DBAT0L, r4
  347. mtspr DBAT0U, r3
  348. isync
  349. /* IBAT 1 */
  350. addis r4, r0, CFG_IBAT1L@h
  351. ori r4, r4, CFG_IBAT1L@l
  352. addis r3, r0, CFG_IBAT1U@h
  353. ori r3, r3, CFG_IBAT1U@l
  354. mtspr IBAT1L, r4
  355. mtspr IBAT1U, r3
  356. isync
  357. /* DBAT 1 */
  358. addis r4, r0, CFG_DBAT1L@h
  359. ori r4, r4, CFG_DBAT1L@l
  360. addis r3, r0, CFG_DBAT1U@h
  361. ori r3, r3, CFG_DBAT1U@l
  362. mtspr DBAT1L, r4
  363. mtspr DBAT1U, r3
  364. isync
  365. /* IBAT 2 */
  366. addis r4, r0, CFG_IBAT2L@h
  367. ori r4, r4, CFG_IBAT2L@l
  368. addis r3, r0, CFG_IBAT2U@h
  369. ori r3, r3, CFG_IBAT2U@l
  370. mtspr IBAT2L, r4
  371. mtspr IBAT2U, r3
  372. isync
  373. /* DBAT 2 */
  374. addis r4, r0, CFG_DBAT2L@h
  375. ori r4, r4, CFG_DBAT2L@l
  376. addis r3, r0, CFG_DBAT2U@h
  377. ori r3, r3, CFG_DBAT2U@l
  378. mtspr DBAT2L, r4
  379. mtspr DBAT2U, r3
  380. isync
  381. /* IBAT 3 */
  382. addis r4, r0, CFG_IBAT3L@h
  383. ori r4, r4, CFG_IBAT3L@l
  384. addis r3, r0, CFG_IBAT3U@h
  385. ori r3, r3, CFG_IBAT3U@l
  386. mtspr IBAT3L, r4
  387. mtspr IBAT3U, r3
  388. isync
  389. /* DBAT 3 */
  390. addis r4, r0, CFG_DBAT3L@h
  391. ori r4, r4, CFG_DBAT3L@l
  392. addis r3, r0, CFG_DBAT3U@h
  393. ori r3, r3, CFG_DBAT3U@l
  394. mtspr DBAT3L, r4
  395. mtspr DBAT3U, r3
  396. isync
  397. /* bats are done, now invalidate the TLBs */
  398. addis r3, 0, 0x0000
  399. addis r5, 0, 0x4 /* upper bound of 0x00040000 for 7400/750 */
  400. isync
  401. tlblp:
  402. tlbie r3
  403. sync
  404. addi r3, r3, 0x1000
  405. cmp 0, 0, r3, r5
  406. blt tlblp
  407. blr
  408. .globl enable_addr_trans
  409. enable_addr_trans:
  410. /* enable address translation */
  411. mfmsr r5
  412. ori r5, r5, (MSR_IR | MSR_DR)
  413. mtmsr r5
  414. isync
  415. blr
  416. .globl disable_addr_trans
  417. disable_addr_trans:
  418. /* disable address translation */
  419. mflr r4
  420. mfmsr r3
  421. andi. r0, r3, (MSR_IR | MSR_DR)
  422. beqlr
  423. andc r3, r3, r0
  424. mtspr SRR0, r4
  425. mtspr SRR1, r3
  426. rfi
  427. /*
  428. * This code finishes saving the registers to the exception frame
  429. * and jumps to the appropriate handler for the exception.
  430. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  431. */
  432. .globl transfer_to_handler
  433. transfer_to_handler:
  434. stw r22,_NIP(r21)
  435. lis r22,MSR_POW@h
  436. andc r23,r23,r22
  437. stw r23,_MSR(r21)
  438. SAVE_GPR(7, r21)
  439. SAVE_4GPRS(8, r21)
  440. SAVE_8GPRS(12, r21)
  441. SAVE_8GPRS(24, r21)
  442. mflr r23
  443. andi. r24,r23,0x3f00 /* get vector offset */
  444. stw r24,TRAP(r21)
  445. li r22,0
  446. stw r22,RESULT(r21)
  447. mtspr SPRG2,r22 /* r1 is now kernel sp */
  448. lwz r24,0(r23) /* virtual address of handler */
  449. lwz r23,4(r23) /* where to go when done */
  450. mtspr SRR0,r24
  451. mtspr SRR1,r20
  452. mtlr r23
  453. SYNC
  454. rfi /* jump to handler, enable MMU */
  455. int_return:
  456. mfmsr r28 /* Disable interrupts */
  457. li r4,0
  458. ori r4,r4,MSR_EE
  459. andc r28,r28,r4
  460. SYNC /* Some chip revs need this... */
  461. mtmsr r28
  462. SYNC
  463. lwz r2,_CTR(r1)
  464. lwz r0,_LINK(r1)
  465. mtctr r2
  466. mtlr r0
  467. lwz r2,_XER(r1)
  468. lwz r0,_CCR(r1)
  469. mtspr XER,r2
  470. mtcrf 0xFF,r0
  471. REST_10GPRS(3, r1)
  472. REST_10GPRS(13, r1)
  473. REST_8GPRS(23, r1)
  474. REST_GPR(31, r1)
  475. lwz r2,_NIP(r1) /* Restore environment */
  476. lwz r0,_MSR(r1)
  477. mtspr SRR0,r2
  478. mtspr SRR1,r0
  479. lwz r0,GPR0(r1)
  480. lwz r2,GPR2(r1)
  481. lwz r1,GPR1(r1)
  482. SYNC
  483. rfi
  484. .globl dc_read
  485. dc_read:
  486. blr
  487. .globl get_pvr
  488. get_pvr:
  489. mfspr r3, PVR
  490. blr
  491. /*-----------------------------------------------------------------------*/
  492. /*
  493. * void relocate_code (addr_sp, gd, addr_moni)
  494. *
  495. * This "function" does not return, instead it continues in RAM
  496. * after relocating the monitor code.
  497. *
  498. * r3 = dest
  499. * r4 = src
  500. * r5 = length in bytes
  501. * r6 = cachelinesize
  502. */
  503. .globl relocate_code
  504. relocate_code:
  505. mr r1, r3 /* Set new stack pointer */
  506. mr r9, r4 /* Save copy of Global Data pointer */
  507. mr r10, r5 /* Save copy of Destination Address */
  508. mr r3, r5 /* Destination Address */
  509. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  510. ori r4, r4, CFG_MONITOR_BASE@l
  511. lwz r5, GOT(__init_end)
  512. sub r5, r5, r4
  513. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  514. /*
  515. * Fix GOT pointer:
  516. *
  517. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
  518. *
  519. * Offset:
  520. */
  521. sub r15, r10, r4
  522. /* First our own GOT */
  523. add r14, r14, r15
  524. /* then the one used by the C code */
  525. add r30, r30, r15
  526. /*
  527. * Now relocate code
  528. */
  529. #ifdef CONFIG_ECC
  530. bl board_relocate_rom
  531. sync
  532. mr r3, r10 /* Destination Address */
  533. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  534. ori r4, r4, CFG_MONITOR_BASE@l
  535. lwz r5, GOT(__init_end)
  536. sub r5, r5, r4
  537. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  538. #else
  539. cmplw cr1,r3,r4
  540. addi r0,r5,3
  541. srwi. r0,r0,2
  542. beq cr1,4f /* In place copy is not necessary */
  543. beq 7f /* Protect against 0 count */
  544. mtctr r0
  545. bge cr1,2f
  546. la r8,-4(r4)
  547. la r7,-4(r3)
  548. 1: lwzu r0,4(r8)
  549. stwu r0,4(r7)
  550. bdnz 1b
  551. b 4f
  552. 2: slwi r0,r0,2
  553. add r8,r4,r0
  554. add r7,r3,r0
  555. 3: lwzu r0,-4(r8)
  556. stwu r0,-4(r7)
  557. bdnz 3b
  558. #endif
  559. /*
  560. * Now flush the cache: note that we must start from a cache aligned
  561. * address. Otherwise we might miss one cache line.
  562. */
  563. 4: cmpwi r6,0
  564. add r5,r3,r5
  565. beq 7f /* Always flush prefetch queue in any case */
  566. subi r0,r6,1
  567. andc r3,r3,r0
  568. mr r4,r3
  569. 5: dcbst 0,r4
  570. add r4,r4,r6
  571. cmplw r4,r5
  572. blt 5b
  573. sync /* Wait for all dcbst to complete on bus */
  574. mr r4,r3
  575. 6: icbi 0,r4
  576. add r4,r4,r6
  577. cmplw r4,r5
  578. blt 6b
  579. 7: sync /* Wait for all icbi to complete on bus */
  580. isync
  581. /*
  582. * We are done. Do not return, instead branch to second part of board
  583. * initialization, now running from RAM.
  584. */
  585. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  586. mtlr r0
  587. blr
  588. in_ram:
  589. #ifdef CONFIG_ECC
  590. bl board_init_ecc
  591. #endif
  592. /*
  593. * Relocation Function, r14 point to got2+0x8000
  594. *
  595. * Adjust got2 pointers, no need to check for 0, this code
  596. * already puts a few entries in the table.
  597. */
  598. li r0,__got2_entries@sectoff@l
  599. la r3,GOT(_GOT2_TABLE_)
  600. lwz r11,GOT(_GOT2_TABLE_)
  601. mtctr r0
  602. sub r11,r3,r11
  603. addi r3,r3,-4
  604. 1: lwzu r0,4(r3)
  605. add r0,r0,r11
  606. stw r0,0(r3)
  607. bdnz 1b
  608. /*
  609. * Now adjust the fixups and the pointers to the fixups
  610. * in case we need to move ourselves again.
  611. */
  612. 2: li r0,__fixup_entries@sectoff@l
  613. lwz r3,GOT(_FIXUP_TABLE_)
  614. cmpwi r0,0
  615. mtctr r0
  616. addi r3,r3,-4
  617. beq 4f
  618. 3: lwzu r4,4(r3)
  619. lwzux r0,r4,r11
  620. add r0,r0,r11
  621. stw r10,0(r3)
  622. stw r0,0(r4)
  623. bdnz 3b
  624. 4:
  625. /* clear_bss: */
  626. /*
  627. * Now clear BSS segment
  628. */
  629. lwz r3,GOT(__bss_start)
  630. lwz r4,GOT(_end)
  631. cmplw 0, r3, r4
  632. beq 6f
  633. li r0, 0
  634. 5:
  635. stw r0, 0(r3)
  636. addi r3, r3, 4
  637. cmplw 0, r3, r4
  638. bne 5b
  639. 6:
  640. mr r3, r10 /* Destination Address */
  641. #ifdef CONFIG_AMIGAONEG3SE
  642. mr r4, r9 /* Use RAM copy of the global data */
  643. #endif
  644. bl after_reloc
  645. /* not reached - end relocate_code */
  646. /*-----------------------------------------------------------------------*/
  647. /*
  648. * Copy exception vector code to low memory
  649. *
  650. * r3: dest_addr
  651. * r7: source address, r8: end address, r9: target address
  652. */
  653. .globl trap_init
  654. trap_init:
  655. lwz r7, GOT(_start)
  656. lwz r8, GOT(_end_of_vectors)
  657. rlwinm r9, r7, 0, 18, 31 /* _start & 0x3FFF */
  658. cmplw 0, r7, r8
  659. bgelr /* return if r7>=r8 - just in case */
  660. mflr r4 /* save link register */
  661. 1:
  662. lwz r0, 0(r7)
  663. stw r0, 0(r9)
  664. addi r7, r7, 4
  665. addi r9, r9, 4
  666. cmplw 0, r7, r8
  667. bne 1b
  668. /*
  669. * relocate `hdlr' and `int_return' entries
  670. */
  671. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  672. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  673. 2:
  674. bl trap_reloc
  675. addi r7, r7, 0x100 /* next exception vector */
  676. cmplw 0, r7, r8
  677. blt 2b
  678. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  679. bl trap_reloc
  680. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  681. bl trap_reloc
  682. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  683. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  684. 3:
  685. bl trap_reloc
  686. addi r7, r7, 0x100 /* next exception vector */
  687. cmplw 0, r7, r8
  688. blt 3b
  689. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  690. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  691. 4:
  692. bl trap_reloc
  693. addi r7, r7, 0x100 /* next exception vector */
  694. cmplw 0, r7, r8
  695. blt 4b
  696. /* enable execptions from RAM vectors */
  697. mfmsr r7
  698. li r8,MSR_IP
  699. andc r7,r7,r8
  700. mtmsr r7
  701. mtlr r4 /* restore link register */
  702. blr
  703. /*
  704. * Function: relocate entries for one exception vector
  705. */
  706. trap_reloc:
  707. lwz r0, 0(r7) /* hdlr ... */
  708. add r0, r0, r3 /* ... += dest_addr */
  709. stw r0, 0(r7)
  710. lwz r0, 4(r7) /* int_return ... */
  711. add r0, r0, r3 /* ... += dest_addr */
  712. stw r0, 4(r7)
  713. sync
  714. isync
  715. blr
  716. #ifdef CFG_INIT_RAM_LOCK
  717. lock_ram_in_cache:
  718. /* Allocate Initial RAM in data cache.
  719. */
  720. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  721. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  722. li r2, ((CFG_INIT_RAM_END & ~31) + \
  723. (CFG_INIT_RAM_ADDR & 31) + 31) / 32
  724. mtctr r2
  725. 1:
  726. dcbz r0, r3
  727. addi r3, r3, 32
  728. bdnz 1b
  729. /* Lock the data cache */
  730. mfspr r0, HID0
  731. ori r0, r0, 0x1000
  732. sync
  733. mtspr HID0, r0
  734. sync
  735. blr
  736. .globl unlock_ram_in_cache
  737. unlock_ram_in_cache:
  738. /* invalidate the INIT_RAM section */
  739. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  740. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  741. li r2, ((CFG_INIT_RAM_END & ~31) + \
  742. (CFG_INIT_RAM_ADDR & 31) + 31) / 32
  743. mtctr r2
  744. 1: icbi r0, r3
  745. addi r3, r3, 32
  746. bdnz 1b
  747. sync /* Wait for all icbi to complete on bus */
  748. isync
  749. /* Unlock the data cache and invalidate it */
  750. mfspr r0, HID0
  751. li r3,0x1000
  752. andc r0,r0,r3
  753. li r3,0x0400
  754. or r0,r0,r3
  755. sync
  756. mtspr HID0, r0
  757. sync
  758. blr
  759. #endif