misc_32.S 18 KB

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