start.S 20 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. /*
  2. * Copyright 2004, 2007 Freescale Semiconductor.
  3. * Srikanth Srinivasan <srikanth.srinivaan@freescale.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /* U-Boot - Startup Code for 86xx PowerPC based Embedded Boards
  24. *
  25. *
  26. * The processor starts at 0xfff00100 and the code is executed
  27. * from flash. The code is organized to be at an other address
  28. * in memory, but as long we don't jump around before relocating.
  29. * board_init lies at a quite high address and when the cpu has
  30. * jumped there, everything is ok.
  31. */
  32. #include <config.h>
  33. #include <mpc86xx.h>
  34. #include <version.h>
  35. #include <ppc_asm.tmpl>
  36. #include <ppc_defs.h>
  37. #include <asm/cache.h>
  38. #include <asm/mmu.h>
  39. #ifndef CONFIG_IDENT_STRING
  40. #define CONFIG_IDENT_STRING ""
  41. #endif
  42. /*
  43. * Need MSR_DR | MSR_IR enabled to access I/O (printf) in exceptions
  44. */
  45. /*
  46. * Set up GOT: Global Offset Table
  47. *
  48. * Use r14 to access the GOT
  49. */
  50. START_GOT
  51. GOT_ENTRY(_GOT2_TABLE_)
  52. GOT_ENTRY(_FIXUP_TABLE_)
  53. GOT_ENTRY(_start)
  54. GOT_ENTRY(_start_of_vectors)
  55. GOT_ENTRY(_end_of_vectors)
  56. GOT_ENTRY(transfer_to_handler)
  57. GOT_ENTRY(__init_end)
  58. GOT_ENTRY(_end)
  59. GOT_ENTRY(__bss_start)
  60. END_GOT
  61. /*
  62. * r3 - 1st arg to board_init(): IMMP pointer
  63. * r4 - 2nd arg to board_init(): boot flag
  64. */
  65. .text
  66. .long 0x27051956 /* U-Boot Magic Number */
  67. .globl version_string
  68. version_string:
  69. .ascii U_BOOT_VERSION
  70. .ascii " (", __DATE__, " - ", __TIME__, ")"
  71. .ascii CONFIG_IDENT_STRING, "\0"
  72. . = EXC_OFF_SYS_RESET
  73. .globl _start
  74. _start:
  75. li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
  76. b boot_cold
  77. sync
  78. . = EXC_OFF_SYS_RESET + 0x10
  79. .globl _start_warm
  80. _start_warm:
  81. li r21, BOOTFLAG_WARM /* Software reboot */
  82. b boot_warm
  83. sync
  84. /* the boot code is located below the exception table */
  85. .globl _start_of_vectors
  86. _start_of_vectors:
  87. /* Machine check */
  88. STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
  89. /* Data Storage exception. */
  90. STD_EXCEPTION(0x300, DataStorage, UnknownException)
  91. /* Instruction Storage exception. */
  92. STD_EXCEPTION(0x400, InstStorage, UnknownException)
  93. /* External Interrupt exception. */
  94. STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
  95. /* Alignment exception. */
  96. . = 0x600
  97. Alignment:
  98. EXCEPTION_PROLOG(SRR0, SRR1)
  99. mfspr r4,DAR
  100. stw r4,_DAR(r21)
  101. mfspr r5,DSISR
  102. stw r5,_DSISR(r21)
  103. addi r3,r1,STACK_FRAME_OVERHEAD
  104. li r20,MSR_KERNEL
  105. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  106. lwz r6,GOT(transfer_to_handler)
  107. mtlr r6
  108. blrl
  109. .L_Alignment:
  110. .long AlignmentException - _start + EXC_OFF_SYS_RESET
  111. .long int_return - _start + EXC_OFF_SYS_RESET
  112. /* Program check exception */
  113. . = 0x700
  114. ProgramCheck:
  115. EXCEPTION_PROLOG(SRR0, SRR1)
  116. addi r3,r1,STACK_FRAME_OVERHEAD
  117. li r20,MSR_KERNEL
  118. rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
  119. lwz r6,GOT(transfer_to_handler)
  120. mtlr r6
  121. blrl
  122. .L_ProgramCheck:
  123. .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
  124. .long int_return - _start + EXC_OFF_SYS_RESET
  125. STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
  126. /* I guess we could implement decrementer, and may have
  127. * to someday for timekeeping.
  128. */
  129. STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
  130. STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
  131. STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
  132. STD_EXCEPTION(0xc00, SystemCall, UnknownException)
  133. STD_EXCEPTION(0xd00, SingleStep, UnknownException)
  134. STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
  135. STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
  136. STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
  137. STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
  138. STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
  139. STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
  140. STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
  141. STD_EXCEPTION(0x1500, Reserved5, UnknownException)
  142. STD_EXCEPTION(0x1600, Reserved6, UnknownException)
  143. STD_EXCEPTION(0x1700, Reserved7, UnknownException)
  144. STD_EXCEPTION(0x1800, Reserved8, UnknownException)
  145. STD_EXCEPTION(0x1900, Reserved9, UnknownException)
  146. STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
  147. STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
  148. STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
  149. STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
  150. STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
  151. STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
  152. .globl _end_of_vectors
  153. _end_of_vectors:
  154. . = 0x2000
  155. boot_cold:
  156. boot_warm:
  157. /* if this is a multi-core system we need to check which cpu
  158. * this is, if it is not cpu 0 send the cpu to the linux reset
  159. * vector */
  160. #if (CONFIG_NUM_CPUS > 1)
  161. mfspr r0, MSSCR0
  162. andi. r0, r0, 0x0020
  163. rlwinm r0,r0,27,31,31
  164. mtspr PIR, r0
  165. beq 1f
  166. bl secondary_cpu_setup
  167. #endif
  168. 1:
  169. #ifdef CONFIG_SYS_RAMBOOT
  170. /* disable everything */
  171. li r0, 0
  172. mtspr HID0, r0
  173. sync
  174. mtmsr 0
  175. #endif
  176. /* Invalidate BATs */
  177. bl invalidate_bats
  178. sync
  179. /* Invalidate all of TLB before MMU turn on */
  180. bl clear_tlbs
  181. sync
  182. #ifdef CONFIG_SYS_L2
  183. /* init the L2 cache */
  184. lis r3, L2_INIT@h
  185. ori r3, r3, L2_INIT@l
  186. mtspr l2cr, r3
  187. /* invalidate the L2 cache */
  188. bl l2cache_invalidate
  189. sync
  190. #endif
  191. /*
  192. * Calculate absolute address in FLASH and jump there
  193. *------------------------------------------------------*/
  194. lis r3, CONFIG_SYS_MONITOR_BASE@h
  195. ori r3, r3, CONFIG_SYS_MONITOR_BASE@l
  196. addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
  197. mtlr r3
  198. blr
  199. in_flash:
  200. /* let the C-code set up the rest */
  201. /* */
  202. /* Be careful to keep code relocatable ! */
  203. /*------------------------------------------------------*/
  204. /* perform low-level init */
  205. /* enable extended addressing */
  206. bl enable_ext_addr
  207. /* setup the bats */
  208. bl early_bats
  209. /*
  210. * Cache must be enabled here for stack-in-cache trick.
  211. * This means we need to enable the BATS.
  212. * Cache should be turned on after BATs, since by default
  213. * everything is write-through.
  214. */
  215. /* enable address translation */
  216. bl enable_addr_trans
  217. sync
  218. /* enable and invalidate the data cache */
  219. /* bl l1dcache_enable */
  220. bl dcache_enable
  221. sync
  222. #if 1
  223. bl icache_enable
  224. #endif
  225. #ifdef CONFIG_SYS_INIT_RAM_LOCK
  226. bl lock_ram_in_cache
  227. sync
  228. #endif
  229. /* set up the stack pointer in our newly created
  230. * cache-ram (r1) */
  231. lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
  232. ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
  233. li r0, 0 /* Make room for stack frame header and */
  234. stwu r0, -4(r1) /* clear final stack frame so that */
  235. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  236. GET_GOT /* initialize GOT access */
  237. /* setup the rest of the bats */
  238. bl setup_bats
  239. sync
  240. #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR)
  241. /* setup ccsrbar */
  242. bl setup_ccsrbar
  243. #endif
  244. /* run low-level CPU init code (from Flash) */
  245. bl cpu_init_f
  246. sync
  247. #ifdef RUN_DIAG
  248. /* Load PX_AUX register address in r4 */
  249. lis r4, 0xf810
  250. ori r4, r4, 0x6
  251. /* Load contents of PX_AUX in r3 bits 24 to 31*/
  252. lbz r3, 0(r4)
  253. /* Mask and obtain the bit in r3 */
  254. rlwinm. r3, r3, 0, 24, 24
  255. /* If not zero, jump and continue with u-boot */
  256. bne diag_done
  257. /* Load back contents of PX_AUX in r3 bits 24 to 31 */
  258. lbz r3, 0(r4)
  259. /* Set the MSB of the register value */
  260. ori r3, r3, 0x80
  261. /* Write value in r3 back to PX_AUX */
  262. stb r3, 0(r4)
  263. /* Get the address to jump to in r3*/
  264. lis r3, CONFIG_SYS_DIAG_ADDR@h
  265. ori r3, r3, CONFIG_SYS_DIAG_ADDR@l
  266. /* Load the LR with the branch address */
  267. mtlr r3
  268. /* Branch to diagnostic */
  269. blr
  270. diag_done:
  271. #endif
  272. /* bl l2cache_enable */
  273. mr r3, r21
  274. /* r3: BOOTFLAG */
  275. /* run 1st part of board init code (from Flash) */
  276. bl board_init_f
  277. sync
  278. /* NOTREACHED */
  279. .globl invalidate_bats
  280. invalidate_bats:
  281. li r0, 0
  282. /* invalidate BATs */
  283. mtspr IBAT0U, r0
  284. mtspr IBAT1U, r0
  285. mtspr IBAT2U, r0
  286. mtspr IBAT3U, r0
  287. mtspr IBAT4U, r0
  288. mtspr IBAT5U, r0
  289. mtspr IBAT6U, r0
  290. mtspr IBAT7U, r0
  291. isync
  292. mtspr DBAT0U, r0
  293. mtspr DBAT1U, r0
  294. mtspr DBAT2U, r0
  295. mtspr DBAT3U, r0
  296. mtspr DBAT4U, r0
  297. mtspr DBAT5U, r0
  298. mtspr DBAT6U, r0
  299. mtspr DBAT7U, r0
  300. isync
  301. sync
  302. blr
  303. /*
  304. * early_bats:
  305. *
  306. * Set up bats needed early on - this is usually the BAT for the
  307. * stack-in-cache and the Flash
  308. */
  309. .globl early_bats
  310. early_bats:
  311. /* IBAT 5 */
  312. lis r4, CONFIG_SYS_IBAT5L@h
  313. ori r4, r4, CONFIG_SYS_IBAT5L@l
  314. lis r3, CONFIG_SYS_IBAT5U@h
  315. ori r3, r3, CONFIG_SYS_IBAT5U@l
  316. mtspr IBAT5L, r4
  317. mtspr IBAT5U, r3
  318. isync
  319. /* DBAT 5 */
  320. lis r4, CONFIG_SYS_DBAT5L@h
  321. ori r4, r4, CONFIG_SYS_DBAT5L@l
  322. lis r3, CONFIG_SYS_DBAT5U@h
  323. ori r3, r3, CONFIG_SYS_DBAT5U@l
  324. mtspr DBAT5L, r4
  325. mtspr DBAT5U, r3
  326. isync
  327. /* IBAT 6 */
  328. lis r4, CONFIG_SYS_IBAT6L@h
  329. ori r4, r4, CONFIG_SYS_IBAT6L@l
  330. lis r3, CONFIG_SYS_IBAT6U@h
  331. ori r3, r3, CONFIG_SYS_IBAT6U@l
  332. mtspr IBAT6L, r4
  333. mtspr IBAT6U, r3
  334. isync
  335. /* DBAT 6 */
  336. lis r4, CONFIG_SYS_DBAT6L@h
  337. ori r4, r4, CONFIG_SYS_DBAT6L@l
  338. lis r3, CONFIG_SYS_DBAT6U@h
  339. ori r3, r3, CONFIG_SYS_DBAT6U@l
  340. mtspr DBAT6L, r4
  341. mtspr DBAT6U, r3
  342. isync
  343. blr
  344. .globl clear_tlbs
  345. clear_tlbs:
  346. addis r3, 0, 0x0000
  347. addis r5, 0, 0x4
  348. isync
  349. tlblp:
  350. tlbie r3
  351. sync
  352. addi r3, r3, 0x1000
  353. cmp 0, 0, r3, r5
  354. blt tlblp
  355. blr
  356. .globl enable_addr_trans
  357. enable_addr_trans:
  358. /* enable address translation */
  359. mfmsr r5
  360. ori r5, r5, (MSR_IR | MSR_DR)
  361. mtmsr r5
  362. isync
  363. blr
  364. .globl disable_addr_trans
  365. disable_addr_trans:
  366. /* disable address translation */
  367. mflr r4
  368. mfmsr r3
  369. andi. r0, r3, (MSR_IR | MSR_DR)
  370. beqlr
  371. andc r3, r3, r0
  372. mtspr SRR0, r4
  373. mtspr SRR1, r3
  374. rfi
  375. /*
  376. * This code finishes saving the registers to the exception frame
  377. * and jumps to the appropriate handler for the exception.
  378. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  379. */
  380. .globl transfer_to_handler
  381. transfer_to_handler:
  382. stw r22,_NIP(r21)
  383. lis r22,MSR_POW@h
  384. andc r23,r23,r22
  385. stw r23,_MSR(r21)
  386. SAVE_GPR(7, r21)
  387. SAVE_4GPRS(8, r21)
  388. SAVE_8GPRS(12, r21)
  389. SAVE_8GPRS(24, r21)
  390. mflr r23
  391. andi. r24,r23,0x3f00 /* get vector offset */
  392. stw r24,TRAP(r21)
  393. li r22,0
  394. stw r22,RESULT(r21)
  395. mtspr SPRG2,r22 /* r1 is now kernel sp */
  396. lwz r24,0(r23) /* virtual address of handler */
  397. lwz r23,4(r23) /* where to go when done */
  398. mtspr SRR0,r24
  399. mtspr SRR1,r20
  400. mtlr r23
  401. SYNC
  402. rfi /* jump to handler, enable MMU */
  403. int_return:
  404. mfmsr r28 /* Disable interrupts */
  405. li r4,0
  406. ori r4,r4,MSR_EE
  407. andc r28,r28,r4
  408. SYNC /* Some chip revs need this... */
  409. mtmsr r28
  410. SYNC
  411. lwz r2,_CTR(r1)
  412. lwz r0,_LINK(r1)
  413. mtctr r2
  414. mtlr r0
  415. lwz r2,_XER(r1)
  416. lwz r0,_CCR(r1)
  417. mtspr XER,r2
  418. mtcrf 0xFF,r0
  419. REST_10GPRS(3, r1)
  420. REST_10GPRS(13, r1)
  421. REST_8GPRS(23, r1)
  422. REST_GPR(31, r1)
  423. lwz r2,_NIP(r1) /* Restore environment */
  424. lwz r0,_MSR(r1)
  425. mtspr SRR0,r2
  426. mtspr SRR1,r0
  427. lwz r0,GPR0(r1)
  428. lwz r2,GPR2(r1)
  429. lwz r1,GPR1(r1)
  430. SYNC
  431. rfi
  432. .globl dc_read
  433. dc_read:
  434. blr
  435. .globl get_pvr
  436. get_pvr:
  437. mfspr r3, PVR
  438. blr
  439. .globl get_svr
  440. get_svr:
  441. mfspr r3, SVR
  442. blr
  443. /*
  444. * Function: in8
  445. * Description: Input 8 bits
  446. */
  447. .globl in8
  448. in8:
  449. lbz r3,0x0000(r3)
  450. blr
  451. /*
  452. * Function: out8
  453. * Description: Output 8 bits
  454. */
  455. .globl out8
  456. out8:
  457. stb r4,0x0000(r3)
  458. blr
  459. /*
  460. * Function: out16
  461. * Description: Output 16 bits
  462. */
  463. .globl out16
  464. out16:
  465. sth r4,0x0000(r3)
  466. blr
  467. /*
  468. * Function: out16r
  469. * Description: Byte reverse and output 16 bits
  470. */
  471. .globl out16r
  472. out16r:
  473. sthbrx r4,r0,r3
  474. blr
  475. /*
  476. * Function: out32
  477. * Description: Output 32 bits
  478. */
  479. .globl out32
  480. out32:
  481. stw r4,0x0000(r3)
  482. blr
  483. /*
  484. * Function: out32r
  485. * Description: Byte reverse and output 32 bits
  486. */
  487. .globl out32r
  488. out32r:
  489. stwbrx r4,r0,r3
  490. blr
  491. /*
  492. * Function: in16
  493. * Description: Input 16 bits
  494. */
  495. .globl in16
  496. in16:
  497. lhz r3,0x0000(r3)
  498. blr
  499. /*
  500. * Function: in16r
  501. * Description: Input 16 bits and byte reverse
  502. */
  503. .globl in16r
  504. in16r:
  505. lhbrx r3,r0,r3
  506. blr
  507. /*
  508. * Function: in32
  509. * Description: Input 32 bits
  510. */
  511. .globl in32
  512. in32:
  513. lwz 3,0x0000(3)
  514. blr
  515. /*
  516. * Function: in32r
  517. * Description: Input 32 bits and byte reverse
  518. */
  519. .globl in32r
  520. in32r:
  521. lwbrx r3,r0,r3
  522. blr
  523. /*
  524. * void relocate_code (addr_sp, gd, addr_moni)
  525. *
  526. * This "function" does not return, instead it continues in RAM
  527. * after relocating the monitor code.
  528. *
  529. * r3 = dest
  530. * r4 = src
  531. * r5 = length in bytes
  532. * r6 = cachelinesize
  533. */
  534. .globl relocate_code
  535. relocate_code:
  536. mr r1, r3 /* Set new stack pointer */
  537. mr r9, r4 /* Save copy of Global Data pointer */
  538. mr r2, r9 /* Save for DECLARE_GLOBAL_DATA_PTR */
  539. mr r10, r5 /* Save copy of Destination Address */
  540. mr r3, r5 /* Destination Address */
  541. lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
  542. ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
  543. lwz r5, GOT(__init_end)
  544. sub r5, r5, r4
  545. li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
  546. /*
  547. * Fix GOT pointer:
  548. *
  549. * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
  550. *
  551. * Offset:
  552. */
  553. sub r15, r10, r4
  554. /* First our own GOT */
  555. add r14, r14, r15
  556. /* then the one used by the C code */
  557. add r30, r30, r15
  558. /*
  559. * Now relocate code
  560. */
  561. cmplw cr1,r3,r4
  562. addi r0,r5,3
  563. srwi. r0,r0,2
  564. beq cr1,4f /* In place copy is not necessary */
  565. beq 7f /* Protect against 0 count */
  566. mtctr r0
  567. bge cr1,2f
  568. la r8,-4(r4)
  569. la r7,-4(r3)
  570. 1: lwzu r0,4(r8)
  571. stwu r0,4(r7)
  572. bdnz 1b
  573. b 4f
  574. 2: slwi r0,r0,2
  575. add r8,r4,r0
  576. add r7,r3,r0
  577. 3: lwzu r0,-4(r8)
  578. stwu r0,-4(r7)
  579. bdnz 3b
  580. /*
  581. * Now flush the cache: note that we must start from a cache aligned
  582. * address. Otherwise we might miss one cache line.
  583. */
  584. 4: cmpwi r6,0
  585. add r5,r3,r5
  586. beq 7f /* Always flush prefetch queue in any case */
  587. subi r0,r6,1
  588. andc r3,r3,r0
  589. mr r4,r3
  590. 5: dcbst 0,r4
  591. add r4,r4,r6
  592. cmplw r4,r5
  593. blt 5b
  594. sync /* Wait for all dcbst to complete on bus */
  595. mr r4,r3
  596. 6: icbi 0,r4
  597. add r4,r4,r6
  598. cmplw r4,r5
  599. blt 6b
  600. 7: sync /* Wait for all icbi to complete on bus */
  601. isync
  602. /*
  603. * We are done. Do not return, instead branch to second part of board
  604. * initialization, now running from RAM.
  605. */
  606. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  607. mtlr r0
  608. blr
  609. in_ram:
  610. /*
  611. * Relocation Function, r14 point to got2+0x8000
  612. *
  613. * Adjust got2 pointers, no need to check for 0, this code
  614. * already puts a few entries in the table.
  615. */
  616. li r0,__got2_entries@sectoff@l
  617. la r3,GOT(_GOT2_TABLE_)
  618. lwz r11,GOT(_GOT2_TABLE_)
  619. mtctr r0
  620. sub r11,r3,r11
  621. addi r3,r3,-4
  622. 1: lwzu r0,4(r3)
  623. add r0,r0,r11
  624. stw r0,0(r3)
  625. bdnz 1b
  626. /*
  627. * Now adjust the fixups and the pointers to the fixups
  628. * in case we need to move ourselves again.
  629. */
  630. 2: li r0,__fixup_entries@sectoff@l
  631. lwz r3,GOT(_FIXUP_TABLE_)
  632. cmpwi r0,0
  633. mtctr r0
  634. addi r3,r3,-4
  635. beq 4f
  636. 3: lwzu r4,4(r3)
  637. lwzux r0,r4,r11
  638. add r0,r0,r11
  639. stw r10,0(r3)
  640. stw r0,0(r4)
  641. bdnz 3b
  642. 4:
  643. /* clear_bss: */
  644. /*
  645. * Now clear BSS segment
  646. */
  647. lwz r3,GOT(__bss_start)
  648. lwz r4,GOT(_end)
  649. cmplw 0, r3, r4
  650. beq 6f
  651. li r0, 0
  652. 5:
  653. stw r0, 0(r3)
  654. addi r3, r3, 4
  655. cmplw 0, r3, r4
  656. bne 5b
  657. 6:
  658. mr r3, r9 /* Init Date pointer */
  659. mr r4, r10 /* Destination Address */
  660. bl board_init_r
  661. /* not reached - end relocate_code */
  662. /*-----------------------------------------------------------------------*/
  663. /*
  664. * Copy exception vector code to low memory
  665. *
  666. * r3: dest_addr
  667. * r7: source address, r8: end address, r9: target address
  668. */
  669. .globl trap_init
  670. trap_init:
  671. lwz r7, GOT(_start)
  672. lwz r8, GOT(_end_of_vectors)
  673. li r9, 0x100 /* reset vector always at 0x100 */
  674. cmplw 0, r7, r8
  675. bgelr /* return if r7>=r8 - just in case */
  676. mflr r4 /* save link register */
  677. 1:
  678. lwz r0, 0(r7)
  679. stw r0, 0(r9)
  680. addi r7, r7, 4
  681. addi r9, r9, 4
  682. cmplw 0, r7, r8
  683. bne 1b
  684. /*
  685. * relocate `hdlr' and `int_return' entries
  686. */
  687. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  688. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  689. 2:
  690. bl trap_reloc
  691. addi r7, r7, 0x100 /* next exception vector */
  692. cmplw 0, r7, r8
  693. blt 2b
  694. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  695. bl trap_reloc
  696. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  697. bl trap_reloc
  698. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  699. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  700. 3:
  701. bl trap_reloc
  702. addi r7, r7, 0x100 /* next exception vector */
  703. cmplw 0, r7, r8
  704. blt 3b
  705. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  706. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  707. 4:
  708. bl trap_reloc
  709. addi r7, r7, 0x100 /* next exception vector */
  710. cmplw 0, r7, r8
  711. blt 4b
  712. /* enable execptions from RAM vectors */
  713. mfmsr r7
  714. li r8,MSR_IP
  715. andc r7,r7,r8
  716. ori r7,r7,MSR_ME /* Enable Machine Check */
  717. mtmsr r7
  718. mtlr r4 /* restore link register */
  719. blr
  720. /*
  721. * Function: relocate entries for one exception vector
  722. */
  723. trap_reloc:
  724. lwz r0, 0(r7) /* hdlr ... */
  725. add r0, r0, r3 /* ... += dest_addr */
  726. stw r0, 0(r7)
  727. lwz r0, 4(r7) /* int_return ... */
  728. add r0, r0, r3 /* ... += dest_addr */
  729. stw r0, 4(r7)
  730. sync
  731. isync
  732. blr
  733. .globl enable_ext_addr
  734. enable_ext_addr:
  735. mfspr r0, HID0
  736. lis r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@h
  737. ori r0, r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@l
  738. mtspr HID0, r0
  739. sync
  740. isync
  741. blr
  742. #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR)
  743. .globl setup_ccsrbar
  744. setup_ccsrbar:
  745. /* Special sequence needed to update CCSRBAR itself */
  746. lis r4, CONFIG_SYS_CCSRBAR_DEFAULT@h
  747. ori r4, r4, CONFIG_SYS_CCSRBAR_DEFAULT@l
  748. lis r5, CONFIG_SYS_CCSRBAR@h
  749. ori r5, r5, CONFIG_SYS_CCSRBAR@l
  750. srwi r6,r5,12
  751. stw r6, 0(r4)
  752. isync
  753. lis r5, 0xffff
  754. ori r5,r5,0xf000
  755. lwz r5, 0(r5)
  756. isync
  757. lis r3, CONFIG_SYS_CCSRBAR@h
  758. lwz r5, CONFIG_SYS_CCSRBAR@l(r3)
  759. isync
  760. blr
  761. #endif
  762. #ifdef CONFIG_SYS_INIT_RAM_LOCK
  763. lock_ram_in_cache:
  764. /* Allocate Initial RAM in data cache.
  765. */
  766. lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
  767. ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
  768. li r4, ((CONFIG_SYS_INIT_RAM_END & ~31) + \
  769. (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
  770. mtctr r4
  771. 1:
  772. dcbz r0, r3
  773. addi r3, r3, 32
  774. bdnz 1b
  775. #if 1
  776. /* Lock the data cache */
  777. mfspr r0, HID0
  778. ori r0, r0, 0x1000
  779. sync
  780. mtspr HID0, r0
  781. sync
  782. blr
  783. #endif
  784. #if 0
  785. /* Lock the first way of the data cache */
  786. mfspr r0, LDSTCR
  787. ori r0, r0, 0x0080
  788. #if defined(CONFIG_ALTIVEC)
  789. dssall
  790. #endif
  791. sync
  792. mtspr LDSTCR, r0
  793. sync
  794. isync
  795. blr
  796. #endif
  797. .globl unlock_ram_in_cache
  798. unlock_ram_in_cache:
  799. /* invalidate the INIT_RAM section */
  800. lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
  801. ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
  802. li r4, ((CONFIG_SYS_INIT_RAM_END & ~31) + \
  803. (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
  804. mtctr r4
  805. 1: icbi r0, r3
  806. addi r3, r3, 32
  807. bdnz 1b
  808. sync /* Wait for all icbi to complete on bus */
  809. isync
  810. #if 1
  811. /* Unlock the data cache and invalidate it */
  812. mfspr r0, HID0
  813. li r3,0x1000
  814. andc r0,r0,r3
  815. li r3,0x0400
  816. or r0,r0,r3
  817. sync
  818. mtspr HID0, r0
  819. sync
  820. blr
  821. #endif
  822. #if 0
  823. /* Unlock the first way of the data cache */
  824. mfspr r0, LDSTCR
  825. li r3,0x0080
  826. andc r0,r0,r3
  827. #ifdef CONFIG_ALTIVEC
  828. dssall
  829. #endif
  830. sync
  831. mtspr LDSTCR, r0
  832. sync
  833. isync
  834. li r3,0x0400
  835. or r0,r0,r3
  836. sync
  837. mtspr HID0, r0
  838. sync
  839. blr
  840. #endif
  841. #endif
  842. /* If this is a multi-cpu system then we need to handle the
  843. * 2nd cpu. The assumption is that the 2nd cpu is being
  844. * held in boot holdoff mode until the 1st cpu unlocks it
  845. * from Linux. We'll do some basic cpu init and then pass
  846. * it to the Linux Reset Vector.
  847. * Sri: Much of this initialization is not required. Linux
  848. * rewrites the bats, and the sprs and also enables the L1 cache.
  849. */
  850. #if (CONFIG_NUM_CPUS > 1)
  851. .globl secondary_cpu_setup
  852. secondary_cpu_setup:
  853. /* Do only core setup on all cores except cpu0 */
  854. bl invalidate_bats
  855. sync
  856. bl enable_ext_addr
  857. #ifdef CONFIG_SYS_L2
  858. /* init the L2 cache */
  859. addis r3, r0, L2_INIT@h
  860. ori r3, r3, L2_INIT@l
  861. sync
  862. mtspr l2cr, r3
  863. #ifdef CONFIG_ALTIVEC
  864. dssall
  865. #endif
  866. /* invalidate the L2 cache */
  867. bl l2cache_invalidate
  868. sync
  869. #endif
  870. /* enable and invalidate the data cache */
  871. bl dcache_enable
  872. sync
  873. /* enable and invalidate the instruction cache*/
  874. bl icache_enable
  875. sync
  876. /* TBEN in HID0 */
  877. mfspr r4, HID0
  878. oris r4, r4, 0x0400
  879. mtspr HID0, r4
  880. sync
  881. isync
  882. /* MCP|SYNCBE|ABE in HID1 */
  883. mfspr r4, HID1
  884. oris r4, r4, 0x8000
  885. ori r4, r4, 0x0C00
  886. mtspr HID1, r4
  887. sync
  888. isync
  889. lis r3, CONFIG_LINUX_RESET_VEC@h
  890. ori r3, r3, CONFIG_LINUX_RESET_VEC@l
  891. mtlr r3
  892. blr
  893. /* Never Returns, Running in Linux Now */
  894. #endif