cpu_32.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Suspend support specific for i386.
  3. *
  4. * Distribute under GPLv2
  5. *
  6. * Copyright (c) 2002 Pavel Machek <pavel@suse.cz>
  7. * Copyright (c) 2001 Patrick Mochel <mochel@osdl.org>
  8. */
  9. #include <linux/module.h>
  10. #include <linux/suspend.h>
  11. #include <asm/mtrr.h>
  12. #include <asm/mce.h>
  13. static struct saved_context saved_context;
  14. unsigned long saved_context_ebx;
  15. unsigned long saved_context_esp, saved_context_ebp;
  16. unsigned long saved_context_esi, saved_context_edi;
  17. unsigned long saved_context_eflags;
  18. static void __save_processor_state(struct saved_context *ctxt)
  19. {
  20. mtrr_save_fixed_ranges(NULL);
  21. kernel_fpu_begin();
  22. /*
  23. * descriptor tables
  24. */
  25. store_gdt(&ctxt->gdt);
  26. store_idt(&ctxt->idt);
  27. store_tr(ctxt->tr);
  28. /*
  29. * segment registers
  30. */
  31. savesegment(es, ctxt->es);
  32. savesegment(fs, ctxt->fs);
  33. savesegment(gs, ctxt->gs);
  34. savesegment(ss, ctxt->ss);
  35. /*
  36. * control registers
  37. */
  38. ctxt->cr0 = read_cr0();
  39. ctxt->cr2 = read_cr2();
  40. ctxt->cr3 = read_cr3();
  41. ctxt->cr4 = read_cr4_safe();
  42. }
  43. /* Needed by apm.c */
  44. void save_processor_state(void)
  45. {
  46. __save_processor_state(&saved_context);
  47. }
  48. EXPORT_SYMBOL(save_processor_state);
  49. static void do_fpu_end(void)
  50. {
  51. /*
  52. * Restore FPU regs if necessary.
  53. */
  54. kernel_fpu_end();
  55. }
  56. static void fix_processor_context(void)
  57. {
  58. int cpu = smp_processor_id();
  59. struct tss_struct *t = &per_cpu(init_tss, cpu);
  60. set_tss_desc(cpu, t); /*
  61. * This just modifies memory; should not be
  62. * necessary. But... This is necessary, because
  63. * 386 hardware has concept of busy TSS or some
  64. * similar stupidity.
  65. */
  66. load_TR_desc(); /* This does ltr */
  67. load_LDT(&current->active_mm->context); /* This does lldt */
  68. /*
  69. * Now maybe reload the debug registers
  70. */
  71. if (current->thread.debugreg7) {
  72. set_debugreg(current->thread.debugreg0, 0);
  73. set_debugreg(current->thread.debugreg1, 1);
  74. set_debugreg(current->thread.debugreg2, 2);
  75. set_debugreg(current->thread.debugreg3, 3);
  76. /* no 4 and 5 */
  77. set_debugreg(current->thread.debugreg6, 6);
  78. set_debugreg(current->thread.debugreg7, 7);
  79. }
  80. }
  81. static void __restore_processor_state(struct saved_context *ctxt)
  82. {
  83. /*
  84. * control registers
  85. */
  86. /* cr4 was introduced in the Pentium CPU */
  87. if (ctxt->cr4)
  88. write_cr4(ctxt->cr4);
  89. write_cr3(ctxt->cr3);
  90. write_cr2(ctxt->cr2);
  91. write_cr0(ctxt->cr0);
  92. /*
  93. * now restore the descriptor tables to their proper values
  94. * ltr is done i fix_processor_context().
  95. */
  96. load_gdt(&ctxt->gdt);
  97. load_idt(&ctxt->idt);
  98. /*
  99. * segment registers
  100. */
  101. loadsegment(es, ctxt->es);
  102. loadsegment(fs, ctxt->fs);
  103. loadsegment(gs, ctxt->gs);
  104. loadsegment(ss, ctxt->ss);
  105. /*
  106. * sysenter MSRs
  107. */
  108. if (boot_cpu_has(X86_FEATURE_SEP))
  109. enable_sep_cpu();
  110. fix_processor_context();
  111. do_fpu_end();
  112. mtrr_ap_init();
  113. mcheck_init(&boot_cpu_data);
  114. }
  115. /* Needed by apm.c */
  116. void restore_processor_state(void)
  117. {
  118. __restore_processor_state(&saved_context);
  119. }
  120. EXPORT_SYMBOL(restore_processor_state);