start.S 19 KB

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