start.S 23 KB

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