misc_32.S 20 KB

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