start.S 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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 - 2003 Wolfgang Denk <wd@denx.de>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. /*
  25. * U-Boot - Startup Code for MPC5xxx CPUs
  26. */
  27. #include <config.h>
  28. #include <mpc5xxx.h>
  29. #include <timestamp.h>
  30. #include <version.h>
  31. #define CONFIG_MPC5xxx 1 /* needed for Linux kernel header files */
  32. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  33. #include <ppc_asm.tmpl>
  34. #include <ppc_defs.h>
  35. #include <asm/cache.h>
  36. #include <asm/mmu.h>
  37. #ifndef CONFIG_IDENT_STRING
  38. #define CONFIG_IDENT_STRING ""
  39. #endif
  40. /* We don't want the MMU yet.
  41. */
  42. #undef MSR_KERNEL
  43. /* Floating Point enable, Machine Check and Recoverable Interr. */
  44. #ifdef DEBUG
  45. #define MSR_KERNEL (MSR_FP|MSR_RI)
  46. #else
  47. #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
  48. #endif
  49. /*
  50. * Set up GOT: Global Offset Table
  51. *
  52. * Use r14 to access the GOT
  53. */
  54. START_GOT
  55. GOT_ENTRY(_GOT2_TABLE_)
  56. GOT_ENTRY(_FIXUP_TABLE_)
  57. GOT_ENTRY(_start)
  58. GOT_ENTRY(_start_of_vectors)
  59. GOT_ENTRY(_end_of_vectors)
  60. GOT_ENTRY(transfer_to_handler)
  61. GOT_ENTRY(__init_end)
  62. GOT_ENTRY(_end)
  63. GOT_ENTRY(__bss_start)
  64. END_GOT
  65. /*
  66. * Version string
  67. */
  68. .data
  69. .globl version_string
  70. version_string:
  71. .ascii U_BOOT_VERSION
  72. .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
  73. .ascii CONFIG_IDENT_STRING, "\0"
  74. /*
  75. * Exception vectors
  76. */
  77. .text
  78. . = EXC_OFF_SYS_RESET
  79. .globl _start
  80. _start:
  81. li r21, BOOTFLAG_COLD /* Normal Power-On */
  82. nop
  83. b boot_cold
  84. . = EXC_OFF_SYS_RESET + 0x10
  85. .globl _start_warm
  86. _start_warm:
  87. li r21, BOOTFLAG_WARM /* Software reboot */
  88. b boot_warm
  89. boot_cold:
  90. boot_warm:
  91. mfmsr r5 /* save msr contents */
  92. /* Move CSBoot and adjust instruction pointer */
  93. /*--------------------------------------------------------------*/
  94. #if defined(CONFIG_SYS_LOWBOOT)
  95. # if defined(CONFIG_SYS_RAMBOOT)
  96. # error CONFIG_SYS_LOWBOOT is incompatible with CONFIG_SYS_RAMBOOT
  97. # endif /* CONFIG_SYS_RAMBOOT */
  98. # if defined(CONFIG_MGT5100)
  99. # error CONFIG_SYS_LOWBOOT is incompatible with MGT5100
  100. # endif /* CONFIG_MGT5100 */
  101. lis r4, CONFIG_SYS_DEFAULT_MBAR@h
  102. lis r3, START_REG(CONFIG_SYS_BOOTCS_START)@h
  103. ori r3, r3, START_REG(CONFIG_SYS_BOOTCS_START)@l
  104. stw r3, 0x4(r4) /* CS0 start */
  105. lis r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@h
  106. ori r3, r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@l
  107. stw r3, 0x8(r4) /* CS0 stop */
  108. lis r3, 0x02010000@h
  109. ori r3, r3, 0x02010000@l
  110. stw r3, 0x54(r4) /* CS0 and Boot enable */
  111. lis r3, lowboot_reentry@h /* jump from bootlow address space (0x0000xxxx) */
  112. ori r3, r3, lowboot_reentry@l /* to the address space the linker used */
  113. mtlr r3
  114. blr
  115. lowboot_reentry:
  116. lis r3, START_REG(CONFIG_SYS_BOOTCS_START)@h
  117. ori r3, r3, START_REG(CONFIG_SYS_BOOTCS_START)@l
  118. stw r3, 0x4c(r4) /* Boot start */
  119. lis r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@h
  120. ori r3, r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@l
  121. stw r3, 0x50(r4) /* Boot stop */
  122. lis r3, 0x02000001@h
  123. ori r3, r3, 0x02000001@l
  124. stw r3, 0x54(r4) /* Boot enable, CS0 disable */
  125. #endif /* CONFIG_SYS_LOWBOOT */
  126. #if defined(CONFIG_SYS_DEFAULT_MBAR) && !defined(CONFIG_SYS_RAMBOOT)
  127. lis r3, CONFIG_SYS_MBAR@h
  128. ori r3, r3, CONFIG_SYS_MBAR@l
  129. #if defined(CONFIG_MPC5200)
  130. /* MBAR is mirrored into the MBAR SPR */
  131. mtspr MBAR,r3
  132. rlwinm r3, r3, 16, 16, 31
  133. #endif
  134. #if defined(CONFIG_MGT5100)
  135. rlwinm r3, r3, 17, 15, 31
  136. #endif
  137. lis r4, CONFIG_SYS_DEFAULT_MBAR@h
  138. stw r3, 0(r4)
  139. #endif /* CONFIG_SYS_DEFAULT_MBAR */
  140. /* Initialise the MPC5xxx processor core */
  141. /*--------------------------------------------------------------*/
  142. bl init_5xxx_core
  143. /* initialize some things that are hard to access from C */
  144. /*--------------------------------------------------------------*/
  145. /* set up stack in on-chip SRAM */
  146. lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
  147. ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
  148. ori r1, r3, CONFIG_SYS_INIT_SP_OFFSET
  149. li r0, 0 /* Make room for stack frame header and */
  150. stwu r0, -4(r1) /* clear final stack frame so that */
  151. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  152. /* let the C-code set up the rest */
  153. /* */
  154. /* Be careful to keep code relocatable ! */
  155. /*--------------------------------------------------------------*/
  156. GET_GOT /* initialize GOT access */
  157. /* r3: IMMR */
  158. bl cpu_init_f /* run low-level CPU init code (in Flash)*/
  159. mr r3, r21
  160. /* r3: BOOTFLAG */
  161. bl board_init_f /* run 1st part of board init code (in Flash)*/
  162. /*
  163. * Vector Table
  164. */
  165. .globl _start_of_vectors
  166. _start_of_vectors:
  167. /* Machine check */
  168. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  169. /* Data Storage exception. */
  170. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  171. /* Instruction Storage exception. */
  172. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  173. /* External Interrupt exception. */
  174. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  175. /* Alignment exception. */
  176. . = 0x600
  177. Alignment:
  178. EXCEPTION_PROLOG(SRR0, SRR1)
  179. mfspr r4,DAR
  180. stw r4,_DAR(r21)
  181. mfspr r5,DSISR
  182. stw r5,_DSISR(r21)
  183. addi r3,r1,STACK_FRAME_OVERHEAD
  184. li r20,MSR_KERNEL
  185. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  186. rlwimi r20,r23,0,25,25 /* copy IP bit from saved MSR */
  187. lwz r6,GOT(transfer_to_handler)
  188. mtlr r6
  189. blrl
  190. .L_Alignment:
  191. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  192. .long int_return - _start + EXC_OFF_SYS_RESET
  193. /* Program check exception */
  194. . = 0x700
  195. ProgramCheck:
  196. EXCEPTION_PROLOG(SRR0, SRR1)
  197. addi r3,r1,STACK_FRAME_OVERHEAD
  198. li r20,MSR_KERNEL
  199. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  200. rlwimi r20,r23,0,25,25 /* copy IP bit from saved MSR */
  201. lwz r6,GOT(transfer_to_handler)
  202. mtlr r6
  203. blrl
  204. .L_ProgramCheck:
  205. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  206. .long int_return - _start + EXC_OFF_SYS_RESET
  207. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  208. /* I guess we could implement decrementer, and may have
  209. * to someday for timekeeping.
  210. */
  211. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  212. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  213. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  214. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  215. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  216. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  217. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  218. STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
  219. STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
  220. STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
  221. #ifdef DEBUG
  222. . = 0x1300
  223. /*
  224. * This exception occurs when the program counter matches the
  225. * Instruction Address Breakpoint Register (IABR).
  226. *
  227. * I want the cpu to halt if this occurs so I can hunt around
  228. * with the debugger and look at things.
  229. *
  230. * When DEBUG is defined, both machine check enable (in the MSR)
  231. * and checkstop reset enable (in the reset mode register) are
  232. * turned off and so a checkstop condition will result in the cpu
  233. * halting.
  234. *
  235. * I force the cpu into a checkstop condition by putting an illegal
  236. * instruction here (at least this is the theory).
  237. *
  238. * well - that didnt work, so just do an infinite loop!
  239. */
  240. 1: b 1b
  241. #else
  242. STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
  243. #endif
  244. STD_EXCEPTION(0x1400, SMI, UnknownException)
  245. STD_EXCEPTION(0x1500, Trap_15, UnknownException)
  246. STD_EXCEPTION(0x1600, Trap_16, UnknownException)
  247. STD_EXCEPTION(0x1700, Trap_17, UnknownException)
  248. STD_EXCEPTION(0x1800, Trap_18, UnknownException)
  249. STD_EXCEPTION(0x1900, Trap_19, UnknownException)
  250. STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
  251. STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
  252. STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
  253. STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
  254. STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
  255. STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
  256. STD_EXCEPTION(0x2000, Trap_20, UnknownException)
  257. STD_EXCEPTION(0x2100, Trap_21, UnknownException)
  258. STD_EXCEPTION(0x2200, Trap_22, UnknownException)
  259. STD_EXCEPTION(0x2300, Trap_23, UnknownException)
  260. STD_EXCEPTION(0x2400, Trap_24, UnknownException)
  261. STD_EXCEPTION(0x2500, Trap_25, UnknownException)
  262. STD_EXCEPTION(0x2600, Trap_26, UnknownException)
  263. STD_EXCEPTION(0x2700, Trap_27, UnknownException)
  264. STD_EXCEPTION(0x2800, Trap_28, UnknownException)
  265. STD_EXCEPTION(0x2900, Trap_29, UnknownException)
  266. STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
  267. STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
  268. STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
  269. STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
  270. STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
  271. STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
  272. .globl _end_of_vectors
  273. _end_of_vectors:
  274. . = 0x3000
  275. /*
  276. * This code finishes saving the registers to the exception frame
  277. * and jumps to the appropriate handler for the exception.
  278. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  279. */
  280. .globl transfer_to_handler
  281. transfer_to_handler:
  282. stw r22,_NIP(r21)
  283. lis r22,MSR_POW@h
  284. andc r23,r23,r22
  285. stw r23,_MSR(r21)
  286. SAVE_GPR(7, r21)
  287. SAVE_4GPRS(8, r21)
  288. SAVE_8GPRS(12, r21)
  289. SAVE_8GPRS(24, r21)
  290. mflr r23
  291. andi. r24,r23,0x3f00 /* get vector offset */
  292. stw r24,TRAP(r21)
  293. li r22,0
  294. stw r22,RESULT(r21)
  295. lwz r24,0(r23) /* virtual address of handler */
  296. lwz r23,4(r23) /* where to go when done */
  297. mtspr SRR0,r24
  298. mtspr SRR1,r20
  299. mtlr r23
  300. SYNC
  301. rfi /* jump to handler, enable MMU */
  302. int_return:
  303. mfmsr r28 /* Disable interrupts */
  304. li r4,0
  305. ori r4,r4,MSR_EE
  306. andc r28,r28,r4
  307. SYNC /* Some chip revs need this... */
  308. mtmsr r28
  309. SYNC
  310. lwz r2,_CTR(r1)
  311. lwz r0,_LINK(r1)
  312. mtctr r2
  313. mtlr r0
  314. lwz r2,_XER(r1)
  315. lwz r0,_CCR(r1)
  316. mtspr XER,r2
  317. mtcrf 0xFF,r0
  318. REST_10GPRS(3, r1)
  319. REST_10GPRS(13, r1)
  320. REST_8GPRS(23, r1)
  321. REST_GPR(31, r1)
  322. lwz r2,_NIP(r1) /* Restore environment */
  323. lwz r0,_MSR(r1)
  324. mtspr SRR0,r2
  325. mtspr SRR1,r0
  326. lwz r0,GPR0(r1)
  327. lwz r2,GPR2(r1)
  328. lwz r1,GPR1(r1)
  329. SYNC
  330. rfi
  331. /*
  332. * This code initialises the MPC5xxx processor core
  333. * (conforms to PowerPC 603e spec)
  334. * Note: expects original MSR contents to be in r5.
  335. */
  336. .globl init_5xx_core
  337. init_5xxx_core:
  338. /* Initialize machine status; enable machine check interrupt */
  339. /*--------------------------------------------------------------*/
  340. li r3, MSR_KERNEL /* Set ME and RI flags */
  341. rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
  342. #ifdef DEBUG
  343. rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
  344. #endif
  345. SYNC /* Some chip revs need this... */
  346. mtmsr r3
  347. SYNC
  348. mtspr SRR1, r3 /* Make SRR1 match MSR */
  349. /* Initialize the Hardware Implementation-dependent Registers */
  350. /* HID0 also contains cache control */
  351. /*--------------------------------------------------------------*/
  352. lis r3, CONFIG_SYS_HID0_INIT@h
  353. ori r3, r3, CONFIG_SYS_HID0_INIT@l
  354. SYNC
  355. mtspr HID0, r3
  356. lis r3, CONFIG_SYS_HID0_FINAL@h
  357. ori r3, r3, CONFIG_SYS_HID0_FINAL@l
  358. SYNC
  359. mtspr HID0, r3
  360. /* clear all BAT's */
  361. /*--------------------------------------------------------------*/
  362. li r0, 0
  363. mtspr DBAT0U, r0
  364. mtspr DBAT0L, r0
  365. mtspr DBAT1U, r0
  366. mtspr DBAT1L, r0
  367. mtspr DBAT2U, r0
  368. mtspr DBAT2L, r0
  369. mtspr DBAT3U, r0
  370. mtspr DBAT3L, r0
  371. mtspr DBAT4U, r0
  372. mtspr DBAT4L, r0
  373. mtspr DBAT5U, r0
  374. mtspr DBAT5L, r0
  375. mtspr DBAT6U, r0
  376. mtspr DBAT6L, r0
  377. mtspr DBAT7U, r0
  378. mtspr DBAT7L, r0
  379. mtspr IBAT0U, r0
  380. mtspr IBAT0L, r0
  381. mtspr IBAT1U, r0
  382. mtspr IBAT1L, r0
  383. mtspr IBAT2U, r0
  384. mtspr IBAT2L, r0
  385. mtspr IBAT3U, r0
  386. mtspr IBAT3L, r0
  387. mtspr IBAT4U, r0
  388. mtspr IBAT4L, r0
  389. mtspr IBAT5U, r0
  390. mtspr IBAT5L, r0
  391. mtspr IBAT6U, r0
  392. mtspr IBAT6L, r0
  393. mtspr IBAT7U, r0
  394. mtspr IBAT7L, r0
  395. SYNC
  396. /* invalidate all tlb's */
  397. /* */
  398. /* From the 603e User Manual: "The 603e provides the ability to */
  399. /* invalidate a TLB entry. The TLB Invalidate Entry (tlbie) */
  400. /* instruction invalidates the TLB entry indexed by the EA, and */
  401. /* operates on both the instruction and data TLBs simultaneously*/
  402. /* invalidating four TLB entries (both sets in each TLB). The */
  403. /* index corresponds to bits 15-19 of the EA. To invalidate all */
  404. /* entries within both TLBs, 32 tlbie instructions should be */
  405. /* issued, incrementing this field by one each time." */
  406. /* */
  407. /* "Note that the tlbia instruction is not implemented on the */
  408. /* 603e." */
  409. /* */
  410. /* bits 15-19 correspond to addresses 0x00000000 to 0x0001F000 */
  411. /* incrementing by 0x1000 each time. The code below is sort of */
  412. /* based on code in "flush_tlbs" from arch/ppc/kernel/head.S */
  413. /* */
  414. /*--------------------------------------------------------------*/
  415. li r3, 32
  416. mtctr r3
  417. li r3, 0
  418. 1: tlbie r3
  419. addi r3, r3, 0x1000
  420. bdnz 1b
  421. SYNC
  422. /* Done! */
  423. /*--------------------------------------------------------------*/
  424. blr
  425. /* Cache functions.
  426. *
  427. * Note: requires that all cache bits in
  428. * HID0 are in the low half word.
  429. */
  430. .globl icache_enable
  431. icache_enable:
  432. mfspr r3, HID0
  433. ori r3, r3, HID0_ICE
  434. lis r4, 0
  435. ori r4, r4, HID0_ILOCK
  436. andc r3, r3, r4
  437. ori r4, r3, HID0_ICFI
  438. isync
  439. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  440. isync
  441. mtspr HID0, r3 /* clears invalidate */
  442. blr
  443. .globl icache_disable
  444. icache_disable:
  445. mfspr r3, HID0
  446. lis r4, 0
  447. ori r4, r4, HID0_ICE|HID0_ILOCK
  448. andc r3, r3, r4
  449. ori r4, r3, HID0_ICFI
  450. isync
  451. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  452. isync
  453. mtspr HID0, r3 /* clears invalidate */
  454. blr
  455. .globl icache_status
  456. icache_status:
  457. mfspr r3, HID0
  458. rlwinm r3, r3, HID0_ICE_BITPOS + 1, 31, 31
  459. blr
  460. .globl dcache_enable
  461. dcache_enable:
  462. mfspr r3, HID0
  463. ori r3, r3, HID0_DCE
  464. lis r4, 0
  465. ori r4, r4, HID0_DLOCK
  466. andc r3, r3, r4
  467. ori r4, r3, HID0_DCI
  468. sync
  469. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  470. sync
  471. mtspr HID0, r3 /* clears invalidate */
  472. blr
  473. .globl dcache_disable
  474. dcache_disable:
  475. mfspr r3, HID0
  476. lis r4, 0
  477. ori r4, r4, HID0_DCE|HID0_DLOCK
  478. andc r3, r3, r4
  479. ori r4, r3, HID0_DCI
  480. sync
  481. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  482. sync
  483. mtspr HID0, r3 /* clears invalidate */
  484. blr
  485. .globl dcache_status
  486. dcache_status:
  487. mfspr r3, HID0
  488. rlwinm r3, r3, HID0_DCE_BITPOS + 1, 31, 31
  489. blr
  490. .globl get_svr
  491. get_svr:
  492. mfspr r3, SVR
  493. blr
  494. .globl get_pvr
  495. get_pvr:
  496. mfspr r3, PVR
  497. blr
  498. /*------------------------------------------------------------------------------*/
  499. /*
  500. * void relocate_code (addr_sp, gd, addr_moni)
  501. *
  502. * This "function" does not return, instead it continues in RAM
  503. * after relocating the monitor code.
  504. *
  505. * r3 = dest
  506. * r4 = src
  507. * r5 = length in bytes
  508. * r6 = cachelinesize
  509. */
  510. .globl relocate_code
  511. relocate_code:
  512. mr r1, r3 /* Set new stack pointer */
  513. mr r9, r4 /* Save copy of Global Data pointer */
  514. mr r10, r5 /* Save copy of Destination Address */
  515. mr r3, r5 /* Destination Address */
  516. lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  517. ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
  518. lwz r5, GOT(__init_end)
  519. sub r5, r5, r4
  520. li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  521. /*
  522. * Fix GOT pointer:
  523. *
  524. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  525. *
  526. * Offset:
  527. */
  528. sub r15, r10, r4
  529. /* First our own GOT */
  530. add r14, r14, r15
  531. /* then the one used by the C code */
  532. add r30, r30, r15
  533. /*
  534. * Now relocate code
  535. */
  536. cmplw cr1,r3,r4
  537. addi r0,r5,3
  538. srwi. r0,r0,2
  539. beq cr1,4f /* In place copy is not necessary */
  540. beq 7f /* Protect against 0 count */
  541. mtctr r0
  542. bge cr1,2f
  543. la r8,-4(r4)
  544. la r7,-4(r3)
  545. 1: lwzu r0,4(r8)
  546. stwu r0,4(r7)
  547. bdnz 1b
  548. b 4f
  549. 2: slwi r0,r0,2
  550. add r8,r4,r0
  551. add r7,r3,r0
  552. 3: lwzu r0,-4(r8)
  553. stwu r0,-4(r7)
  554. bdnz 3b
  555. /*
  556. * Now flush the cache: note that we must start from a cache aligned
  557. * address. Otherwise we might miss one cache line.
  558. */
  559. 4: cmpwi r6,0
  560. add r5,r3,r5
  561. beq 7f /* Always flush prefetch queue in any case */
  562. subi r0,r6,1
  563. andc r3,r3,r0
  564. mfspr r7,HID0 /* don't do dcbst if dcache is disabled */
  565. rlwinm r7,r7,HID0_DCE_BITPOS+1,31,31
  566. cmpwi r7,0
  567. beq 9f
  568. mr r4,r3
  569. 5: dcbst 0,r4
  570. add r4,r4,r6
  571. cmplw r4,r5
  572. blt 5b
  573. sync /* Wait for all dcbst to complete on bus */
  574. 9: mfspr r7,HID0 /* don't do icbi if icache is disabled */
  575. rlwinm r7,r7,HID0_ICE_BITPOS+1,31,31
  576. cmpwi r7,0
  577. beq 7f
  578. mr r4,r3
  579. 6: icbi 0,r4
  580. add r4,r4,r6
  581. cmplw r4,r5
  582. blt 6b
  583. 7: sync /* Wait for all icbi to complete on bus */
  584. isync
  585. /*
  586. * We are done. Do not return, instead branch to second part of board
  587. * initialization, now running from RAM.
  588. */
  589. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  590. mtlr r0
  591. blr
  592. in_ram:
  593. /*
  594. * Relocation Function, r14 point to got2+0x8000
  595. *
  596. * Adjust got2 pointers, no need to check for 0, this code
  597. * already puts a few entries in the table.
  598. */
  599. li r0,__got2_entries@sectoff@l
  600. la r3,GOT(_GOT2_TABLE_)
  601. lwz r11,GOT(_GOT2_TABLE_)
  602. mtctr r0
  603. sub r11,r3,r11
  604. addi r3,r3,-4
  605. 1: lwzu r0,4(r3)
  606. add r0,r0,r11
  607. stw r0,0(r3)
  608. bdnz 1b
  609. /*
  610. * Now adjust the fixups and the pointers to the fixups
  611. * in case we need to move ourselves again.
  612. */
  613. 2: li r0,__fixup_entries@sectoff@l
  614. lwz r3,GOT(_FIXUP_TABLE_)
  615. cmpwi r0,0
  616. mtctr r0
  617. addi r3,r3,-4
  618. beq 4f
  619. 3: lwzu r4,4(r3)
  620. lwzux r0,r4,r11
  621. add r0,r0,r11
  622. stw r10,0(r3)
  623. stw r0,0(r4)
  624. bdnz 3b
  625. 4:
  626. clear_bss:
  627. /*
  628. * Now clear BSS segment
  629. */
  630. lwz r3,GOT(__bss_start)
  631. lwz r4,GOT(_end)
  632. cmplw 0, r3, r4
  633. beq 6f
  634. li r0, 0
  635. 5:
  636. stw r0, 0(r3)
  637. addi r3, r3, 4
  638. cmplw 0, r3, r4
  639. bne 5b
  640. 6:
  641. mr r3, r9 /* Global Data pointer */
  642. mr r4, r10 /* Destination Address */
  643. bl board_init_r
  644. /*
  645. * Copy exception vector code to low memory
  646. *
  647. * r3: dest_addr
  648. * r7: source address, r8: end address, r9: target address
  649. */
  650. .globl trap_init
  651. trap_init:
  652. lwz r7, GOT(_start)
  653. lwz r8, GOT(_end_of_vectors)
  654. li r9, 0x100 /* reset vector always at 0x100 */
  655. cmplw 0, r7, r8
  656. bgelr /* return if r7>=r8 - just in case */
  657. mflr r4 /* save link register */
  658. 1:
  659. lwz r0, 0(r7)
  660. stw r0, 0(r9)
  661. addi r7, r7, 4
  662. addi r9, r9, 4
  663. cmplw 0, r7, r8
  664. bne 1b
  665. /*
  666. * relocate `hdlr' and `int_return' entries
  667. */
  668. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  669. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  670. 2:
  671. bl trap_reloc
  672. addi r7, r7, 0x100 /* next exception vector */
  673. cmplw 0, r7, r8
  674. blt 2b
  675. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  676. bl trap_reloc
  677. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  678. bl trap_reloc
  679. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  680. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  681. 3:
  682. bl trap_reloc
  683. addi r7, r7, 0x100 /* next exception vector */
  684. cmplw 0, r7, r8
  685. blt 3b
  686. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  687. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  688. 4:
  689. bl trap_reloc
  690. addi r7, r7, 0x100 /* next exception vector */
  691. cmplw 0, r7, r8
  692. blt 4b
  693. mfmsr r3 /* now that the vectors have */
  694. lis r7, MSR_IP@h /* relocated into low memory */
  695. ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
  696. andc r3, r3, r7 /* (if it was on) */
  697. SYNC /* Some chip revs need this... */
  698. mtmsr r3
  699. SYNC
  700. mtlr r4 /* restore link register */
  701. blr
  702. /*
  703. * Function: relocate entries for one exception vector
  704. */
  705. trap_reloc:
  706. lwz r0, 0(r7) /* hdlr ... */
  707. add r0, r0, r3 /* ... += dest_addr */
  708. stw r0, 0(r7)
  709. lwz r0, 4(r7) /* int_return ... */
  710. add r0, r0, r3 /* ... += dest_addr */
  711. stw r0, 4(r7)
  712. blr