misc_32.S 20 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. /*
  2. * This file contains miscellaneous low-level functions.
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
  6. * and Paul Mackerras.
  7. *
  8. * kexec bits:
  9. * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com>
  10. * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. *
  17. */
  18. #include <linux/sys.h>
  19. #include <asm/unistd.h>
  20. #include <asm/errno.h>
  21. #include <asm/reg.h>
  22. #include <asm/page.h>
  23. #include <asm/cache.h>
  24. #include <asm/cputable.h>
  25. #include <asm/mmu.h>
  26. #include <asm/ppc_asm.h>
  27. #include <asm/thread_info.h>
  28. #include <asm/asm-offsets.h>
  29. #include <asm/processor.h>
  30. #include <asm/kexec.h>
  31. .text
  32. #ifdef CONFIG_IRQSTACKS
  33. _GLOBAL(call_do_softirq)
  34. mflr r0
  35. stw r0,4(r1)
  36. stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
  37. mr r1,r3
  38. bl __do_softirq
  39. lwz r1,0(r1)
  40. lwz r0,4(r1)
  41. mtlr r0
  42. blr
  43. _GLOBAL(call_handle_irq)
  44. mflr r0
  45. stw r0,4(r1)
  46. mtctr r6
  47. stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r5)
  48. mr r1,r5
  49. bctrl
  50. lwz r1,0(r1)
  51. lwz r0,4(r1)
  52. mtlr r0
  53. blr
  54. #endif /* CONFIG_IRQSTACKS */
  55. /*
  56. * This returns the high 64 bits of the product of two 64-bit numbers.
  57. */
  58. _GLOBAL(mulhdu)
  59. cmpwi r6,0
  60. cmpwi cr1,r3,0
  61. mr r10,r4
  62. mulhwu r4,r4,r5
  63. beq 1f
  64. mulhwu r0,r10,r6
  65. mullw r7,r10,r5
  66. addc r7,r0,r7
  67. addze r4,r4
  68. 1: beqlr cr1 /* all done if high part of A is 0 */
  69. mr r10,r3
  70. mullw r9,r3,r5
  71. mulhwu r3,r3,r5
  72. beq 2f
  73. mullw r0,r10,r6
  74. mulhwu r8,r10,r6
  75. addc r7,r0,r7
  76. adde r4,r4,r8
  77. addze r3,r3
  78. 2: addc r4,r4,r9
  79. addze r3,r3
  80. blr
  81. /*
  82. * sub_reloc_offset(x) returns x - reloc_offset().
  83. */
  84. _GLOBAL(sub_reloc_offset)
  85. mflr r0
  86. bl 1f
  87. 1: mflr r5
  88. lis r4,1b@ha
  89. addi r4,r4,1b@l
  90. subf r5,r4,r5
  91. subf r3,r5,r3
  92. mtlr r0
  93. blr
  94. /*
  95. * reloc_got2 runs through the .got2 section adding an offset
  96. * to each entry.
  97. */
  98. _GLOBAL(reloc_got2)
  99. mflr r11
  100. lis r7,__got2_start@ha
  101. addi r7,r7,__got2_start@l
  102. lis r8,__got2_end@ha
  103. addi r8,r8,__got2_end@l
  104. subf r8,r7,r8
  105. srwi. r8,r8,2
  106. beqlr
  107. mtctr r8
  108. bl 1f
  109. 1: mflr r0
  110. lis r4,1b@ha
  111. addi r4,r4,1b@l
  112. subf r0,r4,r0
  113. add r7,r0,r7
  114. 2: lwz r0,0(r7)
  115. add r0,r0,r3
  116. stw r0,0(r7)
  117. addi r7,r7,4
  118. bdnz 2b
  119. mtlr r11
  120. blr
  121. /*
  122. * call_setup_cpu - call the setup_cpu function for this cpu
  123. * r3 = data offset, r24 = cpu number
  124. *
  125. * Setup function is called with:
  126. * r3 = data offset
  127. * r4 = ptr to CPU spec (relocated)
  128. */
  129. _GLOBAL(call_setup_cpu)
  130. addis r4,r3,cur_cpu_spec@ha
  131. addi r4,r4,cur_cpu_spec@l
  132. lwz r4,0(r4)
  133. add r4,r4,r3
  134. lwz r5,CPU_SPEC_SETUP(r4)
  135. cmpwi 0,r5,0
  136. add r5,r5,r3
  137. beqlr
  138. mtctr r5
  139. bctr
  140. #if defined(CONFIG_CPU_FREQ_PMAC) && defined(CONFIG_6xx)
  141. /* This gets called by via-pmu.c to switch the PLL selection
  142. * on 750fx CPU. This function should really be moved to some
  143. * other place (as most of the cpufreq code in via-pmu
  144. */
  145. _GLOBAL(low_choose_750fx_pll)
  146. /* Clear MSR:EE */
  147. mfmsr r7
  148. rlwinm r0,r7,0,17,15
  149. mtmsr r0
  150. /* If switching to PLL1, disable HID0:BTIC */
  151. cmplwi cr0,r3,0
  152. beq 1f
  153. mfspr r5,SPRN_HID0
  154. rlwinm r5,r5,0,27,25
  155. sync
  156. mtspr SPRN_HID0,r5
  157. isync
  158. sync
  159. 1:
  160. /* Calc new HID1 value */
  161. mfspr r4,SPRN_HID1 /* Build a HID1:PS bit from parameter */
  162. rlwinm r5,r3,16,15,15 /* Clear out HID1:PS from value read */
  163. rlwinm r4,r4,0,16,14 /* Could have I used rlwimi here ? */
  164. or r4,r4,r5
  165. mtspr SPRN_HID1,r4
  166. /* Store new HID1 image */
  167. rlwinm r6,r1,0,0,(31-THREAD_SHIFT)
  168. lwz r6,TI_CPU(r6)
  169. slwi r6,r6,2
  170. addis r6,r6,nap_save_hid1@ha
  171. stw r4,nap_save_hid1@l(r6)
  172. /* If switching to PLL0, enable HID0:BTIC */
  173. cmplwi cr0,r3,0
  174. bne 1f
  175. mfspr r5,SPRN_HID0
  176. ori r5,r5,HID0_BTIC
  177. sync
  178. mtspr SPRN_HID0,r5
  179. isync
  180. sync
  181. 1:
  182. /* Return */
  183. mtmsr r7
  184. blr
  185. _GLOBAL(low_choose_7447a_dfs)
  186. /* Clear MSR:EE */
  187. mfmsr r7
  188. rlwinm r0,r7,0,17,15
  189. mtmsr r0
  190. /* Calc new HID1 value */
  191. mfspr r4,SPRN_HID1
  192. insrwi r4,r3,1,9 /* insert parameter into bit 9 */
  193. sync
  194. mtspr SPRN_HID1,r4
  195. sync
  196. isync
  197. /* Return */
  198. mtmsr r7
  199. blr
  200. #endif /* CONFIG_CPU_FREQ_PMAC && CONFIG_6xx */
  201. /*
  202. * complement mask on the msr then "or" some values on.
  203. * _nmask_and_or_msr(nmask, value_to_or)
  204. */
  205. _GLOBAL(_nmask_and_or_msr)
  206. mfmsr r0 /* Get current msr */
  207. andc r0,r0,r3 /* And off the bits set in r3 (first parm) */
  208. or r0,r0,r4 /* Or on the bits in r4 (second parm) */
  209. SYNC /* Some chip revs have problems here... */
  210. mtmsr r0 /* Update machine state */
  211. isync
  212. blr /* Done */
  213. #ifdef CONFIG_40x
  214. /*
  215. * Do an IO access in real mode
  216. */
  217. _GLOBAL(real_readb)
  218. mfmsr r7
  219. ori r0,r7,MSR_DR
  220. xori r0,r0,MSR_DR
  221. sync
  222. mtmsr r0
  223. sync
  224. isync
  225. lbz r3,0(r3)
  226. sync
  227. mtmsr r7
  228. sync
  229. isync
  230. blr
  231. /*
  232. * Do an IO access in real mode
  233. */
  234. _GLOBAL(real_writeb)
  235. mfmsr r7
  236. ori r0,r7,MSR_DR
  237. xori r0,r0,MSR_DR
  238. sync
  239. mtmsr r0
  240. sync
  241. isync
  242. stb r3,0(r4)
  243. sync
  244. mtmsr r7
  245. sync
  246. isync
  247. blr
  248. #endif /* CONFIG_40x */
  249. /*
  250. * Flush MMU TLB
  251. */
  252. #ifndef CONFIG_FSL_BOOKE
  253. _GLOBAL(_tlbil_all)
  254. _GLOBAL(_tlbil_pid)
  255. #endif
  256. _GLOBAL(_tlbia)
  257. #if defined(CONFIG_40x)
  258. sync /* Flush to memory before changing mapping */
  259. tlbia
  260. isync /* Flush shadow TLB */
  261. #elif defined(CONFIG_44x)
  262. li r3,0
  263. sync
  264. /* Load high watermark */
  265. lis r4,tlb_44x_hwater@ha
  266. lwz r5,tlb_44x_hwater@l(r4)
  267. 1: tlbwe r3,r3,PPC44x_TLB_PAGEID
  268. addi r3,r3,1
  269. cmpw 0,r3,r5
  270. ble 1b
  271. isync
  272. #elif defined(CONFIG_FSL_BOOKE)
  273. /* Invalidate all entries in TLB0 */
  274. li r3, 0x04
  275. tlbivax 0,3
  276. /* Invalidate all entries in TLB1 */
  277. li r3, 0x0c
  278. tlbivax 0,3
  279. msync
  280. #ifdef CONFIG_SMP
  281. tlbsync
  282. #endif /* CONFIG_SMP */
  283. #else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */
  284. #if defined(CONFIG_SMP)
  285. rlwinm r8,r1,0,0,(31-THREAD_SHIFT)
  286. lwz r8,TI_CPU(r8)
  287. oris r8,r8,10
  288. mfmsr r10
  289. SYNC
  290. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  291. rlwinm r0,r0,0,28,26 /* clear DR */
  292. mtmsr r0
  293. SYNC_601
  294. isync
  295. lis r9,mmu_hash_lock@h
  296. ori r9,r9,mmu_hash_lock@l
  297. tophys(r9,r9)
  298. 10: lwarx r7,0,r9
  299. cmpwi 0,r7,0
  300. bne- 10b
  301. stwcx. r8,0,r9
  302. bne- 10b
  303. sync
  304. tlbia
  305. sync
  306. TLBSYNC
  307. li r0,0
  308. stw r0,0(r9) /* clear mmu_hash_lock */
  309. mtmsr r10
  310. SYNC_601
  311. isync
  312. #else /* CONFIG_SMP */
  313. sync
  314. tlbia
  315. sync
  316. #endif /* CONFIG_SMP */
  317. #endif /* ! defined(CONFIG_40x) */
  318. blr
  319. /*
  320. * Flush MMU TLB for a particular address
  321. */
  322. #ifndef CONFIG_FSL_BOOKE
  323. _GLOBAL(_tlbil_va)
  324. #endif
  325. _GLOBAL(_tlbie)
  326. #if defined(CONFIG_40x)
  327. /* We run the search with interrupts disabled because we have to change
  328. * the PID and I don't want to preempt when that happens.
  329. */
  330. mfmsr r5
  331. mfspr r6,SPRN_PID
  332. wrteei 0
  333. mtspr SPRN_PID,r4
  334. tlbsx. r3, 0, r3
  335. mtspr SPRN_PID,r6
  336. wrtee r5
  337. bne 10f
  338. sync
  339. /* There are only 64 TLB entries, so r3 < 64, which means bit 25 is clear.
  340. * Since 25 is the V bit in the TLB_TAG, loading this value will invalidate
  341. * the TLB entry. */
  342. tlbwe r3, r3, TLB_TAG
  343. isync
  344. 10:
  345. #elif defined(CONFIG_44x)
  346. mfspr r5,SPRN_MMUCR
  347. rlwimi r5,r4,0,24,31 /* Set TID */
  348. /* We have to run the search with interrupts disabled, even critical
  349. * and debug interrupts (in fact the only critical exceptions we have
  350. * are debug and machine check). Otherwise an interrupt which causes
  351. * a TLB miss can clobber the MMUCR between the mtspr and the tlbsx. */
  352. mfmsr r4
  353. lis r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@ha
  354. addi r6,r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@l
  355. andc r6,r4,r6
  356. mtmsr r6
  357. mtspr SPRN_MMUCR,r5
  358. tlbsx. r3, 0, r3
  359. mtmsr r4
  360. bne 10f
  361. sync
  362. /* There are only 64 TLB entries, so r3 < 64,
  363. * which means bit 22, is clear. Since 22 is
  364. * the V bit in the TLB_PAGEID, loading this
  365. * value will invalidate the TLB entry.
  366. */
  367. tlbwe r3, r3, PPC44x_TLB_PAGEID
  368. isync
  369. 10:
  370. #elif defined(CONFIG_FSL_BOOKE)
  371. rlwinm r4, r3, 0, 0, 19
  372. ori r5, r4, 0x08 /* TLBSEL = 1 */
  373. tlbivax 0, r4
  374. tlbivax 0, r5
  375. msync
  376. #if defined(CONFIG_SMP)
  377. tlbsync
  378. #endif /* CONFIG_SMP */
  379. #else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */
  380. #if defined(CONFIG_SMP)
  381. rlwinm r8,r1,0,0,(31-THREAD_SHIFT)
  382. lwz r8,TI_CPU(r8)
  383. oris r8,r8,11
  384. mfmsr r10
  385. SYNC
  386. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  387. rlwinm r0,r0,0,28,26 /* clear DR */
  388. mtmsr r0
  389. SYNC_601
  390. isync
  391. lis r9,mmu_hash_lock@h
  392. ori r9,r9,mmu_hash_lock@l
  393. tophys(r9,r9)
  394. 10: lwarx r7,0,r9
  395. cmpwi 0,r7,0
  396. bne- 10b
  397. stwcx. r8,0,r9
  398. bne- 10b
  399. eieio
  400. tlbie r3
  401. sync
  402. TLBSYNC
  403. li r0,0
  404. stw r0,0(r9) /* clear mmu_hash_lock */
  405. mtmsr r10
  406. SYNC_601
  407. isync
  408. #else /* CONFIG_SMP */
  409. tlbie r3
  410. sync
  411. #endif /* CONFIG_SMP */
  412. #endif /* ! CONFIG_40x */
  413. blr
  414. #if defined(CONFIG_FSL_BOOKE)
  415. /*
  416. * Flush MMU TLB, but only on the local processor (no broadcast)
  417. */
  418. _GLOBAL(_tlbil_all)
  419. #define MMUCSR0_TLBFI (MMUCSR0_TLB0FI | MMUCSR0_TLB1FI | \
  420. MMUCSR0_TLB2FI | MMUCSR0_TLB3FI)
  421. li r3,(MMUCSR0_TLBFI)@l
  422. mtspr SPRN_MMUCSR0, r3
  423. 1:
  424. mfspr r3,SPRN_MMUCSR0
  425. andi. r3,r3,MMUCSR0_TLBFI@l
  426. bne 1b
  427. blr
  428. /*
  429. * Flush MMU TLB for a particular process id, but only on the local processor
  430. * (no broadcast)
  431. */
  432. _GLOBAL(_tlbil_pid)
  433. /* we currently do an invalidate all since we don't have per pid invalidate */
  434. li r3,(MMUCSR0_TLBFI)@l
  435. mtspr SPRN_MMUCSR0, r3
  436. 1:
  437. mfspr r3,SPRN_MMUCSR0
  438. andi. r3,r3,MMUCSR0_TLBFI@l
  439. bne 1b
  440. blr
  441. /*
  442. * Flush MMU TLB for a particular address, but only on the local processor
  443. * (no broadcast)
  444. */
  445. _GLOBAL(_tlbil_va)
  446. slwi r4,r4,16
  447. mtspr SPRN_MAS6,r4 /* assume AS=0 for now */
  448. tlbsx 0,r3
  449. mfspr r4,SPRN_MAS1 /* check valid */
  450. andis. r3,r4,MAS1_VALID@h
  451. beqlr
  452. rlwinm r4,r4,0,1,31
  453. mtspr SPRN_MAS1,r4
  454. tlbwe
  455. blr
  456. #endif /* CONFIG_FSL_BOOKE */
  457. /*
  458. * Flush instruction cache.
  459. * This is a no-op on the 601.
  460. */
  461. _GLOBAL(flush_instruction_cache)
  462. #if defined(CONFIG_8xx)
  463. isync
  464. lis r5, IDC_INVALL@h
  465. mtspr SPRN_IC_CST, r5
  466. #elif defined(CONFIG_4xx)
  467. #ifdef CONFIG_403GCX
  468. li r3, 512
  469. mtctr r3
  470. lis r4, KERNELBASE@h
  471. 1: iccci 0, r4
  472. addi r4, r4, 16
  473. bdnz 1b
  474. #else
  475. lis r3, KERNELBASE@h
  476. iccci 0,r3
  477. #endif
  478. #elif CONFIG_FSL_BOOKE
  479. BEGIN_FTR_SECTION
  480. mfspr r3,SPRN_L1CSR0
  481. ori r3,r3,L1CSR0_CFI|L1CSR0_CLFC
  482. /* msync; isync recommended here */
  483. mtspr SPRN_L1CSR0,r3
  484. isync
  485. blr
  486. END_FTR_SECTION_IFSET(CPU_FTR_UNIFIED_ID_CACHE)
  487. mfspr r3,SPRN_L1CSR1
  488. ori r3,r3,L1CSR1_ICFI|L1CSR1_ICLFR
  489. mtspr SPRN_L1CSR1,r3
  490. #else
  491. mfspr r3,SPRN_PVR
  492. rlwinm r3,r3,16,16,31
  493. cmpwi 0,r3,1
  494. beqlr /* for 601, do nothing */
  495. /* 603/604 processor - use invalidate-all bit in HID0 */
  496. mfspr r3,SPRN_HID0
  497. ori r3,r3,HID0_ICFI
  498. mtspr SPRN_HID0,r3
  499. #endif /* CONFIG_8xx/4xx */
  500. isync
  501. blr
  502. /*
  503. * Write any modified data cache blocks out to memory
  504. * and invalidate the corresponding instruction cache blocks.
  505. * This is a no-op on the 601.
  506. *
  507. * flush_icache_range(unsigned long start, unsigned long stop)
  508. */
  509. _KPROBE(__flush_icache_range)
  510. BEGIN_FTR_SECTION
  511. blr /* for 601, do nothing */
  512. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  513. li r5,L1_CACHE_BYTES-1
  514. andc r3,r3,r5
  515. subf r4,r3,r4
  516. add r4,r4,r5
  517. srwi. r4,r4,L1_CACHE_SHIFT
  518. beqlr
  519. mtctr r4
  520. mr r6,r3
  521. 1: dcbst 0,r3
  522. addi r3,r3,L1_CACHE_BYTES
  523. bdnz 1b
  524. sync /* wait for dcbst's to get to ram */
  525. mtctr r4
  526. 2: icbi 0,r6
  527. addi r6,r6,L1_CACHE_BYTES
  528. bdnz 2b
  529. sync /* additional sync needed on g4 */
  530. isync
  531. blr
  532. /*
  533. * Write any modified data cache blocks out to memory.
  534. * Does not invalidate the corresponding cache lines (especially for
  535. * any corresponding instruction cache).
  536. *
  537. * clean_dcache_range(unsigned long start, unsigned long stop)
  538. */
  539. _GLOBAL(clean_dcache_range)
  540. li r5,L1_CACHE_BYTES-1
  541. andc r3,r3,r5
  542. subf r4,r3,r4
  543. add r4,r4,r5
  544. srwi. r4,r4,L1_CACHE_SHIFT
  545. beqlr
  546. mtctr r4
  547. 1: dcbst 0,r3
  548. addi r3,r3,L1_CACHE_BYTES
  549. bdnz 1b
  550. sync /* wait for dcbst's to get to ram */
  551. blr
  552. /*
  553. * Write any modified data cache blocks out to memory and invalidate them.
  554. * Does not invalidate the corresponding instruction cache blocks.
  555. *
  556. * flush_dcache_range(unsigned long start, unsigned long stop)
  557. */
  558. _GLOBAL(flush_dcache_range)
  559. li r5,L1_CACHE_BYTES-1
  560. andc r3,r3,r5
  561. subf r4,r3,r4
  562. add r4,r4,r5
  563. srwi. r4,r4,L1_CACHE_SHIFT
  564. beqlr
  565. mtctr r4
  566. 1: dcbf 0,r3
  567. addi r3,r3,L1_CACHE_BYTES
  568. bdnz 1b
  569. sync /* wait for dcbst's to get to ram */
  570. blr
  571. /*
  572. * Like above, but invalidate the D-cache. This is used by the 8xx
  573. * to invalidate the cache so the PPC core doesn't get stale data
  574. * from the CPM (no cache snooping here :-).
  575. *
  576. * invalidate_dcache_range(unsigned long start, unsigned long stop)
  577. */
  578. _GLOBAL(invalidate_dcache_range)
  579. li r5,L1_CACHE_BYTES-1
  580. andc r3,r3,r5
  581. subf r4,r3,r4
  582. add r4,r4,r5
  583. srwi. r4,r4,L1_CACHE_SHIFT
  584. beqlr
  585. mtctr r4
  586. 1: dcbi 0,r3
  587. addi r3,r3,L1_CACHE_BYTES
  588. bdnz 1b
  589. sync /* wait for dcbi's to get to ram */
  590. blr
  591. /*
  592. * Flush a particular page from the data cache to RAM.
  593. * Note: this is necessary because the instruction cache does *not*
  594. * snoop from the data cache.
  595. * This is a no-op on the 601 which has a unified cache.
  596. *
  597. * void __flush_dcache_icache(void *page)
  598. */
  599. _GLOBAL(__flush_dcache_icache)
  600. BEGIN_FTR_SECTION
  601. blr
  602. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  603. rlwinm r3,r3,0,0,19 /* Get page base address */
  604. li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
  605. mtctr r4
  606. mr r6,r3
  607. 0: dcbst 0,r3 /* Write line to ram */
  608. addi r3,r3,L1_CACHE_BYTES
  609. bdnz 0b
  610. sync
  611. #ifndef CONFIG_44x
  612. /* We don't flush the icache on 44x. Those have a virtual icache
  613. * and we don't have access to the virtual address here (it's
  614. * not the page vaddr but where it's mapped in user space). The
  615. * flushing of the icache on these is handled elsewhere, when
  616. * a change in the address space occurs, before returning to
  617. * user space
  618. */
  619. mtctr r4
  620. 1: icbi 0,r6
  621. addi r6,r6,L1_CACHE_BYTES
  622. bdnz 1b
  623. sync
  624. isync
  625. #endif /* CONFIG_44x */
  626. blr
  627. /*
  628. * Flush a particular page from the data cache to RAM, identified
  629. * by its physical address. We turn off the MMU so we can just use
  630. * the physical address (this may be a highmem page without a kernel
  631. * mapping).
  632. *
  633. * void __flush_dcache_icache_phys(unsigned long physaddr)
  634. */
  635. _GLOBAL(__flush_dcache_icache_phys)
  636. BEGIN_FTR_SECTION
  637. blr /* for 601, do nothing */
  638. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  639. mfmsr r10
  640. rlwinm r0,r10,0,28,26 /* clear DR */
  641. mtmsr r0
  642. isync
  643. rlwinm r3,r3,0,0,19 /* Get page base address */
  644. li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
  645. mtctr r4
  646. mr r6,r3
  647. 0: dcbst 0,r3 /* Write line to ram */
  648. addi r3,r3,L1_CACHE_BYTES
  649. bdnz 0b
  650. sync
  651. mtctr r4
  652. 1: icbi 0,r6
  653. addi r6,r6,L1_CACHE_BYTES
  654. bdnz 1b
  655. sync
  656. mtmsr r10 /* restore DR */
  657. isync
  658. blr
  659. /*
  660. * Clear pages using the dcbz instruction, which doesn't cause any
  661. * memory traffic (except to write out any cache lines which get
  662. * displaced). This only works on cacheable memory.
  663. *
  664. * void clear_pages(void *page, int order) ;
  665. */
  666. _GLOBAL(clear_pages)
  667. li r0,4096/L1_CACHE_BYTES
  668. slw r0,r0,r4
  669. mtctr r0
  670. #ifdef CONFIG_8xx
  671. li r4, 0
  672. 1: stw r4, 0(r3)
  673. stw r4, 4(r3)
  674. stw r4, 8(r3)
  675. stw r4, 12(r3)
  676. #else
  677. 1: dcbz 0,r3
  678. #endif
  679. addi r3,r3,L1_CACHE_BYTES
  680. bdnz 1b
  681. blr
  682. /*
  683. * Copy a whole page. We use the dcbz instruction on the destination
  684. * to reduce memory traffic (it eliminates the unnecessary reads of
  685. * the destination into cache). This requires that the destination
  686. * is cacheable.
  687. */
  688. #define COPY_16_BYTES \
  689. lwz r6,4(r4); \
  690. lwz r7,8(r4); \
  691. lwz r8,12(r4); \
  692. lwzu r9,16(r4); \
  693. stw r6,4(r3); \
  694. stw r7,8(r3); \
  695. stw r8,12(r3); \
  696. stwu r9,16(r3)
  697. _GLOBAL(copy_page)
  698. addi r3,r3,-4
  699. addi r4,r4,-4
  700. #ifdef CONFIG_8xx
  701. /* don't use prefetch on 8xx */
  702. li r0,4096/L1_CACHE_BYTES
  703. mtctr r0
  704. 1: COPY_16_BYTES
  705. bdnz 1b
  706. blr
  707. #else /* not 8xx, we can prefetch */
  708. li r5,4
  709. #if MAX_COPY_PREFETCH > 1
  710. li r0,MAX_COPY_PREFETCH
  711. li r11,4
  712. mtctr r0
  713. 11: dcbt r11,r4
  714. addi r11,r11,L1_CACHE_BYTES
  715. bdnz 11b
  716. #else /* MAX_COPY_PREFETCH == 1 */
  717. dcbt r5,r4
  718. li r11,L1_CACHE_BYTES+4
  719. #endif /* MAX_COPY_PREFETCH */
  720. li r0,4096/L1_CACHE_BYTES - MAX_COPY_PREFETCH
  721. crclr 4*cr0+eq
  722. 2:
  723. mtctr r0
  724. 1:
  725. dcbt r11,r4
  726. dcbz r5,r3
  727. COPY_16_BYTES
  728. #if L1_CACHE_BYTES >= 32
  729. COPY_16_BYTES
  730. #if L1_CACHE_BYTES >= 64
  731. COPY_16_BYTES
  732. COPY_16_BYTES
  733. #if L1_CACHE_BYTES >= 128
  734. COPY_16_BYTES
  735. COPY_16_BYTES
  736. COPY_16_BYTES
  737. COPY_16_BYTES
  738. #endif
  739. #endif
  740. #endif
  741. bdnz 1b
  742. beqlr
  743. crnot 4*cr0+eq,4*cr0+eq
  744. li r0,MAX_COPY_PREFETCH
  745. li r11,4
  746. b 2b
  747. #endif /* CONFIG_8xx */
  748. /*
  749. * void atomic_clear_mask(atomic_t mask, atomic_t *addr)
  750. * void atomic_set_mask(atomic_t mask, atomic_t *addr);
  751. */
  752. _GLOBAL(atomic_clear_mask)
  753. 10: lwarx r5,0,r4
  754. andc r5,r5,r3
  755. PPC405_ERR77(0,r4)
  756. stwcx. r5,0,r4
  757. bne- 10b
  758. blr
  759. _GLOBAL(atomic_set_mask)
  760. 10: lwarx r5,0,r4
  761. or r5,r5,r3
  762. PPC405_ERR77(0,r4)
  763. stwcx. r5,0,r4
  764. bne- 10b
  765. blr
  766. /*
  767. * Extended precision shifts.
  768. *
  769. * Updated to be valid for shift counts from 0 to 63 inclusive.
  770. * -- Gabriel
  771. *
  772. * R3/R4 has 64 bit value
  773. * R5 has shift count
  774. * result in R3/R4
  775. *
  776. * ashrdi3: arithmetic right shift (sign propagation)
  777. * lshrdi3: logical right shift
  778. * ashldi3: left shift
  779. */
  780. _GLOBAL(__ashrdi3)
  781. subfic r6,r5,32
  782. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  783. addi r7,r5,32 # could be xori, or addi with -32
  784. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  785. rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0
  786. sraw r7,r3,r7 # t2 = MSW >> (count-32)
  787. or r4,r4,r6 # LSW |= t1
  788. slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2
  789. sraw r3,r3,r5 # MSW = MSW >> count
  790. or r4,r4,r7 # LSW |= t2
  791. blr
  792. _GLOBAL(__ashldi3)
  793. subfic r6,r5,32
  794. slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count
  795. addi r7,r5,32 # could be xori, or addi with -32
  796. srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count)
  797. slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32)
  798. or r3,r3,r6 # MSW |= t1
  799. slw r4,r4,r5 # LSW = LSW << count
  800. or r3,r3,r7 # MSW |= t2
  801. blr
  802. _GLOBAL(__lshrdi3)
  803. subfic r6,r5,32
  804. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  805. addi r7,r5,32 # could be xori, or addi with -32
  806. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  807. srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32)
  808. or r4,r4,r6 # LSW |= t1
  809. srw r3,r3,r5 # MSW = MSW >> count
  810. or r4,r4,r7 # LSW |= t2
  811. blr
  812. /*
  813. * 64-bit comparison: __ucmpdi2(u64 a, u64 b)
  814. * Returns 0 if a < b, 1 if a == b, 2 if a > b.
  815. */
  816. _GLOBAL(__ucmpdi2)
  817. cmplw r3,r5
  818. li r3,1
  819. bne 1f
  820. cmplw r4,r6
  821. beqlr
  822. 1: li r3,0
  823. bltlr
  824. li r3,2
  825. blr
  826. _GLOBAL(abs)
  827. srawi r4,r3,31
  828. xor r3,r3,r4
  829. sub r3,r3,r4
  830. blr
  831. /*
  832. * Create a kernel thread
  833. * kernel_thread(fn, arg, flags)
  834. */
  835. _GLOBAL(kernel_thread)
  836. stwu r1,-16(r1)
  837. stw r30,8(r1)
  838. stw r31,12(r1)
  839. mr r30,r3 /* function */
  840. mr r31,r4 /* argument */
  841. ori r3,r5,CLONE_VM /* flags */
  842. oris r3,r3,CLONE_UNTRACED>>16
  843. li r4,0 /* new sp (unused) */
  844. li r0,__NR_clone
  845. sc
  846. cmpwi 0,r3,0 /* parent or child? */
  847. bne 1f /* return if parent */
  848. li r0,0 /* make top-level stack frame */
  849. stwu r0,-16(r1)
  850. mtlr r30 /* fn addr in lr */
  851. mr r3,r31 /* load arg and call fn */
  852. PPC440EP_ERR42
  853. blrl
  854. li r0,__NR_exit /* exit if function returns */
  855. li r3,0
  856. sc
  857. 1: lwz r30,8(r1)
  858. lwz r31,12(r1)
  859. addi r1,r1,16
  860. blr
  861. /*
  862. * This routine is just here to keep GCC happy - sigh...
  863. */
  864. _GLOBAL(__main)
  865. blr
  866. #ifdef CONFIG_KEXEC
  867. /*
  868. * Must be relocatable PIC code callable as a C function.
  869. */
  870. .globl relocate_new_kernel
  871. relocate_new_kernel:
  872. /* r3 = page_list */
  873. /* r4 = reboot_code_buffer */
  874. /* r5 = start_address */
  875. li r0, 0
  876. /*
  877. * Set Machine Status Register to a known status,
  878. * switch the MMU off and jump to 1: in a single step.
  879. */
  880. mr r8, r0
  881. ori r8, r8, MSR_RI|MSR_ME
  882. mtspr SPRN_SRR1, r8
  883. addi r8, r4, 1f - relocate_new_kernel
  884. mtspr SPRN_SRR0, r8
  885. sync
  886. rfi
  887. 1:
  888. /* from this point address translation is turned off */
  889. /* and interrupts are disabled */
  890. /* set a new stack at the bottom of our page... */
  891. /* (not really needed now) */
  892. addi r1, r4, KEXEC_CONTROL_PAGE_SIZE - 8 /* for LR Save+Back Chain */
  893. stw r0, 0(r1)
  894. /* Do the copies */
  895. li r6, 0 /* checksum */
  896. mr r0, r3
  897. b 1f
  898. 0: /* top, read another word for the indirection page */
  899. lwzu r0, 4(r3)
  900. 1:
  901. /* is it a destination page? (r8) */
  902. rlwinm. r7, r0, 0, 31, 31 /* IND_DESTINATION (1<<0) */
  903. beq 2f
  904. rlwinm r8, r0, 0, 0, 19 /* clear kexec flags, page align */
  905. b 0b
  906. 2: /* is it an indirection page? (r3) */
  907. rlwinm. r7, r0, 0, 30, 30 /* IND_INDIRECTION (1<<1) */
  908. beq 2f
  909. rlwinm r3, r0, 0, 0, 19 /* clear kexec flags, page align */
  910. subi r3, r3, 4
  911. b 0b
  912. 2: /* are we done? */
  913. rlwinm. r7, r0, 0, 29, 29 /* IND_DONE (1<<2) */
  914. beq 2f
  915. b 3f
  916. 2: /* is it a source page? (r9) */
  917. rlwinm. r7, r0, 0, 28, 28 /* IND_SOURCE (1<<3) */
  918. beq 0b
  919. rlwinm r9, r0, 0, 0, 19 /* clear kexec flags, page align */
  920. li r7, PAGE_SIZE / 4
  921. mtctr r7
  922. subi r9, r9, 4
  923. subi r8, r8, 4
  924. 9:
  925. lwzu r0, 4(r9) /* do the copy */
  926. xor r6, r6, r0
  927. stwu r0, 4(r8)
  928. dcbst 0, r8
  929. sync
  930. icbi 0, r8
  931. bdnz 9b
  932. addi r9, r9, 4
  933. addi r8, r8, 4
  934. b 0b
  935. 3:
  936. /* To be certain of avoiding problems with self-modifying code
  937. * execute a serializing instruction here.
  938. */
  939. isync
  940. sync
  941. /* jump to the entry point, usually the setup routine */
  942. mtlr r5
  943. blrl
  944. 1: b 1b
  945. relocate_new_kernel_end:
  946. .globl relocate_new_kernel_size
  947. relocate_new_kernel_size:
  948. .long relocate_new_kernel_end - relocate_new_kernel
  949. #endif