start.S 19 KB

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