Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. Savestate.c
  5. Abstract:
  6. This module contains routines to save and restore the 16 bit state
  7. Author:
  8. Dave Hastings (daveh) 27-Nov-1992
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #include "softpc.h"
  14. #include <malloc.h>
  15. //
  16. // Internal structures
  17. //
  18. typedef struct _SavedState {
  19. struct _SavedState *Next;
  20. USHORT SegSs;
  21. ULONG Esp;
  22. USHORT SegDs;
  23. USHORT SegEs;
  24. USHORT SegFs;
  25. USHORT SegGs;
  26. } SAVEDCONTEXT, *PSAVEDCONTEXT;
  27. PSAVEDCONTEXT StateStack = NULL;
  28. VOID
  29. DpmiSaveSegmentsAndStack(
  30. PVOID ContextPointer
  31. )
  32. /*++
  33. Routine Description:
  34. This routine saves the segment registers, and the sp value.
  35. Arguments:
  36. None.
  37. Return Value:
  38. None.
  39. Notes:
  40. It would be better if the calling routine did not have to have
  41. any knowlege of what is being saved, but apparently malloc is now
  42. and always will be much too slow to be useful, so we do this.
  43. --*/
  44. {
  45. DECLARE_LocalVdmContext;
  46. PSAVEDCONTEXT SavedState;
  47. ASSERT((sizeof(SAVEDCONTEXT) < sizeof(VSAVEDSTATE)));
  48. SavedState = ContextPointer;
  49. SavedState->Next = StateStack;
  50. StateStack = SavedState;
  51. SavedState->SegSs = getSS();
  52. SavedState->Esp = getESP();
  53. SavedState->SegDs = getDS();
  54. SavedState->SegEs = getES();
  55. SavedState->SegFs = getFS();
  56. SavedState->SegGs = getGS();
  57. }
  58. PVOID
  59. DpmiRestoreSegmentsAndStack(
  60. VOID
  61. )
  62. /*++
  63. Routine Description:
  64. This routine restores the segment registers, and the sp value.
  65. Arguments:
  66. None.
  67. Return Value:
  68. Pointer to state poped off stack.
  69. --*/
  70. {
  71. DECLARE_LocalVdmContext;
  72. PSAVEDCONTEXT SavedState;
  73. SavedState = StateStack;
  74. ASSERT((SavedState));
  75. ASSERT((sizeof(SAVEDCONTEXT) < sizeof(VSAVEDSTATE)));
  76. StateStack = SavedState->Next;
  77. setSS(SavedState->SegSs);
  78. #if 0
  79. if (getSS() != SavedState->SegSs) {
  80. char szFormat[] = "NTVDM Dpmi Error! Can't set SS to %.4X\n";
  81. char szMsg[sizeof(szFormat)+30];
  82. wsprintf(szMsg, szFormat, SavedState->SegSs);
  83. OutputDebugString(szMsg);
  84. DbgBreakPoint();
  85. }
  86. #endif
  87. setESP(SavedState->Esp);
  88. setDS(SavedState->SegDs);
  89. setES(SavedState->SegEs);
  90. setFS(SavedState->SegFs);
  91. setGS(SavedState->SegGs);
  92. return SavedState;
  93. }