misc_32.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  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. _GLOBAL(_tlbia)
  253. #if defined(CONFIG_40x)
  254. sync /* Flush to memory before changing mapping */
  255. tlbia
  256. isync /* Flush shadow TLB */
  257. #elif defined(CONFIG_44x)
  258. li r3,0
  259. sync
  260. /* Load high watermark */
  261. lis r4,tlb_44x_hwater@ha
  262. lwz r5,tlb_44x_hwater@l(r4)
  263. 1: tlbwe r3,r3,PPC44x_TLB_PAGEID
  264. addi r3,r3,1
  265. cmpw 0,r3,r5
  266. ble 1b
  267. isync
  268. #elif defined(CONFIG_FSL_BOOKE)
  269. /* Invalidate all entries in TLB0 */
  270. li r3, 0x04
  271. tlbivax 0,3
  272. /* Invalidate all entries in TLB1 */
  273. li r3, 0x0c
  274. tlbivax 0,3
  275. msync
  276. #ifdef CONFIG_SMP
  277. tlbsync
  278. #endif /* CONFIG_SMP */
  279. #else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */
  280. #if defined(CONFIG_SMP)
  281. rlwinm r8,r1,0,0,(31-THREAD_SHIFT)
  282. lwz r8,TI_CPU(r8)
  283. oris r8,r8,10
  284. mfmsr r10
  285. SYNC
  286. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  287. rlwinm r0,r0,0,28,26 /* clear DR */
  288. mtmsr r0
  289. SYNC_601
  290. isync
  291. lis r9,mmu_hash_lock@h
  292. ori r9,r9,mmu_hash_lock@l
  293. tophys(r9,r9)
  294. 10: lwarx r7,0,r9
  295. cmpwi 0,r7,0
  296. bne- 10b
  297. stwcx. r8,0,r9
  298. bne- 10b
  299. sync
  300. tlbia
  301. sync
  302. TLBSYNC
  303. li r0,0
  304. stw r0,0(r9) /* clear mmu_hash_lock */
  305. mtmsr r10
  306. SYNC_601
  307. isync
  308. #else /* CONFIG_SMP */
  309. sync
  310. tlbia
  311. sync
  312. #endif /* CONFIG_SMP */
  313. #endif /* ! defined(CONFIG_40x) */
  314. blr
  315. /*
  316. * Flush MMU TLB for a particular address
  317. */
  318. _GLOBAL(_tlbie)
  319. #if defined(CONFIG_40x)
  320. /* We run the search with interrupts disabled because we have to change
  321. * the PID and I don't want to preempt when that happens.
  322. */
  323. mfmsr r5
  324. mfspr r6,SPRN_PID
  325. wrteei 0
  326. mtspr SPRN_PID,r4
  327. tlbsx. r3, 0, r3
  328. mtspr SPRN_PID,r6
  329. wrtee r5
  330. bne 10f
  331. sync
  332. /* There are only 64 TLB entries, so r3 < 64, which means bit 25 is clear.
  333. * Since 25 is the V bit in the TLB_TAG, loading this value will invalidate
  334. * the TLB entry. */
  335. tlbwe r3, r3, TLB_TAG
  336. isync
  337. 10:
  338. #elif defined(CONFIG_44x)
  339. mfspr r5,SPRN_MMUCR
  340. rlwimi r5,r4,0,24,31 /* Set TID */
  341. /* We have to run the search with interrupts disabled, even critical
  342. * and debug interrupts (in fact the only critical exceptions we have
  343. * are debug and machine check). Otherwise an interrupt which causes
  344. * a TLB miss can clobber the MMUCR between the mtspr and the tlbsx. */
  345. mfmsr r4
  346. lis r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@ha
  347. addi r6,r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@l
  348. andc r6,r4,r6
  349. mtmsr r6
  350. mtspr SPRN_MMUCR,r5
  351. tlbsx. r3, 0, r3
  352. mtmsr r4
  353. bne 10f
  354. sync
  355. /* There are only 64 TLB entries, so r3 < 64,
  356. * which means bit 22, is clear. Since 22 is
  357. * the V bit in the TLB_PAGEID, loading this
  358. * value will invalidate the TLB entry.
  359. */
  360. tlbwe r3, r3, PPC44x_TLB_PAGEID
  361. isync
  362. 10:
  363. #elif defined(CONFIG_FSL_BOOKE)
  364. rlwinm r4, r3, 0, 0, 19
  365. ori r5, r4, 0x08 /* TLBSEL = 1 */
  366. tlbivax 0, r4
  367. tlbivax 0, r5
  368. msync
  369. #if defined(CONFIG_SMP)
  370. tlbsync
  371. #endif /* CONFIG_SMP */
  372. #else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */
  373. #if defined(CONFIG_SMP)
  374. rlwinm r8,r1,0,0,(31-THREAD_SHIFT)
  375. lwz r8,TI_CPU(r8)
  376. oris r8,r8,11
  377. mfmsr r10
  378. SYNC
  379. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  380. rlwinm r0,r0,0,28,26 /* clear DR */
  381. mtmsr r0
  382. SYNC_601
  383. isync
  384. lis r9,mmu_hash_lock@h
  385. ori r9,r9,mmu_hash_lock@l
  386. tophys(r9,r9)
  387. 10: lwarx r7,0,r9
  388. cmpwi 0,r7,0
  389. bne- 10b
  390. stwcx. r8,0,r9
  391. bne- 10b
  392. eieio
  393. tlbie r3
  394. sync
  395. TLBSYNC
  396. li r0,0
  397. stw r0,0(r9) /* clear mmu_hash_lock */
  398. mtmsr r10
  399. SYNC_601
  400. isync
  401. #else /* CONFIG_SMP */
  402. tlbie r3
  403. sync
  404. #endif /* CONFIG_SMP */
  405. #endif /* ! CONFIG_40x */
  406. blr
  407. /*
  408. * Flush instruction cache.
  409. * This is a no-op on the 601.
  410. */
  411. _GLOBAL(flush_instruction_cache)
  412. #if defined(CONFIG_8xx)
  413. isync
  414. lis r5, IDC_INVALL@h
  415. mtspr SPRN_IC_CST, r5
  416. #elif defined(CONFIG_4xx)
  417. #ifdef CONFIG_403GCX
  418. li r3, 512
  419. mtctr r3
  420. lis r4, KERNELBASE@h
  421. 1: iccci 0, r4
  422. addi r4, r4, 16
  423. bdnz 1b
  424. #else
  425. lis r3, KERNELBASE@h
  426. iccci 0,r3
  427. #endif
  428. #elif CONFIG_FSL_BOOKE
  429. BEGIN_FTR_SECTION
  430. mfspr r3,SPRN_L1CSR0
  431. ori r3,r3,L1CSR0_CFI|L1CSR0_CLFC
  432. /* msync; isync recommended here */
  433. mtspr SPRN_L1CSR0,r3
  434. isync
  435. blr
  436. END_FTR_SECTION_IFSET(CPU_FTR_UNIFIED_ID_CACHE)
  437. mfspr r3,SPRN_L1CSR1
  438. ori r3,r3,L1CSR1_ICFI|L1CSR1_ICLFR
  439. mtspr SPRN_L1CSR1,r3
  440. #else
  441. mfspr r3,SPRN_PVR
  442. rlwinm r3,r3,16,16,31
  443. cmpwi 0,r3,1
  444. beqlr /* for 601, do nothing */
  445. /* 603/604 processor - use invalidate-all bit in HID0 */
  446. mfspr r3,SPRN_HID0
  447. ori r3,r3,HID0_ICFI
  448. mtspr SPRN_HID0,r3
  449. #endif /* CONFIG_8xx/4xx */
  450. isync
  451. blr
  452. /*
  453. * Write any modified data cache blocks out to memory
  454. * and invalidate the corresponding instruction cache blocks.
  455. * This is a no-op on the 601.
  456. *
  457. * flush_icache_range(unsigned long start, unsigned long stop)
  458. */
  459. _KPROBE(__flush_icache_range)
  460. BEGIN_FTR_SECTION
  461. blr /* for 601, do nothing */
  462. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  463. li r5,L1_CACHE_BYTES-1
  464. andc r3,r3,r5
  465. subf r4,r3,r4
  466. add r4,r4,r5
  467. srwi. r4,r4,L1_CACHE_SHIFT
  468. beqlr
  469. mtctr r4
  470. mr r6,r3
  471. 1: dcbst 0,r3
  472. addi r3,r3,L1_CACHE_BYTES
  473. bdnz 1b
  474. sync /* wait for dcbst's to get to ram */
  475. mtctr r4
  476. 2: icbi 0,r6
  477. addi r6,r6,L1_CACHE_BYTES
  478. bdnz 2b
  479. sync /* additional sync needed on g4 */
  480. isync
  481. blr
  482. /*
  483. * Write any modified data cache blocks out to memory.
  484. * Does not invalidate the corresponding cache lines (especially for
  485. * any corresponding instruction cache).
  486. *
  487. * clean_dcache_range(unsigned long start, unsigned long stop)
  488. */
  489. _GLOBAL(clean_dcache_range)
  490. li r5,L1_CACHE_BYTES-1
  491. andc r3,r3,r5
  492. subf r4,r3,r4
  493. add r4,r4,r5
  494. srwi. r4,r4,L1_CACHE_SHIFT
  495. beqlr
  496. mtctr r4
  497. 1: dcbst 0,r3
  498. addi r3,r3,L1_CACHE_BYTES
  499. bdnz 1b
  500. sync /* wait for dcbst's to get to ram */
  501. blr
  502. /*
  503. * Write any modified data cache blocks out to memory and invalidate them.
  504. * Does not invalidate the corresponding instruction cache blocks.
  505. *
  506. * flush_dcache_range(unsigned long start, unsigned long stop)
  507. */
  508. _GLOBAL(flush_dcache_range)
  509. li r5,L1_CACHE_BYTES-1
  510. andc r3,r3,r5
  511. subf r4,r3,r4
  512. add r4,r4,r5
  513. srwi. r4,r4,L1_CACHE_SHIFT
  514. beqlr
  515. mtctr r4
  516. 1: dcbf 0,r3
  517. addi r3,r3,L1_CACHE_BYTES
  518. bdnz 1b
  519. sync /* wait for dcbst's to get to ram */
  520. blr
  521. /*
  522. * Like above, but invalidate the D-cache. This is used by the 8xx
  523. * to invalidate the cache so the PPC core doesn't get stale data
  524. * from the CPM (no cache snooping here :-).
  525. *
  526. * invalidate_dcache_range(unsigned long start, unsigned long stop)
  527. */
  528. _GLOBAL(invalidate_dcache_range)
  529. li r5,L1_CACHE_BYTES-1
  530. andc r3,r3,r5
  531. subf r4,r3,r4
  532. add r4,r4,r5
  533. srwi. r4,r4,L1_CACHE_SHIFT
  534. beqlr
  535. mtctr r4
  536. 1: dcbi 0,r3
  537. addi r3,r3,L1_CACHE_BYTES
  538. bdnz 1b
  539. sync /* wait for dcbi's to get to ram */
  540. blr
  541. /*
  542. * Flush a particular page from the data cache to RAM.
  543. * Note: this is necessary because the instruction cache does *not*
  544. * snoop from the data cache.
  545. * This is a no-op on the 601 which has a unified cache.
  546. *
  547. * void __flush_dcache_icache(void *page)
  548. */
  549. _GLOBAL(__flush_dcache_icache)
  550. BEGIN_FTR_SECTION
  551. blr
  552. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  553. rlwinm r3,r3,0,0,19 /* Get page base address */
  554. li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
  555. mtctr r4
  556. mr r6,r3
  557. 0: dcbst 0,r3 /* Write line to ram */
  558. addi r3,r3,L1_CACHE_BYTES
  559. bdnz 0b
  560. sync
  561. #ifndef CONFIG_44x
  562. /* We don't flush the icache on 44x. Those have a virtual icache
  563. * and we don't have access to the virtual address here (it's
  564. * not the page vaddr but where it's mapped in user space). The
  565. * flushing of the icache on these is handled elsewhere, when
  566. * a change in the address space occurs, before returning to
  567. * user space
  568. */
  569. mtctr r4
  570. 1: icbi 0,r6
  571. addi r6,r6,L1_CACHE_BYTES
  572. bdnz 1b
  573. sync
  574. isync
  575. #endif /* CONFIG_44x */
  576. blr
  577. /*
  578. * Flush a particular page from the data cache to RAM, identified
  579. * by its physical address. We turn off the MMU so we can just use
  580. * the physical address (this may be a highmem page without a kernel
  581. * mapping).
  582. *
  583. * void __flush_dcache_icache_phys(unsigned long physaddr)
  584. */
  585. _GLOBAL(__flush_dcache_icache_phys)
  586. BEGIN_FTR_SECTION
  587. blr /* for 601, do nothing */
  588. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  589. mfmsr r10
  590. rlwinm r0,r10,0,28,26 /* clear DR */
  591. mtmsr r0
  592. isync
  593. rlwinm r3,r3,0,0,19 /* Get page base address */
  594. li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
  595. mtctr r4
  596. mr r6,r3
  597. 0: dcbst 0,r3 /* Write line to ram */
  598. addi r3,r3,L1_CACHE_BYTES
  599. bdnz 0b
  600. sync
  601. mtctr r4
  602. 1: icbi 0,r6
  603. addi r6,r6,L1_CACHE_BYTES
  604. bdnz 1b
  605. sync
  606. mtmsr r10 /* restore DR */
  607. isync
  608. blr
  609. /*
  610. * Clear pages using the dcbz instruction, which doesn't cause any
  611. * memory traffic (except to write out any cache lines which get
  612. * displaced). This only works on cacheable memory.
  613. *
  614. * void clear_pages(void *page, int order) ;
  615. */
  616. _GLOBAL(clear_pages)
  617. li r0,4096/L1_CACHE_BYTES
  618. slw r0,r0,r4
  619. mtctr r0
  620. #ifdef CONFIG_8xx
  621. li r4, 0
  622. 1: stw r4, 0(r3)
  623. stw r4, 4(r3)
  624. stw r4, 8(r3)
  625. stw r4, 12(r3)
  626. #else
  627. 1: dcbz 0,r3
  628. #endif
  629. addi r3,r3,L1_CACHE_BYTES
  630. bdnz 1b
  631. blr
  632. /*
  633. * Copy a whole page. We use the dcbz instruction on the destination
  634. * to reduce memory traffic (it eliminates the unnecessary reads of
  635. * the destination into cache). This requires that the destination
  636. * is cacheable.
  637. */
  638. #define COPY_16_BYTES \
  639. lwz r6,4(r4); \
  640. lwz r7,8(r4); \
  641. lwz r8,12(r4); \
  642. lwzu r9,16(r4); \
  643. stw r6,4(r3); \
  644. stw r7,8(r3); \
  645. stw r8,12(r3); \
  646. stwu r9,16(r3)
  647. _GLOBAL(copy_page)
  648. addi r3,r3,-4
  649. addi r4,r4,-4
  650. #ifdef CONFIG_8xx
  651. /* don't use prefetch on 8xx */
  652. li r0,4096/L1_CACHE_BYTES
  653. mtctr r0
  654. 1: COPY_16_BYTES
  655. bdnz 1b
  656. blr
  657. #else /* not 8xx, we can prefetch */
  658. li r5,4
  659. #if MAX_COPY_PREFETCH > 1
  660. li r0,MAX_COPY_PREFETCH
  661. li r11,4
  662. mtctr r0
  663. 11: dcbt r11,r4
  664. addi r11,r11,L1_CACHE_BYTES
  665. bdnz 11b
  666. #else /* MAX_COPY_PREFETCH == 1 */
  667. dcbt r5,r4
  668. li r11,L1_CACHE_BYTES+4
  669. #endif /* MAX_COPY_PREFETCH */
  670. li r0,4096/L1_CACHE_BYTES - MAX_COPY_PREFETCH
  671. crclr 4*cr0+eq
  672. 2:
  673. mtctr r0
  674. 1:
  675. dcbt r11,r4
  676. dcbz r5,r3
  677. COPY_16_BYTES
  678. #if L1_CACHE_BYTES >= 32
  679. COPY_16_BYTES
  680. #if L1_CACHE_BYTES >= 64
  681. COPY_16_BYTES
  682. COPY_16_BYTES
  683. #if L1_CACHE_BYTES >= 128
  684. COPY_16_BYTES
  685. COPY_16_BYTES
  686. COPY_16_BYTES
  687. COPY_16_BYTES
  688. #endif
  689. #endif
  690. #endif
  691. bdnz 1b
  692. beqlr
  693. crnot 4*cr0+eq,4*cr0+eq
  694. li r0,MAX_COPY_PREFETCH
  695. li r11,4
  696. b 2b
  697. #endif /* CONFIG_8xx */
  698. /*
  699. * void atomic_clear_mask(atomic_t mask, atomic_t *addr)
  700. * void atomic_set_mask(atomic_t mask, atomic_t *addr);
  701. */
  702. _GLOBAL(atomic_clear_mask)
  703. 10: lwarx r5,0,r4
  704. andc r5,r5,r3
  705. PPC405_ERR77(0,r4)
  706. stwcx. r5,0,r4
  707. bne- 10b
  708. blr
  709. _GLOBAL(atomic_set_mask)
  710. 10: lwarx r5,0,r4
  711. or r5,r5,r3
  712. PPC405_ERR77(0,r4)
  713. stwcx. r5,0,r4
  714. bne- 10b
  715. blr
  716. /*
  717. * Extended precision shifts.
  718. *
  719. * Updated to be valid for shift counts from 0 to 63 inclusive.
  720. * -- Gabriel
  721. *
  722. * R3/R4 has 64 bit value
  723. * R5 has shift count
  724. * result in R3/R4
  725. *
  726. * ashrdi3: arithmetic right shift (sign propagation)
  727. * lshrdi3: logical right shift
  728. * ashldi3: left shift
  729. */
  730. _GLOBAL(__ashrdi3)
  731. subfic r6,r5,32
  732. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  733. addi r7,r5,32 # could be xori, or addi with -32
  734. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  735. rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0
  736. sraw r7,r3,r7 # t2 = MSW >> (count-32)
  737. or r4,r4,r6 # LSW |= t1
  738. slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2
  739. sraw r3,r3,r5 # MSW = MSW >> count
  740. or r4,r4,r7 # LSW |= t2
  741. blr
  742. _GLOBAL(__ashldi3)
  743. subfic r6,r5,32
  744. slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count
  745. addi r7,r5,32 # could be xori, or addi with -32
  746. srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count)
  747. slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32)
  748. or r3,r3,r6 # MSW |= t1
  749. slw r4,r4,r5 # LSW = LSW << count
  750. or r3,r3,r7 # MSW |= t2
  751. blr
  752. _GLOBAL(__lshrdi3)
  753. subfic r6,r5,32
  754. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  755. addi r7,r5,32 # could be xori, or addi with -32
  756. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  757. srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32)
  758. or r4,r4,r6 # LSW |= t1
  759. srw r3,r3,r5 # MSW = MSW >> count
  760. or r4,r4,r7 # LSW |= t2
  761. blr
  762. /*
  763. * 64-bit comparison: __ucmpdi2(u64 a, u64 b)
  764. * Returns 0 if a < b, 1 if a == b, 2 if a > b.
  765. */
  766. _GLOBAL(__ucmpdi2)
  767. cmplw r3,r5
  768. li r3,1
  769. bne 1f
  770. cmplw r4,r6
  771. beqlr
  772. 1: li r3,0
  773. bltlr
  774. li r3,2
  775. blr
  776. _GLOBAL(abs)
  777. srawi r4,r3,31
  778. xor r3,r3,r4
  779. sub r3,r3,r4
  780. blr
  781. /*
  782. * Create a kernel thread
  783. * kernel_thread(fn, arg, flags)
  784. */
  785. _GLOBAL(kernel_thread)
  786. stwu r1,-16(r1)
  787. stw r30,8(r1)
  788. stw r31,12(r1)
  789. mr r30,r3 /* function */
  790. mr r31,r4 /* argument */
  791. ori r3,r5,CLONE_VM /* flags */
  792. oris r3,r3,CLONE_UNTRACED>>16
  793. li r4,0 /* new sp (unused) */
  794. li r0,__NR_clone
  795. sc
  796. cmpwi 0,r3,0 /* parent or child? */
  797. bne 1f /* return if parent */
  798. li r0,0 /* make top-level stack frame */
  799. stwu r0,-16(r1)
  800. mtlr r30 /* fn addr in lr */
  801. mr r3,r31 /* load arg and call fn */
  802. PPC440EP_ERR42
  803. blrl
  804. li r0,__NR_exit /* exit if function returns */
  805. li r3,0
  806. sc
  807. 1: lwz r30,8(r1)
  808. lwz r31,12(r1)
  809. addi r1,r1,16
  810. blr
  811. /*
  812. * This routine is just here to keep GCC happy - sigh...
  813. */
  814. _GLOBAL(__main)
  815. blr
  816. #ifdef CONFIG_KEXEC
  817. /*
  818. * Must be relocatable PIC code callable as a C function.
  819. */
  820. .globl relocate_new_kernel
  821. relocate_new_kernel:
  822. /* r3 = page_list */
  823. /* r4 = reboot_code_buffer */
  824. /* r5 = start_address */
  825. li r0, 0
  826. /*
  827. * Set Machine Status Register to a known status,
  828. * switch the MMU off and jump to 1: in a single step.
  829. */
  830. mr r8, r0
  831. ori r8, r8, MSR_RI|MSR_ME
  832. mtspr SPRN_SRR1, r8
  833. addi r8, r4, 1f - relocate_new_kernel
  834. mtspr SPRN_SRR0, r8
  835. sync
  836. rfi
  837. 1:
  838. /* from this point address translation is turned off */
  839. /* and interrupts are disabled */
  840. /* set a new stack at the bottom of our page... */
  841. /* (not really needed now) */
  842. addi r1, r4, KEXEC_CONTROL_PAGE_SIZE - 8 /* for LR Save+Back Chain */
  843. stw r0, 0(r1)
  844. /* Do the copies */
  845. li r6, 0 /* checksum */
  846. mr r0, r3
  847. b 1f
  848. 0: /* top, read another word for the indirection page */
  849. lwzu r0, 4(r3)
  850. 1:
  851. /* is it a destination page? (r8) */
  852. rlwinm. r7, r0, 0, 31, 31 /* IND_DESTINATION (1<<0) */
  853. beq 2f
  854. rlwinm r8, r0, 0, 0, 19 /* clear kexec flags, page align */
  855. b 0b
  856. 2: /* is it an indirection page? (r3) */
  857. rlwinm. r7, r0, 0, 30, 30 /* IND_INDIRECTION (1<<1) */
  858. beq 2f
  859. rlwinm r3, r0, 0, 0, 19 /* clear kexec flags, page align */
  860. subi r3, r3, 4
  861. b 0b
  862. 2: /* are we done? */
  863. rlwinm. r7, r0, 0, 29, 29 /* IND_DONE (1<<2) */
  864. beq 2f
  865. b 3f
  866. 2: /* is it a source page? (r9) */
  867. rlwinm. r7, r0, 0, 28, 28 /* IND_SOURCE (1<<3) */
  868. beq 0b
  869. rlwinm r9, r0, 0, 0, 19 /* clear kexec flags, page align */
  870. li r7, PAGE_SIZE / 4
  871. mtctr r7
  872. subi r9, r9, 4
  873. subi r8, r8, 4
  874. 9:
  875. lwzu r0, 4(r9) /* do the copy */
  876. xor r6, r6, r0
  877. stwu r0, 4(r8)
  878. dcbst 0, r8
  879. sync
  880. icbi 0, r8
  881. bdnz 9b
  882. addi r9, r9, 4
  883. addi r8, r8, 4
  884. b 0b
  885. 3:
  886. /* To be certain of avoiding problems with self-modifying code
  887. * execute a serializing instruction here.
  888. */
  889. isync
  890. sync
  891. /* jump to the entry point, usually the setup routine */
  892. mtlr r5
  893. blrl
  894. 1: b 1b
  895. relocate_new_kernel_end:
  896. .globl relocate_new_kernel_size
  897. relocate_new_kernel_size:
  898. .long relocate_new_kernel_end - relocate_new_kernel
  899. #endif