start.S 30 KB

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