Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* Copyright 2004,2005 Pavel Machek <pavel@suse.cz>, Andi Kleen <ak@suse.de>, Rafael J. Wysocki <rjw@sisk.pl> |
2 | * | |
3 | * Distribute under GPLv2. | |
4 | * | |
5 | * swsusp_arch_resume may not use any stack, nor any variable that is | |
6 | * not "NoSave" during copying pages: | |
7 | * | |
8 | * Its rewriting one kernel image with another. What is stack in "old" | |
9 | * image could very well be data page in "new" image, and overwriting | |
10 | * your own stack under you is bad idea. | |
11 | */ | |
12 | ||
13 | .text | |
14 | #include <linux/linkage.h> | |
15 | #include <asm/segment.h> | |
16 | #include <asm/page.h> | |
e2d5df93 | 17 | #include <asm/asm-offsets.h> |
1da177e4 LT |
18 | |
19 | ENTRY(swsusp_arch_suspend) | |
20 | ||
21 | movq %rsp, saved_context_esp(%rip) | |
22 | movq %rax, saved_context_eax(%rip) | |
23 | movq %rbx, saved_context_ebx(%rip) | |
24 | movq %rcx, saved_context_ecx(%rip) | |
25 | movq %rdx, saved_context_edx(%rip) | |
26 | movq %rbp, saved_context_ebp(%rip) | |
27 | movq %rsi, saved_context_esi(%rip) | |
28 | movq %rdi, saved_context_edi(%rip) | |
29 | movq %r8, saved_context_r08(%rip) | |
30 | movq %r9, saved_context_r09(%rip) | |
31 | movq %r10, saved_context_r10(%rip) | |
32 | movq %r11, saved_context_r11(%rip) | |
33 | movq %r12, saved_context_r12(%rip) | |
34 | movq %r13, saved_context_r13(%rip) | |
35 | movq %r14, saved_context_r14(%rip) | |
36 | movq %r15, saved_context_r15(%rip) | |
37 | pushfq ; popq saved_context_eflags(%rip) | |
38 | ||
39 | call swsusp_save | |
40 | ret | |
41 | ||
42 | ENTRY(swsusp_arch_resume) | |
43 | /* set up cr3 */ | |
44 | leaq init_level4_pgt(%rip),%rax | |
45 | subq $__START_KERNEL_map,%rax | |
46 | movq %rax,%cr3 | |
47 | ||
48 | movq mmu_cr4_features(%rip), %rax | |
49 | movq %rax, %rdx | |
50 | andq $~(1<<7), %rdx # PGE | |
51 | movq %rdx, %cr4; # turn off PGE | |
52 | movq %cr3, %rcx; # flush TLB | |
53 | movq %rcx, %cr3; | |
54 | movq %rax, %cr4; # turn PGE back on | |
55 | ||
56 | movq pagedir_nosave(%rip), %rdx | |
57 | loop: | |
58 | testq %rdx, %rdx | |
59 | jz done | |
60 | ||
61 | /* get addresses from the pbe and copy the page */ | |
62 | movq pbe_address(%rdx), %rsi | |
63 | movq pbe_orig_address(%rdx), %rdi | |
64 | movq $512, %rcx | |
65 | rep | |
66 | movsq | |
67 | ||
68 | /* progress to the next pbe */ | |
69 | movq pbe_next(%rdx), %rdx | |
70 | jmp loop | |
71 | done: | |
72 | /* Flush TLB, including "global" things (vmalloc) */ | |
73 | movq mmu_cr4_features(%rip), %rax | |
74 | movq %rax, %rdx | |
75 | andq $~(1<<7), %rdx; # PGE | |
76 | movq %rdx, %cr4; # turn off PGE | |
77 | movq %cr3, %rcx; # flush TLB | |
78 | movq %rcx, %cr3 | |
79 | movq %rax, %cr4; # turn PGE back on | |
80 | ||
81 | movl $24, %eax | |
82 | movl %eax, %ds | |
83 | ||
84 | movq saved_context_esp(%rip), %rsp | |
85 | movq saved_context_ebp(%rip), %rbp | |
86 | /* Don't restore %rax, it must be 0 anyway */ | |
87 | movq saved_context_ebx(%rip), %rbx | |
88 | movq saved_context_ecx(%rip), %rcx | |
89 | movq saved_context_edx(%rip), %rdx | |
90 | movq saved_context_esi(%rip), %rsi | |
91 | movq saved_context_edi(%rip), %rdi | |
92 | movq saved_context_r08(%rip), %r8 | |
93 | movq saved_context_r09(%rip), %r9 | |
94 | movq saved_context_r10(%rip), %r10 | |
95 | movq saved_context_r11(%rip), %r11 | |
96 | movq saved_context_r12(%rip), %r12 | |
97 | movq saved_context_r13(%rip), %r13 | |
98 | movq saved_context_r14(%rip), %r14 | |
99 | movq saved_context_r15(%rip), %r15 | |
100 | pushq saved_context_eflags(%rip) ; popfq | |
101 | ||
102 | xorq %rax, %rax | |
103 | ||
104 | ret |