start.S 27 KB

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