misc_32.S 17 KB

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