start.S 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  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. xor r4, r4, r4
  374. stw r4, SWCRR(r3)
  375. #endif /* CONFIG_WATCHDOG */
  376. /* Initialize the Hardware Implementation-dependent Registers */
  377. /* HID0 also contains cache control */
  378. /*------------------------------------------------------*/
  379. lis r3, CFG_HID0_INIT@h
  380. ori r3, r3, CFG_HID0_INIT@l
  381. SYNC
  382. mtspr HID0, r3
  383. lis r3, CFG_HID0_FINAL@h
  384. ori r3, r3, CFG_HID0_FINAL@l
  385. SYNC
  386. mtspr HID0, r3
  387. lis r3, CFG_HID2@h
  388. ori r3, r3, CFG_HID2@l
  389. SYNC
  390. mtspr HID2, r3
  391. /* clear all BAT's */
  392. /*----------------------------------*/
  393. xor r0, r0, r0
  394. mtspr DBAT0U, r0
  395. mtspr DBAT0L, r0
  396. mtspr DBAT1U, r0
  397. mtspr DBAT1L, r0
  398. mtspr DBAT2U, r0
  399. mtspr DBAT2L, r0
  400. mtspr DBAT3U, r0
  401. mtspr DBAT3L, r0
  402. mtspr IBAT0U, r0
  403. mtspr IBAT0L, r0
  404. mtspr IBAT1U, r0
  405. mtspr IBAT1L, r0
  406. mtspr IBAT2U, r0
  407. mtspr IBAT2L, r0
  408. mtspr IBAT3U, r0
  409. mtspr IBAT3L, r0
  410. SYNC
  411. /* invalidate all tlb's
  412. *
  413. * From the 603e User Manual: "The 603e provides the ability to
  414. * invalidate a TLB entry. The TLB Invalidate Entry (tlbie)
  415. * instruction invalidates the TLB entry indexed by the EA, and
  416. * operates on both the instruction and data TLBs simultaneously
  417. * invalidating four TLB entries (both sets in each TLB). The
  418. * index corresponds to bits 15-19 of the EA. To invalidate all
  419. * entries within both TLBs, 32 tlbie instructions should be
  420. * issued, incrementing this field by one each time."
  421. *
  422. * "Note that the tlbia instruction is not implemented on the
  423. * 603e."
  424. *
  425. * bits 15-19 correspond to addresses 0x00000000 to 0x0001F000
  426. * incrementing by 0x1000 each time. The code below is sort of
  427. * based on code in "flush_tlbs" from arch/ppc/kernel/head.S
  428. *
  429. */
  430. li r3, 32
  431. mtctr r3
  432. li r3, 0
  433. 1: tlbie r3
  434. addi r3, r3, 0x1000
  435. bdnz 1b
  436. SYNC
  437. /* Done! */
  438. /*------------------------------*/
  439. blr
  440. /* Cache functions.
  441. *
  442. * Note: requires that all cache bits in
  443. * HID0 are in the low half word.
  444. */
  445. .globl icache_enable
  446. icache_enable:
  447. mfspr r3, HID0
  448. ori r3, r3, HID0_ICE
  449. lis r4, 0
  450. ori r4, r4, HID0_ILOCK
  451. andc r3, r3, r4
  452. ori r4, r3, HID0_ICFI
  453. isync
  454. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  455. isync
  456. mtspr HID0, r3 /* clears invalidate */
  457. blr
  458. .globl icache_disable
  459. icache_disable:
  460. mfspr r3, HID0
  461. lis r4, 0
  462. ori r4, r4, HID0_ICE|HID0_ILOCK
  463. andc r3, r3, r4
  464. ori r4, r3, HID0_ICFI
  465. isync
  466. mtspr HID0, r4 /* sets invalidate, clears enable and lock*/
  467. isync
  468. mtspr HID0, r3 /* clears invalidate */
  469. blr
  470. .globl icache_status
  471. icache_status:
  472. mfspr r3, HID0
  473. rlwinm r3, r3, HID0_ICE_SHIFT, 31, 31
  474. blr
  475. .globl dcache_enable
  476. dcache_enable:
  477. mfspr r3, HID0
  478. ori r3, r3, HID0_ENABLE_DATA_CACHE
  479. lis r4, 0
  480. ori r4, r4, HID0_LOCK_DATA_CACHE
  481. andc r3, r3, r4
  482. ori r4, r3, HID0_LOCK_INSTRUCTION_CACHE
  483. sync
  484. mtspr HID0, r4 /* sets enable and invalidate, clears lock */
  485. sync
  486. mtspr HID0, r3 /* clears invalidate */
  487. blr
  488. .globl dcache_disable
  489. dcache_disable:
  490. mfspr r3, HID0
  491. lis r4, 0
  492. ori r4, r4, HID0_ENABLE_DATA_CACHE|HID0_LOCK_DATA_CACHE
  493. andc r3, r3, r4
  494. ori r4, r3, HID0_INVALIDATE_DATA_CACHE
  495. sync
  496. mtspr HID0, r4 /* sets invalidate, clears enable and lock */
  497. sync
  498. mtspr HID0, r3 /* clears invalidate */
  499. blr
  500. .globl dcache_status
  501. dcache_status:
  502. mfspr r3, HID0
  503. rlwinm r3, r3, HID0_DCE_SHIFT, 31, 31
  504. blr
  505. .globl get_pvr
  506. get_pvr:
  507. mfspr r3, PVR
  508. blr
  509. /*-------------------------------------------------------------------*/
  510. /*
  511. * void relocate_code (addr_sp, gd, addr_moni)
  512. *
  513. * This "function" does not return, instead it continues in RAM
  514. * after relocating the monitor code.
  515. *
  516. * r3 = dest
  517. * r4 = src
  518. * r5 = length in bytes
  519. * r6 = cachelinesize
  520. */
  521. .globl relocate_code
  522. relocate_code:
  523. mr r1, r3 /* Set new stack pointer */
  524. mr r9, r4 /* Save copy of Global Data pointer */
  525. mr r10, r5 /* Save copy of Destination Address */
  526. mr r3, r5 /* Destination Address */
  527. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  528. ori r4, r4, CFG_MONITOR_BASE@l
  529. lwz r5, GOT(__init_end)
  530. sub r5, r5, r4
  531. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  532. /*
  533. * Fix GOT pointer:
  534. *
  535. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE)
  536. * + Destination Address
  537. *
  538. * Offset:
  539. */
  540. sub r15, r10, r4
  541. /* First our own GOT */
  542. add r14, r14, r15
  543. /* then the one used by the C code */
  544. add r30, r30, r15
  545. /*
  546. * Now relocate code
  547. */
  548. cmplw cr1,r3,r4
  549. addi r0,r5,3
  550. srwi. r0,r0,2
  551. beq cr1,4f /* In place copy is not necessary */
  552. beq 7f /* Protect against 0 count */
  553. mtctr r0
  554. bge cr1,2f
  555. la r8,-4(r4)
  556. la r7,-4(r3)
  557. /* copy */
  558. 1: lwzu r0,4(r8)
  559. stwu r0,4(r7)
  560. bdnz 1b
  561. addi r0,r5,3
  562. srwi. r0,r0,2
  563. mtctr r0
  564. la r8,-4(r4)
  565. la r7,-4(r3)
  566. /* and compare */
  567. 20: lwzu r20,4(r8)
  568. lwzu r21,4(r7)
  569. xor. r22, r20, r21
  570. bne 30f
  571. bdnz 20b
  572. b 4f
  573. /* compare failed */
  574. 30: li r3, 0
  575. blr
  576. 2: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
  577. add r8,r4,r0
  578. add r7,r3,r0
  579. 3: lwzu r0,-4(r8)
  580. stwu r0,-4(r7)
  581. bdnz 3b
  582. /*
  583. * Now flush the cache: note that we must start from a cache aligned
  584. * address. Otherwise we might miss one cache line.
  585. */
  586. 4:
  587. bl un_setup_stack_in_data_cache
  588. mr r7, r3
  589. mr r8, r4
  590. bl dcache_disable
  591. mr r3, r7
  592. mr r4, r8
  593. cmpwi r6,0
  594. add r5,r3,r5
  595. beq 7f /* Always flush prefetch queue in any case */
  596. subi r0,r6,1
  597. andc r3,r3,r0
  598. mfspr r7,HID0 /* don't do dcbst if dcache is disabled*/
  599. rlwinm r7,r7,HID0_DCE_SHIFT,31,31
  600. cmpwi r7,0
  601. beq 9f
  602. mr r4,r3
  603. 5: dcbst 0,r4
  604. add r4,r4,r6
  605. cmplw r4,r5
  606. blt 5b
  607. sync /* Wait for all dcbst to complete on bus */
  608. 9: mfspr r7,HID0 /* don't do icbi if icache is disabled */
  609. rlwinm r7,r7,HID0_DCE_SHIFT,31,31
  610. cmpwi r7,0
  611. beq 7f
  612. mr r4,r3
  613. 6: icbi 0,r4
  614. add r4,r4,r6
  615. cmplw r4,r5
  616. blt 6b
  617. 7: sync /* Wait for all icbi to complete on bus */
  618. isync
  619. /*
  620. * We are done. Do not return, instead branch to second part of board
  621. * initialization, now running from RAM.
  622. */
  623. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  624. mtlr r0
  625. blr
  626. in_ram:
  627. /*
  628. * Relocation Function, r14 point to got2+0x8000
  629. *
  630. * Adjust got2 pointers, no need to check for 0, this code
  631. * already puts a few entries in the table.
  632. */
  633. li r0,__got2_entries@sectoff@l
  634. la r3,GOT(_GOT2_TABLE_)
  635. lwz r11,GOT(_GOT2_TABLE_)
  636. mtctr r0
  637. sub r11,r3,r11
  638. addi r3,r3,-4
  639. 1: lwzu r0,4(r3)
  640. add r0,r0,r11
  641. stw r0,0(r3)
  642. bdnz 1b
  643. /*
  644. * Now adjust the fixups and the pointers to the fixups
  645. * in case we need to move ourselves again.
  646. */
  647. 2: li r0,__fixup_entries@sectoff@l
  648. lwz r3,GOT(_FIXUP_TABLE_)
  649. cmpwi r0,0
  650. mtctr r0
  651. addi r3,r3,-4
  652. beq 4f
  653. 3: lwzu r4,4(r3)
  654. lwzux r0,r4,r11
  655. add r0,r0,r11
  656. stw r10,0(r3)
  657. stw r0,0(r4)
  658. bdnz 3b
  659. 4:
  660. clear_bss:
  661. /*
  662. * Now clear BSS segment
  663. */
  664. lwz r3,GOT(__bss_start)
  665. #if defined(CONFIG_HYMOD)
  666. /*
  667. * For HYMOD - the environment is the very last item in flash.
  668. * The real .bss stops just before environment starts, so only
  669. * clear up to that point.
  670. *
  671. * taken from mods for FADS board
  672. */
  673. lwz r4,GOT(environment)
  674. #else
  675. lwz r4,GOT(_end)
  676. #endif
  677. cmplw 0, r3, r4
  678. beq 6f
  679. li r0, 0
  680. 5:
  681. stw r0, 0(r3)
  682. addi r3, r3, 4
  683. cmplw 0, r3, r4
  684. bne 5b
  685. 6:
  686. mr r3, r9 /* Global Data pointer */
  687. mr r4, r10 /* Destination Address */
  688. bl board_init_r
  689. /*
  690. * Copy exception vector code to low memory
  691. *
  692. * r3: dest_addr
  693. * r7: source address, r8: end address, r9: target address
  694. */
  695. .globl trap_init
  696. trap_init:
  697. lwz r7, GOT(_start)
  698. lwz r8, GOT(_end_of_vectors)
  699. li r9, 0x100 /* reset vector always at 0x100 */
  700. cmplw 0, r7, r8
  701. bgelr /* return if r7>=r8 - just in case */
  702. mflr r4 /* save link register */
  703. 1:
  704. lwz r0, 0(r7)
  705. stw r0, 0(r9)
  706. addi r7, r7, 4
  707. addi r9, r9, 4
  708. cmplw 0, r7, r8
  709. bne 1b
  710. /*
  711. * relocate `hdlr' and `int_return' entries
  712. */
  713. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  714. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  715. 2:
  716. bl trap_reloc
  717. addi r7, r7, 0x100 /* next exception vector */
  718. cmplw 0, r7, r8
  719. blt 2b
  720. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  721. bl trap_reloc
  722. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  723. bl trap_reloc
  724. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  725. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  726. 3:
  727. bl trap_reloc
  728. addi r7, r7, 0x100 /* next exception vector */
  729. cmplw 0, r7, r8
  730. blt 3b
  731. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  732. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  733. 4:
  734. bl trap_reloc
  735. addi r7, r7, 0x100 /* next exception vector */
  736. cmplw 0, r7, r8
  737. blt 4b
  738. mfmsr r3 /* now that the vectors have */
  739. lis r7, MSR_IP@h /* relocated into low memory */
  740. ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
  741. andc r3, r3, r7 /* (if it was on) */
  742. SYNC /* Some chip revs need this... */
  743. mtmsr r3
  744. SYNC
  745. mtlr r4 /* restore link register */
  746. blr
  747. /*
  748. * Function: relocate entries for one exception vector
  749. */
  750. trap_reloc:
  751. lwz r0, 0(r7) /* hdlr ... */
  752. add r0, r0, r3 /* ... += dest_addr */
  753. stw r0, 0(r7)
  754. lwz r0, 4(r7) /* int_return ... */
  755. add r0, r0, r3 /* ... += dest_addr */
  756. stw r0, 4(r7)
  757. blr
  758. #ifdef CFG_INIT_RAM_LOCK
  759. .globl unlock_ram_in_cache
  760. unlock_ram_in_cache:
  761. /* invalidate the INIT_RAM section */
  762. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  763. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  764. li r2,512
  765. mtctr r2
  766. 1: icbi r0, r3
  767. dcbi r0, r3
  768. addi r3, r3, 32
  769. bdnz 1b
  770. sync /* Wait for all icbi to complete on bus */
  771. isync
  772. blr
  773. #endif
  774. map_flash_by_law1:
  775. /* When booting from ROM (Flash or EPROM), clear the */
  776. /* Address Mask in OR0 so ROM appears everywhere */
  777. /*----------------------------------------------------*/
  778. lis r3, (CFG_IMMRBAR)@h /* r3 <= CFG_IMMRBAR */
  779. lwz r4, OR0@l(r3)
  780. li r5, 0x7fff /* r5 <= 0x00007FFFF */
  781. and r4, r4, r5
  782. stw r4, OR0@l(r3) /* OR0 <= OR0 & 0x00007FFFF */
  783. /* As MPC8349E User's Manual presented, when RCW[BMS] is set to 0,
  784. * system will boot from 0x0000_0100, and the LBLAWBAR0[BASE_ADDR]
  785. * reset value is 0x00000; when RCW[BMS] is set to 1, system will boot
  786. * from 0xFFF0_0100, and the LBLAWBAR0[BASE_ADDR] reset value is
  787. * 0xFF800. From the hard resetting to here, the processor fetched and
  788. * executed the instructions one by one. There is not absolutely
  789. * jumping happened. Laterly, the u-boot code has to do an absolutely
  790. * jumping to tell the CPU instruction fetching component what the
  791. * u-boot TEXT base address is. Because the TEXT base resides in the
  792. * boot ROM memory space, to garantee the code can run smoothly after
  793. * that jumping, we must map in the entire boot ROM by Local Access
  794. * Window. Sometimes, we desire an non-0x00000 or non-0xFF800 starting
  795. * address for boot ROM, such as 0xFE000000. In this case, the default
  796. * LBIU Local Access Widow 0 will not cover this memory space. So, we
  797. * need another window to map in it.
  798. */
  799. lis r4, (CFG_FLASH_BASE)@h
  800. ori r4, r4, (CFG_FLASH_BASE)@l
  801. stw r4, LBLAWBAR1(r3) /* LBLAWBAR1 <= CFG_FLASH_BASE */
  802. lis r4, (0x80000016)@h
  803. ori r4, r4, (0x80000016)@l
  804. stw r4, LBLAWAR1(r3) /* LBLAWAR1 <= 8MB Flash Size */
  805. blr
  806. /* Though all the LBIU Local Access Windows and LBC Banks will be
  807. * initialized in the C code, we'd better configure boot ROM's
  808. * window 0 and bank 0 correctly at here.
  809. */
  810. remap_flash_by_law0:
  811. /* Initialize the BR0 with the boot ROM starting address. */
  812. lwz r4, BR0(r3)
  813. li r5, 0x7FFF
  814. and r4, r4, r5
  815. lis r5, (CFG_FLASH_BASE & 0xFFFF8000)@h
  816. ori r5, r5, (CFG_FLASH_BASE & 0xFFFF8000)@l
  817. or r5, r5, r4
  818. stw r5, BR0(r3) /* r5 <= (CFG_FLASH_BASE & 0xFFFF8000) | (BR0 & 0x00007FFF) */
  819. lwz r4, OR0(r3)
  820. lis r5, 0xFF80 /* 8M */
  821. or r4, r4, r5
  822. stw r4, OR0(r3) /* OR0 <= OR0 | 0xFF800000 */
  823. lis r4, (CFG_FLASH_BASE)@h
  824. ori r4, r4, (CFG_FLASH_BASE)@l
  825. stw r4, LBLAWBAR0(r3) /* LBLAWBAR0 <= CFG_FLASH_BASE */
  826. lis r4, (0x80000016)@h
  827. ori r4, r4, (0x80000016)@l
  828. stw r4, LBLAWAR0(r3) /* LBLAWAR0 <= 8MB Flash Size */
  829. xor r4, r4, r4
  830. stw r4, LBLAWBAR1(r3)
  831. stw r4, LBLAWAR1(r3) /* Off LBIU LAW1 */
  832. blr
  833. setup_stack_in_data_cache_on_r1:
  834. lis r3, (CFG_IMMRBAR)@h
  835. /* setup D-BAT for the D-Cache (with out real memory backup) */
  836. lis r4, (CFG_INIT_RAM_ADDR & 0xFFFE0000)@h
  837. mtspr DBAT0U, r4
  838. ori r4, r4, 0x0002
  839. mtspr DBAT0L, r4
  840. isync
  841. #if 0
  842. /* Enable MMU */
  843. mfmsr r4
  844. ori r4, r4, (MSR_DR | MSR_IR)@l
  845. mtmsr r4
  846. #endif
  847. /* Enable and invalidate data cache. */
  848. mfspr r4, HID0
  849. mr r5, r4
  850. ori r4, r4, HID0_DCE | HID0_DCI
  851. ori r5, r5, HID0_DCE
  852. sync
  853. mtspr HID0, r4
  854. mtspr HID0, r5
  855. sync
  856. /* Allocate Initial RAM in data cache.*/
  857. li r0, 0
  858. lis r4, (CFG_INIT_RAM_ADDR)@h
  859. ori r4, r4, (CFG_INIT_RAM_ADDR)@l
  860. li r5, 128*8 /* 128*8*32=32Kb */
  861. mtctr r5
  862. 1:
  863. dcbz r0, r4
  864. addi r4, r4, 32
  865. bdnz 1b
  866. isync
  867. /* Lock all the D-cache, basically leaving the reset of the program without dcache */
  868. mfspr r4, HID0
  869. ori r4, r4, (HID0_DLOCK)@l
  870. sync
  871. mtspr HID0 , r4
  872. /* setup the stack pointer in r1 */
  873. lis r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@h
  874. ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@l
  875. li r0, 0 /* Make room for stack frame header and */
  876. stwu r0, -4(r1) /* clear final stack frame so that */
  877. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  878. blr
  879. un_setup_stack_in_data_cache:
  880. blr
  881. mr r14, r4
  882. mr r15, r5
  883. lis r4, (CFG_INIT_RAM_ADDR & 0xFFFE0000)@h
  884. mtspr DBAT0U, r4
  885. ori r4, r4, 0x0002
  886. mtspr DBAT0L, r4
  887. isync
  888. /* un lock all the D-cache */
  889. mfspr r4, HID0
  890. lis r5, (~(HID0_DLOCK))@h
  891. ori r5, r5, (~(HID0_DLOCK))@l
  892. and r4, r4, r5
  893. sync
  894. mtspr HID0 , r4
  895. /* Re - Allocate Initial RAM in data cache.*/
  896. li r0, 0
  897. lis r4, (CFG_INIT_RAM_ADDR)@h
  898. ori r4, r4, (CFG_INIT_RAM_ADDR)@l
  899. li r5, 128*8 /* 128*8*32=32Kb */
  900. mtctr r5
  901. 1:
  902. dcbz r0, r4
  903. addi r4, r4, 32
  904. bdnz 1b
  905. isync
  906. mflr r16
  907. bl dcache_disable
  908. mtlr r16
  909. blr
  910. #if 0
  911. #define GREEN_LIGHT 0x2B0D4046
  912. #define RED_LIGHT 0x250D4046
  913. #define LIB_CNT 0x4FFF
  914. /*
  915. * Lib Light
  916. */
  917. .globl liblight
  918. liblight:
  919. lis r3, CFG_IMMRBAR@h
  920. ori r3, r3, CFG_IMMRBAR@l
  921. li r4, 0x3002
  922. mtmsr r4
  923. xor r4, r4, r4
  924. mtspr HID0, r4
  925. mtspr HID2, r4
  926. lis r4, 0xF8000000@h
  927. ori r4, r4, 0xF8000000@l
  928. stw r4, LBLAWBAR1(r3)
  929. lis r4, 0x8000000E@h
  930. ori r4, r4, 0x8000000E@l
  931. stw r4, LBLAWAR1(r3)
  932. lis r4, 0xF8000801@h
  933. ori r4, r4, 0xF8000801@l
  934. stw r4, BR1(r3)
  935. lis r4, 0xFFFFE8f0@h
  936. ori r4, r4, 0xFFFFE8f0@l
  937. stw r4, OR1(r3)
  938. lis r4, 0xF8000000@h
  939. ori r4, r4, 0xF8000000@l
  940. lis r5, GREEN_LIGHT@h
  941. ori r5, r5, GREEN_LIGHT@l
  942. lis r6, RED_LIGHT@h
  943. ori r6, r6, RED_LIGHT@l
  944. lis r7, LIB_CNT@h
  945. ori r7, r7, LIB_CNT@l
  946. 1:
  947. stw r5, 0(r4)
  948. mtctr r7
  949. 2: bdnz 2b
  950. stw r6, 0(r4)
  951. mtctr r7
  952. 3: bdnz 3b
  953. b 1b
  954. #endif