misc_32.S 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  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. * PPC44x port. Copyright (C) 2011, IBM Corporation
  12. * Author: Suzuki Poulose <suzuki@in.ibm.com>
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 2 of the License, or (at your option) any later version.
  18. *
  19. */
  20. #include <linux/sys.h>
  21. #include <asm/unistd.h>
  22. #include <asm/errno.h>
  23. #include <asm/reg.h>
  24. #include <asm/page.h>
  25. #include <asm/cache.h>
  26. #include <asm/cputable.h>
  27. #include <asm/mmu.h>
  28. #include <asm/ppc_asm.h>
  29. #include <asm/thread_info.h>
  30. #include <asm/asm-offsets.h>
  31. #include <asm/processor.h>
  32. #include <asm/kexec.h>
  33. #include <asm/bug.h>
  34. #include <asm/ptrace.h>
  35. .text
  36. /*
  37. * We store the saved ksp_limit in the unused part
  38. * of the STACK_FRAME_OVERHEAD
  39. */
  40. _GLOBAL(call_do_softirq)
  41. mflr r0
  42. stw r0,4(r1)
  43. lwz r10,THREAD+KSP_LIMIT(r2)
  44. addi r11,r3,THREAD_INFO_GAP
  45. stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
  46. mr r1,r3
  47. stw r10,8(r1)
  48. stw r11,THREAD+KSP_LIMIT(r2)
  49. bl __do_softirq
  50. lwz r10,8(r1)
  51. lwz r1,0(r1)
  52. lwz r0,4(r1)
  53. stw r10,THREAD+KSP_LIMIT(r2)
  54. mtlr r0
  55. blr
  56. _GLOBAL(call_do_irq)
  57. mflr r0
  58. stw r0,4(r1)
  59. lwz r10,THREAD+KSP_LIMIT(r2)
  60. addi r11,r3,THREAD_INFO_GAP
  61. stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r4)
  62. mr r1,r4
  63. stw r10,8(r1)
  64. stw r11,THREAD+KSP_LIMIT(r2)
  65. bl __do_irq
  66. lwz r10,8(r1)
  67. lwz r1,0(r1)
  68. lwz r0,4(r1)
  69. stw r10,THREAD+KSP_LIMIT(r2)
  70. mtlr r0
  71. blr
  72. /*
  73. * This returns the high 64 bits of the product of two 64-bit numbers.
  74. */
  75. _GLOBAL(mulhdu)
  76. cmpwi r6,0
  77. cmpwi cr1,r3,0
  78. mr r10,r4
  79. mulhwu r4,r4,r5
  80. beq 1f
  81. mulhwu r0,r10,r6
  82. mullw r7,r10,r5
  83. addc r7,r0,r7
  84. addze r4,r4
  85. 1: beqlr cr1 /* all done if high part of A is 0 */
  86. mr r10,r3
  87. mullw r9,r3,r5
  88. mulhwu r3,r3,r5
  89. beq 2f
  90. mullw r0,r10,r6
  91. mulhwu r8,r10,r6
  92. addc r7,r0,r7
  93. adde r4,r4,r8
  94. addze r3,r3
  95. 2: addc r4,r4,r9
  96. addze r3,r3
  97. blr
  98. /*
  99. * sub_reloc_offset(x) returns x - reloc_offset().
  100. */
  101. _GLOBAL(sub_reloc_offset)
  102. mflr r0
  103. bl 1f
  104. 1: mflr r5
  105. lis r4,1b@ha
  106. addi r4,r4,1b@l
  107. subf r5,r4,r5
  108. subf r3,r5,r3
  109. mtlr r0
  110. blr
  111. /*
  112. * reloc_got2 runs through the .got2 section adding an offset
  113. * to each entry.
  114. */
  115. _GLOBAL(reloc_got2)
  116. mflr r11
  117. lis r7,__got2_start@ha
  118. addi r7,r7,__got2_start@l
  119. lis r8,__got2_end@ha
  120. addi r8,r8,__got2_end@l
  121. subf r8,r7,r8
  122. srwi. r8,r8,2
  123. beqlr
  124. mtctr r8
  125. bl 1f
  126. 1: mflr r0
  127. lis r4,1b@ha
  128. addi r4,r4,1b@l
  129. subf r0,r4,r0
  130. add r7,r0,r7
  131. 2: lwz r0,0(r7)
  132. add r0,r0,r3
  133. stw r0,0(r7)
  134. addi r7,r7,4
  135. bdnz 2b
  136. mtlr r11
  137. blr
  138. /*
  139. * call_setup_cpu - call the setup_cpu function for this cpu
  140. * r3 = data offset, r24 = cpu number
  141. *
  142. * Setup function is called with:
  143. * r3 = data offset
  144. * r4 = ptr to CPU spec (relocated)
  145. */
  146. _GLOBAL(call_setup_cpu)
  147. addis r4,r3,cur_cpu_spec@ha
  148. addi r4,r4,cur_cpu_spec@l
  149. lwz r4,0(r4)
  150. add r4,r4,r3
  151. lwz r5,CPU_SPEC_SETUP(r4)
  152. cmpwi 0,r5,0
  153. add r5,r5,r3
  154. beqlr
  155. mtctr r5
  156. bctr
  157. #if defined(CONFIG_CPU_FREQ_PMAC) && defined(CONFIG_6xx)
  158. /* This gets called by via-pmu.c to switch the PLL selection
  159. * on 750fx CPU. This function should really be moved to some
  160. * other place (as most of the cpufreq code in via-pmu
  161. */
  162. _GLOBAL(low_choose_750fx_pll)
  163. /* Clear MSR:EE */
  164. mfmsr r7
  165. rlwinm r0,r7,0,17,15
  166. mtmsr r0
  167. /* If switching to PLL1, disable HID0:BTIC */
  168. cmplwi cr0,r3,0
  169. beq 1f
  170. mfspr r5,SPRN_HID0
  171. rlwinm r5,r5,0,27,25
  172. sync
  173. mtspr SPRN_HID0,r5
  174. isync
  175. sync
  176. 1:
  177. /* Calc new HID1 value */
  178. mfspr r4,SPRN_HID1 /* Build a HID1:PS bit from parameter */
  179. rlwinm r5,r3,16,15,15 /* Clear out HID1:PS from value read */
  180. rlwinm r4,r4,0,16,14 /* Could have I used rlwimi here ? */
  181. or r4,r4,r5
  182. mtspr SPRN_HID1,r4
  183. /* Store new HID1 image */
  184. CURRENT_THREAD_INFO(r6, r1)
  185. lwz r6,TI_CPU(r6)
  186. slwi r6,r6,2
  187. addis r6,r6,nap_save_hid1@ha
  188. stw r4,nap_save_hid1@l(r6)
  189. /* If switching to PLL0, enable HID0:BTIC */
  190. cmplwi cr0,r3,0
  191. bne 1f
  192. mfspr r5,SPRN_HID0
  193. ori r5,r5,HID0_BTIC
  194. sync
  195. mtspr SPRN_HID0,r5
  196. isync
  197. sync
  198. 1:
  199. /* Return */
  200. mtmsr r7
  201. blr
  202. _GLOBAL(low_choose_7447a_dfs)
  203. /* Clear MSR:EE */
  204. mfmsr r7
  205. rlwinm r0,r7,0,17,15
  206. mtmsr r0
  207. /* Calc new HID1 value */
  208. mfspr r4,SPRN_HID1
  209. insrwi r4,r3,1,9 /* insert parameter into bit 9 */
  210. sync
  211. mtspr SPRN_HID1,r4
  212. sync
  213. isync
  214. /* Return */
  215. mtmsr r7
  216. blr
  217. #endif /* CONFIG_CPU_FREQ_PMAC && CONFIG_6xx */
  218. /*
  219. * complement mask on the msr then "or" some values on.
  220. * _nmask_and_or_msr(nmask, value_to_or)
  221. */
  222. _GLOBAL(_nmask_and_or_msr)
  223. mfmsr r0 /* Get current msr */
  224. andc r0,r0,r3 /* And off the bits set in r3 (first parm) */
  225. or r0,r0,r4 /* Or on the bits in r4 (second parm) */
  226. SYNC /* Some chip revs have problems here... */
  227. mtmsr r0 /* Update machine state */
  228. isync
  229. blr /* Done */
  230. #ifdef CONFIG_40x
  231. /*
  232. * Do an IO access in real mode
  233. */
  234. _GLOBAL(real_readb)
  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. lbz r3,0(r3)
  243. sync
  244. mtmsr r7
  245. sync
  246. isync
  247. blr
  248. /*
  249. * Do an IO access in real mode
  250. */
  251. _GLOBAL(real_writeb)
  252. mfmsr r7
  253. ori r0,r7,MSR_DR
  254. xori r0,r0,MSR_DR
  255. sync
  256. mtmsr r0
  257. sync
  258. isync
  259. stb r3,0(r4)
  260. sync
  261. mtmsr r7
  262. sync
  263. isync
  264. blr
  265. #endif /* CONFIG_40x */
  266. /*
  267. * Flush instruction cache.
  268. * This is a no-op on the 601.
  269. */
  270. _GLOBAL(flush_instruction_cache)
  271. #if defined(CONFIG_8xx)
  272. isync
  273. lis r5, IDC_INVALL@h
  274. mtspr SPRN_IC_CST, r5
  275. #elif defined(CONFIG_4xx)
  276. #ifdef CONFIG_403GCX
  277. li r3, 512
  278. mtctr r3
  279. lis r4, KERNELBASE@h
  280. 1: iccci 0, r4
  281. addi r4, r4, 16
  282. bdnz 1b
  283. #else
  284. lis r3, KERNELBASE@h
  285. iccci 0,r3
  286. #endif
  287. #elif CONFIG_FSL_BOOKE
  288. BEGIN_FTR_SECTION
  289. mfspr r3,SPRN_L1CSR0
  290. ori r3,r3,L1CSR0_CFI|L1CSR0_CLFC
  291. /* msync; isync recommended here */
  292. mtspr SPRN_L1CSR0,r3
  293. isync
  294. blr
  295. END_FTR_SECTION_IFSET(CPU_FTR_UNIFIED_ID_CACHE)
  296. mfspr r3,SPRN_L1CSR1
  297. ori r3,r3,L1CSR1_ICFI|L1CSR1_ICLFR
  298. mtspr SPRN_L1CSR1,r3
  299. #else
  300. mfspr r3,SPRN_PVR
  301. rlwinm r3,r3,16,16,31
  302. cmpwi 0,r3,1
  303. beqlr /* for 601, do nothing */
  304. /* 603/604 processor - use invalidate-all bit in HID0 */
  305. mfspr r3,SPRN_HID0
  306. ori r3,r3,HID0_ICFI
  307. mtspr SPRN_HID0,r3
  308. #endif /* CONFIG_8xx/4xx */
  309. isync
  310. blr
  311. /*
  312. * Write any modified data cache blocks out to memory
  313. * and invalidate the corresponding instruction cache blocks.
  314. * This is a no-op on the 601.
  315. *
  316. * flush_icache_range(unsigned long start, unsigned long stop)
  317. */
  318. _KPROBE(flush_icache_range)
  319. BEGIN_FTR_SECTION
  320. PURGE_PREFETCHED_INS
  321. blr /* for 601, do nothing */
  322. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  323. li r5,L1_CACHE_BYTES-1
  324. andc r3,r3,r5
  325. subf r4,r3,r4
  326. add r4,r4,r5
  327. srwi. r4,r4,L1_CACHE_SHIFT
  328. beqlr
  329. mtctr r4
  330. mr r6,r3
  331. 1: dcbst 0,r3
  332. addi r3,r3,L1_CACHE_BYTES
  333. bdnz 1b
  334. sync /* wait for dcbst's to get to ram */
  335. #ifndef CONFIG_44x
  336. mtctr r4
  337. 2: icbi 0,r6
  338. addi r6,r6,L1_CACHE_BYTES
  339. bdnz 2b
  340. #else
  341. /* Flash invalidate on 44x because we are passed kmapped addresses and
  342. this doesn't work for userspace pages due to the virtually tagged
  343. icache. Sigh. */
  344. iccci 0, r0
  345. #endif
  346. sync /* additional sync needed on g4 */
  347. isync
  348. blr
  349. /*
  350. * Write any modified data cache blocks out to memory.
  351. * Does not invalidate the corresponding cache lines (especially for
  352. * any corresponding instruction cache).
  353. *
  354. * clean_dcache_range(unsigned long start, unsigned long stop)
  355. */
  356. _GLOBAL(clean_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: dcbst 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. * Write any modified data cache blocks out to memory and invalidate them.
  371. * Does not invalidate the corresponding instruction cache blocks.
  372. *
  373. * flush_dcache_range(unsigned long start, unsigned long stop)
  374. */
  375. _GLOBAL(flush_dcache_range)
  376. li r5,L1_CACHE_BYTES-1
  377. andc r3,r3,r5
  378. subf r4,r3,r4
  379. add r4,r4,r5
  380. srwi. r4,r4,L1_CACHE_SHIFT
  381. beqlr
  382. mtctr r4
  383. 1: dcbf 0,r3
  384. addi r3,r3,L1_CACHE_BYTES
  385. bdnz 1b
  386. sync /* wait for dcbst's to get to ram */
  387. blr
  388. /*
  389. * Like above, but invalidate the D-cache. This is used by the 8xx
  390. * to invalidate the cache so the PPC core doesn't get stale data
  391. * from the CPM (no cache snooping here :-).
  392. *
  393. * invalidate_dcache_range(unsigned long start, unsigned long stop)
  394. */
  395. _GLOBAL(invalidate_dcache_range)
  396. li r5,L1_CACHE_BYTES-1
  397. andc r3,r3,r5
  398. subf r4,r3,r4
  399. add r4,r4,r5
  400. srwi. r4,r4,L1_CACHE_SHIFT
  401. beqlr
  402. mtctr r4
  403. 1: dcbi 0,r3
  404. addi r3,r3,L1_CACHE_BYTES
  405. bdnz 1b
  406. sync /* wait for dcbi's to get to ram */
  407. blr
  408. /*
  409. * Flush a particular page from the data cache to RAM.
  410. * Note: this is necessary because the instruction cache does *not*
  411. * snoop from the data cache.
  412. * This is a no-op on the 601 which has a unified cache.
  413. *
  414. * void __flush_dcache_icache(void *page)
  415. */
  416. _GLOBAL(__flush_dcache_icache)
  417. BEGIN_FTR_SECTION
  418. PURGE_PREFETCHED_INS
  419. blr
  420. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  421. rlwinm r3,r3,0,0,31-PAGE_SHIFT /* Get page base address */
  422. li r4,PAGE_SIZE/L1_CACHE_BYTES /* Number of lines in a page */
  423. mtctr r4
  424. mr r6,r3
  425. 0: dcbst 0,r3 /* Write line to ram */
  426. addi r3,r3,L1_CACHE_BYTES
  427. bdnz 0b
  428. sync
  429. #ifdef CONFIG_44x
  430. /* We don't flush the icache on 44x. Those have a virtual icache
  431. * and we don't have access to the virtual address here (it's
  432. * not the page vaddr but where it's mapped in user space). The
  433. * flushing of the icache on these is handled elsewhere, when
  434. * a change in the address space occurs, before returning to
  435. * user space
  436. */
  437. BEGIN_MMU_FTR_SECTION
  438. blr
  439. END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_44x)
  440. #endif /* CONFIG_44x */
  441. mtctr r4
  442. 1: icbi 0,r6
  443. addi r6,r6,L1_CACHE_BYTES
  444. bdnz 1b
  445. sync
  446. isync
  447. blr
  448. #ifndef CONFIG_BOOKE
  449. /*
  450. * Flush a particular page from the data cache to RAM, identified
  451. * by its physical address. We turn off the MMU so we can just use
  452. * the physical address (this may be a highmem page without a kernel
  453. * mapping).
  454. *
  455. * void __flush_dcache_icache_phys(unsigned long physaddr)
  456. */
  457. _GLOBAL(__flush_dcache_icache_phys)
  458. BEGIN_FTR_SECTION
  459. PURGE_PREFETCHED_INS
  460. blr /* for 601, do nothing */
  461. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  462. mfmsr r10
  463. rlwinm r0,r10,0,28,26 /* clear DR */
  464. mtmsr r0
  465. isync
  466. rlwinm r3,r3,0,0,31-PAGE_SHIFT /* Get page base address */
  467. li r4,PAGE_SIZE/L1_CACHE_BYTES /* Number of lines in a page */
  468. mtctr r4
  469. mr r6,r3
  470. 0: dcbst 0,r3 /* Write line to ram */
  471. addi r3,r3,L1_CACHE_BYTES
  472. bdnz 0b
  473. sync
  474. mtctr r4
  475. 1: icbi 0,r6
  476. addi r6,r6,L1_CACHE_BYTES
  477. bdnz 1b
  478. sync
  479. mtmsr r10 /* restore DR */
  480. isync
  481. blr
  482. #endif /* CONFIG_BOOKE */
  483. /*
  484. * Clear pages using the dcbz instruction, which doesn't cause any
  485. * memory traffic (except to write out any cache lines which get
  486. * displaced). This only works on cacheable memory.
  487. *
  488. * void clear_pages(void *page, int order) ;
  489. */
  490. _GLOBAL(clear_pages)
  491. li r0,PAGE_SIZE/L1_CACHE_BYTES
  492. slw r0,r0,r4
  493. mtctr r0
  494. 1: dcbz 0,r3
  495. addi r3,r3,L1_CACHE_BYTES
  496. bdnz 1b
  497. blr
  498. /*
  499. * Copy a whole page. We use the dcbz instruction on the destination
  500. * to reduce memory traffic (it eliminates the unnecessary reads of
  501. * the destination into cache). This requires that the destination
  502. * is cacheable.
  503. */
  504. #define COPY_16_BYTES \
  505. lwz r6,4(r4); \
  506. lwz r7,8(r4); \
  507. lwz r8,12(r4); \
  508. lwzu r9,16(r4); \
  509. stw r6,4(r3); \
  510. stw r7,8(r3); \
  511. stw r8,12(r3); \
  512. stwu r9,16(r3)
  513. _GLOBAL(copy_page)
  514. addi r3,r3,-4
  515. addi r4,r4,-4
  516. li r5,4
  517. #if MAX_COPY_PREFETCH > 1
  518. li r0,MAX_COPY_PREFETCH
  519. li r11,4
  520. mtctr r0
  521. 11: dcbt r11,r4
  522. addi r11,r11,L1_CACHE_BYTES
  523. bdnz 11b
  524. #else /* MAX_COPY_PREFETCH == 1 */
  525. dcbt r5,r4
  526. li r11,L1_CACHE_BYTES+4
  527. #endif /* MAX_COPY_PREFETCH */
  528. li r0,PAGE_SIZE/L1_CACHE_BYTES - MAX_COPY_PREFETCH
  529. crclr 4*cr0+eq
  530. 2:
  531. mtctr r0
  532. 1:
  533. dcbt r11,r4
  534. dcbz r5,r3
  535. COPY_16_BYTES
  536. #if L1_CACHE_BYTES >= 32
  537. COPY_16_BYTES
  538. #if L1_CACHE_BYTES >= 64
  539. COPY_16_BYTES
  540. COPY_16_BYTES
  541. #if L1_CACHE_BYTES >= 128
  542. COPY_16_BYTES
  543. COPY_16_BYTES
  544. COPY_16_BYTES
  545. COPY_16_BYTES
  546. #endif
  547. #endif
  548. #endif
  549. bdnz 1b
  550. beqlr
  551. crnot 4*cr0+eq,4*cr0+eq
  552. li r0,MAX_COPY_PREFETCH
  553. li r11,4
  554. b 2b
  555. /*
  556. * void atomic_clear_mask(atomic_t mask, atomic_t *addr)
  557. * void atomic_set_mask(atomic_t mask, atomic_t *addr);
  558. */
  559. _GLOBAL(atomic_clear_mask)
  560. 10: lwarx r5,0,r4
  561. andc r5,r5,r3
  562. PPC405_ERR77(0,r4)
  563. stwcx. r5,0,r4
  564. bne- 10b
  565. blr
  566. _GLOBAL(atomic_set_mask)
  567. 10: lwarx r5,0,r4
  568. or r5,r5,r3
  569. PPC405_ERR77(0,r4)
  570. stwcx. r5,0,r4
  571. bne- 10b
  572. blr
  573. /*
  574. * Extended precision shifts.
  575. *
  576. * Updated to be valid for shift counts from 0 to 63 inclusive.
  577. * -- Gabriel
  578. *
  579. * R3/R4 has 64 bit value
  580. * R5 has shift count
  581. * result in R3/R4
  582. *
  583. * ashrdi3: arithmetic right shift (sign propagation)
  584. * lshrdi3: logical right shift
  585. * ashldi3: left shift
  586. */
  587. _GLOBAL(__ashrdi3)
  588. subfic r6,r5,32
  589. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  590. addi r7,r5,32 # could be xori, or addi with -32
  591. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  592. rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0
  593. sraw r7,r3,r7 # t2 = MSW >> (count-32)
  594. or r4,r4,r6 # LSW |= t1
  595. slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2
  596. sraw r3,r3,r5 # MSW = MSW >> count
  597. or r4,r4,r7 # LSW |= t2
  598. blr
  599. _GLOBAL(__ashldi3)
  600. subfic r6,r5,32
  601. slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count
  602. addi r7,r5,32 # could be xori, or addi with -32
  603. srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count)
  604. slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32)
  605. or r3,r3,r6 # MSW |= t1
  606. slw r4,r4,r5 # LSW = LSW << count
  607. or r3,r3,r7 # MSW |= t2
  608. blr
  609. _GLOBAL(__lshrdi3)
  610. subfic r6,r5,32
  611. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  612. addi r7,r5,32 # could be xori, or addi with -32
  613. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  614. srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32)
  615. or r4,r4,r6 # LSW |= t1
  616. srw r3,r3,r5 # MSW = MSW >> count
  617. or r4,r4,r7 # LSW |= t2
  618. blr
  619. /*
  620. * 64-bit comparison: __cmpdi2(s64 a, s64 b)
  621. * Returns 0 if a < b, 1 if a == b, 2 if a > b.
  622. */
  623. _GLOBAL(__cmpdi2)
  624. cmpw r3,r5
  625. li r3,1
  626. bne 1f
  627. cmplw r4,r6
  628. beqlr
  629. 1: li r3,0
  630. bltlr
  631. li r3,2
  632. blr
  633. /*
  634. * 64-bit comparison: __ucmpdi2(u64 a, u64 b)
  635. * Returns 0 if a < b, 1 if a == b, 2 if a > b.
  636. */
  637. _GLOBAL(__ucmpdi2)
  638. cmplw r3,r5
  639. li r3,1
  640. bne 1f
  641. cmplw r4,r6
  642. beqlr
  643. 1: li r3,0
  644. bltlr
  645. li r3,2
  646. blr
  647. _GLOBAL(__bswapdi2)
  648. rotlwi r9,r4,8
  649. rotlwi r10,r3,8
  650. rlwimi r9,r4,24,0,7
  651. rlwimi r10,r3,24,0,7
  652. rlwimi r9,r4,24,16,23
  653. rlwimi r10,r3,24,16,23
  654. mr r3,r9
  655. mr r4,r10
  656. blr
  657. _GLOBAL(abs)
  658. srawi r4,r3,31
  659. xor r3,r3,r4
  660. sub r3,r3,r4
  661. blr
  662. #ifdef CONFIG_SMP
  663. _GLOBAL(start_secondary_resume)
  664. /* Reset stack */
  665. CURRENT_THREAD_INFO(r1, r1)
  666. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  667. li r3,0
  668. stw r3,0(r1) /* Zero the stack frame pointer */
  669. bl start_secondary
  670. b .
  671. #endif /* CONFIG_SMP */
  672. /*
  673. * This routine is just here to keep GCC happy - sigh...
  674. */
  675. _GLOBAL(__main)
  676. blr
  677. #ifdef CONFIG_KEXEC
  678. /*
  679. * Must be relocatable PIC code callable as a C function.
  680. */
  681. .globl relocate_new_kernel
  682. relocate_new_kernel:
  683. /* r3 = page_list */
  684. /* r4 = reboot_code_buffer */
  685. /* r5 = start_address */
  686. #ifdef CONFIG_FSL_BOOKE
  687. mr r29, r3
  688. mr r30, r4
  689. mr r31, r5
  690. #define ENTRY_MAPPING_KEXEC_SETUP
  691. #include "fsl_booke_entry_mapping.S"
  692. #undef ENTRY_MAPPING_KEXEC_SETUP
  693. mr r3, r29
  694. mr r4, r30
  695. mr r5, r31
  696. li r0, 0
  697. #elif defined(CONFIG_44x)
  698. /* Save our parameters */
  699. mr r29, r3
  700. mr r30, r4
  701. mr r31, r5
  702. #ifdef CONFIG_PPC_47x
  703. /* Check for 47x cores */
  704. mfspr r3,SPRN_PVR
  705. srwi r3,r3,16
  706. cmplwi cr0,r3,PVR_476@h
  707. beq setup_map_47x
  708. cmplwi cr0,r3,PVR_476_ISS@h
  709. beq setup_map_47x
  710. #endif /* CONFIG_PPC_47x */
  711. /*
  712. * Code for setting up 1:1 mapping for PPC440x for KEXEC
  713. *
  714. * We cannot switch off the MMU on PPC44x.
  715. * So we:
  716. * 1) Invalidate all the mappings except the one we are running from.
  717. * 2) Create a tmp mapping for our code in the other address space(TS) and
  718. * jump to it. Invalidate the entry we started in.
  719. * 3) Create a 1:1 mapping for 0-2GiB in chunks of 256M in original TS.
  720. * 4) Jump to the 1:1 mapping in original TS.
  721. * 5) Invalidate the tmp mapping.
  722. *
  723. * - Based on the kexec support code for FSL BookE
  724. *
  725. */
  726. /*
  727. * Load the PID with kernel PID (0).
  728. * Also load our MSR_IS and TID to MMUCR for TLB search.
  729. */
  730. li r3, 0
  731. mtspr SPRN_PID, r3
  732. mfmsr r4
  733. andi. r4,r4,MSR_IS@l
  734. beq wmmucr
  735. oris r3,r3,PPC44x_MMUCR_STS@h
  736. wmmucr:
  737. mtspr SPRN_MMUCR,r3
  738. sync
  739. /*
  740. * Invalidate all the TLB entries except the current entry
  741. * where we are running from
  742. */
  743. bl 0f /* Find our address */
  744. 0: mflr r5 /* Make it accessible */
  745. tlbsx r23,0,r5 /* Find entry we are in */
  746. li r4,0 /* Start at TLB entry 0 */
  747. li r3,0 /* Set PAGEID inval value */
  748. 1: cmpw r23,r4 /* Is this our entry? */
  749. beq skip /* If so, skip the inval */
  750. tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */
  751. skip:
  752. addi r4,r4,1 /* Increment */
  753. cmpwi r4,64 /* Are we done? */
  754. bne 1b /* If not, repeat */
  755. isync
  756. /* Create a temp mapping and jump to it */
  757. andi. r6, r23, 1 /* Find the index to use */
  758. addi r24, r6, 1 /* r24 will contain 1 or 2 */
  759. mfmsr r9 /* get the MSR */
  760. rlwinm r5, r9, 27, 31, 31 /* Extract the MSR[IS] */
  761. xori r7, r5, 1 /* Use the other address space */
  762. /* Read the current mapping entries */
  763. tlbre r3, r23, PPC44x_TLB_PAGEID
  764. tlbre r4, r23, PPC44x_TLB_XLAT
  765. tlbre r5, r23, PPC44x_TLB_ATTRIB
  766. /* Save our current XLAT entry */
  767. mr r25, r4
  768. /* Extract the TLB PageSize */
  769. li r10, 1 /* r10 will hold PageSize */
  770. rlwinm r11, r3, 0, 24, 27 /* bits 24-27 */
  771. /* XXX: As of now we use 256M, 4K pages */
  772. cmpwi r11, PPC44x_TLB_256M
  773. bne tlb_4k
  774. rotlwi r10, r10, 28 /* r10 = 256M */
  775. b write_out
  776. tlb_4k:
  777. cmpwi r11, PPC44x_TLB_4K
  778. bne default
  779. rotlwi r10, r10, 12 /* r10 = 4K */
  780. b write_out
  781. default:
  782. rotlwi r10, r10, 10 /* r10 = 1K */
  783. write_out:
  784. /*
  785. * Write out the tmp 1:1 mapping for this code in other address space
  786. * Fixup EPN = RPN , TS=other address space
  787. */
  788. insrwi r3, r7, 1, 23 /* Bit 23 is TS for PAGEID field */
  789. /* Write out the tmp mapping entries */
  790. tlbwe r3, r24, PPC44x_TLB_PAGEID
  791. tlbwe r4, r24, PPC44x_TLB_XLAT
  792. tlbwe r5, r24, PPC44x_TLB_ATTRIB
  793. subi r11, r10, 1 /* PageOffset Mask = PageSize - 1 */
  794. not r10, r11 /* Mask for PageNum */
  795. /* Switch to other address space in MSR */
  796. insrwi r9, r7, 1, 26 /* Set MSR[IS] = r7 */
  797. bl 1f
  798. 1: mflr r8
  799. addi r8, r8, (2f-1b) /* Find the target offset */
  800. /* Jump to the tmp mapping */
  801. mtspr SPRN_SRR0, r8
  802. mtspr SPRN_SRR1, r9
  803. rfi
  804. 2:
  805. /* Invalidate the entry we were executing from */
  806. li r3, 0
  807. tlbwe r3, r23, PPC44x_TLB_PAGEID
  808. /* attribute fields. rwx for SUPERVISOR mode */
  809. li r5, 0
  810. ori r5, r5, (PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G)
  811. /* Create 1:1 mapping in 256M pages */
  812. xori r7, r7, 1 /* Revert back to Original TS */
  813. li r8, 0 /* PageNumber */
  814. li r6, 3 /* TLB Index, start at 3 */
  815. next_tlb:
  816. rotlwi r3, r8, 28 /* Create EPN (bits 0-3) */
  817. mr r4, r3 /* RPN = EPN */
  818. ori r3, r3, (PPC44x_TLB_VALID | PPC44x_TLB_256M) /* SIZE = 256M, Valid */
  819. insrwi r3, r7, 1, 23 /* Set TS from r7 */
  820. tlbwe r3, r6, PPC44x_TLB_PAGEID /* PageID field : EPN, V, SIZE */
  821. tlbwe r4, r6, PPC44x_TLB_XLAT /* Address translation : RPN */
  822. tlbwe r5, r6, PPC44x_TLB_ATTRIB /* Attributes */
  823. addi r8, r8, 1 /* Increment PN */
  824. addi r6, r6, 1 /* Increment TLB Index */
  825. cmpwi r8, 8 /* Are we done ? */
  826. bne next_tlb
  827. isync
  828. /* Jump to the new mapping 1:1 */
  829. li r9,0
  830. insrwi r9, r7, 1, 26 /* Set MSR[IS] = r7 */
  831. bl 1f
  832. 1: mflr r8
  833. and r8, r8, r11 /* Get our offset within page */
  834. addi r8, r8, (2f-1b)
  835. and r5, r25, r10 /* Get our target PageNum */
  836. or r8, r8, r5 /* Target jump address */
  837. mtspr SPRN_SRR0, r8
  838. mtspr SPRN_SRR1, r9
  839. rfi
  840. 2:
  841. /* Invalidate the tmp entry we used */
  842. li r3, 0
  843. tlbwe r3, r24, PPC44x_TLB_PAGEID
  844. sync
  845. b ppc44x_map_done
  846. #ifdef CONFIG_PPC_47x
  847. /* 1:1 mapping for 47x */
  848. setup_map_47x:
  849. /*
  850. * Load the kernel pid (0) to PID and also to MMUCR[TID].
  851. * Also set the MSR IS->MMUCR STS
  852. */
  853. li r3, 0
  854. mtspr SPRN_PID, r3 /* Set PID */
  855. mfmsr r4 /* Get MSR */
  856. andi. r4, r4, MSR_IS@l /* TS=1? */
  857. beq 1f /* If not, leave STS=0 */
  858. oris r3, r3, PPC47x_MMUCR_STS@h /* Set STS=1 */
  859. 1: mtspr SPRN_MMUCR, r3 /* Put MMUCR */
  860. sync
  861. /* Find the entry we are running from */
  862. bl 2f
  863. 2: mflr r23
  864. tlbsx r23, 0, r23
  865. tlbre r24, r23, 0 /* TLB Word 0 */
  866. tlbre r25, r23, 1 /* TLB Word 1 */
  867. tlbre r26, r23, 2 /* TLB Word 2 */
  868. /*
  869. * Invalidates all the tlb entries by writing to 256 RPNs(r4)
  870. * of 4k page size in all 4 ways (0-3 in r3).
  871. * This would invalidate the entire UTLB including the one we are
  872. * running from. However the shadow TLB entries would help us
  873. * to continue the execution, until we flush them (rfi/isync).
  874. */
  875. addis r3, 0, 0x8000 /* specify the way */
  876. addi r4, 0, 0 /* TLB Word0 = (EPN=0, VALID = 0) */
  877. addi r5, 0, 0
  878. b clear_utlb_entry
  879. /* Align the loop to speed things up. from head_44x.S */
  880. .align 6
  881. clear_utlb_entry:
  882. tlbwe r4, r3, 0
  883. tlbwe r5, r3, 1
  884. tlbwe r5, r3, 2
  885. addis r3, r3, 0x2000 /* Increment the way */
  886. cmpwi r3, 0
  887. bne clear_utlb_entry
  888. addis r3, 0, 0x8000
  889. addis r4, r4, 0x100 /* Increment the EPN */
  890. cmpwi r4, 0
  891. bne clear_utlb_entry
  892. /* Create the entries in the other address space */
  893. mfmsr r5
  894. rlwinm r7, r5, 27, 31, 31 /* Get the TS (Bit 26) from MSR */
  895. xori r7, r7, 1 /* r7 = !TS */
  896. insrwi r24, r7, 1, 21 /* Change the TS in the saved TLB word 0 */
  897. /*
  898. * write out the TLB entries for the tmp mapping
  899. * Use way '0' so that we could easily invalidate it later.
  900. */
  901. lis r3, 0x8000 /* Way '0' */
  902. tlbwe r24, r3, 0
  903. tlbwe r25, r3, 1
  904. tlbwe r26, r3, 2
  905. /* Update the msr to the new TS */
  906. insrwi r5, r7, 1, 26
  907. bl 1f
  908. 1: mflr r6
  909. addi r6, r6, (2f-1b)
  910. mtspr SPRN_SRR0, r6
  911. mtspr SPRN_SRR1, r5
  912. rfi
  913. /*
  914. * Now we are in the tmp address space.
  915. * Create a 1:1 mapping for 0-2GiB in the original TS.
  916. */
  917. 2:
  918. li r3, 0
  919. li r4, 0 /* TLB Word 0 */
  920. li r5, 0 /* TLB Word 1 */
  921. li r6, 0
  922. ori r6, r6, PPC47x_TLB2_S_RWX /* TLB word 2 */
  923. li r8, 0 /* PageIndex */
  924. xori r7, r7, 1 /* revert back to original TS */
  925. write_utlb:
  926. rotlwi r5, r8, 28 /* RPN = PageIndex * 256M */
  927. /* ERPN = 0 as we don't use memory above 2G */
  928. mr r4, r5 /* EPN = RPN */
  929. ori r4, r4, (PPC47x_TLB0_VALID | PPC47x_TLB0_256M)
  930. insrwi r4, r7, 1, 21 /* Insert the TS to Word 0 */
  931. tlbwe r4, r3, 0 /* Write out the entries */
  932. tlbwe r5, r3, 1
  933. tlbwe r6, r3, 2
  934. addi r8, r8, 1
  935. cmpwi r8, 8 /* Have we completed ? */
  936. bne write_utlb
  937. /* make sure we complete the TLB write up */
  938. isync
  939. /*
  940. * Prepare to jump to the 1:1 mapping.
  941. * 1) Extract page size of the tmp mapping
  942. * DSIZ = TLB_Word0[22:27]
  943. * 2) Calculate the physical address of the address
  944. * to jump to.
  945. */
  946. rlwinm r10, r24, 0, 22, 27
  947. cmpwi r10, PPC47x_TLB0_4K
  948. bne 0f
  949. li r10, 0x1000 /* r10 = 4k */
  950. bl 1f
  951. 0:
  952. /* Defaults to 256M */
  953. lis r10, 0x1000
  954. bl 1f
  955. 1: mflr r4
  956. addi r4, r4, (2f-1b) /* virtual address of 2f */
  957. subi r11, r10, 1 /* offsetmask = Pagesize - 1 */
  958. not r10, r11 /* Pagemask = ~(offsetmask) */
  959. and r5, r25, r10 /* Physical page */
  960. and r6, r4, r11 /* offset within the current page */
  961. or r5, r5, r6 /* Physical address for 2f */
  962. /* Switch the TS in MSR to the original one */
  963. mfmsr r8
  964. insrwi r8, r7, 1, 26
  965. mtspr SPRN_SRR1, r8
  966. mtspr SPRN_SRR0, r5
  967. rfi
  968. 2:
  969. /* Invalidate the tmp mapping */
  970. lis r3, 0x8000 /* Way '0' */
  971. clrrwi r24, r24, 12 /* Clear the valid bit */
  972. tlbwe r24, r3, 0
  973. tlbwe r25, r3, 1
  974. tlbwe r26, r3, 2
  975. /* Make sure we complete the TLB write and flush the shadow TLB */
  976. isync
  977. #endif
  978. ppc44x_map_done:
  979. /* Restore the parameters */
  980. mr r3, r29
  981. mr r4, r30
  982. mr r5, r31
  983. li r0, 0
  984. #else
  985. li r0, 0
  986. /*
  987. * Set Machine Status Register to a known status,
  988. * switch the MMU off and jump to 1: in a single step.
  989. */
  990. mr r8, r0
  991. ori r8, r8, MSR_RI|MSR_ME
  992. mtspr SPRN_SRR1, r8
  993. addi r8, r4, 1f - relocate_new_kernel
  994. mtspr SPRN_SRR0, r8
  995. sync
  996. rfi
  997. 1:
  998. #endif
  999. /* from this point address translation is turned off */
  1000. /* and interrupts are disabled */
  1001. /* set a new stack at the bottom of our page... */
  1002. /* (not really needed now) */
  1003. addi r1, r4, KEXEC_CONTROL_PAGE_SIZE - 8 /* for LR Save+Back Chain */
  1004. stw r0, 0(r1)
  1005. /* Do the copies */
  1006. li r6, 0 /* checksum */
  1007. mr r0, r3
  1008. b 1f
  1009. 0: /* top, read another word for the indirection page */
  1010. lwzu r0, 4(r3)
  1011. 1:
  1012. /* is it a destination page? (r8) */
  1013. rlwinm. r7, r0, 0, 31, 31 /* IND_DESTINATION (1<<0) */
  1014. beq 2f
  1015. rlwinm r8, r0, 0, 0, 19 /* clear kexec flags, page align */
  1016. b 0b
  1017. 2: /* is it an indirection page? (r3) */
  1018. rlwinm. r7, r0, 0, 30, 30 /* IND_INDIRECTION (1<<1) */
  1019. beq 2f
  1020. rlwinm r3, r0, 0, 0, 19 /* clear kexec flags, page align */
  1021. subi r3, r3, 4
  1022. b 0b
  1023. 2: /* are we done? */
  1024. rlwinm. r7, r0, 0, 29, 29 /* IND_DONE (1<<2) */
  1025. beq 2f
  1026. b 3f
  1027. 2: /* is it a source page? (r9) */
  1028. rlwinm. r7, r0, 0, 28, 28 /* IND_SOURCE (1<<3) */
  1029. beq 0b
  1030. rlwinm r9, r0, 0, 0, 19 /* clear kexec flags, page align */
  1031. li r7, PAGE_SIZE / 4
  1032. mtctr r7
  1033. subi r9, r9, 4
  1034. subi r8, r8, 4
  1035. 9:
  1036. lwzu r0, 4(r9) /* do the copy */
  1037. xor r6, r6, r0
  1038. stwu r0, 4(r8)
  1039. dcbst 0, r8
  1040. sync
  1041. icbi 0, r8
  1042. bdnz 9b
  1043. addi r9, r9, 4
  1044. addi r8, r8, 4
  1045. b 0b
  1046. 3:
  1047. /* To be certain of avoiding problems with self-modifying code
  1048. * execute a serializing instruction here.
  1049. */
  1050. isync
  1051. sync
  1052. mfspr r3, SPRN_PIR /* current core we are running on */
  1053. mr r4, r5 /* load physical address of chunk called */
  1054. /* jump to the entry point, usually the setup routine */
  1055. mtlr r5
  1056. blrl
  1057. 1: b 1b
  1058. relocate_new_kernel_end:
  1059. .globl relocate_new_kernel_size
  1060. relocate_new_kernel_size:
  1061. .long relocate_new_kernel_end - relocate_new_kernel
  1062. #endif