Rafael J. Wysocki | c575912 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * 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 Fitzhardinge | 0341c14 | 2009-02-13 11:14:01 -0800 | [diff] [blame] | 11 | #include <asm/page_types.h> |
Sam Ravnborg | 86feeaa | 2005-09-09 19:28:28 +0200 | [diff] [blame] | 12 | #include <asm/asm-offsets.h> |
Uros Bizjak | c171f46 | 2008-08-20 10:44:47 +0200 | [diff] [blame] | 13 | #include <asm/processor-flags.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Uros Bizjak | c171f46 | 2008-08-20 10:44:47 +0200 | [diff] [blame] | 15 | .text |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | ENTRY(swsusp_arch_suspend) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | 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 Bizjak | c171f46 | 2008-08-20 10:44:47 +0200 | [diff] [blame] | 23 | pushfl |
| 24 | popl saved_context_eflags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | call swsusp_save |
| 27 | ret |
| 28 | |
Rafael J. Wysocki | 2d4a34c | 2006-12-06 20:34:29 -0800 | [diff] [blame] | 29 | ENTRY(restore_image) |
David Fries | e532c06 | 2008-08-17 23:03:40 -0500 | [diff] [blame] | 30 | movl resume_pg_dir, %eax |
| 31 | subl $__PAGE_OFFSET, %eax |
| 32 | movl %eax, %cr3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Rafael J. Wysocki | 75534b5 | 2006-09-25 23:32:52 -0700 | [diff] [blame] | 34 | movl restore_pblist, %edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | .p2align 4,,7 |
| 36 | |
| 37 | copy_loop: |
| 38 | testl %edx, %edx |
| 39 | jz done |
| 40 | |
| 41 | movl pbe_address(%edx), %esi |
| 42 | movl pbe_orig_address(%edx), %edi |
| 43 | |
| 44 | movl $1024, %ecx |
| 45 | rep |
| 46 | movsl |
| 47 | |
| 48 | movl pbe_next(%edx), %edx |
| 49 | jmp copy_loop |
| 50 | .p2align 4,,7 |
| 51 | |
| 52 | done: |
Rafael J. Wysocki | 2d4a34c | 2006-12-06 20:34:29 -0800 | [diff] [blame] | 53 | /* go back to the original page tables */ |
David Fries | e532c06 | 2008-08-17 23:03:40 -0500 | [diff] [blame] | 54 | movl $swapper_pg_dir, %eax |
| 55 | subl $__PAGE_OFFSET, %eax |
| 56 | movl %eax, %cr3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | /* Flush TLB, including "global" things (vmalloc) */ |
David Fries | e532c06 | 2008-08-17 23:03:40 -0500 | [diff] [blame] | 58 | movl mmu_cr4_features, %ecx |
| 59 | jecxz 1f # cr4 Pentium and higher, skip if zero |
| 60 | movl %ecx, %edx |
Uros Bizjak | c171f46 | 2008-08-20 10:44:47 +0200 | [diff] [blame] | 61 | andl $~(X86_CR4_PGE), %edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | movl %edx, %cr4; # turn off PGE |
David Fries | e532c06 | 2008-08-17 23:03:40 -0500 | [diff] [blame] | 63 | 1: |
| 64 | movl %cr3, %eax; # flush TLB |
| 65 | movl %eax, %cr3 |
| 66 | jecxz 1f # cr4 Pentium and higher, skip if zero |
| 67 | movl %ecx, %cr4; # turn PGE back on |
| 68 | 1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | movl saved_context_esp, %esp |
| 71 | movl saved_context_ebp, %ebp |
| 72 | movl saved_context_ebx, %ebx |
| 73 | movl saved_context_esi, %esi |
| 74 | movl saved_context_edi, %edi |
| 75 | |
Uros Bizjak | c171f46 | 2008-08-20 10:44:47 +0200 | [diff] [blame] | 76 | pushl saved_context_eflags |
| 77 | popfl |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | xorl %eax, %eax |
| 80 | |
| 81 | ret |