misc_32.S 21 KB

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