misc_64.S 19 KB

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