misc.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  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. * SCOM access functions for 970 (FX only for now)
  553. *
  554. * unsigned long scom970_read(unsigned int address);
  555. * void scom970_write(unsigned int address, unsigned long value);
  556. *
  557. * The address passed in is the 24 bits register address. This code
  558. * is 970 specific and will not check the status bits, so you should
  559. * know what you are doing.
  560. */
  561. _GLOBAL(scom970_read)
  562. /* interrupts off */
  563. mfmsr r4
  564. ori r0,r4,MSR_EE
  565. xori r0,r0,MSR_EE
  566. mtmsrd r0,1
  567. /* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
  568. * (including parity). On current CPUs they must be 0'd,
  569. * and finally or in RW bit
  570. */
  571. rlwinm r3,r3,8,0,15
  572. ori r3,r3,0x8000
  573. /* do the actual scom read */
  574. sync
  575. mtspr SPRN_SCOMC,r3
  576. isync
  577. mfspr r3,SPRN_SCOMD
  578. isync
  579. mfspr r0,SPRN_SCOMC
  580. isync
  581. /* XXX: fixup result on some buggy 970's (ouch ! we lost a bit, bah
  582. * that's the best we can do). Not implemented yet as we don't use
  583. * the scom on any of the bogus CPUs yet, but may have to be done
  584. * ultimately
  585. */
  586. /* restore interrupts */
  587. mtmsrd r4,1
  588. blr
  589. _GLOBAL(scom970_write)
  590. /* interrupts off */
  591. mfmsr r5
  592. ori r0,r5,MSR_EE
  593. xori r0,r0,MSR_EE
  594. mtmsrd r0,1
  595. /* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
  596. * (including parity). On current CPUs they must be 0'd.
  597. */
  598. rlwinm r3,r3,8,0,15
  599. sync
  600. mtspr SPRN_SCOMD,r4 /* write data */
  601. isync
  602. mtspr SPRN_SCOMC,r3 /* write command */
  603. isync
  604. mfspr 3,SPRN_SCOMC
  605. isync
  606. /* restore interrupts */
  607. mtmsrd r5,1
  608. blr
  609. /*
  610. * Create a kernel thread
  611. * kernel_thread(fn, arg, flags)
  612. */
  613. _GLOBAL(kernel_thread)
  614. std r29,-24(r1)
  615. std r30,-16(r1)
  616. stdu r1,-STACK_FRAME_OVERHEAD(r1)
  617. mr r29,r3
  618. mr r30,r4
  619. ori r3,r5,CLONE_VM /* flags */
  620. oris r3,r3,(CLONE_UNTRACED>>16)
  621. li r4,0 /* new sp (unused) */
  622. li r0,__NR_clone
  623. sc
  624. cmpdi 0,r3,0 /* parent or child? */
  625. bne 1f /* return if parent */
  626. li r0,0
  627. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  628. ld r2,8(r29)
  629. ld r29,0(r29)
  630. mtlr r29 /* fn addr in lr */
  631. mr r3,r30 /* load arg and call fn */
  632. blrl
  633. li r0,__NR_exit /* exit after child exits */
  634. li r3,0
  635. sc
  636. 1: addi r1,r1,STACK_FRAME_OVERHEAD
  637. ld r29,-24(r1)
  638. ld r30,-16(r1)
  639. blr
  640. /*
  641. * disable_kernel_fp()
  642. * Disable the FPU.
  643. */
  644. _GLOBAL(disable_kernel_fp)
  645. mfmsr r3
  646. rldicl r0,r3,(63-MSR_FP_LG),1
  647. rldicl r3,r0,(MSR_FP_LG+1),0
  648. mtmsrd r3 /* disable use of fpu now */
  649. isync
  650. blr
  651. #ifdef CONFIG_ALTIVEC
  652. #if 0 /* this has no callers for now */
  653. /*
  654. * disable_kernel_altivec()
  655. * Disable the VMX.
  656. */
  657. _GLOBAL(disable_kernel_altivec)
  658. mfmsr r3
  659. rldicl r0,r3,(63-MSR_VEC_LG),1
  660. rldicl r3,r0,(MSR_VEC_LG+1),0
  661. mtmsrd r3 /* disable use of VMX now */
  662. isync
  663. blr
  664. #endif /* 0 */
  665. /*
  666. * giveup_altivec(tsk)
  667. * Disable VMX for the task given as the argument,
  668. * and save the vector registers in its thread_struct.
  669. * Enables the VMX for use in the kernel on return.
  670. */
  671. _GLOBAL(giveup_altivec)
  672. mfmsr r5
  673. oris r5,r5,MSR_VEC@h
  674. mtmsrd r5 /* enable use of VMX now */
  675. isync
  676. cmpdi 0,r3,0
  677. beqlr- /* if no previous owner, done */
  678. addi r3,r3,THREAD /* want THREAD of task */
  679. ld r5,PT_REGS(r3)
  680. cmpdi 0,r5,0
  681. SAVE_32VRS(0,r4,r3)
  682. mfvscr vr0
  683. li r4,THREAD_VSCR
  684. stvx vr0,r4,r3
  685. beq 1f
  686. ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  687. lis r3,MSR_VEC@h
  688. andc r4,r4,r3 /* disable FP for previous task */
  689. std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  690. 1:
  691. #ifndef CONFIG_SMP
  692. li r5,0
  693. ld r4,last_task_used_altivec@got(r2)
  694. std r5,0(r4)
  695. #endif /* CONFIG_SMP */
  696. blr
  697. #endif /* CONFIG_ALTIVEC */
  698. _GLOBAL(__setup_cpu_power3)
  699. blr
  700. _GLOBAL(execve)
  701. li r0,__NR_execve
  702. sc
  703. bnslr
  704. neg r3,r3
  705. blr
  706. /* kexec_wait(phys_cpu)
  707. *
  708. * wait for the flag to change, indicating this kernel is going away but
  709. * the slave code for the next one is at addresses 0 to 100.
  710. *
  711. * This is used by all slaves.
  712. *
  713. * Physical (hardware) cpu id should be in r3.
  714. */
  715. _GLOBAL(kexec_wait)
  716. bl 1f
  717. 1: mflr r5
  718. addi r5,r5,kexec_flag-1b
  719. 99: HMT_LOW
  720. #ifdef CONFIG_KEXEC /* use no memory without kexec */
  721. lwz r4,0(r5)
  722. cmpwi 0,r4,0
  723. bnea 0x60
  724. #endif
  725. b 99b
  726. /* this can be in text because we won't change it until we are
  727. * running in real anyways
  728. */
  729. kexec_flag:
  730. .long 0
  731. #ifdef CONFIG_KEXEC
  732. /* kexec_smp_wait(void)
  733. *
  734. * call with interrupts off
  735. * note: this is a terminal routine, it does not save lr
  736. *
  737. * get phys id from paca
  738. * set paca id to -1 to say we got here
  739. * switch to real mode
  740. * join other cpus in kexec_wait(phys_id)
  741. */
  742. _GLOBAL(kexec_smp_wait)
  743. lhz r3,PACAHWCPUID(r13)
  744. li r4,-1
  745. sth r4,PACAHWCPUID(r13) /* let others know we left */
  746. bl real_mode
  747. b .kexec_wait
  748. /*
  749. * switch to real mode (turn mmu off)
  750. * we use the early kernel trick that the hardware ignores bits
  751. * 0 and 1 (big endian) of the effective address in real mode
  752. *
  753. * don't overwrite r3 here, it is live for kexec_wait above.
  754. */
  755. real_mode: /* assume normal blr return */
  756. 1: li r9,MSR_RI
  757. li r10,MSR_DR|MSR_IR
  758. mflr r11 /* return address to SRR0 */
  759. mfmsr r12
  760. andc r9,r12,r9
  761. andc r10,r12,r10
  762. mtmsrd r9,1
  763. mtspr SPRN_SRR1,r10
  764. mtspr SPRN_SRR0,r11
  765. rfid
  766. /*
  767. * kexec_sequence(newstack, start, image, control, clear_all())
  768. *
  769. * does the grungy work with stack switching and real mode switches
  770. * also does simple calls to other code
  771. */
  772. _GLOBAL(kexec_sequence)
  773. mflr r0
  774. std r0,16(r1)
  775. /* switch stacks to newstack -- &kexec_stack.stack */
  776. stdu r1,THREAD_SIZE-112(r3)
  777. mr r1,r3
  778. li r0,0
  779. std r0,16(r1)
  780. /* save regs for local vars on new stack.
  781. * yes, we won't go back, but ...
  782. */
  783. std r31,-8(r1)
  784. std r30,-16(r1)
  785. std r29,-24(r1)
  786. std r28,-32(r1)
  787. std r27,-40(r1)
  788. std r26,-48(r1)
  789. std r25,-56(r1)
  790. stdu r1,-112-64(r1)
  791. /* save args into preserved regs */
  792. mr r31,r3 /* newstack (both) */
  793. mr r30,r4 /* start (real) */
  794. mr r29,r5 /* image (virt) */
  795. mr r28,r6 /* control, unused */
  796. mr r27,r7 /* clear_all() fn desc */
  797. mr r26,r8 /* spare */
  798. lhz r25,PACAHWCPUID(r13) /* get our phys cpu from paca */
  799. /* disable interrupts, we are overwriting kernel data next */
  800. mfmsr r3
  801. rlwinm r3,r3,0,17,15
  802. mtmsrd r3,1
  803. /* copy dest pages, flush whole dest image */
  804. mr r3,r29
  805. bl .kexec_copy_flush /* (image) */
  806. /* turn off mmu */
  807. bl real_mode
  808. /* clear out hardware hash page table and tlb */
  809. ld r5,0(r27) /* deref function descriptor */
  810. mtctr r5
  811. bctrl /* ppc_md.hash_clear_all(void); */
  812. /*
  813. * kexec image calling is:
  814. * the first 0x100 bytes of the entry point are copied to 0
  815. *
  816. * all slaves branch to slave = 0x60 (absolute)
  817. * slave(phys_cpu_id);
  818. *
  819. * master goes to start = entry point
  820. * start(phys_cpu_id, start, 0);
  821. *
  822. *
  823. * a wrapper is needed to call existing kernels, here is an approximate
  824. * description of one method:
  825. *
  826. * v2: (2.6.10)
  827. * start will be near the boot_block (maybe 0x100 bytes before it?)
  828. * it will have a 0x60, which will b to boot_block, where it will wait
  829. * and 0 will store phys into struct boot-block and load r3 from there,
  830. * copy kernel 0-0x100 and tell slaves to back down to 0x60 again
  831. *
  832. * v1: (2.6.9)
  833. * boot block will have all cpus scanning device tree to see if they
  834. * are the boot cpu ?????
  835. * other device tree differences (prop sizes, va vs pa, etc)...
  836. */
  837. /* copy 0x100 bytes starting at start to 0 */
  838. li r3,0
  839. mr r4,r30
  840. li r5,0x100
  841. li r6,0
  842. bl .copy_and_flush /* (dest, src, copy limit, start offset) */
  843. 1: /* assume normal blr return */
  844. /* release other cpus to the new kernel secondary start at 0x60 */
  845. mflr r5
  846. li r6,1
  847. stw r6,kexec_flag-1b(5)
  848. mr r3,r25 # my phys cpu
  849. mr r4,r30 # start, aka phys mem offset
  850. mtlr 4
  851. li r5,0
  852. blr /* image->start(physid, image->start, 0); */
  853. #endif /* CONFIG_KEXEC */