misc_32.S 19 KB

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