misc_32.S 18 KB

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