misc_32.S 25 KB

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