misc_32.S 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  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. isync
  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. blr
  419. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  420. rlwinm r3,r3,0,0,31-PAGE_SHIFT /* Get page base address */
  421. li r4,PAGE_SIZE/L1_CACHE_BYTES /* Number of lines in a page */
  422. mtctr r4
  423. mr r6,r3
  424. 0: dcbst 0,r3 /* Write line to ram */
  425. addi r3,r3,L1_CACHE_BYTES
  426. bdnz 0b
  427. sync
  428. #ifdef CONFIG_44x
  429. /* We don't flush the icache on 44x. Those have a virtual icache
  430. * and we don't have access to the virtual address here (it's
  431. * not the page vaddr but where it's mapped in user space). The
  432. * flushing of the icache on these is handled elsewhere, when
  433. * a change in the address space occurs, before returning to
  434. * user space
  435. */
  436. BEGIN_MMU_FTR_SECTION
  437. blr
  438. END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_44x)
  439. #endif /* CONFIG_44x */
  440. mtctr r4
  441. 1: icbi 0,r6
  442. addi r6,r6,L1_CACHE_BYTES
  443. bdnz 1b
  444. sync
  445. isync
  446. blr
  447. #ifndef CONFIG_BOOKE
  448. /*
  449. * Flush a particular page from the data cache to RAM, identified
  450. * by its physical address. We turn off the MMU so we can just use
  451. * the physical address (this may be a highmem page without a kernel
  452. * mapping).
  453. *
  454. * void __flush_dcache_icache_phys(unsigned long physaddr)
  455. */
  456. _GLOBAL(__flush_dcache_icache_phys)
  457. BEGIN_FTR_SECTION
  458. blr /* for 601, do nothing */
  459. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  460. mfmsr r10
  461. rlwinm r0,r10,0,28,26 /* clear DR */
  462. mtmsr r0
  463. isync
  464. rlwinm r3,r3,0,0,31-PAGE_SHIFT /* Get page base address */
  465. li r4,PAGE_SIZE/L1_CACHE_BYTES /* Number of lines in a page */
  466. mtctr r4
  467. mr r6,r3
  468. 0: dcbst 0,r3 /* Write line to ram */
  469. addi r3,r3,L1_CACHE_BYTES
  470. bdnz 0b
  471. sync
  472. mtctr r4
  473. 1: icbi 0,r6
  474. addi r6,r6,L1_CACHE_BYTES
  475. bdnz 1b
  476. sync
  477. mtmsr r10 /* restore DR */
  478. isync
  479. blr
  480. #endif /* CONFIG_BOOKE */
  481. /*
  482. * Clear pages using the dcbz instruction, which doesn't cause any
  483. * memory traffic (except to write out any cache lines which get
  484. * displaced). This only works on cacheable memory.
  485. *
  486. * void clear_pages(void *page, int order) ;
  487. */
  488. _GLOBAL(clear_pages)
  489. li r0,PAGE_SIZE/L1_CACHE_BYTES
  490. slw r0,r0,r4
  491. mtctr r0
  492. 1: dcbz 0,r3
  493. addi r3,r3,L1_CACHE_BYTES
  494. bdnz 1b
  495. blr
  496. /*
  497. * Copy a whole page. We use the dcbz instruction on the destination
  498. * to reduce memory traffic (it eliminates the unnecessary reads of
  499. * the destination into cache). This requires that the destination
  500. * is cacheable.
  501. */
  502. #define COPY_16_BYTES \
  503. lwz r6,4(r4); \
  504. lwz r7,8(r4); \
  505. lwz r8,12(r4); \
  506. lwzu r9,16(r4); \
  507. stw r6,4(r3); \
  508. stw r7,8(r3); \
  509. stw r8,12(r3); \
  510. stwu r9,16(r3)
  511. _GLOBAL(copy_page)
  512. addi r3,r3,-4
  513. addi r4,r4,-4
  514. li r5,4
  515. #if MAX_COPY_PREFETCH > 1
  516. li r0,MAX_COPY_PREFETCH
  517. li r11,4
  518. mtctr r0
  519. 11: dcbt r11,r4
  520. addi r11,r11,L1_CACHE_BYTES
  521. bdnz 11b
  522. #else /* MAX_COPY_PREFETCH == 1 */
  523. dcbt r5,r4
  524. li r11,L1_CACHE_BYTES+4
  525. #endif /* MAX_COPY_PREFETCH */
  526. li r0,PAGE_SIZE/L1_CACHE_BYTES - MAX_COPY_PREFETCH
  527. crclr 4*cr0+eq
  528. 2:
  529. mtctr r0
  530. 1:
  531. dcbt r11,r4
  532. dcbz r5,r3
  533. COPY_16_BYTES
  534. #if L1_CACHE_BYTES >= 32
  535. COPY_16_BYTES
  536. #if L1_CACHE_BYTES >= 64
  537. COPY_16_BYTES
  538. COPY_16_BYTES
  539. #if L1_CACHE_BYTES >= 128
  540. COPY_16_BYTES
  541. COPY_16_BYTES
  542. COPY_16_BYTES
  543. COPY_16_BYTES
  544. #endif
  545. #endif
  546. #endif
  547. bdnz 1b
  548. beqlr
  549. crnot 4*cr0+eq,4*cr0+eq
  550. li r0,MAX_COPY_PREFETCH
  551. li r11,4
  552. b 2b
  553. /*
  554. * void atomic_clear_mask(atomic_t mask, atomic_t *addr)
  555. * void atomic_set_mask(atomic_t mask, atomic_t *addr);
  556. */
  557. _GLOBAL(atomic_clear_mask)
  558. 10: lwarx r5,0,r4
  559. andc r5,r5,r3
  560. PPC405_ERR77(0,r4)
  561. stwcx. r5,0,r4
  562. bne- 10b
  563. blr
  564. _GLOBAL(atomic_set_mask)
  565. 10: lwarx r5,0,r4
  566. or r5,r5,r3
  567. PPC405_ERR77(0,r4)
  568. stwcx. r5,0,r4
  569. bne- 10b
  570. blr
  571. /*
  572. * Extended precision shifts.
  573. *
  574. * Updated to be valid for shift counts from 0 to 63 inclusive.
  575. * -- Gabriel
  576. *
  577. * R3/R4 has 64 bit value
  578. * R5 has shift count
  579. * result in R3/R4
  580. *
  581. * ashrdi3: arithmetic right shift (sign propagation)
  582. * lshrdi3: logical right shift
  583. * ashldi3: left shift
  584. */
  585. _GLOBAL(__ashrdi3)
  586. subfic r6,r5,32
  587. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  588. addi r7,r5,32 # could be xori, or addi with -32
  589. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  590. rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0
  591. sraw r7,r3,r7 # t2 = MSW >> (count-32)
  592. or r4,r4,r6 # LSW |= t1
  593. slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2
  594. sraw r3,r3,r5 # MSW = MSW >> count
  595. or r4,r4,r7 # LSW |= t2
  596. blr
  597. _GLOBAL(__ashldi3)
  598. subfic r6,r5,32
  599. slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count
  600. addi r7,r5,32 # could be xori, or addi with -32
  601. srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count)
  602. slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32)
  603. or r3,r3,r6 # MSW |= t1
  604. slw r4,r4,r5 # LSW = LSW << count
  605. or r3,r3,r7 # MSW |= t2
  606. blr
  607. _GLOBAL(__lshrdi3)
  608. subfic r6,r5,32
  609. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  610. addi r7,r5,32 # could be xori, or addi with -32
  611. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  612. srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32)
  613. or r4,r4,r6 # LSW |= t1
  614. srw r3,r3,r5 # MSW = MSW >> count
  615. or r4,r4,r7 # LSW |= t2
  616. blr
  617. /*
  618. * 64-bit comparison: __cmpdi2(s64 a, s64 b)
  619. * Returns 0 if a < b, 1 if a == b, 2 if a > b.
  620. */
  621. _GLOBAL(__cmpdi2)
  622. cmpw r3,r5
  623. li r3,1
  624. bne 1f
  625. cmplw r4,r6
  626. beqlr
  627. 1: li r3,0
  628. bltlr
  629. li r3,2
  630. blr
  631. /*
  632. * 64-bit comparison: __ucmpdi2(u64 a, u64 b)
  633. * Returns 0 if a < b, 1 if a == b, 2 if a > b.
  634. */
  635. _GLOBAL(__ucmpdi2)
  636. cmplw r3,r5
  637. li r3,1
  638. bne 1f
  639. cmplw r4,r6
  640. beqlr
  641. 1: li r3,0
  642. bltlr
  643. li r3,2
  644. blr
  645. _GLOBAL(__bswapdi2)
  646. rotlwi r9,r4,8
  647. rotlwi r10,r3,8
  648. rlwimi r9,r4,24,0,7
  649. rlwimi r10,r3,24,0,7
  650. rlwimi r9,r4,24,16,23
  651. rlwimi r10,r3,24,16,23
  652. mr r3,r9
  653. mr r4,r10
  654. blr
  655. _GLOBAL(abs)
  656. srawi r4,r3,31
  657. xor r3,r3,r4
  658. sub r3,r3,r4
  659. blr
  660. #ifdef CONFIG_SMP
  661. _GLOBAL(start_secondary_resume)
  662. /* Reset stack */
  663. CURRENT_THREAD_INFO(r1, r1)
  664. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  665. li r3,0
  666. stw r3,0(r1) /* Zero the stack frame pointer */
  667. bl start_secondary
  668. b .
  669. #endif /* CONFIG_SMP */
  670. /*
  671. * This routine is just here to keep GCC happy - sigh...
  672. */
  673. _GLOBAL(__main)
  674. blr
  675. #ifdef CONFIG_KEXEC
  676. /*
  677. * Must be relocatable PIC code callable as a C function.
  678. */
  679. .globl relocate_new_kernel
  680. relocate_new_kernel:
  681. /* r3 = page_list */
  682. /* r4 = reboot_code_buffer */
  683. /* r5 = start_address */
  684. #ifdef CONFIG_FSL_BOOKE
  685. mr r29, r3
  686. mr r30, r4
  687. mr r31, r5
  688. #define ENTRY_MAPPING_KEXEC_SETUP
  689. #include "fsl_booke_entry_mapping.S"
  690. #undef ENTRY_MAPPING_KEXEC_SETUP
  691. mr r3, r29
  692. mr r4, r30
  693. mr r5, r31
  694. li r0, 0
  695. #elif defined(CONFIG_44x)
  696. /* Save our parameters */
  697. mr r29, r3
  698. mr r30, r4
  699. mr r31, r5
  700. #ifdef CONFIG_PPC_47x
  701. /* Check for 47x cores */
  702. mfspr r3,SPRN_PVR
  703. srwi r3,r3,16
  704. cmplwi cr0,r3,PVR_476@h
  705. beq setup_map_47x
  706. cmplwi cr0,r3,PVR_476_ISS@h
  707. beq setup_map_47x
  708. #endif /* CONFIG_PPC_47x */
  709. /*
  710. * Code for setting up 1:1 mapping for PPC440x for KEXEC
  711. *
  712. * We cannot switch off the MMU on PPC44x.
  713. * So we:
  714. * 1) Invalidate all the mappings except the one we are running from.
  715. * 2) Create a tmp mapping for our code in the other address space(TS) and
  716. * jump to it. Invalidate the entry we started in.
  717. * 3) Create a 1:1 mapping for 0-2GiB in chunks of 256M in original TS.
  718. * 4) Jump to the 1:1 mapping in original TS.
  719. * 5) Invalidate the tmp mapping.
  720. *
  721. * - Based on the kexec support code for FSL BookE
  722. *
  723. */
  724. /*
  725. * Load the PID with kernel PID (0).
  726. * Also load our MSR_IS and TID to MMUCR for TLB search.
  727. */
  728. li r3, 0
  729. mtspr SPRN_PID, r3
  730. mfmsr r4
  731. andi. r4,r4,MSR_IS@l
  732. beq wmmucr
  733. oris r3,r3,PPC44x_MMUCR_STS@h
  734. wmmucr:
  735. mtspr SPRN_MMUCR,r3
  736. sync
  737. /*
  738. * Invalidate all the TLB entries except the current entry
  739. * where we are running from
  740. */
  741. bl 0f /* Find our address */
  742. 0: mflr r5 /* Make it accessible */
  743. tlbsx r23,0,r5 /* Find entry we are in */
  744. li r4,0 /* Start at TLB entry 0 */
  745. li r3,0 /* Set PAGEID inval value */
  746. 1: cmpw r23,r4 /* Is this our entry? */
  747. beq skip /* If so, skip the inval */
  748. tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */
  749. skip:
  750. addi r4,r4,1 /* Increment */
  751. cmpwi r4,64 /* Are we done? */
  752. bne 1b /* If not, repeat */
  753. isync
  754. /* Create a temp mapping and jump to it */
  755. andi. r6, r23, 1 /* Find the index to use */
  756. addi r24, r6, 1 /* r24 will contain 1 or 2 */
  757. mfmsr r9 /* get the MSR */
  758. rlwinm r5, r9, 27, 31, 31 /* Extract the MSR[IS] */
  759. xori r7, r5, 1 /* Use the other address space */
  760. /* Read the current mapping entries */
  761. tlbre r3, r23, PPC44x_TLB_PAGEID
  762. tlbre r4, r23, PPC44x_TLB_XLAT
  763. tlbre r5, r23, PPC44x_TLB_ATTRIB
  764. /* Save our current XLAT entry */
  765. mr r25, r4
  766. /* Extract the TLB PageSize */
  767. li r10, 1 /* r10 will hold PageSize */
  768. rlwinm r11, r3, 0, 24, 27 /* bits 24-27 */
  769. /* XXX: As of now we use 256M, 4K pages */
  770. cmpwi r11, PPC44x_TLB_256M
  771. bne tlb_4k
  772. rotlwi r10, r10, 28 /* r10 = 256M */
  773. b write_out
  774. tlb_4k:
  775. cmpwi r11, PPC44x_TLB_4K
  776. bne default
  777. rotlwi r10, r10, 12 /* r10 = 4K */
  778. b write_out
  779. default:
  780. rotlwi r10, r10, 10 /* r10 = 1K */
  781. write_out:
  782. /*
  783. * Write out the tmp 1:1 mapping for this code in other address space
  784. * Fixup EPN = RPN , TS=other address space
  785. */
  786. insrwi r3, r7, 1, 23 /* Bit 23 is TS for PAGEID field */
  787. /* Write out the tmp mapping entries */
  788. tlbwe r3, r24, PPC44x_TLB_PAGEID
  789. tlbwe r4, r24, PPC44x_TLB_XLAT
  790. tlbwe r5, r24, PPC44x_TLB_ATTRIB
  791. subi r11, r10, 1 /* PageOffset Mask = PageSize - 1 */
  792. not r10, r11 /* Mask for PageNum */
  793. /* Switch to other address space in MSR */
  794. insrwi r9, r7, 1, 26 /* Set MSR[IS] = r7 */
  795. bl 1f
  796. 1: mflr r8
  797. addi r8, r8, (2f-1b) /* Find the target offset */
  798. /* Jump to the tmp mapping */
  799. mtspr SPRN_SRR0, r8
  800. mtspr SPRN_SRR1, r9
  801. rfi
  802. 2:
  803. /* Invalidate the entry we were executing from */
  804. li r3, 0
  805. tlbwe r3, r23, PPC44x_TLB_PAGEID
  806. /* attribute fields. rwx for SUPERVISOR mode */
  807. li r5, 0
  808. ori r5, r5, (PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G)
  809. /* Create 1:1 mapping in 256M pages */
  810. xori r7, r7, 1 /* Revert back to Original TS */
  811. li r8, 0 /* PageNumber */
  812. li r6, 3 /* TLB Index, start at 3 */
  813. next_tlb:
  814. rotlwi r3, r8, 28 /* Create EPN (bits 0-3) */
  815. mr r4, r3 /* RPN = EPN */
  816. ori r3, r3, (PPC44x_TLB_VALID | PPC44x_TLB_256M) /* SIZE = 256M, Valid */
  817. insrwi r3, r7, 1, 23 /* Set TS from r7 */
  818. tlbwe r3, r6, PPC44x_TLB_PAGEID /* PageID field : EPN, V, SIZE */
  819. tlbwe r4, r6, PPC44x_TLB_XLAT /* Address translation : RPN */
  820. tlbwe r5, r6, PPC44x_TLB_ATTRIB /* Attributes */
  821. addi r8, r8, 1 /* Increment PN */
  822. addi r6, r6, 1 /* Increment TLB Index */
  823. cmpwi r8, 8 /* Are we done ? */
  824. bne next_tlb
  825. isync
  826. /* Jump to the new mapping 1:1 */
  827. li r9,0
  828. insrwi r9, r7, 1, 26 /* Set MSR[IS] = r7 */
  829. bl 1f
  830. 1: mflr r8
  831. and r8, r8, r11 /* Get our offset within page */
  832. addi r8, r8, (2f-1b)
  833. and r5, r25, r10 /* Get our target PageNum */
  834. or r8, r8, r5 /* Target jump address */
  835. mtspr SPRN_SRR0, r8
  836. mtspr SPRN_SRR1, r9
  837. rfi
  838. 2:
  839. /* Invalidate the tmp entry we used */
  840. li r3, 0
  841. tlbwe r3, r24, PPC44x_TLB_PAGEID
  842. sync
  843. b ppc44x_map_done
  844. #ifdef CONFIG_PPC_47x
  845. /* 1:1 mapping for 47x */
  846. setup_map_47x:
  847. /*
  848. * Load the kernel pid (0) to PID and also to MMUCR[TID].
  849. * Also set the MSR IS->MMUCR STS
  850. */
  851. li r3, 0
  852. mtspr SPRN_PID, r3 /* Set PID */
  853. mfmsr r4 /* Get MSR */
  854. andi. r4, r4, MSR_IS@l /* TS=1? */
  855. beq 1f /* If not, leave STS=0 */
  856. oris r3, r3, PPC47x_MMUCR_STS@h /* Set STS=1 */
  857. 1: mtspr SPRN_MMUCR, r3 /* Put MMUCR */
  858. sync
  859. /* Find the entry we are running from */
  860. bl 2f
  861. 2: mflr r23
  862. tlbsx r23, 0, r23
  863. tlbre r24, r23, 0 /* TLB Word 0 */
  864. tlbre r25, r23, 1 /* TLB Word 1 */
  865. tlbre r26, r23, 2 /* TLB Word 2 */
  866. /*
  867. * Invalidates all the tlb entries by writing to 256 RPNs(r4)
  868. * of 4k page size in all 4 ways (0-3 in r3).
  869. * This would invalidate the entire UTLB including the one we are
  870. * running from. However the shadow TLB entries would help us
  871. * to continue the execution, until we flush them (rfi/isync).
  872. */
  873. addis r3, 0, 0x8000 /* specify the way */
  874. addi r4, 0, 0 /* TLB Word0 = (EPN=0, VALID = 0) */
  875. addi r5, 0, 0
  876. b clear_utlb_entry
  877. /* Align the loop to speed things up. from head_44x.S */
  878. .align 6
  879. clear_utlb_entry:
  880. tlbwe r4, r3, 0
  881. tlbwe r5, r3, 1
  882. tlbwe r5, r3, 2
  883. addis r3, r3, 0x2000 /* Increment the way */
  884. cmpwi r3, 0
  885. bne clear_utlb_entry
  886. addis r3, 0, 0x8000
  887. addis r4, r4, 0x100 /* Increment the EPN */
  888. cmpwi r4, 0
  889. bne clear_utlb_entry
  890. /* Create the entries in the other address space */
  891. mfmsr r5
  892. rlwinm r7, r5, 27, 31, 31 /* Get the TS (Bit 26) from MSR */
  893. xori r7, r7, 1 /* r7 = !TS */
  894. insrwi r24, r7, 1, 21 /* Change the TS in the saved TLB word 0 */
  895. /*
  896. * write out the TLB entries for the tmp mapping
  897. * Use way '0' so that we could easily invalidate it later.
  898. */
  899. lis r3, 0x8000 /* Way '0' */
  900. tlbwe r24, r3, 0
  901. tlbwe r25, r3, 1
  902. tlbwe r26, r3, 2
  903. /* Update the msr to the new TS */
  904. insrwi r5, r7, 1, 26
  905. bl 1f
  906. 1: mflr r6
  907. addi r6, r6, (2f-1b)
  908. mtspr SPRN_SRR0, r6
  909. mtspr SPRN_SRR1, r5
  910. rfi
  911. /*
  912. * Now we are in the tmp address space.
  913. * Create a 1:1 mapping for 0-2GiB in the original TS.
  914. */
  915. 2:
  916. li r3, 0
  917. li r4, 0 /* TLB Word 0 */
  918. li r5, 0 /* TLB Word 1 */
  919. li r6, 0
  920. ori r6, r6, PPC47x_TLB2_S_RWX /* TLB word 2 */
  921. li r8, 0 /* PageIndex */
  922. xori r7, r7, 1 /* revert back to original TS */
  923. write_utlb:
  924. rotlwi r5, r8, 28 /* RPN = PageIndex * 256M */
  925. /* ERPN = 0 as we don't use memory above 2G */
  926. mr r4, r5 /* EPN = RPN */
  927. ori r4, r4, (PPC47x_TLB0_VALID | PPC47x_TLB0_256M)
  928. insrwi r4, r7, 1, 21 /* Insert the TS to Word 0 */
  929. tlbwe r4, r3, 0 /* Write out the entries */
  930. tlbwe r5, r3, 1
  931. tlbwe r6, r3, 2
  932. addi r8, r8, 1
  933. cmpwi r8, 8 /* Have we completed ? */
  934. bne write_utlb
  935. /* make sure we complete the TLB write up */
  936. isync
  937. /*
  938. * Prepare to jump to the 1:1 mapping.
  939. * 1) Extract page size of the tmp mapping
  940. * DSIZ = TLB_Word0[22:27]
  941. * 2) Calculate the physical address of the address
  942. * to jump to.
  943. */
  944. rlwinm r10, r24, 0, 22, 27
  945. cmpwi r10, PPC47x_TLB0_4K
  946. bne 0f
  947. li r10, 0x1000 /* r10 = 4k */
  948. bl 1f
  949. 0:
  950. /* Defaults to 256M */
  951. lis r10, 0x1000
  952. bl 1f
  953. 1: mflr r4
  954. addi r4, r4, (2f-1b) /* virtual address of 2f */
  955. subi r11, r10, 1 /* offsetmask = Pagesize - 1 */
  956. not r10, r11 /* Pagemask = ~(offsetmask) */
  957. and r5, r25, r10 /* Physical page */
  958. and r6, r4, r11 /* offset within the current page */
  959. or r5, r5, r6 /* Physical address for 2f */
  960. /* Switch the TS in MSR to the original one */
  961. mfmsr r8
  962. insrwi r8, r7, 1, 26
  963. mtspr SPRN_SRR1, r8
  964. mtspr SPRN_SRR0, r5
  965. rfi
  966. 2:
  967. /* Invalidate the tmp mapping */
  968. lis r3, 0x8000 /* Way '0' */
  969. clrrwi r24, r24, 12 /* Clear the valid bit */
  970. tlbwe r24, r3, 0
  971. tlbwe r25, r3, 1
  972. tlbwe r26, r3, 2
  973. /* Make sure we complete the TLB write and flush the shadow TLB */
  974. isync
  975. #endif
  976. ppc44x_map_done:
  977. /* Restore the parameters */
  978. mr r3, r29
  979. mr r4, r30
  980. mr r5, r31
  981. li r0, 0
  982. #else
  983. li r0, 0
  984. /*
  985. * Set Machine Status Register to a known status,
  986. * switch the MMU off and jump to 1: in a single step.
  987. */
  988. mr r8, r0
  989. ori r8, r8, MSR_RI|MSR_ME
  990. mtspr SPRN_SRR1, r8
  991. addi r8, r4, 1f - relocate_new_kernel
  992. mtspr SPRN_SRR0, r8
  993. sync
  994. rfi
  995. 1:
  996. #endif
  997. /* from this point address translation is turned off */
  998. /* and interrupts are disabled */
  999. /* set a new stack at the bottom of our page... */
  1000. /* (not really needed now) */
  1001. addi r1, r4, KEXEC_CONTROL_PAGE_SIZE - 8 /* for LR Save+Back Chain */
  1002. stw r0, 0(r1)
  1003. /* Do the copies */
  1004. li r6, 0 /* checksum */
  1005. mr r0, r3
  1006. b 1f
  1007. 0: /* top, read another word for the indirection page */
  1008. lwzu r0, 4(r3)
  1009. 1:
  1010. /* is it a destination page? (r8) */
  1011. rlwinm. r7, r0, 0, 31, 31 /* IND_DESTINATION (1<<0) */
  1012. beq 2f
  1013. rlwinm r8, r0, 0, 0, 19 /* clear kexec flags, page align */
  1014. b 0b
  1015. 2: /* is it an indirection page? (r3) */
  1016. rlwinm. r7, r0, 0, 30, 30 /* IND_INDIRECTION (1<<1) */
  1017. beq 2f
  1018. rlwinm r3, r0, 0, 0, 19 /* clear kexec flags, page align */
  1019. subi r3, r3, 4
  1020. b 0b
  1021. 2: /* are we done? */
  1022. rlwinm. r7, r0, 0, 29, 29 /* IND_DONE (1<<2) */
  1023. beq 2f
  1024. b 3f
  1025. 2: /* is it a source page? (r9) */
  1026. rlwinm. r7, r0, 0, 28, 28 /* IND_SOURCE (1<<3) */
  1027. beq 0b
  1028. rlwinm r9, r0, 0, 0, 19 /* clear kexec flags, page align */
  1029. li r7, PAGE_SIZE / 4
  1030. mtctr r7
  1031. subi r9, r9, 4
  1032. subi r8, r8, 4
  1033. 9:
  1034. lwzu r0, 4(r9) /* do the copy */
  1035. xor r6, r6, r0
  1036. stwu r0, 4(r8)
  1037. dcbst 0, r8
  1038. sync
  1039. icbi 0, r8
  1040. bdnz 9b
  1041. addi r9, r9, 4
  1042. addi r8, r8, 4
  1043. b 0b
  1044. 3:
  1045. /* To be certain of avoiding problems with self-modifying code
  1046. * execute a serializing instruction here.
  1047. */
  1048. isync
  1049. sync
  1050. mfspr r3, SPRN_PIR /* current core we are running on */
  1051. mr r4, r5 /* load physical address of chunk called */
  1052. /* jump to the entry point, usually the setup routine */
  1053. mtlr r5
  1054. blrl
  1055. 1: b 1b
  1056. relocate_new_kernel_end:
  1057. .globl relocate_new_kernel_size
  1058. relocate_new_kernel_size:
  1059. .long relocate_new_kernel_end - relocate_new_kernel
  1060. #endif