start.S 22 KB

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