start.S 30 KB

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