misc_32.S 25 KB

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