misc.S 17 KB

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