start.S 29 KB

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