start.S 30 KB

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