Linux Audio

Check our new training course

Linux debugging, profiling, tracing and performance analysis training

Apr 14-17, 2025
Register
Loading...
v4.10.11
 
 1/*
 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>
11#include <asm/page_types.h>
12#include <asm/asm-offsets.h>
13#include <asm/processor-flags.h>
 
14
15.text
16
17ENTRY(swsusp_arch_suspend)
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
23	pushfl
24	popl saved_context_eflags
25
 
 
 
 
 
26	call swsusp_save
 
27	ret
 
28
29ENTRY(restore_image)
 
 
 
 
30	movl	mmu_cr4_features, %ecx
31	movl	resume_pg_dir, %eax
32	subl	$__PAGE_OFFSET, %eax
 
 
 
 
 
 
33	movl	%eax, %cr3
34
35	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:
41	movl	restore_pblist, %edx
42	.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:
 
 
 
 
 
60	/* go back to the original page tables */
61	movl	$swapper_pg_dir, %eax
62	subl	$__PAGE_OFFSET, %eax
63	movl	%eax, %cr3
64	movl	mmu_cr4_features, %ecx
65	jecxz	1f	# cr4 Pentium and higher, skip if zero
66	movl	%ecx, %cr4;  # turn PGE back on
671:
68
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
75	pushl saved_context_eflags
76	popfl
77
78	/* Saved in save_processor_state. */
79	movl $saved_context, %eax
80	lgdt saved_context_gdt_desc(%eax)
81
82	xorl	%eax, %eax
83
 
 
 
84	ret
v5.4
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * This may not use any stack, nor any variable that is not "NoSave":
  4 *
  5 * Its rewriting one kernel image with another. What is stack in "old"
  6 * image could very well be data page in "new" image, and overwriting
  7 * your own stack under you is bad idea.
  8 */
  9
 10#include <linux/linkage.h>
 11#include <asm/segment.h>
 12#include <asm/page_types.h>
 13#include <asm/asm-offsets.h>
 14#include <asm/processor-flags.h>
 15#include <asm/frame.h>
 16
 17.text
 18
 19ENTRY(swsusp_arch_suspend)
 20	movl %esp, saved_context_esp
 21	movl %ebx, saved_context_ebx
 22	movl %ebp, saved_context_ebp
 23	movl %esi, saved_context_esi
 24	movl %edi, saved_context_edi
 25	pushfl
 26	popl saved_context_eflags
 27
 28	/* save cr3 */
 29	movl	%cr3, %eax
 30	movl	%eax, restore_cr3
 31
 32	FRAME_BEGIN
 33	call swsusp_save
 34	FRAME_END
 35	ret
 36ENDPROC(swsusp_arch_suspend)
 37
 38ENTRY(restore_image)
 39	/* prepare to jump to the image kernel */
 40	movl	restore_jump_address, %ebx
 41	movl	restore_cr3, %ebp
 42
 43	movl	mmu_cr4_features, %ecx
 44
 45	/* jump to relocated restore code */
 46	movl	relocated_restore_code, %eax
 47	jmpl	*%eax
 48
 49/* code below has been relocated to a safe page */
 50ENTRY(core_restore_code)
 51	movl	temp_pgt, %eax
 52	movl	%eax, %cr3
 53
 54	jecxz	1f	# cr4 Pentium and higher, skip if zero
 55	andl	$~(X86_CR4_PGE), %ecx
 56	movl	%ecx, %cr4;  # turn off PGE
 57	movl	%cr3, %eax;  # flush TLB
 58	movl	%eax, %cr3
 591:
 60	movl	restore_pblist, %edx
 61	.p2align 4,,7
 62
 63copy_loop:
 64	testl	%edx, %edx
 65	jz	done
 66
 67	movl	pbe_address(%edx), %esi
 68	movl	pbe_orig_address(%edx), %edi
 69
 70	movl	$(PAGE_SIZE >> 2), %ecx
 71	rep
 72	movsl
 73
 74	movl	pbe_next(%edx), %edx
 75	jmp	copy_loop
 76	.p2align 4,,7
 77
 78done:
 79	jmpl	*%ebx
 80
 81	/* code below belongs to the image kernel */
 82	.align PAGE_SIZE
 83ENTRY(restore_registers)
 84	/* go back to the original page tables */
 85	movl	%ebp, %cr3
 
 
 86	movl	mmu_cr4_features, %ecx
 87	jecxz	1f	# cr4 Pentium and higher, skip if zero
 88	movl	%ecx, %cr4;  # turn PGE back on
 891:
 90
 91	movl saved_context_esp, %esp
 92	movl saved_context_ebp, %ebp
 93	movl saved_context_ebx, %ebx
 94	movl saved_context_esi, %esi
 95	movl saved_context_edi, %edi
 96
 97	pushl saved_context_eflags
 98	popfl
 99
100	/* Saved in save_processor_state. */
101	movl $saved_context, %eax
102	lgdt saved_context_gdt_desc(%eax)
103
104	xorl	%eax, %eax
105
106	/* tell the hibernation core that we've just restored the memory */
107	movl	%eax, in_suspend
108
109	ret
110ENDPROC(restore_registers)