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