start.S 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  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. EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
  252. /* Program check exception */
  253. . = 0x700
  254. ProgramCheck:
  255. EXCEPTION_PROLOG(SRR0, SRR1)
  256. addi r3,r1,STACK_FRAME_OVERHEAD
  257. EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
  258. MSR_KERNEL, COPY_EE)
  259. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  260. /* I guess we could implement decrementer, and may have
  261. * to someday for timekeeping.
  262. */
  263. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  264. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  265. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  266. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  267. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  268. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  269. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  270. STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
  271. STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
  272. STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
  273. #ifdef DEBUG
  274. . = 0x1300
  275. /*
  276. * This exception occurs when the program counter matches the
  277. * Instruction Address Breakpoint Register (IABR).
  278. *
  279. * I want the cpu to halt if this occurs so I can hunt around
  280. * with the debugger and look at things.
  281. *
  282. * When DEBUG is defined, both machine check enable (in the MSR)
  283. * and checkstop reset enable (in the reset mode register) are
  284. * turned off and so a checkstop condition will result in the cpu
  285. * halting.
  286. *
  287. * I force the cpu into a checkstop condition by putting an illegal
  288. * instruction here (at least this is the theory).
  289. *
  290. * well - that didnt work, so just do an infinite loop!
  291. */
  292. 1: b 1b
  293. #else
  294. STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
  295. #endif
  296. STD_EXCEPTION(0x1400, SMI, UnknownException)
  297. STD_EXCEPTION(0x1500, Trap_15, UnknownException)
  298. STD_EXCEPTION(0x1600, Trap_16, UnknownException)
  299. STD_EXCEPTION(0x1700, Trap_17, UnknownException)
  300. STD_EXCEPTION(0x1800, Trap_18, UnknownException)
  301. STD_EXCEPTION(0x1900, Trap_19, UnknownException)
  302. STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
  303. STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
  304. STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
  305. STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
  306. STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
  307. STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
  308. STD_EXCEPTION(0x2000, Trap_20, UnknownException)
  309. STD_EXCEPTION(0x2100, Trap_21, UnknownException)
  310. STD_EXCEPTION(0x2200, Trap_22, UnknownException)
  311. STD_EXCEPTION(0x2300, Trap_23, UnknownException)
  312. STD_EXCEPTION(0x2400, Trap_24, UnknownException)
  313. STD_EXCEPTION(0x2500, Trap_25, UnknownException)
  314. STD_EXCEPTION(0x2600, Trap_26, UnknownException)
  315. STD_EXCEPTION(0x2700, Trap_27, UnknownException)
  316. STD_EXCEPTION(0x2800, Trap_28, UnknownException)
  317. STD_EXCEPTION(0x2900, Trap_29, UnknownException)
  318. STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
  319. STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
  320. STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
  321. STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
  322. STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
  323. STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
  324. .globl _end_of_vectors
  325. _end_of_vectors:
  326. . = 0x3000
  327. /*
  328. * This code finishes saving the registers to the exception frame
  329. * and jumps to the appropriate handler for the exception.
  330. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  331. */
  332. .globl transfer_to_handler
  333. transfer_to_handler:
  334. stw r22,_NIP(r21)
  335. lis r22,MSR_POW@h
  336. andc r23,r23,r22
  337. stw r23,_MSR(r21)
  338. SAVE_GPR(7, r21)
  339. SAVE_4GPRS(8, r21)
  340. SAVE_8GPRS(12, r21)
  341. SAVE_8GPRS(24, r21)
  342. mflr r23
  343. andi. r24,r23,0x3f00 /* get vector offset */
  344. stw r24,TRAP(r21)
  345. li r22,0
  346. stw r22,RESULT(r21)
  347. lwz r24,0(r23) /* virtual address of handler */
  348. lwz r23,4(r23) /* where to go when done */
  349. mtspr SRR0,r24
  350. mtspr SRR1,r20
  351. mtlr r23
  352. SYNC
  353. rfi /* jump to handler, enable MMU */
  354. int_return:
  355. mfmsr r28 /* Disable interrupts */
  356. li r4,0
  357. ori r4,r4,MSR_EE
  358. andc r28,r28,r4
  359. SYNC /* Some chip revs need this... */
  360. mtmsr r28
  361. SYNC
  362. lwz r2,_CTR(r1)
  363. lwz r0,_LINK(r1)
  364. mtctr r2
  365. mtlr r0
  366. lwz r2,_XER(r1)
  367. lwz r0,_CCR(r1)
  368. mtspr XER,r2
  369. mtcrf 0xFF,r0
  370. REST_10GPRS(3, r1)
  371. REST_10GPRS(13, r1)
  372. REST_8GPRS(23, r1)
  373. REST_GPR(31, r1)
  374. lwz r2,_NIP(r1) /* Restore environment */
  375. lwz r0,_MSR(r1)
  376. mtspr SRR0,r2
  377. mtspr SRR1,r0
  378. lwz r0,GPR0(r1)
  379. lwz r2,GPR2(r1)
  380. lwz r1,GPR1(r1)
  381. SYNC
  382. rfi
  383. #if defined(CONFIG_COGENT)
  384. /*
  385. * This code initialises the MPC8260 processor core
  386. * (conforms to PowerPC 603e spec)
  387. */
  388. .globl cogent_init_8260
  389. cogent_init_8260:
  390. /* Taken from page 14 of CMA282 manual */
  391. /*--------------------------------------------------------------*/
  392. lis r4, (CONFIG_SYS_IMMR+IM_REGBASE)@h
  393. lis r3, CONFIG_SYS_IMMR@h
  394. stw r3, IM_IMMR@l(r4)
  395. lwz r3, IM_IMMR@l(r4)
  396. stw r3, 0(r0)
  397. lis r3, CONFIG_SYS_SYPCR@h
  398. ori r3, r3, CONFIG_SYS_SYPCR@l
  399. stw r3, IM_SYPCR@l(r4)
  400. lwz r3, IM_SYPCR@l(r4)
  401. stw r3, 4(r0)
  402. lis r3, CONFIG_SYS_SCCR@h
  403. ori r3, r3, CONFIG_SYS_SCCR@l
  404. stw r3, IM_SCCR@l(r4)
  405. lwz r3, IM_SCCR@l(r4)
  406. stw r3, 8(r0)
  407. /* the rest of this was disassembled from the */
  408. /* EPROM code that came with my CMA282 CPU module */
  409. /*--------------------------------------------------------------*/
  410. lis r1, 0x1234
  411. ori r1, r1, 0x5678
  412. stw r1, 0x20(r0)
  413. lwz r1, 0x20(r0)
  414. stw r1, 0x24(r0)
  415. lwz r1, 0x24(r0)
  416. lis r3, 0x0e80
  417. ori r3, r3, 0
  418. stw r1, 4(r3)
  419. lwz r1, 4(r3)
  420. /* Done! */
  421. /*--------------------------------------------------------------*/
  422. blr
  423. #endif /* CONFIG_COGENT */
  424. /*
  425. * This code initialises the MPC8260 processor core
  426. * (conforms to PowerPC 603e spec)
  427. * Note: expects original MSR contents to be in r5.
  428. */
  429. .globl init_8260_core
  430. init_8260_core:
  431. /* Initialize machine status; enable machine check interrupt */
  432. /*--------------------------------------------------------------*/
  433. li r3, MSR_KERNEL /* Set ME and RI flags */
  434. rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
  435. #ifdef DEBUG
  436. rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
  437. #endif
  438. SYNC /* Some chip revs need this... */
  439. mtmsr r3
  440. SYNC
  441. mtspr SRR1, r3 /* Make SRR1 match MSR */
  442. /* Initialise the SYPCR early, and reset the watchdog (if req) */
  443. /*--------------------------------------------------------------*/
  444. lis r3, (CONFIG_SYS_IMMR+IM_REGBASE)@h
  445. #if !defined(CONFIG_COGENT)
  446. lis r4, CONFIG_SYS_SYPCR@h
  447. ori r4, r4, CONFIG_SYS_SYPCR@l
  448. stw r4, IM_SYPCR@l(r3)
  449. #endif /* !CONFIG_COGENT */
  450. #if defined(CONFIG_WATCHDOG)
  451. li r4, 21868 /* = 0x556c */
  452. sth r4, IM_SWSR@l(r3)
  453. li r4, -21959 /* = 0xaa39 */
  454. sth r4, IM_SWSR@l(r3)
  455. #endif /* CONFIG_WATCHDOG */
  456. /* Initialize the Hardware Implementation-dependent Registers */
  457. /* HID0 also contains cache control */
  458. /*--------------------------------------------------------------*/
  459. lis r3, CONFIG_SYS_HID0_INIT@h
  460. ori r3, r3, CONFIG_SYS_HID0_INIT@l
  461. SYNC
  462. mtspr HID0, r3
  463. lis r3, CONFIG_SYS_HID0_FINAL@h
  464. ori r3, r3, CONFIG_SYS_HID0_FINAL@l
  465. SYNC
  466. mtspr HID0, r3
  467. lis r3, CONFIG_SYS_HID2@h
  468. ori r3, r3, CONFIG_SYS_HID2@l
  469. mtspr HID2, r3
  470. /* clear all BAT's */
  471. /*--------------------------------------------------------------*/
  472. li r0, 0
  473. mtspr DBAT0U, r0
  474. mtspr DBAT0L, r0
  475. mtspr DBAT1U, r0
  476. mtspr DBAT1L, r0
  477. mtspr DBAT2U, r0
  478. mtspr DBAT2L, r0
  479. mtspr DBAT3U, r0
  480. mtspr DBAT3L, r0
  481. mtspr IBAT0U, r0
  482. mtspr IBAT0L, r0
  483. mtspr IBAT1U, r0
  484. mtspr IBAT1L, r0
  485. mtspr IBAT2U, r0
  486. mtspr IBAT2L, r0
  487. mtspr IBAT3U, r0
  488. mtspr IBAT3L, r0
  489. SYNC
  490. /* invalidate all tlb's */
  491. /* */
  492. /* From the 603e User Manual: "The 603e provides the ability to */
  493. /* invalidate a TLB entry. The TLB Invalidate Entry (tlbie) */
  494. /* instruction invalidates the TLB entry indexed by the EA, and */
  495. /* operates on both the instruction and data TLBs simultaneously*/
  496. /* invalidating four TLB entries (both sets in each TLB). The */
  497. /* index corresponds to bits 15-19 of the EA. To invalidate all */
  498. /* entries within both TLBs, 32 tlbie instructions should be */
  499. /* issued, incrementing this field by one each time." */
  500. /* */
  501. /* "Note that the tlbia instruction is not implemented on the */
  502. /* 603e." */
  503. /* */
  504. /* bits 15-19 correspond to addresses 0x00000000 to 0x0001F000 */
  505. /* incrementing by 0x1000 each time. The code below is sort of */
  506. /* based on code in "flush_tlbs" from arch/ppc/kernel/head.S */
  507. /* */
  508. /*--------------------------------------------------------------*/
  509. li r3, 32
  510. mtctr r3
  511. li r3, 0
  512. 1: tlbie r3
  513. addi r3, r3, 0x1000
  514. bdnz 1b
  515. SYNC
  516. /* Done! */
  517. /*--------------------------------------------------------------*/
  518. blr
  519. #ifdef DEBUG
  520. /*
  521. * initialise things related to debugging.
  522. *
  523. * must be called after the global offset table (GOT) is initialised
  524. * (GET_GOT) and after cpu_init_f() has executed.
  525. */
  526. .globl init_debug
  527. init_debug:
  528. lis r3, (CONFIG_SYS_IMMR+IM_REGBASE)@h
  529. /* Quick and dirty hack to enable the RAM and copy the */
  530. /* vectors so that we can take exceptions. */
  531. /*--------------------------------------------------------------*/
  532. /* write Memory Refresh Prescaler */
  533. li r4, CONFIG_SYS_MPTPR
  534. sth r4, IM_MPTPR@l(r3)
  535. /* write 60x Refresh Timer */
  536. li r4, CONFIG_SYS_PSRT
  537. stb r4, IM_PSRT@l(r3)
  538. /* init the 60x SDRAM Mode Register */
  539. lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_NORM)@h
  540. ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_NORM)@l
  541. stw r4, IM_PSDMR@l(r3)
  542. /* write Precharge All Banks command */
  543. lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_PREA)@h
  544. ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_PREA)@l
  545. stw r4, IM_PSDMR@l(r3)
  546. stb r0, 0(0)
  547. /* write eight CBR Refresh commands */
  548. lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_CBRR)@h
  549. ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_CBRR)@l
  550. stw r4, IM_PSDMR@l(r3)
  551. stb r0, 0(0)
  552. stb r0, 0(0)
  553. stb r0, 0(0)
  554. stb r0, 0(0)
  555. stb r0, 0(0)
  556. stb r0, 0(0)
  557. stb r0, 0(0)
  558. stb r0, 0(0)
  559. /* write Mode Register Write command */
  560. lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_MRW)@h
  561. ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_MRW)@l
  562. stw r4, IM_PSDMR@l(r3)
  563. stb r0, 0(0)
  564. /* write Normal Operation command and enable Refresh */
  565. lis r4, (CONFIG_SYS_PSDMR|PSDMR_OP_NORM|PSDMR_RFEN)@h
  566. ori r4, r4, (CONFIG_SYS_PSDMR|PSDMR_OP_NORM|PSDMR_RFEN)@l
  567. stw r4, IM_PSDMR@l(r3)
  568. stb r0, 0(0)
  569. /* RAM should now be operational */
  570. #define VEC_WRD_CNT ((_end_of_vectors - _start + EXC_OFF_SYS_RESET) / 4)
  571. lwz r3, GOT(_end_of_vectors)
  572. rlwinm r4, r3, 0, 18, 31 /* _end_of_vectors & 0x3FFF */
  573. lis r5, VEC_WRD_CNT@h
  574. ori r5, r5, VEC_WRD_CNT@l
  575. mtctr r5
  576. 1:
  577. lwzu r5, -4(r3)
  578. stwu r5, -4(r4)
  579. bdnz 1b
  580. /* Load the Instruction Address Breakpoint Register (IABR). */
  581. /* */
  582. /* The address to load is stored in the first word of dual port */
  583. /* ram and should be preserved while the power is on, so you */
  584. /* can plug addresses into that location then reset the cpu and */
  585. /* this code will load that address into the IABR after the */
  586. /* reset. */
  587. /* */
  588. /* When the program counter matches the contents of the IABR, */
  589. /* an exception is generated (before the instruction at that */
  590. /* location completes). The vector for this exception is 0x1300 */
  591. /*--------------------------------------------------------------*/
  592. lis r3, CONFIG_SYS_IMMR@h
  593. lwz r3, 0(r3)
  594. mtspr IABR, r3
  595. /* Set the entire dual port RAM (where the initial stack */
  596. /* resides) to a known value - makes it easier to see where */
  597. /* the stack has been written */
  598. /*--------------------------------------------------------------*/
  599. lis r3, (CONFIG_SYS_IMMR + CONFIG_SYS_INIT_SP_OFFSET)@h
  600. ori r3, r3, (CONFIG_SYS_IMMR + CONFIG_SYS_INIT_SP_OFFSET)@l
  601. li r4, ((CONFIG_SYS_INIT_SP_OFFSET - 4) / 4)
  602. mtctr r4
  603. lis r4, 0xdeadbeaf@h
  604. ori r4, r4, 0xdeadbeaf@l
  605. 1:
  606. stwu r4, -4(r3)
  607. bdnz 1b
  608. /* Done! */
  609. /*--------------------------------------------------------------*/
  610. blr
  611. #endif
  612. /* Cache functions.
  613. *
  614. * Note: requires that all cache bits in
  615. * HID0 are in the low half word.
  616. */
  617. .globl icache_enable
  618. icache_enable:
  619. mfspr r3, HID0
  620. ori r3, r3, HID0_ICE
  621. lis r4, 0
  622. ori r4, r4, HID0_ILOCK
  623. andc r3, r3, r4
  624. ori r4, r3, HID0_ICFI
  625. isync
  626. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  627. isync
  628. mtspr HID0, r3 /* clears invalidate */
  629. blr
  630. .globl icache_disable
  631. icache_disable:
  632. mfspr r3, HID0
  633. lis r4, 0
  634. ori r4, r4, HID0_ICE|HID0_ILOCK
  635. andc r3, r3, r4
  636. ori r4, r3, HID0_ICFI
  637. isync
  638. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  639. isync
  640. mtspr HID0, r3 /* clears invalidate */
  641. blr
  642. .globl icache_status
  643. icache_status:
  644. mfspr r3, HID0
  645. rlwinm r3, r3, HID0_ICE_BITPOS + 1, 31, 31
  646. blr
  647. .globl dcache_enable
  648. dcache_enable:
  649. mfspr r3, HID0
  650. ori r3, r3, HID0_DCE
  651. lis r4, 0
  652. ori r4, r4, HID0_DLOCK
  653. andc r3, r3, r4
  654. ori r4, r3, HID0_DCI
  655. sync
  656. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  657. sync
  658. mtspr HID0, r3 /* clears invalidate */
  659. blr
  660. .globl dcache_disable
  661. dcache_disable:
  662. mfspr r3, HID0
  663. lis r4, 0
  664. ori r4, r4, HID0_DCE|HID0_DLOCK
  665. andc r3, r3, r4
  666. ori r4, r3, HID0_DCI
  667. sync
  668. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  669. sync
  670. mtspr HID0, r3 /* clears invalidate */
  671. blr
  672. .globl dcache_status
  673. dcache_status:
  674. mfspr r3, HID0
  675. rlwinm r3, r3, HID0_DCE_BITPOS + 1, 31, 31
  676. blr
  677. .globl get_pvr
  678. get_pvr:
  679. mfspr r3, PVR
  680. blr
  681. /*------------------------------------------------------------------------------*/
  682. /*
  683. * void relocate_code (addr_sp, gd, addr_moni)
  684. *
  685. * This "function" does not return, instead it continues in RAM
  686. * after relocating the monitor code.
  687. *
  688. * r3 = dest
  689. * r4 = src
  690. * r5 = length in bytes
  691. * r6 = cachelinesize
  692. */
  693. .globl relocate_code
  694. relocate_code:
  695. mr r1, r3 /* Set new stack pointer */
  696. mr r9, r4 /* Save copy of Global Data pointer */
  697. mr r10, r5 /* Save copy of Destination Address */
  698. mr r3, r5 /* Destination Address */
  699. lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  700. ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
  701. lwz r5, GOT(__init_end)
  702. sub r5, r5, r4
  703. li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  704. /*
  705. * Fix GOT pointer:
  706. *
  707. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  708. *
  709. * Offset:
  710. */
  711. sub r15, r10, r4
  712. /* First our own GOT */
  713. add r14, r14, r15
  714. /* then the one used by the C code */
  715. add r30, r30, r15
  716. /*
  717. * Now relocate code
  718. */
  719. cmplw cr1,r3,r4
  720. addi r0,r5,3
  721. srwi. r0,r0,2
  722. beq cr1,4f /* In place copy is not necessary */
  723. beq 7f /* Protect against 0 count */
  724. mtctr r0
  725. bge cr1,2f
  726. la r8,-4(r4)
  727. la r7,-4(r3)
  728. 1: lwzu r0,4(r8)
  729. stwu r0,4(r7)
  730. bdnz 1b
  731. b 4f
  732. 2: slwi r0,r0,2
  733. add r8,r4,r0
  734. add r7,r3,r0
  735. 3: lwzu r0,-4(r8)
  736. stwu r0,-4(r7)
  737. bdnz 3b
  738. /*
  739. * Now flush the cache: note that we must start from a cache aligned
  740. * address. Otherwise we might miss one cache line.
  741. */
  742. 4: cmpwi r6,0
  743. add r5,r3,r5
  744. beq 7f /* Always flush prefetch queue in any case */
  745. subi r0,r6,1
  746. andc r3,r3,r0
  747. mfspr r7,HID0 /* don't do dcbst if dcache is disabled */
  748. rlwinm r7,r7,HID0_DCE_BITPOS+1,31,31
  749. cmpwi r7,0
  750. beq 9f
  751. mr r4,r3
  752. 5: dcbst 0,r4
  753. add r4,r4,r6
  754. cmplw r4,r5
  755. blt 5b
  756. sync /* Wait for all dcbst to complete on bus */
  757. 9: mfspr r7,HID0 /* don't do icbi if icache is disabled */
  758. rlwinm r7,r7,HID0_ICE_BITPOS+1,31,31
  759. cmpwi r7,0
  760. beq 7f
  761. mr r4,r3
  762. 6: icbi 0,r4
  763. add r4,r4,r6
  764. cmplw r4,r5
  765. blt 6b
  766. 7: sync /* Wait for all icbi to complete on bus */
  767. isync
  768. /*
  769. * We are done. Do not return, instead branch to second part of board
  770. * initialization, now running from RAM.
  771. */
  772. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  773. mtlr r0
  774. blr
  775. in_ram:
  776. /*
  777. * Relocation Function, r14 point to got2+0x8000
  778. *
  779. * Adjust got2 pointers, no need to check for 0, this code
  780. * already puts a few entries in the table.
  781. */
  782. li r0,__got2_entries@sectoff@l
  783. la r3,GOT(_GOT2_TABLE_)
  784. lwz r11,GOT(_GOT2_TABLE_)
  785. mtctr r0
  786. sub r11,r3,r11
  787. addi r3,r3,-4
  788. 1: lwzu r0,4(r3)
  789. cmpwi r0,0
  790. beq- 2f
  791. add r0,r0,r11
  792. stw r0,0(r3)
  793. 2: bdnz 1b
  794. /*
  795. * Now adjust the fixups and the pointers to the fixups
  796. * in case we need to move ourselves again.
  797. */
  798. li r0,__fixup_entries@sectoff@l
  799. lwz r3,GOT(_FIXUP_TABLE_)
  800. cmpwi r0,0
  801. mtctr r0
  802. addi r3,r3,-4
  803. beq 4f
  804. 3: lwzu r4,4(r3)
  805. lwzux r0,r4,r11
  806. add r0,r0,r11
  807. stw r10,0(r3)
  808. stw r0,0(r4)
  809. bdnz 3b
  810. 4:
  811. clear_bss:
  812. /*
  813. * Now clear BSS segment
  814. */
  815. lwz r3,GOT(__bss_start)
  816. #if defined(CONFIG_HYMOD)
  817. /*
  818. * For HYMOD - the environment is the very last item in flash.
  819. * The real .bss stops just before environment starts, so only
  820. * clear up to that point.
  821. *
  822. * taken from mods for FADS board
  823. */
  824. lwz r4,GOT(environment)
  825. #else
  826. lwz r4,GOT(_end)
  827. #endif
  828. cmplw 0, r3, r4
  829. beq 6f
  830. li r0, 0
  831. 5:
  832. stw r0, 0(r3)
  833. addi r3, r3, 4
  834. cmplw 0, r3, r4
  835. bne 5b
  836. 6:
  837. mr r3, r9 /* Global Data pointer */
  838. mr r4, r10 /* Destination Address */
  839. bl board_init_r
  840. /*
  841. * Copy exception vector code to low memory
  842. *
  843. * r3: dest_addr
  844. * r7: source address, r8: end address, r9: target address
  845. */
  846. .globl trap_init
  847. trap_init:
  848. lwz r7, GOT(_start)
  849. lwz r8, GOT(_end_of_vectors)
  850. li r9, 0x100 /* reset vector always at 0x100 */
  851. cmplw 0, r7, r8
  852. bgelr /* return if r7>=r8 - just in case */
  853. mflr r4 /* save link register */
  854. 1:
  855. lwz r0, 0(r7)
  856. stw r0, 0(r9)
  857. addi r7, r7, 4
  858. addi r9, r9, 4
  859. cmplw 0, r7, r8
  860. bne 1b
  861. /*
  862. * relocate `hdlr' and `int_return' entries
  863. */
  864. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  865. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  866. 2:
  867. bl trap_reloc
  868. addi r7, r7, 0x100 /* next exception vector */
  869. cmplw 0, r7, r8
  870. blt 2b
  871. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  872. bl trap_reloc
  873. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  874. bl trap_reloc
  875. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  876. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  877. 3:
  878. bl trap_reloc
  879. addi r7, r7, 0x100 /* next exception vector */
  880. cmplw 0, r7, r8
  881. blt 3b
  882. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  883. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  884. 4:
  885. bl trap_reloc
  886. addi r7, r7, 0x100 /* next exception vector */
  887. cmplw 0, r7, r8
  888. blt 4b
  889. mfmsr r3 /* now that the vectors have */
  890. lis r7, MSR_IP@h /* relocated into low memory */
  891. ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
  892. andc r3, r3, r7 /* (if it was on) */
  893. SYNC /* Some chip revs need this... */
  894. mtmsr r3
  895. SYNC
  896. mtlr r4 /* restore link register */
  897. blr