start.S 30 KB

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