misc_64.S 18 KB

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