start.S 30 KB

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