2 * Suspend support specific for i386.
4 * Distribute under GPLv2
6 * Copyright (c) 2002 Pavel Machek <pavel@suse.cz>
7 * Copyright (c) 2001 Patrick Mochel <mochel@osdl.org>
10 #include <linux/suspend.h>
11 #include <linux/smp.h>
13 #include <asm/pgtable.h>
14 #include <asm/proto.h>
19 #include <asm/suspend.h>
21 static struct saved_context saved_context;
23 unsigned long saved_context_ebx;
24 unsigned long saved_context_esp, saved_context_ebp;
25 unsigned long saved_context_esi, saved_context_edi;
26 unsigned long saved_context_eflags;
28 static void __save_processor_state(struct saved_context *ctxt)
30 mtrr_save_fixed_ranges(NULL);
36 store_gdt(&ctxt->gdt);
37 store_idt(&ctxt->idt);
43 savesegment(es, ctxt->es);
44 savesegment(fs, ctxt->fs);
45 savesegment(gs, ctxt->gs);
46 savesegment(ss, ctxt->ss);
51 ctxt->cr0 = read_cr0();
52 ctxt->cr2 = read_cr2();
53 ctxt->cr3 = read_cr3();
54 ctxt->cr4 = read_cr4_safe();
58 void save_processor_state(void)
60 __save_processor_state(&saved_context);
62 EXPORT_SYMBOL(save_processor_state);
64 static void do_fpu_end(void)
67 * Restore FPU regs if necessary.
72 static void fix_processor_context(void)
74 int cpu = smp_processor_id();
75 struct tss_struct *t = &per_cpu(init_tss, cpu);
77 set_tss_desc(cpu, t); /*
78 * This just modifies memory; should not be
79 * necessary. But... This is necessary, because
80 * 386 hardware has concept of busy TSS or some
84 load_TR_desc(); /* This does ltr */
85 load_LDT(¤t->active_mm->context); /* This does lldt */
88 * Now maybe reload the debug registers
90 if (current->thread.debugreg7) {
91 set_debugreg(current->thread.debugreg0, 0);
92 set_debugreg(current->thread.debugreg1, 1);
93 set_debugreg(current->thread.debugreg2, 2);
94 set_debugreg(current->thread.debugreg3, 3);
96 set_debugreg(current->thread.debugreg6, 6);
97 set_debugreg(current->thread.debugreg7, 7);
102 static void __restore_processor_state(struct saved_context *ctxt)
107 /* cr4 was introduced in the Pentium CPU */
109 write_cr4(ctxt->cr4);
110 write_cr3(ctxt->cr3);
111 write_cr2(ctxt->cr2);
112 write_cr0(ctxt->cr0);
115 * now restore the descriptor tables to their proper values
116 * ltr is done i fix_processor_context().
118 load_gdt(&ctxt->gdt);
119 load_idt(&ctxt->idt);
124 loadsegment(es, ctxt->es);
125 loadsegment(fs, ctxt->fs);
126 loadsegment(gs, ctxt->gs);
127 loadsegment(ss, ctxt->ss);
132 if (boot_cpu_has(X86_FEATURE_SEP))
136 * restore XCR0 for xsave capable cpu's.
139 xsetbv(XCR_XFEATURE_ENABLED_MASK, pcntxt_mask);
141 fix_processor_context();
144 mcheck_init(&boot_cpu_data);
147 /* Needed by apm.c */
148 void restore_processor_state(void)
150 __restore_processor_state(&saved_context);
152 EXPORT_SYMBOL(restore_processor_state);