start.S 28 KB

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