start.S 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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. * Copyright 2004 Freescale Semiconductor, Inc.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. /*
  26. * U-Boot - Startup Code for MPC83xx PowerPC based Embedded Boards
  27. */
  28. #include <config.h>
  29. #include <mpc83xx.h>
  30. #include <version.h>
  31. #define CONFIG_83XX 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 "MPC83XX"
  39. #endif
  40. /* We don't want the MMU yet.
  41. */
  42. #undef MSR_KERNEL
  43. /*
  44. * Floating Point enable, Machine Check and Recoverable Interr.
  45. */
  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 r14 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. END_GOT
  67. /*
  68. * Version string - must be in data segment because MPC83xx uses the
  69. * first 256 bytes for the Hard Reset Configuration Word table (see
  70. * below). Similarly, can't have the U-Boot Magic Number as the first
  71. * thing in the image - don't know how this will affect the image tools,
  72. * but I guess I'll find out soon.
  73. */
  74. .data
  75. .globl version_string
  76. version_string:
  77. .ascii U_BOOT_VERSION
  78. .ascii " (", __DATE__, " - ", __TIME__, ")"
  79. .ascii " ", CONFIG_IDENT_STRING, "\0"
  80. .text
  81. #define _HRCW_TABLE_ENTRY(w) \
  82. .fill 8,1,(((w)>>24)&0xff); \
  83. .fill 8,1,(((w)>>16)&0xff); \
  84. .fill 8,1,(((w)>> 8)&0xff); \
  85. .fill 8,1,(((w) )&0xff)
  86. _HRCW_TABLE_ENTRY(CFG_HRCW_LOW)
  87. _HRCW_TABLE_ENTRY(CFG_HRCW_HIGH)
  88. #ifndef CONFIG_DEFAULT_IMMR
  89. #error CONFIG_DEFAULT_IMMR must be defined
  90. #endif /* CFG_DEFAULT_IMMR */
  91. #ifndef CFG_IMMRBAR
  92. #define CFG_IMMRBAR CONFIG_DEFAULT_IMMR
  93. #endif /* CFG_IMMRBAR */
  94. /*
  95. * After configuration, a system reset exception is executed using the
  96. * vector at offset 0x100 relative to the base set by MSR[IP]. If
  97. * MSR[IP] is 0, the base address is 0x00000000. If MSR[IP] is 1, the
  98. * base address is 0xfff00000. In the case of a Power On Reset or Hard
  99. * Reset, the value of MSR[IP] is determined by the CIP field in the
  100. * HRCW.
  101. *
  102. * Other bits in the HRCW set up the Base Address and Port Size in BR0.
  103. * This determines the location of the boot ROM (flash or EPROM) in the
  104. * processor's address space at boot time. As long as the HRCW is set up
  105. * so that we eventually end up executing the code below when the
  106. * processor executes the reset exception, the actual values used should
  107. * not matter.
  108. *
  109. * Once we have got here, the address mask in OR0 is cleared so that the
  110. * bottom 32K of the boot ROM is effectively repeated all throughout the
  111. * processor's address space, after which we can jump to the absolute
  112. * address at which the boot ROM was linked at compile time, and proceed
  113. * to initialise the memory controller without worrying if the rug will
  114. * be pulled out from under us, so to speak (it will be fine as long as
  115. * we configure BR0 with the same boot ROM link address).
  116. */
  117. . = EXC_OFF_SYS_RESET
  118. .globl _start
  119. _start: /* time t 0 */
  120. li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH*/
  121. nop
  122. b boot_cold
  123. . = EXC_OFF_SYS_RESET + 0x10
  124. .globl _start_warm
  125. _start_warm:
  126. li r21, BOOTFLAG_WARM /* Software reboot */
  127. b boot_warm
  128. boot_cold: /* time t 3 */
  129. lis r4, CONFIG_DEFAULT_IMMR@h
  130. nop
  131. boot_warm: /* time t 5 */
  132. mfmsr r5 /* save msr contents */
  133. lis r3, CFG_IMMRBAR@h
  134. ori r3, r3, CFG_IMMRBAR@l
  135. stw r3, IMMRBAR(r4)
  136. /* Initialise the E300 processor core */
  137. /*------------------------------------------*/
  138. bl init_e300_core
  139. #ifndef CFG_RAMBOOT
  140. /* Inflate flash location so it appears everywhere, calculate */
  141. /* the absolute address in final location of the FLASH, jump */
  142. /* there and deflate the flash size back to minimal size */
  143. /*------------------------------------------------------------*/
  144. bl map_flash_by_law1
  145. lis r4, (CFG_MONITOR_BASE)@h
  146. ori r4, r4, (CFG_MONITOR_BASE)@l
  147. addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
  148. mtlr r5
  149. blr
  150. in_flash:
  151. #if 1 /* Remapping flash with LAW0. */
  152. bl remap_flash_by_law0
  153. #endif
  154. #endif /* CFG_RAMBOOT */
  155. bl setup_stack_in_data_cache_on_r1
  156. /* let the C-code set up the rest */
  157. /* */
  158. /* Be careful to keep code relocatable & stack humble */
  159. /*------------------------------------------------------*/
  160. GET_GOT /* initialize GOT access */
  161. /* r3: IMMR */
  162. lis r3, CFG_IMMRBAR@h
  163. /* run low-level CPU init code (in Flash)*/
  164. bl cpu_init_f
  165. /* r3: BOOTFLAG */
  166. mr r3, r21
  167. /* run 1st part of board init code (in Flash)*/
  168. bl board_init_f
  169. /*
  170. * Vector Table
  171. */
  172. .globl _start_of_vectors
  173. _start_of_vectors:
  174. /* Machine check */
  175. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  176. /* Data Storage exception. */
  177. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  178. /* Instruction Storage exception. */
  179. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  180. /* External Interrupt exception. */
  181. #ifndef FIXME
  182. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  183. #endif
  184. /* Alignment exception. */
  185. . = 0x600
  186. Alignment:
  187. EXCEPTION_PROLOG
  188. mfspr r4,DAR
  189. stw r4,_DAR(r21)
  190. mfspr r5,DSISR
  191. stw r5,_DSISR(r21)
  192. addi r3,r1,STACK_FRAME_OVERHEAD
  193. li r20,MSR_KERNEL
  194. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  195. rlwimi r20,r23,0,25,25 /* copy IP bit from saved MSR */
  196. lwz r6,GOT(transfer_to_handler)
  197. mtlr r6
  198. blrl
  199. .L_Alignment:
  200. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  201. .long int_return - _start + EXC_OFF_SYS_RESET
  202. /* Program check exception */
  203. . = 0x700
  204. ProgramCheck:
  205. EXCEPTION_PROLOG
  206. addi r3,r1,STACK_FRAME_OVERHEAD
  207. li r20,MSR_KERNEL
  208. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  209. rlwimi r20,r23,0,25,25 /* copy IP bit from saved MSR */
  210. lwz r6,GOT(transfer_to_handler)
  211. mtlr r6
  212. blrl
  213. .L_ProgramCheck:
  214. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  215. .long int_return - _start + EXC_OFF_SYS_RESET
  216. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  217. /* I guess we could implement decrementer, and may have
  218. * to someday for timekeeping.
  219. */
  220. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  221. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  222. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  223. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  224. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  225. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  226. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  227. STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
  228. STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
  229. STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
  230. #ifdef DEBUG
  231. . = 0x1300
  232. /*
  233. * This exception occurs when the program counter matches the
  234. * Instruction Address Breakpoint Register (IABR).
  235. *
  236. * I want the cpu to halt if this occurs so I can hunt around
  237. * with the debugger and look at things.
  238. *
  239. * When DEBUG is defined, both machine check enable (in the MSR)
  240. * and checkstop reset enable (in the reset mode register) are
  241. * turned off and so a checkstop condition will result in the cpu
  242. * halting.
  243. *
  244. * I force the cpu into a checkstop condition by putting an illegal
  245. * instruction here (at least this is the theory).
  246. *
  247. * well - that didnt work, so just do an infinite loop!
  248. */
  249. 1: b 1b
  250. #else
  251. STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
  252. #endif
  253. STD_EXCEPTION(0x1400, SMI, UnknownException)
  254. STD_EXCEPTION(0x1500, Trap_15, UnknownException)
  255. STD_EXCEPTION(0x1600, Trap_16, UnknownException)
  256. STD_EXCEPTION(0x1700, Trap_17, UnknownException)
  257. STD_EXCEPTION(0x1800, Trap_18, UnknownException)
  258. STD_EXCEPTION(0x1900, Trap_19, UnknownException)
  259. STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
  260. STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
  261. STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
  262. STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
  263. STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
  264. STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
  265. STD_EXCEPTION(0x2000, Trap_20, UnknownException)
  266. STD_EXCEPTION(0x2100, Trap_21, UnknownException)
  267. STD_EXCEPTION(0x2200, Trap_22, UnknownException)
  268. STD_EXCEPTION(0x2300, Trap_23, UnknownException)
  269. STD_EXCEPTION(0x2400, Trap_24, UnknownException)
  270. STD_EXCEPTION(0x2500, Trap_25, UnknownException)
  271. STD_EXCEPTION(0x2600, Trap_26, UnknownException)
  272. STD_EXCEPTION(0x2700, Trap_27, UnknownException)
  273. STD_EXCEPTION(0x2800, Trap_28, UnknownException)
  274. STD_EXCEPTION(0x2900, Trap_29, UnknownException)
  275. STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
  276. STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
  277. STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
  278. STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
  279. STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
  280. STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
  281. .globl _end_of_vectors
  282. _end_of_vectors:
  283. . = 0x3000
  284. /*
  285. * This code finishes saving the registers to the exception frame
  286. * and jumps to the appropriate handler for the exception.
  287. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  288. */
  289. .globl transfer_to_handler
  290. transfer_to_handler:
  291. stw r22,_NIP(r21)
  292. lis r22,MSR_POW@h
  293. andc r23,r23,r22
  294. stw r23,_MSR(r21)
  295. SAVE_GPR(7, r21)
  296. SAVE_4GPRS(8, r21)
  297. SAVE_8GPRS(12, r21)
  298. SAVE_8GPRS(24, r21)
  299. mflr r23
  300. andi. r24,r23,0x3f00 /* get vector offset */
  301. stw r24,TRAP(r21)
  302. li r22,0
  303. stw r22,RESULT(r21)
  304. lwz r24,0(r23) /* virtual address of handler */
  305. lwz r23,4(r23) /* where to go when done */
  306. mtspr SRR0,r24
  307. mtspr SRR1,r20
  308. mtlr r23
  309. SYNC
  310. rfi /* jump to handler, enable MMU */
  311. int_return:
  312. mfmsr r28 /* Disable interrupts */
  313. li r4,0
  314. ori r4,r4,MSR_EE
  315. andc r28,r28,r4
  316. SYNC /* Some chip revs need this... */
  317. mtmsr r28
  318. SYNC
  319. lwz r2,_CTR(r1)
  320. lwz r0,_LINK(r1)
  321. mtctr r2
  322. mtlr r0
  323. lwz r2,_XER(r1)
  324. lwz r0,_CCR(r1)
  325. mtspr XER,r2
  326. mtcrf 0xFF,r0
  327. REST_10GPRS(3, r1)
  328. REST_10GPRS(13, r1)
  329. REST_8GPRS(23, r1)
  330. REST_GPR(31, r1)
  331. lwz r2,_NIP(r1) /* Restore environment */
  332. lwz r0,_MSR(r1)
  333. mtspr SRR0,r2
  334. mtspr SRR1,r0
  335. lwz r0,GPR0(r1)
  336. lwz r2,GPR2(r1)
  337. lwz r1,GPR1(r1)
  338. SYNC
  339. rfi
  340. /*
  341. * This code initialises the E300 processor core
  342. * (conforms to PowerPC 603e spec)
  343. * Note: expects original MSR contents to be in r5.
  344. */
  345. .globl init_e300_core
  346. init_e300_core: /* time t 10 */
  347. /* Initialize machine status; enable machine check interrupt */
  348. /*-----------------------------------------------------------*/
  349. li r3, MSR_KERNEL /* Set ME and RI flags */
  350. rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
  351. #ifdef DEBUG
  352. rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
  353. #endif
  354. SYNC /* Some chip revs need this... */
  355. mtmsr r3
  356. SYNC
  357. mtspr SRR1, r3 /* Make SRR1 match MSR */
  358. lis r3, CFG_IMMRBAR@h
  359. #if defined(CONFIG_WATCHDOG)
  360. /* Initialise the Wathcdog values and reset it (if req) */
  361. /*------------------------------------------------------*/
  362. lis r4, CFG_WATCHDOG_VALUE
  363. ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR)
  364. stw r4, SWCRR(r3)
  365. /* and reset it */
  366. li r4, 0x556C
  367. sth r4, SWSRR@l(r3)
  368. li r4, 0xAA39
  369. sth r4, SWSRR@l(r3)
  370. #else
  371. /* Disable Wathcdog */
  372. /*-------------------*/
  373. lwz r4, SWCRR(r3)
  374. /* Check to see if its enabled for disabling
  375. once disabled by SW you can't re-enable */
  376. andi. r4, r4, 0x4
  377. beq 1f
  378. xor r4, r4, r4
  379. stw r4, SWCRR(r3)
  380. 1:
  381. #endif /* CONFIG_WATCHDOG */
  382. /* Initialize the Hardware Implementation-dependent Registers */
  383. /* HID0 also contains cache control */
  384. /*------------------------------------------------------*/
  385. lis r3, CFG_HID0_INIT@h
  386. ori r3, r3, CFG_HID0_INIT@l
  387. SYNC
  388. mtspr HID0, r3
  389. lis r3, CFG_HID0_FINAL@h
  390. ori r3, r3, CFG_HID0_FINAL@l
  391. SYNC
  392. mtspr HID0, r3
  393. lis r3, CFG_HID2@h
  394. ori r3, r3, CFG_HID2@l
  395. SYNC
  396. mtspr HID2, r3
  397. /* clear all BAT's */
  398. /*----------------------------------*/
  399. xor r0, r0, r0
  400. mtspr DBAT0U, r0
  401. mtspr DBAT0L, r0
  402. mtspr DBAT1U, r0
  403. mtspr DBAT1L, r0
  404. mtspr DBAT2U, r0
  405. mtspr DBAT2L, r0
  406. mtspr DBAT3U, r0
  407. mtspr DBAT3L, r0
  408. mtspr IBAT0U, r0
  409. mtspr IBAT0L, r0
  410. mtspr IBAT1U, r0
  411. mtspr IBAT1L, r0
  412. mtspr IBAT2U, r0
  413. mtspr IBAT2L, r0
  414. mtspr IBAT3U, r0
  415. mtspr IBAT3L, r0
  416. SYNC
  417. /* invalidate all tlb's
  418. *
  419. * From the 603e User Manual: "The 603e provides the ability to
  420. * invalidate a TLB entry. The TLB Invalidate Entry (tlbie)
  421. * instruction invalidates the TLB entry indexed by the EA, and
  422. * operates on both the instruction and data TLBs simultaneously
  423. * invalidating four TLB entries (both sets in each TLB). The
  424. * index corresponds to bits 15-19 of the EA. To invalidate all
  425. * entries within both TLBs, 32 tlbie instructions should be
  426. * issued, incrementing this field by one each time."
  427. *
  428. * "Note that the tlbia instruction is not implemented on the
  429. * 603e."
  430. *
  431. * bits 15-19 correspond to addresses 0x00000000 to 0x0001F000
  432. * incrementing by 0x1000 each time. The code below is sort of
  433. * based on code in "flush_tlbs" from arch/ppc/kernel/head.S
  434. *
  435. */
  436. li r3, 32
  437. mtctr r3
  438. li r3, 0
  439. 1: tlbie r3
  440. addi r3, r3, 0x1000
  441. bdnz 1b
  442. SYNC
  443. /* Done! */
  444. /*------------------------------*/
  445. blr
  446. /* Cache functions.
  447. *
  448. * Note: requires that all cache bits in
  449. * HID0 are in the low half word.
  450. */
  451. .globl icache_enable
  452. icache_enable:
  453. mfspr r3, HID0
  454. ori r3, r3, HID0_ICE
  455. lis r4, 0
  456. ori r4, r4, HID0_ILOCK
  457. andc r3, r3, r4
  458. ori r4, r3, HID0_ICFI
  459. isync
  460. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  461. isync
  462. mtspr HID0, r3 /* clears invalidate */
  463. blr
  464. .globl icache_disable
  465. icache_disable:
  466. mfspr r3, HID0
  467. lis r4, 0
  468. ori r4, r4, HID0_ICE|HID0_ILOCK
  469. andc r3, r3, r4
  470. ori r4, r3, HID0_ICFI
  471. isync
  472. mtspr HID0, r4 /* sets invalidate, clears enable and lock*/
  473. isync
  474. mtspr HID0, r3 /* clears invalidate */
  475. blr
  476. .globl icache_status
  477. icache_status:
  478. mfspr r3, HID0
  479. rlwinm r3, r3, HID0_ICE_SHIFT, 31, 31
  480. blr
  481. .globl dcache_enable
  482. dcache_enable:
  483. mfspr r3, HID0
  484. ori r3, r3, HID0_ENABLE_DATA_CACHE
  485. lis r4, 0
  486. ori r4, r4, HID0_LOCK_DATA_CACHE
  487. andc r3, r3, r4
  488. ori r4, r3, HID0_LOCK_INSTRUCTION_CACHE
  489. sync
  490. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  491. sync
  492. mtspr HID0, r3 /* clears invalidate */
  493. blr
  494. .globl dcache_disable
  495. dcache_disable:
  496. mfspr r3, HID0
  497. lis r4, 0
  498. ori r4, r4, HID0_ENABLE_DATA_CACHE|HID0_LOCK_DATA_CACHE
  499. andc r3, r3, r4
  500. ori r4, r3, HID0_INVALIDATE_DATA_CACHE
  501. sync
  502. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  503. sync
  504. mtspr HID0, r3 /* clears invalidate */
  505. blr
  506. .globl dcache_status
  507. dcache_status:
  508. mfspr r3, HID0
  509. rlwinm r3, r3, HID0_DCE_SHIFT, 31, 31
  510. blr
  511. .globl get_pvr
  512. get_pvr:
  513. mfspr r3, PVR
  514. blr
  515. /*-------------------------------------------------------------------*/
  516. /*
  517. * void relocate_code (addr_sp, gd, addr_moni)
  518. *
  519. * This "function" does not return, instead it continues in RAM
  520. * after relocating the monitor code.
  521. *
  522. * r3 = dest
  523. * r4 = src
  524. * r5 = length in bytes
  525. * r6 = cachelinesize
  526. */
  527. .globl relocate_code
  528. relocate_code:
  529. mr r1, r3 /* Set new stack pointer */
  530. mr r9, r4 /* Save copy of Global Data pointer */
  531. mr r10, r5 /* Save copy of Destination Address */
  532. mr r3, r5 /* Destination Address */
  533. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  534. ori r4, r4, CFG_MONITOR_BASE@l
  535. lwz r5, GOT(__init_end)
  536. sub r5, r5, r4
  537. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  538. /*
  539. * Fix GOT pointer:
  540. *
  541. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE)
  542. * + Destination Address
  543. *
  544. * Offset:
  545. */
  546. sub r15, r10, r4
  547. /* First our own GOT */
  548. add r14, r14, r15
  549. /* then the one used by the C code */
  550. add r30, r30, r15
  551. /*
  552. * Now relocate code
  553. */
  554. cmplw cr1,r3,r4
  555. addi r0,r5,3
  556. srwi. r0,r0,2
  557. beq cr1,4f /* In place copy is not necessary */
  558. beq 7f /* Protect against 0 count */
  559. mtctr r0
  560. bge cr1,2f
  561. la r8,-4(r4)
  562. la r7,-4(r3)
  563. /* copy */
  564. 1: lwzu r0,4(r8)
  565. stwu r0,4(r7)
  566. bdnz 1b
  567. addi r0,r5,3
  568. srwi. r0,r0,2
  569. mtctr r0
  570. la r8,-4(r4)
  571. la r7,-4(r3)
  572. /* and compare */
  573. 20: lwzu r20,4(r8)
  574. lwzu r21,4(r7)
  575. xor. r22, r20, r21
  576. bne 30f
  577. bdnz 20b
  578. b 4f
  579. /* compare failed */
  580. 30: li r3, 0
  581. blr
  582. 2: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
  583. add r8,r4,r0
  584. add r7,r3,r0
  585. 3: lwzu r0,-4(r8)
  586. stwu r0,-4(r7)
  587. bdnz 3b
  588. /*
  589. * Now flush the cache: note that we must start from a cache aligned
  590. * address. Otherwise we might miss one cache line.
  591. */
  592. 4:
  593. bl un_setup_stack_in_data_cache
  594. mr r7, r3
  595. mr r8, r4
  596. bl dcache_disable
  597. mr r3, r7
  598. mr r4, r8
  599. cmpwi r6,0
  600. add r5,r3,r5
  601. beq 7f /* Always flush prefetch queue in any case */
  602. subi r0,r6,1
  603. andc r3,r3,r0
  604. mfspr r7,HID0 /* don't do dcbst if dcache is disabled*/
  605. rlwinm r7,r7,HID0_DCE_SHIFT,31,31
  606. cmpwi r7,0
  607. beq 9f
  608. mr r4,r3
  609. 5: dcbst 0,r4
  610. add r4,r4,r6
  611. cmplw r4,r5
  612. blt 5b
  613. sync /* Wait for all dcbst to complete on bus */
  614. 9: mfspr r7,HID0 /* don't do icbi if icache is disabled */
  615. rlwinm r7,r7,HID0_DCE_SHIFT,31,31
  616. cmpwi r7,0
  617. beq 7f
  618. mr r4,r3
  619. 6: icbi 0,r4
  620. add r4,r4,r6
  621. cmplw r4,r5
  622. blt 6b
  623. 7: sync /* Wait for all icbi to complete on bus */
  624. isync
  625. /*
  626. * We are done. Do not return, instead branch to second part of board
  627. * initialization, now running from RAM.
  628. */
  629. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  630. mtlr r0
  631. blr
  632. in_ram:
  633. /*
  634. * Relocation Function, r14 point to got2+0x8000
  635. *
  636. * Adjust got2 pointers, no need to check for 0, this code
  637. * already puts a few entries in the table.
  638. */
  639. li r0,__got2_entries@sectoff@l
  640. la r3,GOT(_GOT2_TABLE_)
  641. lwz r11,GOT(_GOT2_TABLE_)
  642. mtctr r0
  643. sub r11,r3,r11
  644. addi r3,r3,-4
  645. 1: lwzu r0,4(r3)
  646. add r0,r0,r11
  647. stw r0,0(r3)
  648. bdnz 1b
  649. /*
  650. * Now adjust the fixups and the pointers to the fixups
  651. * in case we need to move ourselves again.
  652. */
  653. 2: li r0,__fixup_entries@sectoff@l
  654. lwz r3,GOT(_FIXUP_TABLE_)
  655. cmpwi r0,0
  656. mtctr r0
  657. addi r3,r3,-4
  658. beq 4f
  659. 3: lwzu r4,4(r3)
  660. lwzux r0,r4,r11
  661. add r0,r0,r11
  662. stw r10,0(r3)
  663. stw r0,0(r4)
  664. bdnz 3b
  665. 4:
  666. clear_bss:
  667. /*
  668. * Now clear BSS segment
  669. */
  670. lwz r3,GOT(__bss_start)
  671. #if defined(CONFIG_HYMOD)
  672. /*
  673. * For HYMOD - the environment is the very last item in flash.
  674. * The real .bss stops just before environment starts, so only
  675. * clear up to that point.
  676. *
  677. * taken from mods for FADS board
  678. */
  679. lwz r4,GOT(environment)
  680. #else
  681. lwz r4,GOT(_end)
  682. #endif
  683. cmplw 0, r3, r4
  684. beq 6f
  685. li r0, 0
  686. 5:
  687. stw r0, 0(r3)
  688. addi r3, r3, 4
  689. cmplw 0, r3, r4
  690. bne 5b
  691. 6:
  692. mr r3, r9 /* Global Data pointer */
  693. mr r4, r10 /* Destination Address */
  694. bl board_init_r
  695. /*
  696. * Copy exception vector code to low memory
  697. *
  698. * r3: dest_addr
  699. * r7: source address, r8: end address, r9: target address
  700. */
  701. .globl trap_init
  702. trap_init:
  703. lwz r7, GOT(_start)
  704. lwz r8, GOT(_end_of_vectors)
  705. li r9, 0x100 /* reset vector always at 0x100 */
  706. cmplw 0, r7, r8
  707. bgelr /* return if r7>=r8 - just in case */
  708. mflr r4 /* save link register */
  709. 1:
  710. lwz r0, 0(r7)
  711. stw r0, 0(r9)
  712. addi r7, r7, 4
  713. addi r9, r9, 4
  714. cmplw 0, r7, r8
  715. bne 1b
  716. /*
  717. * relocate `hdlr' and `int_return' entries
  718. */
  719. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  720. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  721. 2:
  722. bl trap_reloc
  723. addi r7, r7, 0x100 /* next exception vector */
  724. cmplw 0, r7, r8
  725. blt 2b
  726. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  727. bl trap_reloc
  728. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  729. bl trap_reloc
  730. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  731. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  732. 3:
  733. bl trap_reloc
  734. addi r7, r7, 0x100 /* next exception vector */
  735. cmplw 0, r7, r8
  736. blt 3b
  737. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  738. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  739. 4:
  740. bl trap_reloc
  741. addi r7, r7, 0x100 /* next exception vector */
  742. cmplw 0, r7, r8
  743. blt 4b
  744. mfmsr r3 /* now that the vectors have */
  745. lis r7, MSR_IP@h /* relocated into low memory */
  746. ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
  747. andc r3, r3, r7 /* (if it was on) */
  748. SYNC /* Some chip revs need this... */
  749. mtmsr r3
  750. SYNC
  751. mtlr r4 /* restore link register */
  752. blr
  753. /*
  754. * Function: relocate entries for one exception vector
  755. */
  756. trap_reloc:
  757. lwz r0, 0(r7) /* hdlr ... */
  758. add r0, r0, r3 /* ... += dest_addr */
  759. stw r0, 0(r7)
  760. lwz r0, 4(r7) /* int_return ... */
  761. add r0, r0, r3 /* ... += dest_addr */
  762. stw r0, 4(r7)
  763. blr
  764. #ifdef CFG_INIT_RAM_LOCK
  765. .globl unlock_ram_in_cache
  766. unlock_ram_in_cache:
  767. /* invalidate the INIT_RAM section */
  768. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  769. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  770. li r2,512
  771. mtctr r2
  772. 1: icbi r0, r3
  773. dcbi r0, r3
  774. addi r3, r3, 32
  775. bdnz 1b
  776. sync /* Wait for all icbi to complete on bus */
  777. isync
  778. blr
  779. #endif
  780. map_flash_by_law1:
  781. /* When booting from ROM (Flash or EPROM), clear the */
  782. /* Address Mask in OR0 so ROM appears everywhere */
  783. /*----------------------------------------------------*/
  784. lis r3, (CFG_IMMRBAR)@h /* r3 <= CFG_IMMRBAR */
  785. lwz r4, OR0@l(r3)
  786. li r5, 0x7fff /* r5 <= 0x00007FFFF */
  787. and r4, r4, r5
  788. stw r4, OR0@l(r3) /* OR0 <= OR0 & 0x00007FFFF */
  789. /* As MPC8349E User's Manual presented, when RCW[BMS] is set to 0,
  790. * system will boot from 0x0000_0100, and the LBLAWBAR0[BASE_ADDR]
  791. * reset value is 0x00000; when RCW[BMS] is set to 1, system will boot
  792. * from 0xFFF0_0100, and the LBLAWBAR0[BASE_ADDR] reset value is
  793. * 0xFF800. From the hard resetting to here, the processor fetched and
  794. * executed the instructions one by one. There is not absolutely
  795. * jumping happened. Laterly, the u-boot code has to do an absolutely
  796. * jumping to tell the CPU instruction fetching component what the
  797. * u-boot TEXT base address is. Because the TEXT base resides in the
  798. * boot ROM memory space, to garantee the code can run smoothly after
  799. * that jumping, we must map in the entire boot ROM by Local Access
  800. * Window. Sometimes, we desire an non-0x00000 or non-0xFF800 starting
  801. * address for boot ROM, such as 0xFE000000. In this case, the default
  802. * LBIU Local Access Widow 0 will not cover this memory space. So, we
  803. * need another window to map in it.
  804. */
  805. lis r4, (CFG_FLASH_BASE)@h
  806. ori r4, r4, (CFG_FLASH_BASE)@l
  807. stw r4, LBLAWBAR1(r3) /* LBLAWBAR1 <= CFG_FLASH_BASE */
  808. lis r4, (0x80000016)@h
  809. ori r4, r4, (0x80000016)@l
  810. stw r4, LBLAWAR1(r3) /* LBLAWAR1 <= 8MB Flash Size */
  811. blr
  812. /* Though all the LBIU Local Access Windows and LBC Banks will be
  813. * initialized in the C code, we'd better configure boot ROM's
  814. * window 0 and bank 0 correctly at here.
  815. */
  816. remap_flash_by_law0:
  817. /* Initialize the BR0 with the boot ROM starting address. */
  818. lwz r4, BR0(r3)
  819. li r5, 0x7FFF
  820. and r4, r4, r5
  821. lis r5, (CFG_FLASH_BASE & 0xFFFF8000)@h
  822. ori r5, r5, (CFG_FLASH_BASE & 0xFFFF8000)@l
  823. or r5, r5, r4
  824. stw r5, BR0(r3) /* r5 <= (CFG_FLASH_BASE & 0xFFFF8000) | (BR0 & 0x00007FFF) */
  825. lwz r4, OR0(r3)
  826. lis r5, 0xFF80 /* 8M */
  827. or r4, r4, r5
  828. stw r4, OR0(r3) /* OR0 <= OR0 | 0xFF800000 */
  829. lis r4, (CFG_FLASH_BASE)@h
  830. ori r4, r4, (CFG_FLASH_BASE)@l
  831. stw r4, LBLAWBAR0(r3) /* LBLAWBAR0 <= CFG_FLASH_BASE */
  832. lis r4, (0x80000016)@h
  833. ori r4, r4, (0x80000016)@l
  834. stw r4, LBLAWAR0(r3) /* LBLAWAR0 <= 8MB Flash Size */
  835. xor r4, r4, r4
  836. stw r4, LBLAWBAR1(r3)
  837. stw r4, LBLAWAR1(r3) /* Off LBIU LAW1 */
  838. blr
  839. setup_stack_in_data_cache_on_r1:
  840. lis r3, (CFG_IMMRBAR)@h
  841. /* setup D-BAT for the D-Cache (with out real memory backup) */
  842. lis r4, (CFG_INIT_RAM_ADDR & 0xFFFE0000)@h
  843. mtspr DBAT0U, r4
  844. ori r4, r4, 0x0002
  845. mtspr DBAT0L, r4
  846. isync
  847. #if 0
  848. /* Enable MMU */
  849. mfmsr r4
  850. ori r4, r4, (MSR_DR | MSR_IR)@l
  851. mtmsr r4
  852. #endif
  853. /* Enable and invalidate data cache. */
  854. mfspr r4, HID0
  855. mr r5, r4
  856. ori r4, r4, HID0_DCE | HID0_DCI
  857. ori r5, r5, HID0_DCE
  858. sync
  859. mtspr HID0, r4
  860. mtspr HID0, r5
  861. sync
  862. /* Allocate Initial RAM in data cache.*/
  863. li r0, 0
  864. lis r4, (CFG_INIT_RAM_ADDR)@h
  865. ori r4, r4, (CFG_INIT_RAM_ADDR)@l
  866. li r5, 128*8 /* 128*8*32=32Kb */
  867. mtctr r5
  868. 1:
  869. dcbz r0, r4
  870. addi r4, r4, 32
  871. bdnz 1b
  872. isync
  873. /* Lock all the D-cache, basically leaving the reset of the program without dcache */
  874. mfspr r4, HID0
  875. ori r4, r4, (HID0_DLOCK)@l
  876. sync
  877. mtspr HID0 , r4
  878. /* setup the stack pointer in r1 */
  879. lis r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@h
  880. ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@l
  881. li r0, 0 /* Make room for stack frame header and */
  882. stwu r0, -4(r1) /* clear final stack frame so that */
  883. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  884. blr
  885. un_setup_stack_in_data_cache:
  886. blr
  887. mr r14, r4
  888. mr r15, r5
  889. lis r4, (CFG_INIT_RAM_ADDR & 0xFFFE0000)@h
  890. mtspr DBAT0U, r4
  891. ori r4, r4, 0x0002
  892. mtspr DBAT0L, r4
  893. isync
  894. /* un lock all the D-cache */
  895. mfspr r4, HID0
  896. lis r5, (~(HID0_DLOCK))@h
  897. ori r5, r5, (~(HID0_DLOCK))@l
  898. and r4, r4, r5
  899. sync
  900. mtspr HID0 , r4
  901. /* Re - Allocate Initial RAM in data cache.*/
  902. li r0, 0
  903. lis r4, (CFG_INIT_RAM_ADDR)@h
  904. ori r4, r4, (CFG_INIT_RAM_ADDR)@l
  905. li r5, 128*8 /* 128*8*32=32Kb */
  906. mtctr r5
  907. 1:
  908. dcbz r0, r4
  909. addi r4, r4, 32
  910. bdnz 1b
  911. isync
  912. mflr r16
  913. bl dcache_disable
  914. mtlr r16
  915. blr
  916. #if 0
  917. #define GREEN_LIGHT 0x2B0D4046
  918. #define RED_LIGHT 0x250D4046
  919. #define LIB_CNT 0x4FFF
  920. /*
  921. * Lib Light
  922. */
  923. .globl liblight
  924. liblight:
  925. lis r3, CFG_IMMRBAR@h
  926. ori r3, r3, CFG_IMMRBAR@l
  927. li r4, 0x3002
  928. mtmsr r4
  929. xor r4, r4, r4
  930. mtspr HID0, r4
  931. mtspr HID2, r4
  932. lis r4, 0xF8000000@h
  933. ori r4, r4, 0xF8000000@l
  934. stw r4, LBLAWBAR1(r3)
  935. lis r4, 0x8000000E@h
  936. ori r4, r4, 0x8000000E@l
  937. stw r4, LBLAWAR1(r3)
  938. lis r4, 0xF8000801@h
  939. ori r4, r4, 0xF8000801@l
  940. stw r4, BR1(r3)
  941. lis r4, 0xFFFFE8f0@h
  942. ori r4, r4, 0xFFFFE8f0@l
  943. stw r4, OR1(r3)
  944. lis r4, 0xF8000000@h
  945. ori r4, r4, 0xF8000000@l
  946. lis r5, GREEN_LIGHT@h
  947. ori r5, r5, GREEN_LIGHT@l
  948. lis r6, RED_LIGHT@h
  949. ori r6, r6, RED_LIGHT@l
  950. lis r7, LIB_CNT@h
  951. ori r7, r7, LIB_CNT@l
  952. 1:
  953. stw r5, 0(r4)
  954. mtctr r7
  955. 2: bdnz 2b
  956. stw r6, 0(r4)
  957. mtctr r7
  958. 3: bdnz 3b
  959. b 1b
  960. #endif