misc_32.S 17 KB

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