misc_32.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  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. /*
  28. * This returns the high 64 bits of the product of two 64-bit numbers.
  29. */
  30. _GLOBAL(mulhdu)
  31. cmpwi r6,0
  32. cmpwi cr1,r3,0
  33. mr r10,r4
  34. mulhwu r4,r4,r5
  35. beq 1f
  36. mulhwu r0,r10,r6
  37. mullw r7,r10,r5
  38. addc r7,r0,r7
  39. addze r4,r4
  40. 1: beqlr cr1 /* all done if high part of A is 0 */
  41. mr r10,r3
  42. mullw r9,r3,r5
  43. mulhwu r3,r3,r5
  44. beq 2f
  45. mullw r0,r10,r6
  46. mulhwu r8,r10,r6
  47. addc r7,r0,r7
  48. adde r4,r4,r8
  49. addze r3,r3
  50. 2: addc r4,r4,r9
  51. addze r3,r3
  52. blr
  53. /*
  54. * Returns (address we're running at) - (address we were linked at)
  55. * for use before the text and data are mapped to KERNELBASE.
  56. */
  57. _GLOBAL(reloc_offset)
  58. mflr r0
  59. bl 1f
  60. 1: mflr r3
  61. LOADADDR(r4,1b)
  62. subf r3,r4,r3
  63. mtlr r0
  64. blr
  65. /*
  66. * add_reloc_offset(x) returns x + reloc_offset().
  67. */
  68. _GLOBAL(add_reloc_offset)
  69. mflr r0
  70. bl 1f
  71. 1: mflr r5
  72. LOADADDR(r4,1b)
  73. subf r5,r4,r5
  74. add r3,r3,r5
  75. mtlr r0
  76. blr
  77. /*
  78. * sub_reloc_offset(x) returns x - reloc_offset().
  79. */
  80. _GLOBAL(sub_reloc_offset)
  81. mflr r0
  82. bl 1f
  83. 1: mflr r5
  84. lis r4,1b@ha
  85. addi r4,r4,1b@l
  86. subf r5,r4,r5
  87. subf r3,r5,r3
  88. mtlr r0
  89. blr
  90. /*
  91. * reloc_got2 runs through the .got2 section adding an offset
  92. * to each entry.
  93. */
  94. _GLOBAL(reloc_got2)
  95. mflr r11
  96. lis r7,__got2_start@ha
  97. addi r7,r7,__got2_start@l
  98. lis r8,__got2_end@ha
  99. addi r8,r8,__got2_end@l
  100. subf r8,r7,r8
  101. srwi. r8,r8,2
  102. beqlr
  103. mtctr r8
  104. bl 1f
  105. 1: mflr r0
  106. lis r4,1b@ha
  107. addi r4,r4,1b@l
  108. subf r0,r4,r0
  109. add r7,r0,r7
  110. 2: lwz r0,0(r7)
  111. add r0,r0,r3
  112. stw r0,0(r7)
  113. addi r7,r7,4
  114. bdnz 2b
  115. mtlr r11
  116. blr
  117. /*
  118. * identify_cpu,
  119. * called with r3 = data offset and r4 = CPU number
  120. * doesn't change r3
  121. */
  122. _GLOBAL(identify_cpu)
  123. addis r8,r3,cpu_specs@ha
  124. addi r8,r8,cpu_specs@l
  125. mfpvr r7
  126. 1:
  127. lwz r5,CPU_SPEC_PVR_MASK(r8)
  128. and r5,r5,r7
  129. lwz r6,CPU_SPEC_PVR_VALUE(r8)
  130. cmplw 0,r6,r5
  131. beq 1f
  132. addi r8,r8,CPU_SPEC_ENTRY_SIZE
  133. b 1b
  134. 1:
  135. addis r6,r3,cur_cpu_spec@ha
  136. addi r6,r6,cur_cpu_spec@l
  137. sub r8,r8,r3
  138. stw r8,0(r6)
  139. blr
  140. /*
  141. * do_cpu_ftr_fixups - goes through the list of CPU feature fixups
  142. * and writes nop's over sections of code that don't apply for this cpu.
  143. * r3 = data offset (not changed)
  144. */
  145. _GLOBAL(do_cpu_ftr_fixups)
  146. /* Get CPU 0 features */
  147. addis r6,r3,cur_cpu_spec@ha
  148. addi r6,r6,cur_cpu_spec@l
  149. lwz r4,0(r6)
  150. add r4,r4,r3
  151. lwz r4,CPU_SPEC_FEATURES(r4)
  152. /* Get the fixup table */
  153. addis r6,r3,__start___ftr_fixup@ha
  154. addi r6,r6,__start___ftr_fixup@l
  155. addis r7,r3,__stop___ftr_fixup@ha
  156. addi r7,r7,__stop___ftr_fixup@l
  157. /* Do the fixup */
  158. 1: cmplw 0,r6,r7
  159. bgelr
  160. addi r6,r6,16
  161. lwz r8,-16(r6) /* mask */
  162. and r8,r8,r4
  163. lwz r9,-12(r6) /* value */
  164. cmplw 0,r8,r9
  165. beq 1b
  166. lwz r8,-8(r6) /* section begin */
  167. lwz r9,-4(r6) /* section end */
  168. subf. r9,r8,r9
  169. beq 1b
  170. /* write nops over the section of code */
  171. /* todo: if large section, add a branch at the start of it */
  172. srwi r9,r9,2
  173. mtctr r9
  174. add r8,r8,r3
  175. lis r0,0x60000000@h /* nop */
  176. 3: stw r0,0(r8)
  177. andi. r10,r4,CPU_FTR_SPLIT_ID_CACHE@l
  178. beq 2f
  179. dcbst 0,r8 /* suboptimal, but simpler */
  180. sync
  181. icbi 0,r8
  182. 2: addi r8,r8,4
  183. bdnz 3b
  184. sync /* additional sync needed on g4 */
  185. isync
  186. b 1b
  187. /*
  188. * call_setup_cpu - call the setup_cpu function for this cpu
  189. * r3 = data offset, r24 = cpu number
  190. *
  191. * Setup function is called with:
  192. * r3 = data offset
  193. * r4 = ptr to CPU spec (relocated)
  194. */
  195. _GLOBAL(call_setup_cpu)
  196. addis r4,r3,cur_cpu_spec@ha
  197. addi r4,r4,cur_cpu_spec@l
  198. lwz r4,0(r4)
  199. add r4,r4,r3
  200. lwz r5,CPU_SPEC_SETUP(r4)
  201. cmpi 0,r5,0
  202. add r5,r5,r3
  203. beqlr
  204. mtctr r5
  205. bctr
  206. #if defined(CONFIG_CPU_FREQ_PMAC) && defined(CONFIG_6xx)
  207. /* This gets called by via-pmu.c to switch the PLL selection
  208. * on 750fx CPU. This function should really be moved to some
  209. * other place (as most of the cpufreq code in via-pmu
  210. */
  211. _GLOBAL(low_choose_750fx_pll)
  212. /* Clear MSR:EE */
  213. mfmsr r7
  214. rlwinm r0,r7,0,17,15
  215. mtmsr r0
  216. /* If switching to PLL1, disable HID0:BTIC */
  217. cmplwi cr0,r3,0
  218. beq 1f
  219. mfspr r5,SPRN_HID0
  220. rlwinm r5,r5,0,27,25
  221. sync
  222. mtspr SPRN_HID0,r5
  223. isync
  224. sync
  225. 1:
  226. /* Calc new HID1 value */
  227. mfspr r4,SPRN_HID1 /* Build a HID1:PS bit from parameter */
  228. rlwinm r5,r3,16,15,15 /* Clear out HID1:PS from value read */
  229. rlwinm r4,r4,0,16,14 /* Could have I used rlwimi here ? */
  230. or r4,r4,r5
  231. mtspr SPRN_HID1,r4
  232. /* Store new HID1 image */
  233. rlwinm r6,r1,0,0,18
  234. lwz r6,TI_CPU(r6)
  235. slwi r6,r6,2
  236. addis r6,r6,nap_save_hid1@ha
  237. stw r4,nap_save_hid1@l(r6)
  238. /* If switching to PLL0, enable HID0:BTIC */
  239. cmplwi cr0,r3,0
  240. bne 1f
  241. mfspr r5,SPRN_HID0
  242. ori r5,r5,HID0_BTIC
  243. sync
  244. mtspr SPRN_HID0,r5
  245. isync
  246. sync
  247. 1:
  248. /* Return */
  249. mtmsr r7
  250. blr
  251. _GLOBAL(low_choose_7447a_dfs)
  252. /* Clear MSR:EE */
  253. mfmsr r7
  254. rlwinm r0,r7,0,17,15
  255. mtmsr r0
  256. /* Calc new HID1 value */
  257. mfspr r4,SPRN_HID1
  258. insrwi r4,r3,1,9 /* insert parameter into bit 9 */
  259. sync
  260. mtspr SPRN_HID1,r4
  261. sync
  262. isync
  263. /* Return */
  264. mtmsr r7
  265. blr
  266. #endif /* CONFIG_CPU_FREQ_PMAC && CONFIG_6xx */
  267. /*
  268. * complement mask on the msr then "or" some values on.
  269. * _nmask_and_or_msr(nmask, value_to_or)
  270. */
  271. _GLOBAL(_nmask_and_or_msr)
  272. mfmsr r0 /* Get current msr */
  273. andc r0,r0,r3 /* And off the bits set in r3 (first parm) */
  274. or r0,r0,r4 /* Or on the bits in r4 (second parm) */
  275. SYNC /* Some chip revs have problems here... */
  276. mtmsr r0 /* Update machine state */
  277. isync
  278. blr /* Done */
  279. /*
  280. * Flush MMU TLB
  281. */
  282. _GLOBAL(_tlbia)
  283. #if defined(CONFIG_40x)
  284. sync /* Flush to memory before changing mapping */
  285. tlbia
  286. isync /* Flush shadow TLB */
  287. #elif defined(CONFIG_44x)
  288. li r3,0
  289. sync
  290. /* Load high watermark */
  291. lis r4,tlb_44x_hwater@ha
  292. lwz r5,tlb_44x_hwater@l(r4)
  293. 1: tlbwe r3,r3,PPC44x_TLB_PAGEID
  294. addi r3,r3,1
  295. cmpw 0,r3,r5
  296. ble 1b
  297. isync
  298. #elif defined(CONFIG_FSL_BOOKE)
  299. /* Invalidate all entries in TLB0 */
  300. li r3, 0x04
  301. tlbivax 0,3
  302. /* Invalidate all entries in TLB1 */
  303. li r3, 0x0c
  304. tlbivax 0,3
  305. /* Invalidate all entries in TLB2 */
  306. li r3, 0x14
  307. tlbivax 0,3
  308. /* Invalidate all entries in TLB3 */
  309. li r3, 0x1c
  310. tlbivax 0,3
  311. msync
  312. #ifdef CONFIG_SMP
  313. tlbsync
  314. #endif /* CONFIG_SMP */
  315. #else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */
  316. #if defined(CONFIG_SMP)
  317. rlwinm r8,r1,0,0,18
  318. lwz r8,TI_CPU(r8)
  319. oris r8,r8,10
  320. mfmsr r10
  321. SYNC
  322. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  323. rlwinm r0,r0,0,28,26 /* clear DR */
  324. mtmsr r0
  325. SYNC_601
  326. isync
  327. lis r9,mmu_hash_lock@h
  328. ori r9,r9,mmu_hash_lock@l
  329. tophys(r9,r9)
  330. 10: lwarx r7,0,r9
  331. cmpwi 0,r7,0
  332. bne- 10b
  333. stwcx. r8,0,r9
  334. bne- 10b
  335. sync
  336. tlbia
  337. sync
  338. TLBSYNC
  339. li r0,0
  340. stw r0,0(r9) /* clear mmu_hash_lock */
  341. mtmsr r10
  342. SYNC_601
  343. isync
  344. #else /* CONFIG_SMP */
  345. sync
  346. tlbia
  347. sync
  348. #endif /* CONFIG_SMP */
  349. #endif /* ! defined(CONFIG_40x) */
  350. blr
  351. /*
  352. * Flush MMU TLB for a particular address
  353. */
  354. _GLOBAL(_tlbie)
  355. #if defined(CONFIG_40x)
  356. tlbsx. r3, 0, r3
  357. bne 10f
  358. sync
  359. /* There are only 64 TLB entries, so r3 < 64, which means bit 25 is clear.
  360. * Since 25 is the V bit in the TLB_TAG, loading this value will invalidate
  361. * the TLB entry. */
  362. tlbwe r3, r3, TLB_TAG
  363. isync
  364. 10:
  365. #elif defined(CONFIG_44x)
  366. mfspr r4,SPRN_MMUCR
  367. mfspr r5,SPRN_PID /* Get PID */
  368. rlwimi r4,r5,0,24,31 /* Set TID */
  369. mtspr SPRN_MMUCR,r4
  370. tlbsx. r3, 0, r3
  371. bne 10f
  372. sync
  373. /* There are only 64 TLB entries, so r3 < 64,
  374. * which means bit 22, is clear. Since 22 is
  375. * the V bit in the TLB_PAGEID, loading this
  376. * value will invalidate the TLB entry.
  377. */
  378. tlbwe r3, r3, PPC44x_TLB_PAGEID
  379. isync
  380. 10:
  381. #elif defined(CONFIG_FSL_BOOKE)
  382. rlwinm r4, r3, 0, 0, 19
  383. ori r5, r4, 0x08 /* TLBSEL = 1 */
  384. ori r6, r4, 0x10 /* TLBSEL = 2 */
  385. ori r7, r4, 0x18 /* TLBSEL = 3 */
  386. tlbivax 0, r4
  387. tlbivax 0, r5
  388. tlbivax 0, r6
  389. tlbivax 0, r7
  390. msync
  391. #if defined(CONFIG_SMP)
  392. tlbsync
  393. #endif /* CONFIG_SMP */
  394. #else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */
  395. #if defined(CONFIG_SMP)
  396. rlwinm r8,r1,0,0,18
  397. lwz r8,TI_CPU(r8)
  398. oris r8,r8,11
  399. mfmsr r10
  400. SYNC
  401. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  402. rlwinm r0,r0,0,28,26 /* clear DR */
  403. mtmsr r0
  404. SYNC_601
  405. isync
  406. lis r9,mmu_hash_lock@h
  407. ori r9,r9,mmu_hash_lock@l
  408. tophys(r9,r9)
  409. 10: lwarx r7,0,r9
  410. cmpwi 0,r7,0
  411. bne- 10b
  412. stwcx. r8,0,r9
  413. bne- 10b
  414. eieio
  415. tlbie r3
  416. sync
  417. TLBSYNC
  418. li r0,0
  419. stw r0,0(r9) /* clear mmu_hash_lock */
  420. mtmsr r10
  421. SYNC_601
  422. isync
  423. #else /* CONFIG_SMP */
  424. tlbie r3
  425. sync
  426. #endif /* CONFIG_SMP */
  427. #endif /* ! CONFIG_40x */
  428. blr
  429. /*
  430. * Flush instruction cache.
  431. * This is a no-op on the 601.
  432. */
  433. _GLOBAL(flush_instruction_cache)
  434. #if defined(CONFIG_8xx)
  435. isync
  436. lis r5, IDC_INVALL@h
  437. mtspr SPRN_IC_CST, r5
  438. #elif defined(CONFIG_4xx)
  439. #ifdef CONFIG_403GCX
  440. li r3, 512
  441. mtctr r3
  442. lis r4, KERNELBASE@h
  443. 1: iccci 0, r4
  444. addi r4, r4, 16
  445. bdnz 1b
  446. #else
  447. lis r3, KERNELBASE@h
  448. iccci 0,r3
  449. #endif
  450. #elif CONFIG_FSL_BOOKE
  451. BEGIN_FTR_SECTION
  452. mfspr r3,SPRN_L1CSR0
  453. ori r3,r3,L1CSR0_CFI|L1CSR0_CLFC
  454. /* msync; isync recommended here */
  455. mtspr SPRN_L1CSR0,r3
  456. isync
  457. blr
  458. END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE)
  459. mfspr r3,SPRN_L1CSR1
  460. ori r3,r3,L1CSR1_ICFI|L1CSR1_ICLFR
  461. mtspr SPRN_L1CSR1,r3
  462. #else
  463. mfspr r3,SPRN_PVR
  464. rlwinm r3,r3,16,16,31
  465. cmpwi 0,r3,1
  466. beqlr /* for 601, do nothing */
  467. /* 603/604 processor - use invalidate-all bit in HID0 */
  468. mfspr r3,SPRN_HID0
  469. ori r3,r3,HID0_ICFI
  470. mtspr SPRN_HID0,r3
  471. #endif /* CONFIG_8xx/4xx */
  472. isync
  473. blr
  474. /*
  475. * Write any modified data cache blocks out to memory
  476. * and invalidate the corresponding instruction cache blocks.
  477. * This is a no-op on the 601.
  478. *
  479. * flush_icache_range(unsigned long start, unsigned long stop)
  480. */
  481. _GLOBAL(__flush_icache_range)
  482. BEGIN_FTR_SECTION
  483. blr /* for 601, do nothing */
  484. END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE)
  485. li r5,L1_CACHE_BYTES-1
  486. andc r3,r3,r5
  487. subf r4,r3,r4
  488. add r4,r4,r5
  489. srwi. r4,r4,L1_CACHE_SHIFT
  490. beqlr
  491. mtctr r4
  492. mr r6,r3
  493. 1: dcbst 0,r3
  494. addi r3,r3,L1_CACHE_BYTES
  495. bdnz 1b
  496. sync /* wait for dcbst's to get to ram */
  497. mtctr r4
  498. 2: icbi 0,r6
  499. addi r6,r6,L1_CACHE_BYTES
  500. bdnz 2b
  501. sync /* additional sync needed on g4 */
  502. isync
  503. blr
  504. /*
  505. * Write any modified data cache blocks out to memory.
  506. * Does not invalidate the corresponding cache lines (especially for
  507. * any corresponding instruction cache).
  508. *
  509. * clean_dcache_range(unsigned long start, unsigned long stop)
  510. */
  511. _GLOBAL(clean_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: dcbst 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. * Write any modified data cache blocks out to memory and invalidate them.
  526. * Does not invalidate the corresponding instruction cache blocks.
  527. *
  528. * flush_dcache_range(unsigned long start, unsigned long stop)
  529. */
  530. _GLOBAL(flush_dcache_range)
  531. li r5,L1_CACHE_BYTES-1
  532. andc r3,r3,r5
  533. subf r4,r3,r4
  534. add r4,r4,r5
  535. srwi. r4,r4,L1_CACHE_SHIFT
  536. beqlr
  537. mtctr r4
  538. 1: dcbf 0,r3
  539. addi r3,r3,L1_CACHE_BYTES
  540. bdnz 1b
  541. sync /* wait for dcbst's to get to ram */
  542. blr
  543. /*
  544. * Like above, but invalidate the D-cache. This is used by the 8xx
  545. * to invalidate the cache so the PPC core doesn't get stale data
  546. * from the CPM (no cache snooping here :-).
  547. *
  548. * invalidate_dcache_range(unsigned long start, unsigned long stop)
  549. */
  550. _GLOBAL(invalidate_dcache_range)
  551. li r5,L1_CACHE_BYTES-1
  552. andc r3,r3,r5
  553. subf r4,r3,r4
  554. add r4,r4,r5
  555. srwi. r4,r4,L1_CACHE_SHIFT
  556. beqlr
  557. mtctr r4
  558. 1: dcbi 0,r3
  559. addi r3,r3,L1_CACHE_BYTES
  560. bdnz 1b
  561. sync /* wait for dcbi's to get to ram */
  562. blr
  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. * Create a kernel thread
  905. * kernel_thread(fn, arg, flags)
  906. */
  907. _GLOBAL(kernel_thread)
  908. stwu r1,-16(r1)
  909. stw r30,8(r1)
  910. stw r31,12(r1)
  911. mr r30,r3 /* function */
  912. mr r31,r4 /* argument */
  913. ori r3,r5,CLONE_VM /* flags */
  914. oris r3,r3,CLONE_UNTRACED>>16
  915. li r4,0 /* new sp (unused) */
  916. li r0,__NR_clone
  917. sc
  918. cmpwi 0,r3,0 /* parent or child? */
  919. bne 1f /* return if parent */
  920. li r0,0 /* make top-level stack frame */
  921. stwu r0,-16(r1)
  922. mtlr r30 /* fn addr in lr */
  923. mr r3,r31 /* load arg and call fn */
  924. PPC440EP_ERR42
  925. blrl
  926. li r0,__NR_exit /* exit if function returns */
  927. li r3,0
  928. sc
  929. 1: lwz r30,8(r1)
  930. lwz r31,12(r1)
  931. addi r1,r1,16
  932. blr
  933. _GLOBAL(execve)
  934. li r0,__NR_execve
  935. sc
  936. bnslr
  937. neg r3,r3
  938. blr
  939. /*
  940. * This routine is just here to keep GCC happy - sigh...
  941. */
  942. _GLOBAL(__main)
  943. blr