blob: ad47daeafa4eace0e505c51aae54d43317d62233 [file] [log] [blame]
Rafael J. Wysockic5759122008-02-09 23:24:09 +01001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * This may not use any stack, nor any variable that is not "NoSave":
3 *
4 * Its rewriting one kernel image with another. What is stack in "old"
5 * image could very well be data page in "new" image, and overwriting
6 * your own stack under you is bad idea.
7 */
8
9#include <linux/linkage.h>
10#include <asm/segment.h>
Jeremy Fitzhardinge0341c142009-02-13 11:14:01 -080011#include <asm/page_types.h>
Sam Ravnborg86feeaa2005-09-09 19:28:28 +020012#include <asm/asm-offsets.h>
Uros Bizjakc171f462008-08-20 10:44:47 +020013#include <asm/processor-flags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Uros Bizjakc171f462008-08-20 10:44:47 +020015.text
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17ENTRY(swsusp_arch_suspend)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 movl %esp, saved_context_esp
19 movl %ebx, saved_context_ebx
20 movl %ebp, saved_context_ebp
21 movl %esi, saved_context_esi
22 movl %edi, saved_context_edi
Uros Bizjakc171f462008-08-20 10:44:47 +020023 pushfl
24 popl saved_context_eflags
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26 call swsusp_save
27 ret
28
Rafael J. Wysocki2d4a34c2006-12-06 20:34:29 -080029ENTRY(restore_image)
Shaohua Li8ae06d22010-03-05 08:59:32 +080030 movl mmu_cr4_features, %ecx
David Friese532c062008-08-17 23:03:40 -050031 movl resume_pg_dir, %eax
32 subl $__PAGE_OFFSET, %eax
33 movl %eax, %cr3
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Shaohua Li8ae06d22010-03-05 08:59:32 +080035 jecxz 1f # cr4 Pentium and higher, skip if zero
36 andl $~(X86_CR4_PGE), %ecx
37 movl %ecx, %cr4; # turn off PGE
38 movl %cr3, %eax; # flush TLB
39 movl %eax, %cr3
401:
Rafael J. Wysocki75534b52006-09-25 23:32:52 -070041 movl restore_pblist, %edx
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 .p2align 4,,7
43
44copy_loop:
45 testl %edx, %edx
46 jz done
47
48 movl pbe_address(%edx), %esi
49 movl pbe_orig_address(%edx), %edi
50
51 movl $1024, %ecx
52 rep
53 movsl
54
55 movl pbe_next(%edx), %edx
56 jmp copy_loop
57 .p2align 4,,7
58
59done:
Rafael J. Wysocki2d4a34c2006-12-06 20:34:29 -080060 /* go back to the original page tables */
David Friese532c062008-08-17 23:03:40 -050061 movl $swapper_pg_dir, %eax
62 subl $__PAGE_OFFSET, %eax
63 movl %eax, %cr3
David Friese532c062008-08-17 23:03:40 -050064 movl mmu_cr4_features, %ecx
65 jecxz 1f # cr4 Pentium and higher, skip if zero
David Friese532c062008-08-17 23:03:40 -050066 movl %ecx, %cr4; # turn PGE back on
671:
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69 movl saved_context_esp, %esp
70 movl saved_context_ebp, %ebp
71 movl saved_context_ebx, %ebx
72 movl saved_context_esi, %esi
73 movl saved_context_edi, %edi
74
Uros Bizjakc171f462008-08-20 10:44:47 +020075 pushl saved_context_eflags
76 popfl
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78 xorl %eax, %eax
79
80 ret