start.S 29 KB

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