misc_32.S 25 KB

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