]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/LoongArch64/InternalSwitchStack.c
MdePkg/BaseLib: BaseLib for LOONGARCH64 architecture.
[mirror_edk2.git] / MdePkg / Library / BaseLib / LoongArch64 / InternalSwitchStack.c
diff --git a/MdePkg/Library/BaseLib/LoongArch64/InternalSwitchStack.c b/MdePkg/Library/BaseLib/LoongArch64/InternalSwitchStack.c
new file mode 100644 (file)
index 0000000..859bc96
--- /dev/null
@@ -0,0 +1,58 @@
+/** @file\r
+  SwitchStack() function for LoongArch.\r
+\r
+  Copyright (c) 2022, Loongson Technology Corporation Limited. All rights reserved.<BR>\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#include "BaseLibInternals.h"\r
+\r
+UINTN\r
+EFIAPI\r
+InternalSwitchStackAsm (\r
+  IN     BASE_LIBRARY_JUMP_BUFFER  *JumpBuffer\r
+  );\r
+\r
+/**\r
+  Transfers control to a function starting with a new stack.\r
+\r
+  Transfers control to the function specified by EntryPoint using the\r
+  new stack specified by NewStack and passing in the parameters specified\r
+  by Context1 and Context2.  Context1 and Context2 are optional and may\r
+  be NULL.  The function EntryPoint must never return.\r
+\r
+  If EntryPoint is NULL, then ASSERT().\r
+  If NewStack is NULL, then ASSERT().\r
+\r
+  @param[in]  EntryPoint  A pointer to function to call with the new stack.\r
+  @param[in]  Context1    A pointer to the context to pass into the EntryPoint\r
+                      function.\r
+  @param[in]  Context2    A pointer to the context to pass into the EntryPoint\r
+                      function.\r
+  @param[in]  NewStack    A pointer to the new stack to use for the EntryPoint\r
+                      function.\r
+  @param[in]  Marker      VA_LIST marker for the variable argument list.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+InternalSwitchStack (\r
+  IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,\r
+  IN      VOID                      *Context1   OPTIONAL,\r
+  IN      VOID                      *Context2   OPTIONAL,\r
+  IN      VOID                      *NewStack,\r
+  IN      VA_LIST                   Marker\r
+  )\r
+\r
+{\r
+  BASE_LIBRARY_JUMP_BUFFER  JumpBuffer;\r
+\r
+  JumpBuffer.RA                      = (UINTN)EntryPoint;\r
+  JumpBuffer.SP                      = (UINTN)NewStack - sizeof (VOID *);\r
+  JumpBuffer.SP                     -= sizeof (Context1) + sizeof (Context2);\r
+  ((VOID **)(UINTN)JumpBuffer.SP)[0] = Context1;\r
+  ((VOID **)(UINTN)JumpBuffer.SP)[1] = Context2;\r
+\r
+  InternalSwitchStackAsm (&JumpBuffer);\r
+}\r