start.S 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  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. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. /*
  9. * U-Boot - Startup Code for MPC8260 PowerPC based Embedded Boards
  10. */
  11. #include <asm-offsets.h>
  12. #include <config.h>
  13. #include <mpc8260.h>
  14. #include <version.h>
  15. #include <ppc_asm.tmpl>
  16. #include <ppc_defs.h>
  17. #include <asm/cache.h>
  18. #include <asm/mmu.h>
  19. #include <asm/u-boot.h>
  20. /* We don't want the MMU yet.
  21. */
  22. #undef MSR_KERNEL
  23. /* Floating Point enable, Machine Check and Recoverable Interr. */
  24. #ifdef DEBUG
  25. #define MSR_KERNEL (MSR_FP|MSR_RI)
  26. #else
  27. #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
  28. #endif
  29. /*
  30. * Set up GOT: Global Offset Table
  31. *
  32. * Use r12 to access the GOT
  33. */
  34. START_GOT
  35. GOT_ENTRY(_GOT2_TABLE_)
  36. GOT_ENTRY(_FIXUP_TABLE_)
  37. GOT_ENTRY(_start)
  38. GOT_ENTRY(_start_of_vectors)
  39. GOT_ENTRY(_end_of_vectors)
  40. GOT_ENTRY(transfer_to_handler)
  41. GOT_ENTRY(__init_end)
  42. GOT_ENTRY(__bss_end)
  43. GOT_ENTRY(__bss_start)
  44. END_GOT
  45. /*
  46. * Version string - must be in data segment because MPC8260 uses the first
  47. * 256 bytes for the Hard Reset Configuration Word table (see below).
  48. * Similarly, can't have the U-Boot Magic Number as the first thing in
  49. * the image - don't know how this will affect the image tools, but I guess
  50. * I'll find out soon
  51. */
  52. .data
  53. .globl version_string
  54. version_string:
  55. .ascii U_BOOT_VERSION_STRING, "\0"
  56. /*
  57. * Hard Reset Configuration Word (HRCW) table
  58. *
  59. * The Hard Reset Configuration Word (HRCW) sets a number of useful things
  60. * such as whether there is an external memory controller, whether the
  61. * PowerPC core is disabled (i.e. only the communications processor is
  62. * active, accessed by another CPU on the bus), whether using external
  63. * arbitration, external bus mode, boot port size, core initial prefix,
  64. * internal space base, boot memory space, etc.
  65. *
  66. * These things dictate where the processor begins execution, where the
  67. * boot ROM appears in memory, the memory controller setup when access
  68. * boot ROM, etc. The HRCW is *extremely* important.
  69. *
  70. * The HRCW is read from the bus during reset. One CPU on the bus will
  71. * be a hard reset configuration master, any others will be hard reset
  72. * configuration slaves. The master reads eight HRCWs from flash during
  73. * reset - the first it uses for itself, the other 7 it communicates to
  74. * up to 7 configuration slaves by some complicated mechanism, which is
  75. * not really important here.
  76. *
  77. * The configuration master performs 32 successive reads starting at address
  78. * 0 and incrementing by 8 each read (i.e. on 64 bit boundaries) but only 8
  79. * bits is read, and always from byte lane D[0-7] (so that port size of the
  80. * boot device does not matter). The first four reads form the 32 bit HRCW
  81. * for the master itself. The second four reads form the HRCW for the first
  82. * slave, and so on, up to seven slaves. The 32 bit HRCW is formed by
  83. * concatenating the four bytes, with the first read placed in byte 0 (the
  84. * most significant byte), and so on with the fourth read placed in byte 3
  85. * (the least significant byte).
  86. */
  87. #define _HRCW_TABLE_ENTRY(w) \
  88. .fill 8,1,(((w)>>24)&0xff); \
  89. .fill 8,1,(((w)>>16)&0xff); \
  90. .fill 8,1,(((w)>> 8)&0xff); \
  91. .fill 8,1,(((w) )&0xff)
  92. .text
  93. .globl _hrcw_table
  94. _hrcw_table:
  95. _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_MASTER)
  96. _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE1)
  97. _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE2)
  98. _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE3)
  99. _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE4)
  100. _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE5)
  101. _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE6)
  102. _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_SLAVE7)
  103. /*
  104. * After configuration, a system reset exception is executed using the
  105. * vector at offset 0x100 relative to the base set by MSR[IP]. If MSR[IP]
  106. * is 0, the base address is 0x00000000. If MSR[IP] is 1, the base address
  107. * is 0xfff00000. In the case of a Power On Reset or Hard Reset, the value
  108. * of MSR[IP] is determined by the CIP field in the HRCW.
  109. *
  110. * Other bits in the HRCW set up the Base Address and Port Size in BR0.
  111. * This determines the location of the boot ROM (flash or EPROM) in the
  112. * processor's address space at boot time. As long as the HRCW is set up
  113. * so that we eventually end up executing the code below when the processor
  114. * executes the reset exception, the actual values used should not matter.
  115. *
  116. * Once we have got here, the address mask in OR0 is cleared so that the
  117. * bottom 32K of the boot ROM is effectively repeated all throughout the
  118. * processor's address space, after which we can jump to the absolute
  119. * address at which the boot ROM was linked at compile time, and proceed
  120. * to initialise the memory controller without worrying if the rug will be
  121. * pulled out from under us, so to speak (it will be fine as long as we
  122. * configure BR0 with the same boot ROM link address).
  123. */
  124. . = EXC_OFF_SYS_RESET
  125. .globl _start
  126. _start:
  127. mfmsr r5 /* save msr contents */
  128. #if defined(CONFIG_SYS_DEFAULT_IMMR)
  129. lis r3, CONFIG_SYS_IMMR@h
  130. ori r3, r3, CONFIG_SYS_IMMR@l
  131. lis r4, CONFIG_SYS_DEFAULT_IMMR@h
  132. stw r3, 0x1A8(r4)
  133. #endif /* CONFIG_SYS_DEFAULT_IMMR */
  134. /* Initialise the MPC8260 processor core */
  135. /*--------------------------------------------------------------*/
  136. bl init_8260_core
  137. #ifndef CONFIG_SYS_RAMBOOT
  138. /* When booting from ROM (Flash or EPROM), clear the */
  139. /* Address Mask in OR0 so ROM appears everywhere */
  140. /*--------------------------------------------------------------*/
  141. lis r3, (CONFIG_SYS_IMMR+IM_REGBASE)@h
  142. lwz r4, IM_OR0@l(r3)
  143. li r5, 0x7fff
  144. and r4, r4, r5
  145. stw r4, IM_OR0@l(r3)
  146. /* Calculate absolute address in FLASH and jump there */
  147. /*--------------------------------------------------------------*/
  148. lis r3, CONFIG_SYS_MONITOR_BASE@h
  149. ori r3, r3, CONFIG_SYS_MONITOR_BASE@l
  150. addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
  151. mtlr r3
  152. blr
  153. in_flash:
  154. #endif /* CONFIG_SYS_RAMBOOT */
  155. /* initialize some things that are hard to access from C */
  156. /*--------------------------------------------------------------*/
  157. lis r3, CONFIG_SYS_IMMR@h /* set up stack in internal DPRAM */
  158. ori r1, r3, CONFIG_SYS_INIT_SP_OFFSET
  159. li r0, 0 /* Make room for stack frame header and */
  160. stwu r0, -4(r1) /* clear final stack frame so that */
  161. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  162. /* let the C-code set up the rest */
  163. /* */
  164. /* Be careful to keep code relocatable ! */
  165. /*--------------------------------------------------------------*/
  166. GET_GOT /* initialize GOT access */
  167. /* r3: IMMR */
  168. bl cpu_init_f /* run low-level CPU init code (in Flash)*/
  169. #ifdef DEBUG
  170. bl init_debug /* set up debugging stuff */
  171. #endif
  172. bl board_init_f /* run 1st part of board init code (in Flash)*/
  173. /* NOTREACHED - board_init_f() does not return */
  174. /*
  175. * Vector Table
  176. */
  177. .globl _start_of_vectors
  178. _start_of_vectors:
  179. /* Machine check */
  180. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  181. /* Data Storage exception. */
  182. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  183. /* Instruction Storage exception. */
  184. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  185. /* External Interrupt exception. */
  186. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  187. /* Alignment exception. */
  188. . = 0x600
  189. Alignment:
  190. EXCEPTION_PROLOG(SRR0, SRR1)
  191. mfspr r4,DAR
  192. stw r4,_DAR(r21)
  193. mfspr r5,DSISR
  194. stw r5,_DSISR(r21)
  195. addi r3,r1,STACK_FRAME_OVERHEAD
  196. EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
  197. /* Program check exception */
  198. . = 0x700
  199. ProgramCheck:
  200. EXCEPTION_PROLOG(SRR0, SRR1)
  201. addi r3,r1,STACK_FRAME_OVERHEAD
  202. EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
  203. MSR_KERNEL, COPY_EE)
  204. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  205. /* I guess we could implement decrementer, and may have
  206. * to someday for timekeeping.
  207. */
  208. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  209. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  210. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  211. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  212. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  213. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  214. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  215. STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
  216. STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
  217. STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
  218. #ifdef DEBUG
  219. . = 0x1300
  220. /*
  221. * This exception occurs when the program counter matches the
  222. * Instruction Address Breakpoint Register (IABR).
  223. *
  224. * I want the cpu to halt if this occurs so I can hunt around
  225. * with the debugger and look at things.
  226. *
  227. * When DEBUG is defined, both machine check enable (in the MSR)
  228. * and checkstop reset enable (in the reset mode register) are
  229. * turned off and so a checkstop condition will result in the cpu
  230. * halting.
  231. *
  232. * I force the cpu into a checkstop condition by putting an illegal
  233. * instruction here (at least this is the theory).
  234. *
  235. * well - that didnt work, so just do an infinite loop!
  236. */
  237. 1: b 1b
  238. #else
  239. STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
  240. #endif
  241. STD_EXCEPTION(0x1400, SMI, UnknownException)
  242. STD_EXCEPTION(0x1500, Trap_15, UnknownException)
  243. STD_EXCEPTION(0x1600, Trap_16, UnknownException)
  244. STD_EXCEPTION(0x1700, Trap_17, UnknownException)
  245. STD_EXCEPTION(0x1800, Trap_18, UnknownException)
  246. STD_EXCEPTION(0x1900, Trap_19, UnknownException)
  247. STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
  248. STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
  249. STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
  250. STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
  251. STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
  252. STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
  253. STD_EXCEPTION(0x2000, Trap_20, UnknownException)
  254. STD_EXCEPTION(0x2100, Trap_21, UnknownException)
  255. STD_EXCEPTION(0x2200, Trap_22, UnknownException)
  256. STD_EXCEPTION(0x2300, Trap_23, UnknownException)
  257. STD_EXCEPTION(0x2400, Trap_24, UnknownException)
  258. STD_EXCEPTION(0x2500, Trap_25, UnknownException)
  259. STD_EXCEPTION(0x2600, Trap_26, UnknownException)
  260. STD_EXCEPTION(0x2700, Trap_27, UnknownException)
  261. STD_EXCEPTION(0x2800, Trap_28, UnknownException)
  262. STD_EXCEPTION(0x2900, Trap_29, UnknownException)
  263. STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
  264. STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
  265. STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
  266. STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
  267. STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
  268. STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
  269. .globl _end_of_vectors
  270. _end_of_vectors:
  271. . = 0x3000
  272. /*
  273. * This code finishes saving the registers to the exception frame
  274. * and jumps to the appropriate handler for the exception.
  275. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  276. */
  277. .globl transfer_to_handler
  278. transfer_to_handler:
  279. stw r22,_NIP(r21)
  280. lis r22,MSR_POW@h
  281. andc r23,r23,r22
  282. stw r23,_MSR(r21)
  283. SAVE_GPR(7, r21)
  284. SAVE_4GPRS(8, r21)
  285. SAVE_8GPRS(12, r21)
  286. SAVE_8GPRS(24, r21)
  287. mflr r23
  288. andi. r24,r23,0x3f00 /* get vector offset */
  289. stw r24,TRAP(r21)
  290. li r22,0
  291. stw r22,RESULT(r21)
  292. lwz r24,0(r23) /* virtual address of handler */
  293. lwz r23,4(r23) /* where to go when done */
  294. mtspr SRR0,r24
  295. mtspr SRR1,r20
  296. mtlr r23
  297. SYNC
  298. rfi /* jump to handler, enable MMU */
  299. int_return:
  300. mfmsr r28 /* Disable interrupts */
  301. li r4,0
  302. ori r4,r4,MSR_EE
  303. andc r28,r28,r4
  304. SYNC /* Some chip revs need this... */
  305. mtmsr r28
  306. SYNC
  307. lwz r2,_CTR(r1)
  308. lwz r0,_LINK(r1)
  309. mtctr r2
  310. mtlr r0
  311. lwz r2,_XER(r1)
  312. lwz r0,_CCR(r1)
  313. mtspr XER,r2
  314. mtcrf 0xFF,r0
  315. REST_10GPRS(3, r1)
  316. REST_10GPRS(13, r1)
  317. REST_8GPRS(23, r1)
  318. REST_GPR(31, r1)
  319. lwz r2,_NIP(r1) /* Restore environment */
  320. lwz r0,_MSR(r1)
  321. mtspr SRR0,r2
  322. mtspr SRR1,r0
  323. lwz r0,GPR0(r1)
  324. lwz r2,GPR2(r1)
  325. lwz r1,GPR1(r1)
  326. SYNC
  327. rfi
  328. /*
  329. * This code initialises the MPC8260 processor core
  330. * (conforms to PowerPC 603e spec)
  331. * Note: expects original MSR contents to be in r5.
  332. */
  333. .globl init_8260_core
  334. init_8260_core:
  335. /* Initialize machine status; enable machine check interrupt */
  336. /*--------------------------------------------------------------*/
  337. li r3, MSR_KERNEL /* Set ME and RI flags */
  338. rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
  339. #ifdef DEBUG
  340. rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
  341. #endif
  342. SYNC /* Some chip revs need this... */
  343. mtmsr r3
  344. SYNC
  345. mtspr SRR1, r3 /* Make SRR1 match MSR */
  346. /* Initialise the SYPCR early, and reset the watchdog (if req) */
  347. /*--------------------------------------------------------------*/
  348. lis r3, (CONFIG_SYS_IMMR+IM_REGBASE)@h
  349. lis r4, CONFIG_SYS_SYPCR@h
  350. ori r4, r4, CONFIG_SYS_SYPCR@l
  351. stw r4, IM_SYPCR@l(r3)
  352. #if defined(CONFIG_WATCHDOG)
  353. li r4, 21868 /* = 0x556c */
  354. sth r4, IM_SWSR@l(r3)
  355. li r4, -21959 /* = 0xaa39 */
  356. sth r4, IM_SWSR@l(r3)
  357. #endif /* CONFIG_WATCHDOG */
  358. /* Initialize the Hardware Implementation-dependent Registers */
  359. /* HID0 also contains cache control */
  360. /*--------------------------------------------------------------*/
  361. lis r3, CONFIG_SYS_HID0_INIT@h
  362. ori r3, r3, CONFIG_SYS_HID0_INIT@l
  363. SYNC
  364. mtspr HID0, r3
  365. lis r3, CONFIG_SYS_HID0_FINAL@h
  366. ori r3, r3, CONFIG_SYS_HID0_FINAL@l
  367. SYNC
  368. mtspr HID0, r3
  369. lis r3, CONFIG_SYS_HID2@h
  370. ori r3, r3, CONFIG_SYS_HID2@l
  371. mtspr HID2, r3
  372. /* clear all BAT's */
  373. /*--------------------------------------------------------------*/
  374. li r0, 0
  375. mtspr DBAT0U, r0
  376. mtspr DBAT0L, r0
  377. mtspr DBAT1U, r0
  378. mtspr DBAT1L, r0
  379. mtspr DBAT2U, r0
  380. mtspr DBAT2L, r0
  381. mtspr DBAT3U, r0
  382. mtspr DBAT3L, r0
  383. mtspr IBAT0U, r0
  384. mtspr IBAT0L, r0
  385. mtspr IBAT1U, r0
  386. mtspr IBAT1L, r0
  387. mtspr IBAT2U, r0
  388. mtspr IBAT2L, r0
  389. mtspr IBAT3U, r0
  390. mtspr IBAT3L, r0
  391. SYNC
  392. /* invalidate all tlb's */
  393. /* */
  394. /* From the 603e User Manual: "The 603e provides the ability to */
  395. /* invalidate a TLB entry. The TLB Invalidate Entry (tlbie) */
  396. /* instruction invalidates the TLB entry indexed by the EA, and */
  397. /* operates on both the instruction and data TLBs simultaneously*/
  398. /* invalidating four TLB entries (both sets in each TLB). The */
  399. /* index corresponds to bits 15-19 of the EA. To invalidate all */
  400. /* entries within both TLBs, 32 tlbie instructions should be */
  401. /* issued, incrementing this field by one each time." */
  402. /* */
  403. /* "Note that the tlbia instruction is not implemented on the */
  404. /* 603e." */
  405. /* */
  406. /* bits 15-19 correspond to addresses 0x00000000 to 0x0001F000 */
  407. /* incrementing by 0x1000 each time. The code below is sort of */
  408. /* based on code in "flush_tlbs" from arch/powerpc/kernel/head.S */
  409. /* */
  410. /*--------------------------------------------------------------*/
  411. li r3, 32
  412. mtctr r3
  413. li r3, 0
  414. 1: tlbie r3
  415. addi r3, r3, 0x1000
  416. bdnz 1b
  417. SYNC
  418. /* Done! */
  419. /*--------------------------------------------------------------*/
  420. blr
  421. #ifdef DEBUG
  422. /*
  423. * initialise things related to debugging.
  424. *
  425. * must be called after the global offset table (GOT) is initialised
  426. * (GET_GOT) and after cpu_init_f() has executed.
  427. */
  428. .globl init_debug
  429. init_debug:
  430. lis r3, (CONFIG_SYS_IMMR+IM_REGBASE)@h
  431. /* Quick and dirty hack to enable the RAM and copy the */
  432. /* vectors so that we can take exceptions. */
  433. /*--------------------------------------------------------------*/
  434. /* write Memory Refresh Prescaler */
  435. li r4, CONFIG_SYS_MPTPR
  436. sth r4, IM_MPTPR@l(r3)
  437. /* write 60x Refresh Timer */
  438. li r4, CONFIG_SYS_PSRT
  439. stb r4, IM_PSRT@l(r3)
  440. /* init the 60x SDRAM Mode Register */
  441. lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_NORM)@h
  442. ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_NORM)@l
  443. stw r4, IM_PSDMR@l(r3)
  444. /* write Precharge All Banks command */
  445. lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_PREA)@h
  446. ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_PREA)@l
  447. stw r4, IM_PSDMR@l(r3)
  448. stb r0, 0(0)
  449. /* write eight CBR Refresh commands */
  450. lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_CBRR)@h
  451. ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_CBRR)@l
  452. stw r4, IM_PSDMR@l(r3)
  453. stb r0, 0(0)
  454. stb r0, 0(0)
  455. stb r0, 0(0)
  456. stb r0, 0(0)
  457. stb r0, 0(0)
  458. stb r0, 0(0)
  459. stb r0, 0(0)
  460. stb r0, 0(0)
  461. /* write Mode Register Write command */
  462. lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_MRW)@h
  463. ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_MRW)@l
  464. stw r4, IM_PSDMR@l(r3)
  465. stb r0, 0(0)
  466. /* write Normal Operation command and enable Refresh */
  467. lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_NORM|PSDMR_RFEN)@h
  468. ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_NORM|PSDMR_RFEN)@l
  469. stw r4, IM_PSDMR@l(r3)
  470. stb r0, 0(0)
  471. /* RAM should now be operational */
  472. #define VEC_WRD_CNT ((_end_of_vectors - _start + EXC_OFF_SYS_RESET) / 4)
  473. mflr r3
  474. GET_GOT
  475. mtlr r3
  476. lwz r3, GOT(_end_of_vectors)
  477. rlwinm r4, r3, 0, 18, 31 /* _end_of_vectors & 0x3FFF */
  478. lis r5, VEC_WRD_CNT@h
  479. ori r5, r5, VEC_WRD_CNT@l
  480. mtctr r5
  481. 1:
  482. lwzu r5, -4(r3)
  483. stwu r5, -4(r4)
  484. bdnz 1b
  485. /* Load the Instruction Address Breakpoint Register (IABR). */
  486. /* */
  487. /* The address to load is stored in the first word of dual port */
  488. /* ram and should be preserved while the power is on, so you */
  489. /* can plug addresses into that location then reset the cpu and */
  490. /* this code will load that address into the IABR after the */
  491. /* reset. */
  492. /* */
  493. /* When the program counter matches the contents of the IABR, */
  494. /* an exception is generated (before the instruction at that */
  495. /* location completes). The vector for this exception is 0x1300 */
  496. /*--------------------------------------------------------------*/
  497. lis r3, CONFIG_SYS_IMMR@h
  498. lwz r3, 0(r3)
  499. mtspr IABR, r3
  500. /* Set the entire dual port RAM (where the initial stack */
  501. /* resides) to a known value - makes it easier to see where */
  502. /* the stack has been written */
  503. /*--------------------------------------------------------------*/
  504. lis r3, (CONFIG_SYS_IMMR + CONFIG_SYS_INIT_SP_OFFSET)@h
  505. ori r3, r3, (CONFIG_SYS_IMMR + CONFIG_SYS_INIT_SP_OFFSET)@l
  506. li r4, ((CONFIG_SYS_INIT_SP_OFFSET - 4) / 4)
  507. mtctr r4
  508. lis r4, 0xdeadbeaf@h
  509. ori r4, r4, 0xdeadbeaf@l
  510. 1:
  511. stwu r4, -4(r3)
  512. bdnz 1b
  513. /* Done! */
  514. /*--------------------------------------------------------------*/
  515. blr
  516. #endif
  517. /* Cache functions.
  518. *
  519. * Note: requires that all cache bits in
  520. * HID0 are in the low half word.
  521. */
  522. .globl icache_enable
  523. icache_enable:
  524. mfspr r3, HID0
  525. ori r3, r3, HID0_ICE
  526. lis r4, 0
  527. ori r4, r4, HID0_ILOCK
  528. andc r3, r3, r4
  529. ori r4, r3, HID0_ICFI
  530. isync
  531. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  532. isync
  533. mtspr HID0, r3 /* clears invalidate */
  534. blr
  535. .globl icache_disable
  536. icache_disable:
  537. mfspr r3, HID0
  538. lis r4, 0
  539. ori r4, r4, HID0_ICE|HID0_ILOCK
  540. andc r3, r3, r4
  541. ori r4, r3, HID0_ICFI
  542. isync
  543. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  544. isync
  545. mtspr HID0, r3 /* clears invalidate */
  546. blr
  547. .globl icache_status
  548. icache_status:
  549. mfspr r3, HID0
  550. rlwinm r3, r3, HID0_ICE_BITPOS + 1, 31, 31
  551. blr
  552. .globl dcache_enable
  553. dcache_enable:
  554. mfspr r3, HID0
  555. ori r3, r3, HID0_DCE
  556. lis r4, 0
  557. ori r4, r4, HID0_DLOCK
  558. andc r3, r3, r4
  559. ori r4, r3, HID0_DCI
  560. sync
  561. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  562. sync
  563. mtspr HID0, r3 /* clears invalidate */
  564. blr
  565. .globl dcache_disable
  566. dcache_disable:
  567. mfspr r3, HID0
  568. lis r4, 0
  569. ori r4, r4, HID0_DCE|HID0_DLOCK
  570. andc r3, r3, r4
  571. ori r4, r3, HID0_DCI
  572. sync
  573. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  574. sync
  575. mtspr HID0, r3 /* clears invalidate */
  576. blr
  577. .globl dcache_status
  578. dcache_status:
  579. mfspr r3, HID0
  580. rlwinm r3, r3, HID0_DCE_BITPOS + 1, 31, 31
  581. blr
  582. .globl get_pvr
  583. get_pvr:
  584. mfspr r3, PVR
  585. blr
  586. /*------------------------------------------------------------------------------*/
  587. /*
  588. * void relocate_code (addr_sp, gd, addr_moni)
  589. *
  590. * This "function" does not return, instead it continues in RAM
  591. * after relocating the monitor code.
  592. *
  593. * r3 = dest
  594. * r4 = src
  595. * r5 = length in bytes
  596. * r6 = cachelinesize
  597. */
  598. .globl relocate_code
  599. relocate_code:
  600. mr r1, r3 /* Set new stack pointer */
  601. mr r9, r4 /* Save copy of Global Data pointer */
  602. mr r10, r5 /* Save copy of Destination Address */
  603. GET_GOT
  604. mr r3, r5 /* Destination Address */
  605. lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  606. ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
  607. lwz r5, GOT(__init_end)
  608. sub r5, r5, r4
  609. li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  610. /*
  611. * Fix GOT pointer:
  612. *
  613. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  614. *
  615. * Offset:
  616. */
  617. sub r15, r10, r4
  618. /* First our own GOT */
  619. add r12, r12, r15
  620. /* then the one used by the C code */
  621. add r30, r30, r15
  622. /*
  623. * Now relocate code
  624. */
  625. cmplw cr1,r3,r4
  626. addi r0,r5,3
  627. srwi. r0,r0,2
  628. beq cr1,4f /* In place copy is not necessary */
  629. beq 7f /* Protect against 0 count */
  630. mtctr r0
  631. bge cr1,2f
  632. la r8,-4(r4)
  633. la r7,-4(r3)
  634. 1: lwzu r0,4(r8)
  635. stwu r0,4(r7)
  636. bdnz 1b
  637. b 4f
  638. 2: slwi r0,r0,2
  639. add r8,r4,r0
  640. add r7,r3,r0
  641. 3: lwzu r0,-4(r8)
  642. stwu r0,-4(r7)
  643. bdnz 3b
  644. /*
  645. * Now flush the cache: note that we must start from a cache aligned
  646. * address. Otherwise we might miss one cache line.
  647. */
  648. 4: cmpwi r6,0
  649. add r5,r3,r5
  650. beq 7f /* Always flush prefetch queue in any case */
  651. subi r0,r6,1
  652. andc r3,r3,r0
  653. mfspr r7,HID0 /* don't do dcbst if dcache is disabled */
  654. rlwinm r7,r7,HID0_DCE_BITPOS+1,31,31
  655. cmpwi r7,0
  656. beq 9f
  657. mr r4,r3
  658. 5: dcbst 0,r4
  659. add r4,r4,r6
  660. cmplw r4,r5
  661. blt 5b
  662. sync /* Wait for all dcbst to complete on bus */
  663. 9: mfspr r7,HID0 /* don't do icbi if icache is disabled */
  664. rlwinm r7,r7,HID0_ICE_BITPOS+1,31,31
  665. cmpwi r7,0
  666. beq 7f
  667. mr r4,r3
  668. 6: icbi 0,r4
  669. add r4,r4,r6
  670. cmplw r4,r5
  671. blt 6b
  672. 7: sync /* Wait for all icbi to complete on bus */
  673. isync
  674. /*
  675. * We are done. Do not return, instead branch to second part of board
  676. * initialization, now running from RAM.
  677. */
  678. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  679. mtlr r0
  680. blr
  681. in_ram:
  682. /*
  683. * Relocation Function, r12 point to got2+0x8000
  684. *
  685. * Adjust got2 pointers, no need to check for 0, this code
  686. * already puts a few entries in the table.
  687. */
  688. li r0,__got2_entries@sectoff@l
  689. la r3,GOT(_GOT2_TABLE_)
  690. lwz r11,GOT(_GOT2_TABLE_)
  691. mtctr r0
  692. sub r11,r3,r11
  693. addi r3,r3,-4
  694. 1: lwzu r0,4(r3)
  695. cmpwi r0,0
  696. beq- 2f
  697. add r0,r0,r11
  698. stw r0,0(r3)
  699. 2: bdnz 1b
  700. /*
  701. * Now adjust the fixups and the pointers to the fixups
  702. * in case we need to move ourselves again.
  703. */
  704. li r0,__fixup_entries@sectoff@l
  705. lwz r3,GOT(_FIXUP_TABLE_)
  706. cmpwi r0,0
  707. mtctr r0
  708. addi r3,r3,-4
  709. beq 4f
  710. 3: lwzu r4,4(r3)
  711. lwzux r0,r4,r11
  712. cmpwi r0,0
  713. add r0,r0,r11
  714. stw r4,0(r3)
  715. beq- 5f
  716. stw r0,0(r4)
  717. 5: bdnz 3b
  718. 4:
  719. clear_bss:
  720. /*
  721. * Now clear BSS segment
  722. */
  723. lwz r3,GOT(__bss_start)
  724. lwz r4,GOT(__bss_end)
  725. cmplw 0, r3, r4
  726. beq 6f
  727. li r0, 0
  728. 5:
  729. stw r0, 0(r3)
  730. addi r3, r3, 4
  731. cmplw 0, r3, r4
  732. bne 5b
  733. 6:
  734. mr r3, r9 /* Global Data pointer */
  735. mr r4, r10 /* Destination Address */
  736. bl board_init_r
  737. /*
  738. * Copy exception vector code to low memory
  739. *
  740. * r3: dest_addr
  741. * r7: source address, r8: end address, r9: target address
  742. */
  743. .globl trap_init
  744. trap_init:
  745. mflr r4 /* save link register */
  746. GET_GOT
  747. lwz r7, GOT(_start)
  748. lwz r8, GOT(_end_of_vectors)
  749. li r9, 0x100 /* reset vector always at 0x100 */
  750. cmplw 0, r7, r8
  751. bgelr /* return if r7>=r8 - just in case */
  752. 1:
  753. lwz r0, 0(r7)
  754. stw r0, 0(r9)
  755. addi r7, r7, 4
  756. addi r9, r9, 4
  757. cmplw 0, r7, r8
  758. bne 1b
  759. /*
  760. * relocate `hdlr' and `int_return' entries
  761. */
  762. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  763. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  764. 2:
  765. bl trap_reloc
  766. addi r7, r7, 0x100 /* next exception vector */
  767. cmplw 0, r7, r8
  768. blt 2b
  769. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  770. bl trap_reloc
  771. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  772. bl trap_reloc
  773. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  774. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  775. 3:
  776. bl trap_reloc
  777. addi r7, r7, 0x100 /* next exception vector */
  778. cmplw 0, r7, r8
  779. blt 3b
  780. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  781. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  782. 4:
  783. bl trap_reloc
  784. addi r7, r7, 0x100 /* next exception vector */
  785. cmplw 0, r7, r8
  786. blt 4b
  787. mfmsr r3 /* now that the vectors have */
  788. lis r7, MSR_IP@h /* relocated into low memory */
  789. ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
  790. andc r3, r3, r7 /* (if it was on) */
  791. SYNC /* Some chip revs need this... */
  792. mtmsr r3
  793. SYNC
  794. mtlr r4 /* restore link register */
  795. blr