start.S 30 KB

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