misc_64.S 15 KB

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