misc_32.S 20 KB

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