start.S 27 KB

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