<div>Reviewed-by: Chao Li  <lichao@loongson.cn></div><br><div><signature id="local-a67dfd9c-c219"><p style="color:grey;font-size:11px"><br>Thanks,<br>Chao<br>--------<br><br></p></signature></div><div class="gmail_quote_attribution">On 11月 11 2022, at 5:12 δΈ‹εˆ, xianglai li <lixianglai@loongson.cn> wrote:</div><blockquote><div><div>Add SEC Code And Readme.md for LoongArchQemu</div><br><br><br><div>REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4054</div><br><br><br><div>Cc: Bibo Mao <maobibo@loongson.cn></div><br><div>Cc: Chao Li <lichao@loongson.cn></div><br><div>Cc: Leif Lindholm <quic_llindhol@quicinc.com></div><br><div>Cc: Liming Gao <gaoliming@byosoft.com.cn></div><br><div>Cc: Michael D Kinney <michael.d.kinney@intel.com></div><br><div>Signed-off-by: xianglai li <lixianglai@loongson.cn></div><br><div>Signed-off-by: xianglai li <lixianglai@loongson.cn></div><br><div>---</div><br><div>.../Include/LoongArchQemuPlatform.h | 2 +-</div><br><div>.../Loongson/LoongArchQemuPkg/Loongson.dec | 38 ++</div><br><div>.../Loongson/LoongArchQemuPkg/Loongson.dsc | 122 +++++</div><br><div>.../Loongson/LoongArchQemuPkg/Loongson.fdf | 53 ++</div><br><div>.../LoongArchQemuPkg/Loongson.fdf.inc | 21 +</div><br><div>.../LoongArchQemuPkg/Sec/LoongArch64/Start.S | 84 +++</div><br><div>.../Loongson/LoongArchQemuPkg/Sec/SecMain.c | 494 ++++++++++++++++++</div><br><div>.../Loongson/LoongArchQemuPkg/Sec/SecMain.inf | 51 ++</div><br><div>8 files changed, 864 insertions(+), 1 deletion(-)</div><br><div>create mode 100644 Platform/Loongson/LoongArchQemuPkg/Loongson.dec</div><br><div>create mode 100644 Platform/Loongson/LoongArchQemuPkg/Loongson.dsc</div><br><div>create mode 100644 Platform/Loongson/LoongArchQemuPkg/Loongson.fdf</div><br><div>create mode 100644 Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc</div><br><div>create mode 100644 Platform/Loongson/LoongArchQemuPkg/Sec/LoongArch64/Start.S</div><br><div>create mode 100644 Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.c</div><br><div>create mode 100644 Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf</div><br><br><br><div>diff --git a/Platform/Loongson/LoongArchQemuPkg/Include/LoongArchQemuPlatform.h b/Platform/Loongson/LoongArchQemuPkg/Include/LoongArchQemuPlatform.h</div><br><div>index e942e6a994..d003b9013d 100644</div><br><div>--- a/Platform/Loongson/LoongArchQemuPkg/Include/LoongArchQemuPlatform.h</div><br><div>+++ b/Platform/Loongson/LoongArchQemuPkg/Include/LoongArchQemuPlatform.h</div><br><div>@@ -92,4 +92,4 @@</div><br><div>#define UART_BASE_ADDRESS (0x1fe001e0)</div><br><div>#define UART_BPS (115200)</div><br><div>#define UART_WAIT_TIMOUT (1000000)</div><br><div>-#endif</div><br><div>+#endif // LOONGARCH_QEMU_PLATFORM_H_</div><br><div>diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec</div><br><div>new file mode 100644</div><br><div>index 0000000000..61f600b20d</div><br><div>--- /dev/null</div><br><div>+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec</div><br><div>@@ -0,0 +1,38 @@</div><br><div>+## @file</div><br><div>+#</div><br><div>+# Copyright (c) 2022 Loongson Technology Corporation Limited. All rights reserved.<BR></div><br><div>+#</div><br><div>+# SPDX-License-Identifier: BSD-2-Clause-Patent</div><br><div>+#</div><br><div>+##</div><br><div>+</div><br><div>+[Defines]</div><br><div>+ DEC_SPECIFICATION = 0x00010005</div><br><div>+ PACKAGE_NAME = LoongArchQemuPkg</div><br><div>+ PACKAGE_GUID = b51d765a-41da-45fc-a537-de3ee785c0f6</div><br><div>+ PACKAGE_VERSION = 0.1</div><br><div>+</div><br><div>+################################################################################</div><br><div>+#</div><br><div>+# Include Section - list of Include Paths that are provided by this package.</div><br><div>+# Comments are used for Keywords and Module Types.</div><br><div>+#</div><br><div>+# Supported Module Types:</div><br><div>+# BASE SEC PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER</div><br><div>+# DXE_SAL_DRIVER UEFI_DRIVER UEFI_APPLICATION</div><br><div>+#</div><br><div>+################################################################################</div><br><div>+[Includes.common]</div><br><div>+ Include # Root include for the package</div><br><div>+</div><br><div>+[Guids]</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid = { 0x0e0383ce, 0x0151, 0x4d01, { 0x80, 0x0e, 0x3f, 0xef, 0x8b, 0x27, 0x6d, 0x52 } }</div><br><div>+</div><br><div>+## In the PcdsFixedAtBuild and PcdsDynamic areas, numbers start at 0x0.</div><br><div>+[PcdsFixedAtBuild, PcdsDynamic]</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdFlashPeiFvBase|0x0|UINT64|0x00000000</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdFlashPeiFvSize|0x0|UINT32|0x00000001</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase|0|UINT64|0x0000000b</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize|0|UINT32|0x0000000c</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvBase|0x0|UINT64|0x0000000f</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvSize|0x0|UINT32|0x00000010</div><br><div>diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc</div><br><div>new file mode 100644</div><br><div>index 0000000000..b506f70625</div><br><div>--- /dev/null</div><br><div>+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc</div><br><div>@@ -0,0 +1,122 @@</div><br><div>+## @file</div><br><div>+#</div><br><div>+# Copyright (c) 2022 Loongson Technology Corporation Limited. All rights reserved.<BR></div><br><div>+#</div><br><div>+# SPDX-License-Identifier: BSD-2-Clause-Patent</div><br><div>+#</div><br><div>+##</div><br><div>+</div><br><div>+################################################################################</div><br><div>+#</div><br><div>+# Defines Section - statements that will be processed to create a Makefile.</div><br><div>+#</div><br><div>+###############################################################################</div><br><div>+[Defines]</div><br><div>+ PLATFORM_NAME = LoongArchQemu</div><br><div>+ PLATFORMPKG_NAME = LoongArchQemu</div><br><div>+ PLATFORM_GUID = 7926ea52-b0dc-4ee8-ac63-341eebd84ed4</div><br><div>+ PLATFORM_VERSION = 0.1</div><br><div>+ DSC_SPECIFICATION = 0x00010005</div><br><div>+ OUTPUT_DIRECTORY = Build/$(PLATFORM_NAME)</div><br><div>+ SUPPORTED_ARCHITECTURES = LOONGARCH64</div><br><div>+ BUILD_TARGETS = DEBUG|RELEASE</div><br><div>+ SKUID_IDENTIFIER = DEFAULT</div><br><div>+ FLASH_DEFINITION = Platform/Loongson/LoongArchQemuPkg/Loongson.fdf</div><br><div>+ TTY_TERMINAL = FALSE</div><br><div>+</div><br><div>+############################################################################</div><br><div>+#</div><br><div>+# Defines for default states. These can be changed on the command line.</div><br><div>+# -D FLAG=VALUE</div><br><div>+############################################################################</div><br><div>+[BuildOptions]</div><br><div>+ GCC:RELEASE_*_*_CC_FLAGS = -DSPEEDUP</div><br><div>+</div><br><div>+ #</div><br><div>+ # Disable deprecated APIs.</div><br><div>+ #</div><br><div>+ GCC:*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES</div><br><div>+</div><br><div>+[BuildOptions.LOONGARCH64.EDKII.SEC]</div><br><div>+ *_*_*_CC_FLAGS =</div><br><div>+</div><br><div>+[BuildOptions.common.EDKII.DXE_CORE,BuildOptions.common.EDKII.DXE_DRIVER,BuildOptions.common.EDKII.UEFI_DRIVER,BuildOptions.common.EDKII.UEFI_APPLICATION]</div><br><div>+ GCC:*_*_*_DLINK_FLAGS = -z common-page-size=0x1000</div><br><div>+</div><br><div>+[BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER]</div><br><div>+ GCC:*_*_LOONGARCH64_DLINK_FLAGS = -z common-page-size=0x10000</div><br><div>+</div><br><div>+################################################################################</div><br><div>+#</div><br><div>+# Library Class section - list of all Library Classes needed by this Platform.</div><br><div>+#</div><br><div>+################################################################################</div><br><div>+</div><br><div>+!include MdePkg/MdeLibs.dsc.inc</div><br><div>+</div><br><div>+[LibraryClasses.common]</div><br><div>+ PcdLib | MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf</div><br><div>+ PrintLib | MdePkg/Library/BasePrintLib/BasePrintLib.inf</div><br><div>+ BaseMemoryLib | MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf</div><br><div>+ BaseLib | MdePkg/Library/BaseLib/BaseLib.inf</div><br><div>+ PeCoffLib | MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf</div><br><div>+ PeCoffGetEntryPointLib | MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf</div><br><div>+ IoLib | MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf</div><br><div>+ SerialPortLib | Platform/Loongson/LoongArchQemuPkg/Library/SerialPortLib/SerialPortLib.inf</div><br><div>+ DebugPrintErrorLevelLib | MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf</div><br><div>+ PeCoffExtraActionLib | MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf</div><br><div>+ DebugAgentLib | MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf</div><br><div>+</div><br><div>+################################################################################</div><br><div>+#</div><br><div>+# Pcd Section - list of all EDK II PCD Entries defined by this Platform.</div><br><div>+#</div><br><div>+################################################################################</div><br><div>+[PcdsFixedAtBuild]</div><br><div>+## BaseLib ##</div><br><div>+ gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength | 1000000</div><br><div>+ gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength | 1000000</div><br><div>+ gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength | 1000000</div><br><div>+</div><br><div>+ gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel | 0x8000004F</div><br><div>+ # DEBUG_INIT 0x00000001 // Initialization</div><br><div>+ # DEBUG_WARN 0x00000002 // Warnings</div><br><div>+ # DEBUG_LOAD 0x00000004 // Load events</div><br><div>+ # DEBUG_FS 0x00000008 // EFI File system</div><br><div>+ # DEBUG_POOL 0x00000010 // Alloc & Free (pool)</div><br><div>+ # DEBUG_PAGE 0x00000020 // Alloc & Free (page)</div><br><div>+ # DEBUG_INFO 0x00000040 // Informational debug messages</div><br><div>+ # DEBUG_DISPATCH 0x00000080 // PEI/DXE/SMM Dispatchers</div><br><div>+ # DEBUG_VARIABLE 0x00000100 // Variable</div><br><div>+ # DEBUG_BM 0x00000400 // Boot Manager</div><br><div>+ # DEBUG_BLKIO 0x00001000 // BlkIo Driver</div><br><div>+ # DEBUG_NET 0x00004000 // Network Io Driver</div><br><div>+ # DEBUG_UNDI 0x00010000 // UNDI Driver</div><br><div>+ # DEBUG_LOADFILE 0x00020000 // LoadFile</div><br><div>+ # DEBUG_EVENT 0x00080000 // Event messages</div><br><div>+ # DEBUG_GCD 0x00100000 // Global Coherency Database changes</div><br><div>+ # DEBUG_CACHE 0x00200000 // Memory range cachability changes</div><br><div>+ # DEBUG_VERBOSE 0x00400000 // Detailed debug messages that may</div><br><div>+ # DEBUG_ERROR 0x80000000 // Error</div><br><div>+</div><br><div>+!if $(TARGET) == RELEASE</div><br><div>+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask | 0x21</div><br><div>+!else</div><br><div>+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask | 0x2f</div><br><div>+!endif</div><br><div>+ # DEBUG_ASSERT_ENABLED 0x01</div><br><div>+ # DEBUG_PRINT_ENABLED 0x02</div><br><div>+ # DEBUG_CODE_ENABLED 0x04</div><br><div>+ # CLEAR_MEMORY_ENABLED 0x08</div><br><div>+ # ASSERT_BREAKPOINT_ENABLED 0x10</div><br><div>+ # ASSERT_DEADLOOP_ENABLED 0x20</div><br><div>+</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase | 0x10000</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize | 0x10000</div><br><div>+</div><br><div>+[Components]</div><br><div>+</div><br><div>+ #</div><br><div>+ # SEC Phase modules</div><br><div>+ #</div><br><div>+ Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf</div><br><div>diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf</div><br><div>new file mode 100644</div><br><div>index 0000000000..9685795cda</div><br><div>--- /dev/null</div><br><div>+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf</div><br><div>@@ -0,0 +1,53 @@</div><br><div>+## @file</div><br><div>+#</div><br><div>+# Copyright (c) 2022 Loongson Technology Corporation Limited. All rights reserved.<BR></div><br><div>+#</div><br><div>+# SPDX-License-Identifier: BSD-2-Clause-Patent</div><br><div>+#</div><br><div>+##</div><br><div>+</div><br><div>+#####################################################################################################</div><br><div>+[Defines]</div><br><div>+!include Loongson.fdf.inc</div><br><div>+</div><br><div>+#####################################################################################################</div><br><div>+[FD.QEMU_EFI]</div><br><div>+BaseAddress = $(FD_BASE_ADDRESS)</div><br><div>+Size = $(FD_SIZE)</div><br><div>+ErasePolarity = 1</div><br><div>+BlockSize = $(BLOCK_SIZE)</div><br><div>+NumBlocks = $(FD_BLOCKS)</div><br><div>+</div><br><div>+$(SECFV_OFFSET)|$(SECFV_SIZE)</div><br><div>+gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvBase|gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvSize</div><br><div>+FV = SECFV</div><br><div>+</div><br><div>+#####################################################################################################</div><br><div>+[FV.SECFV]</div><br><div>+FvNameGuid = 587d4265-5e71-41da-9c35-4258551f1e22</div><br><div>+BlockSize = $(BLOCK_SIZE)</div><br><div>+FvAlignment = 16</div><br><div>+ERASE_POLARITY = 1</div><br><div>+MEMORY_MAPPED = TRUE</div><br><div>+STICKY_WRITE = TRUE</div><br><div>+LOCK_CAP = TRUE</div><br><div>+LOCK_STATUS = TRUE</div><br><div>+WRITE_DISABLED_CAP = TRUE</div><br><div>+WRITE_ENABLED_CAP = TRUE</div><br><div>+WRITE_STATUS = TRUE</div><br><div>+WRITE_LOCK_CAP = TRUE</div><br><div>+WRITE_LOCK_STATUS = TRUE</div><br><div>+READ_DISABLED_CAP = TRUE</div><br><div>+READ_ENABLED_CAP = TRUE</div><br><div>+READ_STATUS = TRUE</div><br><div>+READ_LOCK_CAP = TRUE</div><br><div>+READ_LOCK_STATUS = TRUE</div><br><div>+</div><br><div>+INF Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf</div><br><div>+</div><br><div>+#####################################################################################################</div><br><div>+[Rule.Common.SEC]</div><br><div>+ FILE SEC = $(NAMED_GUID) {</div><br><div>+ TE TE Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi</div><br><div>+ UI STRING ="$(MODULE_NAME)" Optional</div><br><div>+ }</div><br><div>diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc</div><br><div>new file mode 100644</div><br><div>index 0000000000..6f17909748</div><br><div>--- /dev/null</div><br><div>+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc</div><br><div>@@ -0,0 +1,21 @@</div><br><div>+## @file</div><br><div>+#</div><br><div>+# Copyright (c) 2022 Loongson Technology Corporation Limited. All rights reserved.<BR></div><br><div>+#</div><br><div>+# SPDX-License-Identifier: BSD-2-Clause-Patent</div><br><div>+#</div><br><div>+##</div><br><div>+</div><br><div>+DEFINE BLOCK_SIZE = 0x1000</div><br><div>+</div><br><div>+############################################################################</div><br><div>+# fd total</div><br><div>+DEFINE FD_BASE_ADDRESS = 0x1c000000</div><br><div>+DEFINE FD_BLOCKS = 0x400</div><br><div>+DEFINE FD_SIZE = 0x400000</div><br><div>+</div><br><div>+############################################################################</div><br><div>+#flash code layout</div><br><div>+#Set Sec base address and size in flash</div><br><div>+DEFINE SECFV_OFFSET = 0x00000000</div><br><div>+DEFINE SECFV_SIZE = 0x00010000</div><br><div>diff --git a/Platform/Loongson/LoongArchQemuPkg/Sec/LoongArch64/Start.S b/Platform/Loongson/LoongArchQemuPkg/Sec/LoongArch64/Start.S</div><br><div>new file mode 100644</div><br><div>index 0000000000..5d7ce313c0</div><br><div>--- /dev/null</div><br><div>+++ b/Platform/Loongson/LoongArchQemuPkg/Sec/LoongArch64/Start.S</div><br><div>@@ -0,0 +1,84 @@</div><br><div>+#------------------------------------------------------------------------------</div><br><div>+#</div><br><div>+# Start for LoongArch</div><br><div>+#</div><br><div>+# Copyright (c) 2022 Loongson Technology Corporation Limited. All rights reserved.<BR></div><br><div>+#</div><br><div>+# SPDX-License-Identifier: BSD-2-Clause-Patent</div><br><div>+#</div><br><div>+# @par Glossary:</div><br><div>+# - CSR - CPU Status Register</div><br><div>+# - EBASE - Exception Base Address</div><br><div>+#------------------------------------------------------------------------------</div><br><div>+#ifndef __ASSEMBLY__</div><br><div>+#define __ASSEMBLY__</div><br><div>+#endif</div><br><div>+</div><br><div>+#include <Library/Cpu.h></div><br><div>+</div><br><div>+ASM_GLOBAL ASM_PFX(_ModuleEntryPoint)</div><br><div>+ASM_GLOBAL ASM_PFX(DeadLoop)</div><br><div>+</div><br><div>+.text</div><br><div>+ASM_PFX(_ModuleEntryPoint):</div><br><div>+ /* configure reset ebase */</div><br><div>+ la.pcrel T0, DeadLoop</div><br><div>+ csrwr T0, LOONGARCH_CSR_EBASE</div><br><div>+</div><br><div>+ /*disable interrupt*/</div><br><div>+ li.d T0, (1 << 2)</div><br><div>+ csrxchg ZERO, T0, LOONGARCH_CSR_CRMD</div><br><div>+</div><br><div>+ /* read physical cpu number id */</div><br><div>+ csrrd T0, LOONGARCH_CSR_CPUNUM</div><br><div>+ andi T0, T0, 0x3ff</div><br><div>+ li.d A0, BOOTCORE_ID //0</div><br><div>+ bne T0, A0, slave_main</div><br><div>+</div><br><div>+call_centry:</div><br><div>+ /*call C function make sure parameter true*/</div><br><div>+ li.d A1, FixedPcdGet64(PcdSecPeiTempRamBase) + FixedPcdGet32(PcdSecPeiTempRamSize) # stack base</div><br><div>+ li.d A0, FixedPcdGet64(PcdFlashPeiFvBase) # PEI Fv base</div><br><div>+ move SP, A1</div><br><div>+ addi.d SP, SP, -0x8</div><br><div>+ bl SecCoreStartupWithStack</div><br><div>+</div><br><div>+slave_main:</div><br><div>+ # clear mailbox</div><br><div>+ li.d T1, LOONGSON_CSR_MAIL_BUF0</div><br><div>+ iocsrwr.d ZERO, T1</div><br><div>+</div><br><div>+ # enable IPI interrupt</div><br><div>+ li.d T0, (1 << 12)</div><br><div>+ csrxchg T0, T0, LOONGARCH_CSR_ECFG</div><br><div>+</div><br><div>+ addi.d T0, ZERO, -1</div><br><div>+ li.d T1, LOONGSON_IOCSR_IPI_EN</div><br><div>+ iocsrwr.w T0, T1</div><br><div>+</div><br><div>+1:</div><br><div>+ # wait for wakeup</div><br><div>+ idle 0</div><br><div>+ nop</div><br><div>+ iocsrrd.w T0, T1</div><br><div>+ beqz T0, 1b</div><br><div>+</div><br><div>+ # read and clear ipi interrupt</div><br><div>+ li.d T1, LOONGSON_IOCSR_IPI_STATUS</div><br><div>+ iocsrrd.w T0, T1</div><br><div>+ li.d T1, LOONGSON_IOCSR_IPI_CLEAR</div><br><div>+ iocsrwr.w T0, T1</div><br><div>+</div><br><div>+ # disable IPI interrupt</div><br><div>+ li.d T0, (1 << 12)</div><br><div>+ csrxchg ZERO, T0, LOONGARCH_CSR_ECFG</div><br><div>+</div><br><div>+ # read mail buf and jump to specified entry</div><br><div>+ li.d T1, LOONGSON_CSR_MAIL_BUF0</div><br><div>+ iocsrrd.d T0, T1</div><br><div>+ or RA, T0, ZERO</div><br><div>+ jirl ZERO, RA, 0x0</div><br><div>+</div><br><div>+.align 12</div><br><div>+ASM_PFX(DeadLoop):</div><br><div>+ b DeadLoop</div><br><div>diff --git a/Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.c b/Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.c</div><br><div>new file mode 100644</div><br><div>index 0000000000..3f1998c48c</div><br><div>--- /dev/null</div><br><div>+++ b/Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.c</div><br><div>@@ -0,0 +1,494 @@</div><br><div>+/** @file</div><br><div>+ Main SEC phase code. Transitions to PEI.</div><br><div>+</div><br><div>+ Copyright (c) 2022 Loongson Technology Corporation Limited. All rights reserved.<BR></div><br><div>+</div><br><div>+ SPDX-License-Identifier: BSD-2-Clause-Patent</div><br><div>+</div><br><div>+**/</div><br><div>+</div><br><div>+#include <PiPei.h></div><br><div>+</div><br><div>+#include <Library/PeimEntryPoint.h></div><br><div>+#include <Library/BaseLib.h></div><br><div>+#include <Library/DebugLib.h></div><br><div>+#include <Library/BaseMemoryLib.h></div><br><div>+#include <Library/PeiServicesLib.h></div><br><div>+#include <Library/PcdLib.h></div><br><div>+#include <Library/DebugAgentLib.h></div><br><div>+#include <Library/IoLib.h></div><br><div>+#include <Library/PeCoffLib.h></div><br><div>+#include <Library/PeCoffGetEntryPointLib.h></div><br><div>+#include <Library/PeCoffExtraActionLib.h></div><br><div>+#include <Library/ExtractGuidedSectionLib.h></div><br><div>+</div><br><div>+#include <Ppi/TemporaryRamSupport.h></div><br><div>+</div><br><div>+/**</div><br><div>+ temporary memory to permanent memory and do stack switching.</div><br><div>+</div><br><div>+ @param[in] PeiServices Pointer to the PEI Services Table.</div><br><div>+ @param[in] TemporaryMemoryBase Temporary Memory Base address.</div><br><div>+ @param[in] PermanentMemoryBase Permanent Memory Base address.</div><br><div>+ @param[in] CopySize The size of memory that needs to be migrated.</div><br><div>+</div><br><div>+ @retval EFI_SUCCESS Migration successful.</div><br><div>+**/</div><br><div>+EFI_STATUS</div><br><div>+EFIAPI</div><br><div>+TemporaryRamMigration (</div><br><div>+ IN CONST EFI_PEI_SERVICES **PeiServices,</div><br><div>+ IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,</div><br><div>+ IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,</div><br><div>+ IN UINTN CopySize</div><br><div>+ );</div><br><div>+</div><br><div>+EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi = {</div><br><div>+ TemporaryRamMigration</div><br><div>+};</div><br><div>+</div><br><div>+EFI_PEI_PPI_DESCRIPTOR mPrivateDispatchTable[] = {</div><br><div>+ {</div><br><div>+ (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),</div><br><div>+ &gEfiTemporaryRamSupportPpiGuid,</div><br><div>+ &mTemporaryRamSupportPpi</div><br><div>+ },</div><br><div>+};</div><br><div>+</div><br><div>+/**</div><br><div>+ Locates a section within a series of sections</div><br><div>+ with the specified section type.</div><br><div>+</div><br><div>+ The Instance parameter indicates which instance of the section</div><br><div>+ type to return. (0 is first instance, 1 is second...)</div><br><div>+</div><br><div>+ @param[in] Sections The sections to search</div><br><div>+ @param[in] SizeOfSections Total size of all sections</div><br><div>+ @param[in] SectionType The section type to locate</div><br><div>+ @param[in] Instance The section instance number</div><br><div>+ @param[out] FoundSection The FFS section if found</div><br><div>+</div><br><div>+ @retval EFI_SUCCESS The file and section was found</div><br><div>+ @retval EFI_NOT_FOUND The file and section was not found</div><br><div>+ @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted</div><br><div>+**/</div><br><div>+EFI_STATUS</div><br><div>+FindFfsSectionInstance (</div><br><div>+ IN VOID *Sections,</div><br><div>+ IN UINTN SizeOfSections,</div><br><div>+ IN EFI_SECTION_TYPE SectionType,</div><br><div>+ IN UINTN Instance,</div><br><div>+ OUT EFI_COMMON_SECTION_HEADER **FoundSection</div><br><div>+ )</div><br><div>+{</div><br><div>+ EFI_PHYSICAL_ADDRESS CurrentAddress;</div><br><div>+ UINT32 Size;</div><br><div>+ EFI_PHYSICAL_ADDRESS EndOfSections;</div><br><div>+ EFI_COMMON_SECTION_HEADER *Section;</div><br><div>+ EFI_PHYSICAL_ADDRESS EndOfSection;</div><br><div>+</div><br><div>+ //</div><br><div>+ // Loop through the FFS file sections within the PEI Core FFS file</div><br><div>+ //</div><br><div>+ EndOfSection = (EFI_PHYSICAL_ADDRESS) (UINTN) Sections;</div><br><div>+ EndOfSections = EndOfSection + SizeOfSections;</div><br><div>+ for (;;) {</div><br><div>+ if (EndOfSection == EndOfSections) {</div><br><div>+ break;</div><br><div>+ }</div><br><div>+ CurrentAddress = (EndOfSection + 3) & ~(3ULL);</div><br><div>+ if (CurrentAddress >= EndOfSections) {</div><br><div>+ return EFI_VOLUME_CORRUPTED;</div><br><div>+ }</div><br><div>+</div><br><div>+ Section = (EFI_COMMON_SECTION_HEADER*) (UINTN) CurrentAddress;</div><br><div>+</div><br><div>+ Size = SECTION_SIZE (Section);</div><br><div>+ if (Size < sizeof (*Section)) {</div><br><div>+ return EFI_VOLUME_CORRUPTED;</div><br><div>+ }</div><br><div>+</div><br><div>+ EndOfSection = CurrentAddress + Size;</div><br><div>+ if (EndOfSection > EndOfSections) {</div><br><div>+ return EFI_VOLUME_CORRUPTED;</div><br><div>+ }</div><br><div>+</div><br><div>+ //</div><br><div>+ // Look for the requested section type</div><br><div>+ //</div><br><div>+ if (Section->Type == SectionType) {</div><br><div>+ if (Instance == 0) {</div><br><div>+ *FoundSection = Section;</div><br><div>+ return EFI_SUCCESS;</div><br><div>+ } else {</div><br><div>+ Instance--;</div><br><div>+ }</div><br><div>+ }</div><br><div>+ }</div><br><div>+</div><br><div>+ return EFI_NOT_FOUND;</div><br><div>+}</div><br><div>+</div><br><div>+/**</div><br><div>+ Locates a section within a series of sections</div><br><div>+ with the specified section type.</div><br><div>+</div><br><div>+ @param[in] Sections The sections to search</div><br><div>+ @param[in] SizeOfSections Total size of all sections</div><br><div>+ @param[in] SectionType The section type to locate</div><br><div>+ @param[out] FoundSection The FFS section if found</div><br><div>+</div><br><div>+ @retval EFI_SUCCESS The file and section was found</div><br><div>+ @retval EFI_NOT_FOUND The file and section was not found</div><br><div>+ @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted</div><br><div>+**/</div><br><div>+EFI_STATUS</div><br><div>+FindFfsSectionInSections (</div><br><div>+ IN VOID *Sections,</div><br><div>+ IN UINTN SizeOfSections,</div><br><div>+ IN EFI_SECTION_TYPE SectionType,</div><br><div>+ OUT EFI_COMMON_SECTION_HEADER **FoundSection</div><br><div>+ )</div><br><div>+{</div><br><div>+ return FindFfsSectionInstance (</div><br><div>+ Sections,</div><br><div>+ SizeOfSections,</div><br><div>+ SectionType,</div><br><div>+ 0,</div><br><div>+ FoundSection</div><br><div>+ );</div><br><div>+}</div><br><div>+</div><br><div>+/**</div><br><div>+ Locates a FFS file with the specified file type and a section</div><br><div>+ within that file with the specified section type.</div><br><div>+</div><br><div>+ @param[in] Fv The firmware volume to search</div><br><div>+ @param[in] FileType The file type to locate</div><br><div>+ @param[in] SectionType The section type to locate</div><br><div>+ @param[out] FoundSection The FFS section if found</div><br><div>+</div><br><div>+ @retval EFI_SUCCESS The file and section was found</div><br><div>+ @retval EFI_NOT_FOUND The file and section was not found</div><br><div>+ @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted</div><br><div>+**/</div><br><div>+EFI_STATUS</div><br><div>+FindFfsFileAndSection (</div><br><div>+ IN EFI_FIRMWARE_VOLUME_HEADER *Fv,</div><br><div>+ IN EFI_FV_FILETYPE FileType,</div><br><div>+ IN EFI_SECTION_TYPE SectionType,</div><br><div>+ OUT EFI_COMMON_SECTION_HEADER **FoundSection</div><br><div>+ )</div><br><div>+{</div><br><div>+ EFI_STATUS Status;</div><br><div>+ EFI_PHYSICAL_ADDRESS CurrentAddress;</div><br><div>+ EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume;</div><br><div>+ EFI_FFS_FILE_HEADER *File;</div><br><div>+ UINT32 Size;</div><br><div>+ EFI_PHYSICAL_ADDRESS EndOfFile;</div><br><div>+</div><br><div>+ if (Fv->Signature != EFI_FVH_SIGNATURE) {</div><br><div>+ DEBUG ((DEBUG_ERROR, "FV at %p does not have FV header signature\n", Fv));</div><br><div>+ return EFI_VOLUME_CORRUPTED;</div><br><div>+ }</div><br><div>+</div><br><div>+ CurrentAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) Fv;</div><br><div>+ EndOfFirmwareVolume = CurrentAddress + Fv->FvLength;</div><br><div>+</div><br><div>+ //</div><br><div>+ // Loop through the FFS files in the Boot Firmware Volume</div><br><div>+ //</div><br><div>+ for (EndOfFile = CurrentAddress + Fv->HeaderLength; ; ) {</div><br><div>+</div><br><div>+ CurrentAddress = (EndOfFile + 7) & ~(7ULL);</div><br><div>+ if (CurrentAddress > EndOfFirmwareVolume) {</div><br><div>+ return EFI_VOLUME_CORRUPTED;</div><br><div>+ }</div><br><div>+</div><br><div>+ File = (EFI_FFS_FILE_HEADER*) (UINTN) CurrentAddress;</div><br><div>+ Size = *(UINT32*) File->Size & 0xffffff;</div><br><div>+ if (Size < (sizeof (*File) + sizeof (EFI_COMMON_SECTION_HEADER))) {</div><br><div>+ return EFI_VOLUME_CORRUPTED;</div><br><div>+ }</div><br><div>+</div><br><div>+ EndOfFile = CurrentAddress + Size;</div><br><div>+ if (EndOfFile > EndOfFirmwareVolume) {</div><br><div>+ return EFI_VOLUME_CORRUPTED;</div><br><div>+ }</div><br><div>+</div><br><div>+ //</div><br><div>+ // Look for the request file type</div><br><div>+ //</div><br><div>+ if (File->Type != FileType) {</div><br><div>+ continue;</div><br><div>+ }</div><br><div>+</div><br><div>+ Status = FindFfsSectionInSections (</div><br><div>+ (VOID*) (File + 1),</div><br><div>+ (UINTN) EndOfFile - (UINTN) (File + 1),</div><br><div>+ SectionType,</div><br><div>+ FoundSection</div><br><div>+ );</div><br><div>+ if (!EFI_ERROR (Status)</div><br><div>+ || (Status == EFI_VOLUME_CORRUPTED))</div><br><div>+ {</div><br><div>+ return Status;</div><br><div>+ }</div><br><div>+ }</div><br><div>+}</div><br><div>+</div><br><div>+/**</div><br><div>+ Locates the PEI Core entry point address</div><br><div>+</div><br><div>+ @param[in] Fv The firmware volume to search</div><br><div>+ @param[out] PeiCoreEntryPoint The entry point of the PEI Core image</div><br><div>+</div><br><div>+ @retval EFI_SUCCESS The file and section was found</div><br><div>+ @retval EFI_NOT_FOUND The file and section was not found</div><br><div>+ @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted</div><br><div>+**/</div><br><div>+EFI_STATUS</div><br><div>+FindPeiCoreImageBaseInFv (</div><br><div>+ IN EFI_FIRMWARE_VOLUME_HEADER *Fv,</div><br><div>+ OUT EFI_PHYSICAL_ADDRESS *PeiCoreImageBase</div><br><div>+ )</div><br><div>+{</div><br><div>+ EFI_STATUS Status;</div><br><div>+ EFI_COMMON_SECTION_HEADER *Section;</div><br><div>+</div><br><div>+ Status = FindFfsFileAndSection (</div><br><div>+ Fv,</div><br><div>+ EFI_FV_FILETYPE_PEI_CORE,</div><br><div>+ EFI_SECTION_PE32,</div><br><div>+ &Section</div><br><div>+ );</div><br><div>+ if (EFI_ERROR (Status)) {</div><br><div>+ Status = FindFfsFileAndSection (</div><br><div>+ Fv,</div><br><div>+ EFI_FV_FILETYPE_PEI_CORE,</div><br><div>+ EFI_SECTION_TE,</div><br><div>+ &Section</div><br><div>+ );</div><br><div>+ if (EFI_ERROR (Status)) {</div><br><div>+ DEBUG ((DEBUG_ERROR, "Unable to find PEI Core image\n"));</div><br><div>+ return Status;</div><br><div>+ }</div><br><div>+ }</div><br><div>+</div><br><div>+ *PeiCoreImageBase = (EFI_PHYSICAL_ADDRESS)(UINTN)(Section + 1);</div><br><div>+ return EFI_SUCCESS;</div><br><div>+}</div><br><div>+</div><br><div>+/**</div><br><div>+ Find and return Pei Core entry point.</div><br><div>+</div><br><div>+ It also find SEC and PEI Core file debug information. It will report them if</div><br><div>+ remote debug is enabled.</div><br><div>+**/</div><br><div>+VOID</div><br><div>+FindAndReportEntryPoints (</div><br><div>+ IN EFI_FIRMWARE_VOLUME_HEADER **BootFirmwareVolumePtr,</div><br><div>+ OUT EFI_PEI_CORE_ENTRY_POINT *PeiCoreEntryPoint</div><br><div>+ )</div><br><div>+{</div><br><div>+ EFI_STATUS Status;</div><br><div>+ EFI_PHYSICAL_ADDRESS PeiCoreImageBase = 0;</div><br><div>+ PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;</div><br><div>+</div><br><div>+ Status = FindPeiCoreImageBaseInFv (*BootFirmwareVolumePtr, &PeiCoreImageBase);</div><br><div>+ ASSERT (Status == EFI_SUCCESS);</div><br><div>+</div><br><div>+ ZeroMem ((VOID *) &ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT));</div><br><div>+</div><br><div>+ //</div><br><div>+ // Report PEI Core debug information when remote debug is enabled</div><br><div>+ //</div><br><div>+ ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)PeiCoreImageBase;</div><br><div>+ ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);</div><br><div>+ PeCoffLoaderRelocateImageExtraAction (&ImageContext);</div><br><div>+</div><br><div>+ //</div><br><div>+ // Find PEI Core entry point</div><br><div>+ //</div><br><div>+ Status = PeCoffLoaderGetEntryPoint ((VOID *) (UINTN) PeiCoreImageBase, (VOID**) PeiCoreEntryPoint);</div><br><div>+ if (EFI_ERROR (Status)) {</div><br><div>+ *PeiCoreEntryPoint = 0;</div><br><div>+ }</div><br><div>+</div><br><div>+ return;</div><br><div>+}</div><br><div>+</div><br><div>+/**</div><br><div>+ Find the peicore entry point and jump to the entry point to execute.</div><br><div>+</div><br><div>+ @param[in] Context The first input parameter of InitializeDebugAgent().</div><br><div>+**/</div><br><div>+VOID</div><br><div>+EFIAPI</div><br><div>+SecStartupPhase2 (</div><br><div>+ IN VOID *Context</div><br><div>+ )</div><br><div>+{</div><br><div>+ EFI_SEC_PEI_HAND_OFF *SecCoreData;</div><br><div>+ EFI_FIRMWARE_VOLUME_HEADER *BootFv;</div><br><div>+ EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;</div><br><div>+</div><br><div>+ SecCoreData = (EFI_SEC_PEI_HAND_OFF *) Context;</div><br><div>+</div><br><div>+ //</div><br><div>+ // Find PEI Core entry point. It will report SEC and Pei Core debug information if remote debug</div><br><div>+ // is enabled.</div><br><div>+ //</div><br><div>+ BootFv = (EFI_FIRMWARE_VOLUME_HEADER *)SecCoreData->BootFirmwareVolumeBase;</div><br><div>+ FindAndReportEntryPoints (&BootFv, &PeiCoreEntryPoint);</div><br><div>+ SecCoreData->BootFirmwareVolumeBase = BootFv;</div><br><div>+ SecCoreData->BootFirmwareVolumeSize = (UINTN) BootFv->FvLength;</div><br><div>+</div><br><div>+ DEBUG ((DEBUG_INFO, "Find Pei EntryPoint=%p\n", PeiCoreEntryPoint));</div><br><div>+</div><br><div>+ //</div><br><div>+ // Transfer the control to the PEI core</div><br><div>+ //</div><br><div>+ DEBUG ((DEBUG_INFO, "SecStartupPhase2 %p\n", PeiCoreEntryPoint));</div><br><div>+</div><br><div>+ (*PeiCoreEntryPoint) (SecCoreData, (EFI_PEI_PPI_DESCRIPTOR *)&mPrivateDispatchTable);</div><br><div>+</div><br><div>+ //</div><br><div>+ // If we get here then the PEI Core returned, which is not recoverable.</div><br><div>+ //</div><br><div>+ ASSERT (FALSE);</div><br><div>+ CpuDeadLoop ();</div><br><div>+}</div><br><div>+/**</div><br><div>+ Entry point to the C language phase of SEC. initialize some temporary memory and set up the stack,</div><br><div>+ the control is transferred to this function.</div><br><div>+</div><br><div>+ @param[in] BootFv The pointer to the PEI FV in memory.</div><br><div>+ @param[in] TopOfCurrentStack Top of Current Stack.</div><br><div>+**/</div><br><div>+VOID</div><br><div>+EFIAPI</div><br><div>+SecCoreStartupWithStack (</div><br><div>+ IN EFI_FIRMWARE_VOLUME_HEADER *BootFv,</div><br><div>+ IN VOID *TopOfCurrentStack</div><br><div>+ )</div><br><div>+{</div><br><div>+ EFI_SEC_PEI_HAND_OFF SecCoreData;</div><br><div>+ EFI_FIRMWARE_VOLUME_HEADER *BootPeiFv = (EFI_FIRMWARE_VOLUME_HEADER*) BootFv;</div><br><div>+</div><br><div>+ DEBUG ((DEBUG_INFO, "Entering C environment\n"));</div><br><div>+</div><br><div>+ ProcessLibraryConstructorList (NULL, NULL);</div><br><div>+</div><br><div>+ DEBUG ((DEBUG_INFO,</div><br><div>+ "SecCoreStartupWithStack (0x%lx, 0x%lx)\n",</div><br><div>+ (UINTN)BootFv,</div><br><div>+ (UINTN)TopOfCurrentStack</div><br><div>+ ));</div><br><div>+ DEBUG ((DEBUG_INFO,</div><br><div>+ "(0x%lx, 0x%lx)\n",</div><br><div>+ (UINTN) (PcdGet64 (PcdSecPeiTempRamBase)),</div><br><div>+ (UINTN) (PcdGet32 (PcdSecPeiTempRamSize))</div><br><div>+ ));</div><br><div>+</div><br><div>+ // |-------------| <-- TopOfCurrentStack</div><br><div>+ // | Stack | 32k</div><br><div>+ // |-------------|</div><br><div>+ // | Heap | 32k</div><br><div>+ // |-------------| <-- SecCoreData.TemporaryRamBase</div><br><div>+ //</div><br><div>+</div><br><div>+ ASSERT ((UINTN) (PcdGet64 (PcdSecPeiTempRamBase) +</div><br><div>+ PcdGet32 (PcdSecPeiTempRamSize)) ==</div><br><div>+ (UINTN) TopOfCurrentStack);</div><br><div>+</div><br><div>+ //</div><br><div>+ // Initialize SEC hand-off state</div><br><div>+ //</div><br><div>+ SecCoreData.DataSize = sizeof (EFI_SEC_PEI_HAND_OFF);</div><br><div>+</div><br><div>+ SecCoreData.TemporaryRamSize = (UINTN) PcdGet32 (PcdSecPeiTempRamSize);</div><br><div>+ SecCoreData.TemporaryRamBase = (VOID *) PcdGet64 (PcdSecPeiTempRamBase);</div><br><div>+</div><br><div>+ SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;</div><br><div>+ SecCoreData.PeiTemporaryRamSize = SecCoreData.TemporaryRamSize >> 1;</div><br><div>+</div><br><div>+ SecCoreData.StackBase = (UINT8 *)SecCoreData.TemporaryRamBase + SecCoreData.PeiTemporaryRamSize;</div><br><div>+ SecCoreData.StackSize = SecCoreData.TemporaryRamSize >> 1;</div><br><div>+</div><br><div>+ SecCoreData.BootFirmwareVolumeBase = BootPeiFv;</div><br><div>+ SecCoreData.BootFirmwareVolumeSize = (UINTN) BootPeiFv->FvLength;</div><br><div>+</div><br><div>+ DEBUG ((DEBUG_INFO,</div><br><div>+ "&SecCoreData.BootFirmwareVolumeBase=%lx SecCoreData.BootFirmwareVolumeBase=%lx\n",</div><br><div>+ (UINT64)&(SecCoreData.BootFirmwareVolumeBase),</div><br><div>+ (UINT64) (SecCoreData.BootFirmwareVolumeBase)));</div><br><div>+ DEBUG ((DEBUG_INFO,</div><br><div>+ "&SecCoreData.BootFirmwareVolumeSize=%lx SecCoreData.BootFirmwareVolumeSize=%lx\n",</div><br><div>+ (UINT64)&(SecCoreData.BootFirmwareVolumeSize),</div><br><div>+ (UINT64) (SecCoreData.BootFirmwareVolumeSize)));</div><br><div>+</div><br><div>+ //</div><br><div>+ // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.</div><br><div>+ //</div><br><div>+ InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, NULL, NULL);</div><br><div>+ SecStartupPhase2 (&SecCoreData);</div><br><div>+}</div><br><div>+</div><br><div>+/**</div><br><div>+ temporary memory to permanent memory and do stack switching.</div><br><div>+</div><br><div>+ @param[in] PeiServices Pointer to the PEI Services Table.</div><br><div>+ @param[in] TemporaryMemoryBase Temporary Memory Base address.</div><br><div>+ @param[in] PermanentMemoryBase Permanent Memory Base address.</div><br><div>+ @param[in] CopySize The size of memory that needs to be migrated.</div><br><div>+</div><br><div>+ @retval EFI_SUCCESS Migration successful.</div><br><div>+**/</div><br><div>+EFI_STATUS</div><br><div>+EFIAPI</div><br><div>+TemporaryRamMigration (</div><br><div>+ IN CONST EFI_PEI_SERVICES **PeiServices,</div><br><div>+ IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,</div><br><div>+ IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,</div><br><div>+ IN UINTN CopySize</div><br><div>+ )</div><br><div>+{</div><br><div>+ VOID *OldHeap;</div><br><div>+ VOID *NewHeap;</div><br><div>+ VOID *OldStack;</div><br><div>+ VOID *NewStack;</div><br><div>+ BASE_LIBRARY_JUMP_BUFFER JumpBuffer;</div><br><div>+</div><br><div>+ DEBUG ((DEBUG_INFO,</div><br><div>+ "TemporaryRamMigration (0x%Lx, 0x%Lx, 0x%Lx)\n",</div><br><div>+ TemporaryMemoryBase,</div><br><div>+ PermanentMemoryBase,</div><br><div>+ (UINT64)CopySize</div><br><div>+ ));</div><br><div>+</div><br><div>+ OldHeap = (VOID*) (UINTN)TemporaryMemoryBase;</div><br><div>+ NewHeap = (VOID*) ((UINTN)PermanentMemoryBase + (CopySize >> 1));</div><br><div>+</div><br><div>+ OldStack = (VOID*) ((UINTN)TemporaryMemoryBase + (CopySize >> 1));</div><br><div>+ NewStack = (VOID*) (UINTN)PermanentMemoryBase;</div><br><div>+</div><br><div>+ //</div><br><div>+ // Migrate Heap</div><br><div>+ //</div><br><div>+ CopyMem (NewHeap, OldHeap, CopySize >> 1);</div><br><div>+</div><br><div>+ //</div><br><div>+ // Migrate Stack</div><br><div>+ //</div><br><div>+ CopyMem (NewStack, OldStack, CopySize >> 1);</div><br><div>+</div><br><div>+ // Use SetJump ()/LongJump () to switch to a new stack.</div><br><div>+ //</div><br><div>+ if (SetJump (&JumpBuffer) == 0) {</div><br><div>+ JumpBuffer.SP = JumpBuffer.SP - (UINTN)OldStack + (UINTN)NewStack ;</div><br><div>+ LongJump (&JumpBuffer, (UINTN)-1);</div><br><div>+ }</div><br><div>+</div><br><div>+ return EFI_SUCCESS;</div><br><div>+}</div><br><div>diff --git a/Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf b/Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf</div><br><div>new file mode 100644</div><br><div>index 0000000000..c0d5439d53</div><br><div>--- /dev/null</div><br><div>+++ b/Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf</div><br><div>@@ -0,0 +1,51 @@</div><br><div>+## @file</div><br><div>+# SEC Driver</div><br><div>+#</div><br><div>+# Copyright (c) 2022 Loongson Technology Corporation Limited. All rights reserved.<BR></div><br><div>+#</div><br><div>+# SPDX-License-Identifier: BSD-2-Clause-Patent</div><br><div>+#</div><br><div>+##</div><br><div>+</div><br><div>+[Defines]</div><br><div>+ INF_VERSION = 0x00010005</div><br><div>+ BASE_NAME = SecMain</div><br><div>+ FILE_GUID = 57d02d4f-5a5d-4bfa-b7d6-ba0a4d2c72ce</div><br><div>+ MODULE_TYPE = SEC</div><br><div>+ VERSION_STRING = 1.0</div><br><div>+</div><br><div>+#</div><br><div>+# VALID_ARCHITECTURES = LOONGARCH64</div><br><div>+#</div><br><div>+</div><br><div>+[Sources]</div><br><div>+ LoongArch64/Start.S</div><br><div>+ SecMain.c</div><br><div>+</div><br><div>+[Packages]</div><br><div>+ Platform/Loongson/LoongArchQemuPkg/Loongson.dec</div><br><div>+ MdePkg/MdePkg.dec</div><br><div>+ MdeModulePkg/MdeModulePkg.dec</div><br><div>+</div><br><div>+[LibraryClasses]</div><br><div>+ BaseLib</div><br><div>+ DebugLib</div><br><div>+ BaseMemoryLib</div><br><div>+ PcdLib</div><br><div>+ DebugAgentLib</div><br><div>+ IoLib</div><br><div>+ PeCoffLib</div><br><div>+ PeCoffGetEntryPointLib</div><br><div>+ PeCoffExtraActionLib</div><br><div>+</div><br><div>+[Ppis]</div><br><div>+ gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED</div><br><div>+</div><br><div>+[FixedPcd]</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize</div><br><div>+</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvBase</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvSize</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdFlashPeiFvBase</div><br><div>+ gLoongArchQemuPkgTokenSpaceGuid.PcdFlashPeiFvSize</div><br><div>--</div><br><div>2.31.1</div></div></blockquote>


 <div width="1" style="color:white;clear:both">_._,_._,_</div> <hr>   Groups.io Links:<p>   You receive all messages sent to this group.    <p> <a target="_blank" href="https://edk2.groups.io/g/devel/message/96287">View/Reply Online (#96287)</a> |    |  <a target="_blank" href="https://groups.io/mt/94954837/1813853">Mute This Topic</a>  | <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>    <a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> | <a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |  <a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>  [edk2-devel-archive@redhat.com]<br> <div width="1" style="color:white;clear:both">_._,_._,_</div>