start.S 29 KB

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