start.S 27 KB

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