diff options
author | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
---|---|---|
committer | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
commit | b7c51c9cf4864df6aabb99a1ae843becd577237c (patch) | |
tree | eebe9b0d0ca03062955223097e57da84dd618b9a /Core/CPU/x64 | |
download | zprj-master.tar.xz |
Diffstat (limited to 'Core/CPU/x64')
62 files changed, 5360 insertions, 0 deletions
diff --git a/Core/CPU/x64/AmiX64Lib.cif b/Core/CPU/x64/AmiX64Lib.cif new file mode 100644 index 0000000..5070b67 --- /dev/null +++ b/Core/CPU/x64/AmiX64Lib.cif @@ -0,0 +1,52 @@ +<component> + name = "AmiX64Lib" + category = ModulePart + LocalRoot = "Core\CPU\x64\" + RefName = "AmiX64Lib" +[files] +"AmiX64Lib.sdl" +"AmiX64Lib.mak" +"x64CLib.c" +"x64AsmLib\checkpoint.asm" +"x64AsmLib\CPULib_CpuID.asm" +"x64AsmLib\CPULib_DisableInterrupt.asm" +"x64AsmLib\CPULib_EnableInterrupt.asm" +"x64AsmLib\CPULib_GetInterruptState.asm" +"x64AsmLib\CPULIB_GetPageTable.asm" +"x64AsmLib\CPULib_LoadGdt.asm" +"x64AsmLib\CPULib_LoadIdt.asm" +"x64AsmLib\CPULib_LockByteDec.asm" +"x64AsmLib\CPULib_LockByteInc.asm" +"x64AsmLib\CPULib_Pause.asm" +"x64AsmLib\CPULib_SaveGdt.asm" +"x64AsmLib\CPULib_SaveIdt.asm" +"x64AsmLib\DisableCacheInCR0.asm" +"x64AsmLib\EnableCacheInCR0.asm" +"x64AsmLib\EnableMachineCheck.asm" +"x64AsmLib\GetCpuTimer.asm" +"x64AsmLib\GetCsSegment.asm" +"x64AsmLib\GetPowerOfTwo64.asm" +"x64AsmLib\HltCpu.asm" +"x64AsmLib\IoRead16.asm" +"x64AsmLib\IoRead32.asm" +"x64AsmLib\IoRead64.asm" +"x64AsmLib\IoRead8.asm" +"x64AsmLib\IoWrite16.asm" +"x64AsmLib\IoWrite32.asm" +"x64AsmLib\IoWrite64.asm" +"x64AsmLib\IoWrite8.asm" +"x64AsmLib\MemCpy.asm" +"x64AsmLib\MemRead32.asm" +"x64AsmLib\MemReadWrite32.asm" +"x64AsmLib\MemSet.asm" +"x64AsmLib\ReadCr3.asm" +"x64AsmLib\ReadMsr.asm" +"x64AsmLib\ReadRtdsc.asm" +"x64AsmLib\WaitForever.asm" +"x64AsmLib\WaitForSemaphore.asm" +"x64AsmLib\WaitUntilZero32.asm" +"x64AsmLib\WaitUntilZero8.asm" +"x64AsmLib\WriteCr3.asm" +"x64AsmLib\WriteMsr.asm" +"x64AsmLib\MemCpy32.asm" +<endComponent> diff --git a/Core/CPU/x64/AmiX64Lib.mak b/Core/CPU/x64/AmiX64Lib.mak new file mode 100644 index 0000000..e2cd482 --- /dev/null +++ b/Core/CPU/x64/AmiX64Lib.mak @@ -0,0 +1,63 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2006, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 6145-F Northbelt Pkwy, Norcross, GA 30071 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/SOURCE/Core/Modules/x64Core/AmiX64Lib.mak 1 10/13/06 8:37p Felixp $ +# +# $Revision: 1 $ +# +# $Date: 10/13/06 8:37p $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Core/Modules/x64Core/AmiX64Lib.mak $ +# +# 1 10/13/06 8:37p Felixp +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: AmiX64Lib.mak +# +# Description: +# +#<AMI_FHDR_END> +#********************************************************************** +AmiX64Lib : $(BUILD_DIR)\AmiX64Lib.mak AmiX64LibBin + +$(BUILD_DIR)\AmiX64Lib.mak : $(AmiX64Lib_DIR)\$(@B).cif $(AmiX64Lib_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(AmiX64Lib_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +!IF "$(PROCESSOR)"=="x64" +AmiDxeLibBin : $(BUILD_DIR)\AmiX64Lib.lib +$(BUILD_DIR)\AmiX64Lib.lib : AmiX64Lib +!ENDIF + +AmiX64LibBin : + $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\ + /f $(BUILD_DIR)\AmiX64Lib.mak all\ + TYPE=LIBRARY +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2006, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 6145-F Northbelt Pkwy, Norcross, GA 30071 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#**********************************************************************
\ No newline at end of file diff --git a/Core/CPU/x64/AmiX64Lib.sdl b/Core/CPU/x64/AmiX64Lib.sdl new file mode 100644 index 0000000..79b7e36 --- /dev/null +++ b/Core/CPU/x64/AmiX64Lib.sdl @@ -0,0 +1,19 @@ +TOKEN + Name = "AmiX64Lib_SUPPORT" + Value = "1" + Help = "Main switch to enable AmiX64Lib support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +PATH + Name = "AmiX64Lib_DIR" +End + +MODULE + Help = "Includes AmiX64Lib.mak to Project" + File = "AmiX64Lib.mak" +End + diff --git a/Core/CPU/x64/EfiJump.h b/Core/CPU/x64/EfiJump.h new file mode 100644 index 0000000..61f371f --- /dev/null +++ b/Core/CPU/x64/EfiJump.h @@ -0,0 +1,42 @@ +/*++ + +Copyright (c) 2005, 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: + + EfiJump.h + +Abstract: + + This is the Setjump/Longjump pair for an x64 processor. + +--*/ + +#ifndef _EFI_JUMP_H_ +#define _EFI_JUMP_H_ + +typedef struct { + UINT64 Rbx; + UINT64 Rsp; + UINT64 Rbp; + UINT64 Rdi; + UINT64 Rsi; + UINT64 R10; + UINT64 R11; + UINT64 R12; + UINT64 R13; + UINT64 R14; + UINT64 R15; + UINT64 Rip; + UINT32 MxCsr; + UINT8 XmmBuffer[160]; // XMM6-XMM15 +} EFI_JUMP_BUFFER; + +#endif diff --git a/Core/CPU/x64/Foundationx64.cif b/Core/CPU/x64/Foundationx64.cif new file mode 100644 index 0000000..cb10e7a --- /dev/null +++ b/Core/CPU/x64/Foundationx64.cif @@ -0,0 +1,15 @@ +<component> + name = "Foundationx64" + category = ModulePart + LocalRoot = "Core\CPU\x64\" + RefName = "Foundationx64" +[files] +"Foundationx64.sdl" +"Foundationx64.mak" +"ProcessorAsms.Asm" +"EfiJump.h" +"PeCoffLoaderEx.c" +"PeCoffLoaderEx.h" +"Processor.c" +"Processor.h" +<endComponent> diff --git a/Core/CPU/x64/Foundationx64.mak b/Core/CPU/x64/Foundationx64.mak new file mode 100644 index 0000000..488e672 --- /dev/null +++ b/Core/CPU/x64/Foundationx64.mak @@ -0,0 +1,65 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2006, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 6145-F Northbelt Pkwy, Norcross, GA 30071 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/SOURCE/Core/EDK/x64/Foundationx64.mak 1 8/24/06 12:36p Felixp $ +# +# $Revision: 1 $ +# +# $Date: 8/24/06 12:36p $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Core/EDK/x64/Foundationx64.mak $ +# +# 1 8/24/06 12:36p Felixp +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: Foundationx64.mak +# +# Description: +# +#<AMI_FHDR_END> +#********************************************************************** +Foundationx64 : $(BUILD_DIR)\Foundationx64.mak Foundationx64Bin + +$(BUILD_DIR)\Foundationx64.mak : $(Foundationx64_DIR)\$(@B).cif $(Foundationx64_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(Foundationx64_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +!IF "$(PROCESSOR)"=="x64" +FoundationBin : $(BUILD_DIR)\Foundationx64.lib +$(BUILD_DIR)\Foundationx64.lib : Foundationx64 +!ENDIF + + +Foundationx64Bin : + $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\ + /f $(BUILD_DIR)\Foundationx64.mak all\ + "CFLAGS=$(CFLAGS) /I$(Foundation_DIR)"\ + TYPE=LIBRARY +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2006, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 6145-F Northbelt Pkwy, Norcross, GA 30071 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#**********************************************************************
\ No newline at end of file diff --git a/Core/CPU/x64/Foundationx64.sdl b/Core/CPU/x64/Foundationx64.sdl new file mode 100644 index 0000000..bb61c1a --- /dev/null +++ b/Core/CPU/x64/Foundationx64.sdl @@ -0,0 +1,19 @@ +TOKEN + Name = "Foundationx64_SUPPORT" + Value = "1" + Help = "Main switch to enable Foundationx64 support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +PATH + Name = "Foundationx64_DIR" +End + +MODULE + Help = "Includes Foundationx64.mak to Project" + File = "Foundationx64.mak" +End + diff --git a/Core/CPU/x64/MiscLib/Misc.asm b/Core/CPU/x64/MiscLib/Misc.asm new file mode 100644 index 0000000..facdd89 --- /dev/null +++ b/Core/CPU/x64/MiscLib/Misc.asm @@ -0,0 +1,124 @@ +;********************************************************************** +;********************************************************************** +;** ** +;** (C)Copyright 1985-2010, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;********************************************************************** +;********************************************************************** + +;********************************************************************** +; $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/CPU Core/MiscX64Lib/Misc.asm 2 10/04/12 9:17a Davidhsieh $ +; +; $Revision: 2 $ +; +; $Date: 10/04/12 9:17a $ +;********************************************************************** +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/CPU Core/MiscX64Lib/Misc.asm $ +; +; 2 10/04/12 9:17a Davidhsieh +; Add MpMtrrSynchUpEntry and MpMtrrSynchUpExit procedures +; +; 1 5/15/12 5:41a Davidhsieh +; +; 1 5/08/12 6:02a Dukeyeh +; [TAG] EIP89382 +; [Category] Improvement +; [Description] clear direction flag inside Timer callback function. +; [Files] MiscX64Lib.cif +; Misc.asm +; MiscX64Lib.sdl +; MiscX64Lib.mak +; +; 6 1/13/10 2:13p Felixp +; +;********************************************************************** +;<AMI_FHDR_START> +; +; Name: Misc +; +; Description: +; +;<AMI_FHDR_END> +;********************************************************************** + +.code + +ClearDirectionFlag Proc + cld + ret +ClearDirectionFlag endp + +MpMtrrSynchUpEntry PROC PUBLIC + ; + ; Enter no fill cache mode, CD=1(Bit30), NW=0 (Bit29) + ; + mov rax, cr0 + and rax, 0DFFFFFFFh + or rax, 040000000h + mov cr0, rax + ; + ; Flush cache + ; + wbinvd + ; + ; Clear PGE flag Bit 7 + ; + mov rax, cr4 + mov rdx, rax + and rax, 0FFFFFF7Fh + mov cr4, rax + ; + ; Flush all TLBs + ; + mov rax, cr3 + mov cr3, rax + + mov rax, rdx + + ret + +MpMtrrSynchUpEntry ENDP + +MpMtrrSynchUpExit PROC PUBLIC + ; + ; Flush all TLBs the second time + ; + mov rax, cr3 + mov cr3, rax + ; + ; Enable Normal Mode caching CD=NW=0, CD(Bit30), NW(Bit29) + ; + mov rax, cr0 + and rax, 09FFFFFFFh + mov cr0, rax + ; + ; Set PGE Flag in CR4 if set + ; + mov cr4, rcx + ret + +MpMtrrSynchUpExit ENDP + +END + +;********************************************************************** +;********************************************************************** +;** ** +;** (C)Copyright 1985-2010, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;********************************************************************** +;**********************************************************************
\ No newline at end of file diff --git a/Core/CPU/x64/MiscLib/MiscX64Lib.cif b/Core/CPU/x64/MiscLib/MiscX64Lib.cif new file mode 100644 index 0000000..c05edf2 --- /dev/null +++ b/Core/CPU/x64/MiscLib/MiscX64Lib.cif @@ -0,0 +1,10 @@ +<component> + name = "MiscX64Lib" + category = ModulePart + LocalRoot = "Core\CPU\x64\MiscLib" + RefName = "MiscX64Lib" +[files] +"Misc.asm" +"MiscX64Lib.sdl" +"MiscX64Lib.mak" +<endComponent> diff --git a/Core/CPU/x64/MiscLib/MiscX64Lib.mak b/Core/CPU/x64/MiscLib/MiscX64Lib.mak new file mode 100644 index 0000000..61e7446 --- /dev/null +++ b/Core/CPU/x64/MiscLib/MiscX64Lib.mak @@ -0,0 +1,74 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2006, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 6145-F Northbelt Pkwy, Norcross, GA 30071 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/CPU Core/MiscX64Lib/MiscX64Lib.mak 1 5/15/12 5:41a Davidhsieh $ +# +# $Revision: 1 $ +# +# $Date: 5/15/12 5:41a $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/CPU Core/MiscX64Lib/MiscX64Lib.mak $ +# +# 1 5/15/12 5:41a Davidhsieh +# +# 1 5/08/12 6:02a Dukeyeh +# [TAG] EIP89382 +# [Category] Improvement +# [Description] clear direction flag inside Timer callback function. +# [Files] MiscX64Lib.cif +# Misc.asm +# MiscX64Lib.sdl +# MiscX64Lib.mak +# +# 1 10/13/06 8:37p Felixp +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: MiscX64Lib.mak +# +# Description: +# +#<AMI_FHDR_END> +#********************************************************************** +MiscX64Lib : $(BUILD_DIR)\MiscX64Lib.mak MiscX64LibBin + +$(BUILD_DIR)\MiscX64Lib.mak : $(MiscX64Lib_DIR)\$(@B).cif $(MiscX64Lib_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(MiscX64Lib_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +!IF "$(PROCESSOR)"=="x64" +AmiDxeLibBin : $(BUILD_DIR)\MiscX64Lib.lib +$(BUILD_DIR)\MiscX64Lib.lib : MiscX64Lib +!ENDIF + +MiscX64LibBin : + $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\ + /f $(BUILD_DIR)\MiscX64Lib.mak all\ + TYPE=LIBRARY +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2006, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 6145-F Northbelt Pkwy, Norcross, GA 30071 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#**********************************************************************
\ No newline at end of file diff --git a/Core/CPU/x64/MiscLib/MiscX64Lib.sdl b/Core/CPU/x64/MiscLib/MiscX64Lib.sdl new file mode 100644 index 0000000..a9c676e --- /dev/null +++ b/Core/CPU/x64/MiscLib/MiscX64Lib.sdl @@ -0,0 +1,19 @@ +TOKEN + Name = "MiscX64Lib_SUPPORT" + Value = "1" + Help = "Main switch to enable MiscX64Lib support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +PATH + Name = "MiscX64Lib_DIR" +End + +MODULE + Help = "Includes MiscX64Lib.mak to Project" + File = "MiscX64Lib.mak" +End + diff --git a/Core/CPU/x64/PeCoffLoaderEx.c b/Core/CPU/x64/PeCoffLoaderEx.c new file mode 100644 index 0000000..ff216a7 --- /dev/null +++ b/Core/CPU/x64/PeCoffLoaderEx.c @@ -0,0 +1,87 @@ +/*++ + +Copyright (c) 2005 - 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: + + PeCoffLoaderEx.c + +Abstract: + + x64 Specific relocation fixups + +Revision History + +--*/ + +#include "Tiano.h" +#include "EfiImage.h" + +EFI_STATUS +PeCoffLoaderRelocateImageEx ( + IN UINT16 *Reloc, + IN OUT CHAR8 *Fixup, + IN OUT CHAR8 **FixupData, + IN UINT64 Adjust + ) +/*++ + +Routine Description: + Performs an x64 specific relocation fixup + +Arguments: + Reloc - Pointer to the relocation record + Fixup - Pointer to the address to fix up + FixupData - Pointer to a buffer to log the fixups + Adjust - The offset to adjust the fixup + +Returns: + EFI_UNSUPPORTED - relocate unsupported + +--*/ +{ + return EFI_UNSUPPORTED; +} + +BOOLEAN +PeCoffLoaderImageFormatSupported ( + IN UINT16 Machine + ) +/*++ +Routine Description: + + Returns TRUE if the machine type of PE/COFF image is supported. Supported + does not mean the image can be executed it means the PE/COFF loader supports + loading and relocating of the image type. It's up to the caller to support + the entry point. + + This function implies the basic PE/COFF loader/relocator supports IA32, EBC, + & X64 images. Calling the entry point in a correct mannor is up to the + consumer of this library. + +Arguments: + + Machine - Machine type from the PE Header. + +Returns: + + TRUE - if this PE/COFF loader can load the image + FALSE - if this PE/COFF loader cannot load the image + +--*/ +{ + if ((Machine == EFI_IMAGE_MACHINE_IA32) || (Machine == EFI_IMAGE_MACHINE_X64) || + (Machine == EFI_IMAGE_MACHINE_EBC)) { + return TRUE; + } + + return FALSE; +} diff --git a/Core/CPU/x64/PeCoffLoaderEx.h b/Core/CPU/x64/PeCoffLoaderEx.h new file mode 100644 index 0000000..a3f78e0 --- /dev/null +++ b/Core/CPU/x64/PeCoffLoaderEx.h @@ -0,0 +1,85 @@ +/*++ + +Copyright (c) 2004 - 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: + + PeCoffLoaderEx.h + +Abstract: + + x64 Specific relocation fixups + +Revision History + +--*/ + +#ifndef _PE_COFF_LOADER_EX_H_ +#define _PE_COFF_LOADER_EX_H_ + +EFI_STATUS +PeCoffLoaderRelocateImageEx ( + IN UINT16 *Reloc, + IN OUT CHAR8 *Fixup, + IN OUT CHAR8 **FixupData, + IN UINT64 Adjust + ) +/*++ + +Routine Description: + + Performs an x64 specific relocation fixup + +Arguments: + + Reloc - Pointer to the relocation record + + Fixup - Pointer to the address to fix up + + FixupData - Pointer to a buffer to log the fixups + + Adjust - The offset to adjust the fixup + +Returns: + + EFI_UNSUPPORTED - relocate unsupported + +--*/ +; + +BOOLEAN +PeCoffLoaderImageFormatSupported ( + IN UINT16 Machine + ) +/*++ +Routine Description: + + Returns TRUE if the machine type of PE/COFF image is supported. Supported + does not mean the image can be executed it means the PE/COFF loader supports + loading and relocating of the image type. It's up to the caller to support + the entry point. + + This function implies the basic PE/COFF loader/relocator supports IA32, EBC, + & X64 images. Calling the entry point in a correct mannor is up to the + consumer of this library. + +Arguments: + + Machine - Machine type from the PE Header. + +Returns: + + TRUE - if this PE/COFF loader can load the image + FALSE - if this PE/COFF loader cannot load the image + +--*/ +; + +#endif diff --git a/Core/CPU/x64/Processor.c b/Core/CPU/x64/Processor.c new file mode 100644 index 0000000..21a1649 --- /dev/null +++ b/Core/CPU/x64/Processor.c @@ -0,0 +1,146 @@ +/*++ + +Copyright 2005 - 2009, 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: + + Processor.c + +Abstract: + +--*/ + +#include "Tiano.h" +#include "EfiJump.h" +#include EFI_GUID_DEFINITION (PeiFlushInstructionCache) +#include EFI_GUID_DEFINITION (PeiTransferControl) + +// +// Prototypes +// +EFI_STATUS +EFIAPI +TransferControlSetJump ( + IN EFI_PEI_TRANSFER_CONTROL_PROTOCOL *This, + IN EFI_JUMP_BUFFER *Jump + ); + +EFI_STATUS +EFIAPI +TransferControlLongJump ( + IN EFI_PEI_TRANSFER_CONTROL_PROTOCOL *This, + IN EFI_JUMP_BUFFER *Jump + ); + +EFI_STATUS +EFIAPI +FlushInstructionCacheFlush ( + IN EFI_PEI_FLUSH_INSTRUCTION_CACHE_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length + ); + +// +// Table declarations +// +EFI_PEI_TRANSFER_CONTROL_PROTOCOL mTransferControl = { + TransferControlSetJump, + TransferControlLongJump, + sizeof (EFI_JUMP_BUFFER) +}; + +EFI_PEI_FLUSH_INSTRUCTION_CACHE_PROTOCOL mFlushInstructionCache = { + FlushInstructionCacheFlush +}; + + +EFI_STATUS +EFIAPI +InstallEfiPeiTransferControl( + IN OUT EFI_PEI_TRANSFER_CONTROL_PROTOCOL **This + ) +/*++ + +Routine Description: + + Installs the pointer to the transfer control mechanism + +Arguments: + + This - Pointer to transfer control mechanism. + +Returns: + + This - Pointer to transfer control mechanism. + +--*/ +{ + *This = &mTransferControl; + return EFI_SUCCESS; +} + + +EFI_STATUS +EFIAPI +InstallEfiPeiFlushInstructionCache ( + IN OUT EFI_PEI_FLUSH_INSTRUCTION_CACHE_PROTOCOL **This + ) +/*++ + +Routine Description: + + Installs the pointer to the flush instruction cache mechanism + +Arguments: + + This - Pointer to flush instruction cache mechanism. + +Returns: + + This - Pointer to flush instruction cache mechanism. + +--*/ +{ + *This = &mFlushInstructionCache; + return EFI_SUCCESS; +} + + +EFI_STATUS +EFIAPI +FlushInstructionCacheFlush ( + IN EFI_PEI_FLUSH_INSTRUCTION_CACHE_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS Start, + IN UINT64 Length + ) +/*++ + +Routine Description: + + This routine would provide support for flushing the CPU instruction cache. + In the case of IA32, this flushing is not necessary and is thus not implemented. + +Arguments: + + Pointer to CPU Architectural Protocol interface + Start adddress in memory to flush + Length of memory to flush + +Returns: + + Status + EFI_SUCCESS + +--*/ +{ + return EFI_SUCCESS; +} + diff --git a/Core/CPU/x64/Processor.h b/Core/CPU/x64/Processor.h new file mode 100644 index 0000000..cdf2992 --- /dev/null +++ b/Core/CPU/x64/Processor.h @@ -0,0 +1,27 @@ +/*++ + +Copyright (c) 2005, 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: + Processor.h + +Abstract: + This file contains the x64 processor specific definitions + +--*/ + +#ifndef _PROCESSOR_H_ +#define _PROCESSOR_H_ + +#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE) + +#define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE) + +#endif diff --git a/Core/CPU/x64/ProcessorAsms.Asm b/Core/CPU/x64/ProcessorAsms.Asm new file mode 100644 index 0000000..ebd8b03 --- /dev/null +++ b/Core/CPU/x64/ProcessorAsms.Asm @@ -0,0 +1,186 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2005 - 2007, 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: +; ProcessorAsms.Asm +; +; Abstract: +; This is separated from processor.c to allow this functions to be built with /O1 +; +; +;------------------------------------------------------------------------------ + +text SEGMENT + + +; +; Routine Description: +; This allows the caller to switch the stack and goes to the new entry point +; +; Arguments: +; EntryPoint - Pointer to the location to enter // rcx +; Parameter - Parameter to pass in // rdx +; NewStack - New Location of the stack // r8 +; NewBsp - New BSP // r9 - not used +; +; Returns: +; Nothing. Goes to the Entry Point passing in the new parameters +; +SwitchStacks PROC PUBLIC + + ; Adjust stack for + ; 1) leave 4 registers space + ; 2) let it 16 bytes aligned after call + sub r8, 20h + and r8w, 0fff0h ; do not assume 16 bytes aligned + + mov rsp, r8 ; rsp = NewStack + mov r10, rcx ; save EntryPoint + mov rcx, rdx ; Arg1 = Parameter + call r10 ; r10 = copy of EntryPoint + ; + ; no ret as we have a new stack and we jumped to the new location + ; + ret + +SwitchStacks ENDP + + +EFI_SUCCESS equ 0 +EFI_WARN_RETURN_FROM_LONG_JUMP equ 5 + +; +; Generated by h2inc run manually +; +_EFI_JUMP_BUFFER STRUCT 2t +_rbx QWORD ? +_rsp QWORD ? +_rbp QWORD ? +_rdi QWORD ? +_rsi QWORD ? +_r10 QWORD ? +_r11 QWORD ? +_r12 QWORD ? +_r13 QWORD ? +_r14 QWORD ? +_r15 QWORD ? +_rip QWORD ? +_MxCsr DWORD ? +_XmmBuffer DB 160 DUP (?) +_EFI_JUMP_BUFFER ENDS + +EFI_JUMP_BUFFER TYPEDEF _EFI_JUMP_BUFFER + + +; +;Routine Description: +; +; This routine implements the x64 variant of the SetJump call. Its +; responsibility is to store system state information for a possible +; subsequent LongJump. +; +;Arguments: +; +; Pointer to CPU context save buffer. +; +;Returns: +; +; EFI_SUCCESS +; +; EFI_STATUS +; EFIAPI +; TransferControlLongJump ( +; IN EFI_PEI_TRANSFER_CONTROL_PROTOCOL *This, +; IN EFI_JUMP_BUFFER *Jump +; ); +; +; rcx - *This +; rdx - JumpBuffer +; +PUBLIC TransferControlSetJump +TransferControlSetJump PROC + mov (EFI_JUMP_BUFFER PTR [rdx])._rbx, rbx + mov (EFI_JUMP_BUFFER PTR [rdx])._rsp, rsp + mov (EFI_JUMP_BUFFER PTR [rdx])._rbp, rbp + mov (EFI_JUMP_BUFFER PTR [rdx])._rdi, rdi + mov (EFI_JUMP_BUFFER PTR [rdx])._rsi, rsi + mov (EFI_JUMP_BUFFER PTR [rdx])._r10, r10 + mov (EFI_JUMP_BUFFER PTR [rdx])._r11, r11 + mov (EFI_JUMP_BUFFER PTR [rdx])._r12, r12 + mov (EFI_JUMP_BUFFER PTR [rdx])._r13, r13 + mov (EFI_JUMP_BUFFER PTR [rdx])._r14, r14 + mov (EFI_JUMP_BUFFER PTR [rdx])._r15, r15 + ; save non-volatile fp registers + stmxcsr (EFI_JUMP_BUFFER PTR [rdx])._MxCsr + lea rax, (EFI_JUMP_BUFFER PTR [rdx])._XmmBuffer + movdqu [rax], xmm6 + movdqu [rax + 10h], xmm7 + movdqu [rax + 20h], xmm8 + movdqu [rax + 30h], xmm9 + movdqu [rax + 40h], xmm10 + movdqu [rax + 50h], xmm11 + movdqu [rax + 60h], xmm12 + movdqu [rax + 70h], xmm13 + movdqu [rax + 80h], xmm14 + movdqu [rax + 90h], xmm15 + mov rax, QWORD PTR [rsp+0] + mov (EFI_JUMP_BUFFER PTR [rdx])._rip, rax + mov rax, EFI_SUCCESS + ret + +TransferControlSetJump ENDP + +; +; EFI_STATUS +; EFIAPI +; TransferControlLongJump ( +; IN EFI_PEI_TRANSFER_CONTROL_PROTOCOL *This, // rcx +; IN EFI_JUMP_BUFFER *Jump // rdx +; ); +; +; +PUBLIC TransferControlLongJump +TransferControlLongJump PROC + ; load non-volatile fp registers + ldmxcsr (EFI_JUMP_BUFFER PTR [rdx])._MxCsr + lea rax, (EFI_JUMP_BUFFER PTR [rdx])._XmmBuffer + movdqu xmm6, [rax] + movdqu xmm7, [rax + 10h] + movdqu xmm8, [rax + 20h] + movdqu xmm9, [rax + 30h] + movdqu xmm10, [rax + 40h] + movdqu xmm11, [rax + 50h] + movdqu xmm12, [rax + 60h] + movdqu xmm13, [rax + 70h] + movdqu xmm14, [rax + 80h] + movdqu xmm15, [rax + 90h] + ; set return from SetJump to EFI_WARN_RETURN_FROM_LONG_JUMP + mov rax, EFI_WARN_RETURN_FROM_LONG_JUMP + mov rbx, (EFI_JUMP_BUFFER PTR [rdx])._rbx + mov rsp, (EFI_JUMP_BUFFER PTR [rdx])._rsp + mov rbp, (EFI_JUMP_BUFFER PTR [rdx])._rbp + mov rdi, (EFI_JUMP_BUFFER PTR [rdx])._rdi + mov rsi, (EFI_JUMP_BUFFER PTR [rdx])._rsi + mov r10, (EFI_JUMP_BUFFER PTR [rdx])._r10 + mov r11, (EFI_JUMP_BUFFER PTR [rdx])._r11 + mov r12, (EFI_JUMP_BUFFER PTR [rdx])._r12 + mov r13, (EFI_JUMP_BUFFER PTR [rdx])._r13 + mov r14, (EFI_JUMP_BUFFER PTR [rdx])._r14 + mov r15, (EFI_JUMP_BUFFER PTR [rdx])._r15 + add rsp, 8 ;pop the eip + jmp QWORD PTR (EFI_JUMP_BUFFER PTR [rdx])._rip + ; set return from SetJump to EFI_WARN_RETURN_FROM_LONG_JUMP + mov rax, EFI_WARN_RETURN_FROM_LONG_JUMP + ret +TransferControlLongJump ENDP + +text ENDS +END diff --git a/Core/CPU/x64/x64AsmLib/CPULIB_GetPageTable.asm b/Core/CPU/x64/x64AsmLib/CPULIB_GetPageTable.asm new file mode 100644 index 0000000..973357f --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/CPULIB_GetPageTable.asm @@ -0,0 +1,80 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULIB_GetPageTable.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULIB_GetPageTable.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: CPULIB_GetPageTable +; +; Description: +; VOID* CPULIB_GetPageTable() retrieves the address of the page table. +; +; Input: +; VOID. +; +; Output: +; VOID* address of the page table. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +CPULIB_GetPageTable proc + mov rax, cr3 + ret +CPULIB_GetPageTable endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/CPULib_CpuID.asm b/Core/CPU/x64/x64AsmLib/CPULib_CpuID.asm new file mode 100644 index 0000000..53719f2 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/CPULib_CpuID.asm @@ -0,0 +1,130 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_CpuID.asm 2 11/11/11 3:40p Artems $ +; +; $Revision: 2 $ +; +; $Date: 11/11/11 3:40p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_CpuID.asm $ +; +; 2 11/11/11 3:40p Artems +; Bug fix: Verify pointer is not NULL, when return value +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: CPULib_CpuID +; +; Description: +; VOID CPULib_CpuID(IN UINT32 CpuIDIndex, IN UINT32 *pRegEAX, +; IN UINT32 *pRegEBX, IN UINT32 *pRegECX, IN UINT32 *pRegEDX) issues the +; CPUID instruction with the index provided and returns the register values. +; +; Input: +; IN UINT32 CpuIDIndex +; 32-bit CPUID index. +; +; IN UINT32 *pRegEAX +; Value of EAX after CPUID instruction. +; +; IN UINT32 *pRegEBX +; Value of EBX after CPUID instruction. +; +; IN UINT32 *pRegECX +; Value of ECX after CPUID instruction. +; +; IN UINT32 *pRegEDX +; Value of EDX after CPUID instruction. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +CPULib_CpuID proc +;rcx = CpuIDIndex +;rdx = pRegEax +;r8 = pRegEBX +;r9 = pRegECX +;[rsp + 8] = pRegEDX:DWORD + + push rbx + mov r11, [rsp + 30h] ;pRegEDX + mov r10, r9 ;pRegECX + mov r9, r8 ;pRegEBX + mov r8, rdx ;pRegEAX + + mov eax, ecx + mov ecx, [r10] + cpuid + + or r8, r8 + jz skip1 + mov [r8], eax +skip1: + or r9, r9 + jz skip2 + mov [r9], ebx +skip2: + or r10, r10 + jz skip3 + mov [r10], ecx +skip3: + or r11, r11 + jz skip4 + mov [r11], edx +skip4: + pop rbx + ret +CPULib_CpuID endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/CPULib_DisableInterrupt.asm b/Core/CPU/x64/x64AsmLib/CPULib_DisableInterrupt.asm new file mode 100644 index 0000000..6c63f8a --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/CPULib_DisableInterrupt.asm @@ -0,0 +1,81 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_DisableInterrupt.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_DisableInterrupt.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: CPULib_DisableInterrupt +; +; Description: +; VOID CPULib_DisableInterrupt() disables interrupts on the CPU. +; +; Input: +; VOID. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +CPULib_DisableInterrupt PROC PUBLIC +; Disable Interrupt + cli + ret +CPULib_DisableInterrupt ENDP + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/CPULib_EnableInterrupt.asm b/Core/CPU/x64/x64AsmLib/CPULib_EnableInterrupt.asm new file mode 100644 index 0000000..bc43c62 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/CPULib_EnableInterrupt.asm @@ -0,0 +1,81 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_EnableInterrupt.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_EnableInterrupt.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: CPULib_EnableInterrupt +; +; Description: +; VOID CPULib_EnableInterrupt() enables interrupts on the CPU. +; +; Input: +; VOID. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +CPULib_EnableInterrupt PROC PUBLIC +; Enable Interrupt + sti + ret +CPULib_EnableInterrupt ENDP + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/CPULib_GetInterruptState.asm b/Core/CPU/x64/x64AsmLib/CPULib_GetInterruptState.asm new file mode 100644 index 0000000..436cba7 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/CPULib_GetInterruptState.asm @@ -0,0 +1,87 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_GetInterruptState.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_GetInterruptState.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: CPULib_GetInterruptState +; +; Description: +; BOOLEAN CPULib_GetInterruptState()returns the current CPU interrupt state. +; +; Input: +; VOID. +; +; Output: +; FALSE if interrupts are disabled; otherwise TRUE. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +CPULib_GetInterruptState PROC PUBLIC + xor cl, cl + pushf ; push flags onto stack. + pop ax ; eax = flags. + bt ax, 9 ; IF (bit 9) if set, set carry flag. + ; Interrupts are allowed if IF is set. + adc cl, 0 ; CL = IF = CF. + + mov al, cl ; Return value + ret +CPULib_GetInterruptState ENDP + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/CPULib_LoadGdt.asm b/Core/CPU/x64/x64AsmLib/CPULib_LoadGdt.asm new file mode 100644 index 0000000..1fc3c23 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/CPULib_LoadGdt.asm @@ -0,0 +1,82 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_LoadGdt.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_LoadGdt.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: CPULib_LoadGdt +; +; Description: +; VOID CPULib_LoadGdt(IN VOID *ptr) loads the GDT at the location pointed to +; by ptr. +; +; Input: +; IN VOID *ptr +; Address of the GDT to be loaded. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +CPULib_LoadGdt proc + lgdt fword ptr [rcx] + ret +CPULib_LoadGdt endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/CPULib_LoadIdt.asm b/Core/CPU/x64/x64AsmLib/CPULib_LoadIdt.asm new file mode 100644 index 0000000..3c4afc8 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/CPULib_LoadIdt.asm @@ -0,0 +1,82 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_LoadIdt.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_LoadIdt.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: CPULib_LoadIdt +; +; Description: +; VOID CPULib_LoadIdt(IN VOID *ptr) loads the IDT at the location provided +; by ptr. +; +; Input: +; IN VOID *ptr +; Address of the IDT to be loaded. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +CPULib_LoadIdt proc + lidt fword ptr [rcx] + ret +CPULib_LoadIdt endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/CPULib_LockByteDec.asm b/Core/CPU/x64/x64AsmLib/CPULib_LockByteDec.asm new file mode 100644 index 0000000..433bd1b --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/CPULib_LockByteDec.asm @@ -0,0 +1,82 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_LockByteDec.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_LockByteDec.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: CPULib_LockByteDec +; +; Description: +; VOID CPULib_LockByteDec(IN UINT8 *ptr) locks the preceeding byte before +; the address pointed to by ptr. +; +; Input: +; IN UINT8 *ptr +; Address to the byte which follows the desired byte to be locked. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +CPULib_LockByteDec proc + lock dec byte ptr [rcx] + ret +CPULib_LockByteDec endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/CPULib_LockByteInc.asm b/Core/CPU/x64/x64AsmLib/CPULib_LockByteInc.asm new file mode 100644 index 0000000..83addc8 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/CPULib_LockByteInc.asm @@ -0,0 +1,82 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_LockByteInc.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_LockByteInc.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: CPULib_LockByteInc +; +; Description: +; VOID CPULib_LockByteInc(IN UINT8 *ptr) locks the next byte after the +; address pointed to by ptr. +; +; Input: +; IN UINT8 *ptr +; Address to the byte which preceeds the desired byte to be locked. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +CPULib_LockByteInc proc + lock inc byte ptr [rcx] + ret +CPULib_LockByteInc endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/CPULib_Pause.asm b/Core/CPU/x64/x64AsmLib/CPULib_Pause.asm new file mode 100644 index 0000000..c7d2574 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/CPULib_Pause.asm @@ -0,0 +1,80 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_Pause.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_Pause.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: CPULib_Pause +; +; Description: +; VOID CPULib_Pause() performs the pause assembly instruction. +; +; Input: +; VOID. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +CPULib_Pause Proc + pause + ret +CPULib_Pause endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/CPULib_SaveGdt.asm b/Core/CPU/x64/x64AsmLib/CPULib_SaveGdt.asm new file mode 100644 index 0000000..28258cf --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/CPULib_SaveGdt.asm @@ -0,0 +1,83 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_SaveGdt.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_SaveGdt.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: CPULib_SaveGdt +; +; Description: +; VOID CPULib_SaveGdt(IN VOID *ptr) stores the loaded GDT at the location +; provided by ptr. +; +; Input: +; IN VOID *ptr +; Address to save the GDT. User is responsible for allocating the necessary +; memory resources. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +CPULib_SaveGdt proc + sgdt fword ptr [rcx] + ret +CPULib_SaveGdt endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/CPULib_SaveIdt.asm b/Core/CPU/x64/x64AsmLib/CPULib_SaveIdt.asm new file mode 100644 index 0000000..046b7f6 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/CPULib_SaveIdt.asm @@ -0,0 +1,83 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_SaveIdt.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/CPULib_SaveIdt.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: CPULib_SaveIdt +; +; Description: +; VOID CPULib_SaveIdt(IN VOID *ptr) stores the loaded IDT at the location +; provided by ptr. +; +; Input: +; IN VOID *ptr +; Address to save the IDT. User is responsible for allocating the necessary +; memory resources. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +CPULib_SaveIdt proc + sidt fword ptr [rcx] + ret +CPULib_SaveIdt endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/DisableCacheInCR0.asm b/Core/CPU/x64/x64AsmLib/DisableCacheInCR0.asm new file mode 100644 index 0000000..c03cd1f --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/DisableCacheInCR0.asm @@ -0,0 +1,84 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/DisableCacheInCR0.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/DisableCacheInCR0.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: DisableCacheInCR0 +; +; Description: +; VOID DisableCacheInCR0() disables the CPU cache using the CR0 register. +; +; Input: +; VOID. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +DisableCacheInCR0 PROC PUBLIC + wbinvd + mov rax, cr0 + or eax, 060000000h ;SET CD, NW + mov cr0, rax + wbinvd ;Invalidate cache + ret +DisableCacheInCR0 ENDP + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/EnableCacheInCR0.asm b/Core/CPU/x64/x64AsmLib/EnableCacheInCR0.asm new file mode 100644 index 0000000..7633a1f --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/EnableCacheInCR0.asm @@ -0,0 +1,84 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/EnableCacheInCR0.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/EnableCacheInCR0.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: EnableCacheInCR0 +; +; Description: +; VOID EnableCacheInCR0() enables the CPU cache using the CR0 register. +; +; Input: +; VOID. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +EnableCacheInCR0 PROC PUBLIC +; Enable cache + mov rax, cr0 + and eax, 09fffffffh ;SET CD, NW + mov cr0, rax + wbinvd + ret +EnableCacheInCR0 ENDP + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/EnableMachineCheck.asm b/Core/CPU/x64/x64AsmLib/EnableMachineCheck.asm new file mode 100644 index 0000000..b220afd --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/EnableMachineCheck.asm @@ -0,0 +1,83 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/EnableMachineCheck.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/EnableMachineCheck.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: EnableMachineCheck +; +; Description: +; VOID EnableMachineCheck() sets the Machine Check Exception bit in CR4, +; which enables machine check interrupts to occur. +; +; Input: +; VOID. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +EnableMachineCheck proc + mov rax, cr4 + or eax, 1 SHL 6 + mov cr4, rax + ret +EnableMachineCheck endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/GetCpuTimer.asm b/Core/CPU/x64/x64AsmLib/GetCpuTimer.asm new file mode 100644 index 0000000..f606744 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/GetCpuTimer.asm @@ -0,0 +1,82 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/GetCpuTimer.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/GetCpuTimer.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: GetCpuTimer +; +; Description: +; UINT64 GetCpuTimer() returns the value of the CPU timer. +; +; Input: +; None. +; +; Output: +; UINT64 value of the CPU timer. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +GetCpuTimer proc + rdtsc + shl rdx,32 + or rax, rdx + ret +GetCpuTimer endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/GetCsSegment.asm b/Core/CPU/x64/x64AsmLib/GetCsSegment.asm new file mode 100644 index 0000000..02138c3 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/GetCsSegment.asm @@ -0,0 +1,79 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/GetCsSegment.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/GetCsSegment.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: GetCsSegment +; +; Description: +; UINT16 GetCsSegment() retreives the value of the CS register. +; +; Input: +; VOID. +; +; Output: +; UINT16 value of CS. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +GetCsSegment proc + mov ax, cs + ret +GetCsSegment endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/GetPowerOfTwo64.asm b/Core/CPU/x64/x64AsmLib/GetPowerOfTwo64.asm new file mode 100644 index 0000000..9cebe72 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/GetPowerOfTwo64.asm @@ -0,0 +1,84 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/GetPowerOfTwo64.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/GetPowerOfTwo64.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: GetPowerOfTwo64 +; +; Description: +; UINT64 GetPowerOfTwo64(IN UINT64 Input) returns the highest bit set in +; the provided UINT64 Input. Equivalent to 1 << log2(x). +; +; Input: +; IN UINT64 Input +; The 64-bit value to check for its highest bit. +; +; Output: +; UINT64 value of the highest bit; if Input is 0, returns 0. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +GetPowerOfTwo64 proc + bsr rdx, rcx + xor rax, rax + bts rax, rdx + ret +GetPowerOfTwo64 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/HltCpu.asm b/Core/CPU/x64/x64AsmLib/HltCpu.asm new file mode 100644 index 0000000..a8c8a6e --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/HltCpu.asm @@ -0,0 +1,83 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/HltCpu.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/HltCpu.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: HltCpu +; +; Description: +; VOID HltCpu() halts the CPU. +; +; Input: +; VOID. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +HltCpu Proc +@@: + cli + hlt + jmp @b + ret +HltCpu endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/IoRead16.asm b/Core/CPU/x64/x64AsmLib/IoRead16.asm new file mode 100644 index 0000000..3403a34 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/IoRead16.asm @@ -0,0 +1,83 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoRead16.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoRead16.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: IoRead16 +; +; Description: +; UINT16 IoRead16(IN UINT16 Port) reads the 16-bit value stored at the I/O +; port defined by Port. +; +; Input: +; IN UINT16 Port +; I/O port to read 16-bits from. +; +; Output: +; UINT16 value stored at I/O Port. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +IoRead16 proc + mov dx, cx + in ax, dx + ret +IoRead16 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/IoRead32.asm b/Core/CPU/x64/x64AsmLib/IoRead32.asm new file mode 100644 index 0000000..510a01f --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/IoRead32.asm @@ -0,0 +1,83 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoRead32.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoRead32.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: IoRead32 +; +; Description: +; UINT32 IoRead32(IN UINT16 Port) reads the 32-bit value stored at the I/O +; port defined by Port. +; +; Input: +; IN UINT16 Port +; I/O port to read 32-bits from. +; +; Output: +; UINT32 value stored at I/O Port. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +IoRead32 proc + mov dx, cx + in eax, dx + ret +IoRead32 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/IoRead64.asm b/Core/CPU/x64/x64AsmLib/IoRead64.asm new file mode 100644 index 0000000..ff1da50 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/IoRead64.asm @@ -0,0 +1,83 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoRead64.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoRead64.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: IoRead64 +; +; Description: +; UINT32 IoRead64(IN UINT16 Port) reads the 64-bit value stored at the I/O +; port defined by Port. +; +; Input: +; IN UINT16 Port +; I/O port to read 64-bits from. +; +; Output: +; UINT64 value stored at I/O Port. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +IoRead64 proc + mov dx, cx + in rax, dx + ret +IoRead64 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/IoRead8.asm b/Core/CPU/x64/x64AsmLib/IoRead8.asm new file mode 100644 index 0000000..3dfd1fd --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/IoRead8.asm @@ -0,0 +1,83 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoRead8.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoRead8.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: IoRead8 +; +; Description: +; UINT8 IoRead8(IN UINT16 Port) reads the 8-bit value stored at the I/O +; port defined by Port. +; +; Input: +; IN UINT16 Port +; I/O port to read 8-bits from. +; +; Output: +; UINT8 value stored at I/O Port. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +IoRead8 proc + mov dx, cx + in al, dx + ret +IoRead8 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/IoWrite16.asm b/Core/CPU/x64/x64AsmLib/IoWrite16.asm new file mode 100644 index 0000000..2616d1a --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/IoWrite16.asm @@ -0,0 +1,87 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoWrite16.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoWrite16.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: IoWrite16 +; +; Description: +; VOID IoWrite16(IN UINT16 Port, IN UINT16 Value) writes the 16-bit Value +; to the I/O port defined by Port. +; +; Input: +; IN UINT16 Port +; I/O port to write 16-bits to. +; +; IN UINT16 Value +; 16-bits to write to the I/O Port. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +IoWrite16 proc + mov ax, dx + mov dx, cx + out dx, ax + ret +IoWrite16 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/IoWrite32.asm b/Core/CPU/x64/x64AsmLib/IoWrite32.asm new file mode 100644 index 0000000..98096d7 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/IoWrite32.asm @@ -0,0 +1,87 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoWrite32.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoWrite32.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: IoWrite32 +; +; Description: +; VOID IoWrite32(IN UINT16 Port, IN UINT32 Value) writes the 32-bit Value +; to the I/O port defined by Port. +; +; Input: +; IN UINT16 Port +; I/O port to write 32-bits to. +; +; IN UINT32 Value +; 32-bits to write to the I/O Port. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +IoWrite32 proc + mov eax, edx + mov dx, cx + out dx, eax + ret +IoWrite32 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/IoWrite64.asm b/Core/CPU/x64/x64AsmLib/IoWrite64.asm new file mode 100644 index 0000000..c38c832 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/IoWrite64.asm @@ -0,0 +1,87 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoWrite64.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoWrite64.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: IoWrite64 +; +; Description: +; VOID IoWrite64(IN UINT16 Port, IN UINT64 Value) writes the 64-bit Value +; to the I/O port defined by Port. +; +; Input: +; IN UINT16 Port +; I/O port to write 64-bits to. +; +; IN UINT64 Value +; 64-bits to write to the I/O Port. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +IoWrite64 proc + mov rax, rdx + mov dx, cx + out dx, rax + ret +IoWrite64 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/IoWrite8.asm b/Core/CPU/x64/x64AsmLib/IoWrite8.asm new file mode 100644 index 0000000..4bd5119 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/IoWrite8.asm @@ -0,0 +1,87 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoWrite8.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/IoWrite8.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: IoWrite8 +; +; Description: +; VOID IoWrite8(IN UINT16 Port, IN UINT8 Value) writes the 8-bit Value to +; the I/O port defined by Port. +; +; Input: +; IN UINT16 Port +; I/O port to write 8-bits to. +; +; IN UINT8 Value +; 8-bits to write to the I/O Port. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +IoWrite8 proc + mov al, dl + mov dx, cx + out dx, al + ret +IoWrite8 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/MemCpy.asm b/Core/CPU/x64/x64AsmLib/MemCpy.asm new file mode 100644 index 0000000..a671ec8 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/MemCpy.asm @@ -0,0 +1,178 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/MemCpy.asm 2 3/09/11 1:58p Felixp $ +; +; $Revision: 2 $ +; +; $Date: 3/09/11 1:58p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/MemCpy.asm $ +; +; 2 3/09/11 1:58p Felixp +; MemCpy is updated to copy 8 bytes at a time (used to be 4) +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: MemCpy +; +; Description: +; VOID MemCpy(OUT VOID *pDestination, IN VOID *pSource, IN UINTN Count) +; copies Count bytes of memory from Source to Destination. +; +; Input: +; OUT VOID *pDestination +; Memory address where data shall be copied. User is responsible for +; allocating the necessary memory resources. +; +; IN VOID *pSource +; Memory address from where data shall be copied. +; +; IN UINTN Count +; Number of bytes to copy from pSource. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; This function checks for overlapping of source and destination and +; selects copy direction that prevents memory corruption. +; +;<AMI_PHDR_END> +;************************************************************************* +public memcpy +memcpy: +MemCpy proc + push rdi + push rsi + push rbx + pushf + mov rsi, rdx ; pSource + mov rdi, rcx ; pDestination + mov rcx, r8 ; Count + mov dl, 0 + ; if pSource > pDestination CopyForward + mov rax, rsi + sub rax, rdi ; rax = pSource-pDestination + jnb CopyForward; if pSource-pDestination > 0 CopyForward + ; if pSource+Count < pDestination then CopyForward + lea rbx, [rsi+rcx] ; rbx = pSource + Count + neg rax ; rax = pDestination - pSource + cmp rbx, rdi + jb CopyForward ; if (pSource + Count < pDestination ) CopyForward + ; Copy Backward + mov rsi, rbx; rsi = pSource + Count + lea rdi, [rdi+rcx]; rdi = pDestination + Count + mov dl, 1; Flag to indicate that we are copying backward + std; set direction flag to copy backward +CopyForward: + cmp rcx, 8 ; if (Counter<8) copy byte by byte + jb m8 + cmp rax, 8 ; if (pDestination - pSource < 8) copy byte by byte + jb m8 + ; if pSource and pDestination are not 8 byte aligned + ; Calculate 8-(Buffer%8), which is a number of bytes we have to copy to align the buffer + ; if this number if the same for source and destinations + ; copy several bytes to align them + ; otherwise proceed to QWORD copy + mov rax, rsi + mov rbx, rdi + and rax, 7 + and rbx, 7 + test dl, dl + jz skip1 + dec rsi + dec rdi +skip1: + cmp rax, rbx + jne m64 + test rax, rax + jz m64 + test dl, dl + jnz skip_nz1 + neg rax + add rax, 8 +skip_nz1: + xchg rax, rcx + sub rax, rcx + rep movsb + mov rcx, rax +m64: + test dl, dl + jz skip2 + sub rsi, 7 + sub rdi, 7 +skip2: + mov rax, rcx + shr rcx, 3 + rep movsq + and rax, 7 + jz MemCpuEnd + test dl, dl + jz skip3 + add rsi, 8 + add rdi, 8 +skip3: + mov rcx, rax +m8: + test dl, dl + jz skip4 + dec rsi + dec rdi +skip4: + rep movsb +MemCpuEnd: + popf + pop rbx + pop rsi + pop rdi + ret +MemCpy endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/MemCpy32.asm b/Core/CPU/x64/x64AsmLib/MemCpy32.asm new file mode 100644 index 0000000..a5886b3 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/MemCpy32.asm @@ -0,0 +1,178 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/MemCpy32.asm 1 10/17/11 1:03p Yakovlevs $ +; +; $Revision: 1 $ +; +; $Date: 10/17/11 1:03p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/MemCpy32.asm $ +; +; 1 10/17/11 1:03p Yakovlevs +; [TAG] EIP71694 +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: MemCpy32 +; +; Description: +; VOID MemCpy32(OUT VOID *pDestination, IN VOID *pSource, IN UINTN Count) +; copies Count bytes of memory from Source to Destination. +; +; Input: +; OUT VOID *pDestination +; Memory address where data shall be copied. User is responsible for +; allocating the necessary memory resources. +; +; IN VOID *pSource +; Memory address from where data shall be copied. +; +; IN UINTN Count +; Number of bytes to copy from pSource. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; This function checks for overlapping of source and destination and +; selects copy direction that prevents memory corruption. +; +;<AMI_PHDR_END> +;************************************************************************* +public memcpy32 +memcpy32: +MemCpy32 proc + push rdi + push rsi + push rbx + pushf + mov rsi, rdx ; pSource + mov rdi, rcx ; pDestination + mov rcx, r8 ; Count + mov dl, 0 + ; if pSource > pDestination CopyForward + mov rax, rsi + sub rax, rdi ; rax = pSource-pDestination + jnb CopyForward; if pSource-pDestination > 0 CopyForward + ; if pSource+Count < pDestination then CopyForward + lea rbx, [rsi+rcx] ; rbx = pSource + Count + neg rax ; rax = pDestination - pSource + cmp rbx, rdi + jb CopyForward ; if (pSource + Count < pDestination ) CopyForward + ; Copy Backward + mov rsi, rbx; rsi = pSource + Count + lea rdi, [rdi+rcx]; rdi = pDestination + Count + mov dl, 1; Flag to indicate that we are copying backward + std; set direction flag to copy backward +CopyForward: + cmp rcx, 4 ; if (Counter<4) copy byte by byte + jb m8 + cmp rax, 4 ; if (pDestination - pSource < 4) copy byte by byte + jb m8 + ; if pSource and pDestination are not 4 byte aligned + ; Calculate 4-(Buffer%4), which is a number of bytes we have to copy to align the buffer + ; if this number if the same for source and destinations + ; copy several bytes to align them + ; otherwise proceed to DWORD copy + mov rax, rsi + mov rbx, rdi + and rax, 3 + and rbx, 3 + test dl, dl + jz skip1 + dec rsi + dec rdi +skip1: + cmp rax, rbx + jne m32 + test rax, rax + jz m32 + test dl, dl + jnz skip_nz1 + neg rax + add rax, 4 +skip_nz1: + xchg rax, rcx + sub rax, rcx + rep movsb + mov rcx, rax +m32: + test dl, dl + jz skip2 + sub rsi, 3 + sub rdi, 3 +skip2: + mov rax, rcx + shr rcx, 2 + rep movsd + and rax, 3 + jz MemCpuEnd + test dl, dl + jz skip3 + add rsi, 4 + add rdi, 4 +skip3: + mov rcx, rax +m8: + test dl, dl + jz skip4 + dec rsi + dec rdi +skip4: + rep movsb +MemCpuEnd: + popf + pop rbx + pop rsi + pop rdi + ret +MemCpy32 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/MemRead32.asm b/Core/CPU/x64/x64AsmLib/MemRead32.asm new file mode 100644 index 0000000..3f79a06 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/MemRead32.asm @@ -0,0 +1,82 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/MemRead32.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/MemRead32.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: MemRead32 +; +; Description: +; UINT32 MemRead32(IN UINT32 *Address) reads and returns the 32-bit value +; stored at the user provided address. +; +; Input: +; IN UINT32 *Address +; Address to read 32-bits from. +; +; Output: +; UINT32 value stored at Address. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +MemRead32 proc + mov eax, [rcx] + ret +MemRead32 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/MemReadWrite32.asm b/Core/CPU/x64/x64AsmLib/MemReadWrite32.asm new file mode 100644 index 0000000..a9ab5ba --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/MemReadWrite32.asm @@ -0,0 +1,93 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/MemReadWrite32.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/MemReadWrite32.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: MemReadWrite32 +; +; Description: +; VOID MemReadWrite32(IN UINT32 *Address, IN UINT32 Value, IN UINT32 Mask) +; reads the 32-bit value stored at Address, ANDs it with Mask, ORs the result +; with Value, then writes the result back to Address. +; +; Input: +; IN UINT32 *Address +; Address which shall be read from and subsequently written to. +; +; IN UINT32 Value +; Value to be ORed with the value stored at Address after it has been ANDed +; with the provided Mask. +; +; IN UINT32 Mask +; Mask to be ANDed with the original value stored at Address. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +MemReadWrite32 proc + mov eax, [rcx] + and eax, r8D ;Mask + or eax, edx ;Value + mov [rcx], eax + ret +MemReadWrite32 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/MemSet.asm b/Core/CPU/x64/x64AsmLib/MemSet.asm new file mode 100644 index 0000000..246b985 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/MemSet.asm @@ -0,0 +1,127 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/MemSet.asm 1 10/01/10 5:08p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:08p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/MemSet.asm $ +; +; 1 10/01/10 5:08p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: MemSet +; +; Description: +; VOID MemSet(IN VOID *pBuffer, IN UINTN Count, IN UINT8 Value) fills Count +; bytes of memory in pBuffer with Value. +; +; Input: +; IN VOID *pBuffer +; The starting location in memory where to begin filling. +; +; IN UINTN Count +; The number of bytes to fill with Value. +; +; IN UINT8 Value +; The value to fill memory with starting at pBuffer. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +MemSet proc + push rdi + push rbx + mov rdi, rcx ; rdi = pBuffer + mov rcx, rdx ; rcx = Count + mov rax, r8 ; al = Value + ; fill EAX with the Value so that we can perform DWORD operatins + mov ah, al + mov bx,ax + shl rax,16 + mov ax,bx + ; if Counter is less then 4, jump to byte copy + cmp rcx, 4 + jb CopyByte + ; check if the Buffer is 4-bytes aligned + mov rdx,rdi + and rdx, 3 + ; if the Buffer is 4-bytes aligned, jump to DWORD copy + jz CopyDword + ; Buffer is not 4-bytes aligned + ; Calculate 4-(Buffer%4), which is a number of bytes we have to copy before + ; Buffer will reach 4-bytes boundary, and perform byte copy + neg rdx + add rdx, 4 + xchg rcx, rdx + sub rdx, rcx + rep stosb + mov rcx, rdx +CopyDword: + ; perform DWORD copy + mov rdx, rcx + shr rcx, 2 + rep stosd + ; copy the remainder + and rdx,3 + mov rcx, rdx +CopyByte: + rep stosb + ;;; + pop rbx + pop rdi + ret +MemSet endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/ReadCr3.asm b/Core/CPU/x64/x64AsmLib/ReadCr3.asm new file mode 100644 index 0000000..ad90c20 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/ReadCr3.asm @@ -0,0 +1,79 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/ReadCr3.asm 1 10/01/10 5:08p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:08p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/ReadCr3.asm $ +; +; 1 10/01/10 5:08p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: ReadCr3 +; +; Description: +; UINTN ReadCr3() reads the register CR3 and returns its value. +; +; Input: +; +; Output: +; UINTN value stored in the CR3 register. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +ReadCr3 PROC PUBLIC + mov rax, cr3 + ret +ReadCr3 ENDP + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/ReadMsr.asm b/Core/CPU/x64/x64AsmLib/ReadMsr.asm new file mode 100644 index 0000000..3fbeff6 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/ReadMsr.asm @@ -0,0 +1,85 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/ReadMsr.asm 1 10/01/10 5:08p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:08p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/ReadMsr.asm $ +; +; 1 10/01/10 5:08p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: ReadMsr +; +; Description: +; UINT64 ReadMsr(UINT32 Msr) reads the CPU MSR index defined by Msr and +; returns the value. +; +; Input: +; IN UINT32 Msr +; 32-bit MSR index to be read. +; +; Output: +; UINT64 MSR value at MSR index, Msr. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +ReadMsr Proc ;(UINT32 Msr) + rdmsr ;rcx = MSR + and rax, 0ffffffffh + shl rdx, 32 + or rax, rdx ;rax = (rdx << 32) | eax + ret +ReadMsr endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/ReadRtdsc.asm b/Core/CPU/x64/x64AsmLib/ReadRtdsc.asm new file mode 100644 index 0000000..078964c --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/ReadRtdsc.asm @@ -0,0 +1,82 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/ReadRtdsc.asm 1 10/01/10 5:08p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:08p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/ReadRtdsc.asm $ +; +; 1 10/01/10 5:08p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: ReadRtdsc +; +; Description: +; UINT64 ReadRtdsc() retrieves the time stamp counter. +; +; Input: +; VOID. +; +; Output: +; UINT64 value of the time stamp counter. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +ReadRtdsc Proc + rdtsc + shl rdx,32 + or rax, rdx + ret +ReadRtdsc endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/WaitForSemaphore.asm b/Core/CPU/x64/x64AsmLib/WaitForSemaphore.asm new file mode 100644 index 0000000..a5efa82 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/WaitForSemaphore.asm @@ -0,0 +1,88 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/WaitForSemaphore.asm 1 10/01/10 5:08p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:08p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/WaitForSemaphore.asm $ +; +; 1 10/01/10 5:08p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: WaitForSemaphore +; +; Description: +; VOID WaitForSemaphore(IN volatile UINT8 *Semaphore) waits for the +; semaphore to become available; once available, it claims the semaphore and +; returns. +; +; Input: +; IN volatile UINT8 *Semaphore +; Pointer to the desired semaphore. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +WaitForSemaphore Proc + mov al, 1 +@@: + xchg al, [rcx] + or al, al + pause + jnz @b + ret +WaitForSemaphore endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/WaitForever.asm b/Core/CPU/x64/x64AsmLib/WaitForever.asm new file mode 100644 index 0000000..c010643 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/WaitForever.asm @@ -0,0 +1,82 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/WaitForever.asm 1 10/01/10 5:08p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:08p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/WaitForever.asm $ +; +; 1 10/01/10 5:08p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: WaitForever +; +; Description: +; VOID WaitForever() performs an infinite loop which does nothing. +; +; Input: +; VOID. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +WaitForever Proc +@@: + Pause + jmp @b + ret +WaitForever endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/WaitUntilZero32.asm b/Core/CPU/x64/x64AsmLib/WaitUntilZero32.asm new file mode 100644 index 0000000..cdda323 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/WaitUntilZero32.asm @@ -0,0 +1,86 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/WaitUntilZero32.asm 1 10/01/10 5:08p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:08p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/WaitUntilZero32.asm $ +; +; 1 10/01/10 5:08p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: WaitUntilZero32 +; +; Description: +; VOID WaitUntilZero32(IN volatile UINT32 *Value) waits until the UINT32 +; value stored at the Value address becomes 0, then continues. +; +; Input: +; IN volatile UINT32 *Value +; Address of the UINT32 value to be monitored. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +WaitUntilZero32 Proc +@@: + mov eax, [rcx] + or eax, eax + pause + jnz @b + ret +WaitUntilZero32 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/WaitUntilZero8.asm b/Core/CPU/x64/x64AsmLib/WaitUntilZero8.asm new file mode 100644 index 0000000..b2c5f4d --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/WaitUntilZero8.asm @@ -0,0 +1,86 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/WaitUntilZero8.asm 1 10/01/10 5:08p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:08p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/WaitUntilZero8.asm $ +; +; 1 10/01/10 5:08p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: WaitUntilZero8 +; +; Description: +; VOID WaitUntilZero8(IN volatile UINT8 *Value) waits until the byte stored +; at Value becomes 0, then continues. +; +; Input: +; IN volatile UINT8 *Value +; Address of the byte value to be monitored. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +WaitUntilZero8 Proc +@@: + mov al, [rcx] + or al, al + pause + jnz @b + ret +WaitUntilZero8 endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/WriteCr3.asm b/Core/CPU/x64/x64AsmLib/WriteCr3.asm new file mode 100644 index 0000000..d028b07 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/WriteCr3.asm @@ -0,0 +1,81 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/WriteCr3.asm 1 10/01/10 5:08p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:08p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/WriteCr3.asm $ +; +; 1 10/01/10 5:08p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: WriteCr3 +; +; Description: +; VOID WriteCr3(IN UINTN CR3) writes the provided value to the CR3 register. +; +; Input: +; IN UINTN CR3 +; Value to be written to the CR3 register. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +WriteCr3 PROC PUBLIC + mov cr3, rcx + ret +WriteCr3 ENDP + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/WriteMsr.asm b/Core/CPU/x64/x64AsmLib/WriteMsr.asm new file mode 100644 index 0000000..b181a5b --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/WriteMsr.asm @@ -0,0 +1,89 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/WriteMsr.asm 1 10/01/10 5:08p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:08p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/WriteMsr.asm $ +; +; 1 10/01/10 5:08p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: WriteMsr +; +; Description: +; VOID WriteMsr(IN UINT32 Msr, IN UINT64 Value) writes the Value to the +; supplied MSR index, Msr. +; +; Input: +; IN UINT32 Msr +; 32-bit MSR index to be written to. +; +; IN UINT64 Value +; Value to be written to MSR index. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; +;<AMI_PHDR_END> +;************************************************************************* +WriteMsr proc + ;rcx = MSR + mov rax, rdx ;rax = rdx = Value + and rax, 0ffffffffh ;Lower 32 bit MSR Value + shr rdx, 32 ;Upper 32 bit MSR Value + wrmsr + ret +WriteMsr endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64AsmLib/checkpoint.asm b/Core/CPU/x64/x64AsmLib/checkpoint.asm new file mode 100644 index 0000000..38edb52 --- /dev/null +++ b/Core/CPU/x64/x64AsmLib/checkpoint.asm @@ -0,0 +1,84 @@ +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* +;************************************************************************* + +;************************************************************************* +; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/checkpoint.asm 1 10/01/10 5:07p Felixp $ +; +; $Revision: 1 $ +; +; $Date: 10/01/10 5:07p $ +;************************************************************************* +; Revision History +; ---------------- +; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/checkpoint.asm $ +; +; 1 10/01/10 5:07p Felixp +; +; 1 8/24/06 12:57p Felixp +; +;************************************************************************* +;<AMI_FHDR_START> +; +; Name: +; +; Description: +; +;<AMI_FHDR_END> +;************************************************************************* +.code + +;************************************************************************* +;<AMI_PHDR_START> +; +; Name: checkpoint +; +; Description: +; VOID checkpoint(IN UINT8 c) writes the value c to port 0x80. +; +; Input: +; IN UINT8 c +; The value/checkpoint to write to 0x80. +; +; Output: +; VOID. +; +; Modified: +; +; Referrals: +; +; Notes: +; This routine should only be used if the PROGRESS_CODE or +; PEI_PROGRESS_CODE macros are unavailable. +; +;<AMI_PHDR_END> +;************************************************************************* +checkpoint proc + mov al, cl + out 80h,al + ret +checkpoint endp + +END +;************************************************************************* +;************************************************************************* +;** ** +;** (C)Copyright 1985-2009, American Megatrends, Inc. ** +;** ** +;** All Rights Reserved. ** +;** ** +;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +;** ** +;** Phone: (770)-246-8600 ** +;** ** +;************************************************************************* diff --git a/Core/CPU/x64/x64CLib.c b/Core/CPU/x64/x64CLib.c new file mode 100644 index 0000000..ad96411 --- /dev/null +++ b/Core/CPU/x64/x64CLib.c @@ -0,0 +1,328 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2009, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* + +//************************************************************************* +// $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64CLib.c 4 7/10/09 9:30a Felixp $ +// +// $Revision: 4 $ +// +// $Date: 7/10/09 9:30a $ +//************************************************************************* +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64CLib.c $ +// +// 4 7/10/09 9:30a Felixp +// Function headers are added. +// +// 3 10/09/06 10:11a Felixp +// MemCpy/MemSet replaced with assembler routines +// +// 2 8/25/06 10:52a Felixp +// memcpy, memset functions updated with the volotile qualifier to +// restrain compiler optimization. +// +// 1 8/24/06 12:57p Felixp +// +//************************************************************************* +//<AMI_FHDR_START> +// +// Name: x64CLib.c +// +// Description: +// Generic CPU library functions for the x64 architecture. +// +//<AMI_FHDR_END> +//************************************************************************* + +#include <efi.h> + +//************************************************************************* +// Math +//************************************************************************* + +//************************************************************************* +//<AMI_GHDR_START> +// +// Name: Math_64_Bit_Functions +// +// Description: +// Math functions involving 64-bit input parameters designed to be usable on +// both 32-bit and 64-bit platforms. +// +// Fields: Header Function Description +// ------------------------------------------------------------------ +// AmiLib Shr64 Shift 64-bit value right. +// AmiLib Shl64 Shift 64-bit value left. +// AmiLib Div64 Divide 64-bit value by a 31-bit value. +// AmiLib Mul64 Multiply 64-bit value by a 32-bit value. +// AmiLib GetPowerOfTwo64 Determine the highest set bit in a 64-bit value. +// +// Notes: +// Header details which header file contains the function prototype for +// the above functions. Append .h to the given name. +// +//<AMI_GHDR_END> +//************************************************************************* + +//************************************************************************* +//<AMI_GHDR_START> +// +// Name: CPU_Functions +// +// Description: +// CPU related functions defined in the AMI library. +// +// Fields: Header Function Description +// ------------------------------------------------------------------ +// None CPULib_CpuID Perform the cpuid assembly instruction. +// None CPULib_DisableInterrupt Disable interrupts. +// None CPULib_EnableInterrupt Enable interrupts. +// None CPULib_GetInterruptState Get current interrupt state (enabled or disabled). +// None CPULIB_GetPageTable Retrieve address of the page table. +// None CPULib_LoadGdt Load GDT. +// None CPULib_LoadIdt Load IDT. +// None CPULib_LockByteDec Lock preceeding byte. +// None CPULib_LockByteInc Lock following byte. +// None CPULib_Pause Pause CPU. +// None CPULib_SaveGdt Save GDT at provided location. +// None CPULib_SaveIdt Save IDT at provided location. +// None DisableCacheInCR0 Disable CPU cache using CR0. +// None EnableCacheInCR0 Enable CPU cache using CR0. +// None EnableMachineCheck Enable machine check exception bit in CR4. +// AmiLib GetCpuTimer Retrieve the CPU timer's value. +// None GetCsSegment Retrieve the code segment. +// None HltCpu Halt the CPU. +// None WaitForever Perform infinite loop. +// None WaitForSemaphore Wait for semaphore to become available. then take control. +// None WaitUntilZero32 Wait until a 32-bit memory region becomes zero. +// None WaitUntilZero8 Wait until an 8-bit meomry region becomes zero. +// None WriteMsr Write a value to a MSR. +// None ReadMsr Read value from a MSR. +// AmiLib WriteCr3 Write a value to CR3. +// AmiLib ReadCr3 Read value from CR3. +// None ReadRtdsc Retrieve the time stamp counter. +// +// Notes: +// Header details which header file contains the function prototype for +// the above functions. Append .h to the given name. +// +//<AMI_GHDR_END> +//************************************************************************* + + +//************************************************************************* +//<AMI_PHDR_START> +// +// Name: Shr64 +// +// Description: +// UINT64 Shr64(IN UINT64 Value, IN UINT8 Shift) shifts the 64-bit Value +// right the provided number of bits, Shift. +// +// Input: +// IN UINT64 Value +// The value to be shifted. +// +// IN UINT8 Shift +// The number of bits to shift right. +// +// Output: +// UINT64 Value shifted right Shift number of bits. +// +// Modified: +// +// Referrals: +// +// Notes: +// +//<AMI_PHDR_END> +//************************************************************************* +UINT64 Shr64( + IN UINT64 Value, + IN UINT8 Shift + ) +{ + return Value>>Shift; +} + +//************************************************************************* +//<AMI_PHDR_START> +// +// Name: Shl64 +// +// Description: +// UINT64 Shl64(IN UINT64 Value, IN UINT8 Shift) shifts the 64-bit Value +// left the provided number of bits, Shift. +// +// Input: +// IN UINT64 Value +// The value to be shifted left. +// +// IN UINT8 Shift +// The number of bits to shift. +// +// Output: +// UINT64 Value shifted left Shift number of bits. +// +// Modified: +// +// Referrals: +// +// Notes: +// +//<AMI_PHDR_END> +//************************************************************************* +UINT64 Shl64( + IN UINT64 Value, + IN UINT8 Shift + ) +{ + return Value<<Shift; +} + +//************************************************************************* +//<AMI_PHDR_START> +// +// Name: Div64 +// +// Description: +// UINT64 Div64(IN UINT64 Dividend, IN UINTN Divisor, +// OUT UINTN *Remainder OPTIONAL) divides a 64-bit number, Dividend, by the +// Divisor, which can be up to 31-bits. +// +// Input: +// IN UINT64 Dividend +// The 64-bit number to be divided. +// +// IN UINT Divisor +// The number to divide Dividend by; may not exceed 31-bits in size. +// +// OUT UINTN *Remainder OPTIONAL +// The remainder of the division. Provide NULL if undesired; otherwise user +// is responsible for handling the necessary memory resources. +// +// Output: +// UINT64 result of dividing Dividend by Divisor. +// +// Modified: +// +// Referrals: +// +// Notes: +// +//<AMI_PHDR_END> +//************************************************************************* +UINT64 Div64 ( + IN UINT64 Dividend, + IN UINTN Divisor, //Can only be 31 bits. + OUT UINTN *Remainder OPTIONAL + ) +{ + UINT64 Result = Dividend/Divisor; + if (Remainder) *Remainder=Dividend%Divisor; + return Result; +} + +//************************************************************************* +//<AMI_PHDR_START> +// +// Name: Mul64 +// +// Description: +// UINT64 Mul64(IN UINT64 Value64, IN UINTN Value32) multiplies a 64-bit +// number by a 32-bit number and returns the 64-bit result. +// +// Input: +// IN UINTN64 Value64 +// The 64-bit number to multiply by. +// +// IN UINTN Value32 +// The 32-bit number to multiply by. +// +// Output: +// UINT64 result of multiplying Value64 by Value32. +// +// Modified: +// +// Referrals: +// +// Notes: +// +//<AMI_PHDR_END> +//************************************************************************* +UINT64 Mul64( + IN UINT64 Value64, + IN UINTN Value32 + ) +{ + return Value64*Value32; +} + +//************************************************************************* +// Memory Operations +//************************************************************************* + +VOID MemSet(VOID* pBuffer, UINTN Count, UINT8 Value); + +//************************************************************************* +//<AMI_PHDR_START> +// +// Name: memset +// +// Description: +// VOID memset(IN VOID *pBuffer, IN UINT8 Value, IN UINTN Count) is a +// wrapper for MemSet which fills Count bytes of memory in pBuffer with +// Value. +// +// Input: +// IN VOID *pBuffer +// The starting location in memory where to begin filling. +// +// IN UINT8 Value +// The value to fill memory with starting at pBuffer. +// +// IN UINTN Count +// The number of bytes to fill with Value. +// +// Output: +// VOID. +// +// Modified: +// +// Referrals: +// MemSet +// +// Notes: +// +//<AMI_PHDR_END> +//************************************************************************* +VOID memset(VOID* pBuffer, UINTN Value, UINTN Count) +{ + MemSet(pBuffer,Count,(UINT8)Value); +} + +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2009, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* diff --git a/Core/CPU/x64/x64Core.cif b/Core/CPU/x64/x64Core.cif new file mode 100644 index 0000000..0d92f09 --- /dev/null +++ b/Core/CPU/x64/x64Core.cif @@ -0,0 +1,9 @@ +<component> + name = "x64 Core" + category = ModulePart + LocalRoot = "Core\CPU\x64\" + RefName = "x64Core" +[files] +"x64Core.sdl" +"x64rules.mak" +<endComponent> diff --git a/Core/CPU/x64/x64Core.sdl b/Core/CPU/x64/x64Core.sdl new file mode 100644 index 0000000..389aa0f --- /dev/null +++ b/Core/CPU/x64/x64Core.sdl @@ -0,0 +1,112 @@ +TOKEN + Name = "x64_BUILD" + Value = "0" + Help = "Main switch to enable x64 support in Project\DO REBUILD ALL AFTER CHANGING THIS SWITCH!!!" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +TOKEN + Name = "GLOBAL_DEFINES_x64" + Value = "/DEFIx64 /DEFIX64" + Help = "Global x64-specific macro definitions. Added to CFLAGSx64 and AFLAGSx64" + TokenType = Expression + TargetMAK = Yes +End + +TOKEN + Name = "CC" + Value = "$(SILENT)$(CCX64DIR)\CL" + TokenType = Expression + TargetMAK = Yes +End + +TOKEN + Name = "LINK" + Value = "$(SILENT)$(CCX64DIR)\LINK" + TokenType = Expression + TargetMAK = Yes +End + +TOKEN + Name = "LIBEXE" + Value = "$(SILENT)$(CCX64DIR)\LINK /LIB" + TokenType = Expression + TargetMAK = Yes +End + +TOKEN + Name = "CCPEI" + Value = "$(SILENT)$(CCX86DIR)\CL" + TokenType = Expression + TargetMAK = Yes +End + +TOKEN + Name = "LINKPEI" + Value = "$(SILENT)$(CCX86DIR)\LINK" + TokenType = Expression + TargetMAK = Yes +End + +TOKEN + Name = "LIBEXEPEI" + Value = "$(SILENT)$(CCX86DIR)\LINK /LIB" + TokenType = Expression + TargetMAK = Yes +End + +TOKEN + Name = "CFLAGSx64" + Value = "/GS- $(GLOBAL_DEFINES_x64)" + TokenType = Expression + TargetMAK = Yes +End + +TOKEN + Name = "ASMx64" + Value = "$(SILENT)$(CCX64DIR)\ML64" + TokenType = Expression + TargetMAK = Yes +End + +TOKEN + Name = "AFLAGSx64" + Value = "$(GLOBAL_DEFINES_x64) /Cp" + TokenType = Expression + TargetMAK = Yes +End + +TOKEN + Name = "LFLAGSx64" + Value = "/MACHINE:AMD64" + TokenType = Expression + TargetMAK = Yes +End + +TOKEN + Name = "CP" + Value = "$(SILENT)$(CCX64DIR)\CL /nologo /EP" + Help = "C preprocessor" + TokenType = Expression + TargetMAK = Yes +End + +PATH + Name = "x64Core_DIR" +End + +ELINK + Name = "x64" + Parent = "IA32" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "$(x64Core_DIR)\x64rules.mak" + Parent = "$(IA32Core_DIR)\IA32rules.mak" + InvokeOrder = ReplaceParent +End + diff --git a/Core/CPU/x64/x64rules.mak b/Core/CPU/x64/x64rules.mak new file mode 100644 index 0000000..ed1ab3c --- /dev/null +++ b/Core/CPU/x64/x64rules.mak @@ -0,0 +1,86 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2006, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 6145-F Northbelt Pkwy, Norcross, GA 30071 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/BIN/Core/Modules/x64Core/x64rules.mak 3 8/02/07 1:33a Felixp $ +# +# $Revision: 3 $ +# +# $Date: 8/02/07 1:33a $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/BIN/Core/Modules/x64Core/x64rules.mak $ +# +# 3 8/02/07 1:33a Felixp +# minor modification to use newly defined COMPONENT_BUILD_RULES macro +# defined in rules.mak +# +# 2 3/13/07 11:53a Felixp +# Global and CPU architecture specific macros are now passed +# to C preprocessor (used during DepEx and VFR compilation) +# +# 1 10/13/06 8:31p Felixp +# +# 3 9/05/06 6:03p Felixp +# define PROCESSOR is IA32 when building PEI components in x64 build. +# +# 2 8/25/06 11:12a Felixp +# +# 1 8/24/06 12:57p Felixp +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: x64rules.mak +# +# Description: Defines x64-specific build rules. +# This file is included into the template makefile rules.mak +# +#<AMI_FHDR_END> +#********************************************************************** +!IF "$(COMPONENT_BUILD_RULES)"=="PEI" +# IA32 Build +CC = $(CCPEI) +LINK = $(LINKPEI) +LIBEXE=$(LIBEXEPEI) + +LIB_BUILD_DIR=$(BUILD_ROOT)\IA32 +!UNDEF PROCESSOR +PROCESSOR=IA32 +!INCLUDE $(IA32Core_DIR)\IA32rules.mak + +!ELSE +# x64 Build +ASM=$(ASMx64) + +EXTRA_CFLAGS=$(EXTRA_CFLAGS) $(CFLAGSx64) +EXTRA_LFLAGS=$(EXTRA_LFLAGS) $(LFLAGSx64) +EXTRA_AFLAGS=$(EXTRA_AFLAGS) $(AFLAGSx64) +EXTRA_AFLAGS16=$(EXTRA_AFLAGS16) $(GLOBAL_DEFINES_x64) +CPFLAGS=$(CPFLAGS) $(GLOBAL_DEFINES_x64) +!ENDIF +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2006, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 6145-F Northbelt Pkwy, Norcross, GA 30071 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#**********************************************************************
\ No newline at end of file |