hibernate_asm_64.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Hibernation support for x86-64
  3. *
  4. * Distribute under GPLv2.
  5. *
  6. * Copyright 2007 Rafael J. Wysocki <rjw@sisk.pl>
  7. * Copyright 2005 Andi Kleen <ak@suse.de>
  8. * Copyright 2004 Pavel Machek <pavel@suse.cz>
  9. *
  10. * swsusp_arch_resume must not use any stack or any nonlocal variables while
  11. * copying pages:
  12. *
  13. * Its rewriting one kernel image with another. What is stack in "old"
  14. * image could very well be data page in "new" image, and overwriting
  15. * your own stack under you is bad idea.
  16. */
  17. .text
  18. #include <linux/linkage.h>
  19. #include <asm/segment.h>
  20. #include <asm/page.h>
  21. #include <asm/asm-offsets.h>
  22. ENTRY(swsusp_arch_suspend)
  23. movq $saved_context, %rax
  24. movq %rsp, pt_regs_sp(%rax)
  25. movq %rbp, pt_regs_bp(%rax)
  26. movq %rsi, pt_regs_si(%rax)
  27. movq %rdi, pt_regs_di(%rax)
  28. movq %rbx, pt_regs_bx(%rax)
  29. movq %rcx, pt_regs_cx(%rax)
  30. movq %rdx, pt_regs_dx(%rax)
  31. movq %r8, pt_regs_r8(%rax)
  32. movq %r9, pt_regs_r9(%rax)
  33. movq %r10, pt_regs_r10(%rax)
  34. movq %r11, pt_regs_r11(%rax)
  35. movq %r12, pt_regs_r12(%rax)
  36. movq %r13, pt_regs_r13(%rax)
  37. movq %r14, pt_regs_r14(%rax)
  38. movq %r15, pt_regs_r15(%rax)
  39. pushfq
  40. popq pt_regs_flags(%rax)
  41. /* save the address of restore_registers */
  42. movq $restore_registers, %rax
  43. movq %rax, restore_jump_address(%rip)
  44. /* save cr3 */
  45. movq %cr3, %rax
  46. movq %rax, restore_cr3(%rip)
  47. call swsusp_save
  48. ret
  49. ENTRY(restore_image)
  50. /* switch to temporary page tables */
  51. movq $__PAGE_OFFSET, %rdx
  52. movq temp_level4_pgt(%rip), %rax
  53. subq %rdx, %rax
  54. movq %rax, %cr3
  55. /* Flush TLB */
  56. movq mmu_cr4_features(%rip), %rax
  57. movq %rax, %rdx
  58. andq $~(1<<7), %rdx # PGE
  59. movq %rdx, %cr4; # turn off PGE
  60. movq %cr3, %rcx; # flush TLB
  61. movq %rcx, %cr3;
  62. movq %rax, %cr4; # turn PGE back on
  63. /* prepare to jump to the image kernel */
  64. movq restore_jump_address(%rip), %rax
  65. movq restore_cr3(%rip), %rbx
  66. /* prepare to copy image data to their original locations */
  67. movq restore_pblist(%rip), %rdx
  68. movq relocated_restore_code(%rip), %rcx
  69. jmpq *%rcx
  70. /* code below has been relocated to a safe page */
  71. ENTRY(core_restore_code)
  72. loop:
  73. testq %rdx, %rdx
  74. jz done
  75. /* get addresses from the pbe and copy the page */
  76. movq pbe_address(%rdx), %rsi
  77. movq pbe_orig_address(%rdx), %rdi
  78. movq $(PAGE_SIZE >> 3), %rcx
  79. rep
  80. movsq
  81. /* progress to the next pbe */
  82. movq pbe_next(%rdx), %rdx
  83. jmp loop
  84. done:
  85. /* jump to the restore_registers address from the image header */
  86. jmpq *%rax
  87. /*
  88. * NOTE: This assumes that the boot kernel's text mapping covers the
  89. * image kernel's page containing restore_registers and the address of
  90. * this page is the same as in the image kernel's text mapping (it
  91. * should always be true, because the text mapping is linear, starting
  92. * from 0, and is supposed to cover the entire kernel text for every
  93. * kernel).
  94. *
  95. * code below belongs to the image kernel
  96. */
  97. ENTRY(restore_registers)
  98. /* go back to the original page tables */
  99. movq %rbx, %cr3
  100. /* Flush TLB, including "global" things (vmalloc) */
  101. movq mmu_cr4_features(%rip), %rax
  102. movq %rax, %rdx
  103. andq $~(1<<7), %rdx; # PGE
  104. movq %rdx, %cr4; # turn off PGE
  105. movq %cr3, %rcx; # flush TLB
  106. movq %rcx, %cr3
  107. movq %rax, %cr4; # turn PGE back on
  108. /* We don't restore %rax, it must be 0 anyway */
  109. movq $saved_context, %rax
  110. movq pt_regs_sp(%rax), %rsp
  111. movq pt_regs_bp(%rax), %rbp
  112. movq pt_regs_si(%rax), %rsi
  113. movq pt_regs_di(%rax), %rdi
  114. movq pt_regs_bx(%rax), %rbx
  115. movq pt_regs_cx(%rax), %rcx
  116. movq pt_regs_dx(%rax), %rdx
  117. movq pt_regs_r8(%rax), %r8
  118. movq pt_regs_r9(%rax), %r9
  119. movq pt_regs_r10(%rax), %r10
  120. movq pt_regs_r11(%rax), %r11
  121. movq pt_regs_r12(%rax), %r12
  122. movq pt_regs_r13(%rax), %r13
  123. movq pt_regs_r14(%rax), %r14
  124. movq pt_regs_r15(%rax), %r15
  125. pushq pt_regs_flags(%rax)
  126. popfq
  127. xorq %rax, %rax
  128. /* tell the hibernation core that we've just restored the memory */
  129. movq %rax, in_suspend(%rip)
  130. ret