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