fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / x86_64 / kernel / suspend_asm.S
index 8a39998..bfbe007 100644 (file)
@@ -1,6 +1,9 @@
-/* Originally gcc generated, modified by hand
+/* Copyright 2004,2005 Pavel Machek <pavel@suse.cz>, Andi Kleen <ak@suse.de>, Rafael J. Wysocki <rjw@sisk.pl>
  *
- * This may not use any stack, nor any variable that is not "NoSave":
+ * Distribute under GPLv2.
+ *
+ * swsusp_arch_resume may not use any stack, nor any variable that is
+ * not "NoSave" during copying pages:
  *
  * Its rewriting one kernel image with another. What is stack in "old"
  * image could very well be data page in "new" image, and overwriting
@@ -11,6 +14,7 @@
 #include <linux/linkage.h>
 #include <asm/segment.h>
 #include <asm/page.h>
+#include <asm/asm-offsets.h>
 
 ENTRY(swsusp_arch_suspend)
 
@@ -35,12 +39,13 @@ ENTRY(swsusp_arch_suspend)
        call swsusp_save
        ret
 
-ENTRY(swsusp_arch_resume)
-       /* set up cr3 */        
-       leaq    init_level4_pgt(%rip),%rax
-       subq    $__START_KERNEL_map,%rax
-       movq    %rax,%cr3
-
+ENTRY(restore_image)
+       /* switch to temporary page tables */
+       movq    $__PAGE_OFFSET, %rdx
+       movq    temp_level4_pgt(%rip), %rax
+       subq    %rdx, %rax
+       movq    %rax, %cr3
+       /* Flush TLB */
        movq    mmu_cr4_features(%rip), %rax
        movq    %rax, %rdx
        andq    $~(1<<7), %rdx  # PGE
@@ -49,50 +54,41 @@ ENTRY(swsusp_arch_resume)
        movq    %rcx, %cr3;
        movq    %rax, %cr4;  # turn PGE back on
 
-       movl    nr_copy_pages(%rip), %eax
-       xorl    %ecx, %ecx
-       movq    $0, %r10
-       testl   %eax, %eax
+       movq    restore_pblist(%rip), %rdx
+loop:
+       testq   %rdx, %rdx
        jz      done
-.L105:
-       xorl    %esi, %esi
-       movq    $0, %r11
-       jmp     .L104
-       .p2align 4,,7
-copy_one_page:
-       movq    %r10, %rcx
-.L104:
-       movq    pagedir_nosave(%rip), %rdx
-       movq    %rcx, %rax
-       salq    $5, %rax
-       movq    8(%rdx,%rax), %rcx
-       movq    (%rdx,%rax), %rax
-       movzbl  (%rsi,%rax), %eax
-       movb    %al, (%rsi,%rcx)
 
-       movq    %cr3, %rax;  # flush TLB
-       movq    %rax, %cr3;
+       /* get addresses from the pbe and copy the page */
+       movq    pbe_address(%rdx), %rsi
+       movq    pbe_orig_address(%rdx), %rdi
+       movq    $512, %rcx
+       rep
+       movsq
 
-       movq    %r11, %rax
-       incq    %rax
-       cmpq    $4095, %rax
-       movq    %rax, %rsi
-       movq    %rax, %r11
-       jbe     copy_one_page
-       movq    %r10, %rax
-       incq    %rax
-       movq    %rax, %rcx
-       movq    %rax, %r10
-       mov     nr_copy_pages(%rip), %eax
-       cmpq    %rax, %rcx
-       jb      .L105
+       /* progress to the next pbe */
+       movq    pbe_next(%rdx), %rdx
+       jmp     loop
 done:
+       /* go back to the original page tables */
+       leaq    init_level4_pgt(%rip), %rax
+       subq    $__START_KERNEL_map, %rax
+       movq    %rax, %cr3
+       /* Flush TLB, including "global" things (vmalloc) */
+       movq    mmu_cr4_features(%rip), %rax
+       movq    %rax, %rdx
+       andq    $~(1<<7), %rdx;  # PGE
+       movq    %rdx, %cr4;  # turn off PGE
+       movq    %cr3, %rcx;  # flush TLB
+       movq    %rcx, %cr3
+       movq    %rax, %cr4;  # turn PGE back on
+
        movl    $24, %eax
        movl    %eax, %ds
 
        movq saved_context_esp(%rip), %rsp
        movq saved_context_ebp(%rip), %rbp
-       movq saved_context_eax(%rip), %rax
+       /* Don't restore %rax, it must be 0 anyway */
        movq saved_context_ebx(%rip), %rbx
        movq saved_context_ecx(%rip), %rcx
        movq saved_context_edx(%rip), %rdx
@@ -107,5 +103,7 @@ done:
        movq saved_context_r14(%rip), %r14
        movq saved_context_r15(%rip), %r15
        pushq saved_context_eflags(%rip) ; popfq
-       call    swsusp_restore
+
+       xorq    %rax, %rax
+
        ret