misc_32.S 23 KB

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