start.S 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  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 CFG_RAMBOOT
  170. /* disable everything */
  171. li r0, 0
  172. mtspr HID0, r0
  173. sync
  174. mtmsr 0
  175. #endif
  176. bl invalidate_bats
  177. sync
  178. #ifdef CFG_L2
  179. /* init the L2 cache */
  180. lis r3, L2_INIT@h
  181. ori r3, r3, L2_INIT@l
  182. mtspr l2cr, r3
  183. /* invalidate the L2 cache */
  184. bl l2cache_invalidate
  185. sync
  186. #endif
  187. /*
  188. * Calculate absolute address in FLASH and jump there
  189. *------------------------------------------------------*/
  190. lis r3, CFG_MONITOR_BASE@h
  191. ori r3, r3, CFG_MONITOR_BASE@l
  192. addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
  193. mtlr r3
  194. blr
  195. in_flash:
  196. /* let the C-code set up the rest */
  197. /* */
  198. /* Be careful to keep code relocatable ! */
  199. /*------------------------------------------------------*/
  200. /* perform low-level init */
  201. /* enable extended addressing */
  202. bl enable_ext_addr
  203. /* setup the bats */
  204. bl early_bats
  205. /*
  206. * Cache must be enabled here for stack-in-cache trick.
  207. * This means we need to enable the BATS.
  208. * Cache should be turned on after BATs, since by default
  209. * everything is write-through.
  210. */
  211. /* enable address translation */
  212. bl enable_addr_trans
  213. sync
  214. /* enable and invalidate the data cache */
  215. /* bl l1dcache_enable */
  216. bl dcache_enable
  217. sync
  218. #if 1
  219. bl icache_enable
  220. #endif
  221. #ifdef CFG_INIT_RAM_LOCK
  222. bl lock_ram_in_cache
  223. sync
  224. #endif
  225. /* set up the stack pointer in our newly created
  226. * cache-ram (r1) */
  227. lis r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@h
  228. ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@l
  229. li r0, 0 /* Make room for stack frame header and */
  230. stwu r0, -4(r1) /* clear final stack frame so that */
  231. stwu r0, -4(r1) /* stack backtraces terminate cleanly */
  232. GET_GOT /* initialize GOT access */
  233. /* setup the rest of the bats */
  234. bl setup_bats
  235. bl clear_tlbs
  236. sync
  237. #if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
  238. /* setup ccsrbar */
  239. bl setup_ccsrbar
  240. #endif
  241. /* run low-level CPU init code (from Flash) */
  242. bl cpu_init_f
  243. sync
  244. #ifdef RUN_DIAG
  245. /* Load PX_AUX register address in r4 */
  246. lis r4, 0xf810
  247. ori r4, r4, 0x6
  248. /* Load contents of PX_AUX in r3 bits 24 to 31*/
  249. lbz r3, 0(r4)
  250. /* Mask and obtain the bit in r3 */
  251. rlwinm. r3, r3, 0, 24, 24
  252. /* If not zero, jump and continue with u-boot */
  253. bne diag_done
  254. /* Load back contents of PX_AUX in r3 bits 24 to 31 */
  255. lbz r3, 0(r4)
  256. /* Set the MSB of the register value */
  257. ori r3, r3, 0x80
  258. /* Write value in r3 back to PX_AUX */
  259. stb r3, 0(r4)
  260. /* Get the address to jump to in r3*/
  261. lis r3, CFG_DIAG_ADDR@h
  262. ori r3, r3, CFG_DIAG_ADDR@l
  263. /* Load the LR with the branch address */
  264. mtlr r3
  265. /* Branch to diagnostic */
  266. blr
  267. diag_done:
  268. #endif
  269. /* bl l2cache_enable */
  270. mr r3, r21
  271. /* r3: BOOTFLAG */
  272. /* run 1st part of board init code (from Flash) */
  273. bl board_init_f
  274. sync
  275. /* NOTREACHED */
  276. .globl invalidate_bats
  277. invalidate_bats:
  278. li r0, 0
  279. /* invalidate BATs */
  280. mtspr IBAT0U, r0
  281. mtspr IBAT1U, r0
  282. mtspr IBAT2U, r0
  283. mtspr IBAT3U, r0
  284. mtspr IBAT4U, r0
  285. mtspr IBAT5U, r0
  286. mtspr IBAT6U, r0
  287. mtspr IBAT7U, r0
  288. isync
  289. mtspr DBAT0U, r0
  290. mtspr DBAT1U, r0
  291. mtspr DBAT2U, r0
  292. mtspr DBAT3U, r0
  293. mtspr DBAT4U, r0
  294. mtspr DBAT5U, r0
  295. mtspr DBAT6U, r0
  296. mtspr DBAT7U, r0
  297. isync
  298. sync
  299. blr
  300. /* setup_bats - set them up to some initial state */
  301. /* Skip any BATS setup in early_bats */
  302. .globl setup_bats
  303. setup_bats:
  304. addis r0, r0, 0x0000
  305. /* IBAT 0 */
  306. addis r4, r0, CFG_IBAT0L@h
  307. ori r4, r4, CFG_IBAT0L@l
  308. addis r3, r0, CFG_IBAT0U@h
  309. ori r3, r3, CFG_IBAT0U@l
  310. mtspr IBAT0L, r4
  311. mtspr IBAT0U, r3
  312. isync
  313. /* DBAT 0 */
  314. addis r4, r0, CFG_DBAT0L@h
  315. ori r4, r4, CFG_DBAT0L@l
  316. addis r3, r0, CFG_DBAT0U@h
  317. ori r3, r3, CFG_DBAT0U@l
  318. mtspr DBAT0L, r4
  319. mtspr DBAT0U, r3
  320. isync
  321. /* IBAT 1 */
  322. addis r4, r0, CFG_IBAT1L@h
  323. ori r4, r4, CFG_IBAT1L@l
  324. addis r3, r0, CFG_IBAT1U@h
  325. ori r3, r3, CFG_IBAT1U@l
  326. mtspr IBAT1L, r4
  327. mtspr IBAT1U, r3
  328. isync
  329. /* DBAT 1 */
  330. addis r4, r0, CFG_DBAT1L@h
  331. ori r4, r4, CFG_DBAT1L@l
  332. addis r3, r0, CFG_DBAT1U@h
  333. ori r3, r3, CFG_DBAT1U@l
  334. mtspr DBAT1L, r4
  335. mtspr DBAT1U, r3
  336. isync
  337. /* IBAT 2 */
  338. addis r4, r0, CFG_IBAT2L@h
  339. ori r4, r4, CFG_IBAT2L@l
  340. addis r3, r0, CFG_IBAT2U@h
  341. ori r3, r3, CFG_IBAT2U@l
  342. mtspr IBAT2L, r4
  343. mtspr IBAT2U, r3
  344. isync
  345. /* DBAT 2 */
  346. addis r4, r0, CFG_DBAT2L@h
  347. ori r4, r4, CFG_DBAT2L@l
  348. addis r3, r0, CFG_DBAT2U@h
  349. ori r3, r3, CFG_DBAT2U@l
  350. mtspr DBAT2L, r4
  351. mtspr DBAT2U, r3
  352. isync
  353. /* IBAT 3 */
  354. addis r4, r0, CFG_IBAT3L@h
  355. ori r4, r4, CFG_IBAT3L@l
  356. addis r3, r0, CFG_IBAT3U@h
  357. ori r3, r3, CFG_IBAT3U@l
  358. mtspr IBAT3L, r4
  359. mtspr IBAT3U, r3
  360. isync
  361. /* DBAT 3 */
  362. addis r4, r0, CFG_DBAT3L@h
  363. ori r4, r4, CFG_DBAT3L@l
  364. addis r3, r0, CFG_DBAT3U@h
  365. ori r3, r3, CFG_DBAT3U@l
  366. mtspr DBAT3L, r4
  367. mtspr DBAT3U, r3
  368. isync
  369. /* IBAT 4 */
  370. addis r4, r0, CFG_IBAT4L@h
  371. ori r4, r4, CFG_IBAT4L@l
  372. addis r3, r0, CFG_IBAT4U@h
  373. ori r3, r3, CFG_IBAT4U@l
  374. mtspr IBAT4L, r4
  375. mtspr IBAT4U, r3
  376. isync
  377. /* DBAT 4 */
  378. addis r4, r0, CFG_DBAT4L@h
  379. ori r4, r4, CFG_DBAT4L@l
  380. addis r3, r0, CFG_DBAT4U@h
  381. ori r3, r3, CFG_DBAT4U@l
  382. mtspr DBAT4L, r4
  383. mtspr DBAT4U, r3
  384. isync
  385. /* IBAT 7 */
  386. addis r4, r0, CFG_IBAT7L@h
  387. ori r4, r4, CFG_IBAT7L@l
  388. addis r3, r0, CFG_IBAT7U@h
  389. ori r3, r3, CFG_IBAT7U@l
  390. mtspr IBAT7L, r4
  391. mtspr IBAT7U, r3
  392. isync
  393. /* DBAT 7 */
  394. addis r4, r0, CFG_DBAT7L@h
  395. ori r4, r4, CFG_DBAT7L@l
  396. addis r3, r0, CFG_DBAT7U@h
  397. ori r3, r3, CFG_DBAT7U@l
  398. mtspr DBAT7L, r4
  399. mtspr DBAT7U, r3
  400. isync
  401. sync
  402. blr
  403. /*
  404. * early_bats:
  405. *
  406. * Set up bats needed early on - this is usually the BAT for the
  407. * stack-in-cache and the Flash
  408. */
  409. .globl early_bats
  410. early_bats:
  411. /* IBAT 5 */
  412. lis r4, CFG_IBAT5L@h
  413. ori r4, r4, CFG_IBAT5L@l
  414. lis r3, CFG_IBAT5U@h
  415. ori r3, r3, CFG_IBAT5U@l
  416. mtspr IBAT5L, r4
  417. mtspr IBAT5U, r3
  418. isync
  419. /* DBAT 5 */
  420. lis r4, CFG_DBAT5L@h
  421. ori r4, r4, CFG_DBAT5L@l
  422. lis r3, CFG_DBAT5U@h
  423. ori r3, r3, CFG_DBAT5U@l
  424. mtspr DBAT5L, r4
  425. mtspr DBAT5U, r3
  426. isync
  427. /* IBAT 6 */
  428. lis r4, CFG_IBAT6L@h
  429. ori r4, r4, CFG_IBAT6L@l
  430. lis r3, CFG_IBAT6U@h
  431. ori r3, r3, CFG_IBAT6U@l
  432. mtspr IBAT6L, r4
  433. mtspr IBAT6U, r3
  434. isync
  435. /* DBAT 6 */
  436. lis r4, CFG_DBAT6L@h
  437. ori r4, r4, CFG_DBAT6L@l
  438. lis r3, CFG_DBAT6U@h
  439. ori r3, r3, CFG_DBAT6U@l
  440. mtspr DBAT6L, r4
  441. mtspr DBAT6U, r3
  442. isync
  443. blr
  444. .globl clear_tlbs
  445. clear_tlbs:
  446. addis r3, 0, 0x0000
  447. addis r5, 0, 0x4
  448. isync
  449. tlblp:
  450. tlbie r3
  451. sync
  452. addi r3, r3, 0x1000
  453. cmp 0, 0, r3, r5
  454. blt tlblp
  455. blr
  456. .globl enable_addr_trans
  457. enable_addr_trans:
  458. /* enable address translation */
  459. mfmsr r5
  460. ori r5, r5, (MSR_IR | MSR_DR)
  461. mtmsr r5
  462. isync
  463. blr
  464. .globl disable_addr_trans
  465. disable_addr_trans:
  466. /* disable address translation */
  467. mflr r4
  468. mfmsr r3
  469. andi. r0, r3, (MSR_IR | MSR_DR)
  470. beqlr
  471. andc r3, r3, r0
  472. mtspr SRR0, r4
  473. mtspr SRR1, r3
  474. rfi
  475. /*
  476. * This code finishes saving the registers to the exception frame
  477. * and jumps to the appropriate handler for the exception.
  478. * Register r21 is pointer into trap frame, r1 has new stack pointer.
  479. */
  480. .globl transfer_to_handler
  481. transfer_to_handler:
  482. stw r22,_NIP(r21)
  483. lis r22,MSR_POW@h
  484. andc r23,r23,r22
  485. stw r23,_MSR(r21)
  486. SAVE_GPR(7, r21)
  487. SAVE_4GPRS(8, r21)
  488. SAVE_8GPRS(12, r21)
  489. SAVE_8GPRS(24, r21)
  490. mflr r23
  491. andi. r24,r23,0x3f00 /* get vector offset */
  492. stw r24,TRAP(r21)
  493. li r22,0
  494. stw r22,RESULT(r21)
  495. mtspr SPRG2,r22 /* r1 is now kernel sp */
  496. lwz r24,0(r23) /* virtual address of handler */
  497. lwz r23,4(r23) /* where to go when done */
  498. mtspr SRR0,r24
  499. mtspr SRR1,r20
  500. mtlr r23
  501. SYNC
  502. rfi /* jump to handler, enable MMU */
  503. int_return:
  504. mfmsr r28 /* Disable interrupts */
  505. li r4,0
  506. ori r4,r4,MSR_EE
  507. andc r28,r28,r4
  508. SYNC /* Some chip revs need this... */
  509. mtmsr r28
  510. SYNC
  511. lwz r2,_CTR(r1)
  512. lwz r0,_LINK(r1)
  513. mtctr r2
  514. mtlr r0
  515. lwz r2,_XER(r1)
  516. lwz r0,_CCR(r1)
  517. mtspr XER,r2
  518. mtcrf 0xFF,r0
  519. REST_10GPRS(3, r1)
  520. REST_10GPRS(13, r1)
  521. REST_8GPRS(23, r1)
  522. REST_GPR(31, r1)
  523. lwz r2,_NIP(r1) /* Restore environment */
  524. lwz r0,_MSR(r1)
  525. mtspr SRR0,r2
  526. mtspr SRR1,r0
  527. lwz r0,GPR0(r1)
  528. lwz r2,GPR2(r1)
  529. lwz r1,GPR1(r1)
  530. SYNC
  531. rfi
  532. .globl dc_read
  533. dc_read:
  534. blr
  535. .globl get_pvr
  536. get_pvr:
  537. mfspr r3, PVR
  538. blr
  539. .globl get_svr
  540. get_svr:
  541. mfspr r3, SVR
  542. blr
  543. /*
  544. * Function: in8
  545. * Description: Input 8 bits
  546. */
  547. .globl in8
  548. in8:
  549. lbz r3,0x0000(r3)
  550. blr
  551. /*
  552. * Function: out8
  553. * Description: Output 8 bits
  554. */
  555. .globl out8
  556. out8:
  557. stb r4,0x0000(r3)
  558. blr
  559. /*
  560. * Function: out16
  561. * Description: Output 16 bits
  562. */
  563. .globl out16
  564. out16:
  565. sth r4,0x0000(r3)
  566. blr
  567. /*
  568. * Function: out16r
  569. * Description: Byte reverse and output 16 bits
  570. */
  571. .globl out16r
  572. out16r:
  573. sthbrx r4,r0,r3
  574. blr
  575. /*
  576. * Function: out32
  577. * Description: Output 32 bits
  578. */
  579. .globl out32
  580. out32:
  581. stw r4,0x0000(r3)
  582. blr
  583. /*
  584. * Function: out32r
  585. * Description: Byte reverse and output 32 bits
  586. */
  587. .globl out32r
  588. out32r:
  589. stwbrx r4,r0,r3
  590. blr
  591. /*
  592. * Function: in16
  593. * Description: Input 16 bits
  594. */
  595. .globl in16
  596. in16:
  597. lhz r3,0x0000(r3)
  598. blr
  599. /*
  600. * Function: in16r
  601. * Description: Input 16 bits and byte reverse
  602. */
  603. .globl in16r
  604. in16r:
  605. lhbrx r3,r0,r3
  606. blr
  607. /*
  608. * Function: in32
  609. * Description: Input 32 bits
  610. */
  611. .globl in32
  612. in32:
  613. lwz 3,0x0000(3)
  614. blr
  615. /*
  616. * Function: in32r
  617. * Description: Input 32 bits and byte reverse
  618. */
  619. .globl in32r
  620. in32r:
  621. lwbrx r3,r0,r3
  622. blr
  623. /*
  624. * Function: ppcDcbf
  625. * Description: Data Cache block flush
  626. * Input: r3 = effective address
  627. * Output: none.
  628. */
  629. .globl ppcDcbf
  630. ppcDcbf:
  631. dcbf r0,r3
  632. blr
  633. /*
  634. * Function: ppcDcbi
  635. * Description: Data Cache block Invalidate
  636. * Input: r3 = effective address
  637. * Output: none.
  638. */
  639. .globl ppcDcbi
  640. ppcDcbi:
  641. dcbi r0,r3
  642. blr
  643. /*
  644. * Function: ppcDcbz
  645. * Description: Data Cache block zero.
  646. * Input: r3 = effective address
  647. * Output: none.
  648. */
  649. .globl ppcDcbz
  650. ppcDcbz:
  651. dcbz r0,r3
  652. blr
  653. /*
  654. * Function: ppcSync
  655. * Description: Processor Synchronize
  656. * Input: none.
  657. * Output: none.
  658. */
  659. .globl ppcSync
  660. ppcSync:
  661. sync
  662. blr
  663. /*
  664. * void relocate_code (addr_sp, gd, addr_moni)
  665. *
  666. * This "function" does not return, instead it continues in RAM
  667. * after relocating the monitor code.
  668. *
  669. * r3 = dest
  670. * r4 = src
  671. * r5 = length in bytes
  672. * r6 = cachelinesize
  673. */
  674. .globl relocate_code
  675. relocate_code:
  676. mr r1, r3 /* Set new stack pointer */
  677. mr r9, r4 /* Save copy of Global Data pointer */
  678. mr r29, r9 /* Save for DECLARE_GLOBAL_DATA_PTR */
  679. mr r10, r5 /* Save copy of Destination Address */
  680. mr r3, r5 /* Destination Address */
  681. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  682. ori r4, r4, CFG_MONITOR_BASE@l
  683. lwz r5, GOT(__init_end)
  684. sub r5, r5, r4
  685. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  686. /*
  687. * Fix GOT pointer:
  688. *
  689. * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
  690. *
  691. * Offset:
  692. */
  693. sub r15, r10, r4
  694. /* First our own GOT */
  695. add r14, r14, r15
  696. /* then the one used by the C code */
  697. add r30, r30, r15
  698. /*
  699. * Now relocate code
  700. */
  701. #ifdef CONFIG_ECC
  702. bl board_relocate_rom
  703. sync
  704. mr r3, r10 /* Destination Address */
  705. lis r4, CFG_MONITOR_BASE@h /* Source Address */
  706. ori r4, r4, CFG_MONITOR_BASE@l
  707. lwz r5, GOT(__init_end)
  708. sub r5, r5, r4
  709. li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
  710. #else
  711. cmplw cr1,r3,r4
  712. addi r0,r5,3
  713. srwi. r0,r0,2
  714. beq cr1,4f /* In place copy is not necessary */
  715. beq 7f /* Protect against 0 count */
  716. mtctr r0
  717. bge cr1,2f
  718. la r8,-4(r4)
  719. la r7,-4(r3)
  720. 1: lwzu r0,4(r8)
  721. stwu r0,4(r7)
  722. bdnz 1b
  723. b 4f
  724. 2: slwi r0,r0,2
  725. add r8,r4,r0
  726. add r7,r3,r0
  727. 3: lwzu r0,-4(r8)
  728. stwu r0,-4(r7)
  729. bdnz 3b
  730. #endif
  731. /*
  732. * Now flush the cache: note that we must start from a cache aligned
  733. * address. Otherwise we might miss one cache line.
  734. */
  735. 4: cmpwi r6,0
  736. add r5,r3,r5
  737. beq 7f /* Always flush prefetch queue in any case */
  738. subi r0,r6,1
  739. andc r3,r3,r0
  740. mr r4,r3
  741. 5: dcbst 0,r4
  742. add r4,r4,r6
  743. cmplw r4,r5
  744. blt 5b
  745. sync /* Wait for all dcbst to complete on bus */
  746. mr r4,r3
  747. 6: icbi 0,r4
  748. add r4,r4,r6
  749. cmplw r4,r5
  750. blt 6b
  751. 7: sync /* Wait for all icbi to complete on bus */
  752. isync
  753. /*
  754. * We are done. Do not return, instead branch to second part of board
  755. * initialization, now running from RAM.
  756. */
  757. addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
  758. mtlr r0
  759. blr
  760. in_ram:
  761. #ifdef CONFIG_ECC
  762. bl board_init_ecc
  763. #endif
  764. /*
  765. * Relocation Function, r14 point to got2+0x8000
  766. *
  767. * Adjust got2 pointers, no need to check for 0, this code
  768. * already puts a few entries in the table.
  769. */
  770. li r0,__got2_entries@sectoff@l
  771. la r3,GOT(_GOT2_TABLE_)
  772. lwz r11,GOT(_GOT2_TABLE_)
  773. mtctr r0
  774. sub r11,r3,r11
  775. addi r3,r3,-4
  776. 1: lwzu r0,4(r3)
  777. add r0,r0,r11
  778. stw r0,0(r3)
  779. bdnz 1b
  780. /*
  781. * Now adjust the fixups and the pointers to the fixups
  782. * in case we need to move ourselves again.
  783. */
  784. 2: li r0,__fixup_entries@sectoff@l
  785. lwz r3,GOT(_FIXUP_TABLE_)
  786. cmpwi r0,0
  787. mtctr r0
  788. addi r3,r3,-4
  789. beq 4f
  790. 3: lwzu r4,4(r3)
  791. lwzux r0,r4,r11
  792. add r0,r0,r11
  793. stw r10,0(r3)
  794. stw r0,0(r4)
  795. bdnz 3b
  796. 4:
  797. /* clear_bss: */
  798. /*
  799. * Now clear BSS segment
  800. */
  801. lwz r3,GOT(__bss_start)
  802. lwz r4,GOT(_end)
  803. cmplw 0, r3, r4
  804. beq 6f
  805. li r0, 0
  806. 5:
  807. stw r0, 0(r3)
  808. addi r3, r3, 4
  809. cmplw 0, r3, r4
  810. bne 5b
  811. 6:
  812. mr r3, r9 /* Init Date pointer */
  813. mr r4, r10 /* Destination Address */
  814. bl board_init_r
  815. /* not reached - end relocate_code */
  816. /*-----------------------------------------------------------------------*/
  817. /*
  818. * Copy exception vector code to low memory
  819. *
  820. * r3: dest_addr
  821. * r7: source address, r8: end address, r9: target address
  822. */
  823. .globl trap_init
  824. trap_init:
  825. lwz r7, GOT(_start)
  826. lwz r8, GOT(_end_of_vectors)
  827. li r9, 0x100 /* reset vector always at 0x100 */
  828. cmplw 0, r7, r8
  829. bgelr /* return if r7>=r8 - just in case */
  830. mflr r4 /* save link register */
  831. 1:
  832. lwz r0, 0(r7)
  833. stw r0, 0(r9)
  834. addi r7, r7, 4
  835. addi r9, r9, 4
  836. cmplw 0, r7, r8
  837. bne 1b
  838. /*
  839. * relocate `hdlr' and `int_return' entries
  840. */
  841. li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
  842. li r8, Alignment - _start + EXC_OFF_SYS_RESET
  843. 2:
  844. bl trap_reloc
  845. addi r7, r7, 0x100 /* next exception vector */
  846. cmplw 0, r7, r8
  847. blt 2b
  848. li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
  849. bl trap_reloc
  850. li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
  851. bl trap_reloc
  852. li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
  853. li r8, SystemCall - _start + EXC_OFF_SYS_RESET
  854. 3:
  855. bl trap_reloc
  856. addi r7, r7, 0x100 /* next exception vector */
  857. cmplw 0, r7, r8
  858. blt 3b
  859. li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
  860. li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
  861. 4:
  862. bl trap_reloc
  863. addi r7, r7, 0x100 /* next exception vector */
  864. cmplw 0, r7, r8
  865. blt 4b
  866. /* enable execptions from RAM vectors */
  867. mfmsr r7
  868. li r8,MSR_IP
  869. andc r7,r7,r8
  870. ori r7,r7,MSR_ME /* Enable Machine Check */
  871. mtmsr r7
  872. mtlr r4 /* restore link register */
  873. blr
  874. /*
  875. * Function: relocate entries for one exception vector
  876. */
  877. trap_reloc:
  878. lwz r0, 0(r7) /* hdlr ... */
  879. add r0, r0, r3 /* ... += dest_addr */
  880. stw r0, 0(r7)
  881. lwz r0, 4(r7) /* int_return ... */
  882. add r0, r0, r3 /* ... += dest_addr */
  883. stw r0, 4(r7)
  884. sync
  885. isync
  886. blr
  887. .globl enable_ext_addr
  888. enable_ext_addr:
  889. mfspr r0, HID0
  890. lis r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@h
  891. ori r0, r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@l
  892. mtspr HID0, r0
  893. sync
  894. isync
  895. blr
  896. #if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
  897. .globl setup_ccsrbar
  898. setup_ccsrbar:
  899. /* Special sequence needed to update CCSRBAR itself */
  900. lis r4, CFG_CCSRBAR_DEFAULT@h
  901. ori r4, r4, CFG_CCSRBAR_DEFAULT@l
  902. lis r5, CFG_CCSRBAR@h
  903. ori r5, r5, CFG_CCSRBAR@l
  904. srwi r6,r5,12
  905. stw r6, 0(r4)
  906. isync
  907. lis r5, 0xffff
  908. ori r5,r5,0xf000
  909. lwz r5, 0(r5)
  910. isync
  911. lis r3, CFG_CCSRBAR@h
  912. lwz r5, CFG_CCSRBAR@l(r3)
  913. isync
  914. blr
  915. #endif
  916. #ifdef CFG_INIT_RAM_LOCK
  917. lock_ram_in_cache:
  918. /* Allocate Initial RAM in data cache.
  919. */
  920. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  921. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  922. li r2, ((CFG_INIT_RAM_END & ~31) + \
  923. (CFG_INIT_RAM_ADDR & 31) + 31) / 32
  924. mtctr r2
  925. 1:
  926. dcbz r0, r3
  927. addi r3, r3, 32
  928. bdnz 1b
  929. #if 1
  930. /* Lock the data cache */
  931. mfspr r0, HID0
  932. ori r0, r0, 0x1000
  933. sync
  934. mtspr HID0, r0
  935. sync
  936. blr
  937. #endif
  938. #if 0
  939. /* Lock the first way of the data cache */
  940. mfspr r0, LDSTCR
  941. ori r0, r0, 0x0080
  942. #if defined(CONFIG_ALTIVEC)
  943. dssall
  944. #endif
  945. sync
  946. mtspr LDSTCR, r0
  947. sync
  948. isync
  949. blr
  950. #endif
  951. .globl unlock_ram_in_cache
  952. unlock_ram_in_cache:
  953. /* invalidate the INIT_RAM section */
  954. lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
  955. ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
  956. li r2, ((CFG_INIT_RAM_END & ~31) + \
  957. (CFG_INIT_RAM_ADDR & 31) + 31) / 32
  958. mtctr r2
  959. 1: icbi r0, r3
  960. addi r3, r3, 32
  961. bdnz 1b
  962. sync /* Wait for all icbi to complete on bus */
  963. isync
  964. #if 1
  965. /* Unlock the data cache and invalidate it */
  966. mfspr r0, HID0
  967. li r3,0x1000
  968. andc r0,r0,r3
  969. li r3,0x0400
  970. or r0,r0,r3
  971. sync
  972. mtspr HID0, r0
  973. sync
  974. blr
  975. #endif
  976. #if 0
  977. /* Unlock the first way of the data cache */
  978. mfspr r0, LDSTCR
  979. li r3,0x0080
  980. andc r0,r0,r3
  981. #ifdef CONFIG_ALTIVEC
  982. dssall
  983. #endif
  984. sync
  985. mtspr LDSTCR, r0
  986. sync
  987. isync
  988. li r3,0x0400
  989. or r0,r0,r3
  990. sync
  991. mtspr HID0, r0
  992. sync
  993. blr
  994. #endif
  995. #endif
  996. /* If this is a multi-cpu system then we need to handle the
  997. * 2nd cpu. The assumption is that the 2nd cpu is being
  998. * held in boot holdoff mode until the 1st cpu unlocks it
  999. * from Linux. We'll do some basic cpu init and then pass
  1000. * it to the Linux Reset Vector.
  1001. * Sri: Much of this initialization is not required. Linux
  1002. * rewrites the bats, and the sprs and also enables the L1 cache.
  1003. */
  1004. #if (CONFIG_NUM_CPUS > 1)
  1005. .globl secondary_cpu_setup
  1006. secondary_cpu_setup:
  1007. /* Do only core setup on all cores except cpu0 */
  1008. bl invalidate_bats
  1009. sync
  1010. bl enable_ext_addr
  1011. #ifdef CFG_L2
  1012. /* init the L2 cache */
  1013. addis r3, r0, L2_INIT@h
  1014. ori r3, r3, L2_INIT@l
  1015. sync
  1016. mtspr l2cr, r3
  1017. #ifdef CONFIG_ALTIVEC
  1018. dssall
  1019. #endif
  1020. /* invalidate the L2 cache */
  1021. bl l2cache_invalidate
  1022. sync
  1023. #endif
  1024. /* enable and invalidate the data cache */
  1025. bl dcache_enable
  1026. sync
  1027. /* enable and invalidate the instruction cache*/
  1028. bl icache_enable
  1029. sync
  1030. /* TBEN in HID0 */
  1031. mfspr r4, HID0
  1032. oris r4, r4, 0x0400
  1033. mtspr HID0, r4
  1034. sync
  1035. isync
  1036. /* MCP|SYNCBE|ABE in HID1 */
  1037. mfspr r4, HID1
  1038. oris r4, r4, 0x8000
  1039. ori r4, r4, 0x0C00
  1040. mtspr HID1, r4
  1041. sync
  1042. isync
  1043. lis r3, CONFIG_LINUX_RESET_VEC@h
  1044. ori r3, r3, CONFIG_LINUX_RESET_VEC@l
  1045. mtlr r3
  1046. blr
  1047. /* Never Returns, Running in Linux Now */
  1048. #endif