misc_32.S 19 KB

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