misc_32.S 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  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. #ifndef CONFIG_44x
  319. mtctr r4
  320. 2: icbi 0,r6
  321. addi r6,r6,L1_CACHE_BYTES
  322. bdnz 2b
  323. #else
  324. /* Flash invalidate on 44x because we are passed kmapped addresses and
  325. this doesn't work for userspace pages due to the virtually tagged
  326. icache. Sigh. */
  327. iccci 0, r0
  328. #endif
  329. sync /* additional sync needed on g4 */
  330. isync
  331. blr
  332. /*
  333. * Write any modified data cache blocks out to memory.
  334. * Does not invalidate the corresponding cache lines (especially for
  335. * any corresponding instruction cache).
  336. *
  337. * clean_dcache_range(unsigned long start, unsigned long stop)
  338. */
  339. _GLOBAL(clean_dcache_range)
  340. li r5,L1_CACHE_BYTES-1
  341. andc r3,r3,r5
  342. subf r4,r3,r4
  343. add r4,r4,r5
  344. srwi. r4,r4,L1_CACHE_SHIFT
  345. beqlr
  346. mtctr r4
  347. 1: dcbst 0,r3
  348. addi r3,r3,L1_CACHE_BYTES
  349. bdnz 1b
  350. sync /* wait for dcbst's to get to ram */
  351. blr
  352. /*
  353. * Write any modified data cache blocks out to memory and invalidate them.
  354. * Does not invalidate the corresponding instruction cache blocks.
  355. *
  356. * flush_dcache_range(unsigned long start, unsigned long stop)
  357. */
  358. _GLOBAL(flush_dcache_range)
  359. li r5,L1_CACHE_BYTES-1
  360. andc r3,r3,r5
  361. subf r4,r3,r4
  362. add r4,r4,r5
  363. srwi. r4,r4,L1_CACHE_SHIFT
  364. beqlr
  365. mtctr r4
  366. 1: dcbf 0,r3
  367. addi r3,r3,L1_CACHE_BYTES
  368. bdnz 1b
  369. sync /* wait for dcbst's to get to ram */
  370. blr
  371. /*
  372. * Like above, but invalidate the D-cache. This is used by the 8xx
  373. * to invalidate the cache so the PPC core doesn't get stale data
  374. * from the CPM (no cache snooping here :-).
  375. *
  376. * invalidate_dcache_range(unsigned long start, unsigned long stop)
  377. */
  378. _GLOBAL(invalidate_dcache_range)
  379. li r5,L1_CACHE_BYTES-1
  380. andc r3,r3,r5
  381. subf r4,r3,r4
  382. add r4,r4,r5
  383. srwi. r4,r4,L1_CACHE_SHIFT
  384. beqlr
  385. mtctr r4
  386. 1: dcbi 0,r3
  387. addi r3,r3,L1_CACHE_BYTES
  388. bdnz 1b
  389. sync /* wait for dcbi's to get to ram */
  390. blr
  391. /*
  392. * Flush a particular page from the data cache to RAM.
  393. * Note: this is necessary because the instruction cache does *not*
  394. * snoop from the data cache.
  395. * This is a no-op on the 601 which has a unified cache.
  396. *
  397. * void __flush_dcache_icache(void *page)
  398. */
  399. _GLOBAL(__flush_dcache_icache)
  400. BEGIN_FTR_SECTION
  401. blr
  402. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  403. rlwinm r3,r3,0,0,31-PAGE_SHIFT /* Get page base address */
  404. li r4,PAGE_SIZE/L1_CACHE_BYTES /* Number of lines in a page */
  405. mtctr r4
  406. mr r6,r3
  407. 0: dcbst 0,r3 /* Write line to ram */
  408. addi r3,r3,L1_CACHE_BYTES
  409. bdnz 0b
  410. sync
  411. #ifndef CONFIG_44x
  412. /* We don't flush the icache on 44x. Those have a virtual icache
  413. * and we don't have access to the virtual address here (it's
  414. * not the page vaddr but where it's mapped in user space). The
  415. * flushing of the icache on these is handled elsewhere, when
  416. * a change in the address space occurs, before returning to
  417. * user space
  418. */
  419. mtctr r4
  420. 1: icbi 0,r6
  421. addi r6,r6,L1_CACHE_BYTES
  422. bdnz 1b
  423. sync
  424. isync
  425. #endif /* CONFIG_44x */
  426. blr
  427. /*
  428. * Flush a particular page from the data cache to RAM, identified
  429. * by its physical address. We turn off the MMU so we can just use
  430. * the physical address (this may be a highmem page without a kernel
  431. * mapping).
  432. *
  433. * void __flush_dcache_icache_phys(unsigned long physaddr)
  434. */
  435. _GLOBAL(__flush_dcache_icache_phys)
  436. BEGIN_FTR_SECTION
  437. blr /* for 601, do nothing */
  438. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  439. mfmsr r10
  440. rlwinm r0,r10,0,28,26 /* clear DR */
  441. mtmsr r0
  442. isync
  443. rlwinm r3,r3,0,0,31-PAGE_SHIFT /* Get page base address */
  444. li r4,PAGE_SIZE/L1_CACHE_BYTES /* Number of lines in a page */
  445. mtctr r4
  446. mr r6,r3
  447. 0: dcbst 0,r3 /* Write line to ram */
  448. addi r3,r3,L1_CACHE_BYTES
  449. bdnz 0b
  450. sync
  451. mtctr r4
  452. 1: icbi 0,r6
  453. addi r6,r6,L1_CACHE_BYTES
  454. bdnz 1b
  455. sync
  456. mtmsr r10 /* restore DR */
  457. isync
  458. blr
  459. /*
  460. * Clear pages using the dcbz instruction, which doesn't cause any
  461. * memory traffic (except to write out any cache lines which get
  462. * displaced). This only works on cacheable memory.
  463. *
  464. * void clear_pages(void *page, int order) ;
  465. */
  466. _GLOBAL(clear_pages)
  467. li r0,PAGE_SIZE/L1_CACHE_BYTES
  468. slw r0,r0,r4
  469. mtctr r0
  470. #ifdef CONFIG_8xx
  471. li r4, 0
  472. 1: stw r4, 0(r3)
  473. stw r4, 4(r3)
  474. stw r4, 8(r3)
  475. stw r4, 12(r3)
  476. #else
  477. 1: dcbz 0,r3
  478. #endif
  479. addi r3,r3,L1_CACHE_BYTES
  480. bdnz 1b
  481. blr
  482. /*
  483. * Copy a whole page. We use the dcbz instruction on the destination
  484. * to reduce memory traffic (it eliminates the unnecessary reads of
  485. * the destination into cache). This requires that the destination
  486. * is cacheable.
  487. */
  488. #define COPY_16_BYTES \
  489. lwz r6,4(r4); \
  490. lwz r7,8(r4); \
  491. lwz r8,12(r4); \
  492. lwzu r9,16(r4); \
  493. stw r6,4(r3); \
  494. stw r7,8(r3); \
  495. stw r8,12(r3); \
  496. stwu r9,16(r3)
  497. _GLOBAL(copy_page)
  498. addi r3,r3,-4
  499. addi r4,r4,-4
  500. #ifdef CONFIG_8xx
  501. /* don't use prefetch on 8xx */
  502. li r0,4096/L1_CACHE_BYTES
  503. mtctr r0
  504. 1: COPY_16_BYTES
  505. bdnz 1b
  506. blr
  507. #else /* not 8xx, we can prefetch */
  508. li r5,4
  509. #if MAX_COPY_PREFETCH > 1
  510. li r0,MAX_COPY_PREFETCH
  511. li r11,4
  512. mtctr r0
  513. 11: dcbt r11,r4
  514. addi r11,r11,L1_CACHE_BYTES
  515. bdnz 11b
  516. #else /* MAX_COPY_PREFETCH == 1 */
  517. dcbt r5,r4
  518. li r11,L1_CACHE_BYTES+4
  519. #endif /* MAX_COPY_PREFETCH */
  520. li r0,PAGE_SIZE/L1_CACHE_BYTES - MAX_COPY_PREFETCH
  521. crclr 4*cr0+eq
  522. 2:
  523. mtctr r0
  524. 1:
  525. dcbt r11,r4
  526. dcbz r5,r3
  527. COPY_16_BYTES
  528. #if L1_CACHE_BYTES >= 32
  529. COPY_16_BYTES
  530. #if L1_CACHE_BYTES >= 64
  531. COPY_16_BYTES
  532. COPY_16_BYTES
  533. #if L1_CACHE_BYTES >= 128
  534. COPY_16_BYTES
  535. COPY_16_BYTES
  536. COPY_16_BYTES
  537. COPY_16_BYTES
  538. #endif
  539. #endif
  540. #endif
  541. bdnz 1b
  542. beqlr
  543. crnot 4*cr0+eq,4*cr0+eq
  544. li r0,MAX_COPY_PREFETCH
  545. li r11,4
  546. b 2b
  547. #endif /* CONFIG_8xx */
  548. /*
  549. * void atomic_clear_mask(atomic_t mask, atomic_t *addr)
  550. * void atomic_set_mask(atomic_t mask, atomic_t *addr);
  551. */
  552. _GLOBAL(atomic_clear_mask)
  553. 10: lwarx r5,0,r4
  554. andc r5,r5,r3
  555. PPC405_ERR77(0,r4)
  556. stwcx. r5,0,r4
  557. bne- 10b
  558. blr
  559. _GLOBAL(atomic_set_mask)
  560. 10: lwarx r5,0,r4
  561. or r5,r5,r3
  562. PPC405_ERR77(0,r4)
  563. stwcx. r5,0,r4
  564. bne- 10b
  565. blr
  566. /*
  567. * Extended precision shifts.
  568. *
  569. * Updated to be valid for shift counts from 0 to 63 inclusive.
  570. * -- Gabriel
  571. *
  572. * R3/R4 has 64 bit value
  573. * R5 has shift count
  574. * result in R3/R4
  575. *
  576. * ashrdi3: arithmetic right shift (sign propagation)
  577. * lshrdi3: logical right shift
  578. * ashldi3: left shift
  579. */
  580. _GLOBAL(__ashrdi3)
  581. subfic r6,r5,32
  582. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  583. addi r7,r5,32 # could be xori, or addi with -32
  584. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  585. rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0
  586. sraw r7,r3,r7 # t2 = MSW >> (count-32)
  587. or r4,r4,r6 # LSW |= t1
  588. slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2
  589. sraw r3,r3,r5 # MSW = MSW >> count
  590. or r4,r4,r7 # LSW |= t2
  591. blr
  592. _GLOBAL(__ashldi3)
  593. subfic r6,r5,32
  594. slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count
  595. addi r7,r5,32 # could be xori, or addi with -32
  596. srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count)
  597. slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32)
  598. or r3,r3,r6 # MSW |= t1
  599. slw r4,r4,r5 # LSW = LSW << count
  600. or r3,r3,r7 # MSW |= t2
  601. blr
  602. _GLOBAL(__lshrdi3)
  603. subfic r6,r5,32
  604. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  605. addi r7,r5,32 # could be xori, or addi with -32
  606. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  607. srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32)
  608. or r4,r4,r6 # LSW |= t1
  609. srw r3,r3,r5 # MSW = MSW >> count
  610. or r4,r4,r7 # LSW |= t2
  611. blr
  612. /*
  613. * 64-bit comparison: __ucmpdi2(u64 a, u64 b)
  614. * Returns 0 if a < b, 1 if a == b, 2 if a > b.
  615. */
  616. _GLOBAL(__ucmpdi2)
  617. cmplw r3,r5
  618. li r3,1
  619. bne 1f
  620. cmplw r4,r6
  621. beqlr
  622. 1: li r3,0
  623. bltlr
  624. li r3,2
  625. blr
  626. _GLOBAL(abs)
  627. srawi r4,r3,31
  628. xor r3,r3,r4
  629. sub r3,r3,r4
  630. blr
  631. /*
  632. * Create a kernel thread
  633. * kernel_thread(fn, arg, flags)
  634. */
  635. _GLOBAL(kernel_thread)
  636. stwu r1,-16(r1)
  637. stw r30,8(r1)
  638. stw r31,12(r1)
  639. mr r30,r3 /* function */
  640. mr r31,r4 /* argument */
  641. ori r3,r5,CLONE_VM /* flags */
  642. oris r3,r3,CLONE_UNTRACED>>16
  643. li r4,0 /* new sp (unused) */
  644. li r0,__NR_clone
  645. sc
  646. bns+ 1f /* did system call indicate error? */
  647. neg r3,r3 /* if so, make return code negative */
  648. 1: cmpwi 0,r3,0 /* parent or child? */
  649. bne 2f /* return if parent */
  650. li r0,0 /* make top-level stack frame */
  651. stwu r0,-16(r1)
  652. mtlr r30 /* fn addr in lr */
  653. mr r3,r31 /* load arg and call fn */
  654. PPC440EP_ERR42
  655. blrl
  656. li r0,__NR_exit /* exit if function returns */
  657. li r3,0
  658. sc
  659. 2: lwz r30,8(r1)
  660. lwz r31,12(r1)
  661. addi r1,r1,16
  662. blr
  663. /*
  664. * This routine is just here to keep GCC happy - sigh...
  665. */
  666. _GLOBAL(__main)
  667. blr
  668. #ifdef CONFIG_KEXEC
  669. /*
  670. * Must be relocatable PIC code callable as a C function.
  671. */
  672. .globl relocate_new_kernel
  673. relocate_new_kernel:
  674. /* r3 = page_list */
  675. /* r4 = reboot_code_buffer */
  676. /* r5 = start_address */
  677. li r0, 0
  678. /*
  679. * Set Machine Status Register to a known status,
  680. * switch the MMU off and jump to 1: in a single step.
  681. */
  682. mr r8, r0
  683. ori r8, r8, MSR_RI|MSR_ME
  684. mtspr SPRN_SRR1, r8
  685. addi r8, r4, 1f - relocate_new_kernel
  686. mtspr SPRN_SRR0, r8
  687. sync
  688. rfi
  689. 1:
  690. /* from this point address translation is turned off */
  691. /* and interrupts are disabled */
  692. /* set a new stack at the bottom of our page... */
  693. /* (not really needed now) */
  694. addi r1, r4, KEXEC_CONTROL_PAGE_SIZE - 8 /* for LR Save+Back Chain */
  695. stw r0, 0(r1)
  696. /* Do the copies */
  697. li r6, 0 /* checksum */
  698. mr r0, r3
  699. b 1f
  700. 0: /* top, read another word for the indirection page */
  701. lwzu r0, 4(r3)
  702. 1:
  703. /* is it a destination page? (r8) */
  704. rlwinm. r7, r0, 0, 31, 31 /* IND_DESTINATION (1<<0) */
  705. beq 2f
  706. rlwinm r8, r0, 0, 0, 19 /* clear kexec flags, page align */
  707. b 0b
  708. 2: /* is it an indirection page? (r3) */
  709. rlwinm. r7, r0, 0, 30, 30 /* IND_INDIRECTION (1<<1) */
  710. beq 2f
  711. rlwinm r3, r0, 0, 0, 19 /* clear kexec flags, page align */
  712. subi r3, r3, 4
  713. b 0b
  714. 2: /* are we done? */
  715. rlwinm. r7, r0, 0, 29, 29 /* IND_DONE (1<<2) */
  716. beq 2f
  717. b 3f
  718. 2: /* is it a source page? (r9) */
  719. rlwinm. r7, r0, 0, 28, 28 /* IND_SOURCE (1<<3) */
  720. beq 0b
  721. rlwinm r9, r0, 0, 0, 19 /* clear kexec flags, page align */
  722. li r7, PAGE_SIZE / 4
  723. mtctr r7
  724. subi r9, r9, 4
  725. subi r8, r8, 4
  726. 9:
  727. lwzu r0, 4(r9) /* do the copy */
  728. xor r6, r6, r0
  729. stwu r0, 4(r8)
  730. dcbst 0, r8
  731. sync
  732. icbi 0, r8
  733. bdnz 9b
  734. addi r9, r9, 4
  735. addi r8, r8, 4
  736. b 0b
  737. 3:
  738. /* To be certain of avoiding problems with self-modifying code
  739. * execute a serializing instruction here.
  740. */
  741. isync
  742. sync
  743. /* jump to the entry point, usually the setup routine */
  744. mtlr r5
  745. blrl
  746. 1: b 1b
  747. relocate_new_kernel_end:
  748. .globl relocate_new_kernel_size
  749. relocate_new_kernel_size:
  750. .long relocate_new_kernel_end - relocate_new_kernel
  751. #endif