Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Rafael J. Wysocki | c575912 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 10 | #include <linux/linkage.h> |
| 11 | #include <asm/segment.h> |
Jeremy Fitzhardinge | 0341c14 | 2009-02-13 11:14:01 -0800 | [diff] [blame] | 12 | #include <asm/page_types.h> |
Sam Ravnborg | 86feeaa | 2005-09-09 19:28:28 +0200 | [diff] [blame] | 13 | #include <asm/asm-offsets.h> |
Uros Bizjak | c171f46 | 2008-08-20 10:44:47 +0200 | [diff] [blame] | 14 | #include <asm/processor-flags.h> |
Zhimin Gu | 8e5b2a3 | 2018-09-21 14:26:47 +0800 | [diff] [blame] | 15 | #include <asm/frame.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Uros Bizjak | c171f46 | 2008-08-20 10:44:47 +0200 | [diff] [blame] | 17 | .text |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Jiri Slaby | 6d685e5 | 2019-10-11 13:51:07 +0200 | [diff] [blame] | 19 | SYM_FUNC_START(swsusp_arch_suspend) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | 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 Bizjak | c171f46 | 2008-08-20 10:44:47 +0200 | [diff] [blame] | 25 | pushfl |
| 26 | popl saved_context_eflags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Zhimin Gu | 32aa276 | 2018-09-21 14:28:11 +0800 | [diff] [blame] | 28 | /* save cr3 */ |
| 29 | movl %cr3, %eax |
| 30 | movl %eax, restore_cr3 |
| 31 | |
Zhimin Gu | 8e5b2a3 | 2018-09-21 14:26:47 +0800 | [diff] [blame] | 32 | FRAME_BEGIN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | call swsusp_save |
Zhimin Gu | 8e5b2a3 | 2018-09-21 14:26:47 +0800 | [diff] [blame] | 34 | FRAME_END |
Peter Zijlstra | f94909c | 2021-12-04 14:43:40 +0100 | [diff] [blame] | 35 | RET |
Jiri Slaby | 6d685e5 | 2019-10-11 13:51:07 +0200 | [diff] [blame] | 36 | SYM_FUNC_END(swsusp_arch_suspend) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Jiri Slaby | 78762b0 | 2019-10-11 13:51:05 +0200 | [diff] [blame] | 38 | SYM_CODE_START(restore_image) |
Zhimin Gu | 5331d2c | 2018-09-21 14:28:32 +0800 | [diff] [blame] | 39 | /* prepare to jump to the image kernel */ |
| 40 | movl restore_jump_address, %ebx |
Zhimin Gu | 32aa276 | 2018-09-21 14:28:11 +0800 | [diff] [blame] | 41 | movl restore_cr3, %ebp |
| 42 | |
Shaohua Li | 8ae06d2 | 2010-03-05 08:59:32 +0800 | [diff] [blame] | 43 | movl mmu_cr4_features, %ecx |
Zhimin Gu | 6bae499 | 2018-09-21 14:28:22 +0800 | [diff] [blame] | 44 | |
| 45 | /* jump to relocated restore code */ |
| 46 | movl relocated_restore_code, %eax |
| 47 | jmpl *%eax |
Jiri Slaby | 78762b0 | 2019-10-11 13:51:05 +0200 | [diff] [blame] | 48 | SYM_CODE_END(restore_image) |
Zhimin Gu | 6bae499 | 2018-09-21 14:28:22 +0800 | [diff] [blame] | 49 | |
| 50 | /* code below has been relocated to a safe page */ |
Jiri Slaby | 78762b0 | 2019-10-11 13:51:05 +0200 | [diff] [blame] | 51 | SYM_CODE_START(core_restore_code) |
Zhimin Gu | 7c0a982 | 2018-09-21 14:27:51 +0800 | [diff] [blame] | 52 | movl temp_pgt, %eax |
David Fries | e532c06 | 2008-08-17 23:03:40 -0500 | [diff] [blame] | 53 | movl %eax, %cr3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Shaohua Li | 8ae06d2 | 2010-03-05 08:59:32 +0800 | [diff] [blame] | 55 | 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 |
| 60 | 1: |
Rafael J. Wysocki | 75534b5 | 2006-09-25 23:32:52 -0700 | [diff] [blame] | 61 | movl restore_pblist, %edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | .p2align 4,,7 |
| 63 | |
| 64 | copy_loop: |
| 65 | testl %edx, %edx |
| 66 | jz done |
| 67 | |
| 68 | movl pbe_address(%edx), %esi |
| 69 | movl pbe_orig_address(%edx), %edi |
| 70 | |
Zhimin Gu | 0b0a6b1 | 2018-09-21 14:28:01 +0800 | [diff] [blame] | 71 | movl $(PAGE_SIZE >> 2), %ecx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | rep |
| 73 | movsl |
| 74 | |
| 75 | movl pbe_next(%edx), %edx |
| 76 | jmp copy_loop |
| 77 | .p2align 4,,7 |
| 78 | |
| 79 | done: |
Zhimin Gu | 5331d2c | 2018-09-21 14:28:32 +0800 | [diff] [blame] | 80 | jmpl *%ebx |
Jiri Slaby | 78762b0 | 2019-10-11 13:51:05 +0200 | [diff] [blame] | 81 | SYM_CODE_END(core_restore_code) |
Zhimin Gu | 8e5b2a3 | 2018-09-21 14:26:47 +0800 | [diff] [blame] | 82 | |
| 83 | /* code below belongs to the image kernel */ |
| 84 | .align PAGE_SIZE |
Jiri Slaby | 6d685e5 | 2019-10-11 13:51:07 +0200 | [diff] [blame] | 85 | SYM_FUNC_START(restore_registers) |
Rafael J. Wysocki | 2d4a34c | 2006-12-06 20:34:29 -0800 | [diff] [blame] | 86 | /* go back to the original page tables */ |
Zhimin Gu | 32aa276 | 2018-09-21 14:28:11 +0800 | [diff] [blame] | 87 | movl %ebp, %cr3 |
David Fries | e532c06 | 2008-08-17 23:03:40 -0500 | [diff] [blame] | 88 | movl mmu_cr4_features, %ecx |
| 89 | jecxz 1f # cr4 Pentium and higher, skip if zero |
David Fries | e532c06 | 2008-08-17 23:03:40 -0500 | [diff] [blame] | 90 | movl %ecx, %cr4; # turn PGE back on |
| 91 | 1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 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 Bizjak | c171f46 | 2008-08-20 10:44:47 +0200 | [diff] [blame] | 99 | pushl saved_context_eflags |
| 100 | popfl |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Konrad Rzeszutek Wilk | cc456c4 | 2013-05-01 21:53:30 -0400 | [diff] [blame] | 102 | /* Saved in save_processor_state. */ |
| 103 | movl $saved_context, %eax |
| 104 | lgdt saved_context_gdt_desc(%eax) |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | xorl %eax, %eax |
| 107 | |
Zhimin Gu | 1fca4ba | 2018-09-21 14:28:41 +0800 | [diff] [blame] | 108 | /* tell the hibernation core that we've just restored the memory */ |
| 109 | movl %eax, in_suspend |
| 110 | |
Peter Zijlstra | f94909c | 2021-12-04 14:43:40 +0100 | [diff] [blame] | 111 | RET |
Jiri Slaby | 6d685e5 | 2019-10-11 13:51:07 +0200 | [diff] [blame] | 112 | SYM_FUNC_END(restore_registers) |