start.S 30 KB

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