misc_32.S 21 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  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. msync
  441. isync
  442. blr
  443. /*
  444. * Flush MMU TLB for a particular address, but only on the local processor
  445. * (no broadcast)
  446. */
  447. _GLOBAL(_tlbil_va)
  448. slwi r4,r4,16
  449. mtspr SPRN_MAS6,r4 /* assume AS=0 for now */
  450. tlbsx 0,r3
  451. mfspr r4,SPRN_MAS1 /* check valid */
  452. andis. r3,r4,MAS1_VALID@h
  453. beqlr
  454. rlwinm r4,r4,0,1,31
  455. mtspr SPRN_MAS1,r4
  456. tlbwe
  457. msync
  458. isync
  459. blr
  460. #endif /* CONFIG_FSL_BOOKE */
  461. /*
  462. * Flush instruction cache.
  463. * This is a no-op on the 601.
  464. */
  465. _GLOBAL(flush_instruction_cache)
  466. #if defined(CONFIG_8xx)
  467. isync
  468. lis r5, IDC_INVALL@h
  469. mtspr SPRN_IC_CST, r5
  470. #elif defined(CONFIG_4xx)
  471. #ifdef CONFIG_403GCX
  472. li r3, 512
  473. mtctr r3
  474. lis r4, KERNELBASE@h
  475. 1: iccci 0, r4
  476. addi r4, r4, 16
  477. bdnz 1b
  478. #else
  479. lis r3, KERNELBASE@h
  480. iccci 0,r3
  481. #endif
  482. #elif CONFIG_FSL_BOOKE
  483. BEGIN_FTR_SECTION
  484. mfspr r3,SPRN_L1CSR0
  485. ori r3,r3,L1CSR0_CFI|L1CSR0_CLFC
  486. /* msync; isync recommended here */
  487. mtspr SPRN_L1CSR0,r3
  488. isync
  489. blr
  490. END_FTR_SECTION_IFSET(CPU_FTR_UNIFIED_ID_CACHE)
  491. mfspr r3,SPRN_L1CSR1
  492. ori r3,r3,L1CSR1_ICFI|L1CSR1_ICLFR
  493. mtspr SPRN_L1CSR1,r3
  494. #else
  495. mfspr r3,SPRN_PVR
  496. rlwinm r3,r3,16,16,31
  497. cmpwi 0,r3,1
  498. beqlr /* for 601, do nothing */
  499. /* 603/604 processor - use invalidate-all bit in HID0 */
  500. mfspr r3,SPRN_HID0
  501. ori r3,r3,HID0_ICFI
  502. mtspr SPRN_HID0,r3
  503. #endif /* CONFIG_8xx/4xx */
  504. isync
  505. blr
  506. /*
  507. * Write any modified data cache blocks out to memory
  508. * and invalidate the corresponding instruction cache blocks.
  509. * This is a no-op on the 601.
  510. *
  511. * flush_icache_range(unsigned long start, unsigned long stop)
  512. */
  513. _KPROBE(__flush_icache_range)
  514. BEGIN_FTR_SECTION
  515. blr /* for 601, do nothing */
  516. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  517. li r5,L1_CACHE_BYTES-1
  518. andc r3,r3,r5
  519. subf r4,r3,r4
  520. add r4,r4,r5
  521. srwi. r4,r4,L1_CACHE_SHIFT
  522. beqlr
  523. mtctr r4
  524. mr r6,r3
  525. 1: dcbst 0,r3
  526. addi r3,r3,L1_CACHE_BYTES
  527. bdnz 1b
  528. sync /* wait for dcbst's to get to ram */
  529. mtctr r4
  530. 2: icbi 0,r6
  531. addi r6,r6,L1_CACHE_BYTES
  532. bdnz 2b
  533. sync /* additional sync needed on g4 */
  534. isync
  535. blr
  536. /*
  537. * Write any modified data cache blocks out to memory.
  538. * Does not invalidate the corresponding cache lines (especially for
  539. * any corresponding instruction cache).
  540. *
  541. * clean_dcache_range(unsigned long start, unsigned long stop)
  542. */
  543. _GLOBAL(clean_dcache_range)
  544. li r5,L1_CACHE_BYTES-1
  545. andc r3,r3,r5
  546. subf r4,r3,r4
  547. add r4,r4,r5
  548. srwi. r4,r4,L1_CACHE_SHIFT
  549. beqlr
  550. mtctr r4
  551. 1: dcbst 0,r3
  552. addi r3,r3,L1_CACHE_BYTES
  553. bdnz 1b
  554. sync /* wait for dcbst's to get to ram */
  555. blr
  556. /*
  557. * Write any modified data cache blocks out to memory and invalidate them.
  558. * Does not invalidate the corresponding instruction cache blocks.
  559. *
  560. * flush_dcache_range(unsigned long start, unsigned long stop)
  561. */
  562. _GLOBAL(flush_dcache_range)
  563. li r5,L1_CACHE_BYTES-1
  564. andc r3,r3,r5
  565. subf r4,r3,r4
  566. add r4,r4,r5
  567. srwi. r4,r4,L1_CACHE_SHIFT
  568. beqlr
  569. mtctr r4
  570. 1: dcbf 0,r3
  571. addi r3,r3,L1_CACHE_BYTES
  572. bdnz 1b
  573. sync /* wait for dcbst's to get to ram */
  574. blr
  575. /*
  576. * Like above, but invalidate the D-cache. This is used by the 8xx
  577. * to invalidate the cache so the PPC core doesn't get stale data
  578. * from the CPM (no cache snooping here :-).
  579. *
  580. * invalidate_dcache_range(unsigned long start, unsigned long stop)
  581. */
  582. _GLOBAL(invalidate_dcache_range)
  583. li r5,L1_CACHE_BYTES-1
  584. andc r3,r3,r5
  585. subf r4,r3,r4
  586. add r4,r4,r5
  587. srwi. r4,r4,L1_CACHE_SHIFT
  588. beqlr
  589. mtctr r4
  590. 1: dcbi 0,r3
  591. addi r3,r3,L1_CACHE_BYTES
  592. bdnz 1b
  593. sync /* wait for dcbi's to get to ram */
  594. blr
  595. /*
  596. * Flush a particular page from the data cache to RAM.
  597. * Note: this is necessary because the instruction cache does *not*
  598. * snoop from the data cache.
  599. * This is a no-op on the 601 which has a unified cache.
  600. *
  601. * void __flush_dcache_icache(void *page)
  602. */
  603. _GLOBAL(__flush_dcache_icache)
  604. BEGIN_FTR_SECTION
  605. blr
  606. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  607. rlwinm r3,r3,0,0,19 /* Get page base address */
  608. li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
  609. mtctr r4
  610. mr r6,r3
  611. 0: dcbst 0,r3 /* Write line to ram */
  612. addi r3,r3,L1_CACHE_BYTES
  613. bdnz 0b
  614. sync
  615. #ifndef CONFIG_44x
  616. /* We don't flush the icache on 44x. Those have a virtual icache
  617. * and we don't have access to the virtual address here (it's
  618. * not the page vaddr but where it's mapped in user space). The
  619. * flushing of the icache on these is handled elsewhere, when
  620. * a change in the address space occurs, before returning to
  621. * user space
  622. */
  623. mtctr r4
  624. 1: icbi 0,r6
  625. addi r6,r6,L1_CACHE_BYTES
  626. bdnz 1b
  627. sync
  628. isync
  629. #endif /* CONFIG_44x */
  630. blr
  631. /*
  632. * Flush a particular page from the data cache to RAM, identified
  633. * by its physical address. We turn off the MMU so we can just use
  634. * the physical address (this may be a highmem page without a kernel
  635. * mapping).
  636. *
  637. * void __flush_dcache_icache_phys(unsigned long physaddr)
  638. */
  639. _GLOBAL(__flush_dcache_icache_phys)
  640. BEGIN_FTR_SECTION
  641. blr /* for 601, do nothing */
  642. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  643. mfmsr r10
  644. rlwinm r0,r10,0,28,26 /* clear DR */
  645. mtmsr r0
  646. isync
  647. rlwinm r3,r3,0,0,19 /* Get page base address */
  648. li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
  649. mtctr r4
  650. mr r6,r3
  651. 0: dcbst 0,r3 /* Write line to ram */
  652. addi r3,r3,L1_CACHE_BYTES
  653. bdnz 0b
  654. sync
  655. mtctr r4
  656. 1: icbi 0,r6
  657. addi r6,r6,L1_CACHE_BYTES
  658. bdnz 1b
  659. sync
  660. mtmsr r10 /* restore DR */
  661. isync
  662. blr
  663. /*
  664. * Clear pages using the dcbz instruction, which doesn't cause any
  665. * memory traffic (except to write out any cache lines which get
  666. * displaced). This only works on cacheable memory.
  667. *
  668. * void clear_pages(void *page, int order) ;
  669. */
  670. _GLOBAL(clear_pages)
  671. li r0,4096/L1_CACHE_BYTES
  672. slw r0,r0,r4
  673. mtctr r0
  674. #ifdef CONFIG_8xx
  675. li r4, 0
  676. 1: stw r4, 0(r3)
  677. stw r4, 4(r3)
  678. stw r4, 8(r3)
  679. stw r4, 12(r3)
  680. #else
  681. 1: dcbz 0,r3
  682. #endif
  683. addi r3,r3,L1_CACHE_BYTES
  684. bdnz 1b
  685. blr
  686. /*
  687. * Copy a whole page. We use the dcbz instruction on the destination
  688. * to reduce memory traffic (it eliminates the unnecessary reads of
  689. * the destination into cache). This requires that the destination
  690. * is cacheable.
  691. */
  692. #define COPY_16_BYTES \
  693. lwz r6,4(r4); \
  694. lwz r7,8(r4); \
  695. lwz r8,12(r4); \
  696. lwzu r9,16(r4); \
  697. stw r6,4(r3); \
  698. stw r7,8(r3); \
  699. stw r8,12(r3); \
  700. stwu r9,16(r3)
  701. _GLOBAL(copy_page)
  702. addi r3,r3,-4
  703. addi r4,r4,-4
  704. #ifdef CONFIG_8xx
  705. /* don't use prefetch on 8xx */
  706. li r0,4096/L1_CACHE_BYTES
  707. mtctr r0
  708. 1: COPY_16_BYTES
  709. bdnz 1b
  710. blr
  711. #else /* not 8xx, we can prefetch */
  712. li r5,4
  713. #if MAX_COPY_PREFETCH > 1
  714. li r0,MAX_COPY_PREFETCH
  715. li r11,4
  716. mtctr r0
  717. 11: dcbt r11,r4
  718. addi r11,r11,L1_CACHE_BYTES
  719. bdnz 11b
  720. #else /* MAX_COPY_PREFETCH == 1 */
  721. dcbt r5,r4
  722. li r11,L1_CACHE_BYTES+4
  723. #endif /* MAX_COPY_PREFETCH */
  724. li r0,4096/L1_CACHE_BYTES - MAX_COPY_PREFETCH
  725. crclr 4*cr0+eq
  726. 2:
  727. mtctr r0
  728. 1:
  729. dcbt r11,r4
  730. dcbz r5,r3
  731. COPY_16_BYTES
  732. #if L1_CACHE_BYTES >= 32
  733. COPY_16_BYTES
  734. #if L1_CACHE_BYTES >= 64
  735. COPY_16_BYTES
  736. COPY_16_BYTES
  737. #if L1_CACHE_BYTES >= 128
  738. COPY_16_BYTES
  739. COPY_16_BYTES
  740. COPY_16_BYTES
  741. COPY_16_BYTES
  742. #endif
  743. #endif
  744. #endif
  745. bdnz 1b
  746. beqlr
  747. crnot 4*cr0+eq,4*cr0+eq
  748. li r0,MAX_COPY_PREFETCH
  749. li r11,4
  750. b 2b
  751. #endif /* CONFIG_8xx */
  752. /*
  753. * void atomic_clear_mask(atomic_t mask, atomic_t *addr)
  754. * void atomic_set_mask(atomic_t mask, atomic_t *addr);
  755. */
  756. _GLOBAL(atomic_clear_mask)
  757. 10: lwarx r5,0,r4
  758. andc r5,r5,r3
  759. PPC405_ERR77(0,r4)
  760. stwcx. r5,0,r4
  761. bne- 10b
  762. blr
  763. _GLOBAL(atomic_set_mask)
  764. 10: lwarx r5,0,r4
  765. or r5,r5,r3
  766. PPC405_ERR77(0,r4)
  767. stwcx. r5,0,r4
  768. bne- 10b
  769. blr
  770. /*
  771. * Extended precision shifts.
  772. *
  773. * Updated to be valid for shift counts from 0 to 63 inclusive.
  774. * -- Gabriel
  775. *
  776. * R3/R4 has 64 bit value
  777. * R5 has shift count
  778. * result in R3/R4
  779. *
  780. * ashrdi3: arithmetic right shift (sign propagation)
  781. * lshrdi3: logical right shift
  782. * ashldi3: left shift
  783. */
  784. _GLOBAL(__ashrdi3)
  785. subfic r6,r5,32
  786. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  787. addi r7,r5,32 # could be xori, or addi with -32
  788. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  789. rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0
  790. sraw r7,r3,r7 # t2 = MSW >> (count-32)
  791. or r4,r4,r6 # LSW |= t1
  792. slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2
  793. sraw r3,r3,r5 # MSW = MSW >> count
  794. or r4,r4,r7 # LSW |= t2
  795. blr
  796. _GLOBAL(__ashldi3)
  797. subfic r6,r5,32
  798. slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count
  799. addi r7,r5,32 # could be xori, or addi with -32
  800. srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count)
  801. slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32)
  802. or r3,r3,r6 # MSW |= t1
  803. slw r4,r4,r5 # LSW = LSW << count
  804. or r3,r3,r7 # MSW |= t2
  805. blr
  806. _GLOBAL(__lshrdi3)
  807. subfic r6,r5,32
  808. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  809. addi r7,r5,32 # could be xori, or addi with -32
  810. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  811. srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32)
  812. or r4,r4,r6 # LSW |= t1
  813. srw r3,r3,r5 # MSW = MSW >> count
  814. or r4,r4,r7 # LSW |= t2
  815. blr
  816. /*
  817. * 64-bit comparison: __ucmpdi2(u64 a, u64 b)
  818. * Returns 0 if a < b, 1 if a == b, 2 if a > b.
  819. */
  820. _GLOBAL(__ucmpdi2)
  821. cmplw r3,r5
  822. li r3,1
  823. bne 1f
  824. cmplw r4,r6
  825. beqlr
  826. 1: li r3,0
  827. bltlr
  828. li r3,2
  829. blr
  830. _GLOBAL(abs)
  831. srawi r4,r3,31
  832. xor r3,r3,r4
  833. sub r3,r3,r4
  834. blr
  835. /*
  836. * Create a kernel thread
  837. * kernel_thread(fn, arg, flags)
  838. */
  839. _GLOBAL(kernel_thread)
  840. stwu r1,-16(r1)
  841. stw r30,8(r1)
  842. stw r31,12(r1)
  843. mr r30,r3 /* function */
  844. mr r31,r4 /* argument */
  845. ori r3,r5,CLONE_VM /* flags */
  846. oris r3,r3,CLONE_UNTRACED>>16
  847. li r4,0 /* new sp (unused) */
  848. li r0,__NR_clone
  849. sc
  850. bns+ 1f /* did system call indicate error? */
  851. neg r3,r3 /* if so, make return code negative */
  852. 1: cmpwi 0,r3,0 /* parent or child? */
  853. bne 2f /* return if parent */
  854. li r0,0 /* make top-level stack frame */
  855. stwu r0,-16(r1)
  856. mtlr r30 /* fn addr in lr */
  857. mr r3,r31 /* load arg and call fn */
  858. PPC440EP_ERR42
  859. blrl
  860. li r0,__NR_exit /* exit if function returns */
  861. li r3,0
  862. sc
  863. 2: lwz r30,8(r1)
  864. lwz r31,12(r1)
  865. addi r1,r1,16
  866. blr
  867. /*
  868. * This routine is just here to keep GCC happy - sigh...
  869. */
  870. _GLOBAL(__main)
  871. blr
  872. #ifdef CONFIG_KEXEC
  873. /*
  874. * Must be relocatable PIC code callable as a C function.
  875. */
  876. .globl relocate_new_kernel
  877. relocate_new_kernel:
  878. /* r3 = page_list */
  879. /* r4 = reboot_code_buffer */
  880. /* r5 = start_address */
  881. li r0, 0
  882. /*
  883. * Set Machine Status Register to a known status,
  884. * switch the MMU off and jump to 1: in a single step.
  885. */
  886. mr r8, r0
  887. ori r8, r8, MSR_RI|MSR_ME
  888. mtspr SPRN_SRR1, r8
  889. addi r8, r4, 1f - relocate_new_kernel
  890. mtspr SPRN_SRR0, r8
  891. sync
  892. rfi
  893. 1:
  894. /* from this point address translation is turned off */
  895. /* and interrupts are disabled */
  896. /* set a new stack at the bottom of our page... */
  897. /* (not really needed now) */
  898. addi r1, r4, KEXEC_CONTROL_PAGE_SIZE - 8 /* for LR Save+Back Chain */
  899. stw r0, 0(r1)
  900. /* Do the copies */
  901. li r6, 0 /* checksum */
  902. mr r0, r3
  903. b 1f
  904. 0: /* top, read another word for the indirection page */
  905. lwzu r0, 4(r3)
  906. 1:
  907. /* is it a destination page? (r8) */
  908. rlwinm. r7, r0, 0, 31, 31 /* IND_DESTINATION (1<<0) */
  909. beq 2f
  910. rlwinm r8, r0, 0, 0, 19 /* clear kexec flags, page align */
  911. b 0b
  912. 2: /* is it an indirection page? (r3) */
  913. rlwinm. r7, r0, 0, 30, 30 /* IND_INDIRECTION (1<<1) */
  914. beq 2f
  915. rlwinm r3, r0, 0, 0, 19 /* clear kexec flags, page align */
  916. subi r3, r3, 4
  917. b 0b
  918. 2: /* are we done? */
  919. rlwinm. r7, r0, 0, 29, 29 /* IND_DONE (1<<2) */
  920. beq 2f
  921. b 3f
  922. 2: /* is it a source page? (r9) */
  923. rlwinm. r7, r0, 0, 28, 28 /* IND_SOURCE (1<<3) */
  924. beq 0b
  925. rlwinm r9, r0, 0, 0, 19 /* clear kexec flags, page align */
  926. li r7, PAGE_SIZE / 4
  927. mtctr r7
  928. subi r9, r9, 4
  929. subi r8, r8, 4
  930. 9:
  931. lwzu r0, 4(r9) /* do the copy */
  932. xor r6, r6, r0
  933. stwu r0, 4(r8)
  934. dcbst 0, r8
  935. sync
  936. icbi 0, r8
  937. bdnz 9b
  938. addi r9, r9, 4
  939. addi r8, r8, 4
  940. b 0b
  941. 3:
  942. /* To be certain of avoiding problems with self-modifying code
  943. * execute a serializing instruction here.
  944. */
  945. isync
  946. sync
  947. /* jump to the entry point, usually the setup routine */
  948. mtlr r5
  949. blrl
  950. 1: b 1b
  951. relocate_new_kernel_end:
  952. .globl relocate_new_kernel_size
  953. relocate_new_kernel_size:
  954. .long relocate_new_kernel_end - relocate_new_kernel
  955. #endif