misc_32.S 19 KB

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