start.S 19 KB

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