start.S 30 KB

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