misc_64.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. /*
  2. * arch/powerpc/kernel/misc64.S
  3. *
  4. * This file contains miscellaneous low-level functions.
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. *
  7. * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
  8. * and Paul Mackerras.
  9. * Adapted for iSeries by Mike Corrigan (mikejc@us.ibm.com)
  10. * PPC64 updates by Dave Engebretsen (engebret@us.ibm.com)
  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/processor.h>
  23. #include <asm/page.h>
  24. #include <asm/cache.h>
  25. #include <asm/ppc_asm.h>
  26. #include <asm/asm-offsets.h>
  27. #include <asm/cputable.h>
  28. .text
  29. /*
  30. * Returns (address we are running at) - (address we were linked at)
  31. * for use before the text and data are mapped to KERNELBASE.
  32. */
  33. _GLOBAL(reloc_offset)
  34. mflr r0
  35. bl 1f
  36. 1: mflr r3
  37. LOADADDR(r4,1b)
  38. subf r3,r4,r3
  39. mtlr r0
  40. blr
  41. /*
  42. * add_reloc_offset(x) returns x + reloc_offset().
  43. */
  44. _GLOBAL(add_reloc_offset)
  45. mflr r0
  46. bl 1f
  47. 1: mflr r5
  48. LOADADDR(r4,1b)
  49. subf r5,r4,r5
  50. add r3,r3,r5
  51. mtlr r0
  52. blr
  53. _GLOBAL(get_msr)
  54. mfmsr r3
  55. blr
  56. _GLOBAL(get_dar)
  57. mfdar r3
  58. blr
  59. _GLOBAL(get_srr0)
  60. mfsrr0 r3
  61. blr
  62. _GLOBAL(get_srr1)
  63. mfsrr1 r3
  64. blr
  65. _GLOBAL(get_sp)
  66. mr r3,r1
  67. blr
  68. #ifdef CONFIG_IRQSTACKS
  69. _GLOBAL(call_do_softirq)
  70. mflr r0
  71. std r0,16(r1)
  72. stdu r1,THREAD_SIZE-112(r3)
  73. mr r1,r3
  74. bl .__do_softirq
  75. ld r1,0(r1)
  76. ld r0,16(r1)
  77. mtlr r0
  78. blr
  79. _GLOBAL(call_handle_IRQ_event)
  80. mflr r0
  81. std r0,16(r1)
  82. stdu r1,THREAD_SIZE-112(r6)
  83. mr r1,r6
  84. bl .handle_IRQ_event
  85. ld r1,0(r1)
  86. ld r0,16(r1)
  87. mtlr r0
  88. blr
  89. #endif /* CONFIG_IRQSTACKS */
  90. /*
  91. * To be called by C code which needs to do some operations with MMU
  92. * disabled. Note that interrupts have to be disabled by the caller
  93. * prior to calling us. The code called _MUST_ be in the RMO of course
  94. * and part of the linear mapping as we don't attempt to translate the
  95. * stack pointer at all. The function is called with the stack switched
  96. * to this CPU emergency stack
  97. *
  98. * prototype is void *call_with_mmu_off(void *func, void *data);
  99. *
  100. * the called function is expected to be of the form
  101. *
  102. * void *called(void *data);
  103. */
  104. _GLOBAL(call_with_mmu_off)
  105. mflr r0 /* get link, save it on stackframe */
  106. std r0,16(r1)
  107. mr r1,r5 /* save old stack ptr */
  108. ld r1,PACAEMERGSP(r13) /* get emerg. stack */
  109. subi r1,r1,STACK_FRAME_OVERHEAD
  110. std r0,16(r1) /* save link on emerg. stack */
  111. std r5,0(r1) /* save old stack ptr in backchain */
  112. ld r3,0(r3) /* get to real function ptr (assume same TOC) */
  113. bl 2f /* we need LR to return, continue at label 2 */
  114. ld r0,16(r1) /* we return here from the call, get LR and */
  115. ld r1,0(r1) /* .. old stack ptr */
  116. mtspr SPRN_SRR0,r0 /* and get back to virtual mode with these */
  117. mfmsr r4
  118. ori r4,r4,MSR_IR|MSR_DR
  119. mtspr SPRN_SRR1,r4
  120. rfid
  121. 2: mtspr SPRN_SRR0,r3 /* coming from above, enter real mode */
  122. mr r3,r4 /* get parameter */
  123. mfmsr r0
  124. ori r0,r0,MSR_IR|MSR_DR
  125. xori r0,r0,MSR_IR|MSR_DR
  126. mtspr SPRN_SRR1,r0
  127. rfid
  128. .section ".toc","aw"
  129. PPC64_CACHES:
  130. .tc ppc64_caches[TC],ppc64_caches
  131. .section ".text"
  132. /*
  133. * Write any modified data cache blocks out to memory
  134. * and invalidate the corresponding instruction cache blocks.
  135. *
  136. * flush_icache_range(unsigned long start, unsigned long stop)
  137. *
  138. * flush all bytes from start through stop-1 inclusive
  139. */
  140. _KPROBE(__flush_icache_range)
  141. /*
  142. * Flush the data cache to memory
  143. *
  144. * Different systems have different cache line sizes
  145. * and in some cases i-cache and d-cache line sizes differ from
  146. * each other.
  147. */
  148. ld r10,PPC64_CACHES@toc(r2)
  149. lwz r7,DCACHEL1LINESIZE(r10)/* Get cache line size */
  150. addi r5,r7,-1
  151. andc r6,r3,r5 /* round low to line bdy */
  152. subf r8,r6,r4 /* compute length */
  153. add r8,r8,r5 /* ensure we get enough */
  154. lwz r9,DCACHEL1LOGLINESIZE(r10) /* Get log-2 of cache line size */
  155. srw. r8,r8,r9 /* compute line count */
  156. beqlr /* nothing to do? */
  157. mtctr r8
  158. 1: dcbst 0,r6
  159. add r6,r6,r7
  160. bdnz 1b
  161. sync
  162. /* Now invalidate the instruction cache */
  163. lwz r7,ICACHEL1LINESIZE(r10) /* Get Icache line size */
  164. addi r5,r7,-1
  165. andc r6,r3,r5 /* round low to line bdy */
  166. subf r8,r6,r4 /* compute length */
  167. add r8,r8,r5
  168. lwz r9,ICACHEL1LOGLINESIZE(r10) /* Get log-2 of Icache line size */
  169. srw. r8,r8,r9 /* compute line count */
  170. beqlr /* nothing to do? */
  171. mtctr r8
  172. 2: icbi 0,r6
  173. add r6,r6,r7
  174. bdnz 2b
  175. isync
  176. blr
  177. .previous .text
  178. /*
  179. * Like above, but only do the D-cache.
  180. *
  181. * flush_dcache_range(unsigned long start, unsigned long stop)
  182. *
  183. * flush all bytes from start to stop-1 inclusive
  184. */
  185. _GLOBAL(flush_dcache_range)
  186. /*
  187. * Flush the data cache to memory
  188. *
  189. * Different systems have different cache line sizes
  190. */
  191. ld r10,PPC64_CACHES@toc(r2)
  192. lwz r7,DCACHEL1LINESIZE(r10) /* Get dcache line size */
  193. addi r5,r7,-1
  194. andc r6,r3,r5 /* round low to line bdy */
  195. subf r8,r6,r4 /* compute length */
  196. add r8,r8,r5 /* ensure we get enough */
  197. lwz r9,DCACHEL1LOGLINESIZE(r10) /* Get log-2 of dcache line size */
  198. srw. r8,r8,r9 /* compute line count */
  199. beqlr /* nothing to do? */
  200. mtctr r8
  201. 0: dcbst 0,r6
  202. add r6,r6,r7
  203. bdnz 0b
  204. sync
  205. blr
  206. /*
  207. * Like above, but works on non-mapped physical addresses.
  208. * Use only for non-LPAR setups ! It also assumes real mode
  209. * is cacheable. Used for flushing out the DART before using
  210. * it as uncacheable memory
  211. *
  212. * flush_dcache_phys_range(unsigned long start, unsigned long stop)
  213. *
  214. * flush all bytes from start to stop-1 inclusive
  215. */
  216. _GLOBAL(flush_dcache_phys_range)
  217. ld r10,PPC64_CACHES@toc(r2)
  218. lwz r7,DCACHEL1LINESIZE(r10) /* Get dcache line size */
  219. addi r5,r7,-1
  220. andc r6,r3,r5 /* round low to line bdy */
  221. subf r8,r6,r4 /* compute length */
  222. add r8,r8,r5 /* ensure we get enough */
  223. lwz r9,DCACHEL1LOGLINESIZE(r10) /* Get log-2 of dcache line size */
  224. srw. r8,r8,r9 /* compute line count */
  225. beqlr /* nothing to do? */
  226. mfmsr r5 /* Disable MMU Data Relocation */
  227. ori r0,r5,MSR_DR
  228. xori r0,r0,MSR_DR
  229. sync
  230. mtmsr r0
  231. sync
  232. isync
  233. mtctr r8
  234. 0: dcbst 0,r6
  235. add r6,r6,r7
  236. bdnz 0b
  237. sync
  238. isync
  239. mtmsr r5 /* Re-enable MMU Data Relocation */
  240. sync
  241. isync
  242. blr
  243. _GLOBAL(flush_inval_dcache_range)
  244. ld r10,PPC64_CACHES@toc(r2)
  245. lwz r7,DCACHEL1LINESIZE(r10) /* Get dcache line size */
  246. addi r5,r7,-1
  247. andc r6,r3,r5 /* round low to line bdy */
  248. subf r8,r6,r4 /* compute length */
  249. add r8,r8,r5 /* ensure we get enough */
  250. lwz r9,DCACHEL1LOGLINESIZE(r10)/* Get log-2 of dcache line size */
  251. srw. r8,r8,r9 /* compute line count */
  252. beqlr /* nothing to do? */
  253. sync
  254. isync
  255. mtctr r8
  256. 0: dcbf 0,r6
  257. add r6,r6,r7
  258. bdnz 0b
  259. sync
  260. isync
  261. blr
  262. /*
  263. * Flush a particular page from the data cache to RAM.
  264. * Note: this is necessary because the instruction cache does *not*
  265. * snoop from the data cache.
  266. *
  267. * void __flush_dcache_icache(void *page)
  268. */
  269. _GLOBAL(__flush_dcache_icache)
  270. /*
  271. * Flush the data cache to memory
  272. *
  273. * Different systems have different cache line sizes
  274. */
  275. /* Flush the dcache */
  276. ld r7,PPC64_CACHES@toc(r2)
  277. clrrdi r3,r3,PAGE_SHIFT /* Page align */
  278. lwz r4,DCACHEL1LINESPERPAGE(r7) /* Get # dcache lines per page */
  279. lwz r5,DCACHEL1LINESIZE(r7) /* Get dcache line size */
  280. mr r6,r3
  281. mtctr r4
  282. 0: dcbst 0,r6
  283. add r6,r6,r5
  284. bdnz 0b
  285. sync
  286. /* Now invalidate the icache */
  287. lwz r4,ICACHEL1LINESPERPAGE(r7) /* Get # icache lines per page */
  288. lwz r5,ICACHEL1LINESIZE(r7) /* Get icache line size */
  289. mtctr r4
  290. 1: icbi 0,r3
  291. add r3,r3,r5
  292. bdnz 1b
  293. isync
  294. blr
  295. /*
  296. * I/O string operations
  297. *
  298. * insb(port, buf, len)
  299. * outsb(port, buf, len)
  300. * insw(port, buf, len)
  301. * outsw(port, buf, len)
  302. * insl(port, buf, len)
  303. * outsl(port, buf, len)
  304. * insw_ns(port, buf, len)
  305. * outsw_ns(port, buf, len)
  306. * insl_ns(port, buf, len)
  307. * outsl_ns(port, buf, len)
  308. *
  309. * The *_ns versions don't do byte-swapping.
  310. */
  311. _GLOBAL(_insb)
  312. cmpwi 0,r5,0
  313. mtctr r5
  314. subi r4,r4,1
  315. blelr-
  316. 00: lbz r5,0(r3)
  317. eieio
  318. stbu r5,1(r4)
  319. bdnz 00b
  320. twi 0,r5,0
  321. isync
  322. blr
  323. _GLOBAL(_outsb)
  324. cmpwi 0,r5,0
  325. mtctr r5
  326. subi r4,r4,1
  327. blelr-
  328. 00: lbzu r5,1(r4)
  329. stb r5,0(r3)
  330. bdnz 00b
  331. sync
  332. blr
  333. _GLOBAL(_insw)
  334. cmpwi 0,r5,0
  335. mtctr r5
  336. subi r4,r4,2
  337. blelr-
  338. 00: lhbrx r5,0,r3
  339. eieio
  340. sthu r5,2(r4)
  341. bdnz 00b
  342. twi 0,r5,0
  343. isync
  344. blr
  345. _GLOBAL(_outsw)
  346. cmpwi 0,r5,0
  347. mtctr r5
  348. subi r4,r4,2
  349. blelr-
  350. 00: lhzu r5,2(r4)
  351. sthbrx r5,0,r3
  352. bdnz 00b
  353. sync
  354. blr
  355. _GLOBAL(_insl)
  356. cmpwi 0,r5,0
  357. mtctr r5
  358. subi r4,r4,4
  359. blelr-
  360. 00: lwbrx r5,0,r3
  361. eieio
  362. stwu r5,4(r4)
  363. bdnz 00b
  364. twi 0,r5,0
  365. isync
  366. blr
  367. _GLOBAL(_outsl)
  368. cmpwi 0,r5,0
  369. mtctr r5
  370. subi r4,r4,4
  371. blelr-
  372. 00: lwzu r5,4(r4)
  373. stwbrx r5,0,r3
  374. bdnz 00b
  375. sync
  376. blr
  377. /* _GLOBAL(ide_insw) now in drivers/ide/ide-iops.c */
  378. _GLOBAL(_insw_ns)
  379. cmpwi 0,r5,0
  380. mtctr r5
  381. subi r4,r4,2
  382. blelr-
  383. 00: lhz r5,0(r3)
  384. eieio
  385. sthu r5,2(r4)
  386. bdnz 00b
  387. twi 0,r5,0
  388. isync
  389. blr
  390. /* _GLOBAL(ide_outsw) now in drivers/ide/ide-iops.c */
  391. _GLOBAL(_outsw_ns)
  392. cmpwi 0,r5,0
  393. mtctr r5
  394. subi r4,r4,2
  395. blelr-
  396. 00: lhzu r5,2(r4)
  397. sth r5,0(r3)
  398. bdnz 00b
  399. sync
  400. blr
  401. _GLOBAL(_insl_ns)
  402. cmpwi 0,r5,0
  403. mtctr r5
  404. subi r4,r4,4
  405. blelr-
  406. 00: lwz r5,0(r3)
  407. eieio
  408. stwu r5,4(r4)
  409. bdnz 00b
  410. twi 0,r5,0
  411. isync
  412. blr
  413. _GLOBAL(_outsl_ns)
  414. cmpwi 0,r5,0
  415. mtctr r5
  416. subi r4,r4,4
  417. blelr-
  418. 00: lwzu r5,4(r4)
  419. stw r5,0(r3)
  420. bdnz 00b
  421. sync
  422. blr
  423. _GLOBAL(cvt_fd)
  424. lfd 0,0(r5) /* load up fpscr value */
  425. mtfsf 0xff,0
  426. lfs 0,0(r3)
  427. stfd 0,0(r4)
  428. mffs 0 /* save new fpscr value */
  429. stfd 0,0(r5)
  430. blr
  431. _GLOBAL(cvt_df)
  432. lfd 0,0(r5) /* load up fpscr value */
  433. mtfsf 0xff,0
  434. lfd 0,0(r3)
  435. stfs 0,0(r4)
  436. mffs 0 /* save new fpscr value */
  437. stfd 0,0(r5)
  438. blr
  439. /*
  440. * identify_cpu and calls setup_cpu
  441. * In: r3 = base of the cpu_specs array
  442. * r4 = address of cur_cpu_spec
  443. * r5 = relocation offset
  444. */
  445. _GLOBAL(identify_cpu)
  446. mfpvr r7
  447. 1:
  448. lwz r8,CPU_SPEC_PVR_MASK(r3)
  449. and r8,r8,r7
  450. lwz r9,CPU_SPEC_PVR_VALUE(r3)
  451. cmplw 0,r9,r8
  452. beq 1f
  453. addi r3,r3,CPU_SPEC_ENTRY_SIZE
  454. b 1b
  455. 1:
  456. sub r0,r3,r5
  457. std r0,0(r4)
  458. ld r4,CPU_SPEC_SETUP(r3)
  459. add r4,r4,r5
  460. ld r4,0(r4)
  461. add r4,r4,r5
  462. mtctr r4
  463. /* Calling convention for cpu setup is r3=offset, r4=cur_cpu_spec */
  464. mr r4,r3
  465. mr r3,r5
  466. bctr
  467. /*
  468. * do_cpu_ftr_fixups - goes through the list of CPU feature fixups
  469. * and writes nop's over sections of code that don't apply for this cpu.
  470. * r3 = data offset (not changed)
  471. */
  472. _GLOBAL(do_cpu_ftr_fixups)
  473. /* Get CPU 0 features */
  474. LOADADDR(r6,cur_cpu_spec)
  475. sub r6,r6,r3
  476. ld r4,0(r6)
  477. sub r4,r4,r3
  478. ld r4,CPU_SPEC_FEATURES(r4)
  479. /* Get the fixup table */
  480. LOADADDR(r6,__start___ftr_fixup)
  481. sub r6,r6,r3
  482. LOADADDR(r7,__stop___ftr_fixup)
  483. sub r7,r7,r3
  484. /* Do the fixup */
  485. 1: cmpld r6,r7
  486. bgelr
  487. addi r6,r6,32
  488. ld r8,-32(r6) /* mask */
  489. and r8,r8,r4
  490. ld r9,-24(r6) /* value */
  491. cmpld r8,r9
  492. beq 1b
  493. ld r8,-16(r6) /* section begin */
  494. ld r9,-8(r6) /* section end */
  495. subf. r9,r8,r9
  496. beq 1b
  497. /* write nops over the section of code */
  498. /* todo: if large section, add a branch at the start of it */
  499. srwi r9,r9,2
  500. mtctr r9
  501. sub r8,r8,r3
  502. lis r0,0x60000000@h /* nop */
  503. 3: stw r0,0(r8)
  504. andi. r10,r4,CPU_FTR_SPLIT_ID_CACHE@l
  505. beq 2f
  506. dcbst 0,r8 /* suboptimal, but simpler */
  507. sync
  508. icbi 0,r8
  509. 2: addi r8,r8,4
  510. bdnz 3b
  511. sync /* additional sync needed on g4 */
  512. isync
  513. b 1b
  514. #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE)
  515. /*
  516. * Do an IO access in real mode
  517. */
  518. _GLOBAL(real_readb)
  519. mfmsr r7
  520. ori r0,r7,MSR_DR
  521. xori r0,r0,MSR_DR
  522. sync
  523. mtmsrd r0
  524. sync
  525. isync
  526. mfspr r6,SPRN_HID4
  527. rldicl r5,r6,32,0
  528. ori r5,r5,0x100
  529. rldicl r5,r5,32,0
  530. sync
  531. mtspr SPRN_HID4,r5
  532. isync
  533. slbia
  534. isync
  535. lbz r3,0(r3)
  536. sync
  537. mtspr SPRN_HID4,r6
  538. isync
  539. slbia
  540. isync
  541. mtmsrd r7
  542. sync
  543. isync
  544. blr
  545. /*
  546. * Do an IO access in real mode
  547. */
  548. _GLOBAL(real_writeb)
  549. mfmsr r7
  550. ori r0,r7,MSR_DR
  551. xori r0,r0,MSR_DR
  552. sync
  553. mtmsrd r0
  554. sync
  555. isync
  556. mfspr r6,SPRN_HID4
  557. rldicl r5,r6,32,0
  558. ori r5,r5,0x100
  559. rldicl r5,r5,32,0
  560. sync
  561. mtspr SPRN_HID4,r5
  562. isync
  563. slbia
  564. isync
  565. stb r3,0(r4)
  566. sync
  567. mtspr SPRN_HID4,r6
  568. isync
  569. slbia
  570. isync
  571. mtmsrd r7
  572. sync
  573. isync
  574. blr
  575. #endif /* defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE) */
  576. /*
  577. * Create a kernel thread
  578. * kernel_thread(fn, arg, flags)
  579. */
  580. _GLOBAL(kernel_thread)
  581. std r29,-24(r1)
  582. std r30,-16(r1)
  583. stdu r1,-STACK_FRAME_OVERHEAD(r1)
  584. mr r29,r3
  585. mr r30,r4
  586. ori r3,r5,CLONE_VM /* flags */
  587. oris r3,r3,(CLONE_UNTRACED>>16)
  588. li r4,0 /* new sp (unused) */
  589. li r0,__NR_clone
  590. sc
  591. cmpdi 0,r3,0 /* parent or child? */
  592. bne 1f /* return if parent */
  593. li r0,0
  594. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  595. ld r2,8(r29)
  596. ld r29,0(r29)
  597. mtlr r29 /* fn addr in lr */
  598. mr r3,r30 /* load arg and call fn */
  599. blrl
  600. li r0,__NR_exit /* exit after child exits */
  601. li r3,0
  602. sc
  603. 1: addi r1,r1,STACK_FRAME_OVERHEAD
  604. ld r29,-24(r1)
  605. ld r30,-16(r1)
  606. blr
  607. /*
  608. * disable_kernel_fp()
  609. * Disable the FPU.
  610. */
  611. _GLOBAL(disable_kernel_fp)
  612. mfmsr r3
  613. rldicl r0,r3,(63-MSR_FP_LG),1
  614. rldicl r3,r0,(MSR_FP_LG+1),0
  615. mtmsrd r3 /* disable use of fpu now */
  616. isync
  617. blr
  618. #ifdef CONFIG_ALTIVEC
  619. #if 0 /* this has no callers for now */
  620. /*
  621. * disable_kernel_altivec()
  622. * Disable the VMX.
  623. */
  624. _GLOBAL(disable_kernel_altivec)
  625. mfmsr r3
  626. rldicl r0,r3,(63-MSR_VEC_LG),1
  627. rldicl r3,r0,(MSR_VEC_LG+1),0
  628. mtmsrd r3 /* disable use of VMX now */
  629. isync
  630. blr
  631. #endif /* 0 */
  632. /*
  633. * giveup_altivec(tsk)
  634. * Disable VMX for the task given as the argument,
  635. * and save the vector registers in its thread_struct.
  636. * Enables the VMX for use in the kernel on return.
  637. */
  638. _GLOBAL(giveup_altivec)
  639. mfmsr r5
  640. oris r5,r5,MSR_VEC@h
  641. mtmsrd r5 /* enable use of VMX now */
  642. isync
  643. cmpdi 0,r3,0
  644. beqlr- /* if no previous owner, done */
  645. addi r3,r3,THREAD /* want THREAD of task */
  646. ld r5,PT_REGS(r3)
  647. cmpdi 0,r5,0
  648. SAVE_32VRS(0,r4,r3)
  649. mfvscr vr0
  650. li r4,THREAD_VSCR
  651. stvx vr0,r4,r3
  652. beq 1f
  653. ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  654. lis r3,MSR_VEC@h
  655. andc r4,r4,r3 /* disable FP for previous task */
  656. std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  657. 1:
  658. #ifndef CONFIG_SMP
  659. li r5,0
  660. ld r4,last_task_used_altivec@got(r2)
  661. std r5,0(r4)
  662. #endif /* CONFIG_SMP */
  663. blr
  664. #endif /* CONFIG_ALTIVEC */
  665. _GLOBAL(__setup_cpu_power3)
  666. blr
  667. _GLOBAL(execve)
  668. li r0,__NR_execve
  669. sc
  670. bnslr
  671. neg r3,r3
  672. blr
  673. /* kexec_wait(phys_cpu)
  674. *
  675. * wait for the flag to change, indicating this kernel is going away but
  676. * the slave code for the next one is at addresses 0 to 100.
  677. *
  678. * This is used by all slaves.
  679. *
  680. * Physical (hardware) cpu id should be in r3.
  681. */
  682. _GLOBAL(kexec_wait)
  683. bl 1f
  684. 1: mflr r5
  685. addi r5,r5,kexec_flag-1b
  686. 99: HMT_LOW
  687. #ifdef CONFIG_KEXEC /* use no memory without kexec */
  688. lwz r4,0(r5)
  689. cmpwi 0,r4,0
  690. bnea 0x60
  691. #endif
  692. b 99b
  693. /* this can be in text because we won't change it until we are
  694. * running in real anyways
  695. */
  696. kexec_flag:
  697. .long 0
  698. #ifdef CONFIG_KEXEC
  699. /* kexec_smp_wait(void)
  700. *
  701. * call with interrupts off
  702. * note: this is a terminal routine, it does not save lr
  703. *
  704. * get phys id from paca
  705. * set paca id to -1 to say we got here
  706. * switch to real mode
  707. * join other cpus in kexec_wait(phys_id)
  708. */
  709. _GLOBAL(kexec_smp_wait)
  710. lhz r3,PACAHWCPUID(r13)
  711. li r4,-1
  712. sth r4,PACAHWCPUID(r13) /* let others know we left */
  713. bl real_mode
  714. b .kexec_wait
  715. /*
  716. * switch to real mode (turn mmu off)
  717. * we use the early kernel trick that the hardware ignores bits
  718. * 0 and 1 (big endian) of the effective address in real mode
  719. *
  720. * don't overwrite r3 here, it is live for kexec_wait above.
  721. */
  722. real_mode: /* assume normal blr return */
  723. 1: li r9,MSR_RI
  724. li r10,MSR_DR|MSR_IR
  725. mflr r11 /* return address to SRR0 */
  726. mfmsr r12
  727. andc r9,r12,r9
  728. andc r10,r12,r10
  729. mtmsrd r9,1
  730. mtspr SPRN_SRR1,r10
  731. mtspr SPRN_SRR0,r11
  732. rfid
  733. /*
  734. * kexec_sequence(newstack, start, image, control, clear_all())
  735. *
  736. * does the grungy work with stack switching and real mode switches
  737. * also does simple calls to other code
  738. */
  739. _GLOBAL(kexec_sequence)
  740. mflr r0
  741. std r0,16(r1)
  742. /* switch stacks to newstack -- &kexec_stack.stack */
  743. stdu r1,THREAD_SIZE-112(r3)
  744. mr r1,r3
  745. li r0,0
  746. std r0,16(r1)
  747. /* save regs for local vars on new stack.
  748. * yes, we won't go back, but ...
  749. */
  750. std r31,-8(r1)
  751. std r30,-16(r1)
  752. std r29,-24(r1)
  753. std r28,-32(r1)
  754. std r27,-40(r1)
  755. std r26,-48(r1)
  756. std r25,-56(r1)
  757. stdu r1,-112-64(r1)
  758. /* save args into preserved regs */
  759. mr r31,r3 /* newstack (both) */
  760. mr r30,r4 /* start (real) */
  761. mr r29,r5 /* image (virt) */
  762. mr r28,r6 /* control, unused */
  763. mr r27,r7 /* clear_all() fn desc */
  764. mr r26,r8 /* spare */
  765. lhz r25,PACAHWCPUID(r13) /* get our phys cpu from paca */
  766. /* disable interrupts, we are overwriting kernel data next */
  767. mfmsr r3
  768. rlwinm r3,r3,0,17,15
  769. mtmsrd r3,1
  770. /* copy dest pages, flush whole dest image */
  771. mr r3,r29
  772. bl .kexec_copy_flush /* (image) */
  773. /* turn off mmu */
  774. bl real_mode
  775. /* clear out hardware hash page table and tlb */
  776. ld r5,0(r27) /* deref function descriptor */
  777. mtctr r5
  778. bctrl /* ppc_md.hash_clear_all(void); */
  779. /*
  780. * kexec image calling is:
  781. * the first 0x100 bytes of the entry point are copied to 0
  782. *
  783. * all slaves branch to slave = 0x60 (absolute)
  784. * slave(phys_cpu_id);
  785. *
  786. * master goes to start = entry point
  787. * start(phys_cpu_id, start, 0);
  788. *
  789. *
  790. * a wrapper is needed to call existing kernels, here is an approximate
  791. * description of one method:
  792. *
  793. * v2: (2.6.10)
  794. * start will be near the boot_block (maybe 0x100 bytes before it?)
  795. * it will have a 0x60, which will b to boot_block, where it will wait
  796. * and 0 will store phys into struct boot-block and load r3 from there,
  797. * copy kernel 0-0x100 and tell slaves to back down to 0x60 again
  798. *
  799. * v1: (2.6.9)
  800. * boot block will have all cpus scanning device tree to see if they
  801. * are the boot cpu ?????
  802. * other device tree differences (prop sizes, va vs pa, etc)...
  803. */
  804. /* copy 0x100 bytes starting at start to 0 */
  805. li r3,0
  806. mr r4,r30
  807. li r5,0x100
  808. li r6,0
  809. bl .copy_and_flush /* (dest, src, copy limit, start offset) */
  810. 1: /* assume normal blr return */
  811. /* release other cpus to the new kernel secondary start at 0x60 */
  812. mflr r5
  813. li r6,1
  814. stw r6,kexec_flag-1b(5)
  815. mr r3,r25 # my phys cpu
  816. mr r4,r30 # start, aka phys mem offset
  817. mtlr 4
  818. li r5,0
  819. blr /* image->start(physid, image->start, 0); */
  820. #endif /* CONFIG_KEXEC */