start.S 29 KB

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