start.S 30 KB

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