misc_32.S 21 KB

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