misc_32.S 16 KB

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