start.S 26 KB

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