start.S 29 KB

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