From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from loongson.cn (loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.3678.1668159340226502226 for ; Fri, 11 Nov 2022 01:35:45 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: loongson.cn, ip: 114.242.206.163, mailfrom: lichao@loongson.cn) Received: from loongson.cn (unknown [10.40.24.149]) by gateway (Coremail) with SMTP id _____8BxLLZpF25jghUGAA--.7456S3; Fri, 11 Nov 2022 17:35:37 +0800 (CST) Received: from lichao-PC (unknown [10.40.24.149]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxn+BoF25jjNEQAA--.46140S2; Fri, 11 Nov 2022 17:35:36 +0800 (CST) Date: Fri, 11 Nov 2022 17:35:36 +0800 From: "Chao Li" To: xianglai li Cc: "=?utf-8?Q?devel=40edk2.groups.io?=" , Bibo Mao , Leif Lindholm , Liming Gao , Michael D Kinney Message-ID: <16727D8D-5F17-4B8F-8DE4-0C4BFD80E555@getmailspring.com> In-Reply-To: <5808d9638bcee3d0d32626ced147f47914ab4284.1668157715.git.lixianglai@loongson.cn> References: <5808d9638bcee3d0d32626ced147f47914ab4284.1668157715.git.lixianglai@loongson.cn> Subject: Re: [edk2-platforms][PATCH V5 02/15] Platform/Loongson: Support SEC X-Mailer: Mailspring MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cxn+BoF25jjNEQAA--.46140S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAHCGNs6eQZ0AARsU X-Coremail-Antispam: 1Uk129KBjvAXoWftr45WFWrtryrJFW8GrWktFb_yoW5CF4UAo WxuFWIkw48Gr1rX3WUGrnrJrW0yF1rXa15tr1rX34DGF4jyFn8Ka95J3srGw15Jw15J3Z8 G34rGaykJrW7t3Wkn29KB7ZKAUJUUUUk529EdanIXcx71UUUUU7KY7ZEXasCq-sGcSsGvf J3Ec02F40Eb7x2x7xS6r1j6r4UMc02F40EFcxC0VAKzVAqx4xG6I80ewAqx4xG64kEw2xG 04xIwI0_Xr0_WrUv73VFW2AGmfu7bjvjm3AaLaJ3UjIYCTnIWjp_UUUOT7kC6x804xWl14 x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWU XVWUAwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14 v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j6F4UM28EF7xvwVC2z280aVAF wI0_Cr1j6rxdM28EF7xvwVC2z280aVCY1x0267AKxVWxJr0_GcWln4kS14v26r1q6r43M2 AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx1l5I8CrVAYj202 j2C_Jr0_Gr1l5I8CrVACY4xI64kE6c02F40Ex7xfMc02F40Ew4AK048IF2xKxVW5JVWrJw Av7VC0I7IYx2IY67AKxVWUAVWUtwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY 6r1j6r4UM4x0Y48IcxkI7VAKI48JMx8GjcxK6IxK0xIIj40E5I8CrwCY1x0262kKe7AKxV WUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r106r1rMI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU0sYFtUU UUU== Content-Type: multipart/alternative; boundary="636e1768_c7e4c42_1e57b" --636e1768_c7e4c42_1e57b Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Reviewed-by: Chao Li Thanks, Chao -------- On 11=E6=9C=88 11 2022, at 5:12 =E4=B8=8B=E5=8D=88, xianglai li wrote: > Add SEC Code And Readme.md for LoongArchQemu > > > > RE=46: https://bugzilla.tianocore.org/show=5Fbug.cgi=3Fid=3D4054 > > > Cc: Bibo Mao > Cc: Chao Li > Cc: Leif Lindholm > Cc: Liming Gao > Cc: Michael D Kinney > Signed-off-by: xianglai li > Signed-off-by: xianglai li > --- > .../Include/LoongArchQemuPlatform.h =7C 2 +- > .../Loongson/LoongArchQemuPkg/Loongson.dec =7C 38 ++ > .../Loongson/LoongArchQemuPkg/Loongson.dsc =7C 122 +++++ > .../Loongson/LoongArchQemuPkg/Loongson.fdf =7C 53 ++ > .../LoongArchQemuPkg/Loongson.fdf.inc =7C 21 + > .../LoongArchQemuPkg/Sec/LoongArch64/Start.S =7C 84 +++ > .../Loongson/LoongArchQemuPkg/Sec/SecMain.c =7C 494 ++++++++++++++++++ > .../Loongson/LoongArchQemuPkg/Sec/SecMain.inf =7C 51 ++ > 8 files changed, 864 insertions(+), 1 deletion(-) > create mode 100644 Platform/Loongson/LoongArchQemuPkg/Loongson.dec > create mode 100644 Platform/Loongson/LoongArchQemuPkg/Loongson.dsc > create mode 100644 Platform/Loongson/LoongArchQemuPkg/Loongson.fdf > create mode 100644 Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc > create mode 100644 Platform/Loongson/LoongArchQemuPkg/Sec/LoongArch64/S= tart.S > create mode 100644 Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.c > create mode 100644 Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf > > > diff --git a/Platform/Loongson/LoongArchQemuPkg/Include/LoongArchQemuPl= atform.h b/Platform/Loongson/LoongArchQemuPkg/Include/LoongArchQemuPlatfo= rm.h > index e942e6a994..d003b9013d 100644 > --- a/Platform/Loongson/LoongArchQemuPkg/Include/LoongArchQemuPlatform.= h > +++ b/Platform/Loongson/LoongArchQemuPkg/Include/LoongArchQemuPlatform.= h > =40=40 -92,4 +92,4 =40=40 > =23define UART=5FBASE=5FADDRESS (0x1fe001e0) > =23define UART=5FBPS (115200) > =23define UART=5FWAIT=5FTIMOUT (1000000) > -=23endif > +=23endif // LOONGARCH=5FQEMU=5FPLAT=46ORM=5FH=5F > diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec b/Platform= /Loongson/LoongArchQemuPkg/Loongson.dec > new file mode 100644 > index 0000000000..61f600b20d > --- /dev/null > +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec > =40=40 -0,0 +1,38 =40=40 > +=23=23 =40file > +=23 > +=23 Copyright (c) 2022 Loongson Technology Corporation Limited. All ri= ghts reserved.
> +=23 > +=23 SPDX-License-Identifier: BSD-2-Clause-Patent > +=23 > +=23=23 > + > +=5BDefines=5D > + DEC=5FSPECI=46ICATION =3D 0x00010005 > + PACKAGE=5FNAME =3D LoongArchQemuPkg > + PACKAGE=5FGUID =3D b51d765a-41da-45fc-a537-de3ee785c0f6 > + PACKAGE=5FVERSION =3D 0.1 > + > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23 > +=23 > +=23 Include Section - list of Include Paths that are provided by this = package. > +=23 Comments are used for Keywords and Module Types. > +=23 > +=23 Supported Module Types: > +=23 BASE SEC PEI=5FCORE PEIM DXE=5FCORE DXE=5FDRIVER DXE=5FRUNTIME=5FD= RIVER DXE=5FSMM=5FDRIVER > +=23 DXE=5FSAL=5FDRIVER UE=46I=5FDRIVER UE=46I=5FAPPLICATION > +=23 > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23 > +=5BIncludes.common=5D > + Include =23 Root include for the package > + > +=5BGuids=5D > + gLoongArchQemuPkgTokenSpaceGuid =3D =7B 0x0e0383ce, 0x0151, 0x4d01, =7B= 0x80, 0x0e, 0x3f, 0xef, 0x8b, 0x27, 0x6d, 0x52 =7D =7D > + > +=23=23 In the Pcds=46ixedAtBuild and PcdsDynamic areas, numbers start = at 0x0. > +=5BPcds=46ixedAtBuild, PcdsDynamic=5D > + gLoongArchQemuPkgTokenSpaceGuid.Pcd=46lashPei=46vBase=7C0x0=7CUINT64=7C= 0x00000000 > + gLoongArchQemuPkgTokenSpaceGuid.Pcd=46lashPei=46vSize=7C0x0=7CUINT32=7C= 0x00000001 > + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase=7C0=7CUINT64=7C0= x0000000b > + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize=7C0=7CUINT32=7C0= x0000000c > + gLoongArchQemuPkgTokenSpaceGuid.Pcd=46lashSec=46vBase=7C0x0=7CUINT64=7C= 0x0000000f > + gLoongArchQemuPkgTokenSpaceGuid.Pcd=46lashSec=46vSize=7C0x0=7CUINT32=7C= 0x00000010 > diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc b/Platform= /Loongson/LoongArchQemuPkg/Loongson.dsc > new file mode 100644 > index 0000000000..b506f70625 > --- /dev/null > +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc > =40=40 -0,0 +1,122 =40=40 > +=23=23 =40file > +=23 > +=23 Copyright (c) 2022 Loongson Technology Corporation Limited. All ri= ghts reserved.
> +=23 > +=23 SPDX-License-Identifier: BSD-2-Clause-Patent > +=23 > +=23=23 > + > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23 > +=23 > +=23 Defines Section - statements that will be processed to create a Ma= kefile. > +=23 > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23 > +=5BDefines=5D > + PLAT=46ORM=5FNAME =3D LoongArchQemu > + PLAT=46ORMPKG=5FNAME =3D LoongArchQemu > + PLAT=46ORM=5FGUID =3D 7926ea52-b0dc-4ee8-ac63-341eebd84ed4 > + PLAT=46ORM=5FVERSION =3D 0.1 > + DSC=5FSPECI=46ICATION =3D 0x00010005 > + OUTPUT=5FDIRECTORY =3D Build/=24(PLAT=46ORM=5FNAME) > + SUPPORTED=5FARCHITECTURES =3D LOONGARCH64 > + BUILD=5FTARGETS =3D DEBUG=7CRELEASE > + SKUID=5FIDENTI=46IER =3D DE=46AULT > + =46LASH=5FDE=46INITION =3D Platform/Loongson/LoongArchQemuPkg/Loongso= n.fdf > + TTY=5FTERMINAL =3D =46ALSE > + > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23 > +=23 > +=23 Defines for default states. These can be changed on the command li= ne. > +=23 -D =46LAG=3DVALUE > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23 > +=5BBuildOptions=5D > + GCC:RELEASE=5F*=5F*=5FCC=5F=46LAGS =3D -DSPEEDUP > + > + =23 > + =23 Disable deprecated APIs. > + =23 > + GCC:*=5F*=5F*=5FCC=5F=46LAGS =3D -D DISABLE=5FNEW=5FDEPRECATED=5FINTE= R=46ACES > + > +=5BBuildOptions.LOONGARCH64.EDKII.SEC=5D > + *=5F*=5F*=5FCC=5F=46LAGS =3D > + > +=5BBuildOptions.common.EDKII.DXE=5FCORE,BuildOptions.common.EDKII.DXE=5F= DRIVER,BuildOptions.common.EDKII.UE=46I=5FDRIVER,BuildOptions.common.EDKI= I.UE=46I=5FAPPLICATION=5D > + GCC:*=5F*=5F*=5FDLINK=5F=46LAGS =3D -z common-page-size=3D0x1000 > + > +=5BBuildOptions.common.EDKII.DXE=5FRUNTIME=5FDRIVER=5D > + GCC:*=5F*=5FLOONGARCH64=5FDLINK=5F=46LAGS =3D -z common-page-size=3D0= x10000 > + > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23 > +=23 > +=23 Library Class section - list of all Library Classes needed by this= Platform. > +=23 > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23 > + > +=21include MdePkg/MdeLibs.dsc.inc > + > +=5BLibraryClasses.common=5D > + PcdLib =7C MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf > + PrintLib =7C MdePkg/Library/BasePrintLib/BasePrintLib.inf > + BaseMemoryLib =7C MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf > + BaseLib =7C MdePkg/Library/BaseLib/BaseLib.inf > + PeCoffLib =7C MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf > + PeCoffGetEntryPointLib =7C MdePkg/Library/BasePeCoffGetEntryPointLib/= BasePeCoffGetEntryPointLib.inf > + IoLib =7C MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf > + SerialPortLib =7C Platform/Loongson/LoongArchQemuPkg/Library/SerialPo= rtLib/SerialPortLib.inf > + DebugPrintErrorLevelLib =7C MdePkg/Library/BaseDebugPrintErrorLevelLi= b/BaseDebugPrintErrorLevelLib.inf > + PeCoffExtraActionLib =7C MdePkg/Library/BasePeCoffExtraActionLibNull/= BasePeCoffExtraActionLibNull.inf > + DebugAgentLib =7C MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLi= bNull.inf > + > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23 > +=23 > +=23 Pcd Section - list of all EDK II PCD Entries defined by this Platf= orm. > +=23 > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23 > +=5BPcds=46ixedAtBuild=5D > +=23=23 BaseLib =23=23 > + gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength =7C 1000000 > + gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength =7C 1000000 > + gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength =7C 1000000 > + > + gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel =7C 0x8000004=46 > + =23 DEBUG=5FINIT 0x00000001 // Initialization > + =23 DEBUG=5FWARN 0x00000002 // Warnings > + =23 DEBUG=5FLOAD 0x00000004 // Load events > + =23 DEBUG=5F=46S 0x00000008 // E=46I =46ile system > + =23 DEBUG=5FPOOL 0x00000010 // Alloc & =46ree (pool) > + =23 DEBUG=5FPAGE 0x00000020 // Alloc & =46ree (page) > + =23 DEBUG=5FIN=46O 0x00000040 // Informational debug messages > + =23 DEBUG=5FDISPATCH 0x00000080 // PEI/DXE/SMM Dispatchers > + =23 DEBUG=5FVARIABLE 0x00000100 // Variable > + =23 DEBUG=5FBM 0x00000400 // Boot Manager > + =23 DEBUG=5FBLKIO 0x00001000 // BlkIo Driver > + =23 DEBUG=5FNET 0x00004000 // Network Io Driver > + =23 DEBUG=5FUNDI 0x00010000 // UNDI Driver > + =23 DEBUG=5FLOAD=46ILE 0x00020000 // Load=46ile > + =23 DEBUG=5FEVENT 0x00080000 // Event messages > + =23 DEBUG=5FGCD 0x00100000 // Global Coherency Database changes > + =23 DEBUG=5FCACHE 0x00200000 // Memory range cachability changes > + =23 DEBUG=5FVERBOSE 0x00400000 // Detailed debug messages that may > + =23 DEBUG=5FERROR 0x80000000 // Error > + > +=21if =24(TARGET) =3D=3D RELEASE > + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask =7C 0x21 > +=21else > + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask =7C 0x2f > +=21endif > + =23 DEBUG=5FASSERT=5FENABLED 0x01 > + =23 DEBUG=5FPRINT=5FENABLED 0x02 > + =23 DEBUG=5FCODE=5FENABLED 0x04 > + =23 CLEAR=5FMEMORY=5FENABLED 0x08 > + =23 ASSERT=5FBREAKPOINT=5FENABLED 0x10 > + =23 ASSERT=5FDEADLOOP=5FENABLED 0x20 > + > + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase =7C 0x10000 > + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize =7C 0x10000 > + > +=5BComponents=5D > + > + =23 > + =23 SEC Phase modules > + =23 > + Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf > diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf b/Platform= /Loongson/LoongArchQemuPkg/Loongson.fdf > new file mode 100644 > index 0000000000..9685795cda > --- /dev/null > +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf > =40=40 -0,0 +1,53 =40=40 > +=23=23 =40file > +=23 > +=23 Copyright (c) 2022 Loongson Technology Corporation Limited. All ri= ghts reserved.
> +=23 > +=23 SPDX-License-Identifier: BSD-2-Clause-Patent > +=23 > +=23=23 > + > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23 > +=5BDefines=5D > +=21include Loongson.fdf.inc > + > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23 > +=5B=46D.QEMU=5FE=46I=5D > +BaseAddress =3D =24(=46D=5FBASE=5FADDRESS) > +Size =3D =24(=46D=5FSIZE) > +ErasePolarity =3D 1 > +BlockSize =3D =24(BLOCK=5FSIZE) > +NumBlocks =3D =24(=46D=5FBLOCKS) > + > +=24(SEC=46V=5FO=46=46SET)=7C=24(SEC=46V=5FSIZE) > +gLoongArchQemuPkgTokenSpaceGuid.Pcd=46lashSec=46vBase=7CgLoongArchQemu= PkgTokenSpaceGuid.Pcd=46lashSec=46vSize > +=46V =3D SEC=46V > + > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23 > +=5B=46V.SEC=46V=5D > +=46vNameGuid =3D 587d4265-5e71-41da-9c35-4258551f1e22 > +BlockSize =3D =24(BLOCK=5FSIZE) > +=46vAlignment =3D 16 > +ERASE=5FPOLARITY =3D 1 > +MEMORY=5FMAPPED =3D TRUE > +STICKY=5FWRITE =3D TRUE > +LOCK=5FCAP =3D TRUE > +LOCK=5FSTATUS =3D TRUE > +WRITE=5FDISABLED=5FCAP =3D TRUE > +WRITE=5FENABLED=5FCAP =3D TRUE > +WRITE=5FSTATUS =3D TRUE > +WRITE=5FLOCK=5FCAP =3D TRUE > +WRITE=5FLOCK=5FSTATUS =3D TRUE > +READ=5FDISABLED=5FCAP =3D TRUE > +READ=5FENABLED=5FCAP =3D TRUE > +READ=5FSTATUS =3D TRUE > +READ=5FLOCK=5FCAP =3D TRUE > +READ=5FLOCK=5FSTATUS =3D TRUE > + > +IN=46 Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf > + > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23 > +=5BRule.Common.SEC=5D > + =46ILE SEC =3D =24(NAMED=5FGUID) =7B > + TE TE Align =3D Auto =24(IN=46=5FOUTPUT)/=24(MODULE=5FNAME).efi > + UI STRING =3D=22=24(MODULE=5FNAME)=22 Optional > + =7D > diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc b/Plat= form/Loongson/LoongArchQemuPkg/Loongson.fdf.inc > new file mode 100644 > index 0000000000..6f17909748 > --- /dev/null > +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc > =40=40 -0,0 +1,21 =40=40 > +=23=23 =40file > +=23 > +=23 Copyright (c) 2022 Loongson Technology Corporation Limited. All ri= ghts reserved.
> +=23 > +=23 SPDX-License-Identifier: BSD-2-Clause-Patent > +=23 > +=23=23 > + > +DE=46INE BLOCK=5FSIZE =3D 0x1000 > + > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23 > +=23 fd total > +DE=46INE =46D=5FBASE=5FADDRESS =3D 0x1c000000 > +DE=46INE =46D=5FBLOCKS =3D 0x400 > +DE=46INE =46D=5FSIZE =3D 0x400000 > + > +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23 > +=23flash code layout > +=23Set Sec base address and size in flash > +DE=46INE SEC=46V=5FO=46=46SET =3D 0x00000000 > +DE=46INE SEC=46V=5FSIZE =3D 0x00010000 > diff --git a/Platform/Loongson/LoongArchQemuPkg/Sec/LoongArch64/Start.S= b/Platform/Loongson/LoongArchQemuPkg/Sec/LoongArch64/Start.S > new file mode 100644 > index 0000000000..5d7ce313c0 > --- /dev/null > +++ b/Platform/Loongson/LoongArchQemuPkg/Sec/LoongArch64/Start.S > =40=40 -0,0 +1,84 =40=40 > +=23-------------------------------------------------------------------= ----------- > +=23 > +=23 Start for LoongArch > +=23 > +=23 Copyright (c) 2022 Loongson Technology Corporation Limited. All ri= ghts reserved.
> +=23 > +=23 SPDX-License-Identifier: BSD-2-Clause-Patent > +=23 > +=23 =40par Glossary: > +=23 - CSR - CPU Status Register > +=23 - EBASE - Exception Base Address > +=23-------------------------------------------------------------------= ----------- > +=23ifndef =5F=5FASSEMBLY=5F=5F > +=23define =5F=5FASSEMBLY=5F=5F > +=23endif > + > +=23include > + > +ASM=5FGLOBAL ASM=5FP=46X(=5FModuleEntryPoint) > +ASM=5FGLOBAL ASM=5FP=46X(DeadLoop) > + > +.text > +ASM=5FP=46X(=5FModuleEntryPoint): > + /* configure reset ebase */ > + la.pcrel T0, DeadLoop > + csrwr T0, LOONGARCH=5FCSR=5FEBASE > + > + /*disable interrupt*/ > + li.d T0, (1 << 2) > + csrxchg ZERO, T0, LOONGARCH=5FCSR=5FCRMD > + > + /* read physical cpu number id */ > + csrrd T0, LOONGARCH=5FCSR=5FCPUNUM > + andi T0, T0, 0x3ff > + li.d A0, BOOTCORE=5FID //0 > + bne T0, A0, slave=5Fmain > + > +call=5Fcentry: > + /*call C function make sure parameter true*/ > + li.d A1, =46ixedPcdGet64(PcdSecPeiTempRamBase) + =46ixedPcdGet32(PcdS= ecPeiTempRamSize) =23 stack base > + li.d A0, =46ixedPcdGet64(Pcd=46lashPei=46vBase) =23 PEI =46v base > + move SP, A1 > + addi.d SP, SP, -0x8 > + bl SecCoreStartupWithStack > + > +slave=5Fmain: > + =23 clear mailbox > + li.d T1, LOONGSON=5FCSR=5FMAIL=5FBU=460 > + iocsrwr.d ZERO, T1 > + > + =23 enable IPI interrupt > + li.d T0, (1 << 12) > + csrxchg T0, T0, LOONGARCH=5FCSR=5FEC=46G > + > + addi.d T0, ZERO, -1 > + li.d T1, LOONGSON=5FIOCSR=5FIPI=5FEN > + iocsrwr.w T0, T1 > + > +1: > + =23 wait for wakeup > + idle 0 > + nop > + iocsrrd.w T0, T1 > + beqz T0, 1b > + > + =23 read and clear ipi interrupt > + li.d T1, LOONGSON=5FIOCSR=5FIPI=5FSTATUS > + iocsrrd.w T0, T1 > + li.d T1, LOONGSON=5FIOCSR=5FIPI=5FCLEAR > + iocsrwr.w T0, T1 > + > + =23 disable IPI interrupt > + li.d T0, (1 << 12) > + csrxchg ZERO, T0, LOONGARCH=5FCSR=5FEC=46G > + > + =23 read mail buf and jump to specified entry > + li.d T1, LOONGSON=5FCSR=5FMAIL=5FBU=460 > + iocsrrd.d T0, T1 > + or RA, T0, ZERO > + jirl ZERO, RA, 0x0 > + > +.align 12 > +ASM=5FP=46X(DeadLoop): > + b DeadLoop > diff --git a/Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.c b/Platfor= m/Loongson/LoongArchQemuPkg/Sec/SecMain.c > new file mode 100644 > index 0000000000..3f1998c48c > --- /dev/null > +++ b/Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.c > =40=40 -0,0 +1,494 =40=40 > +/** =40file > + Main SEC phase code. Transitions to PEI. > + > + Copyright (c) 2022 Loongson Technology Corporation Limited. All right= s reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +=23include > + > +=23include > +=23include > +=23include > +=23include > +=23include > +=23include > +=23include > +=23include > +=23include > +=23include > +=23include > +=23include > + > +=23include > + > +/** > + temporary memory to permanent memory and do stack switching. > + > + =40param=5Bin=5D PeiServices Pointer to the PEI Services Table. > + =40param=5Bin=5D TemporaryMemoryBase Temporary Memory Base address. > + =40param=5Bin=5D PermanentMemoryBase Permanent Memory Base address. > + =40param=5Bin=5D CopySize The size of memory that needs to be migrate= d. > + > + =40retval E=46I=5FSUCCESS Migration successful. > +**/ > +E=46I=5FSTATUS > +E=46IAPI > +TemporaryRamMigration ( > + IN CONST E=46I=5FPEI=5FSERVICES **PeiServices, > + IN E=46I=5FPHYSICAL=5FADDRESS TemporaryMemoryBase, > + IN E=46I=5FPHYSICAL=5FADDRESS PermanentMemoryBase, > + IN UINTN CopySize > + ); > + > +E=46I=5FPEI=5FTEMPORARY=5FRAM=5FSUPPORT=5FPPI mTemporaryRamSupportPpi = =3D =7B > + TemporaryRamMigration > +=7D; > + > +E=46I=5FPEI=5FPPI=5FDESCRIPTOR mPrivateDispatchTable=5B=5D =3D =7B > + =7B > + (E=46I=5FPEI=5FPPI=5FDESCRIPTOR=5FPPI =7C E=46I=5FPEI=5FPPI=5FDESCRIP= TOR=5FTERMINATE=5FLIST), > + &gEfiTemporaryRamSupportPpiGuid, > + &mTemporaryRamSupportPpi > + =7D, > +=7D; > + > +/** > + Locates a section within a series of sections > + with the specified section type. > + > + The Instance parameter indicates which instance of the section > + type to return. (0 is first instance, 1 is second...) > + > + =40param=5Bin=5D Sections The sections to search > + =40param=5Bin=5D SizeOfSections Total size of all sections > + =40param=5Bin=5D SectionType The section type to locate > + =40param=5Bin=5D Instance The section instance number > + =40param=5Bout=5D =46oundSection The =46=46S section if found > + > + =40retval E=46I=5FSUCCESS The file and section was found > + =40retval E=46I=5FNOT=5F=46OUND The file and section was not found > + =40retval E=46I=5FVOLUME=5FCORRUPTED The firmware volume was corrupte= d > +**/ > +E=46I=5FSTATUS > +=46ind=46fsSectionInstance ( > + IN VOID *Sections, > + IN UINTN SizeOfSections, > + IN E=46I=5FSECTION=5FTYPE SectionType, > + IN UINTN Instance, > + OUT E=46I=5FCOMMON=5FSECTION=5FHEADER **=46oundSection > + ) > +=7B > + E=46I=5FPHYSICAL=5FADDRESS CurrentAddress; > + UINT32 Size; > + E=46I=5FPHYSICAL=5FADDRESS EndOfSections; > + E=46I=5FCOMMON=5FSECTION=5FHEADER *Section; > + E=46I=5FPHYSICAL=5FADDRESS EndOfSection; > + > + // > + // Loop through the =46=46S file sections within the PEI Core =46=46S= file > + // > + EndOfSection =3D (E=46I=5FPHYSICAL=5FADDRESS) (UINTN) Sections; > + EndOfSections =3D EndOfSection + SizeOfSections; > + for (;;) =7B > + if (EndOfSection =3D=3D EndOfSections) =7B > + break; > + =7D > + CurrentAddress =3D (EndOfSection + 3) & =7E(3ULL); > + if (CurrentAddress >=3D EndOfSections) =7B > + return E=46I=5FVOLUME=5FCORRUPTED; > + =7D > + > + Section =3D (E=46I=5FCOMMON=5FSECTION=5FHEADER*) (UINTN) CurrentAddre= ss; > + > + Size =3D SECTION=5FSIZE (Section); > + if (Size < sizeof (*Section)) =7B > + return E=46I=5FVOLUME=5FCORRUPTED; > + =7D > + > + EndOfSection =3D CurrentAddress + Size; > + if (EndOfSection > EndOfSections) =7B > + return E=46I=5FVOLUME=5FCORRUPTED; > + =7D > + > + // > + // Look for the requested section type > + // > + if (Section->Type =3D=3D SectionType) =7B > + if (Instance =3D=3D 0) =7B > + *=46oundSection =3D Section; > + return E=46I=5FSUCCESS; > + =7D else =7B > + Instance--; > + =7D > + =7D > + =7D > + > + return E=46I=5FNOT=5F=46OUND; > +=7D > + > +/** > + Locates a section within a series of sections > + with the specified section type. > + > + =40param=5Bin=5D Sections The sections to search > + =40param=5Bin=5D SizeOfSections Total size of all sections > + =40param=5Bin=5D SectionType The section type to locate > + =40param=5Bout=5D =46oundSection The =46=46S section if found > + > + =40retval E=46I=5FSUCCESS The file and section was found > + =40retval E=46I=5FNOT=5F=46OUND The file and section was not found > + =40retval E=46I=5FVOLUME=5FCORRUPTED The firmware volume was corrupte= d > +**/ > +E=46I=5FSTATUS > +=46ind=46fsSectionInSections ( > + IN VOID *Sections, > + IN UINTN SizeOfSections, > + IN E=46I=5FSECTION=5FTYPE SectionType, > + OUT E=46I=5FCOMMON=5FSECTION=5FHEADER **=46oundSection > + ) > +=7B > + return =46ind=46fsSectionInstance ( > + Sections, > + SizeOfSections, > + SectionType, > + 0, > + =46oundSection > + ); > +=7D > + > +/** > + Locates a =46=46S file with the specified file type and a section > + within that file with the specified section type. > + > + =40param=5Bin=5D =46v The firmware volume to search > + =40param=5Bin=5D =46ileType The file type to locate > + =40param=5Bin=5D SectionType The section type to locate > + =40param=5Bout=5D =46oundSection The =46=46S section if found > + > + =40retval E=46I=5FSUCCESS The file and section was found > + =40retval E=46I=5FNOT=5F=46OUND The file and section was not found > + =40retval E=46I=5FVOLUME=5FCORRUPTED The firmware volume was corrupte= d > +**/ > +E=46I=5FSTATUS > +=46ind=46fs=46ileAndSection ( > + IN E=46I=5F=46IRMWARE=5FVOLUME=5FHEADER *=46v, > + IN E=46I=5F=46V=5F=46ILETYPE =46ileType, > + IN E=46I=5FSECTION=5FTYPE SectionType, > + OUT E=46I=5FCOMMON=5FSECTION=5FHEADER **=46oundSection > + ) > +=7B > + E=46I=5FSTATUS Status; > + E=46I=5FPHYSICAL=5FADDRESS CurrentAddress; > + E=46I=5FPHYSICAL=5FADDRESS EndOf=46irmwareVolume; > + E=46I=5F=46=46S=5F=46ILE=5FHEADER *=46ile; > + UINT32 Size; > + E=46I=5FPHYSICAL=5FADDRESS EndOf=46ile; > + > + if (=46v->Signature =21=3D E=46I=5F=46VH=5FSIGNATURE) =7B > + DEBUG ((DEBUG=5FERROR, =22=46V at %p does not have =46V header signat= ure=5Cn=22, =46v)); > + return E=46I=5FVOLUME=5FCORRUPTED; > + =7D > + > + CurrentAddress =3D (E=46I=5FPHYSICAL=5FADDRESS) (UINTN) =46v; > + EndOf=46irmwareVolume =3D CurrentAddress + =46v->=46vLength; > + > + // > + // Loop through the =46=46S files in the Boot =46irmware Volume > + // > + for (EndOf=46ile =3D CurrentAddress + =46v->HeaderLength; ; ) =7B > + > + CurrentAddress =3D (EndOf=46ile + 7) & =7E(7ULL); > + if (CurrentAddress > EndOf=46irmwareVolume) =7B > + return E=46I=5FVOLUME=5FCORRUPTED; > + =7D > + > + =46ile =3D (E=46I=5F=46=46S=5F=46ILE=5FHEADER*) (UINTN) CurrentAddres= s; > + Size =3D *(UINT32*) =46ile->Size & 0xffffff; > + if (Size < (sizeof (*=46ile) + sizeof (E=46I=5FCOMMON=5FSECTION=5FHEA= DER))) =7B > + return E=46I=5FVOLUME=5FCORRUPTED; > + =7D > + > + EndOf=46ile =3D CurrentAddress + Size; > + if (EndOf=46ile > EndOf=46irmwareVolume) =7B > + return E=46I=5FVOLUME=5FCORRUPTED; > + =7D > + > + // > + // Look for the request file type > + // > + if (=46ile->Type =21=3D =46ileType) =7B > + continue; > + =7D > + > + Status =3D =46ind=46fsSectionInSections ( > + (VOID*) (=46ile + 1), > + (UINTN) EndOf=46ile - (UINTN) (=46ile + 1), > + SectionType, > + =46oundSection > + ); > + if (=21E=46I=5FERROR (Status) > + =7C=7C (Status =3D=3D E=46I=5FVOLUME=5FCORRUPTED)) > + =7B > + return Status; > + =7D > + =7D > +=7D > + > +/** > + Locates the PEI Core entry point address > + > + =40param=5Bin=5D =46v The firmware volume to search > + =40param=5Bout=5D PeiCoreEntryPoint The entry point of the PEI Core i= mage > + > + =40retval E=46I=5FSUCCESS The file and section was found > + =40retval E=46I=5FNOT=5F=46OUND The file and section was not found > + =40retval E=46I=5FVOLUME=5FCORRUPTED The firmware volume was corrupte= d > +**/ > +E=46I=5FSTATUS > +=46indPeiCoreImageBaseIn=46v ( > + IN E=46I=5F=46IRMWARE=5FVOLUME=5FHEADER *=46v, > + OUT E=46I=5FPHYSICAL=5FADDRESS *PeiCoreImageBase > + ) > +=7B > + E=46I=5FSTATUS Status; > + E=46I=5FCOMMON=5FSECTION=5FHEADER *Section; > + > + Status =3D =46ind=46fs=46ileAndSection ( > + =46v, > + E=46I=5F=46V=5F=46ILETYPE=5FPEI=5FCORE, > + E=46I=5FSECTION=5FPE32, > + &Section > + ); > + if (E=46I=5FERROR (Status)) =7B > + Status =3D =46ind=46fs=46ileAndSection ( > + =46v, > + E=46I=5F=46V=5F=46ILETYPE=5FPEI=5FCORE, > + E=46I=5FSECTION=5FTE, > + &Section > + ); > + if (E=46I=5FERROR (Status)) =7B > + DEBUG ((DEBUG=5FERROR, =22Unable to find PEI Core image=5Cn=22)); > + return Status; > + =7D > + =7D > + > + *PeiCoreImageBase =3D (E=46I=5FPHYSICAL=5FADDRESS)(UINTN)(Section + 1= ); > + return E=46I=5FSUCCESS; > +=7D > + > +/** > + =46ind and return Pei Core entry point. > + > + It also find SEC and PEI Core file debug information. It will report = them if > + remote debug is enabled. > +**/ > +VOID > +=46indAndReportEntryPoints ( > + IN E=46I=5F=46IRMWARE=5FVOLUME=5FHEADER **Boot=46irmwareVolumePtr, > + OUT E=46I=5FPEI=5FCORE=5FENTRY=5FPOINT *PeiCoreEntryPoint > + ) > +=7B > + E=46I=5FSTATUS Status; > + E=46I=5FPHYSICAL=5FADDRESS PeiCoreImageBase =3D 0; > + PE=5FCO=46=46=5FLOADER=5FIMAGE=5FCONTEXT ImageContext; > + > + Status =3D =46indPeiCoreImageBaseIn=46v (*Boot=46irmwareVolumePtr, &P= eiCoreImageBase); > + ASSERT (Status =3D=3D E=46I=5FSUCCESS); > + > + ZeroMem ((VOID *) &ImageContext, sizeof (PE=5FCO=46=46=5FLOADER=5FIMA= GE=5FCONTEXT)); > + > + // > + // Report PEI Core debug information when remote debug is enabled > + // > + ImageContext.ImageAddress =3D (E=46I=5FPHYSICAL=5FADDRESS)(UINTN)PeiC= oreImageBase; > + ImageContext.PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID*) (UINTN= ) ImageContext.ImageAddress); > + PeCoffLoaderRelocateImageExtraAction (&ImageContext); > + > + // > + // =46ind PEI Core entry point > + // > + Status =3D PeCoffLoaderGetEntryPoint ((VOID *) (UINTN) PeiCoreImageBa= se, (VOID**) PeiCoreEntryPoint); > + if (E=46I=5FERROR (Status)) =7B > + *PeiCoreEntryPoint =3D 0; > + =7D > + > + return; > +=7D > + > +/** > + =46ind the peicore entry point and jump to the entry point to execute= . > + > + =40param=5Bin=5D Context The first input parameter of InitializeDebug= Agent(). > +**/ > +VOID > +E=46IAPI > +SecStartupPhase2 ( > + IN VOID *Context > + ) > +=7B > + E=46I=5FSEC=5FPEI=5FHAND=5FO=46=46 *SecCoreData; > + E=46I=5F=46IRMWARE=5FVOLUME=5FHEADER *Boot=46v; > + E=46I=5FPEI=5FCORE=5FENTRY=5FPOINT PeiCoreEntryPoint; > + > + SecCoreData =3D (E=46I=5FSEC=5FPEI=5FHAND=5FO=46=46 *) Context; > + > + // > + // =46ind PEI Core entry point. It will report SEC and Pei Core debug= information if remote debug > + // is enabled. > + // > + Boot=46v =3D (E=46I=5F=46IRMWARE=5FVOLUME=5FHEADER *)SecCoreData->Boo= t=46irmwareVolumeBase; > + =46indAndReportEntryPoints (&Boot=46v, &PeiCoreEntryPoint); > + SecCoreData->Boot=46irmwareVolumeBase =3D Boot=46v; > + SecCoreData->Boot=46irmwareVolumeSize =3D (UINTN) Boot=46v->=46vLengt= h; > + > + DEBUG ((DEBUG=5FIN=46O, =22=46ind Pei EntryPoint=3D%p=5Cn=22, PeiCore= EntryPoint)); > + > + // > + // Transfer the control to the PEI core > + // > + DEBUG ((DEBUG=5FIN=46O, =22SecStartupPhase2 %p=5Cn=22, PeiCoreEntryPo= int)); > + > + (*PeiCoreEntryPoint) (SecCoreData, (E=46I=5FPEI=5FPPI=5FDESCRIPTOR *)= &mPrivateDispatchTable); > + > + // > + // If we get here then the PEI Core returned, which is not recoverabl= e. > + // > + ASSERT (=46ALSE); > + CpuDeadLoop (); > +=7D > +/** > + Entry point to the C language phase of SEC. initialize some temporary= memory and set up the stack, > + the control is transferred to this function. > + > + =40param=5Bin=5D Boot=46v The pointer to the PEI =46V in memory. > + =40param=5Bin=5D TopOfCurrentStack Top of Current Stack. > +**/ > +VOID > +E=46IAPI > +SecCoreStartupWithStack ( > + IN E=46I=5F=46IRMWARE=5FVOLUME=5FHEADER *Boot=46v, > + IN VOID *TopOfCurrentStack > + ) > +=7B > + E=46I=5FSEC=5FPEI=5FHAND=5FO=46=46 SecCoreData; > + E=46I=5F=46IRMWARE=5FVOLUME=5FHEADER *BootPei=46v =3D (E=46I=5F=46IRM= WARE=5FVOLUME=5FHEADER*) Boot=46v; > + > + DEBUG ((DEBUG=5FIN=46O, =22Entering C environment=5Cn=22)); > + > + ProcessLibraryConstructorList (NULL, NULL); > + > + DEBUG ((DEBUG=5FIN=46O, > + =22SecCoreStartupWithStack (0x%lx, 0x%lx)=5Cn=22, > + (UINTN)Boot=46v, > + (UINTN)TopOfCurrentStack > + )); > + DEBUG ((DEBUG=5FIN=46O, > + =22(0x%lx, 0x%lx)=5Cn=22, > + (UINTN) (PcdGet64 (PcdSecPeiTempRamBase)), > + (UINTN) (PcdGet32 (PcdSecPeiTempRamSize)) > + )); > + > + // =7C-------------=7C <-- TopOfCurrentStack > + // =7C Stack =7C 32k > + // =7C-------------=7C > + // =7C Heap =7C 32k > + // =7C-------------=7C <-- SecCoreData.TemporaryRamBase > + // > + > + ASSERT ((UINTN) (PcdGet64 (PcdSecPeiTempRamBase) + > + PcdGet32 (PcdSecPeiTempRamSize)) =3D=3D > + (UINTN) TopOfCurrentStack); > + > + // > + // Initialize SEC hand-off state > + // > + SecCoreData.DataSize =3D sizeof (E=46I=5FSEC=5FPEI=5FHAND=5FO=46=46);= > + > + SecCoreData.TemporaryRamSize =3D (UINTN) PcdGet32 (PcdSecPeiTempRamSi= ze); > + SecCoreData.TemporaryRamBase =3D (VOID *) PcdGet64 (PcdSecPeiTempRamB= ase); > + > + SecCoreData.PeiTemporaryRamBase =3D SecCoreData.TemporaryRamBase; > + SecCoreData.PeiTemporaryRamSize =3D SecCoreData.TemporaryRamSize >> 1= ; > + > + SecCoreData.StackBase =3D (UINT8 *)SecCoreData.TemporaryRamBase + Sec= CoreData.PeiTemporaryRamSize; > + SecCoreData.StackSize =3D SecCoreData.TemporaryRamSize >> 1; > + > + SecCoreData.Boot=46irmwareVolumeBase =3D BootPei=46v; > + SecCoreData.Boot=46irmwareVolumeSize =3D (UINTN) BootPei=46v->=46vLen= gth; > + > + DEBUG ((DEBUG=5FIN=46O, > + =22&SecCoreData.Boot=46irmwareVolumeBase=3D%lx SecCoreData.Boot=46irm= wareVolumeBase=3D%lx=5Cn=22, > + (UINT64)&(SecCoreData.Boot=46irmwareVolumeBase), > + (UINT64) (SecCoreData.Boot=46irmwareVolumeBase))); > + DEBUG ((DEBUG=5FIN=46O, > + =22&SecCoreData.Boot=46irmwareVolumeSize=3D%lx SecCoreData.Boot=46irm= wareVolumeSize=3D%lx=5Cn=22, > + (UINT64)&(SecCoreData.Boot=46irmwareVolumeSize), > + (UINT64) (SecCoreData.Boot=46irmwareVolumeSize))); > + > + // > + // Initialize Debug Agent to support source level debug in SEC/PEI ph= ases before memory ready. > + // > + InitializeDebugAgent (DEBUG=5FAGENT=5FINIT=5FPREMEM=5FSEC, NULL, NULL= ); > + SecStartupPhase2 (&SecCoreData); > +=7D > + > +/** > + temporary memory to permanent memory and do stack switching. > + > + =40param=5Bin=5D PeiServices Pointer to the PEI Services Table. > + =40param=5Bin=5D TemporaryMemoryBase Temporary Memory Base address. > + =40param=5Bin=5D PermanentMemoryBase Permanent Memory Base address. > + =40param=5Bin=5D CopySize The size of memory that needs to be migrate= d. > + > + =40retval E=46I=5FSUCCESS Migration successful. > +**/ > +E=46I=5FSTATUS > +E=46IAPI > +TemporaryRamMigration ( > + IN CONST E=46I=5FPEI=5FSERVICES **PeiServices, > + IN E=46I=5FPHYSICAL=5FADDRESS TemporaryMemoryBase, > + IN E=46I=5FPHYSICAL=5FADDRESS PermanentMemoryBase, > + IN UINTN CopySize > + ) > +=7B > + VOID *OldHeap; > + VOID *NewHeap; > + VOID *OldStack; > + VOID *NewStack; > + BASE=5FLIBRARY=5FJUMP=5FBU=46=46ER JumpBuffer; > + > + DEBUG ((DEBUG=5FIN=46O, > + =22TemporaryRamMigration (0x%Lx, 0x%Lx, 0x%Lx)=5Cn=22, > + TemporaryMemoryBase, > + PermanentMemoryBase, > + (UINT64)CopySize > + )); > + > + OldHeap =3D (VOID*) (UINTN)TemporaryMemoryBase; > + NewHeap =3D (VOID*) ((UINTN)PermanentMemoryBase + (CopySize >> 1)); > + > + OldStack =3D (VOID*) ((UINTN)TemporaryMemoryBase + (CopySize >> 1)); > + NewStack =3D (VOID*) (UINTN)PermanentMemoryBase; > + > + // > + // Migrate Heap > + // > + CopyMem (NewHeap, OldHeap, CopySize >> 1); > + > + // > + // Migrate Stack > + // > + CopyMem (NewStack, OldStack, CopySize >> 1); > + > + // Use SetJump ()/LongJump () to switch to a new stack. > + // > + if (SetJump (&JumpBuffer) =3D=3D 0) =7B > + JumpBuffer.SP =3D JumpBuffer.SP - (UINTN)OldStack + (UINTN)NewStack ;= > + LongJump (&JumpBuffer, (UINTN)-1); > + =7D > + > + return E=46I=5FSUCCESS; > +=7D > diff --git a/Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf b/Platf= orm/Loongson/LoongArchQemuPkg/Sec/SecMain.inf > new file mode 100644 > index 0000000000..c0d5439d53 > --- /dev/null > +++ b/Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf > =40=40 -0,0 +1,51 =40=40 > +=23=23 =40file > +=23 SEC Driver > +=23 > +=23 Copyright (c) 2022 Loongson Technology Corporation Limited. All ri= ghts reserved.
> +=23 > +=23 SPDX-License-Identifier: BSD-2-Clause-Patent > +=23 > +=23=23 > + > +=5BDefines=5D > + IN=46=5FVERSION =3D 0x00010005 > + BASE=5FNAME =3D SecMain > + =46ILE=5FGUID =3D 57d02d4f-5a5d-4bfa-b7d6-ba0a4d2c72ce > + MODULE=5FTYPE =3D SEC > + VERSION=5FSTRING =3D 1.0 > + > +=23 > +=23 VALID=5FARCHITECTURES =3D LOONGARCH64 > +=23 > + > +=5BSources=5D > + LoongArch64/Start.S > + SecMain.c > + > +=5BPackages=5D > + Platform/Loongson/LoongArchQemuPkg/Loongson.dec > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + > +=5BLibraryClasses=5D > + BaseLib > + DebugLib > + BaseMemoryLib > + PcdLib > + DebugAgentLib > + IoLib > + PeCoffLib > + PeCoffGetEntryPointLib > + PeCoffExtraActionLib > + > +=5BPpis=5D > + gEfiTemporaryRamSupportPpiGuid =23 PPI ALWAYS=5FPRODUCED > + > +=5B=46ixedPcd=5D > + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase > + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize > + > + gLoongArchQemuPkgTokenSpaceGuid.Pcd=46lashSec=46vBase > + gLoongArchQemuPkgTokenSpaceGuid.Pcd=46lashSec=46vSize > + gLoongArchQemuPkgTokenSpaceGuid.Pcd=46lashPei=46vBase > + gLoongArchQemuPkgTokenSpaceGuid.Pcd=46lashPei=46vSize > -- > 2.31.1 --636e1768_c7e4c42_1e57b Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Reviewed-by: Chao Li  <lichao=40loongson.cn>


Thanks,
Chao
--------

On 11=E6=9C=88 11 2= 022, at 5:12 =E4=B8=8B=E5=8D=88, xianglai li <lixianglai=40loongson.cn= > wrote:
Add SEC Code And Readme.md for Loo= ngArchQemu



RE=46: https://bugzilla.tianocore.org/sh= ow=5Fbug.cgi=3Fid=3D4054



Cc: Bibo Mao <maobibo=40= loongson.cn>

Cc: Chao Li <lichao=40loongson.cn>
Cc: Leif Lindholm <quic=5Fllindhol=40quicinc.com>
=
Cc: Liming Gao <gaoliming=40byosoft.com.cn>

= Cc: Michael D Kinney <michael.d.kinney=40intel.com>

S= igned-off-by: xianglai li <lixianglai=40loongson.cn>

= Signed-off-by: xianglai li <lixianglai=40loongson.cn>

---

.../Include/LoongArchQemuPlatform.h =7C 2 +-

=
.../Loongson/LoongArchQemuPkg/Loongson.dec =7C 38 ++

.= ../Loongson/LoongArchQemuPkg/Loongson.dsc =7C 122 +++++

...= /Loongson/LoongArchQemuPkg/Loongson.fdf =7C 53 ++

.../Loong= ArchQemuPkg/Loongson.fdf.inc =7C 21 +

.../LoongArchQemuPkg/= Sec/LoongArch64/Start.S =7C 84 +++

.../Loongson/LoongArchQe= muPkg/Sec/SecMain.c =7C 494 ++++++++++++++++++

.../Loongson= /LoongArchQemuPkg/Sec/SecMain.inf =7C 51 ++

8 files changed= , 864 insertions(+), 1 deletion(-)

create mode 100644 Platf= orm/Loongson/LoongArchQemuPkg/Loongson.dec

create mode 1006= 44 Platform/Loongson/LoongArchQemuPkg/Loongson.dsc

create m= ode 100644 Platform/Loongson/LoongArchQemuPkg/Loongson.fdf

= create mode 100644 Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc
create mode 100644 Platform/Loongson/LoongArchQemuPkg/Sec/Loo= ngArch64/Start.S

create mode 100644 Platform/Loongson/Loong= ArchQemuPkg/Sec/SecMain.c

create mode 100644 Platform/Loong= son/LoongArchQemuPkg/Sec/SecMain.inf



diff --git a/P= latform/Loongson/LoongArchQemuPkg/Include/LoongArchQemuPlatform.h b/Platf= orm/Loongson/LoongArchQemuPkg/Include/LoongArchQemuPlatform.h

index e942e6a994..d003b9013d 100644

--- a/Platform/Loong= son/LoongArchQemuPkg/Include/LoongArchQemuPlatform.h

+++ b/= Platform/Loongson/LoongArchQemuPkg/Include/LoongArchQemuPlatform.h
<= br>
=40=40 -92,4 +92,4 =40=40

=23define UART=5FBASE=5FA= DDRESS (0x1fe001e0)

=23define UART=5FBPS (115200)

=
=23define UART=5FWAIT=5FTIMOUT (1000000)

-=23endif
+=23endif // LOONGARCH=5FQEMU=5FPLAT=46ORM=5FH=5F

diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec b/Platform= /Loongson/LoongArchQemuPkg/Loongson.dec

new file mode 10064= 4

index 0000000000..61f600b20d

--- /dev/null<= /div>
+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec
=
=40=40 -0,0 +1,38 =40=40

+=23=23 =40file

=
+=23

+=23 Copyright (c) 2022 Loongson Technology Corpo= ration Limited. All rights reserved.<BR>

+=23
+=23 SPDX-License-Identifier: BSD-2-Clause-Patent

+=23=

+=23=23

+

+=5BDefines=5D
=
+ DEC=5FSPECI=46ICATION =3D 0x00010005

+ PACKAGE=5F= NAME =3D LoongArchQemuPkg

+ PACKAGE=5FGUID =3D b51d765a-41d= a-45fc-a537-de3ee785c0f6

+ PACKAGE=5FVERSION =3D 0.1
<= br>
+

+=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23

+=23

+=23 Include Section - list of Include Paths that are provided by this= package.

+=23 Comments are used for Keywords and Module Ty= pes.

+=23

+=23 Supported Module Types:
<= br>
+=23 BASE SEC PEI=5FCORE PEIM DXE=5FCORE DXE=5FDRIVER DXE=5FRUNTI= ME=5FDRIVER DXE=5FSMM=5FDRIVER

+=23 DXE=5FSAL=5FDRIVER UE=46= I=5FDRIVER UE=46I=5FAPPLICATION

+=23

+=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23

+=5BIncludes.common=5D

+ Include =23 R= oot include for the package

+

+=5BGuids=5D
+ gLoongArchQemuPkgTokenSpaceGuid =3D =7B 0x0e0383ce, 0x0151,= 0x4d01, =7B 0x80, 0x0e, 0x3f, 0xef, 0x8b, 0x27, 0x6d, 0x52 =7D =7D
=
+

+=23=23 In the Pcds=46ixedAtBuild and PcdsDynami= c areas, numbers start at 0x0.

+=5BPcds=46ixedAtBuild, Pcds= Dynamic=5D

+ gLoongArchQemuPkgTokenSpaceGuid.Pcd=46lashPei=46= vBase=7C0x0=7CUINT64=7C0x00000000

+ gLoongArchQemuPkgTokenS= paceGuid.Pcd=46lashPei=46vSize=7C0x0=7CUINT32=7C0x00000001

= + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase=7C0=7CUINT64=7C0x0= 000000b

+ gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamS= ize=7C0=7CUINT32=7C0x0000000c

+ gLoongArchQemuPkgTokenSpace= Guid.Pcd=46lashSec=46vBase=7C0x0=7CUINT64=7C0x0000000f

+ gL= oongArchQemuPkgTokenSpaceGuid.Pcd=46lashSec=46vSize=7C0x0=7CUINT32=7C0x00= 000010

diff --git a/Platform/Loongson/LoongArchQemuPkg/Loon= gson.dsc b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc

= new file mode 100644

index 0000000000..b506f70625

=
--- /dev/null

+++ b/Platform/Loongson/LoongArchQemuPkg= /Loongson.dsc

=40=40 -0,0 +1,122 =40=40

+=23=23= =40file

+=23

+=23 Copyright (c) 2022 Loongso= n Technology Corporation Limited. All rights reserved.<BR>
+=23

+=23 SPDX-License-Identifier: BSD-2-Clause-Paten= t

+=23

+=23=23

+

= +=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23

+=23

+=23 Defines Section = - statements that will be processed to create a Makefile.

+= =23

+=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23

+=5BDefines=5D

<= div>+ PLAT=46ORM=5FNAME =3D LoongArchQemu

+ PLAT=46ORMPKG=5F= NAME =3D LoongArchQemu

+ PLAT=46ORM=5FGUID =3D 7926ea52-b0d= c-4ee8-ac63-341eebd84ed4

+ PLAT=46ORM=5FVERSION =3D 0.1
+ DSC=5FSPECI=46ICATION =3D 0x00010005

+ OUTPUT=5F= DIRECTORY =3D Build/=24(PLAT=46ORM=5FNAME)

+ SUPPORTED=5FAR= CHITECTURES =3D LOONGARCH64

+ BUILD=5FTARGETS =3D DEBUG=7CR= ELEASE

+ SKUID=5FIDENTI=46IER =3D DE=46AULT

+= =46LASH=5FDE=46INITION =3D Platform/Loongson/LoongArchQemuPkg/Loongson.f= df

+ TTY=5FTERMINAL =3D =46ALSE

+

+=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23

+=23

+=23 Defines for default state= s. These can be changed on the command line.

+=23 -D =46LAG= =3DVALUE

+=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23

+=5BBuildOptions=5D

+ GCC:RELEASE=5F*=5F*=5FCC=5F=46LAGS =3D -DSPEEDUP

+
+ =23

+ =23 Disable deprecated APIs.

+ =23

+ GCC:*=5F*=5F*=5FCC=5F=46LAGS =3D -D DISABLE=5FNE= W=5FDEPRECATED=5FINTER=46ACES

+

+=5BBuildOpti= ons.LOONGARCH64.EDKII.SEC=5D

+ *=5F*=5F*=5FCC=5F=46LAGS =3D=

+

+=5BBuildOptions.common.EDKII.DXE=5FCORE,B= uildOptions.common.EDKII.DXE=5FDRIVER,BuildOptions.common.EDKII.UE=46I=5F= DRIVER,BuildOptions.common.EDKII.UE=46I=5FAPPLICATION=5D

+ = GCC:*=5F*=5F*=5FDLINK=5F=46LAGS =3D -z common-page-size=3D0x1000
+

+=5BBuildOptions.common.EDKII.DXE=5FRUNTIME=5FDRIVE= R=5D

+ GCC:*=5F*=5FLOONGARCH64=5FDLINK=5F=46LAGS =3D -z com= mon-page-size=3D0x10000

+

+=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23<= /div>
+=23

+=23 Library Class section - list of all= Library Classes needed by this Platform.

+=23

+=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23

+

+=21include MdePkg/MdeLi= bs.dsc.inc

+

+=5BLibraryClasses.common=5D
+ PcdLib =7C MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf<= /div>
+ PrintLib =7C MdePkg/Library/BasePrintLib/BasePrintLib.inf=

+ BaseMemoryLib =7C MdePkg/Library/BaseMemoryLib/BaseMemor= yLib.inf

+ BaseLib =7C MdePkg/Library/BaseLib/BaseLib.inf
+ PeCoffLib =7C MdePkg/Library/BasePeCoffLib/BasePeCoffLib.i= nf

+ PeCoffGetEntryPointLib =7C MdePkg/Library/BasePeCoffGe= tEntryPointLib/BasePeCoffGetEntryPointLib.inf

+ IoLib =7C M= dePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf

+ S= erialPortLib =7C Platform/Loongson/LoongArchQemuPkg/Library/SerialPortLib= /SerialPortLib.inf

+ DebugPrintErrorLevelLib =7C MdePkg/Lib= rary/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
+ PeCoffExtraActionLib =7C MdePkg/Library/BasePeCoffExtraActionLibN= ull/BasePeCoffExtraActionLibNull.inf

+ DebugAgentLib =7C Md= eModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf

= +

+=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23

+=23

+=23 P= cd Section - list of all EDK II PCD Entries defined by this Platform.
+=23

+=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23

+=5BPcds=46= ixedAtBuild=5D

+=23=23 BaseLib =23=23

+ gEfiM= dePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength =7C 1000000

+ gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength =7C 1000000
+ gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength =7C 1000= 000

+

+ gEfiMdePkgTokenSpaceGuid.PcdDebugPrin= tErrorLevel =7C 0x8000004=46

+ =23 DEBUG=5FINIT 0x00000001 = // Initialization

+ =23 DEBUG=5FWARN 0x00000002 // Warnings=

+ =23 DEBUG=5FLOAD 0x00000004 // Load events

+ =23 DEBUG=5F=46S 0x00000008 // E=46I =46ile system

+ =23= DEBUG=5FPOOL 0x00000010 // Alloc & =46ree (pool)

+ =23= DEBUG=5FPAGE 0x00000020 // Alloc & =46ree (page)

+ =23= DEBUG=5FIN=46O 0x00000040 // Informational debug messages

= + =23 DEBUG=5FDISPATCH 0x00000080 // PEI/DXE/SMM Dispatchers

+ =23 DEBUG=5FVARIABLE 0x00000100 // Variable

+ =23 DEBUG= =5FBM 0x00000400 // Boot Manager

+ =23 DEBUG=5FBLKIO 0x0000= 1000 // BlkIo Driver

+ =23 DEBUG=5FNET 0x00004000 // Networ= k Io Driver

+ =23 DEBUG=5FUNDI 0x00010000 // UNDI Driver
+ =23 DEBUG=5FLOAD=46ILE 0x00020000 // Load=46ile

+ =23 DEBUG=5FEVENT 0x00080000 // Event messages

+ =23 D= EBUG=5FGCD 0x00100000 // Global Coherency Database changes

= + =23 DEBUG=5FCACHE 0x00200000 // Memory range cachability changes
<= br>
+ =23 DEBUG=5FVERBOSE 0x00400000 // Detailed debug messages that = may

+ =23 DEBUG=5FERROR 0x80000000 // Error

+=

+=21if =24(TARGET) =3D=3D RELEASE

+ gEfiMdeP= kgTokenSpaceGuid.PcdDebugPropertyMask =7C 0x21

+=21else
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask =7C 0x2f
=
+=21endif

+ =23 DEBUG=5FASSERT=5FENABLED 0x01
+ =23 DEBUG=5FPRINT=5FENABLED 0x02

+ =23 DEBUG=5F= CODE=5FENABLED 0x04

+ =23 CLEAR=5FMEMORY=5FENABLED 0x08
+ =23 ASSERT=5FBREAKPOINT=5FENABLED 0x10

+ =23 A= SSERT=5FDEADLOOP=5FENABLED 0x20

+

+ gLoongArc= hQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase =7C 0x10000

+ g= LoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize =7C 0x10000

=
+

+=5BComponents=5D

+

+ =23=

+ =23 SEC Phase modules

+ =23

= + Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf

diff -= -git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf b/Platform/Loongso= n/LoongArchQemuPkg/Loongson.fdf

new file mode 100644
<= br>
index 0000000000..9685795cda

--- /dev/null
+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf

=40=40 -0,0 +1,53 =40=40

+=23=23 =40file

+=23=

+=23 Copyright (c) 2022 Loongson Technology Corporation Li= mited. All rights reserved.<BR>

+=23

+=23= SPDX-License-Identifier: BSD-2-Clause-Patent

+=23
+=23=23

+

+=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23

+=5BDefine= s=5D

+=21include Loongson.fdf.inc

+

=
+=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23

+=5B=46D.QEMU=5FE=46I=5D

+BaseAddre= ss =3D =24(=46D=5FBASE=5FADDRESS)

+Size =3D =24(=46D=5FSIZE= )

+ErasePolarity =3D 1

+BlockSize =3D =24(BLO= CK=5FSIZE)

+NumBlocks =3D =24(=46D=5FBLOCKS)

= +

+=24(SEC=46V=5FO=46=46SET)=7C=24(SEC=46V=5FSIZE)
+gLoongArchQemuPkgTokenSpaceGuid.Pcd=46lashSec=46vBase=7CgLoongArch= QemuPkgTokenSpaceGuid.Pcd=46lashSec=46vSize

+=46V =3D SEC=46= V

+

+=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23

+=5B=46V.SEC=46V=5D
+=46vNameGuid =3D 587d4265-5e71-41da-9c35-4258551f1e22
<= br>
+BlockSize =3D =24(BLOCK=5FSIZE)

+=46vAlignment =3D= 16

+ERASE=5FPOLARITY =3D 1

+MEMORY=5FMAPPED = =3D TRUE

+STICKY=5FWRITE =3D TRUE

+LOCK=5FCAP= =3D TRUE

+LOCK=5FSTATUS =3D TRUE

+WRITE=5FDI= SABLED=5FCAP =3D TRUE

+WRITE=5FENABLED=5FCAP =3D TRUE
=
+WRITE=5FSTATUS =3D TRUE

+WRITE=5FLOCK=5FCAP =3D T= RUE

+WRITE=5FLOCK=5FSTATUS =3D TRUE

+READ=5FD= ISABLED=5FCAP =3D TRUE

+READ=5FENABLED=5FCAP =3D TRUE
=
+READ=5FSTATUS =3D TRUE

+READ=5FLOCK=5FCAP =3D TRU= E

+READ=5FLOCK=5FSTATUS =3D TRUE

+

<= div>+IN=46 Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf

+

+=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23

+=5BRule.Common.SEC=5D

+ =46ILE SEC =3D =24(NAMED=5FGUID) =7B

+ TE TE Align =3D= Auto =24(IN=46=5FOUTPUT)/=24(MODULE=5FNAME).efi

+ UI STRIN= G =3D=22=24(MODULE=5FNAME)=22 Optional

+ =7D

= diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc b/Platfo= rm/Loongson/LoongArchQemuPkg/Loongson.fdf.inc

new file mode= 100644

index 0000000000..6f17909748

--- /dev= /null

+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf= .inc

=40=40 -0,0 +1,21 =40=40

+=23=23 =40file=

+=23

+=23 Copyright (c) 2022 Loongson Techno= logy Corporation Limited. All rights reserved.<BR>

+=23=

+=23 SPDX-License-Identifier: BSD-2-Clause-Patent
+=23

+=23=23

+

+DE=46INE = BLOCK=5FSIZE =3D 0x1000

+

+=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23

+=23 fd total

+DE=46INE =46D=5FBASE=5FADDRESS =3D 0x1c000= 000

+DE=46INE =46D=5FBLOCKS =3D 0x400

+DE=46I= NE =46D=5FSIZE =3D 0x400000

+

+=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23= =23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23=23

=
+=23flash code layout

+=23Set Sec base address and siz= e in flash

+DE=46INE SEC=46V=5FO=46=46SET =3D 0x00000000
+DE=46INE SEC=46V=5FSIZE =3D 0x00010000

diff --= git a/Platform/Loongson/LoongArchQemuPkg/Sec/LoongArch64/Start.S b/Platfo= rm/Loongson/LoongArchQemuPkg/Sec/LoongArch64/Start.S

new fi= le mode 100644

index 0000000000..5d7ce313c0

-= -- /dev/null

+++ b/Platform/Loongson/LoongArchQemuPkg/Sec/L= oongArch64/Start.S

=40=40 -0,0 +1,84 =40=40

+= =23----------------------------------------------------------------------= --------

+=23

+=23 Start for LoongArch
<= br>
+=23

+=23 Copyright (c) 2022 Loongson Technology Co= rporation Limited. All rights reserved.<BR>

+=23
+=23 SPDX-License-Identifier: BSD-2-Clause-Patent

+=23

+=23 =40par Glossary:

+=23 - CSR - CPU = Status Register

+=23 - EBASE - Exception Base Address
=
+=23------------------------------------------------------------= ------------------

+=23ifndef =5F=5FASSEMBLY=5F=5F
+=23define =5F=5FASSEMBLY=5F=5F

+=23endif

+

+=23include <Library/Cpu.h>

+
+ASM=5FGLOBAL ASM=5FP=46X(=5FModuleEntryPoint)

+A= SM=5FGLOBAL ASM=5FP=46X(DeadLoop)

+

+.text
+ASM=5FP=46X(=5FModuleEntryPoint):

+ /* configu= re reset ebase */

+ la.pcrel T0, DeadLoop

+ c= srwr T0, LOONGARCH=5FCSR=5FEBASE

+

+ /*disabl= e interrupt*/

+ li.d T0, (1 << 2)

+ csr= xchg ZERO, T0, LOONGARCH=5FCSR=5FCRMD

+

+ /* = read physical cpu number id */

+ csrrd T0, LOONGARCH=5FCSR=5F= CPUNUM

+ andi T0, T0, 0x3ff

+ li.d A0, BOOTCO= RE=5FID //0

+ bne T0, A0, slave=5Fmain

+
+call=5Fcentry:

+ /*call C function make sure par= ameter true*/

+ li.d A1, =46ixedPcdGet64(PcdSecPeiTempRamBa= se) + =46ixedPcdGet32(PcdSecPeiTempRamSize) =23 stack base

= + li.d A0, =46ixedPcdGet64(Pcd=46lashPei=46vBase) =23 PEI =46v base
=
+ move SP, A1

+ addi.d SP, SP, -0x8

= + bl SecCoreStartupWithStack

+

+slave=5Fmain:=

+ =23 clear mailbox

+ li.d T1, LOONGSON=5FCS= R=5FMAIL=5FBU=460

+ iocsrwr.d ZERO, T1

+
+ =23 enable IPI interrupt

+ li.d T0, (1 <<= 12)

+ csrxchg T0, T0, LOONGARCH=5FCSR=5FEC=46G

+

+ addi.d T0, ZERO, -1

+ li.d T1, LOONGSO= N=5FIOCSR=5FIPI=5FEN

+ iocsrwr.w T0, T1

+
+1:

+ =23 wait for wakeup

+ idle 0=

+ nop

+ iocsrrd.w T0, T1

+ beq= z T0, 1b

+

+ =23 read and clear ipi interrupt=

+ li.d T1, LOONGSON=5FIOCSR=5FIPI=5FSTATUS

+= iocsrrd.w T0, T1

+ li.d T1, LOONGSON=5FIOCSR=5FIPI=5FCLEAR=

+ iocsrwr.w T0, T1

+

+ =23 dis= able IPI interrupt

+ li.d T0, (1 << 12)

+ csrxchg ZERO, T0, LOONGARCH=5FCSR=5FEC=46G

+

+ =23 read mail buf and jump to specified entry

+ li.d T= 1, LOONGSON=5FCSR=5FMAIL=5FBU=460

+ iocsrrd.d T0, T1
<= br>
+ or RA, T0, ZERO

+ jirl ZERO, RA, 0x0

+

+.align 12

+ASM=5FP=46X(DeadLoop):
<= br>
+ b DeadLoop

diff --git a/Platform/Loongson/LoongAr= chQemuPkg/Sec/SecMain.c b/Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.= c

new file mode 100644

index 0000000000..3f19= 98c48c

--- /dev/null

+++ b/Platform/Loongson/= LoongArchQemuPkg/Sec/SecMain.c

=40=40 -0,0 +1,494 =40=40
+/** =40file

+ Main SEC phase code. Transitions= to PEI.

+

+ Copyright (c) 2022 Loongson Tech= nology Corporation Limited. All rights reserved.<BR>

= +

+ SPDX-License-Identifier: BSD-2-Clause-Patent

<= div>+

+**/

+

+=23include <Pi= Pei.h>

+

+=23include <Library/PeimEntry= Point.h>

+=23include <Library/BaseLib.h>

=
+=23include <Library/DebugLib.h>

+=23include <= ;Library/BaseMemoryLib.h>

+=23include <Library/PeiSer= vicesLib.h>

+=23include <Library/PcdLib.h>
+=23include <Library/DebugAgentLib.h>

+=23incl= ude <Library/IoLib.h>

+=23include <Library/PeCoffL= ib.h>

+=23include <Library/PeCoffGetEntryPointLib.h&g= t;

+=23include <Library/PeCoffExtraActionLib.h>
=
+=23include <Library/ExtractGuidedSectionLib.h>

<= div>+

+=23include <Ppi/TemporaryRamSupport.h>
+

+/**

+ temporary memory to permanent= memory and do stack switching.

+

+ =40param=5B= in=5D PeiServices Pointer to the PEI Services Table.

+ =40p= aram=5Bin=5D TemporaryMemoryBase Temporary Memory Base address.

=
+ =40param=5Bin=5D PermanentMemoryBase Permanent Memory Base address= .

+ =40param=5Bin=5D CopySize The size of memory that needs= to be migrated.

+

+ =40retval E=46I=5FSUCCES= S Migration successful.

+**/

+E=46I=5FSTATUS<= /div>
+E=46IAPI

+TemporaryRamMigration (

<= div>+ IN CONST E=46I=5FPEI=5FSERVICES **PeiServices,

+ IN E= =46I=5FPHYSICAL=5FADDRESS TemporaryMemoryBase,

+ IN E=46I=5F= PHYSICAL=5FADDRESS PermanentMemoryBase,

+ IN UINTN CopySize=

+ );

+

+E=46I=5FPEI=5FTEMPORAR= Y=5FRAM=5FSUPPORT=5FPPI mTemporaryRamSupportPpi =3D =7B

+ T= emporaryRamMigration

+=7D;

+

+E= =46I=5FPEI=5FPPI=5FDESCRIPTOR mPrivateDispatchTable=5B=5D =3D =7B
+ =7B

+ (E=46I=5FPEI=5FPPI=5FDESCRIPTOR=5FPPI =7C E=46= I=5FPEI=5FPPI=5FDESCRIPTOR=5FTERMINATE=5FLIST),

+ &gEfi= TemporaryRamSupportPpiGuid,

+ &mTemporaryRamSupportPpi<= /div>
+ =7D,

+=7D;

+

+/= **

+ Locates a section within a series of sections
+ with the specified section type.

+

+ = The Instance parameter indicates which instance of the section

<= div>+ type to return. (0 is first instance, 1 is second...)

+

+ =40param=5Bin=5D Sections The sections to search
=
+ =40param=5Bin=5D SizeOfSections Total size of all sections
+ =40param=5Bin=5D SectionType The section type to locate
+ =40param=5Bin=5D Instance The section instance number
+ =40param=5Bout=5D =46oundSection The =46=46S section if found
+

+ =40retval E=46I=5FSUCCESS The file and sect= ion was found

+ =40retval E=46I=5FNOT=5F=46OUND The file an= d section was not found

+ =40retval E=46I=5FVOLUME=5FCORRUP= TED The firmware volume was corrupted

+**/

+E= =46I=5FSTATUS

+=46ind=46fsSectionInstance (

+= IN VOID *Sections,

+ IN UINTN SizeOfSections,

+ IN E=46I=5FSECTION=5FTYPE SectionType,

+ IN UINTN Insta= nce,

+ OUT E=46I=5FCOMMON=5FSECTION=5FHEADER **=46oundSecti= on

+ )

+=7B

+ E=46I=5FPHYSICAL=5F= ADDRESS CurrentAddress;

+ UINT32 Size;

+ E=46= I=5FPHYSICAL=5FADDRESS EndOfSections;

+ E=46I=5FCOMMON=5FSE= CTION=5FHEADER *Section;

+ E=46I=5FPHYSICAL=5FADDRESS EndOf= Section;

+

+ //

+ // Loop throu= gh the =46=46S file sections within the PEI Core =46=46S file

+ //

+ EndOfSection =3D (E=46I=5FPHYSICAL=5FADDRESS) (UI= NTN) Sections;

+ EndOfSections =3D EndOfSection + SizeOfSec= tions;

+ for (;;) =7B

+ if (EndOfSection =3D=3D= EndOfSections) =7B

+ break;

+ =7D

<= div>+ CurrentAddress =3D (EndOfSection + 3) & =7E(3ULL);

+ if (CurrentAddress >=3D EndOfSections) =7B
+ return = E=46I=5FVOLUME=5FCORRUPTED;

+ =7D

+

=
+ Section =3D (E=46I=5FCOMMON=5FSECTION=5FHEADER*) (UINTN) CurrentAd= dress;

+

+ Size =3D SECTION=5FSIZE (Section);=

+ if (Size < sizeof (*Section)) =7B

+ ret= urn E=46I=5FVOLUME=5FCORRUPTED;

+ =7D

+
=
+ EndOfSection =3D CurrentAddress + Size;

+ if (En= dOfSection > EndOfSections) =7B

+ return E=46I=5FVOLUME=5F= CORRUPTED;

+ =7D

+

+ //
+ // Look for the requested section type

+ //
<= br>
+ if (Section->Type =3D=3D SectionType) =7B

+ if= (Instance =3D=3D 0) =7B

+ *=46oundSection =3D Section;
+ return E=46I=5FSUCCESS;

+ =7D else =7B
+ Instance--;

+ =7D

+ =7D

+ =7D

+

+ return E=46I=5FNOT=5F=46OUND;
+=7D

+

+/**

+ Locate= s a section within a series of sections

+ with the specifie= d section type.

+

+ =40param=5Bin=5D Sections= The sections to search

+ =40param=5Bin=5D SizeOfSections T= otal size of all sections

+ =40param=5Bin=5D SectionType Th= e section type to locate

+ =40param=5Bout=5D =46oundSection= The =46=46S section if found

+

+ =40retval E= =46I=5FSUCCESS The file and section was found

+ =40retval E= =46I=5FNOT=5F=46OUND The file and section was not found

+ =40= retval E=46I=5FVOLUME=5FCORRUPTED The firmware volume was corrupted
=
+**/

+E=46I=5FSTATUS

+=46ind=46fsSec= tionInSections (

+ IN VOID *Sections,

+ IN UI= NTN SizeOfSections,

+ IN E=46I=5FSECTION=5FTYPE SectionType= ,

+ OUT E=46I=5FCOMMON=5FSECTION=5FHEADER **=46oundSection<= /div>
+ )

+=7B

+ return =46ind=46fsSe= ctionInstance (

+ Sections,

+ SizeOfSections,=

+ SectionType,

+ 0,

+ =46oundS= ection

+ );

+=7D

+

+/**

+ Locates a =46=46S file with the specified file typ= e and a section

+ within that file with the specified secti= on type.

+

+ =40param=5Bin=5D =46v The firmwa= re volume to search

+ =40param=5Bin=5D =46ileType The file = type to locate

+ =40param=5Bin=5D SectionType The section t= ype to locate

+ =40param=5Bout=5D =46oundSection The =46=46= S section if found

+

+ =40retval E=46I=5FSUCC= ESS The file and section was found

+ =40retval E=46I=5FNOT=5F= =46OUND The file and section was not found

+ =40retval E=46= I=5FVOLUME=5FCORRUPTED The firmware volume was corrupted

+*= */

+E=46I=5FSTATUS

+=46ind=46fs=46ileAndSecti= on (

+ IN E=46I=5F=46IRMWARE=5FVOLUME=5FHEADER *=46v,
=
+ IN E=46I=5F=46V=5F=46ILETYPE =46ileType,

+ IN E=46= I=5FSECTION=5FTYPE SectionType,

+ OUT E=46I=5FCOMMON=5FSECT= ION=5FHEADER **=46oundSection

+ )

+=7B
<= br>
+ E=46I=5FSTATUS Status;

+ E=46I=5FPHYSICAL=5FADDRE= SS CurrentAddress;

+ E=46I=5FPHYSICAL=5FADDRESS EndOf=46irm= wareVolume;

+ E=46I=5F=46=46S=5F=46ILE=5FHEADER *=46ile;
+ UINT32 Size;

+ E=46I=5FPHYSICAL=5FADDRESS End= Of=46ile;

+

+ if (=46v->Signature =21=3D E= =46I=5F=46VH=5FSIGNATURE) =7B

+ DEBUG ((DEBUG=5FERROR, =22=46= V at %p does not have =46V header signature=5Cn=22, =46v));

+ return E=46I=5FVOLUME=5FCORRUPTED;

+ =7D

+=

+ CurrentAddress =3D (E=46I=5FPHYSICAL=5FADDRESS) (UINTN) = =46v;

+ EndOf=46irmwareVolume =3D CurrentAddress + =46v->= ;=46vLength;

+

+ //

+ // Loop t= hrough the =46=46S files in the Boot =46irmware Volume

+ //=

+ for (EndOf=46ile =3D CurrentAddress + =46v->HeaderLen= gth; ; ) =7B

+

+ CurrentAddress =3D (EndOf=46= ile + 7) & =7E(7ULL);

+ if (CurrentAddress > EndOf=46= irmwareVolume) =7B

+ return E=46I=5FVOLUME=5FCORRUPTED;
+ =7D

+

+ =46ile =3D (E=46I=5F=46=46= S=5F=46ILE=5FHEADER*) (UINTN) CurrentAddress;

+ Size =3D *(= UINT32*) =46ile->Size & 0xffffff;

+ if (Size < (s= izeof (*=46ile) + sizeof (E=46I=5FCOMMON=5FSECTION=5FHEADER))) =7B
<= br>
+ return E=46I=5FVOLUME=5FCORRUPTED;

+ =7D
+

+ EndOf=46ile =3D CurrentAddress + Size;

<= div>+ if (EndOf=46ile > EndOf=46irmwareVolume) =7B

+ ret= urn E=46I=5FVOLUME=5FCORRUPTED;

+ =7D

+
=
+ //

+ // Look for the request file type

=
+ //

+ if (=46ile->Type =21=3D =46ileType) =7B
+ continue;

+ =7D

+

+= Status =3D =46ind=46fsSectionInSections (

+ (VOID*) (=46il= e + 1),

+ (UINTN) EndOf=46ile - (UINTN) (=46ile + 1),
=
+ SectionType,

+ =46oundSection

+ );=

+ if (=21E=46I=5FERROR (Status)

+ =7C=7C (St= atus =3D=3D E=46I=5FVOLUME=5FCORRUPTED))

+ =7B

+ return Status;

+ =7D

+ =7D

= +=7D

+

+/**

+ Locates the PEI C= ore entry point address

+

+ =40param=5Bin=5D = =46v The firmware volume to search

+ =40param=5Bout=5D PeiC= oreEntryPoint The entry point of the PEI Core image

+
=
+ =40retval E=46I=5FSUCCESS The file and section was found
=
+ =40retval E=46I=5FNOT=5F=46OUND The file and section was not f= ound

+ =40retval E=46I=5FVOLUME=5FCORRUPTED The firmware vo= lume was corrupted

+**/

+E=46I=5FSTATUS
=
+=46indPeiCoreImageBaseIn=46v (

+ IN E=46I=5F=46IR= MWARE=5FVOLUME=5FHEADER *=46v,

+ OUT E=46I=5FPHYSICAL=5FADD= RESS *PeiCoreImageBase

+ )

+=7B

+ E=46I=5FSTATUS Status;

+ E=46I=5FCOMMON=5FSECTION=5FHEAD= ER *Section;

+

+ Status =3D =46ind=46fs=46ile= AndSection (

+ =46v,

+ E=46I=5F=46V=5F=46ILET= YPE=5FPEI=5FCORE,

+ E=46I=5FSECTION=5FPE32,

+= &Section

+ );

+ if (E=46I=5FERROR (Statu= s)) =7B

+ Status =3D =46ind=46fs=46ileAndSection (
+ =46v,

+ E=46I=5F=46V=5F=46ILETYPE=5FPEI=5FCORE,
+ E=46I=5FSECTION=5FTE,

+ &Section

=
+ );

+ if (E=46I=5FERROR (Status)) =7B

+= DEBUG ((DEBUG=5FERROR, =22Unable to find PEI Core image=5Cn=22));
<= br>
+ return Status;

+ =7D

+ =7D
+

+ *PeiCoreImageBase =3D (E=46I=5FPHYSICAL=5FADDRESS= )(UINTN)(Section + 1);

+ return E=46I=5FSUCCESS;

<= div>+=7D

+

+/**

+ =46ind and re= turn Pei Core entry point.

+

+ It also find S= EC and PEI Core file debug information. It will report them if

<= div>+ remote debug is enabled.
+**/

+VOID
+=46indAndReportEntryPoints (

+ IN E=46I=5F=46IR= MWARE=5FVOLUME=5FHEADER **Boot=46irmwareVolumePtr,

+ OUT E=46= I=5FPEI=5FCORE=5FENTRY=5FPOINT *PeiCoreEntryPoint

+ )
=
+=7B

+ E=46I=5FSTATUS Status;

+ E=46= I=5FPHYSICAL=5FADDRESS PeiCoreImageBase =3D 0;

+ PE=5FCO=46= =46=5FLOADER=5FIMAGE=5FCONTEXT ImageContext;

+

+ Status =3D =46indPeiCoreImageBaseIn=46v (*Boot=46irmwareVolumePtr, &a= mp;PeiCoreImageBase);

+ ASSERT (Status =3D=3D E=46I=5FSUCCE= SS);

+

+ ZeroMem ((VOID *) &ImageContext,= sizeof (PE=5FCO=46=46=5FLOADER=5FIMAGE=5FCONTEXT));

+
+ //

+ // Report PEI Core debug information when = remote debug is enabled

+ //

+ ImageContext.I= mageAddress =3D (E=46I=5FPHYSICAL=5FADDRESS)(UINTN)PeiCoreImageBase;
+ ImageContext.PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID*= ) (UINTN) ImageContext.ImageAddress);

+ PeCoffLoaderRelocat= eImageExtraAction (&ImageContext);

+

+ //=

+ // =46ind PEI Core entry point

+ //
<= br>
+ Status =3D PeCoffLoaderGetEntryPoint ((VOID *) (UINTN) PeiCoreI= mageBase, (VOID**) PeiCoreEntryPoint);

+ if (E=46I=5FERROR = (Status)) =7B

+ *PeiCoreEntryPoint =3D 0;

+ =7D=

+

+ return;

+=7D

+

+/**

+ =46ind the peicore entry point and = jump to the entry point to execute.

+

+ =40pa= ram=5Bin=5D Context The first input parameter of InitializeDebugAgent().<= /div>
+**/

+VOID

+E=46IAPI

<= div>+SecStartupPhase2 (

+ IN VOID *Context

+ = )

+=7B

+ E=46I=5FSEC=5FPEI=5FHAND=5FO=46=46 *= SecCoreData;

+ E=46I=5F=46IRMWARE=5FVOLUME=5FHEADER *Boot=46= v;

+ E=46I=5FPEI=5FCORE=5FENTRY=5FPOINT PeiCoreEntryPoint;<= /div>
+

+ SecCoreData =3D (E=46I=5FSEC=5FPEI=5FHAND= =5FO=46=46 *) Context;

+

+ //

+= // =46ind PEI Core entry point. It will report SEC and Pei Core debug in= formation if remote debug

+ // is enabled.

+ = //

+ Boot=46v =3D (E=46I=5F=46IRMWARE=5FVOLUME=5FHEADER *)S= ecCoreData->Boot=46irmwareVolumeBase;

+ =46indAndReportE= ntryPoints (&Boot=46v, &PeiCoreEntryPoint);

+ SecCo= reData->Boot=46irmwareVolumeBase =3D Boot=46v;

+ SecCore= Data->Boot=46irmwareVolumeSize =3D (UINTN) Boot=46v->=46vLength;
+

+ DEBUG ((DEBUG=5FIN=46O, =22=46ind Pei Entry= Point=3D%p=5Cn=22, PeiCoreEntryPoint));

+

+ /= /

+ // Transfer the control to the PEI core

+= //

+ DEBUG ((DEBUG=5FIN=46O, =22SecStartupPhase2 %p=5Cn=22= , PeiCoreEntryPoint));

+

+ (*PeiCoreEntryPoin= t) (SecCoreData, (E=46I=5FPEI=5FPPI=5FDESCRIPTOR *)&mPrivateDispatchT= able);

+

+ //

+ // If we get he= re then the PEI Core returned, which is not recoverable.

+ = //

+ ASSERT (=46ALSE);

+ CpuDeadLoop ();
+=7D

+/**

+ Entry point to the C la= nguage phase of SEC. initialize some temporary memory and set up the stac= k,

+ the control is transferred to this function.

=
+

+ =40param=5Bin=5D Boot=46v The pointer to the PEI =46= V in memory.

+ =40param=5Bin=5D TopOfCurrentStack Top of Cu= rrent Stack.

+**/

+VOID

+E=46IA= PI

+SecCoreStartupWithStack (

+ IN E=46I=5F=46= IRMWARE=5FVOLUME=5FHEADER *Boot=46v,

+ IN VOID *TopOfCurren= tStack

+ )

+=7B

+ E=46I=5FSEC=5F= PEI=5FHAND=5FO=46=46 SecCoreData;

+ E=46I=5F=46IRMWARE=5FVO= LUME=5FHEADER *BootPei=46v =3D (E=46I=5F=46IRMWARE=5FVOLUME=5FHEADER*) Bo= ot=46v;

+

+ DEBUG ((DEBUG=5FIN=46O, =22Enteri= ng C environment=5Cn=22));

+

+ ProcessLibrary= ConstructorList (NULL, NULL);

+

+ DEBUG ((DEB= UG=5FIN=46O,

+ =22SecCoreStartupWithStack (0x%lx, 0x%lx)=5C= n=22,

+ (UINTN)Boot=46v,

+ (UINTN)TopOfCurren= tStack

+ ));

+ DEBUG ((DEBUG=5FIN=46O,
<= br>
+ =22(0x%lx, 0x%lx)=5Cn=22,

+ (UINTN) (PcdGet64 (Pc= dSecPeiTempRamBase)),

+ (UINTN) (PcdGet32 (PcdSecPeiTempRam= Size))

+ ));

+

+ // =7C--------= -----=7C <-- TopOfCurrentStack

+ // =7C Stack =7C 32k
+ // =7C-------------=7C

+ // =7C Heap =7C 32k<= /div>
+ // =7C-------------=7C <-- SecCoreData.TemporaryRamBas= e

+ //

+

+ ASSERT ((UINTN) (Pcd= Get64 (PcdSecPeiTempRamBase) +

+ PcdGet32 (PcdSecPeiTempRam= Size)) =3D=3D

+ (UINTN) TopOfCurrentStack);

+=

+ //

+ // Initialize SEC hand-off state
+ //

+ SecCoreData.DataSize =3D sizeof (E=46I=5FS= EC=5FPEI=5FHAND=5FO=46=46);

+

+ SecCoreData.T= emporaryRamSize =3D (UINTN) PcdGet32 (PcdSecPeiTempRamSize);

+ SecCoreData.TemporaryRamBase =3D (VOID *) PcdGet64 (PcdSecPeiTempRamB= ase);

+

+ SecCoreData.PeiTemporaryRamBase =3D= SecCoreData.TemporaryRamBase;

+ SecCoreData.PeiTemporaryRa= mSize =3D SecCoreData.TemporaryRamSize >> 1;

+
<= br>
+ SecCoreData.StackBase =3D (UINT8 *)SecCoreData.TemporaryRamBase= + SecCoreData.PeiTemporaryRamSize;

+ SecCoreData.StackSize= =3D SecCoreData.TemporaryRamSize >> 1;

+

+ SecCoreData.Boot=46irmwareVolumeBase =3D BootPei=46v;

= + SecCoreData.Boot=46irmwareVolumeSize =3D (UINTN) BootPei=46v->=46vLe= ngth;

+

+ DEBUG ((DEBUG=5FIN=46O,

+ =22&SecCoreData.Boot=46irmwareVolumeBase=3D%lx SecCoreData.Boot=46= irmwareVolumeBase=3D%lx=5Cn=22,

+ (UINT64)&(SecCoreData= .Boot=46irmwareVolumeBase),

+ (UINT64) (SecCoreData.Boot=46= irmwareVolumeBase)));

+ DEBUG ((DEBUG=5FIN=46O,

+ =22&SecCoreData.Boot=46irmwareVolumeSize=3D%lx SecCoreData.Boot=46= irmwareVolumeSize=3D%lx=5Cn=22,

+ (UINT64)&(SecCoreData= .Boot=46irmwareVolumeSize),

+ (UINT64) (SecCoreData.Boot=46= irmwareVolumeSize)));

+

+ //

+ = // Initialize Debug Agent to support source level debug in SEC/PEI phases= before memory ready.

+ //

+ InitializeDebugA= gent (DEBUG=5FAGENT=5FINIT=5FPREMEM=5FSEC, NULL, NULL);

+ S= ecStartupPhase2 (&SecCoreData);

+=7D

+
+/**

+ temporary memory to permanent memory and= do stack switching.

+

+ =40param=5Bin=5D Pei= Services Pointer to the PEI Services Table.

+ =40param=5Bin= =5D TemporaryMemoryBase Temporary Memory Base address.

+ =40= param=5Bin=5D PermanentMemoryBase Permanent Memory Base address.
+ =40param=5Bin=5D CopySize The size of memory that needs to be mig= rated.

+

+ =40retval E=46I=5FSUCCESS Migratio= n successful.

+**/

+E=46I=5FSTATUS

<= div>+E=46IAPI

+TemporaryRamMigration (

+ IN C= ONST E=46I=5FPEI=5FSERVICES **PeiServices,

+ IN E=46I=5FPHY= SICAL=5FADDRESS TemporaryMemoryBase,

+ IN E=46I=5FPHYSICAL=5F= ADDRESS PermanentMemoryBase,

+ IN UINTN CopySize

<= div>+ )

+=7B

+ VOID *OldHeap;

+= VOID *NewHeap;

+ VOID *OldStack;

+ VOID *New= Stack;

+ BASE=5FLIBRARY=5FJUMP=5FBU=46=46ER JumpBuffer;
+

+ DEBUG ((DEBUG=5FIN=46O,

+ =22T= emporaryRamMigration (0x%Lx, 0x%Lx, 0x%Lx)=5Cn=22,

+ Tempor= aryMemoryBase,

+ PermanentMemoryBase,

+ (UINT= 64)CopySize

+ ));

+

+ OldHeap =3D= (VOID*) (UINTN)TemporaryMemoryBase;

+ NewHeap =3D (VOID*) = ((UINTN)PermanentMemoryBase + (CopySize >> 1));

+
+ OldStack =3D (VOID*) ((UINTN)TemporaryMemoryBase + (CopySize= >> 1));

+ NewStack =3D (VOID*) (UINTN)PermanentMemor= yBase;

+

+ //

+ // Migrate Heap=

+ //

+ CopyMem (NewHeap, OldHeap, CopySize &= gt;> 1);

+

+ //

+ // Migrate= Stack

+ //

+ CopyMem (NewStack, OldStack, Co= pySize >> 1);

+

+ // Use SetJump ()/Lon= gJump () to switch to a new stack.

+ //

+ if = (SetJump (&JumpBuffer) =3D=3D 0) =7B

+ JumpBuffer.SP =3D= JumpBuffer.SP - (UINTN)OldStack + (UINTN)NewStack ;

+ Long= Jump (&JumpBuffer, (UINTN)-1);

+ =7D

+
+ return E=46I=5FSUCCESS;

+=7D

di= ff --git a/Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf b/Platform/= Loongson/LoongArchQemuPkg/Sec/SecMain.inf

new file mode 100= 644

index 0000000000..c0d5439d53

--- /dev/nul= l

+++ b/Platform/Loongson/LoongArchQemuPkg/Sec/SecMain.inf<= /div>
=40=40 -0,0 +1,51 =40=40

+=23=23 =40file
+=23 SEC Driver

+=23

+=23 Copyright= (c) 2022 Loongson Technology Corporation Limited. All rights reserved.&l= t;BR>

+=23

+=23 SPDX-License-Identifier: B= SD-2-Clause-Patent

+=23

+=23=23

+

+=5BDefines=5D

+ IN=46=5FVERSION =3D 0x000= 10005

+ BASE=5FNAME =3D SecMain

+ =46ILE=5FGU= ID =3D 57d02d4f-5a5d-4bfa-b7d6-ba0a4d2c72ce

+ MODULE=5FTYPE= =3D SEC

+ VERSION=5FSTRING =3D 1.0

+
+=23

+=23 VALID=5FARCHITECTURES =3D LOONGARCH64
+=23

+

+=5BSources=5D

+ LoongArch64/Start.S

+ SecMain.c

+
+=5BPackages=5D

+ Platform/Loongson/LoongArchQemuPkg/= Loongson.dec

+ MdePkg/MdePkg.dec

+ MdeModuleP= kg/MdeModulePkg.dec

+

+=5BLibraryClasses=5D
+ BaseLib

+ DebugLib

+ BaseMemor= yLib

+ PcdLib

+ DebugAgentLib

+= IoLib

+ PeCoffLib

+ PeCoffGetEntryPointLib
+ PeCoffExtraActionLib

+

+=5BPpi= s=5D

+ gEfiTemporaryRamSupportPpiGuid =23 PPI ALWAYS=5FPROD= UCED

+

+=5B=46ixedPcd=5D

+ gLoo= ngArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase

+ gLoongAr= chQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize

+

+ gLoongArchQemuPkgTokenSpaceGuid.Pcd=46lashSec=46vBase

+= gLoongArchQemuPkgTokenSpaceGuid.Pcd=46lashSec=46vSize

+ gL= oongArchQemuPkgTokenSpaceGuid.Pcd=46lashPei=46vBase

+ gLoon= gArchQemuPkgTokenSpaceGuid.Pcd=46lashPei=46vSize

--
2.31.1
--636e1768_c7e4c42_1e57b--