blob: 5606a15cf9a173b39dba6dbbdd8409dd822bdb00 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Rafael J. Wysockic5759122008-02-09 23:24:09 +01002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * 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
10#include <linux/linkage.h>
11#include <asm/segment.h>
Jeremy Fitzhardinge0341c142009-02-13 11:14:01 -080012#include <asm/page_types.h>
Sam Ravnborg86feeaa2005-09-09 19:28:28 +020013#include <asm/asm-offsets.h>
Uros Bizjakc171f462008-08-20 10:44:47 +020014#include <asm/processor-flags.h>
Zhimin Gu8e5b2a32018-09-21 14:26:47 +080015#include <asm/frame.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Uros Bizjakc171f462008-08-20 10:44:47 +020017.text
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Jiri Slaby6d685e52019-10-11 13:51:07 +020019SYM_FUNC_START(swsusp_arch_suspend)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 movl %esp, saved_context_esp
21 movl %ebx, saved_context_ebx
22 movl %ebp, saved_context_ebp
23 movl %esi, saved_context_esi
24 movl %edi, saved_context_edi
Uros Bizjakc171f462008-08-20 10:44:47 +020025 pushfl
26 popl saved_context_eflags
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Zhimin Gu32aa2762018-09-21 14:28:11 +080028 /* save cr3 */
29 movl %cr3, %eax
30 movl %eax, restore_cr3
31
Zhimin Gu8e5b2a32018-09-21 14:26:47 +080032 FRAME_BEGIN
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 call swsusp_save
Zhimin Gu8e5b2a32018-09-21 14:26:47 +080034 FRAME_END
Peter Zijlstraf94909c2021-12-04 14:43:40 +010035 RET
Jiri Slaby6d685e52019-10-11 13:51:07 +020036SYM_FUNC_END(swsusp_arch_suspend)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Jiri Slaby78762b02019-10-11 13:51:05 +020038SYM_CODE_START(restore_image)
Zhimin Gu5331d2c2018-09-21 14:28:32 +080039 /* prepare to jump to the image kernel */
40 movl restore_jump_address, %ebx
Zhimin Gu32aa2762018-09-21 14:28:11 +080041 movl restore_cr3, %ebp
42
Shaohua Li8ae06d22010-03-05 08:59:32 +080043 movl mmu_cr4_features, %ecx
Zhimin Gu6bae4992018-09-21 14:28:22 +080044
45 /* jump to relocated restore code */
46 movl relocated_restore_code, %eax
47 jmpl *%eax
Jiri Slaby78762b02019-10-11 13:51:05 +020048SYM_CODE_END(restore_image)
Zhimin Gu6bae4992018-09-21 14:28:22 +080049
50/* code below has been relocated to a safe page */
Jiri Slaby78762b02019-10-11 13:51:05 +020051SYM_CODE_START(core_restore_code)
Zhimin Gu7c0a9822018-09-21 14:27:51 +080052 movl temp_pgt, %eax
David Friese532c062008-08-17 23:03:40 -050053 movl %eax, %cr3
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Shaohua Li8ae06d22010-03-05 08:59:32 +080055 jecxz 1f # cr4 Pentium and higher, skip if zero
56 andl $~(X86_CR4_PGE), %ecx
57 movl %ecx, %cr4; # turn off PGE
58 movl %cr3, %eax; # flush TLB
59 movl %eax, %cr3
601:
Rafael J. Wysocki75534b52006-09-25 23:32:52 -070061 movl restore_pblist, %edx
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 .p2align 4,,7
63
64copy_loop:
65 testl %edx, %edx
66 jz done
67
68 movl pbe_address(%edx), %esi
69 movl pbe_orig_address(%edx), %edi
70
Zhimin Gu0b0a6b12018-09-21 14:28:01 +080071 movl $(PAGE_SIZE >> 2), %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 rep
73 movsl
74
75 movl pbe_next(%edx), %edx
76 jmp copy_loop
77 .p2align 4,,7
78
79done:
Zhimin Gu5331d2c2018-09-21 14:28:32 +080080 jmpl *%ebx
Jiri Slaby78762b02019-10-11 13:51:05 +020081SYM_CODE_END(core_restore_code)
Zhimin Gu8e5b2a32018-09-21 14:26:47 +080082
83 /* code below belongs to the image kernel */
84 .align PAGE_SIZE
Jiri Slaby6d685e52019-10-11 13:51:07 +020085SYM_FUNC_START(restore_registers)
Rafael J. Wysocki2d4a34c2006-12-06 20:34:29 -080086 /* go back to the original page tables */
Zhimin Gu32aa2762018-09-21 14:28:11 +080087 movl %ebp, %cr3
David Friese532c062008-08-17 23:03:40 -050088 movl mmu_cr4_features, %ecx
89 jecxz 1f # cr4 Pentium and higher, skip if zero
David Friese532c062008-08-17 23:03:40 -050090 movl %ecx, %cr4; # turn PGE back on
911:
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 movl saved_context_esp, %esp
94 movl saved_context_ebp, %ebp
95 movl saved_context_ebx, %ebx
96 movl saved_context_esi, %esi
97 movl saved_context_edi, %edi
98
Uros Bizjakc171f462008-08-20 10:44:47 +020099 pushl saved_context_eflags
100 popfl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Konrad Rzeszutek Wilkcc456c42013-05-01 21:53:30 -0400102 /* Saved in save_processor_state. */
103 movl $saved_context, %eax
104 lgdt saved_context_gdt_desc(%eax)
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 xorl %eax, %eax
107
Zhimin Gu1fca4ba2018-09-21 14:28:41 +0800108 /* tell the hibernation core that we've just restored the memory */
109 movl %eax, in_suspend
110
Peter Zijlstraf94909c2021-12-04 14:43:40 +0100111 RET
Jiri Slaby6d685e52019-10-11 13:51:07 +0200112SYM_FUNC_END(restore_registers)