misc_32.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  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. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. *
  17. */
  18. #include <linux/sys.h>
  19. #include <asm/unistd.h>
  20. #include <asm/errno.h>
  21. #include <asm/reg.h>
  22. #include <asm/page.h>
  23. #include <asm/cache.h>
  24. #include <asm/cputable.h>
  25. #include <asm/mmu.h>
  26. #include <asm/ppc_asm.h>
  27. #include <asm/thread_info.h>
  28. #include <asm/asm-offsets.h>
  29. #include <asm/processor.h>
  30. #include <asm/kexec.h>
  31. .text
  32. /*
  33. * This returns the high 64 bits of the product of two 64-bit numbers.
  34. */
  35. _GLOBAL(mulhdu)
  36. cmpwi r6,0
  37. cmpwi cr1,r3,0
  38. mr r10,r4
  39. mulhwu r4,r4,r5
  40. beq 1f
  41. mulhwu r0,r10,r6
  42. mullw r7,r10,r5
  43. addc r7,r0,r7
  44. addze r4,r4
  45. 1: beqlr cr1 /* all done if high part of A is 0 */
  46. mr r10,r3
  47. mullw r9,r3,r5
  48. mulhwu r3,r3,r5
  49. beq 2f
  50. mullw r0,r10,r6
  51. mulhwu r8,r10,r6
  52. addc r7,r0,r7
  53. adde r4,r4,r8
  54. addze r3,r3
  55. 2: addc r4,r4,r9
  56. addze r3,r3
  57. blr
  58. /*
  59. * sub_reloc_offset(x) returns x - reloc_offset().
  60. */
  61. _GLOBAL(sub_reloc_offset)
  62. mflr r0
  63. bl 1f
  64. 1: mflr r5
  65. lis r4,1b@ha
  66. addi r4,r4,1b@l
  67. subf r5,r4,r5
  68. subf r3,r5,r3
  69. mtlr r0
  70. blr
  71. /*
  72. * reloc_got2 runs through the .got2 section adding an offset
  73. * to each entry.
  74. */
  75. _GLOBAL(reloc_got2)
  76. mflr r11
  77. lis r7,__got2_start@ha
  78. addi r7,r7,__got2_start@l
  79. lis r8,__got2_end@ha
  80. addi r8,r8,__got2_end@l
  81. subf r8,r7,r8
  82. srwi. r8,r8,2
  83. beqlr
  84. mtctr r8
  85. bl 1f
  86. 1: mflr r0
  87. lis r4,1b@ha
  88. addi r4,r4,1b@l
  89. subf r0,r4,r0
  90. add r7,r0,r7
  91. 2: lwz r0,0(r7)
  92. add r0,r0,r3
  93. stw r0,0(r7)
  94. addi r7,r7,4
  95. bdnz 2b
  96. mtlr r11
  97. blr
  98. /*
  99. * call_setup_cpu - call the setup_cpu function for this cpu
  100. * r3 = data offset, r24 = cpu number
  101. *
  102. * Setup function is called with:
  103. * r3 = data offset
  104. * r4 = ptr to CPU spec (relocated)
  105. */
  106. _GLOBAL(call_setup_cpu)
  107. addis r4,r3,cur_cpu_spec@ha
  108. addi r4,r4,cur_cpu_spec@l
  109. lwz r4,0(r4)
  110. add r4,r4,r3
  111. lwz r5,CPU_SPEC_SETUP(r4)
  112. cmpwi 0,r5,0
  113. add r5,r5,r3
  114. beqlr
  115. mtctr r5
  116. bctr
  117. #if defined(CONFIG_CPU_FREQ_PMAC) && defined(CONFIG_6xx)
  118. /* This gets called by via-pmu.c to switch the PLL selection
  119. * on 750fx CPU. This function should really be moved to some
  120. * other place (as most of the cpufreq code in via-pmu
  121. */
  122. _GLOBAL(low_choose_750fx_pll)
  123. /* Clear MSR:EE */
  124. mfmsr r7
  125. rlwinm r0,r7,0,17,15
  126. mtmsr r0
  127. /* If switching to PLL1, disable HID0:BTIC */
  128. cmplwi cr0,r3,0
  129. beq 1f
  130. mfspr r5,SPRN_HID0
  131. rlwinm r5,r5,0,27,25
  132. sync
  133. mtspr SPRN_HID0,r5
  134. isync
  135. sync
  136. 1:
  137. /* Calc new HID1 value */
  138. mfspr r4,SPRN_HID1 /* Build a HID1:PS bit from parameter */
  139. rlwinm r5,r3,16,15,15 /* Clear out HID1:PS from value read */
  140. rlwinm r4,r4,0,16,14 /* Could have I used rlwimi here ? */
  141. or r4,r4,r5
  142. mtspr SPRN_HID1,r4
  143. /* Store new HID1 image */
  144. rlwinm r6,r1,0,0,(31-THREAD_SHIFT)
  145. lwz r6,TI_CPU(r6)
  146. slwi r6,r6,2
  147. addis r6,r6,nap_save_hid1@ha
  148. stw r4,nap_save_hid1@l(r6)
  149. /* If switching to PLL0, enable HID0:BTIC */
  150. cmplwi cr0,r3,0
  151. bne 1f
  152. mfspr r5,SPRN_HID0
  153. ori r5,r5,HID0_BTIC
  154. sync
  155. mtspr SPRN_HID0,r5
  156. isync
  157. sync
  158. 1:
  159. /* Return */
  160. mtmsr r7
  161. blr
  162. _GLOBAL(low_choose_7447a_dfs)
  163. /* Clear MSR:EE */
  164. mfmsr r7
  165. rlwinm r0,r7,0,17,15
  166. mtmsr r0
  167. /* Calc new HID1 value */
  168. mfspr r4,SPRN_HID1
  169. insrwi r4,r3,1,9 /* insert parameter into bit 9 */
  170. sync
  171. mtspr SPRN_HID1,r4
  172. sync
  173. isync
  174. /* Return */
  175. mtmsr r7
  176. blr
  177. #endif /* CONFIG_CPU_FREQ_PMAC && CONFIG_6xx */
  178. /*
  179. * complement mask on the msr then "or" some values on.
  180. * _nmask_and_or_msr(nmask, value_to_or)
  181. */
  182. _GLOBAL(_nmask_and_or_msr)
  183. mfmsr r0 /* Get current msr */
  184. andc r0,r0,r3 /* And off the bits set in r3 (first parm) */
  185. or r0,r0,r4 /* Or on the bits in r4 (second parm) */
  186. SYNC /* Some chip revs have problems here... */
  187. mtmsr r0 /* Update machine state */
  188. isync
  189. blr /* Done */
  190. #ifdef CONFIG_40x
  191. /*
  192. * Do an IO access in real mode
  193. */
  194. _GLOBAL(real_readb)
  195. mfmsr r7
  196. ori r0,r7,MSR_DR
  197. xori r0,r0,MSR_DR
  198. sync
  199. mtmsr r0
  200. sync
  201. isync
  202. lbz r3,0(r3)
  203. sync
  204. mtmsr r7
  205. sync
  206. isync
  207. blr
  208. /*
  209. * Do an IO access in real mode
  210. */
  211. _GLOBAL(real_writeb)
  212. mfmsr r7
  213. ori r0,r7,MSR_DR
  214. xori r0,r0,MSR_DR
  215. sync
  216. mtmsr r0
  217. sync
  218. isync
  219. stb r3,0(r4)
  220. sync
  221. mtmsr r7
  222. sync
  223. isync
  224. blr
  225. #endif /* CONFIG_40x */
  226. /*
  227. * Flush MMU TLB
  228. */
  229. _GLOBAL(_tlbia)
  230. #if defined(CONFIG_40x)
  231. sync /* Flush to memory before changing mapping */
  232. tlbia
  233. isync /* Flush shadow TLB */
  234. #elif defined(CONFIG_44x)
  235. li r3,0
  236. sync
  237. /* Load high watermark */
  238. lis r4,tlb_44x_hwater@ha
  239. lwz r5,tlb_44x_hwater@l(r4)
  240. 1: tlbwe r3,r3,PPC44x_TLB_PAGEID
  241. addi r3,r3,1
  242. cmpw 0,r3,r5
  243. ble 1b
  244. isync
  245. #elif defined(CONFIG_FSL_BOOKE)
  246. /* Invalidate all entries in TLB0 */
  247. li r3, 0x04
  248. tlbivax 0,3
  249. /* Invalidate all entries in TLB1 */
  250. li r3, 0x0c
  251. tlbivax 0,3
  252. msync
  253. #ifdef CONFIG_SMP
  254. tlbsync
  255. #endif /* CONFIG_SMP */
  256. #else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */
  257. #if defined(CONFIG_SMP)
  258. rlwinm r8,r1,0,0,(31-THREAD_SHIFT)
  259. lwz r8,TI_CPU(r8)
  260. oris r8,r8,10
  261. mfmsr r10
  262. SYNC
  263. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  264. rlwinm r0,r0,0,28,26 /* clear DR */
  265. mtmsr r0
  266. SYNC_601
  267. isync
  268. lis r9,mmu_hash_lock@h
  269. ori r9,r9,mmu_hash_lock@l
  270. tophys(r9,r9)
  271. 10: lwarx r7,0,r9
  272. cmpwi 0,r7,0
  273. bne- 10b
  274. stwcx. r8,0,r9
  275. bne- 10b
  276. sync
  277. tlbia
  278. sync
  279. TLBSYNC
  280. li r0,0
  281. stw r0,0(r9) /* clear mmu_hash_lock */
  282. mtmsr r10
  283. SYNC_601
  284. isync
  285. #else /* CONFIG_SMP */
  286. sync
  287. tlbia
  288. sync
  289. #endif /* CONFIG_SMP */
  290. #endif /* ! defined(CONFIG_40x) */
  291. blr
  292. /*
  293. * Flush MMU TLB for a particular address
  294. */
  295. _GLOBAL(_tlbie)
  296. #if defined(CONFIG_40x)
  297. /* We run the search with interrupts disabled because we have to change
  298. * the PID and I don't want to preempt when that happens.
  299. */
  300. mfmsr r5
  301. mfspr r6,SPRN_PID
  302. wrteei 0
  303. mtspr SPRN_PID,r4
  304. tlbsx. r3, 0, r3
  305. mtspr SPRN_PID,r6
  306. wrtee r5
  307. bne 10f
  308. sync
  309. /* There are only 64 TLB entries, so r3 < 64, which means bit 25 is clear.
  310. * Since 25 is the V bit in the TLB_TAG, loading this value will invalidate
  311. * the TLB entry. */
  312. tlbwe r3, r3, TLB_TAG
  313. isync
  314. 10:
  315. #elif defined(CONFIG_44x)
  316. mfspr r5,SPRN_MMUCR
  317. rlwimi r5,r4,0,24,31 /* Set TID */
  318. /* We have to run the search with interrupts disabled, even critical
  319. * and debug interrupts (in fact the only critical exceptions we have
  320. * are debug and machine check). Otherwise an interrupt which causes
  321. * a TLB miss can clobber the MMUCR between the mtspr and the tlbsx. */
  322. mfmsr r4
  323. lis r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@ha
  324. addi r6,r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@l
  325. andc r6,r4,r6
  326. mtmsr r6
  327. mtspr SPRN_MMUCR,r5
  328. tlbsx. r3, 0, r3
  329. mtmsr r4
  330. bne 10f
  331. sync
  332. /* There are only 64 TLB entries, so r3 < 64,
  333. * which means bit 22, is clear. Since 22 is
  334. * the V bit in the TLB_PAGEID, loading this
  335. * value will invalidate the TLB entry.
  336. */
  337. tlbwe r3, r3, PPC44x_TLB_PAGEID
  338. isync
  339. 10:
  340. #elif defined(CONFIG_FSL_BOOKE)
  341. rlwinm r4, r3, 0, 0, 19
  342. ori r5, r4, 0x08 /* TLBSEL = 1 */
  343. tlbivax 0, r4
  344. tlbivax 0, r5
  345. msync
  346. #if defined(CONFIG_SMP)
  347. tlbsync
  348. #endif /* CONFIG_SMP */
  349. #else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */
  350. #if defined(CONFIG_SMP)
  351. rlwinm r8,r1,0,0,(31-THREAD_SHIFT)
  352. lwz r8,TI_CPU(r8)
  353. oris r8,r8,11
  354. mfmsr r10
  355. SYNC
  356. rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
  357. rlwinm r0,r0,0,28,26 /* clear DR */
  358. mtmsr r0
  359. SYNC_601
  360. isync
  361. lis r9,mmu_hash_lock@h
  362. ori r9,r9,mmu_hash_lock@l
  363. tophys(r9,r9)
  364. 10: lwarx r7,0,r9
  365. cmpwi 0,r7,0
  366. bne- 10b
  367. stwcx. r8,0,r9
  368. bne- 10b
  369. eieio
  370. tlbie r3
  371. sync
  372. TLBSYNC
  373. li r0,0
  374. stw r0,0(r9) /* clear mmu_hash_lock */
  375. mtmsr r10
  376. SYNC_601
  377. isync
  378. #else /* CONFIG_SMP */
  379. tlbie r3
  380. sync
  381. #endif /* CONFIG_SMP */
  382. #endif /* ! CONFIG_40x */
  383. blr
  384. /*
  385. * Flush instruction cache.
  386. * This is a no-op on the 601.
  387. */
  388. _GLOBAL(flush_instruction_cache)
  389. #if defined(CONFIG_8xx)
  390. isync
  391. lis r5, IDC_INVALL@h
  392. mtspr SPRN_IC_CST, r5
  393. #elif defined(CONFIG_4xx)
  394. #ifdef CONFIG_403GCX
  395. li r3, 512
  396. mtctr r3
  397. lis r4, KERNELBASE@h
  398. 1: iccci 0, r4
  399. addi r4, r4, 16
  400. bdnz 1b
  401. #else
  402. lis r3, KERNELBASE@h
  403. iccci 0,r3
  404. #endif
  405. #elif CONFIG_FSL_BOOKE
  406. BEGIN_FTR_SECTION
  407. mfspr r3,SPRN_L1CSR0
  408. ori r3,r3,L1CSR0_CFI|L1CSR0_CLFC
  409. /* msync; isync recommended here */
  410. mtspr SPRN_L1CSR0,r3
  411. isync
  412. blr
  413. END_FTR_SECTION_IFSET(CPU_FTR_UNIFIED_ID_CACHE)
  414. mfspr r3,SPRN_L1CSR1
  415. ori r3,r3,L1CSR1_ICFI|L1CSR1_ICLFR
  416. mtspr SPRN_L1CSR1,r3
  417. #else
  418. mfspr r3,SPRN_PVR
  419. rlwinm r3,r3,16,16,31
  420. cmpwi 0,r3,1
  421. beqlr /* for 601, do nothing */
  422. /* 603/604 processor - use invalidate-all bit in HID0 */
  423. mfspr r3,SPRN_HID0
  424. ori r3,r3,HID0_ICFI
  425. mtspr SPRN_HID0,r3
  426. #endif /* CONFIG_8xx/4xx */
  427. isync
  428. blr
  429. /*
  430. * Write any modified data cache blocks out to memory
  431. * and invalidate the corresponding instruction cache blocks.
  432. * This is a no-op on the 601.
  433. *
  434. * flush_icache_range(unsigned long start, unsigned long stop)
  435. */
  436. _GLOBAL(__flush_icache_range)
  437. BEGIN_FTR_SECTION
  438. blr /* for 601, do nothing */
  439. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  440. li r5,L1_CACHE_BYTES-1
  441. andc r3,r3,r5
  442. subf r4,r3,r4
  443. add r4,r4,r5
  444. srwi. r4,r4,L1_CACHE_SHIFT
  445. beqlr
  446. mtctr r4
  447. mr r6,r3
  448. 1: dcbst 0,r3
  449. addi r3,r3,L1_CACHE_BYTES
  450. bdnz 1b
  451. sync /* wait for dcbst's to get to ram */
  452. mtctr r4
  453. 2: icbi 0,r6
  454. addi r6,r6,L1_CACHE_BYTES
  455. bdnz 2b
  456. sync /* additional sync needed on g4 */
  457. isync
  458. blr
  459. /*
  460. * Write any modified data cache blocks out to memory.
  461. * Does not invalidate the corresponding cache lines (especially for
  462. * any corresponding instruction cache).
  463. *
  464. * clean_dcache_range(unsigned long start, unsigned long stop)
  465. */
  466. _GLOBAL(clean_dcache_range)
  467. li r5,L1_CACHE_BYTES-1
  468. andc r3,r3,r5
  469. subf r4,r3,r4
  470. add r4,r4,r5
  471. srwi. r4,r4,L1_CACHE_SHIFT
  472. beqlr
  473. mtctr r4
  474. 1: dcbst 0,r3
  475. addi r3,r3,L1_CACHE_BYTES
  476. bdnz 1b
  477. sync /* wait for dcbst's to get to ram */
  478. blr
  479. /*
  480. * Write any modified data cache blocks out to memory and invalidate them.
  481. * Does not invalidate the corresponding instruction cache blocks.
  482. *
  483. * flush_dcache_range(unsigned long start, unsigned long stop)
  484. */
  485. _GLOBAL(flush_dcache_range)
  486. li r5,L1_CACHE_BYTES-1
  487. andc r3,r3,r5
  488. subf r4,r3,r4
  489. add r4,r4,r5
  490. srwi. r4,r4,L1_CACHE_SHIFT
  491. beqlr
  492. mtctr r4
  493. 1: dcbf 0,r3
  494. addi r3,r3,L1_CACHE_BYTES
  495. bdnz 1b
  496. sync /* wait for dcbst's to get to ram */
  497. blr
  498. /*
  499. * Like above, but invalidate the D-cache. This is used by the 8xx
  500. * to invalidate the cache so the PPC core doesn't get stale data
  501. * from the CPM (no cache snooping here :-).
  502. *
  503. * invalidate_dcache_range(unsigned long start, unsigned long stop)
  504. */
  505. _GLOBAL(invalidate_dcache_range)
  506. li r5,L1_CACHE_BYTES-1
  507. andc r3,r3,r5
  508. subf r4,r3,r4
  509. add r4,r4,r5
  510. srwi. r4,r4,L1_CACHE_SHIFT
  511. beqlr
  512. mtctr r4
  513. 1: dcbi 0,r3
  514. addi r3,r3,L1_CACHE_BYTES
  515. bdnz 1b
  516. sync /* wait for dcbi's to get to ram */
  517. blr
  518. /*
  519. * Flush a particular page from the data cache to RAM.
  520. * Note: this is necessary because the instruction cache does *not*
  521. * snoop from the data cache.
  522. * This is a no-op on the 601 which has a unified cache.
  523. *
  524. * void __flush_dcache_icache(void *page)
  525. */
  526. _GLOBAL(__flush_dcache_icache)
  527. BEGIN_FTR_SECTION
  528. blr
  529. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  530. rlwinm r3,r3,0,0,19 /* Get page base address */
  531. li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
  532. mtctr r4
  533. mr r6,r3
  534. 0: dcbst 0,r3 /* Write line to ram */
  535. addi r3,r3,L1_CACHE_BYTES
  536. bdnz 0b
  537. sync
  538. #ifndef CONFIG_44x
  539. /* We don't flush the icache on 44x. Those have a virtual icache
  540. * and we don't have access to the virtual address here (it's
  541. * not the page vaddr but where it's mapped in user space). The
  542. * flushing of the icache on these is handled elsewhere, when
  543. * a change in the address space occurs, before returning to
  544. * user space
  545. */
  546. mtctr r4
  547. 1: icbi 0,r6
  548. addi r6,r6,L1_CACHE_BYTES
  549. bdnz 1b
  550. sync
  551. isync
  552. #endif /* CONFIG_44x */
  553. blr
  554. /*
  555. * Flush a particular page from the data cache to RAM, identified
  556. * by its physical address. We turn off the MMU so we can just use
  557. * the physical address (this may be a highmem page without a kernel
  558. * mapping).
  559. *
  560. * void __flush_dcache_icache_phys(unsigned long physaddr)
  561. */
  562. _GLOBAL(__flush_dcache_icache_phys)
  563. BEGIN_FTR_SECTION
  564. blr /* for 601, do nothing */
  565. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  566. mfmsr r10
  567. rlwinm r0,r10,0,28,26 /* clear DR */
  568. mtmsr r0
  569. isync
  570. rlwinm r3,r3,0,0,19 /* Get page base address */
  571. li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
  572. mtctr r4
  573. mr r6,r3
  574. 0: dcbst 0,r3 /* Write line to ram */
  575. addi r3,r3,L1_CACHE_BYTES
  576. bdnz 0b
  577. sync
  578. mtctr r4
  579. 1: icbi 0,r6
  580. addi r6,r6,L1_CACHE_BYTES
  581. bdnz 1b
  582. sync
  583. mtmsr r10 /* restore DR */
  584. isync
  585. blr
  586. /*
  587. * Clear pages using the dcbz instruction, which doesn't cause any
  588. * memory traffic (except to write out any cache lines which get
  589. * displaced). This only works on cacheable memory.
  590. *
  591. * void clear_pages(void *page, int order) ;
  592. */
  593. _GLOBAL(clear_pages)
  594. li r0,4096/L1_CACHE_BYTES
  595. slw r0,r0,r4
  596. mtctr r0
  597. #ifdef CONFIG_8xx
  598. li r4, 0
  599. 1: stw r4, 0(r3)
  600. stw r4, 4(r3)
  601. stw r4, 8(r3)
  602. stw r4, 12(r3)
  603. #else
  604. 1: dcbz 0,r3
  605. #endif
  606. addi r3,r3,L1_CACHE_BYTES
  607. bdnz 1b
  608. blr
  609. /*
  610. * Copy a whole page. We use the dcbz instruction on the destination
  611. * to reduce memory traffic (it eliminates the unnecessary reads of
  612. * the destination into cache). This requires that the destination
  613. * is cacheable.
  614. */
  615. #define COPY_16_BYTES \
  616. lwz r6,4(r4); \
  617. lwz r7,8(r4); \
  618. lwz r8,12(r4); \
  619. lwzu r9,16(r4); \
  620. stw r6,4(r3); \
  621. stw r7,8(r3); \
  622. stw r8,12(r3); \
  623. stwu r9,16(r3)
  624. _GLOBAL(copy_page)
  625. addi r3,r3,-4
  626. addi r4,r4,-4
  627. #ifdef CONFIG_8xx
  628. /* don't use prefetch on 8xx */
  629. li r0,4096/L1_CACHE_BYTES
  630. mtctr r0
  631. 1: COPY_16_BYTES
  632. bdnz 1b
  633. blr
  634. #else /* not 8xx, we can prefetch */
  635. li r5,4
  636. #if MAX_COPY_PREFETCH > 1
  637. li r0,MAX_COPY_PREFETCH
  638. li r11,4
  639. mtctr r0
  640. 11: dcbt r11,r4
  641. addi r11,r11,L1_CACHE_BYTES
  642. bdnz 11b
  643. #else /* MAX_COPY_PREFETCH == 1 */
  644. dcbt r5,r4
  645. li r11,L1_CACHE_BYTES+4
  646. #endif /* MAX_COPY_PREFETCH */
  647. li r0,4096/L1_CACHE_BYTES - MAX_COPY_PREFETCH
  648. crclr 4*cr0+eq
  649. 2:
  650. mtctr r0
  651. 1:
  652. dcbt r11,r4
  653. dcbz r5,r3
  654. COPY_16_BYTES
  655. #if L1_CACHE_BYTES >= 32
  656. COPY_16_BYTES
  657. #if L1_CACHE_BYTES >= 64
  658. COPY_16_BYTES
  659. COPY_16_BYTES
  660. #if L1_CACHE_BYTES >= 128
  661. COPY_16_BYTES
  662. COPY_16_BYTES
  663. COPY_16_BYTES
  664. COPY_16_BYTES
  665. #endif
  666. #endif
  667. #endif
  668. bdnz 1b
  669. beqlr
  670. crnot 4*cr0+eq,4*cr0+eq
  671. li r0,MAX_COPY_PREFETCH
  672. li r11,4
  673. b 2b
  674. #endif /* CONFIG_8xx */
  675. /*
  676. * void atomic_clear_mask(atomic_t mask, atomic_t *addr)
  677. * void atomic_set_mask(atomic_t mask, atomic_t *addr);
  678. */
  679. _GLOBAL(atomic_clear_mask)
  680. 10: lwarx r5,0,r4
  681. andc r5,r5,r3
  682. PPC405_ERR77(0,r4)
  683. stwcx. r5,0,r4
  684. bne- 10b
  685. blr
  686. _GLOBAL(atomic_set_mask)
  687. 10: lwarx r5,0,r4
  688. or r5,r5,r3
  689. PPC405_ERR77(0,r4)
  690. stwcx. r5,0,r4
  691. bne- 10b
  692. blr
  693. /*
  694. * Extended precision shifts.
  695. *
  696. * Updated to be valid for shift counts from 0 to 63 inclusive.
  697. * -- Gabriel
  698. *
  699. * R3/R4 has 64 bit value
  700. * R5 has shift count
  701. * result in R3/R4
  702. *
  703. * ashrdi3: arithmetic right shift (sign propagation)
  704. * lshrdi3: logical right shift
  705. * ashldi3: left shift
  706. */
  707. _GLOBAL(__ashrdi3)
  708. subfic r6,r5,32
  709. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  710. addi r7,r5,32 # could be xori, or addi with -32
  711. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  712. rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0
  713. sraw r7,r3,r7 # t2 = MSW >> (count-32)
  714. or r4,r4,r6 # LSW |= t1
  715. slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2
  716. sraw r3,r3,r5 # MSW = MSW >> count
  717. or r4,r4,r7 # LSW |= t2
  718. blr
  719. _GLOBAL(__ashldi3)
  720. subfic r6,r5,32
  721. slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count
  722. addi r7,r5,32 # could be xori, or addi with -32
  723. srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count)
  724. slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32)
  725. or r3,r3,r6 # MSW |= t1
  726. slw r4,r4,r5 # LSW = LSW << count
  727. or r3,r3,r7 # MSW |= t2
  728. blr
  729. _GLOBAL(__lshrdi3)
  730. subfic r6,r5,32
  731. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  732. addi r7,r5,32 # could be xori, or addi with -32
  733. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  734. srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32)
  735. or r4,r4,r6 # LSW |= t1
  736. srw r3,r3,r5 # MSW = MSW >> count
  737. or r4,r4,r7 # LSW |= t2
  738. blr
  739. /*
  740. * 64-bit comparison: __ucmpdi2(u64 a, u64 b)
  741. * Returns 0 if a < b, 1 if a == b, 2 if a > b.
  742. */
  743. _GLOBAL(__ucmpdi2)
  744. cmplw r3,r5
  745. li r3,1
  746. bne 1f
  747. cmplw r4,r6
  748. beqlr
  749. 1: li r3,0
  750. bltlr
  751. li r3,2
  752. blr
  753. _GLOBAL(abs)
  754. srawi r4,r3,31
  755. xor r3,r3,r4
  756. sub r3,r3,r4
  757. blr
  758. /*
  759. * Create a kernel thread
  760. * kernel_thread(fn, arg, flags)
  761. */
  762. _GLOBAL(kernel_thread)
  763. stwu r1,-16(r1)
  764. stw r30,8(r1)
  765. stw r31,12(r1)
  766. mr r30,r3 /* function */
  767. mr r31,r4 /* argument */
  768. ori r3,r5,CLONE_VM /* flags */
  769. oris r3,r3,CLONE_UNTRACED>>16
  770. li r4,0 /* new sp (unused) */
  771. li r0,__NR_clone
  772. sc
  773. cmpwi 0,r3,0 /* parent or child? */
  774. bne 1f /* return if parent */
  775. li r0,0 /* make top-level stack frame */
  776. stwu r0,-16(r1)
  777. mtlr r30 /* fn addr in lr */
  778. mr r3,r31 /* load arg and call fn */
  779. PPC440EP_ERR42
  780. blrl
  781. li r0,__NR_exit /* exit if function returns */
  782. li r3,0
  783. sc
  784. 1: lwz r30,8(r1)
  785. lwz r31,12(r1)
  786. addi r1,r1,16
  787. blr
  788. /*
  789. * This routine is just here to keep GCC happy - sigh...
  790. */
  791. _GLOBAL(__main)
  792. blr
  793. #ifdef CONFIG_KEXEC
  794. /*
  795. * Must be relocatable PIC code callable as a C function.
  796. */
  797. .globl relocate_new_kernel
  798. relocate_new_kernel:
  799. /* r3 = page_list */
  800. /* r4 = reboot_code_buffer */
  801. /* r5 = start_address */
  802. li r0, 0
  803. /*
  804. * Set Machine Status Register to a known status,
  805. * switch the MMU off and jump to 1: in a single step.
  806. */
  807. mr r8, r0
  808. ori r8, r8, MSR_RI|MSR_ME
  809. mtspr SPRN_SRR1, r8
  810. addi r8, r4, 1f - relocate_new_kernel
  811. mtspr SPRN_SRR0, r8
  812. sync
  813. rfi
  814. 1:
  815. /* from this point address translation is turned off */
  816. /* and interrupts are disabled */
  817. /* set a new stack at the bottom of our page... */
  818. /* (not really needed now) */
  819. addi r1, r4, KEXEC_CONTROL_CODE_SIZE - 8 /* for LR Save+Back Chain */
  820. stw r0, 0(r1)
  821. /* Do the copies */
  822. li r6, 0 /* checksum */
  823. mr r0, r3
  824. b 1f
  825. 0: /* top, read another word for the indirection page */
  826. lwzu r0, 4(r3)
  827. 1:
  828. /* is it a destination page? (r8) */
  829. rlwinm. r7, r0, 0, 31, 31 /* IND_DESTINATION (1<<0) */
  830. beq 2f
  831. rlwinm r8, r0, 0, 0, 19 /* clear kexec flags, page align */
  832. b 0b
  833. 2: /* is it an indirection page? (r3) */
  834. rlwinm. r7, r0, 0, 30, 30 /* IND_INDIRECTION (1<<1) */
  835. beq 2f
  836. rlwinm r3, r0, 0, 0, 19 /* clear kexec flags, page align */
  837. subi r3, r3, 4
  838. b 0b
  839. 2: /* are we done? */
  840. rlwinm. r7, r0, 0, 29, 29 /* IND_DONE (1<<2) */
  841. beq 2f
  842. b 3f
  843. 2: /* is it a source page? (r9) */
  844. rlwinm. r7, r0, 0, 28, 28 /* IND_SOURCE (1<<3) */
  845. beq 0b
  846. rlwinm r9, r0, 0, 0, 19 /* clear kexec flags, page align */
  847. li r7, PAGE_SIZE / 4
  848. mtctr r7
  849. subi r9, r9, 4
  850. subi r8, r8, 4
  851. 9:
  852. lwzu r0, 4(r9) /* do the copy */
  853. xor r6, r6, r0
  854. stwu r0, 4(r8)
  855. dcbst 0, r8
  856. sync
  857. icbi 0, r8
  858. bdnz 9b
  859. addi r9, r9, 4
  860. addi r8, r8, 4
  861. b 0b
  862. 3:
  863. /* To be certain of avoiding problems with self-modifying code
  864. * execute a serializing instruction here.
  865. */
  866. isync
  867. sync
  868. /* jump to the entry point, usually the setup routine */
  869. mtlr r5
  870. blrl
  871. 1: b 1b
  872. relocate_new_kernel_end:
  873. .globl relocate_new_kernel_size
  874. relocate_new_kernel_size:
  875. .long relocate_new_kernel_end - relocate_new_kernel
  876. #endif