start.S 27 KB

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