]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmulatorPkg/Win/Host/WinHost.c
EmulatorPkg/WinHost: Add Reset2 PPI
[mirror_edk2.git] / EmulatorPkg / Win / Host / WinHost.c
index 9b10290ff3c089ec846698bec093d4f68dd58ea8..096292f95a6fadc2e6ef3c1098212d63f5c40608 100644 (file)
@@ -56,6 +56,14 @@ NT_FD_INFO  *gFdInfo;
 UINTN             gSystemMemoryCount = 0;\r
 NT_SYSTEM_MEMORY  *gSystemMemory;\r
 \r
+BASE_LIBRARY_JUMP_BUFFER  mResetJumpBuffer;\r
+CHAR8                     *mResetTypeStr[] = {\r
+  "EfiResetCold",\r
+  "EfiResetWarm",\r
+  "EfiResetShutdown",\r
+  "EfiResetPlatformSpecific"\r
+};\r
+\r
 /*++\r
 \r
 Routine Description:\r
@@ -196,6 +204,45 @@ SecPrint (
     );\r
 }\r
 \r
+/**\r
+  Resets the entire platform.\r
+\r
+  @param[in] ResetType      The type of reset to perform.\r
+  @param[in] ResetStatus    The status code for the reset.\r
+  @param[in] DataSize       The size, in bytes, of ResetData.\r
+  @param[in] ResetData      For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown\r
+                            the data buffer starts with a Null-terminated string, optionally\r
+                            followed by additional binary data. The string is a description\r
+                            that the caller may use to further indicate the reason for the\r
+                            system reset.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+WinReset (\r
+  IN EFI_RESET_TYPE  ResetType,\r
+  IN EFI_STATUS      ResetStatus,\r
+  IN UINTN           DataSize,\r
+  IN VOID            *ResetData OPTIONAL\r
+  )\r
+{\r
+  ASSERT (ResetType <= EfiResetPlatformSpecific);\r
+  SecPrint ("  Emu ResetSystem is called: ResetType = %s\n", mResetTypeStr[ResetType]);\r
+\r
+  if (ResetType == EfiResetShutdown) {\r
+    exit (0);\r
+  } else {\r
+    //\r
+    // Jump back to SetJump with jump code = ResetType + 1\r
+    //\r
+    LongJump (&mResetJumpBuffer, ResetType + 1);\r
+  }\r
+}\r
+\r
+EFI_PEI_RESET2_PPI  mEmuReset2Ppi = {\r
+  WinReset\r
+};\r
+\r
 /*++\r
 \r
 Routine Description:\r
@@ -388,6 +435,7 @@ Returns:
   UINTN                ProcessAffinityMask;\r
   UINTN                SystemAffinityMask;\r
   INT32                LowBit;\r
+  UINTN                ResetJumpCode;\r
 \r
   //\r
   // Enable the privilege so that RTC driver can successfully run SetTime()\r
@@ -430,6 +478,7 @@ Returns:
   // PPIs pased into PEI_CORE\r
   //\r
   AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuThunkPpiGuid, &mSecEmuThunkPpi);\r
+  AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEfiPeiReset2PpiGuid, &mEmuReset2Ppi);\r
 \r
   //\r
   // Emulator Bus Driver Thunks\r
@@ -500,14 +549,6 @@ Returns:
     exit (1);\r
   }\r
 \r
-  SetMem32 (TemporaryRam, TemporaryRamSize, PcdGet32 (PcdInitValueInTempStack));\r
-\r
-  SecPrint (\r
-    "  OS Emulator passing in %u KB of temp RAM at 0x%08lx to SEC\n\r",\r
-    TemporaryRamSize / SIZE_1KB,\r
-    TemporaryRam\r
-    );\r
-\r
   //\r
   // If enabled use the magic page to communicate between modules\r
   // This replaces the PI PeiServicesTable pointer mechanism that\r
@@ -591,6 +632,24 @@ Returns:
     SecPrint ("\n\r");\r
   }\r
 \r
+  ResetJumpCode = SetJump (&mResetJumpBuffer);\r
+\r
+  //\r
+  // Do not clear memory content for warm reset.\r
+  //\r
+  if (ResetJumpCode != EfiResetWarm + 1) {\r
+    SecPrint ("  OS Emulator clearing temp RAM and physical RAM (to be discovered later)......\n\r");\r
+    SetMem32 (TemporaryRam, TemporaryRamSize, PcdGet32 (PcdInitValueInTempStack));\r
+    for (Index = 0; Index < gSystemMemoryCount; Index++) {\r
+      SetMem32 ((VOID *)(UINTN)gSystemMemory[Index].Memory, (UINTN)gSystemMemory[Index].Size, PcdGet32 (PcdInitValueInTempStack));\r
+    }\r
+  }\r
+\r
+  SecPrint (\r
+    "  OS Emulator passing in %u KB of temp RAM at 0x%08lx to SEC\n\r",\r
+    TemporaryRamSize / SIZE_1KB,\r
+    TemporaryRam\r
+    );\r
   //\r
   // Hand off to SEC Core\r
   //\r