start.S 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. /*
  10. * U-Boot - Startup Code for MPC83xx PowerPC based Embedded Boards
  11. */
  12. #include <asm-offsets.h>
  13. #include <config.h>
  14. #include <mpc83xx.h>
  15. #include <version.h>
  16. #define CONFIG_83XX 1 /* needed for Linux kernel header files*/
  17. #include <ppc_asm.tmpl>
  18. #include <ppc_defs.h>
  19. #include <asm/cache.h>
  20. #include <asm/mmu.h>
  21. #include <asm/u-boot.h>
  22. /* We don't want the MMU yet.
  23. */
  24. #undef MSR_KERNEL
  25. /*
  26. * Floating Point enable, Machine Check and Recoverable Interr.
  27. */
  28. #ifdef DEBUG
  29. #define MSR_KERNEL (MSR_FP|MSR_RI)
  30. #else
  31. #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
  32. #endif
  33. #if defined(CONFIG_NAND_SPL) || \
  34. (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_INIT_MINIMAL))
  35. #define MINIMAL_SPL
  36. #endif
  37. #if !defined(CONFIG_SPL_BUILD) && !defined(CONFIG_NAND_SPL) && \
  38. !defined(CONFIG_SYS_RAMBOOT)
  39. #define CONFIG_SYS_FLASHBOOT
  40. #endif
  41. /*
  42. * Set up GOT: Global Offset Table
  43. *
  44. * Use r12 to access the GOT
  45. */
  46. START_GOT
  47. GOT_ENTRY(_GOT2_TABLE_)
  48. GOT_ENTRY(__bss_start)
  49. GOT_ENTRY(__bss_end)
  50. #ifndef MINIMAL_SPL
  51. GOT_ENTRY(_FIXUP_TABLE_)
  52. GOT_ENTRY(_start)
  53. GOT_ENTRY(_start_of_vectors)
  54. GOT_ENTRY(_end_of_vectors)
  55. GOT_ENTRY(transfer_to_handler)
  56. #endif
  57. END_GOT
  58. /*
  59. * The Hard Reset Configuration Word (HRCW) table is in the first 64
  60. * (0x40) bytes of flash. It has 8 bytes, but each byte is repeated 8
  61. * times so the processor can fetch it out of flash whether the flash
  62. * is 8, 16, 32, or 64 bits wide (hardware trickery).
  63. */
  64. .text
  65. #define _HRCW_TABLE_ENTRY(w) \
  66. .fill 8,1,(((w)>>24)&0xff); \
  67. .fill 8,1,(((w)>>16)&0xff); \
  68. .fill 8,1,(((w)>> 8)&0xff); \
  69. .fill 8,1,(((w) )&0xff)
  70. _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_LOW)
  71. _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_HIGH)
  72. /*
  73. * Magic number and version string - put it after the HRCW since it
  74. * cannot be first in flash like it is in many other processors.
  75. */
  76. .long 0x27051956 /* U-Boot Magic Number */
  77. .globl version_string
  78. version_string:
  79. .ascii U_BOOT_VERSION_STRING, "\0"
  80. .align 2
  81. .globl enable_addr_trans
  82. enable_addr_trans:
  83. /* enable address translation */
  84. mfmsr r5
  85. ori r5, r5, (MSR_IR | MSR_DR)
  86. mtmsr r5
  87. isync
  88. blr
  89. .globl disable_addr_trans
  90. disable_addr_trans:
  91. /* disable address translation */
  92. mflr r4
  93. mfmsr r3
  94. andi. r0, r3, (MSR_IR | MSR_DR)
  95. beqlr
  96. andc r3, r3, r0
  97. mtspr SRR0, r4
  98. mtspr SRR1, r3
  99. rfi
  100. .globl get_svr
  101. get_svr:
  102. mfspr r3, SVR
  103. blr
  104. .globl get_pvr
  105. get_pvr:
  106. mfspr r3, PVR
  107. blr
  108. .globl ppcDWstore
  109. ppcDWstore:
  110. lfd 1, 0(r4)
  111. stfd 1, 0(r3)
  112. blr
  113. .globl ppcDWload
  114. ppcDWload:
  115. lfd 1, 0(r3)
  116. stfd 1, 0(r4)
  117. blr
  118. #ifndef CONFIG_DEFAULT_IMMR
  119. #error CONFIG_DEFAULT_IMMR must be defined
  120. #endif /* CONFIG_SYS_DEFAULT_IMMR */
  121. #ifndef CONFIG_SYS_IMMR
  122. #define CONFIG_SYS_IMMR CONFIG_DEFAULT_IMMR
  123. #endif /* CONFIG_SYS_IMMR */
  124. /*
  125. * After configuration, a system reset exception is executed using the
  126. * vector at offset 0x100 relative to the base set by MSR[IP]. If
  127. * MSR[IP] is 0, the base address is 0x00000000. If MSR[IP] is 1, the
  128. * base address is 0xfff00000. In the case of a Power On Reset or Hard
  129. * Reset, the value of MSR[IP] is determined by the CIP field in the
  130. * HRCW.
  131. *
  132. * Other bits in the HRCW set up the Base Address and Port Size in BR0.
  133. * This determines the location of the boot ROM (flash or EPROM) in the
  134. * processor's address space at boot time. As long as the HRCW is set up
  135. * so that we eventually end up executing the code below when the
  136. * processor executes the reset exception, the actual values used should
  137. * not matter.
  138. *
  139. * Once we have got here, the address mask in OR0 is cleared so that the
  140. * bottom 32K of the boot ROM is effectively repeated all throughout the
  141. * processor's address space, after which we can jump to the absolute
  142. * address at which the boot ROM was linked at compile time, and proceed
  143. * to initialise the memory controller without worrying if the rug will
  144. * be pulled out from under us, so to speak (it will be fine as long as
  145. * we configure BR0 with the same boot ROM link address).
  146. */
  147. . = EXC_OFF_SYS_RESET
  148. .globl _start
  149. _start: /* time t 0 */
  150. lis r4, CONFIG_DEFAULT_IMMR@h
  151. nop
  152. mfmsr r5 /* save msr contents */
  153. /* 83xx manuals prescribe a specific sequence for updating IMMRBAR. */
  154. bl 1f
  155. 1: mflr r7
  156. lis r3, CONFIG_SYS_IMMR@h
  157. ori r3, r3, CONFIG_SYS_IMMR@l
  158. lwz r6, IMMRBAR(r4)
  159. isync
  160. stw r3, IMMRBAR(r4)
  161. lwz r6, 0(r7) /* Arbitrary external load */
  162. isync
  163. lwz r6, IMMRBAR(r3)
  164. isync
  165. /* Initialise the E300 processor core */
  166. /*------------------------------------------*/
  167. #if (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MPC83XX_WAIT_FOR_NAND)) || \
  168. defined(CONFIG_NAND_SPL)
  169. /* The FCM begins execution after only the first page
  170. * is loaded. Wait for the rest before branching
  171. * to another flash page.
  172. */
  173. 1: lwz r6, 0x50b0(r3)
  174. andi. r6, r6, 1
  175. beq 1b
  176. #endif
  177. bl init_e300_core
  178. #ifdef CONFIG_SYS_FLASHBOOT
  179. /* Inflate flash location so it appears everywhere, calculate */
  180. /* the absolute address in final location of the FLASH, jump */
  181. /* there and deflate the flash size back to minimal size */
  182. /*------------------------------------------------------------*/
  183. bl map_flash_by_law1
  184. lis r4, (CONFIG_SYS_MONITOR_BASE)@h
  185. ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l
  186. addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
  187. mtlr r5
  188. blr
  189. in_flash:
  190. #if 1 /* Remapping flash with LAW0. */
  191. bl remap_flash_by_law0
  192. #endif
  193. #endif /* CONFIG_SYS_FLASHBOOT */
  194. /* setup the bats */
  195. bl setup_bats
  196. sync
  197. /*
  198. * Cache must be enabled here for stack-in-cache trick.
  199. * This means we need to enable the BATS.
  200. * This means:
  201. * 1) for the EVB, original gt regs need to be mapped
  202. * 2) need to have an IBAT for the 0xf region,
  203. * we are running there!
  204. * Cache should be turned on after BATs, since by default
  205. * everything is write-through.
  206. * The init-mem BAT can be reused after reloc. The old
  207. * gt-regs BAT can be reused after board_init_f calls
  208. * board_early_init_f (EVB only).
  209. */
  210. /* enable address translation */
  211. bl enable_addr_trans
  212. sync
  213. /* enable the data cache */
  214. bl dcache_enable
  215. sync
  216. #ifdef CONFIG_SYS_INIT_RAM_LOCK
  217. bl lock_ram_in_cache
  218. sync
  219. #endif
  220. /* set up the stack pointer in our newly created
  221. * cache-ram; use r3 to keep the new SP for now to
  222. * avoid overiding the SP it uselessly */
  223. lis r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
  224. ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
  225. /* r4 = end of GD area */
  226. addi r4, r3, GENERATED_GBL_DATA_SIZE
  227. /* Zero GD area */
  228. li r0, 0
  229. 1:
  230. subi r4, r4, 1
  231. stb r0, 0(r4)
  232. cmplw r3, r4
  233. bne 1b
  234. #ifdef CONFIG_SYS_MALLOC_F_LEN
  235. #if CONFIG_SYS_MALLOC_F_LEN + GENERATED_GBL_DATA_SIZE > CONFIG_SYS_INIT_RAM_SIZE
  236. #error "CONFIG_SYS_MALLOC_F_LEN too large to fit into initial RAM."
  237. #endif
  238. /* r3 = new stack pointer / pre-reloc malloc area */
  239. subi r3, r3, CONFIG_SYS_MALLOC_F_LEN
  240. /* Set pointer to pre-reloc malloc area in GD */
  241. stw r3, GD_MALLOC_BASE(r4)
  242. #endif
  243. li r0, 0 /* Make room for stack frame header and */
  244. stwu r0, -4(r3) /* clear final stack frame so that */
  245. stwu r0, -4(r3) /* stack backtraces terminate cleanly */
  246. /* Finally, actually set SP */
  247. mr r1, r3
  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. /* run 1st part of board init code (in Flash)*/
  258. li r3, 0 /* clear boot_flag for calling board_init_f */
  259. bl board_init_f
  260. /* NOTREACHED - board_init_f() does not return */
  261. #ifndef MINIMAL_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 /* !MINIMAL_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 MINIMAL_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 /* !MINIMAL_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 MINIMAL_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. cmpwi r0,0
  844. add r0,r0,r11
  845. stw r4,0(r3)
  846. beq- 5f
  847. stw r0,0(r4)
  848. 5: bdnz 3b
  849. 4:
  850. #endif
  851. clear_bss:
  852. /*
  853. * Now clear BSS segment
  854. */
  855. lwz r3,GOT(__bss_start)
  856. lwz r4,GOT(__bss_end)
  857. cmplw 0, r3, r4
  858. beq 6f
  859. li r0, 0
  860. 5:
  861. stw r0, 0(r3)
  862. addi r3, r3, 4
  863. cmplw 0, r3, r4
  864. bne 5b
  865. 6:
  866. mr r3, r9 /* Global Data pointer */
  867. mr r4, r10 /* Destination Address */
  868. bl board_init_r
  869. #ifndef MINIMAL_SPL
  870. /*
  871. * Copy exception vector code to low memory
  872. *
  873. * r3: dest_addr
  874. * r7: source address, r8: end address, r9: target address
  875. */
  876. .globl trap_init
  877. trap_init:
  878. mflr r4 /* save link register */
  879. GET_GOT
  880. lwz r7, GOT(_start)
  881. lwz r8, GOT(_end_of_vectors)
  882. li r9, 0x100 /* reset vector always at 0x100 */
  883. cmplw 0, r7, r8
  884. bgelr /* return if r7>=r8 - just in case */
  885. 1:
  886. lwz r0, 0(r7)
  887. stw r0, 0(r9)
  888. addi r7, r7, 4
  889. addi r9, r9, 4
  890. cmplw 0, r7, r8
  891. bne 1b
  892. /*
  893. * relocate `hdlr' and `int_return' entries
  894. */
  895. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  896. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  897. 2:
  898. bl trap_reloc
  899. addi r7, r7, 0x100 /* next exception vector */
  900. cmplw 0, r7, r8
  901. blt 2b
  902. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  903. bl trap_reloc
  904. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  905. bl trap_reloc
  906. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  907. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  908. 3:
  909. bl trap_reloc
  910. addi r7, r7, 0x100 /* next exception vector */
  911. cmplw 0, r7, r8
  912. blt 3b
  913. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  914. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  915. 4:
  916. bl trap_reloc
  917. addi r7, r7, 0x100 /* next exception vector */
  918. cmplw 0, r7, r8
  919. blt 4b
  920. mfmsr r3 /* now that the vectors have */
  921. lis r7, MSR_IP@h /* relocated into low memory */
  922. ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
  923. andc r3, r3, r7 /* (if it was on) */
  924. SYNC /* Some chip revs need this... */
  925. mtmsr r3
  926. SYNC
  927. mtlr r4 /* restore link register */
  928. blr
  929. #endif /* !MINIMAL_SPL */
  930. #ifdef CONFIG_SYS_INIT_RAM_LOCK
  931. lock_ram_in_cache:
  932. /* Allocate Initial RAM in data cache.
  933. */
  934. lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
  935. ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
  936. li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
  937. (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
  938. mtctr r4
  939. 1:
  940. dcbz r0, r3
  941. addi r3, r3, 32
  942. bdnz 1b
  943. /* Lock the data cache */
  944. mfspr r0, HID0
  945. ori r0, r0, HID0_DLOCK
  946. sync
  947. mtspr HID0, r0
  948. sync
  949. blr
  950. #ifndef MINIMAL_SPL
  951. .globl unlock_ram_in_cache
  952. unlock_ram_in_cache:
  953. /* invalidate the INIT_RAM section */
  954. lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
  955. ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
  956. li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
  957. (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
  958. mtctr r4
  959. 1: icbi r0, r3
  960. dcbi r0, r3
  961. addi r3, r3, 32
  962. bdnz 1b
  963. sync /* Wait for all icbi to complete on bus */
  964. isync
  965. /* Unlock the data cache and invalidate it */
  966. mfspr r3, HID0
  967. li r5, HID0_DLOCK|HID0_DCFI
  968. andc r3, r3, r5 /* no invalidate, unlock */
  969. ori r5, r3, HID0_DCFI /* invalidate, unlock */
  970. sync
  971. mtspr HID0, r5 /* invalidate, unlock */
  972. sync
  973. mtspr HID0, r3 /* no invalidate, unlock */
  974. blr
  975. #endif /* !MINIMAL_SPL */
  976. #endif /* CONFIG_SYS_INIT_RAM_LOCK */
  977. #ifdef CONFIG_SYS_FLASHBOOT
  978. map_flash_by_law1:
  979. /* When booting from ROM (Flash or EPROM), clear the */
  980. /* Address Mask in OR0 so ROM appears everywhere */
  981. /*----------------------------------------------------*/
  982. lis r3, (CONFIG_SYS_IMMR)@h /* r3 <= CONFIG_SYS_IMMR */
  983. lwz r4, OR0@l(r3)
  984. li r5, 0x7fff /* r5 <= 0x00007FFFF */
  985. and r4, r4, r5
  986. stw r4, OR0@l(r3) /* OR0 <= OR0 & 0x00007FFFF */
  987. /* As MPC8349E User's Manual presented, when RCW[BMS] is set to 0,
  988. * system will boot from 0x0000_0100, and the LBLAWBAR0[BASE_ADDR]
  989. * reset value is 0x00000; when RCW[BMS] is set to 1, system will boot
  990. * from 0xFFF0_0100, and the LBLAWBAR0[BASE_ADDR] reset value is
  991. * 0xFF800. From the hard resetting to here, the processor fetched and
  992. * executed the instructions one by one. There is not absolutely
  993. * jumping happened. Laterly, the u-boot code has to do an absolutely
  994. * jumping to tell the CPU instruction fetching component what the
  995. * u-boot TEXT base address is. Because the TEXT base resides in the
  996. * boot ROM memory space, to garantee the code can run smoothly after
  997. * that jumping, we must map in the entire boot ROM by Local Access
  998. * Window. Sometimes, we desire an non-0x00000 or non-0xFF800 starting
  999. * address for boot ROM, such as 0xFE000000. In this case, the default
  1000. * LBIU Local Access Widow 0 will not cover this memory space. So, we
  1001. * need another window to map in it.
  1002. */
  1003. lis r4, (CONFIG_SYS_FLASH_BASE)@h
  1004. ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
  1005. stw r4, LBLAWBAR1(r3) /* LBLAWBAR1 <= CONFIG_SYS_FLASH_BASE */
  1006. /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR1 */
  1007. lis r4, (0x80000012)@h
  1008. ori r4, r4, (0x80000012)@l
  1009. li r5, CONFIG_SYS_FLASH_SIZE
  1010. 1: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
  1011. addi r4, r4, 1
  1012. bne 1b
  1013. stw r4, LBLAWAR1(r3) /* LBLAWAR1 <= 8MB Flash Size */
  1014. /* Wait for HW to catch up */
  1015. lwz r4, LBLAWAR1(r3)
  1016. twi 0,r4,0
  1017. isync
  1018. blr
  1019. /* Though all the LBIU Local Access Windows and LBC Banks will be
  1020. * initialized in the C code, we'd better configure boot ROM's
  1021. * window 0 and bank 0 correctly at here.
  1022. */
  1023. remap_flash_by_law0:
  1024. /* Initialize the BR0 with the boot ROM starting address. */
  1025. lwz r4, BR0(r3)
  1026. li r5, 0x7FFF
  1027. and r4, r4, r5
  1028. lis r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@h
  1029. ori r5, r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@l
  1030. or r5, r5, r4
  1031. stw r5, BR0(r3) /* r5 <= (CONFIG_SYS_FLASH_BASE & 0xFFFF8000) | (BR0 & 0x00007FFF) */
  1032. lwz r4, OR0(r3)
  1033. lis r5, ~((CONFIG_SYS_FLASH_SIZE << 4) - 1)
  1034. or r4, r4, r5
  1035. stw r4, OR0(r3)
  1036. lis r4, (CONFIG_SYS_FLASH_BASE)@h
  1037. ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
  1038. stw r4, LBLAWBAR0(r3) /* LBLAWBAR0 <= CONFIG_SYS_FLASH_BASE */
  1039. /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR0 */
  1040. lis r4, (0x80000012)@h
  1041. ori r4, r4, (0x80000012)@l
  1042. li r5, CONFIG_SYS_FLASH_SIZE
  1043. 1: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
  1044. addi r4, r4, 1
  1045. bne 1b
  1046. stw r4, LBLAWAR0(r3) /* LBLAWAR0 <= Flash Size */
  1047. xor r4, r4, r4
  1048. stw r4, LBLAWBAR1(r3)
  1049. stw r4, LBLAWAR1(r3) /* Off LBIU LAW1 */
  1050. /* Wait for HW to catch up */
  1051. lwz r4, LBLAWAR1(r3)
  1052. twi 0,r4,0
  1053. isync
  1054. blr
  1055. #endif /* CONFIG_SYS_FLASHBOOT */