hibernate_asm_32.S 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * This may not use any stack, nor any variable that is not "NoSave":
  4. *
  5. * Its rewriting one kernel image with another. What is stack in "old"
  6. * image could very well be data page in "new" image, and overwriting
  7. * your own stack under you is bad idea.
  8. */
  9. #include <linux/linkage.h>
  10. #include <asm/segment.h>
  11. #include <asm/page_types.h>
  12. #include <asm/asm-offsets.h>
  13. #include <asm/processor-flags.h>
  14. .text
  15. ENTRY(swsusp_arch_suspend)
  16. movl %esp, saved_context_esp
  17. movl %ebx, saved_context_ebx
  18. movl %ebp, saved_context_ebp
  19. movl %esi, saved_context_esi
  20. movl %edi, saved_context_edi
  21. pushfl
  22. popl saved_context_eflags
  23. call swsusp_save
  24. ret
  25. ENTRY(restore_image)
  26. movl mmu_cr4_features, %ecx
  27. movl resume_pg_dir, %eax
  28. subl $__PAGE_OFFSET, %eax
  29. movl %eax, %cr3
  30. jecxz 1f # cr4 Pentium and higher, skip if zero
  31. andl $~(X86_CR4_PGE), %ecx
  32. movl %ecx, %cr4; # turn off PGE
  33. movl %cr3, %eax; # flush TLB
  34. movl %eax, %cr3
  35. 1:
  36. movl restore_pblist, %edx
  37. .p2align 4,,7
  38. copy_loop:
  39. testl %edx, %edx
  40. jz done
  41. movl pbe_address(%edx), %esi
  42. movl pbe_orig_address(%edx), %edi
  43. movl $1024, %ecx
  44. rep
  45. movsl
  46. movl pbe_next(%edx), %edx
  47. jmp copy_loop
  48. .p2align 4,,7
  49. done:
  50. /* go back to the original page tables */
  51. movl $swapper_pg_dir, %eax
  52. subl $__PAGE_OFFSET, %eax
  53. movl %eax, %cr3
  54. movl mmu_cr4_features, %ecx
  55. jecxz 1f # cr4 Pentium and higher, skip if zero
  56. movl %ecx, %cr4; # turn PGE back on
  57. 1:
  58. movl saved_context_esp, %esp
  59. movl saved_context_ebp, %ebp
  60. movl saved_context_ebx, %ebx
  61. movl saved_context_esi, %esi
  62. movl saved_context_edi, %edi
  63. pushl saved_context_eflags
  64. popfl
  65. /* Saved in save_processor_state. */
  66. movl $saved_context, %eax
  67. lgdt saved_context_gdt_desc(%eax)
  68. xorl %eax, %eax
  69. ret