1 /* Copyright 2004,2005 Pavel Machek <pavel@suse.cz>, Andi Kleen <ak@suse.de>, Rafael J. Wysocki <rjw@sisk.pl>
3 * Distribute under GPLv2.
5 * swsusp_arch_resume must not use any stack or any nonlocal variables while
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.
14 #include <linux/linkage.h>
15 #include <asm/segment.h>
17 #include <asm/asm-offsets.h>
19 ENTRY(swsusp_arch_suspend)
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)
39 /* save the address of restore_registers */
40 movq $restore_registers, %rax
41 movq %rax, restore_jump_address(%rip)
44 movq %rax, restore_cr3(%rip)
50 /* switch to temporary page tables */
51 movq $__PAGE_OFFSET, %rdx
52 movq temp_level4_pgt(%rip), %rax
56 movq mmu_cr4_features(%rip), %rax
58 andq $~(1<<7), %rdx # PGE
59 movq %rdx, %cr4; # turn off PGE
60 movq %cr3, %rcx; # flush TLB
62 movq %rax, %cr4; # turn PGE back on
64 /* prepare to jump to the image kernel */
65 movq restore_jump_address(%rip), %rax
66 movq restore_cr3(%rip), %rbx
68 /* prepare to copy image data to their original locations */
69 movq restore_pblist(%rip), %rdx
70 movq relocated_restore_code(%rip), %rcx
73 /* code below has been relocated to a safe page */
74 ENTRY(core_restore_code)
79 /* get addresses from the pbe and copy the page */
80 movq pbe_address(%rdx), %rsi
81 movq pbe_orig_address(%rdx), %rdi
82 movq $(PAGE_SIZE >> 3), %rcx
86 /* progress to the next pbe */
87 movq pbe_next(%rdx), %rdx
90 /* jump to the restore_registers address from the image header */
93 * NOTE: This assumes that the boot kernel's text mapping covers the
94 * image kernel's page containing restore_registers and the address of
95 * this page is the same as in the image kernel's text mapping (it
96 * should always be true, because the text mapping is linear, starting
97 * from 0, and is supposed to cover the entire kernel text for every
100 * code below belongs to the image kernel
103 ENTRY(restore_registers)
104 /* go back to the original page tables */
107 /* Flush TLB, including "global" things (vmalloc) */
108 movq mmu_cr4_features(%rip), %rax
110 andq $~(1<<7), %rdx; # PGE
111 movq %rdx, %cr4; # turn off PGE
112 movq %cr3, %rcx; # flush TLB
114 movq %rax, %cr4; # turn PGE back on
116 movq saved_context_esp(%rip), %rsp
117 movq saved_context_ebp(%rip), %rbp
118 /* restore GPRs (we don't restore %rax, it must be 0 anyway) */
119 movq saved_context_ebx(%rip), %rbx
120 movq saved_context_ecx(%rip), %rcx
121 movq saved_context_edx(%rip), %rdx
122 movq saved_context_esi(%rip), %rsi
123 movq saved_context_edi(%rip), %rdi
124 movq saved_context_r08(%rip), %r8
125 movq saved_context_r09(%rip), %r9
126 movq saved_context_r10(%rip), %r10
127 movq saved_context_r11(%rip), %r11
128 movq saved_context_r12(%rip), %r12
129 movq saved_context_r13(%rip), %r13
130 movq saved_context_r14(%rip), %r14
131 movq saved_context_r15(%rip), %r15
132 pushq saved_context_eflags(%rip) ; popfq
136 /* tell the hibernation core that we've just restored the memory */
137 movq %rax, in_suspend(%rip)