From 7d7c2b4640a6b46eed90af5777f8d22504519a8e Mon Sep 17 00:00:00 2001 From: vanjeff Date: Fri, 2 Jun 2006 07:58:31 +0000 Subject: [PATCH] Deleted x64\SwitchStack.c Ipf/SwitchStack.c. Added SwitchStack.c in Baselib\ Rename Ia32/SwitchStack.c to Ia32/InternalSwitchStack.c Changed _SwitchStack() into InternalSwitchStack() in SwitchStack.asm and SwitchStack.s Fixed one bug in LinkedList.c, that List length couldn't up to PcdMaximumLinkedListLength. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@394 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Library/BaseLib/BaseLib-Gcc.msa | 7 +-- MdePkg/Library/BaseLib/BaseLib.msa | 7 +-- MdePkg/Library/BaseLib/BaseLibInternals.h | 9 ++++ .../BaseLib/Ia32/InternalSwitchStack.c | 52 +++++++++++++++++++ MdePkg/Library/BaseLib/Ipf/SwitchStack.s | 6 +-- MdePkg/Library/BaseLib/LinkedList.c | 5 ++ MdePkg/Library/BaseLib/SwitchStack.c | 51 ++++++++++++++++++ MdePkg/Library/BaseLib/X64/SwitchStack.asm | 4 +- 8 files changed, 130 insertions(+), 11 deletions(-) create mode 100644 MdePkg/Library/BaseLib/Ia32/InternalSwitchStack.c create mode 100644 MdePkg/Library/BaseLib/SwitchStack.c diff --git a/MdePkg/Library/BaseLib/BaseLib-Gcc.msa b/MdePkg/Library/BaseLib/BaseLib-Gcc.msa index 8246375b05..1957312501 100644 --- a/MdePkg/Library/BaseLib/BaseLib-Gcc.msa +++ b/MdePkg/Library/BaseLib/BaseLib-Gcc.msa @@ -73,6 +73,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. x86Thunk.c Unaligned.c LongJump.c + SwitchStack.c Ia32/Non-existing.c Ia32/LShiftU64.s Ia32/RShiftU64.s @@ -89,7 +90,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Ia32/SwapBytes64.s Ia32/SetJump.s Ia32/LongJump.s - Ia32/SwitchStack.c + Ia32/InternalSwitchStack.c Ia32/CpuId.s Ia32/ReadEflags.s Ia32/ReadMsr64.s @@ -179,8 +180,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Unaligned.c Math64.c LongJump.c + SwitchStack.c x64/Non-existing.c - x64/SwitchStack.c x64/SwitchStack.asm x64/SetJump.asm x64/LongJump.asm @@ -269,9 +270,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Math64.c LongJump.c + SwitchStack.c Ipf/setjmp.s Ipf/SwitchStack.s - x64/SwitchStack.c Ipf/Unaligned.c Ipf/CpuBreakpoint.c Ipf/InterlockedCompareExchange32.s diff --git a/MdePkg/Library/BaseLib/BaseLib.msa b/MdePkg/Library/BaseLib/BaseLib.msa index afcfa754f3..4f50169550 100644 --- a/MdePkg/Library/BaseLib/BaseLib.msa +++ b/MdePkg/Library/BaseLib/BaseLib.msa @@ -73,7 +73,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. x86Thunk.c Unaligned.c LongJump.c + SwitchStack.c Ia32/Non-existing.c + Ia32/InternalSwitchStack.c Ia32/LShiftU64.asm Ia32/RShiftU64.asm Ia32/ARShiftU64.asm @@ -89,7 +91,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Ia32/SwapBytes64.asm Ia32/SetJump.asm Ia32/LongJump.asm - Ia32/SwitchStack.c Ia32/CpuId.asm Ia32/ReadEflags.asm Ia32/ReadMsr64.asm @@ -179,8 +180,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Unaligned.c Math64.c LongJump.c + SwitchStack.c x64/Non-existing.c - x64/SwitchStack.c x64/SwitchStack.asm x64/SetJump.asm x64/LongJump.asm @@ -269,9 +270,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Math64.c LongJump.c + SwitchStack.c Ipf/PalCallStatic.s Ipf/setjmp.s - x64/SwitchStack.c Ipf/SwitchStack.s Ipf/Unaligned.c Ipf/CpuBreakpoint.c diff --git a/MdePkg/Library/BaseLib/BaseLibInternals.h b/MdePkg/Library/BaseLib/BaseLibInternals.h index 4cccdae528..0c32e1bd2c 100644 --- a/MdePkg/Library/BaseLib/BaseLibInternals.h +++ b/MdePkg/Library/BaseLib/BaseLibInternals.h @@ -114,6 +114,15 @@ InternalMathDivRemS64x64 ( OUT INT64 *Remainder ); +VOID +EFIAPI +InternalSwitchStack ( + IN SWITCH_STACK_ENTRY_POINT EntryPoint, + IN VOID *Context1, + IN VOID *Context2, + IN VOID *NewStack + ); + // // Ia32 and x64 specific functions // diff --git a/MdePkg/Library/BaseLib/Ia32/InternalSwitchStack.c b/MdePkg/Library/BaseLib/Ia32/InternalSwitchStack.c new file mode 100644 index 0000000000..ab8116b4b5 --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/InternalSwitchStack.c @@ -0,0 +1,52 @@ +/** @file + SwitchStack() function for IA-32. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + + Module Name: InternalSwitchStack.c + +**/ + +/** + Transfers control to a function starting with a new stack. + + Transfers control to the function specified by EntryPoint using the new stack + specified by NewStack and passing in the parameters specified by Context1 and + Context2. Context1 and Context2 are optional and may be NULL. The function + EntryPoint must never return. + + @param EntryPoint A pointer to function to call with the new stack. + @param Context1 A pointer to the context to pass into the EntryPoint + function. + @param Context2 A pointer to the context to pass into the EntryPoint + function. + @param NewStack A pointer to the new stack to use for the EntryPoint + function. + +**/ +VOID +EFIAPI +InternalSwitchStack ( + IN SWITCH_STACK_ENTRY_POINT EntryPoint, + IN VOID *Context1, + IN VOID *Context2, + IN VOID *NewStack + ) +{ + BASE_LIBRARY_JUMP_BUFFER JumpBuffer; + + JumpBuffer.Eip = (UINTN)EntryPoint; + JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*); + JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2); + ((VOID**)JumpBuffer.Esp)[1] = Context1; + ((VOID**)JumpBuffer.Esp)[2] = Context2; + + LongJump (&JumpBuffer, (UINTN)-1); +} diff --git a/MdePkg/Library/BaseLib/Ipf/SwitchStack.s b/MdePkg/Library/BaseLib/Ipf/SwitchStack.s index 16358add22..58fe43d87f 100644 --- a/MdePkg/Library/BaseLib/Ipf/SwitchStack.s +++ b/MdePkg/Library/BaseLib/Ipf/SwitchStack.s @@ -66,7 +66,7 @@ //VOID -//_SwitchStack ( +//InternalSwitchStack ( // VOID *ContinuationFunction, // UINTN Parameter, // UINTN NewTopOfStack, @@ -85,7 +85,7 @@ // //--*/ -PROCEDURE_ENTRY(_SwitchStack) +PROCEDURE_ENTRY(InternalSwitchStack) mov r16 = -0x10;; and r16 = r34, r16;; // get new stack value in R16, 0 the last nibble. @@ -117,6 +117,6 @@ PROCEDURE_ENTRY(_SwitchStack) ;; br.call.sptk.few b0=b6;; // Call the continuation function ;; -PROCEDURE_EXIT(_SwitchStack) +PROCEDURE_EXIT(InternalSwitchStack) diff --git a/MdePkg/Library/BaseLib/LinkedList.c b/MdePkg/Library/BaseLib/LinkedList.c index 0f42749775..9ad1b0875b 100644 --- a/MdePkg/Library/BaseLib/LinkedList.c +++ b/MdePkg/Library/BaseLib/LinkedList.c @@ -34,6 +34,10 @@ IsNodeInList ( ASSERT (Node != NULL); Count = FixedPcdGet32 (PcdMaximumLinkedListLength); + if (Count != 0) { + Count++; + } + Ptr = List; do { Ptr = Ptr->ForwardLink; @@ -44,6 +48,7 @@ IsNodeInList ( if (FixedPcdGet32 (PcdMaximumLinkedListLength) > 0) { while ((Count > 0) && (Ptr != List)) { Ptr = Ptr->ForwardLink; + Count--; } ASSERT (Count > 0); } diff --git a/MdePkg/Library/BaseLib/SwitchStack.c b/MdePkg/Library/BaseLib/SwitchStack.c new file mode 100644 index 0000000000..fec3cfaa60 --- /dev/null +++ b/MdePkg/Library/BaseLib/SwitchStack.c @@ -0,0 +1,51 @@ +/** @file + Switch Stack functions. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + + Module Name: SwitchStack.c + +**/ + +#include + +/** + Transfers control to a function starting with a new stack. + + Transfers control to the function specified by EntryPoint using the new stack + specified by NewStack and passing in the parameters specified by Context1 and + Context2. Context1 and Context2 are optional and may be NULL. The function + EntryPoint must never return. + + If EntryPoint is NULL, then ASSERT(). + If NewStack is NULL, then ASSERT(). + + @param EntryPoint A pointer to function to call with the new stack. + @param Context1 A pointer to the context to pass into the EntryPoint + function. + @param Context2 A pointer to the context to pass into the EntryPoint + function. + @param NewStack A pointer to the new stack to use for the EntryPoint + function. + +**/ +VOID +EFIAPI +SwitchStack ( + IN SWITCH_STACK_ENTRY_POINT EntryPoint, + IN VOID *Context1, + IN VOID *Context2, + IN VOID *NewStack + ) +{ + ASSERT (EntryPoint != NULL && NewStack != NULL); + + InternalSwitchStack (EntryPoint, Context1, Context2, NewStack); +} diff --git a/MdePkg/Library/BaseLib/X64/SwitchStack.asm b/MdePkg/Library/BaseLib/X64/SwitchStack.asm index a1304ca295..53d1417f0b 100644 --- a/MdePkg/Library/BaseLib/X64/SwitchStack.asm +++ b/MdePkg/Library/BaseLib/X64/SwitchStack.asm @@ -36,12 +36,12 @@ ; None ; ;------------------------------------------------------------------------------ -_SwitchStack PROC +InternalSwitchStack PROC mov rax, rcx mov rcx, rdx mov rdx, r8 lea rsp, [r9 - 20h] call rax -_SwitchStack ENDP +InternalSwitchStack ENDP END