start.S 19 KB

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