wakeup_64.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. .text
  3. #include <linux/linkage.h>
  4. #include <linux/objtool.h>
  5. #include <asm/segment.h>
  6. #include <asm/pgtable_types.h>
  7. #include <asm/page_types.h>
  8. #include <asm/msr.h>
  9. #include <asm/asm-offsets.h>
  10. #include <asm/frame.h>
  11. #include <asm/nospec-branch.h>
  12. # Copyright 2003 Pavel Machek <[email protected]
  13. .code64
  14. /*
  15. * Hooray, we are in Long 64-bit mode (but still running in low memory)
  16. */
  17. SYM_FUNC_START(wakeup_long64)
  18. movq saved_magic, %rax
  19. movq $0x123456789abcdef0, %rdx
  20. cmpq %rdx, %rax
  21. je 2f
  22. /* stop here on a saved_magic mismatch */
  23. movq $0xbad6d61676963, %rcx
  24. 1:
  25. jmp 1b
  26. 2:
  27. movw $__KERNEL_DS, %ax
  28. movw %ax, %ss
  29. movw %ax, %ds
  30. movw %ax, %es
  31. movw %ax, %fs
  32. movw %ax, %gs
  33. movq saved_rsp, %rsp
  34. movq saved_rbx, %rbx
  35. movq saved_rdi, %rdi
  36. movq saved_rsi, %rsi
  37. movq saved_rbp, %rbp
  38. movq saved_rip, %rax
  39. ANNOTATE_RETPOLINE_SAFE
  40. jmp *%rax
  41. SYM_FUNC_END(wakeup_long64)
  42. SYM_FUNC_START(do_suspend_lowlevel)
  43. FRAME_BEGIN
  44. subq $8, %rsp
  45. xorl %eax, %eax
  46. call save_processor_state
  47. movq $saved_context, %rax
  48. movq %rsp, pt_regs_sp(%rax)
  49. movq %rbp, pt_regs_bp(%rax)
  50. movq %rsi, pt_regs_si(%rax)
  51. movq %rdi, pt_regs_di(%rax)
  52. movq %rbx, pt_regs_bx(%rax)
  53. movq %rcx, pt_regs_cx(%rax)
  54. movq %rdx, pt_regs_dx(%rax)
  55. movq %r8, pt_regs_r8(%rax)
  56. movq %r9, pt_regs_r9(%rax)
  57. movq %r10, pt_regs_r10(%rax)
  58. movq %r11, pt_regs_r11(%rax)
  59. movq %r12, pt_regs_r12(%rax)
  60. movq %r13, pt_regs_r13(%rax)
  61. movq %r14, pt_regs_r14(%rax)
  62. movq %r15, pt_regs_r15(%rax)
  63. pushfq
  64. popq pt_regs_flags(%rax)
  65. movq $.Lresume_point, saved_rip(%rip)
  66. movq %rsp, saved_rsp
  67. movq %rbp, saved_rbp
  68. movq %rbx, saved_rbx
  69. movq %rdi, saved_rdi
  70. movq %rsi, saved_rsi
  71. addq $8, %rsp
  72. movl $3, %edi
  73. xorl %eax, %eax
  74. call x86_acpi_enter_sleep_state
  75. /* in case something went wrong, restore the machine status and go on */
  76. jmp .Lresume_point
  77. .align 4
  78. .Lresume_point:
  79. /* We don't restore %rax, it must be 0 anyway */
  80. movq $saved_context, %rax
  81. movq saved_context_cr4(%rax), %rbx
  82. movq %rbx, %cr4
  83. movq saved_context_cr3(%rax), %rbx
  84. movq %rbx, %cr3
  85. movq saved_context_cr2(%rax), %rbx
  86. movq %rbx, %cr2
  87. movq saved_context_cr0(%rax), %rbx
  88. movq %rbx, %cr0
  89. pushq pt_regs_flags(%rax)
  90. popfq
  91. movq pt_regs_sp(%rax), %rsp
  92. movq pt_regs_bp(%rax), %rbp
  93. movq pt_regs_si(%rax), %rsi
  94. movq pt_regs_di(%rax), %rdi
  95. movq pt_regs_bx(%rax), %rbx
  96. movq pt_regs_cx(%rax), %rcx
  97. movq pt_regs_dx(%rax), %rdx
  98. movq pt_regs_r8(%rax), %r8
  99. movq pt_regs_r9(%rax), %r9
  100. movq pt_regs_r10(%rax), %r10
  101. movq pt_regs_r11(%rax), %r11
  102. movq pt_regs_r12(%rax), %r12
  103. movq pt_regs_r13(%rax), %r13
  104. movq pt_regs_r14(%rax), %r14
  105. movq pt_regs_r15(%rax), %r15
  106. #if defined(CONFIG_KASAN) && defined(CONFIG_KASAN_STACK)
  107. /*
  108. * The suspend path may have poisoned some areas deeper in the stack,
  109. * which we now need to unpoison.
  110. */
  111. movq %rsp, %rdi
  112. call kasan_unpoison_task_stack_below
  113. #endif
  114. xorl %eax, %eax
  115. addq $8, %rsp
  116. FRAME_END
  117. jmp restore_processor_state
  118. SYM_FUNC_END(do_suspend_lowlevel)
  119. STACK_FRAME_NON_STANDARD do_suspend_lowlevel
  120. .data
  121. saved_rbp: .quad 0
  122. saved_rsi: .quad 0
  123. saved_rdi: .quad 0
  124. saved_rbx: .quad 0
  125. saved_rip: .quad 0
  126. saved_rsp: .quad 0
  127. SYM_DATA(saved_magic, .quad 0)