misc_64.S 17 KB

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