start.S 26 KB

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