hibernate_asm_64.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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_types.h>
  21. #include <asm/asm-offsets.h>
  22. #include <asm/processor-flags.h>
  23. #include <asm/frame.h>
  24. ENTRY(swsusp_arch_suspend)
  25. movq $saved_context, %rax
  26. movq %rsp, pt_regs_sp(%rax)
  27. movq %rbp, pt_regs_bp(%rax)
  28. movq %rsi, pt_regs_si(%rax)
  29. movq %rdi, pt_regs_di(%rax)
  30. movq %rbx, pt_regs_bx(%rax)
  31. movq %rcx, pt_regs_cx(%rax)
  32. movq %rdx, pt_regs_dx(%rax)
  33. movq %r8, pt_regs_r8(%rax)
  34. movq %r9, pt_regs_r9(%rax)
  35. movq %r10, pt_regs_r10(%rax)
  36. movq %r11, pt_regs_r11(%rax)
  37. movq %r12, pt_regs_r12(%rax)
  38. movq %r13, pt_regs_r13(%rax)
  39. movq %r14, pt_regs_r14(%rax)
  40. movq %r15, pt_regs_r15(%rax)
  41. pushfq
  42. popq pt_regs_flags(%rax)
  43. /* save cr3 */
  44. movq %cr3, %rax
  45. movq %rax, restore_cr3(%rip)
  46. FRAME_BEGIN
  47. call swsusp_save
  48. FRAME_END
  49. ret
  50. ENDPROC(swsusp_arch_suspend)
  51. ENTRY(restore_image)
  52. /* prepare to jump to the image kernel */
  53. movq restore_jump_address(%rip), %r8
  54. movq restore_cr3(%rip), %r9
  55. /* prepare to switch to temporary page tables */
  56. movq temp_level4_pgt(%rip), %rax
  57. movq mmu_cr4_features(%rip), %rbx
  58. /* prepare to copy image data to their original locations */
  59. movq restore_pblist(%rip), %rdx
  60. /* jump to relocated restore code */
  61. movq relocated_restore_code(%rip), %rcx
  62. jmpq *%rcx
  63. /* code below has been relocated to a safe page */
  64. ENTRY(core_restore_code)
  65. /* switch to temporary page tables */
  66. movq %rax, %cr3
  67. /* flush TLB */
  68. movq %rbx, %rcx
  69. andq $~(X86_CR4_PGE), %rcx
  70. movq %rcx, %cr4; # turn off PGE
  71. movq %cr3, %rcx; # flush TLB
  72. movq %rcx, %cr3;
  73. movq %rbx, %cr4; # turn PGE back on
  74. .Lloop:
  75. testq %rdx, %rdx
  76. jz .Ldone
  77. /* get addresses from the pbe and copy the page */
  78. movq pbe_address(%rdx), %rsi
  79. movq pbe_orig_address(%rdx), %rdi
  80. movq $(PAGE_SIZE >> 3), %rcx
  81. rep
  82. movsq
  83. /* progress to the next pbe */
  84. movq pbe_next(%rdx), %rdx
  85. jmp .Lloop
  86. .Ldone:
  87. /* jump to the restore_registers address from the image header */
  88. jmpq *%r8
  89. /* code below belongs to the image kernel */
  90. .align PAGE_SIZE
  91. ENTRY(restore_registers)
  92. /* go back to the original page tables */
  93. movq %r9, %cr3
  94. /* Flush TLB, including "global" things (vmalloc) */
  95. movq mmu_cr4_features(%rip), %rax
  96. movq %rax, %rdx
  97. andq $~(X86_CR4_PGE), %rdx
  98. movq %rdx, %cr4; # turn off PGE
  99. movq %cr3, %rcx; # flush TLB
  100. movq %rcx, %cr3
  101. movq %rax, %cr4; # turn PGE back on
  102. /* We don't restore %rax, it must be 0 anyway */
  103. movq $saved_context, %rax
  104. movq pt_regs_sp(%rax), %rsp
  105. movq pt_regs_bp(%rax), %rbp
  106. movq pt_regs_si(%rax), %rsi
  107. movq pt_regs_di(%rax), %rdi
  108. movq pt_regs_bx(%rax), %rbx
  109. movq pt_regs_cx(%rax), %rcx
  110. movq pt_regs_dx(%rax), %rdx
  111. movq pt_regs_r8(%rax), %r8
  112. movq pt_regs_r9(%rax), %r9
  113. movq pt_regs_r10(%rax), %r10
  114. movq pt_regs_r11(%rax), %r11
  115. movq pt_regs_r12(%rax), %r12
  116. movq pt_regs_r13(%rax), %r13
  117. movq pt_regs_r14(%rax), %r14
  118. movq pt_regs_r15(%rax), %r15
  119. pushq pt_regs_flags(%rax)
  120. popfq
  121. /* Saved in save_processor_state. */
  122. lgdt saved_context_gdt_desc(%rax)
  123. xorq %rax, %rax
  124. /* tell the hibernation core that we've just restored the memory */
  125. movq %rax, in_suspend(%rip)
  126. ret
  127. ENDPROC(restore_registers)