public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg
@ 2020-12-01 16:17 Daniel Schaefer
  2020-12-01 16:17 ` [edk2-test PATCH v1 1/2] SctPkg: Add RISCV64 support Daniel Schaefer
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Daniel Schaefer @ 2020-12-01 16:17 UTC (permalink / raw)
  To: devel
  Cc: Leif Lindholm, Heinrich Schuchardt, Abner Chang, Gilbert Chen,
	Eric Jin, G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042

With this patch series we can build the UEFI SCT for RISCV64. It was confirmed
to be working on the U-Boot UEFI implementation by Heinrich.
It hasn't been tested on EDK2 yet.

Build requirements are the same as for the EDK2 RISCV64 port and detailed here:
https://github.com/riscv/riscv-uefi-edk2-docs

The second patch is a big one because it adds architecture specific files by
copying them from the Aarch64 directory. Only a single file, an assembly file
needed modifications. I'm not sure why the other ones are in an architecture
specific directory. They're all C files and seem to be generic. We can probably
unify them.

Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Abner Chang <abner.chang@hpe.com>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
Cc: Eric Jin <eric.jin@intel.com>
Cc: G Edhaya Chandran <Edhaya.Chandran@arm.com>
Cc: Barton Gao <gaojie@byosoft.com.cn>
Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>

Daniel Schaefer (2):
  SctPkg: Add RISCV64 support
  SctPkg: Enable RISCV64 support using AARCH64 sources

 uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h                                                                     |   3 +
 uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h                                                                        |  32 +++
 uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c                                                                          |  45 ++++
 uefi-sct/SctPkg/Library/SctLib/SctLib.inf                                                                                  |   6 +
 uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S                                                                           |  45 ++++
 uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c                                                                       | 182 +++++++++++++
 uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf                                                                                   |   6 +
 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c                                                                            |  88 +++++++
 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c                                                                             |  68 +++++
 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c                                                                               | 134 ++++++++++
 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h                                                                               |  48 ++++
 uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf                                                                             |   7 +
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf                                |   6 +
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c             | 137 ++++++++++
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c | 276 ++++++++++++++++++++
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c                                 |  30 +++
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf                                              |   4 +
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c                                     |  51 ++++
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf                                                |   4 +
 uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf                                                   |   5 +
 uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h                                         |  55 ++++
 uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c                                            |  55 ++++
 uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile                                                                            |   3 +
 uefi-sct/SctPkg/UEFI/IHV_SCT.dsc                                                                                           |  14 +-
 uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h                                                                               |  62 ++++-
 uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc                                                                                          |  14 +-
 uefi-sct/SctPkg/build.sh                                                                                                   |  10 +-
 27 files changed, 1386 insertions(+), 4 deletions(-)
 create mode 100644 uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h
 create mode 100644 uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c
 create mode 100644 uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
 create mode 100644 uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c
 create mode 100644 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c
 create mode 100644 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c
 create mode 100644 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c
 create mode 100644 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h
 create mode 100644 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c
 create mode 100644 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
 create mode 100644 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c
 create mode 100644 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c
 create mode 100644 uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h
 create mode 100644 uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c

-- 
2.28.0


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [edk2-test PATCH v1 1/2] SctPkg: Add RISCV64 support
  2020-12-01 16:17 [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg Daniel Schaefer
@ 2020-12-01 16:17 ` Daniel Schaefer
  2020-12-02 11:44   ` [edk2-devel] " Leif Lindholm
  2020-12-01 16:17 ` [edk2-test PATCH v1 2/2] SctPkg: Enable RISCV64 support using AARCH64 sources Daniel Schaefer
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 18+ messages in thread
From: Daniel Schaefer @ 2020-12-01 16:17 UTC (permalink / raw)
  To: devel
  Cc: Leif Lindholm, Heinrich Schuchardt, Abner Chang, Gilbert Chen,
	Eric Jin, G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042

TODO: Need to check whether we can avoid copying Aarch64 sources.

Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Abner Chang <abner.chang@hpe.com>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
Cc: Eric Jin <eric.jin@intel.com>
Cc: G Edhaya Chandran <Edhaya.Chandran@arm.com>
Cc: Barton Gao <gaojie@byosoft.com.cn>
Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Signed-off-by: Daniel Schaefer <daniel.schaefer@hpe.com>
---
 uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h                                      |  3 +
 uefi-sct/SctPkg/Library/SctLib/SctLib.inf                                                   |  6 ++
 uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf                                                    |  6 ++
 uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf                                              |  7 +++
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf |  6 ++
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf               |  4 ++
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf                 |  4 ++
 uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf                    |  5 ++
 uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile                                             |  3 +
 uefi-sct/SctPkg/UEFI/IHV_SCT.dsc                                                            | 14 ++++-
 uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h                                                | 62 +++++++++++++++++++-
 uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc                                                           | 14 ++++-
 uefi-sct/SctPkg/build.sh                                                                    | 10 +++-
 13 files changed, 140 insertions(+), 4 deletions(-)

diff --git a/uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h b/uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h
index a7815580..3a7c8f31 100644
--- a/uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h
+++ b/uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h
@@ -32,6 +32,9 @@
 #elif defined(EFIAARCH64)
   #define INSTALL_SCT_PLATFORM_SHORT_NAME   L"aarch64"
   #define INSTALL_SCT_PLATFORM_NAME         L"AARCH64"
+#elif defined(EFIRISCV64)
+  #define INSTALL_SCT_PLATFORM_SHORT_NAME   L"riscv64"
+  #define INSTALL_SCT_PLATFORM_NAME         L"RISCV64"
 #else
   #error "Architecture not supported"
 #endif
diff --git a/uefi-sct/SctPkg/Library/SctLib/SctLib.inf b/uefi-sct/SctPkg/Library/SctLib/SctLib.inf
index 23cb77fb..6f59d974 100644
--- a/uefi-sct/SctPkg/Library/SctLib/SctLib.inf
+++ b/uefi-sct/SctPkg/Library/SctLib/SctLib.inf
@@ -62,6 +62,12 @@
   Aarch64/initplat.c
   Math.c
 
+# TODO: Copied source from AARCH64, need to check if they need to be adjusted
+[sources.RISCV64]
+  Riscv64/SctLibPlat.h
+  Riscv64/initplat.c
+  Math.c
+
 [sources.ia32]
   ia32/SctLibPlat.h
   ia32/initplat.c
diff --git a/uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf b/uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf
index 7aca6e30..66de4cac 100644
--- a/uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf
+++ b/uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf
@@ -39,6 +39,12 @@
   Aarch64/GoVirtual.asm | RVCT
   Aarch64/GoVirtual.S | GCC
 
+# TODO: Copied source from AARCH64, need to check if they need to be adjusted
+#       ASM is adjusted but not sure if it is correct
+[sources.RISCV64]
+  Riscv64/VirtualMemory.c
+  Riscv64/GoVirtual.S | GCC
+
 [sources.ia32]
   ia32/VirtualMemory.c
   ia32/GoVirtual.asm | MSFT
diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf b/uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf
index ad0eb0f8..bc0ade5b 100644
--- a/uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf
+++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf
@@ -69,6 +69,13 @@
   Aarch64/Dump.c
   Aarch64/Debug.c
 
+# TODO: Copied source from AARCH64, need to check if they need to be adjusted
+[sources.RISCV64]
+  Riscv64/Io.c
+  Riscv64/Io.h
+  Riscv64/Dump.c
+  Riscv64/Debug.c
+
 [sources.common]
   Guid.h
   Guid.c
diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf
index 799f86fd..7010c7f1 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf
@@ -67,6 +67,12 @@
   Aarch64/DebugSupportBBTestExceptionCallbackFunction.c
   Aarch64/DebugSupportBBTestCacheFunction.c
 
+# TODO: Copied source from AARCH64, need to check if they need to be adjusted
+[sources.RISCV64]
+  Riscv64/PlatformIsa.c
+  Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
+  Riscv64/DebugSupportBBTestCacheFunction.c
+
 [Packages]
   SctPkg/SctPkg.dec
   SctPkg/UEFI/UEFI.dec
diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf
index e8118739..e42acd29 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf
@@ -55,6 +55,10 @@
 #[sources.Aarch64]
 #  IPF/TimerInterrupt.c
 
+# TODO: Seems like almost all archs can use the IPF code, need to check
+[sources.Riscv64]
+  IPF/TimerInterrupt.c
+
 [Packages]
   MdePkg/MdePkg.dec
   SctPkg/SctPkg.dec
diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf
index efc438c1..0d47536f 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf
@@ -55,6 +55,10 @@
 [sources.Aarch64]
   Aarch64/TimerInterrupt.c
 
+# TODO: Copied source from AARCH64, need to check if they need to be adjusted
+[sources.RISCV64]
+  Riscv64/TimerInterrupt.c
+
 [Packages]
   MdePkg/MdePkg.dec
   SctPkg/SctPkg.dec
diff --git a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf
index 23f12d1a..1b2a92f2 100644
--- a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf
+++ b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf
@@ -66,6 +66,11 @@
   Aarch64/EntsLibPlat.h
   Aarch64/InitPlat.c
 
+# TODO: Copied source from AARCH64, need to check if they need to be adjusted
+[sources.RISCV64]
+  Riscv64/EntsLibPlat.h
+  Riscv64/InitPlat.c
+
 [Packages]
   MdePkg/MdePkg.dec
   SctPkg/SctPkg.dec
diff --git a/uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile b/uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile
index c235f313..e49284e7 100644
--- a/uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile
+++ b/uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile
@@ -31,6 +31,9 @@ ifndef ARCH
   ifneq (,$(findstring arm,$(uname_m)))
     ARCH=ARM
   endif
+  ifneq (,$(findstring riscv64,$(uname_m)))
+    ARCH=RISCV64
+  endif
   ifndef ARCH
     $(info Could not detected ARCH from uname results)
     $(error ARCH is not defined!)
diff --git a/uefi-sct/SctPkg/UEFI/IHV_SCT.dsc b/uefi-sct/SctPkg/UEFI/IHV_SCT.dsc
index f9e86264..2f373c5f 100644
--- a/uefi-sct/SctPkg/UEFI/IHV_SCT.dsc
+++ b/uefi-sct/SctPkg/UEFI/IHV_SCT.dsc
@@ -42,7 +42,7 @@
   PLATFORM_VERSION               = 0.1
   DSC_SPECIFICATION              = 0x00010005
   OUTPUT_DIRECTORY               = Build/IhvSct
-  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64
+  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64|RISCV64
   BUILD_TARGETS                  = DEBUG|RELEASE
   SKUID_IDENTIFIER               = DEFAULT
 
@@ -109,6 +109,12 @@
   *_*_AARCH64_PP_FLAGS         = -D EFIAARCH64 $(GCC_VER_MACRO)
   RVCT:*_*_AARCH64_DLINK_FLAGS = --muldefweak
 
+  *_*_RISCV64_CC_FLAGS         = -D EFIRISCV64 $(GCC_VER_MACRO)
+  GCC:*_*_RISCV64_CC_FLAGS  = -D EFIRISCV64 $(GCC_VER_MACRO) -ffreestanding -nostdinc -nostdlib -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error
+  *_*_RISCV64_VFRPP_FLAGS      = -D EFIRISCV64 $(GCC_VER_MACRO)
+  *_*_RISCV64_APP_FLAGS        = -D EFIRISCV64 $(GCC_VER_MACRO)
+  *_*_RISCV64_PP_FLAGS         = -D EFIRISCV64 $(GCC_VER_MACRO)
+
   DEBUG_*_*_CC_FLAGS  = -DEFI_DEBUG
   RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG
 
@@ -124,6 +130,9 @@
 [Libraries.AARCH64]
   ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
 
+[Libraries.RISCV64]
+  ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
+
 [Libraries.IA32,Libraries.X64]
 
 [LibraryClasses.common]
@@ -146,6 +155,9 @@
 [LibraryClasses.AARCH64]
   NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
 
+[LibraryClasses.RISCV64]
+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
+
 [LibraryClasses.IA32]
 
 ###############################################################################
diff --git a/uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h b/uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h
index 7fba87ae..fb11bda4 100644
--- a/uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h
+++ b/uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h
@@ -607,6 +607,60 @@ typedef struct {
   UINT64  FAR;  // Fault Address Register
 } EFI_SYSTEM_CONTEXT_AARCH64;
 
+///
+/// RISC-V processor exception types.
+///
+#define EXCEPT_RISCV_INST_MISALIGNED              0
+#define EXCEPT_RISCV_INST_ACCESS_FAULT            1
+#define EXCEPT_RISCV_ILLEGAL_INST                 2
+#define EXCEPT_RISCV_BREAKPOINT                   3
+#define EXCEPT_RISCV_LOAD_ADDRESS_MISALIGNED      4
+#define EXCEPT_RISCV_LOAD_ACCESS_FAULT            5
+#define EXCEPT_RISCV_STORE_AMO_ADDRESS_MISALIGNED 6
+#define EXCEPT_RISCV_STORE_AMO_ACCESS_FAULT       7
+#define EXCEPT_RISCV_ENV_CALL_FROM_UMODE          8
+#define EXCEPT_RISCV_ENV_CALL_FROM_SMODE          9
+#define EXCEPT_RISCV_ENV_CALL_FROM_HMODE          10
+#define EXCEPT_RISCV_ENV_CALL_FROM_MMODE          11
+
+#define EXCEPT_RISCV_SOFTWARE_INT       0x0
+#define EXCEPT_RISCV_TIMER_INT          0x1
+
+typedef struct {
+  UINT64  X0;
+  UINT64  X1;
+  UINT64  X2;
+  UINT64  X3;
+  UINT64  X4;
+  UINT64  X5;
+  UINT64  X6;
+  UINT64  X7;
+  UINT64  X8;
+  UINT64  X9;
+  UINT64  X10;
+  UINT64  X11;
+  UINT64  X12;
+  UINT64  X13;
+  UINT64  X14;
+  UINT64  X15;
+  UINT64  X16;
+  UINT64  X17;
+  UINT64  X18;
+  UINT64  X19;
+  UINT64  X20;
+  UINT64  X21;
+  UINT64  X22;
+  UINT64  X23;
+  UINT64  X24;
+  UINT64  X25;
+  UINT64  X26;
+  UINT64  X27;
+  UINT64  X28;
+  UINT64  X29;
+  UINT64  X30;
+  UINT64  X31;
+} EFI_SYSTEM_CONTEXT_RISCV64;
+
 //
 // Universal EFI_SYSTEM_CONTEXT definition
 //
@@ -618,6 +672,7 @@ union {
   EFI_SYSTEM_CONTEXT_IPF                  *SystemContextIpf;
   EFI_SYSTEM_CONTEXT_ARM                  *SystemContextArm;
   EFI_SYSTEM_CONTEXT_AARCH64              *SystemContextAArch64;
+  EFI_SYSTEM_CONTEXT_RISCV64              *SystemContextRiscV64;
 } EFI_SYSTEM_CONTEXT;
 
 //
@@ -645,6 +700,10 @@ VOID
 #define IMAGE_FILE_MACHINE_EBC             0x0EBC
 #define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED  0x01c2
 #define IMAGE_FILE_MACHINE_ARM64           0xAA64
+#define IMAGE_FILE_MACHINE_RISCV32         0x5032
+#define IMAGE_FILE_MACHINE_RISCV64         0x5064
+#define IMAGE_FILE_MACHINE_RISCV128        0x5128
+
 
 typedef
 enum {
@@ -653,7 +712,8 @@ enum {
   IsaIpf  = IMAGE_FILE_MACHINE_IA64,
   IsaEbc  = IMAGE_FILE_MACHINE_EBC,
   IsaArm  = IMAGE_FILE_MACHINE_ARMTHUMB_MIXED, ///< 0x01c2
-  IsaAArch64  = IMAGE_FILE_MACHINE_ARM64       ///< 0xAA64
+  IsaAArch64  = IMAGE_FILE_MACHINE_ARM64,      ///< 0xAA64
+  IsaRiscv64  = IMAGE_FILE_MACHINE_RISCV64
 } EFI_INSTRUCTION_SET_ARCHITECTURE;
 
 typedef struct _EFI_DEBUG_SUPPORT_PROTOCOL EFI_DEBUG_SUPPORT_PROTOCOL;;
diff --git a/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc b/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc
index 2e97687b..666f06dd 100644
--- a/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc
+++ b/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc
@@ -42,7 +42,7 @@
   PLATFORM_VERSION               = 0.1
   DSC_SPECIFICATION              = 0x00010005
   OUTPUT_DIRECTORY               = Build/UefiSct
-  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64
+  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64|RISCV64
   BUILD_TARGETS                  = DEBUG|RELEASE
   SKUID_IDENTIFIER               = DEFAULT
   
@@ -112,6 +112,12 @@
   *_*_AARCH64_PP_FLAGS         = -D EFIAARCH64 $(GCC_VER_MACRO)
   RVCT:*_*_AARCH64_DLINK_FLAGS = --muldefweak
 
+  *_*_RISCV64_CC_FLAGS         = -D EFIRISCV64 $(GCC_VER_MACRO)
+  GCC:*_*_RISCV64_CC_FLAGS     = -D EFIRISCV64 $(GCC_VER_MACRO) -ffreestanding -nostdinc -nostdlib -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error
+  *_*_RISCV64_VFRPP_FLAGS      = -D EFIRISCV64 $(GCC_VER_MACRO)
+  *_*_RISCV64_APP_FLAGS        = -D EFIRISCV64 $(GCC_VER_MACRO)
+  *_*_RISCV64_PP_FLAGS         = -D EFIRISCV64 $(GCC_VER_MACRO)
+
   DEBUG_*_*_CC_FLAGS  = -DEFI_DEBUG
   RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG
 
@@ -129,6 +135,9 @@
 [Libraries.AARCH64]
   ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
 
+[Libraries.RISCV64]
+  ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
+
 [LibraryClasses.common]
   UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
   UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
@@ -157,6 +166,9 @@
 [LibraryClasses.AARCH64]
   NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
 
+[LibraryClasses.RISCV64]
+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
+
 ###############################################################################
 #
 # These are the components that will be built by the master makefile
diff --git a/uefi-sct/SctPkg/build.sh b/uefi-sct/SctPkg/build.sh
index cad17ccd..3d61daed 100755
--- a/uefi-sct/SctPkg/build.sh
+++ b/uefi-sct/SctPkg/build.sh
@@ -22,6 +22,8 @@ function get_build_arch
 	        BUILD_ARCH=ARM;;
 	    aarch64*)
 	        BUILD_ARCH=AARCH64;;
+	    riscv64*)
+	        BUILD_ARCH=RISCV64;;
 	    *)
 	        BUILD_ARCH=other;;
 	esac
@@ -47,6 +49,12 @@ function set_cross_compile
 	    else
 	        TEMP_CROSS_COMPILE=arm-linux-gnueabihf-
 	    fi
+	elif [ "$SCT_TARGET_ARCH" == "RISCV64" ]; then
+	    if [ X"$CROSS_COMPILE_64" != X"" ]; then
+	        TEMP_CROSS_COMPILE="$CROSS_COMPILE_64"
+	    else
+	        TEMP_CROSS_COMPILE=riscv64-unknown-elf-
+	    fi
 	else
 	    echo "Unsupported target architecture '$SCT_TARGET_ARCH'!" >&2
 	fi
@@ -110,7 +118,7 @@ PrintUsage() {
 	#Print Help
 	#
 	echo "Usage:"
-	echo "    $0 <architecture (ARM, AARCH64, X64, etc)> \
+	echo "    $0 <architecture (ARM, AARCH64, X64, RISCV64, etc)> \
 <toolchain name (RVCT or ARMGCC or GCC*)> \
 [build type (RELEASE OR DEBUG, DEFAULT: DEBUG)]"
 }
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [edk2-test PATCH v1 2/2] SctPkg: Enable RISCV64 support using AARCH64 sources
  2020-12-01 16:17 [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg Daniel Schaefer
  2020-12-01 16:17 ` [edk2-test PATCH v1 1/2] SctPkg: Add RISCV64 support Daniel Schaefer
@ 2020-12-01 16:17 ` Daniel Schaefer
  2020-12-02 12:04   ` [edk2-devel] " Leif Lindholm
  2020-12-01 16:59 ` [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg Heinrich Schuchardt
  2020-12-02 12:07 ` Leif Lindholm
  3 siblings, 1 reply; 18+ messages in thread
From: Daniel Schaefer @ 2020-12-01 16:17 UTC (permalink / raw)
  To: devel
  Cc: Leif Lindholm, Heinrich Schuchardt, Abner Chang, Gilbert Chen,
	Eric Jin, G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042

TODO: Need to check whether we can avoid copying Aarch64 sources.

Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Abner Chang <abner.chang@hpe.com>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
Cc: Eric Jin <eric.jin@intel.com>
Cc: G Edhaya Chandran <Edhaya.Chandran@arm.com>
Cc: Barton Gao <gaojie@byosoft.com.cn>
Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Signed-off-by: Daniel Schaefer <daniel.schaefer@hpe.com>
---
 uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h                                                                        |  32 +++
 uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c                                                                          |  45 ++++
 uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S                                                                           |  45 ++++
 uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c                                                                       | 182 +++++++++++++
 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c                                                                            |  88 +++++++
 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c                                                                             |  68 +++++
 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c                                                                               | 134 ++++++++++
 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h                                                                               |  48 ++++
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c             | 137 ++++++++++
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c | 276 ++++++++++++++++++++
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c                                 |  30 +++
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c                                     |  51 ++++
 uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h                                         |  55 ++++
 uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c                                            |  55 ++++
 14 files changed, 1246 insertions(+)

diff --git a/uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h b/uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h
new file mode 100644
index 00000000..ee7c656b
--- /dev/null
+++ b/uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h
@@ -0,0 +1,32 @@
+/** @file
+
+  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
+  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at 
+  http://opensource.org/licenses/bsd-license.php
+ 
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ 
+**/
+/*++
+
+Module Name:
+
+  SctLibPlat.h
+
+Abstract:
+
+  AArch64 specific defines
+
+--*/
+
+#ifndef _EFI_LIB_PLAT_H_
+#define _EFI_LIB_PLAT_H_
+
+#define MIN_ALIGNMENT_SIZE  8
+
+#endif
diff --git a/uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c b/uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c
new file mode 100644
index 00000000..a48bb2f3
--- /dev/null
+++ b/uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c
@@ -0,0 +1,45 @@
+/** @file
+
+  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
+  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at 
+  http://opensource.org/licenses/bsd-license.php
+ 
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ 
+**/
+/*++
+
+Module Name:
+
+  initplat.c
+
+Abstract:
+
+  Math routines for compatibility with native EFI library routines.
+
+--*/
+
+#include "SctLibInternal.h"
+
+VOID
+InitializeLibPlatform (
+    IN EFI_HANDLE           ImageHandle,
+    IN EFI_SYSTEM_TABLE     *SystemTable
+    )
+
+{
+  // No platform-specific initializations
+}
+
+UINT64
+SctReadTsc (
+  VOID
+  )
+{
+  return 0;
+}
diff --git a/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
new file mode 100644
index 00000000..8bc2c624
--- /dev/null
+++ b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
@@ -0,0 +1,45 @@
+## @file
+#
+#  Copyright 2010 - 2012 Unified EFI, Inc.<BR>
+#  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
+#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP.<BR>
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at 
+#  http://opensource.org/licenses/bsd-license.php
+# 
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+# 
+##
+#
+#
+#/*++
+#
+# Module Name:
+#
+#  GoVirtual.S
+#
+#--*/
+#start of the code section
+.text
+/* FIXME: Should alignment be different on Aarch64? */
+.align 3
+
+.global JumpToTestFunc
+.type JumpToTestFunc, %function
+
+#------------------------------------------------------------------------------
+# VOID
+# JumpToTestFunc (
+#   IN  UINTN  FuncPointer,
+#   IN  UNITN  ConfigInfo
+#   )
+# TODO: Make sure this code is correct
+JumpToTestFunc:
+	mv x2, x0
+	mv x0, x1
+
+	// Jump to Virtual function
+	jalr x2
diff --git a/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c
new file mode 100644
index 00000000..397b3514
--- /dev/null
+++ b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c
@@ -0,0 +1,182 @@
+/** @file
+
+  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
+  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at 
+  http://opensource.org/licenses/bsd-license.php
+ 
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ 
+**/
+/*++
+
+Module Name:
+
+  VirtualMemory.c
+
+--*/
+
+#include "SCRTApp.h"
+
+#define VIRT_TO_PHYS_OFFSET       (0x80000000)     //2G
+
+BOOLEAN     HighAddress = FALSE;
+UINTN       PageTable   = 0;
+
+
+VOID
+ConvertRuntimeFuncPtr (
+  IN OUT UINTN      *VirtualFunc
+  )
+/*++
+
+Routine Description:
+
+  Change RuntimeTestFunc physical address to virtual address
+
+Arguments:
+
+  VirtualFunc  - On input, RuntimeTestFunc physical address.
+                 On output, RuntimeTest virtual address.
+
+Returns:
+
+  NONE
+
+--*/
+{
+	/*Note: It is presumed that on ARM v5, V6 and V7 architectures
+	 * the MMU is configured and enabled in PEI phase. As VirtualFunc
+	 * is already mapped to virtual memory, don't have to do anything here.
+	 */
+  /* FIXME: Is it the same on ARM v8? */
+}
+
+
+EFI_STATUS
+DoMemoryAllocation (
+  IN UINTN PhysicalFunc
+  )
+/*++
+
+Routine Description:
+
+  Allocate memory and create the PageTable to set up physical-virtual map.
+
+Arguments:
+
+  PhysicalFunc  - Physical address where RuntimeTestFunc locates.
+
+Returns:
+
+  EFI_STATUS
+
+--*/
+{
+  EFI_STATUS                  Status;
+  EFI_PHYSICAL_ADDRESS        AllocateMemory;
+
+  //create new page tables or use existing page tables.
+  //
+  // Allocate PageTable memory close to this Application image location in
+  // the system memory. In this way, it is safe for page table memory.
+  //
+  AllocateMemory = PhysicalFunc;
+
+  Status = tBS->AllocatePages (
+                  AllocateMaxAddress,
+                  EfiRuntimeServicesData,
+                  1,
+                  &AllocateMemory
+                  );
+
+  if (EFI_ERROR(Status)) {
+    return Status;
+  }
+
+  PageTable = (UINTN)AllocateMemory;
+  return EFI_SUCCESS;
+}
+
+
+VOID
+PrepareVirtualAddressMap (
+  IN UINTN                       MemoryMapSize,
+  IN UINTN                       DescriptorSize,
+  IN EFI_MEMORY_DESCRIPTOR       *MemoryMap,
+  IN EFI_MEMORY_DESCRIPTOR       *VirtualMemoryMap,
+  IN OUT UINTN                   *VirtualMapSize
+  )
+/*++
+
+Routine Description:
+
+  Construct VirtualAddressMap from physical address to virtual address
+
+Arguments:
+
+  MemoryMapSize     - The size, in bytes, of the MemoryMap buffer
+  DescriptorSize    - The size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR
+  MemoryMap         - A pointer to the current memory map
+  VirtualMemoryMap  - A pointer to the modified virtual memory map
+  VirtualMapSize    - A pointer to the size, in bytes, of the VirtualMemoryMap buffer
+
+Returns:
+
+  NONE
+
+--*/
+{
+  UINTN    Index;
+  *VirtualMapSize        = 0;
+
+  //
+  // Copy entries that need runtime mapping to construct virtualMemoryMap
+  //
+  for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {
+    if ((MemoryMap->Attribute & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) {
+      SctCopyMem ((VOID *) VirtualMemoryMap, (VOID *) MemoryMap, DescriptorSize);
+      VirtualMemoryMap->VirtualStart  = VirtualMemoryMap->PhysicalStart;
+      *VirtualMapSize += DescriptorSize;
+      VirtualMemoryMap = NextMemoryDescriptor (VirtualMemoryMap, DescriptorSize);
+    }
+
+    MemoryMap = NextMemoryDescriptor (MemoryMap, DescriptorSize);
+  }
+}
+
+
+
+VOID
+JumpVirtualMode(
+  IN UINTN VirtualFunc,
+  IN UINTN HandOffAddr
+  )
+/*++
+
+Routine Description:
+
+  Enable virtual addressing mode, and jump to RuntimeTestFunc in virtual address
+
+Arguments:
+
+  VirtualFunc  - RuntimeTestFunc virtual address
+  HandOffAddr  - Configuration Data Address
+
+Returns:
+
+  NONE
+
+--*/
+{
+  //
+  // Note: It is assumed that the MMU and page tables are configured on ARM platforms
+  // based on ARM v5 v6 and v7 architecture.
+  //
+  /* FIXME: Is it the same on ARM v8? */
+	JumpToTestFunc(VirtualFunc, HandOffAddr);
+}
diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c
new file mode 100644
index 00000000..6161d596
--- /dev/null
+++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c
@@ -0,0 +1,88 @@
+/** @file
+
+  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
+  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>   
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at 
+  http://opensource.org/licenses/bsd-license.php
+ 
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ 
+**/
+
+/*++
+
+Module Name:
+
+  Debug.c
+
+--*/
+
+#include "SCRTDriver.h"
+
+UINTN                 mHandOffPtr        =  0;
+EFI_PHYSICAL_ADDRESS  mIoPortSpaceAddress = 0;
+
+
+EFI_STATUS
+ConsumeHandOff (
+  IN  UINTN         HandOffAddr,
+  OUT CONF_INFO     *ConfigData
+  )
+{
+   RUNTIME_HANDOFF   *HandOffPtr;
+   //
+   // First fix the memory address of hand off data.
+   //
+   FixAddress(&HandOffAddr);
+   mHandOffPtr = HandOffAddr;
+   HandOffPtr  = (RUNTIME_HANDOFF*)mHandOffPtr;
+   *ConfigData =  HandOffPtr->ConfigureInfo;
+
+   if (!HandOffPtr->DebuggerInfo.MmioFlag){
+     //
+     // If debug port is I/O mapped, fix IoBase Address.
+     //
+     FixAddress(&HandOffPtr->DebuggerInfo.IoBase);
+     mIoPortSpaceAddress = HandOffPtr->DebuggerInfo.IoBase;
+   } else {
+     //
+     // If debug port is MMIO, fix MmioBase Address.
+     //
+     FixAddress(&HandOffPtr->DebuggerInfo.MmioBase);
+   }
+
+   return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+Send2UART (
+  CHAR8                *String
+  )
+{
+  //
+  // TODO: On ARM platforms use platform specific functions to
+  // write the data to UART.
+  //
+  return EFI_SUCCESS;
+}
+
+
+
+EFI_STATUS
+DebugWorker (
+  IN CHAR8    *String
+  )
+{
+  EFI_STATUS    Status;
+
+  //
+  // Send text message to registered UART.
+  //
+  Status = Send2UART(String);
+  return Status;
+}
diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c
new file mode 100644
index 00000000..cc8d9869
--- /dev/null
+++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c
@@ -0,0 +1,68 @@
+/** @file
+
+  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
+  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>   
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at 
+  http://opensource.org/licenses/bsd-license.php
+ 
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ 
+**/
+
+/*++
+
+Module Name:
+
+  Dump.c
+
+--*/
+
+#include "SCRTDriver.h"
+
+VOID
+DumpRuntimeTable()
+{
+  SctAPrint ("\n================Dump Runtime Table===============\n");
+  SctAPrint ("Header Signature = 0x%x\n", VRT->Hdr.Signature);
+
+  SctAPrint ("\n================GetTime Service==============\n");
+  SctAPrint ("GetTime @ 0x%x\n", VRT->GetTime);
+
+  SctAPrint ("\n================SetTime Service==============\n");
+  SctAPrint ("SetTime @ 0x%x\n", VRT->SetTime);
+
+  SctAPrint ("\n================GetWakeupTime Service==============\n");
+  SctAPrint ("GetWakeupTime @ 0x%x\n", VRT->GetWakeupTime);
+
+  SctAPrint ("\n================SetWakeupTime Service==============\n");
+  SctAPrint ("SetWakeupTime @ 0x%x\n", VRT->SetWakeupTime);
+
+  SctAPrint ("\n================GetVariable Service==============\n");
+  SctAPrint ("GetVariable @ 0x%x\n", VRT->GetVariable);
+
+  SctAPrint ("\n================GetNextVariableName Service==============\n");
+  SctAPrint ("GetNextVariableName @ 0x%x\n", VRT->GetNextVariableName);
+
+  SctAPrint ("\n================SetVariable Service==============\n");
+  SctAPrint ("SetVariable @ 0x%x\n", VRT->SetVariable);
+
+  SctAPrint ("\n================GetNextHighMonotonicCount Service==============\n");
+  SctAPrint ("GetNextHighMonotonicCount @ 0x%x\n", VRT->GetNextHighMonotonicCount);
+
+  SctAPrint ("\n================ResetSystem Service==============\n");
+  SctAPrint ("ResetSystem @ 0x%x\n", VRT->ResetSystem);
+#if 0
+  SctAPrint ("\n================UpdateCapsule Service==============\n");
+  SctAPrint ("UpdateCapsule @ 0x%x\n", VRT->UpdateCapsule);
+
+  SctAPrint ("\n================QueryCapsuleCapabilities Service==============\n");
+  SctAPrint ("QueryCapsuleCapabilities @ 0x%x\n", VRT->QueryCapsuleCapabilities);
+
+  SctAPrint ("\n================QueryVariableInfo Service==============\n");
+  SctAPrint ("QueryVariableInfo @ 0x%x\n", VRT->QueryVariableInfo);
+#endif
+}
diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c
new file mode 100644
index 00000000..b925e151
--- /dev/null
+++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c
@@ -0,0 +1,134 @@
+/** @file
+
+  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
+  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>   
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at 
+  http://opensource.org/licenses/bsd-license.php
+ 
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ 
+**/
+
+/*++
+
+Module Name:
+
+  Io.c
+
+--*/
+
+#include "Io.h"
+
+EFI_STATUS
+EFIAPI
+CpuIoServiceWrite (
+  IN EFI_PEI_CPU_IO_PPI_WIDTH  Width,
+  IN UINT64                     UserAddress,
+  IN UINTN                      Count,
+  IN VOID                       *UserBuffer
+  )
+/*++
+
+Routine Description:
+
+  Perform the port I/O write service
+
+Arguments:
+
+  Width   - Width of the port I/O operation
+  Address - Base address of the port I/O operation
+  Count   - Count of the number of accesses to perform
+  Buffer  - Pointer to the source buffer from which to write data
+
+Returns:
+
+  EFI_SUCCESS           - The data was written.
+  EFI_INVALID_PARAMETER - Width is invalid.
+  EFI_INVALID_PARAMETER - Buffer is NULL.
+  EFI_UNSUPPORTED       - The Buffer is not aligned for the given Width.
+  EFI_UNSUPPORTED       - The address range specified by Address, Width,
+                          and Count is not valid.
+
+--*/
+{
+  return EFI_UNSUPPORTED;
+}
+
+
+EFI_STATUS
+EfiIoWrite (
+  IN     EFI_PEI_CPU_IO_PPI_WIDTH  Width,
+  IN     UINT64                     Address,
+  IN     UINTN                      Count,
+  IN OUT VOID                       *Buffer
+  )
+/*++
+
+Routine Description:
+  Perform an IO write into Buffer.
+
+Arguments:
+  Width   - Width of write transaction, and repeat operation to use
+  Address - IO address to write
+  Count   - Number of times to write the IO address.
+  Buffer  - Buffer to write data from. size is Width * Count
+
+Returns:
+  Status code
+
+--*/
+{
+  return CpuIoServiceWrite(Width, Address, Count, Buffer);
+}
+
+
+EFI_STATUS
+EfiIoRead (
+  IN     EFI_PEI_CPU_IO_PPI_WIDTH  Width,
+  IN     UINT64                     Address,
+  IN     UINTN                      Count,
+  IN OUT VOID                       *Buffer
+  )
+/*++
+
+Routine Description:
+  Perform an IO read into Buffer.
+
+Arguments:
+  Width   - Width of read transaction, and repeat operation to use
+  Address - IO address to read
+  Count   - Number of times to read the IO address.
+  Buffer  - Buffer to read data into. size is Width * Count
+
+Returns:
+  Status code
+
+--*/
+{
+  return EFI_UNSUPPORTED;
+}
+
+
+VOID
+FixAddress (
+  IN UINTN     *PhyAddress
+  )
+{
+		//
+		//Note: On ARM platforms don't have to do this as all the functions are virtually mapped.
+		//
+}
+
+// Quick port to ARM
+
+VOID
+Port80 (
+  UINT8 Number
+  )
+{
+  //EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Port80 %02x", Number));
+}
diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h
new file mode 100644
index 00000000..1e78b3e4
--- /dev/null
+++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h
@@ -0,0 +1,48 @@
+/** @file
+
+  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
+  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>   
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at 
+  http://opensource.org/licenses/bsd-license.php
+ 
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ 
+**/
+
+/*++
+
+Module Name:
+
+  Debug.h
+
+--*/
+
+#ifndef _IA32_IO_ACCESS_H
+#define _IA32_IO_ACCESS_H
+
+#include "SCRTDriver.h"
+
+#define IA32_MAX_IO_ADDRESS   0xFFFF
+
+#define IA32API
+
+
+typedef union {
+  UINT8  VOLATILE  *buf;
+  UINT8  VOLATILE  *ui8;
+  UINT16 VOLATILE  *ui16;
+  UINT32 VOLATILE  *ui32;
+  UINT64 VOLATILE  *ui64;
+  UINTN  VOLATILE  ui;
+} PTR;
+
+// This address is assuming a pure PC architecture. Not required?
+#define   VIRT_TO_PHYS_OFFSET            (0x80000000)     //2G
+
+
+
+#endif
diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c
new file mode 100644
index 00000000..96ee7b57
--- /dev/null
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c
@@ -0,0 +1,137 @@
+/** @file
+
+  Copyright 2006 - 2016 Unified EFI, Inc.<BR>
+  Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at 
+  http://opensource.org/licenses/bsd-license.php
+ 
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ 
+**/
+/*++
+
+Module Name:
+
+  DebugSupportBBTestCacheFunction.c
+
+Abstract:
+
+  Interface Function Test Cases of Debug Support Protocol
+
+--*/
+
+
+#include "DebugSupportBBTestMain.h"
+
+/**
+ *  Entrypoint for EFI_DEBUG_SUPPORT_PROTOCOL.InvalidateInstructionCache() Function Test.
+ *  @param This a pointer of EFI_BB_TEST_PROTOCOL.
+ *  @param ClientInterface a pointer to the interface to be tested.
+ *  @param TestLevel test "thoroughness" control.
+ *  @param SupportHandle a handle containing protocols required.
+ *  @return EFI_SUCCESS Finish the test successfully.
+ */
+//
+// TDS 3.5
+//
+EFI_STATUS
+BBTestInvalidateInstructionCacheFunctionAutoTest (
+  IN EFI_BB_TEST_PROTOCOL       *This,
+  IN VOID                       *ClientInterface,
+  IN EFI_TEST_LEVEL             TestLevel,
+  IN EFI_HANDLE                 SupportHandle
+  )
+{
+  EFI_STANDARD_TEST_LIBRARY_PROTOCOL   *StandardLib;
+  EFI_STATUS                           Status;
+  EFI_DEBUG_SUPPORT_PROTOCOL           *DebugSupport;
+  EFI_TEST_ASSERTION                   AssertionType;
+  UINT64                               Start;
+  UINT64                               Length;
+  UINTN                                MaxProcessorIndex;
+  UINTN                                ProcessorIndex;
+
+  //
+  // Get the Standard Library Interface
+  //
+  Status = gtBS->HandleProtocol (
+                   SupportHandle,
+                   &gEfiStandardTestLibraryGuid,
+                   (VOID **) &StandardLib
+                   );
+
+  if (EFI_ERROR(Status)) {
+    StandardLib->RecordAssertion (
+                   StandardLib,
+                   EFI_TEST_ASSERTION_FAILED,
+                   gTestGenericFailureGuid,
+                   L"BS.HandleProtocol - Handle standard test library",
+                   L"%a:%d:Status - %r",
+                   __FILE__,
+                   (UINTN)__LINE__,
+                   Status
+                   );
+    return Status;
+  }
+
+  DebugSupport = (EFI_DEBUG_SUPPORT_PROTOCOL *)ClientInterface;
+
+  if (DebugSupport->Isa != PlatformIsa) {
+    return EFI_SUCCESS;
+  }
+
+  Status = DebugSupport->GetMaximumProcessorIndex (DebugSupport, &MaxProcessorIndex);
+  if (EFI_ERROR(Status)) {
+    StandardLib->RecordAssertion (
+                   StandardLib,
+                   EFI_TEST_ASSERTION_FAILED,
+                   gTestGenericFailureGuid,
+                   L"EFI_DEBUG_SUPPORT_PROTOCOL.GetMaximumProcessorIndex",
+                   L"%a:%d:Status - %r",
+                   __FILE__,
+                   (UINTN)__LINE__,
+                   Status
+                   );
+    return Status;
+  }
+
+  for (ProcessorIndex = 0; ProcessorIndex <= MaxProcessorIndex; ProcessorIndex++) {
+
+    //
+    // Assertion Point 3.5.2.1
+    // Invoke InvalidateInstructionCache and verify interface correctness.
+    //
+
+    // The Physical base of the memory range to be invalidated.
+    Start  = 0x0;
+
+    // The minimum number of bytes in the processor's instruction cache to be invalidated.
+    Length = 0x0;
+
+    Status = DebugSupport->InvalidateInstructionCache (DebugSupport, ProcessorIndex, (VOID*)&Start, Length);
+
+    if (EFI_ERROR(Status)) {
+      AssertionType = EFI_TEST_ASSERTION_FAILED;
+    } else {
+      AssertionType = EFI_TEST_ASSERTION_PASSED;
+    }
+
+    StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gDebugSupportBBTestFunctionAssertionGuid015,
+                 L"EFI_DEBUG_SUPPORT_PROTOCOL.InvalidateInstructionCache - Invoke this function and verify interface correctness",
+                 L"%a:%d:Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+  }
+
+  return EFI_SUCCESS;
+}
+
diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
new file mode 100644
index 00000000..c27c0c0c
--- /dev/null
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
@@ -0,0 +1,276 @@
+/** @file
+
+  Copyright 2006 - 2016 Unified EFI, Inc.<BR>
+  Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at 
+  http://opensource.org/licenses/bsd-license.php
+ 
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ 
+**/
+/*++
+
+Module Name:
+
+  DebugSupportBBExceptionCallbackFunction.c
+
+Abstract:
+
+  Interface Function Test Cases of Debug Support Protocol
+
+--*/
+
+
+#include "DebugSupportBBTestMain.h"
+
+extern volatile  UINTN InvokedExceptionCallback;
+extern volatile  UINTN InvokedPeriodicCallback;
+
+extern EFI_INSTRUCTION_SET_ARCHITECTURE PlatformIsa;
+
+void
+SoftwareBreak (
+  void
+  )
+{
+  // Not ported to ARM yet
+  ASSERT (FALSE);
+}
+
+/**
+ *  Entrypoint for EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback() Function Test.
+ *  @param This a pointer of EFI_BB_TEST_PROTOCOL.
+ *  @param ClientInterface a pointer to the interface to be tested.
+ *  @param TestLevel test "thoroughness" control.
+ *  @param SupportHandle a handle containing protocols required.
+ *  @return EFI_SUCCESS Finish the test successfully.
+ */
+//
+// TDS 3.4
+//
+EFI_STATUS
+BBTestRegisterExceptionCallbackFunctionManualTest (
+  IN EFI_BB_TEST_PROTOCOL       *This,
+  IN VOID                       *ClientInterface,
+  IN EFI_TEST_LEVEL             TestLevel,
+  IN EFI_HANDLE                 SupportHandle
+  )
+{
+  EFI_STANDARD_TEST_LIBRARY_PROTOCOL   *StandardLib;
+  EFI_STATUS                           Status;
+  EFI_DEBUG_SUPPORT_PROTOCOL           *DebugSupport;
+  EFI_TEST_ASSERTION                   AssertionType;
+
+  DebugSupport = (EFI_DEBUG_SUPPORT_PROTOCOL *)ClientInterface;
+
+  if (DebugSupport->Isa != PlatformIsa) {
+    return EFI_SUCCESS;
+  }
+
+  //
+  // Get the Standard Library Interface
+  //
+  Status = gtBS->HandleProtocol (
+                   SupportHandle,
+                   &gEfiStandardTestLibraryGuid,
+                   (VOID **) &StandardLib
+                   );
+
+  if (EFI_ERROR(Status)) {
+    StandardLib->RecordAssertion (
+                   StandardLib,
+                   EFI_TEST_ASSERTION_FAILED,
+                   gTestGenericFailureGuid,
+                   L"BS.HandleProtocol - Handle standard test library",
+                   L"%a:%d:Status - %r",
+                   __FILE__,
+                   (UINTN)__LINE__,
+                   Status
+                   );
+    return Status;
+  }
+
+  //
+  // Assertion Point 3.4.2.1
+  // Invoke RegisterExceptionCallback() to install an interrupt handler function.
+  //
+  InvokedExceptionCallback = FALSE;
+  // FIXME: Is it normal that we use EXCEPT_IA32_BREAKPOINT here?
+  // Shouldn't we define proper constants for ARM exceptions in DebugSupportProtocol.h file?
+  Status = DebugSupport->RegisterExceptionCallback (DebugSupport, 0, ExceptionCallback, EXCEPT_IA32_BREAKPOINT);
+
+  if ((Status == EFI_SUCCESS) || (Status == EFI_ALREADY_STARTED)) {
+    AssertionType = EFI_TEST_ASSERTION_PASSED;
+  } else {
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gDebugSupportBBTestFunctionAssertionGuid009,
+                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Invoke this function and verify interface correctness",
+                 L"%a:%d:Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+  //
+  // If the callback function is already registed, return
+  //
+  if (EFI_ERROR(Status)) {
+    return EFI_SUCCESS;
+  }
+
+  //
+  // Test the callback function registed.
+  //
+
+  //
+  // Call SoftwareBreak to invoke the interrupt handler function.
+  //
+  SoftwareBreak ();
+
+  if (InvokedExceptionCallback == FALSE) {
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  } else {
+    AssertionType = EFI_TEST_ASSERTION_PASSED;
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gDebugSupportBBTestFunctionAssertionGuid010,
+                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Verify the callback function was invoked.",
+                 L"%a:%d:Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+  //
+  // Assertion Point 3.4.2.2
+  // Invoke RegisterPeriodicCallback() to install the Periodic interrupt handler function.
+  // Verify the two callback functions can be both invoked.
+  //
+  InvokedExceptionCallback = FALSE;
+  InvokedPeriodicCallback  = FALSE;
+
+  Status = DebugSupport->RegisterPeriodicCallback (DebugSupport, 0, PeriodicCallback);
+  if (EFI_ERROR(Status)) {
+    return Status;
+  }
+
+  //
+  // Wait the PeriodicCallback to be invoked.
+  //
+  gtBS->Stall (500000);
+
+  //
+  // Call SoftwareBreak to invoke the interrupt handler function.
+  //
+  SoftwareBreak ();
+
+  if ((InvokedExceptionCallback == TRUE) && (InvokedPeriodicCallback == TRUE)) {
+    AssertionType = EFI_TEST_ASSERTION_PASSED;
+  } else {
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gDebugSupportBBTestFunctionAssertionGuid011,
+                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Verify the two callback functions can be both invoked.",
+                 L"%a:%d:Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+  //
+  // Uninstall the Periodic callback function.
+  //
+  Status = DebugSupport->RegisterPeriodicCallback (DebugSupport, 0, NULL);
+  if (EFI_ERROR(Status)) {
+    return Status;
+  }
+
+  //
+  // Assertion Point 3.4.2.3
+  // Invoke RegisterExceptionCallback() to install another interrupt handler function.
+  //
+  Status = DebugSupport->RegisterExceptionCallback (DebugSupport, 0, ExceptionCallback1, EXCEPT_IA32_BREAKPOINT);
+
+  if (Status != EFI_ALREADY_STARTED) {
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  } else {
+    AssertionType = EFI_TEST_ASSERTION_PASSED;
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gDebugSupportBBTestFunctionAssertionGuid012,
+                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Register another callback function.",
+                 L"%a:%d:Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+  //
+  // Assertion Point 3.4.2.4
+  // Invoke RegisterExceptionCallback() to unstall the interrupt handler function.
+  //
+  Status = DebugSupport->RegisterExceptionCallback (DebugSupport, 0, NULL, EXCEPT_IA32_BREAKPOINT);
+
+  if (EFI_ERROR(Status)) {
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  } else {
+    AssertionType = EFI_TEST_ASSERTION_PASSED;
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gDebugSupportBBTestFunctionAssertionGuid013,
+                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Invoke this function to uninstall the interrupt handler function",
+                 L"%a:%d:Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+  InvokedExceptionCallback = FALSE;
+
+  //
+  // Call SoftwareBreak to invoke the interrupt handler function.
+  //
+  SoftwareBreak ();
+
+  if (InvokedExceptionCallback != FALSE) {
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  } else {
+    AssertionType = EFI_TEST_ASSERTION_PASSED;
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gDebugSupportBBTestFunctionAssertionGuid014,
+                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Verify the callback function wasn't invoked",
+                 L"%a:%d:Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+  return EFI_SUCCESS;
+}
+
diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c
new file mode 100644
index 00000000..8334f601
--- /dev/null
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c
@@ -0,0 +1,30 @@
+/** @file
+
+  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
+  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at 
+  http://opensource.org/licenses/bsd-license.php
+ 
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ 
+**/
+/*++
+
+Module Name:
+
+  PlatformIsa.c
+
+Abstract:
+
+  Platform related Isa definition.
+
+--*/
+
+#include "DebugSupportBBTestMain.h"
+
+EFI_INSTRUCTION_SET_ARCHITECTURE PlatformIsa = IsaAArch64;
+
diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c
new file mode 100644
index 00000000..1c1940e5
--- /dev/null
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c
@@ -0,0 +1,51 @@
+/** @file
+
+  Copyright 2006 - 2010 Unified EFI, Inc.<BR>
+  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at 
+  http://opensource.org/licenses/bsd-license.php
+ 
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ 
+**/
+/**
+ *  Ipf Source file for Mask/Unmask TimerInterrupt.
+ */
+/*++
+
+Module Name:
+  TimerInterrupt.c
+
+Abstract:
+  Ipf Source file for Mask/Unmask TimerInterrupt.
+
+Author(s):
+
+
+References:
+  EFI Specification 1.10
+  EFI/Tiano DXE Test Case Writer's Guide
+
+Revision History:
+  Initial 10-20-2002
+  Version 0.01
+
+--*/
+
+#include "UsbHcTest.h"
+
+VOID MaskTimerInterrupt()
+{
+  // TBD
+  return;
+}
+
+VOID UnmaskTimerInterrupt()
+{
+  // TBD
+  return;
+}
diff --git a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h
new file mode 100644
index 00000000..ff781aee
--- /dev/null
+++ b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h
@@ -0,0 +1,55 @@
+/** @file
+
+  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
+  Copyright (c) 2010 - 2012, ARM Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at 
+  http://opensource.org/licenses/bsd-license.php
+ 
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ 
+**/
+/*++
+
+Module Name:
+
+  EntsLibPlat.h
+
+Abstract:
+
+  AArch64 specific defines
+
+--*/
+
+#ifndef _EFI_LIB_PLAT_H_
+#define _EFI_LIB_PLAT_H_
+
+#define MIN_ALIGNMENT_SIZE  8
+
+VOID
+EntsInitializeLibPlatform (
+  IN EFI_HANDLE           ImageHandle,
+  IN EFI_SYSTEM_TABLE     *SystemTable
+  )
+/*++
+
+Routine Description:
+
+  Initialize platform.
+
+Arguments:
+
+  ImageHandle           - The image handle.
+  SystemTable           - The system table.
+
+Returns:
+
+  None.
+
+--*/
+;
+
+#endif
diff --git a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c
new file mode 100644
index 00000000..70a509a4
--- /dev/null
+++ b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c
@@ -0,0 +1,55 @@
+/** @file
+
+  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
+  Copyright (c) 2010 - 2012, ARM Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at 
+  http://opensource.org/licenses/bsd-license.php
+ 
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ 
+**/
+/*++
+
+Module Name:
+
+  InitPlat.c
+
+Abstract:
+
+  Math routines for compatibility with native EFI library routines.
+
+--*/
+
+#include "Efi.h"
+#include "EntsLibPlat.h"
+
+VOID
+EntsInitializeLibPlatform (
+  IN EFI_HANDLE           ImageHandle,
+  IN EFI_SYSTEM_TABLE     *SystemTable
+  )
+/*++
+
+Routine Description:
+
+  Initialize platform.
+
+Arguments:
+
+  ImageHandle           - The image handle.
+  SystemTable           - The system table.
+
+Returns:
+
+  None.
+
+--*/
+{
+  //
+  // No platform-specific initializations
+  //
+}
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg
  2020-12-01 16:17 [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg Daniel Schaefer
  2020-12-01 16:17 ` [edk2-test PATCH v1 1/2] SctPkg: Add RISCV64 support Daniel Schaefer
  2020-12-01 16:17 ` [edk2-test PATCH v1 2/2] SctPkg: Enable RISCV64 support using AARCH64 sources Daniel Schaefer
@ 2020-12-01 16:59 ` Heinrich Schuchardt
  2020-12-01 17:11   ` Daniel Schaefer
  2020-12-02 12:07 ` Leif Lindholm
  3 siblings, 1 reply; 18+ messages in thread
From: Heinrich Schuchardt @ 2020-12-01 16:59 UTC (permalink / raw)
  To: Daniel Schaefer, devel
  Cc: Leif Lindholm, Abner Chang, Gilbert Chen, Eric Jin,
	G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

On 12/1/20 5:17 PM, Daniel Schaefer wrote:
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042
>
> With this patch series we can build the UEFI SCT for RISCV64. It was confirmed
> to be working on the U-Boot UEFI implementation by Heinrich.
> It hasn't been tested on EDK2 yet.
>
> Build requirements are the same as for the EDK2 RISCV64 port and detailed here:
> https://github.com/riscv/riscv-uefi-edk2-docs
>
> The second patch is a big one because it adds architecture specific files by
> copying them from the Aarch64 directory. Only a single file, an assembly file
> needed modifications. I'm not sure why the other ones are in an architecture
> specific directory. They're all C files and seem to be generic. We can probably
> unify them.

Hello Daniel,

thanks a lot for your patches.

You address the uefi-sct/SctPkg/TestCase/UEFI/EFI directory.

Are you planning future patches for uefi-sct/SctPkg/TestCase/UEFI/IHV too?

Best regards

Heinrich

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg
  2020-12-01 16:59 ` [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg Heinrich Schuchardt
@ 2020-12-01 17:11   ` Daniel Schaefer
  2020-12-01 17:37     ` Heinrich Schuchardt
  0 siblings, 1 reply; 18+ messages in thread
From: Daniel Schaefer @ 2020-12-01 17:11 UTC (permalink / raw)
  To: Heinrich Schuchardt, devel
  Cc: Leif Lindholm, Abner Chang, Gilbert Chen, Eric Jin,
	G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

On 12/2/20 12:59 AM, Heinrich Schuchardt wrote:
> On 12/1/20 5:17 PM, Daniel Schaefer wrote:
>> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042
>>
>> With this patch series we can build the UEFI SCT for RISCV64. It was confirmed
>> to be working on the U-Boot UEFI implementation by Heinrich.
>> It hasn't been tested on EDK2 yet.
>>
>> Build requirements are the same as for the EDK2 RISCV64 port and detailed here:
>> https://github.com/riscv/riscv-uefi-edk2-docs
>>
>> The second patch is a big one because it adds architecture specific files by
>> copying them from the Aarch64 directory. Only a single file, an assembly file
>> needed modifications. I'm not sure why the other ones are in an architecture
>> specific directory. They're all C files and seem to be generic. We can probably
>> unify them.
> 
> Hello Daniel,
> 
> thanks a lot for your patches.
> 
> You address the uefi-sct/SctPkg/TestCase/UEFI/EFI directory.
> 
> Are you planning future patches for uefi-sct/SctPkg/TestCase/UEFI/IHV too?

I grepped the repo for strings related to arm64 and aarch64. I ported what I found.
Do you see anything that's not ported?

The only thing I see, is in Protocol/UsbIo/BlackBoxTest/UsbIoTestConformance.c
where some code is not used for ARM because:

   // Note: This function uses the EDKII Glu library from EDKII compatibility pkg.

   // which is not ported to ARM yet. Hence for the time being just return success.


I'm not yet sure what library that's referring to, but most likely it's also
not implemented for RISC-V.

Thanks for testing!
Does the SCT result look like what you expect? Or are some tests failing that you expect to succeed?

- Daniel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg
  2020-12-01 17:11   ` Daniel Schaefer
@ 2020-12-01 17:37     ` Heinrich Schuchardt
  2021-02-08 14:30       ` Daniel Schaefer
  0 siblings, 1 reply; 18+ messages in thread
From: Heinrich Schuchardt @ 2020-12-01 17:37 UTC (permalink / raw)
  To: Daniel Schaefer, devel
  Cc: Leif Lindholm, Abner Chang, Gilbert Chen, Eric Jin,
	G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

On 12/1/20 6:11 PM, Daniel Schaefer wrote:
> On 12/2/20 12:59 AM, Heinrich Schuchardt wrote:
>> On 12/1/20 5:17 PM, Daniel Schaefer wrote:
>>> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042
>>>
>>> With this patch series we can build the UEFI SCT for RISCV64. It was
>>> confirmed
>>> to be working on the U-Boot UEFI implementation by Heinrich.
>>> It hasn't been tested on EDK2 yet.
>>>
>>> Build requirements are the same as for the EDK2 RISCV64 port and
>>> detailed here:
>>> https://github.com/riscv/riscv-uefi-edk2-docs
>>>
>>> The second patch is a big one because it adds architecture specific
>>> files by
>>> copying them from the Aarch64 directory. Only a single file, an
>>> assembly file
>>> needed modifications. I'm not sure why the other ones are in an
>>> architecture
>>> specific directory. They're all C files and seem to be generic. We
>>> can probably
>>> unify them.
>>
>> Hello Daniel,
>>
>> thanks a lot for your patches.
>>
>> You address the uefi-sct/SctPkg/TestCase/UEFI/EFI directory.
>>
>> Are you planning future patches for uefi-sct/SctPkg/TestCase/UEFI/IHV
>> too?
>
> I grepped the repo for strings related to arm64 and aarch64. I ported
> what I found.
> Do you see anything that's not ported?

uefi-sct/SctPkg/UEFI/IHV_SCT.dsc is the only IHV related file with
AARCH64 in it and that one is covered by your patch series.

>
> The only thing I see, is in
> Protocol/UsbIo/BlackBoxTest/UsbIoTestConformance.c
> where some code is not used for ARM because:
>
>   // Note: This function uses the EDKII Glu library from EDKII
> compatibility pkg.
>
>   // which is not ported to ARM yet. Hence for the time being just
> return success.
>
>
> I'm not yet sure what library that's referring to, but most likely it's
> also
> not implemented for RISC-V.

I assume this refers to:
https://github.com/tianocore/edk/tree/master/Foundation/Library/EdkIIGlueLib

The files of this library are in edk2/MdePkg/Library now.

>
> Thanks for testing!
> Does the SCT result look like what you expect? Or are some tests failing
> that you expect to succeed?

Not all tests have run yet. Running SCT on QEMU is really slow.

But from what I can see there is no difference to AARCH64 results on QEMU.

Best regards

Heinrich

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-devel] [edk2-test PATCH v1 1/2] SctPkg: Add RISCV64 support
  2020-12-01 16:17 ` [edk2-test PATCH v1 1/2] SctPkg: Add RISCV64 support Daniel Schaefer
@ 2020-12-02 11:44   ` Leif Lindholm
  2021-02-08 15:09     ` Daniel Schaefer
  0 siblings, 1 reply; 18+ messages in thread
From: Leif Lindholm @ 2020-12-02 11:44 UTC (permalink / raw)
  To: devel, daniel.schaefer
  Cc: Heinrich Schuchardt, Abner Chang, Gilbert Chen, Eric Jin,
	G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

On Wed, Dec 02, 2020 at 00:17:51 +0800, Daniel Schaefer wrote:
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042
> 
> TODO: Need to check whether we can avoid copying Aarch64 sources.
> 
> Cc: Leif Lindholm <leif@nuviainc.com>
> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Cc: Abner Chang <abner.chang@hpe.com>
> Cc: Gilbert Chen <gilbert.chen@hpe.com>
> Cc: Eric Jin <eric.jin@intel.com>
> Cc: G Edhaya Chandran <Edhaya.Chandran@arm.com>
> Cc: Barton Gao <gaojie@byosoft.com.cn>
> Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
> Signed-off-by: Daniel Schaefer <daniel.schaefer@hpe.com>
> ---
>  uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h                                      |  3 +
>  uefi-sct/SctPkg/Library/SctLib/SctLib.inf                                                   |  6 ++
>  uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf                                                    |  6 ++
>  uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf                                              |  7 +++
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf |  6 ++
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf               |  4 ++
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf                 |  4 ++
>  uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf                    |  5 ++
>  uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile                                             |  3 +
>  uefi-sct/SctPkg/UEFI/IHV_SCT.dsc                                                            | 14 ++++-
>  uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h                                                | 62 +++++++++++++++++++-
>  uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc                                                           | 14 ++++-
>  uefi-sct/SctPkg/build.sh                                                                    | 10 +++-
>  13 files changed, 140 insertions(+), 4 deletions(-)
> 
> diff --git a/uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h b/uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h
> index a7815580..3a7c8f31 100644
> --- a/uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h
> +++ b/uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h
> @@ -32,6 +32,9 @@
>  #elif defined(EFIAARCH64)
>    #define INSTALL_SCT_PLATFORM_SHORT_NAME   L"aarch64"
>    #define INSTALL_SCT_PLATFORM_NAME         L"AARCH64"
> +#elif defined(EFIRISCV64)
> +  #define INSTALL_SCT_PLATFORM_SHORT_NAME   L"riscv64"
> +  #define INSTALL_SCT_PLATFORM_NAME         L"RISCV64"
>  #else
>    #error "Architecture not supported"
>  #endif
> diff --git a/uefi-sct/SctPkg/Library/SctLib/SctLib.inf b/uefi-sct/SctPkg/Library/SctLib/SctLib.inf
> index 23cb77fb..6f59d974 100644
> --- a/uefi-sct/SctPkg/Library/SctLib/SctLib.inf
> +++ b/uefi-sct/SctPkg/Library/SctLib/SctLib.inf
> @@ -62,6 +62,12 @@
>    Aarch64/initplat.c
>    Math.c
>  
> +# TODO: Copied source from AARCH64, need to check if they need to be adjusted

TODOs need to go, throughout.

> +[sources.RISCV64]
> +  Riscv64/SctLibPlat.h
> +  Riscv64/initplat.c
> +  Math.c
> +
>  [sources.ia32]
>    ia32/SctLibPlat.h
>    ia32/initplat.c
> diff --git a/uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf b/uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf
> index 7aca6e30..66de4cac 100644
> --- a/uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf
> +++ b/uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf
> @@ -39,6 +39,12 @@
>    Aarch64/GoVirtual.asm | RVCT
>    Aarch64/GoVirtual.S | GCC
>  
> +# TODO: Copied source from AARCH64, need to check if they need to be adjusted
> +#       ASM is adjusted but not sure if it is correct
> +[sources.RISCV64]
> +  Riscv64/VirtualMemory.c
> +  Riscv64/GoVirtual.S | GCC
> +
>  [sources.ia32]
>    ia32/VirtualMemory.c
>    ia32/GoVirtual.asm | MSFT
> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf b/uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf
> index ad0eb0f8..bc0ade5b 100644
> --- a/uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf
> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf
> @@ -69,6 +69,13 @@
>    Aarch64/Dump.c
>    Aarch64/Debug.c
>  
> +# TODO: Copied source from AARCH64, need to check if they need to be adjusted
> +[sources.RISCV64]
> +  Riscv64/Io.c
> +  Riscv64/Io.h
> +  Riscv64/Dump.c
> +  Riscv64/Debug.c
> +
>  [sources.common]
>    Guid.h
>    Guid.c
> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf
> index 799f86fd..7010c7f1 100644
> --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf
> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf
> @@ -67,6 +67,12 @@
>    Aarch64/DebugSupportBBTestExceptionCallbackFunction.c
>    Aarch64/DebugSupportBBTestCacheFunction.c
>  
> +# TODO: Copied source from AARCH64, need to check if they need to be adjusted
> +[sources.RISCV64]
> +  Riscv64/PlatformIsa.c
> +  Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
> +  Riscv64/DebugSupportBBTestCacheFunction.c
> +
>  [Packages]
>    SctPkg/SctPkg.dec
>    SctPkg/UEFI/UEFI.dec
> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf
> index e8118739..e42acd29 100644
> --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf
> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf
> @@ -55,6 +55,10 @@
>  #[sources.Aarch64]
>  #  IPF/TimerInterrupt.c
>  
> +# TODO: Seems like almost all archs can use the IPF code, need to check
> +[sources.Riscv64]
> +  IPF/TimerInterrupt.c
> +
>  [Packages]
>    MdePkg/MdePkg.dec
>    SctPkg/SctPkg.dec
> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf
> index efc438c1..0d47536f 100644
> --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf
> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf
> @@ -55,6 +55,10 @@
>  [sources.Aarch64]
>    Aarch64/TimerInterrupt.c
>  
> +# TODO: Copied source from AARCH64, need to check if they need to be adjusted
> +[sources.RISCV64]
> +  Riscv64/TimerInterrupt.c
> +
>  [Packages]
>    MdePkg/MdePkg.dec
>    SctPkg/SctPkg.dec
> diff --git a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf
> index 23f12d1a..1b2a92f2 100644
> --- a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf
> +++ b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf
> @@ -66,6 +66,11 @@
>    Aarch64/EntsLibPlat.h
>    Aarch64/InitPlat.c
>  
> +# TODO: Copied source from AARCH64, need to check if they need to be adjusted
> +[sources.RISCV64]
> +  Riscv64/EntsLibPlat.h
> +  Riscv64/InitPlat.c
> +
>  [Packages]
>    MdePkg/MdePkg.dec
>    SctPkg/SctPkg.dec
> diff --git a/uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile b/uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile
> index c235f313..e49284e7 100644
> --- a/uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile
> +++ b/uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile
> @@ -31,6 +31,9 @@ ifndef ARCH
>    ifneq (,$(findstring arm,$(uname_m)))
>      ARCH=ARM
>    endif
> +  ifneq (,$(findstring riscv64,$(uname_m)))
> +    ARCH=RISCV64
> +  endif
>    ifndef ARCH
>      $(info Could not detected ARCH from uname results)
>      $(error ARCH is not defined!)
> diff --git a/uefi-sct/SctPkg/UEFI/IHV_SCT.dsc b/uefi-sct/SctPkg/UEFI/IHV_SCT.dsc
> index f9e86264..2f373c5f 100644
> --- a/uefi-sct/SctPkg/UEFI/IHV_SCT.dsc
> +++ b/uefi-sct/SctPkg/UEFI/IHV_SCT.dsc
> @@ -42,7 +42,7 @@
>    PLATFORM_VERSION               = 0.1
>    DSC_SPECIFICATION              = 0x00010005
>    OUTPUT_DIRECTORY               = Build/IhvSct
> -  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64
> +  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64|RISCV64
>    BUILD_TARGETS                  = DEBUG|RELEASE
>    SKUID_IDENTIFIER               = DEFAULT
>  
> @@ -109,6 +109,12 @@
>    *_*_AARCH64_PP_FLAGS         = -D EFIAARCH64 $(GCC_VER_MACRO)
>    RVCT:*_*_AARCH64_DLINK_FLAGS = --muldefweak
>  
> +  *_*_RISCV64_CC_FLAGS         = -D EFIRISCV64 $(GCC_VER_MACRO)
> +  GCC:*_*_RISCV64_CC_FLAGS  = -D EFIRISCV64 $(GCC_VER_MACRO) -ffreestanding -nostdinc -nostdlib -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error

These flags do not look RISCV64-specific.
If there are bugs to be fixed in common code, they should be fixed.
If there are too many to usefully test, then the flags should be set
for
GCC:*_*_*_CC_FLAGS

> +  *_*_RISCV64_VFRPP_FLAGS      = -D EFIRISCV64 $(GCC_VER_MACRO)
> +  *_*_RISCV64_APP_FLAGS        = -D EFIRISCV64 $(GCC_VER_MACRO)
> +  *_*_RISCV64_PP_FLAGS         = -D EFIRISCV64 $(GCC_VER_MACRO)
> +
>    DEBUG_*_*_CC_FLAGS  = -DEFI_DEBUG
>    RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG
>  
> @@ -124,6 +130,9 @@
>  [Libraries.AARCH64]
>    ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
>  
> +[Libraries.RISCV64]
> +  ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
> +
>  [Libraries.IA32,Libraries.X64]
>  
>  [LibraryClasses.common]
> @@ -146,6 +155,9 @@
>  [LibraryClasses.AARCH64]
>    NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
>  
> +[LibraryClasses.RISCV64]
> +  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
> +
>  [LibraryClasses.IA32]
>  
>  ###############################################################################
> diff --git a/uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h b/uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h
> index 7fba87ae..fb11bda4 100644
> --- a/uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h
> +++ b/uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h
> @@ -607,6 +607,60 @@ typedef struct {
>    UINT64  FAR;  // Fault Address Register
>  } EFI_SYSTEM_CONTEXT_AARCH64;
>  
> +///
> +/// RISC-V processor exception types.
> +///
> +#define EXCEPT_RISCV_INST_MISALIGNED              0
> +#define EXCEPT_RISCV_INST_ACCESS_FAULT            1
> +#define EXCEPT_RISCV_ILLEGAL_INST                 2
> +#define EXCEPT_RISCV_BREAKPOINT                   3
> +#define EXCEPT_RISCV_LOAD_ADDRESS_MISALIGNED      4
> +#define EXCEPT_RISCV_LOAD_ACCESS_FAULT            5
> +#define EXCEPT_RISCV_STORE_AMO_ADDRESS_MISALIGNED 6
> +#define EXCEPT_RISCV_STORE_AMO_ACCESS_FAULT       7
> +#define EXCEPT_RISCV_ENV_CALL_FROM_UMODE          8
> +#define EXCEPT_RISCV_ENV_CALL_FROM_SMODE          9
> +#define EXCEPT_RISCV_ENV_CALL_FROM_HMODE          10
> +#define EXCEPT_RISCV_ENV_CALL_FROM_MMODE          11
> +
> +#define EXCEPT_RISCV_SOFTWARE_INT       0x0
> +#define EXCEPT_RISCV_TIMER_INT          0x1
> +
> +typedef struct {
> +  UINT64  X0;
> +  UINT64  X1;
> +  UINT64  X2;
> +  UINT64  X3;
> +  UINT64  X4;
> +  UINT64  X5;
> +  UINT64  X6;
> +  UINT64  X7;
> +  UINT64  X8;
> +  UINT64  X9;
> +  UINT64  X10;
> +  UINT64  X11;
> +  UINT64  X12;
> +  UINT64  X13;
> +  UINT64  X14;
> +  UINT64  X15;
> +  UINT64  X16;
> +  UINT64  X17;
> +  UINT64  X18;
> +  UINT64  X19;
> +  UINT64  X20;
> +  UINT64  X21;
> +  UINT64  X22;
> +  UINT64  X23;
> +  UINT64  X24;
> +  UINT64  X25;
> +  UINT64  X26;
> +  UINT64  X27;
> +  UINT64  X28;
> +  UINT64  X29;
> +  UINT64  X30;
> +  UINT64  X31;
> +} EFI_SYSTEM_CONTEXT_RISCV64;
> +
>  //
>  // Universal EFI_SYSTEM_CONTEXT definition
>  //
> @@ -618,6 +672,7 @@ union {
>    EFI_SYSTEM_CONTEXT_IPF                  *SystemContextIpf;
>    EFI_SYSTEM_CONTEXT_ARM                  *SystemContextArm;
>    EFI_SYSTEM_CONTEXT_AARCH64              *SystemContextAArch64;
> +  EFI_SYSTEM_CONTEXT_RISCV64              *SystemContextRiscV64;
>  } EFI_SYSTEM_CONTEXT;
>  
>  //
> @@ -645,6 +700,10 @@ VOID
>  #define IMAGE_FILE_MACHINE_EBC             0x0EBC
>  #define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED  0x01c2
>  #define IMAGE_FILE_MACHINE_ARM64           0xAA64
> +#define IMAGE_FILE_MACHINE_RISCV32         0x5032
> +#define IMAGE_FILE_MACHINE_RISCV64         0x5064
> +#define IMAGE_FILE_MACHINE_RISCV128        0x5128

This set is not adding support for RISCV32/RISCV128, so no real point
adding those #defines.

> +
>  
>  typedef
>  enum {
> @@ -653,7 +712,8 @@ enum {
>    IsaIpf  = IMAGE_FILE_MACHINE_IA64,
>    IsaEbc  = IMAGE_FILE_MACHINE_EBC,
>    IsaArm  = IMAGE_FILE_MACHINE_ARMTHUMB_MIXED, ///< 0x01c2
> -  IsaAArch64  = IMAGE_FILE_MACHINE_ARM64       ///< 0xAA64
> +  IsaAArch64  = IMAGE_FILE_MACHINE_ARM64,      ///< 0xAA64
> +  IsaRiscv64  = IMAGE_FILE_MACHINE_RISCV64

Add the doxygen comment to match the others.

>  } EFI_INSTRUCTION_SET_ARCHITECTURE;
>  
>  typedef struct _EFI_DEBUG_SUPPORT_PROTOCOL EFI_DEBUG_SUPPORT_PROTOCOL;;
> diff --git a/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc b/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc
> index 2e97687b..666f06dd 100644
> --- a/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc
> +++ b/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc
> @@ -42,7 +42,7 @@
>    PLATFORM_VERSION               = 0.1
>    DSC_SPECIFICATION              = 0x00010005
>    OUTPUT_DIRECTORY               = Build/UefiSct
> -  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64
> +  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64|RISCV64
>    BUILD_TARGETS                  = DEBUG|RELEASE
>    SKUID_IDENTIFIER               = DEFAULT
>    
> @@ -112,6 +112,12 @@
>    *_*_AARCH64_PP_FLAGS         = -D EFIAARCH64 $(GCC_VER_MACRO)
>    RVCT:*_*_AARCH64_DLINK_FLAGS = --muldefweak
>  
> +  *_*_RISCV64_CC_FLAGS         = -D EFIRISCV64 $(GCC_VER_MACRO)
> +  GCC:*_*_RISCV64_CC_FLAGS     = -D EFIRISCV64 $(GCC_VER_MACRO) -ffreestanding -nostdinc -nostdlib -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error

Same as above.

/
    Leif

> +  *_*_RISCV64_VFRPP_FLAGS      = -D EFIRISCV64 $(GCC_VER_MACRO)
> +  *_*_RISCV64_APP_FLAGS        = -D EFIRISCV64 $(GCC_VER_MACRO)
> +  *_*_RISCV64_PP_FLAGS         = -D EFIRISCV64 $(GCC_VER_MACRO)
> +
>    DEBUG_*_*_CC_FLAGS  = -DEFI_DEBUG
>    RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG
>  
> @@ -129,6 +135,9 @@
>  [Libraries.AARCH64]
>    ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
>  
> +[Libraries.RISCV64]
> +  ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
> +
>  [LibraryClasses.common]
>    UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
>    UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
> @@ -157,6 +166,9 @@
>  [LibraryClasses.AARCH64]
>    NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
>  
> +[LibraryClasses.RISCV64]
> +  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
> +
>  ###############################################################################
>  #
>  # These are the components that will be built by the master makefile
> diff --git a/uefi-sct/SctPkg/build.sh b/uefi-sct/SctPkg/build.sh
> index cad17ccd..3d61daed 100755
> --- a/uefi-sct/SctPkg/build.sh
> +++ b/uefi-sct/SctPkg/build.sh
> @@ -22,6 +22,8 @@ function get_build_arch
>  	        BUILD_ARCH=ARM;;
>  	    aarch64*)
>  	        BUILD_ARCH=AARCH64;;
> +	    riscv64*)
> +	        BUILD_ARCH=RISCV64;;
>  	    *)
>  	        BUILD_ARCH=other;;
>  	esac
> @@ -47,6 +49,12 @@ function set_cross_compile
>  	    else
>  	        TEMP_CROSS_COMPILE=arm-linux-gnueabihf-
>  	    fi
> +	elif [ "$SCT_TARGET_ARCH" == "RISCV64" ]; then
> +	    if [ X"$CROSS_COMPILE_64" != X"" ]; then
> +	        TEMP_CROSS_COMPILE="$CROSS_COMPILE_64"
> +	    else
> +	        TEMP_CROSS_COMPILE=riscv64-unknown-elf-
> +	    fi
>  	else
>  	    echo "Unsupported target architecture '$SCT_TARGET_ARCH'!" >&2
>  	fi
> @@ -110,7 +118,7 @@ PrintUsage() {
>  	#Print Help
>  	#
>  	echo "Usage:"
> -	echo "    $0 <architecture (ARM, AARCH64, X64, etc)> \
> +	echo "    $0 <architecture (ARM, AARCH64, X64, RISCV64, etc)> \
>  <toolchain name (RVCT or ARMGCC or GCC*)> \
>  [build type (RELEASE OR DEBUG, DEFAULT: DEBUG)]"
>  }
> -- 
> 2.28.0
> 
> 
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-devel] [edk2-test PATCH v1 2/2] SctPkg: Enable RISCV64 support using AARCH64 sources
  2020-12-01 16:17 ` [edk2-test PATCH v1 2/2] SctPkg: Enable RISCV64 support using AARCH64 sources Daniel Schaefer
@ 2020-12-02 12:04   ` Leif Lindholm
  2021-02-08 15:09     ` Daniel Schaefer
  0 siblings, 1 reply; 18+ messages in thread
From: Leif Lindholm @ 2020-12-02 12:04 UTC (permalink / raw)
  To: devel, daniel.schaefer
  Cc: Heinrich Schuchardt, Abner Chang, Gilbert Chen, Eric Jin,
	G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

On Wed, Dec 02, 2020 at 00:17:52 +0800, Daniel Schaefer wrote:
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042
> 
> TODO: Need to check whether we can avoid copying Aarch64 sources.
> 
> Cc: Leif Lindholm <leif@nuviainc.com>
> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Cc: Abner Chang <abner.chang@hpe.com>
> Cc: Gilbert Chen <gilbert.chen@hpe.com>
> Cc: Eric Jin <eric.jin@intel.com>
> Cc: G Edhaya Chandran <Edhaya.Chandran@arm.com>
> Cc: Barton Gao <gaojie@byosoft.com.cn>
> Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
> Signed-off-by: Daniel Schaefer <daniel.schaefer@hpe.com>
> ---
>  uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h                                                                        |  32 +++
>  uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c                                                                          |  45 ++++
>  uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S                                                                           |  45 ++++
>  uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c                                                                       | 182 +++++++++++++
>  uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c                                                                            |  88 +++++++
>  uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c                                                                             |  68 +++++
>  uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c                                                                               | 134 ++++++++++
>  uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h                                                                               |  48 ++++
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c             | 137 ++++++++++
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c | 276 ++++++++++++++++++++
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c                                 |  30 +++
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c                                     |  51 ++++
>  uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h                                         |  55 ++++
>  uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c                                            |  55 ++++
>  14 files changed, 1246 insertions(+)
> 
> diff --git a/uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h b/uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h
> new file mode 100644
> index 00000000..ee7c656b
> --- /dev/null
> +++ b/uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h
> @@ -0,0 +1,32 @@
> +/** @file
> +
> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
> +  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD License
> +  which accompanies this distribution.  The full text of the license may be found at 
> +  http://opensource.org/licenses/bsd-license.php
> + 
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> + 
> +**/
> +/*++
> +
> +Module Name:
> +
> +  SctLibPlat.h
> +
> +Abstract:
> +
> +  AArch64 specific defines

*cough*

> +
> +--*/
> +
> +#ifndef _EFI_LIB_PLAT_H_
> +#define _EFI_LIB_PLAT_H_

No leading _ in macros.

> +
> +#define MIN_ALIGNMENT_SIZE  8
> +
> +#endif
> diff --git a/uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c b/uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c
> new file mode 100644
> index 00000000..a48bb2f3
> --- /dev/null
> +++ b/uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c
> @@ -0,0 +1,45 @@
> +/** @file
> +
> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
> +  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD License
> +  which accompanies this distribution.  The full text of the license may be found at 
> +  http://opensource.org/licenses/bsd-license.php
> + 
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> + 
> +**/
> +/*++
> +
> +Module Name:
> +
> +  initplat.c
> +
> +Abstract:
> +
> +  Math routines for compatibility with native EFI library routines.
> +
> +--*/
> +
> +#include "SctLibInternal.h"
> +
> +VOID
> +InitializeLibPlatform (
> +    IN EFI_HANDLE           ImageHandle,
> +    IN EFI_SYSTEM_TABLE     *SystemTable
> +    )
> +
> +{
> +  // No platform-specific initializations
> +}
> +
> +UINT64
> +SctReadTsc (
> +  VOID
> +  )
> +{
> +  return 0;
> +}
> diff --git a/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
> new file mode 100644
> index 00000000..8bc2c624
> --- /dev/null
> +++ b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
> @@ -0,0 +1,45 @@
> +## @file
> +#
> +#  Copyright 2010 - 2012 Unified EFI, Inc.<BR>
> +#  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
> +#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP.<BR>
> +#
> +#  This program and the accompanying materials
> +#  are licensed and made available under the terms and conditions of the BSD License
> +#  which accompanies this distribution.  The full text of the license may be found at 
> +#  http://opensource.org/licenses/bsd-license.php
> +# 
> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +# 
> +##
> +#
> +#
> +#/*++
> +#
> +# Module Name:
> +#
> +#  GoVirtual.S
> +#
> +#--*/
> +#start of the code section
> +.text
> +/* FIXME: Should alignment be different on Aarch64? */

1) FIXME
2) Aarch64.

> +.align 3
> +
> +.global JumpToTestFunc
> +.type JumpToTestFunc, %function
> +
> +#------------------------------------------------------------------------------
> +# VOID
> +# JumpToTestFunc (
> +#   IN  UINTN  FuncPointer,
> +#   IN  UNITN  ConfigInfo
> +#   )
> +# TODO: Make sure this code is correct

No TODO.
Should this set really be called an RFC?

> +JumpToTestFunc:
> +	mv x2, x0
> +	mv x0, x1
> +
> +	// Jump to Virtual function
> +	jalr x2
> diff --git a/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c
> new file mode 100644
> index 00000000..397b3514
> --- /dev/null
> +++ b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c
> @@ -0,0 +1,182 @@
> +/** @file
> +
> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
> +  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD License
> +  which accompanies this distribution.  The full text of the license may be found at 
> +  http://opensource.org/licenses/bsd-license.php
> + 
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> + 
> +**/
> +/*++
> +
> +Module Name:
> +
> +  VirtualMemory.c
> +
> +--*/
> +
> +#include "SCRTApp.h"
> +
> +#define VIRT_TO_PHYS_OFFSET       (0x80000000)     //2G
> +
> +BOOLEAN     HighAddress = FALSE;
> +UINTN       PageTable   = 0;
> +
> +
> +VOID
> +ConvertRuntimeFuncPtr (
> +  IN OUT UINTN      *VirtualFunc
> +  )
> +/*++
> +
> +Routine Description:
> +
> +  Change RuntimeTestFunc physical address to virtual address
> +
> +Arguments:
> +
> +  VirtualFunc  - On input, RuntimeTestFunc physical address.
> +                 On output, RuntimeTest virtual address.
> +
> +Returns:
> +
> +  NONE
> +
> +--*/
> +{
> +	/*Note: It is presumed that on ARM v5, V6 and V7 architectures
> +	 * the MMU is configured and enabled in PEI phase. As VirtualFunc
> +	 * is already mapped to virtual memory, don't have to do anything here.
> +	 */
> +  /* FIXME: Is it the same on ARM v8? */

FIXME?
(Even if it's copied, it's wrong :)
ARM in general.

> +}
> +
> +
> +EFI_STATUS
> +DoMemoryAllocation (
> +  IN UINTN PhysicalFunc
> +  )
> +/*++
> +
> +Routine Description:
> +
> +  Allocate memory and create the PageTable to set up physical-virtual map.
> +
> +Arguments:
> +
> +  PhysicalFunc  - Physical address where RuntimeTestFunc locates.
> +
> +Returns:
> +
> +  EFI_STATUS
> +
> +--*/
> +{
> +  EFI_STATUS                  Status;
> +  EFI_PHYSICAL_ADDRESS        AllocateMemory;
> +
> +  //create new page tables or use existing page tables.
> +  //
> +  // Allocate PageTable memory close to this Application image location in
> +  // the system memory. In this way, it is safe for page table memory.
> +  //
> +  AllocateMemory = PhysicalFunc;
> +
> +  Status = tBS->AllocatePages (
> +                  AllocateMaxAddress,
> +                  EfiRuntimeServicesData,
> +                  1,
> +                  &AllocateMemory
> +                  );
> +
> +  if (EFI_ERROR(Status)) {
> +    return Status;
> +  }
> +
> +  PageTable = (UINTN)AllocateMemory;
> +  return EFI_SUCCESS;
> +}
> +
> +
> +VOID
> +PrepareVirtualAddressMap (
> +  IN UINTN                       MemoryMapSize,
> +  IN UINTN                       DescriptorSize,
> +  IN EFI_MEMORY_DESCRIPTOR       *MemoryMap,
> +  IN EFI_MEMORY_DESCRIPTOR       *VirtualMemoryMap,
> +  IN OUT UINTN                   *VirtualMapSize
> +  )
> +/*++
> +
> +Routine Description:
> +
> +  Construct VirtualAddressMap from physical address to virtual address
> +
> +Arguments:
> +
> +  MemoryMapSize     - The size, in bytes, of the MemoryMap buffer
> +  DescriptorSize    - The size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR
> +  MemoryMap         - A pointer to the current memory map
> +  VirtualMemoryMap  - A pointer to the modified virtual memory map
> +  VirtualMapSize    - A pointer to the size, in bytes, of the VirtualMemoryMap buffer
> +
> +Returns:
> +
> +  NONE
> +
> +--*/
> +{
> +  UINTN    Index;
> +  *VirtualMapSize        = 0;
> +
> +  //
> +  // Copy entries that need runtime mapping to construct virtualMemoryMap
> +  //
> +  for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {
> +    if ((MemoryMap->Attribute & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) {
> +      SctCopyMem ((VOID *) VirtualMemoryMap, (VOID *) MemoryMap, DescriptorSize);
> +      VirtualMemoryMap->VirtualStart  = VirtualMemoryMap->PhysicalStart;
> +      *VirtualMapSize += DescriptorSize;
> +      VirtualMemoryMap = NextMemoryDescriptor (VirtualMemoryMap, DescriptorSize);
> +    }
> +
> +    MemoryMap = NextMemoryDescriptor (MemoryMap, DescriptorSize);
> +  }
> +}
> +
> +
> +
> +VOID
> +JumpVirtualMode(
> +  IN UINTN VirtualFunc,
> +  IN UINTN HandOffAddr
> +  )
> +/*++
> +
> +Routine Description:
> +
> +  Enable virtual addressing mode, and jump to RuntimeTestFunc in virtual address
> +
> +Arguments:
> +
> +  VirtualFunc  - RuntimeTestFunc virtual address
> +  HandOffAddr  - Configuration Data Address
> +
> +Returns:
> +
> +  NONE
> +
> +--*/
> +{
> +  //
> +  // Note: It is assumed that the MMU and page tables are configured on ARM platforms
> +  // based on ARM v5 v6 and v7 architecture.
> +  //
> +  /* FIXME: Is it the same on ARM v8? */
> +	JumpToTestFunc(VirtualFunc, HandOffAddr);

Again.

> +}
> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c
> new file mode 100644
> index 00000000..6161d596
> --- /dev/null
> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c
> @@ -0,0 +1,88 @@
> +/** @file
> +
> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
> +  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>   
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD License
> +  which accompanies this distribution.  The full text of the license may be found at 
> +  http://opensource.org/licenses/bsd-license.php
> + 
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> + 
> +**/
> +
> +/*++
> +
> +Module Name:
> +
> +  Debug.c
> +
> +--*/
> +
> +#include "SCRTDriver.h"
> +
> +UINTN                 mHandOffPtr        =  0;
> +EFI_PHYSICAL_ADDRESS  mIoPortSpaceAddress = 0;
> +
> +
> +EFI_STATUS
> +ConsumeHandOff (
> +  IN  UINTN         HandOffAddr,
> +  OUT CONF_INFO     *ConfigData
> +  )
> +{
> +   RUNTIME_HANDOFF   *HandOffPtr;
> +   //
> +   // First fix the memory address of hand off data.
> +   //
> +   FixAddress(&HandOffAddr);
> +   mHandOffPtr = HandOffAddr;
> +   HandOffPtr  = (RUNTIME_HANDOFF*)mHandOffPtr;
> +   *ConfigData =  HandOffPtr->ConfigureInfo;
> +
> +   if (!HandOffPtr->DebuggerInfo.MmioFlag){
> +     //
> +     // If debug port is I/O mapped, fix IoBase Address.
> +     //
> +     FixAddress(&HandOffPtr->DebuggerInfo.IoBase);
> +     mIoPortSpaceAddress = HandOffPtr->DebuggerInfo.IoBase;

Looks redundant on !x86

> +   } else {
> +     //
> +     // If debug port is MMIO, fix MmioBase Address.
> +     //
> +     FixAddress(&HandOffPtr->DebuggerInfo.MmioBase);
> +   }
> +
> +   return EFI_SUCCESS;
> +}
> +
> +
> +EFI_STATUS
> +Send2UART (
> +  CHAR8                *String
> +  )
> +{
> +  //
> +  // TODO: On ARM platforms use platform specific functions to
> +  // write the data to UART.
> +  //

Ye gods...

> +  return EFI_SUCCESS;
> +}
> +
> +
> +
> +EFI_STATUS
> +DebugWorker (
> +  IN CHAR8    *String
> +  )
> +{
> +  EFI_STATUS    Status;
> +
> +  //
> +  // Send text message to registered UART.
> +  //
> +  Status = Send2UART(String);
> +  return Status;
> +}
> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c
> new file mode 100644
> index 00000000..cc8d9869
> --- /dev/null
> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c
> @@ -0,0 +1,68 @@
> +/** @file
> +
> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
> +  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>   
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD License
> +  which accompanies this distribution.  The full text of the license may be found at 
> +  http://opensource.org/licenses/bsd-license.php
> + 
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> + 
> +**/
> +
> +/*++
> +
> +Module Name:
> +
> +  Dump.c
> +
> +--*/
> +
> +#include "SCRTDriver.h"
> +
> +VOID
> +DumpRuntimeTable()
> +{
> +  SctAPrint ("\n================Dump Runtime Table===============\n");
> +  SctAPrint ("Header Signature = 0x%x\n", VRT->Hdr.Signature);
> +
> +  SctAPrint ("\n================GetTime Service==============\n");
> +  SctAPrint ("GetTime @ 0x%x\n", VRT->GetTime);
> +
> +  SctAPrint ("\n================SetTime Service==============\n");
> +  SctAPrint ("SetTime @ 0x%x\n", VRT->SetTime);
> +
> +  SctAPrint ("\n================GetWakeupTime Service==============\n");
> +  SctAPrint ("GetWakeupTime @ 0x%x\n", VRT->GetWakeupTime);
> +
> +  SctAPrint ("\n================SetWakeupTime Service==============\n");
> +  SctAPrint ("SetWakeupTime @ 0x%x\n", VRT->SetWakeupTime);
> +
> +  SctAPrint ("\n================GetVariable Service==============\n");
> +  SctAPrint ("GetVariable @ 0x%x\n", VRT->GetVariable);
> +
> +  SctAPrint ("\n================GetNextVariableName Service==============\n");
> +  SctAPrint ("GetNextVariableName @ 0x%x\n", VRT->GetNextVariableName);
> +
> +  SctAPrint ("\n================SetVariable Service==============\n");
> +  SctAPrint ("SetVariable @ 0x%x\n", VRT->SetVariable);
> +
> +  SctAPrint ("\n================GetNextHighMonotonicCount Service==============\n");
> +  SctAPrint ("GetNextHighMonotonicCount @ 0x%x\n", VRT->GetNextHighMonotonicCount);
> +
> +  SctAPrint ("\n================ResetSystem Service==============\n");
> +  SctAPrint ("ResetSystem @ 0x%x\n", VRT->ResetSystem);
> +#if 0

Better to delete if not usable, but why disabled for AArch64 in the
first place?

> +  SctAPrint ("\n================UpdateCapsule Service==============\n");
> +  SctAPrint ("UpdateCapsule @ 0x%x\n", VRT->UpdateCapsule);
> +
> +  SctAPrint ("\n================QueryCapsuleCapabilities Service==============\n");
> +  SctAPrint ("QueryCapsuleCapabilities @ 0x%x\n", VRT->QueryCapsuleCapabilities);
> +
> +  SctAPrint ("\n================QueryVariableInfo Service==============\n");
> +  SctAPrint ("QueryVariableInfo @ 0x%x\n", VRT->QueryVariableInfo);
> +#endif
> +}
> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c
> new file mode 100644
> index 00000000..b925e151
> --- /dev/null
> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c
> @@ -0,0 +1,134 @@
> +/** @file
> +
> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
> +  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>   

More trailing spaces than usual in line above.
(The below block has 3 of them in every copy.)

> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD License
> +  which accompanies this distribution.  The full text of the license may be found at 
> +  http://opensource.org/licenses/bsd-license.php
> + 
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> + 
> +**/
> +
> +/*++
> +
> +Module Name:
> +
> +  Io.c
> +
> +--*/
> +
> +#include "Io.h"
> +
> +EFI_STATUS
> +EFIAPI
> +CpuIoServiceWrite (
> +  IN EFI_PEI_CPU_IO_PPI_WIDTH  Width,
> +  IN UINT64                     UserAddress,
> +  IN UINTN                      Count,
> +  IN VOID                       *UserBuffer
> +  )
> +/*++
> +
> +Routine Description:
> +
> +  Perform the port I/O write service
> +
> +Arguments:
> +
> +  Width   - Width of the port I/O operation
> +  Address - Base address of the port I/O operation
> +  Count   - Count of the number of accesses to perform
> +  Buffer  - Pointer to the source buffer from which to write data
> +
> +Returns:
> +
> +  EFI_SUCCESS           - The data was written.
> +  EFI_INVALID_PARAMETER - Width is invalid.
> +  EFI_INVALID_PARAMETER - Buffer is NULL.
> +  EFI_UNSUPPORTED       - The Buffer is not aligned for the given Width.
> +  EFI_UNSUPPORTED       - The address range specified by Address, Width,
> +                          and Count is not valid.
> +
> +--*/
> +{
> +  return EFI_UNSUPPORTED;
> +}
> +
> +
> +EFI_STATUS
> +EfiIoWrite (
> +  IN     EFI_PEI_CPU_IO_PPI_WIDTH  Width,
> +  IN     UINT64                     Address,
> +  IN     UINTN                      Count,
> +  IN OUT VOID                       *Buffer
> +  )
> +/*++
> +
> +Routine Description:
> +  Perform an IO write into Buffer.
> +
> +Arguments:
> +  Width   - Width of write transaction, and repeat operation to use
> +  Address - IO address to write
> +  Count   - Number of times to write the IO address.
> +  Buffer  - Buffer to write data from. size is Width * Count
> +
> +Returns:
> +  Status code
> +
> +--*/
> +{
> +  return CpuIoServiceWrite(Width, Address, Count, Buffer);
> +}
> +
> +
> +EFI_STATUS
> +EfiIoRead (
> +  IN     EFI_PEI_CPU_IO_PPI_WIDTH  Width,
> +  IN     UINT64                     Address,
> +  IN     UINTN                      Count,
> +  IN OUT VOID                       *Buffer
> +  )
> +/*++
> +
> +Routine Description:
> +  Perform an IO read into Buffer.
> +
> +Arguments:
> +  Width   - Width of read transaction, and repeat operation to use
> +  Address - IO address to read
> +  Count   - Number of times to read the IO address.
> +  Buffer  - Buffer to read data into. size is Width * Count
> +
> +Returns:
> +  Status code
> +
> +--*/
> +{
> +  return EFI_UNSUPPORTED;
> +}
> +
> +
> +VOID
> +FixAddress (
> +  IN UINTN     *PhyAddress
> +  )
> +{
> +		//
> +		//Note: On ARM platforms don't have to do this as all the functions are virtually mapped.
> +		//

ARM

> +}
> +
> +// Quick port to ARM
> +
> +VOID
> +Port80 (
> +  UINT8 Number
> +  )
> +{
> +  //EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Port80 %02x", Number));

Eew.

> +}
> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h
> new file mode 100644
> index 00000000..1e78b3e4
> --- /dev/null
> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h
> @@ -0,0 +1,48 @@
> +/** @file
> +
> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
> +  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>   
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD License
> +  which accompanies this distribution.  The full text of the license may be found at 
> +  http://opensource.org/licenses/bsd-license.php
> + 
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> + 

Trailing spaces.

> +**/
> +
> +/*++
> +
> +Module Name:
> +
> +  Debug.h
> +
> +--*/
> +
> +#ifndef _IA32_IO_ACCESS_H
> +#define _IA32_IO_ACCESS_H

Srsly?

> +
> +#include "SCRTDriver.h"
> +
> +#define IA32_MAX_IO_ADDRESS   0xFFFF
> +
> +#define IA32API
> +
> +
> +typedef union {
> +  UINT8  VOLATILE  *buf;
> +  UINT8  VOLATILE  *ui8;
> +  UINT16 VOLATILE  *ui16;
> +  UINT32 VOLATILE  *ui32;
> +  UINT64 VOLATILE  *ui64;
> +  UINTN  VOLATILE  ui;
> +} PTR;
> +
> +// This address is assuming a pure PC architecture. Not required?
> +#define   VIRT_TO_PHYS_OFFSET            (0x80000000)     //2G
> +
> +
> +
> +#endif
> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c
> new file mode 100644
> index 00000000..96ee7b57
> --- /dev/null
> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c
> @@ -0,0 +1,137 @@
> +/** @file
> +
> +  Copyright 2006 - 2016 Unified EFI, Inc.<BR>
> +  Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.<BR>
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD License
> +  which accompanies this distribution.  The full text of the license may be found at 
> +  http://opensource.org/licenses/bsd-license.php
> + 
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> + 
> +**/
> +/*++
> +
> +Module Name:
> +
> +  DebugSupportBBTestCacheFunction.c
> +
> +Abstract:
> +
> +  Interface Function Test Cases of Debug Support Protocol
> +
> +--*/
> +
> +
> +#include "DebugSupportBBTestMain.h"
> +
> +/**
> + *  Entrypoint for EFI_DEBUG_SUPPORT_PROTOCOL.InvalidateInstructionCache() Function Test.
> + *  @param This a pointer of EFI_BB_TEST_PROTOCOL.
> + *  @param ClientInterface a pointer to the interface to be tested.
> + *  @param TestLevel test "thoroughness" control.
> + *  @param SupportHandle a handle containing protocols required.
> + *  @return EFI_SUCCESS Finish the test successfully.
> + */
> +//
> +// TDS 3.5
> +//
> +EFI_STATUS
> +BBTestInvalidateInstructionCacheFunctionAutoTest (
> +  IN EFI_BB_TEST_PROTOCOL       *This,
> +  IN VOID                       *ClientInterface,
> +  IN EFI_TEST_LEVEL             TestLevel,
> +  IN EFI_HANDLE                 SupportHandle
> +  )
> +{
> +  EFI_STANDARD_TEST_LIBRARY_PROTOCOL   *StandardLib;
> +  EFI_STATUS                           Status;
> +  EFI_DEBUG_SUPPORT_PROTOCOL           *DebugSupport;
> +  EFI_TEST_ASSERTION                   AssertionType;
> +  UINT64                               Start;
> +  UINT64                               Length;
> +  UINTN                                MaxProcessorIndex;
> +  UINTN                                ProcessorIndex;
> +
> +  //
> +  // Get the Standard Library Interface
> +  //
> +  Status = gtBS->HandleProtocol (
> +                   SupportHandle,
> +                   &gEfiStandardTestLibraryGuid,
> +                   (VOID **) &StandardLib
> +                   );
> +
> +  if (EFI_ERROR(Status)) {
> +    StandardLib->RecordAssertion (
> +                   StandardLib,
> +                   EFI_TEST_ASSERTION_FAILED,
> +                   gTestGenericFailureGuid,
> +                   L"BS.HandleProtocol - Handle standard test library",
> +                   L"%a:%d:Status - %r",
> +                   __FILE__,
> +                   (UINTN)__LINE__,
> +                   Status
> +                   );
> +    return Status;
> +  }
> +
> +  DebugSupport = (EFI_DEBUG_SUPPORT_PROTOCOL *)ClientInterface;
> +
> +  if (DebugSupport->Isa != PlatformIsa) {
> +    return EFI_SUCCESS;
> +  }
> +
> +  Status = DebugSupport->GetMaximumProcessorIndex (DebugSupport, &MaxProcessorIndex);
> +  if (EFI_ERROR(Status)) {
> +    StandardLib->RecordAssertion (
> +                   StandardLib,
> +                   EFI_TEST_ASSERTION_FAILED,
> +                   gTestGenericFailureGuid,
> +                   L"EFI_DEBUG_SUPPORT_PROTOCOL.GetMaximumProcessorIndex",
> +                   L"%a:%d:Status - %r",
> +                   __FILE__,
> +                   (UINTN)__LINE__,
> +                   Status
> +                   );
> +    return Status;
> +  }
> +
> +  for (ProcessorIndex = 0; ProcessorIndex <= MaxProcessorIndex; ProcessorIndex++) {
> +
> +    //
> +    // Assertion Point 3.5.2.1
> +    // Invoke InvalidateInstructionCache and verify interface correctness.
> +    //
> +
> +    // The Physical base of the memory range to be invalidated.
> +    Start  = 0x0;
> +
> +    // The minimum number of bytes in the processor's instruction cache to be invalidated.
> +    Length = 0x0;
> +
> +    Status = DebugSupport->InvalidateInstructionCache (DebugSupport, ProcessorIndex, (VOID*)&Start, Length);
> +
> +    if (EFI_ERROR(Status)) {
> +      AssertionType = EFI_TEST_ASSERTION_FAILED;
> +    } else {
> +      AssertionType = EFI_TEST_ASSERTION_PASSED;
> +    }
> +
> +    StandardLib->RecordAssertion (
> +                 StandardLib,
> +                 AssertionType,
> +                 gDebugSupportBBTestFunctionAssertionGuid015,
> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.InvalidateInstructionCache - Invoke this function and verify interface correctness",
> +                 L"%a:%d:Status - %r",
> +                 __FILE__,
> +                 (UINTN)__LINE__,
> +                 Status
> +                 );
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
> new file mode 100644
> index 00000000..c27c0c0c
> --- /dev/null
> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
> @@ -0,0 +1,276 @@
> +/** @file
> +
> +  Copyright 2006 - 2016 Unified EFI, Inc.<BR>
> +  Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.<BR>
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD License
> +  which accompanies this distribution.  The full text of the license may be found at 
> +  http://opensource.org/licenses/bsd-license.php
> + 
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> + 
> +**/
> +/*++
> +
> +Module Name:
> +
> +  DebugSupportBBExceptionCallbackFunction.c
> +
> +Abstract:
> +
> +  Interface Function Test Cases of Debug Support Protocol
> +
> +--*/
> +
> +
> +#include "DebugSupportBBTestMain.h"
> +
> +extern volatile  UINTN InvokedExceptionCallback;
> +extern volatile  UINTN InvokedPeriodicCallback;
> +
> +extern EFI_INSTRUCTION_SET_ARCHITECTURE PlatformIsa;
> +
> +void
> +SoftwareBreak (
> +  void
> +  )
> +{
> +  // Not ported to ARM yet

Eew.

> +  ASSERT (FALSE);
> +}
> +
> +/**
> + *  Entrypoint for EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback() Function Test.
> + *  @param This a pointer of EFI_BB_TEST_PROTOCOL.
> + *  @param ClientInterface a pointer to the interface to be tested.
> + *  @param TestLevel test "thoroughness" control.
> + *  @param SupportHandle a handle containing protocols required.
> + *  @return EFI_SUCCESS Finish the test successfully.
> + */
> +//
> +// TDS 3.4
> +//
> +EFI_STATUS
> +BBTestRegisterExceptionCallbackFunctionManualTest (
> +  IN EFI_BB_TEST_PROTOCOL       *This,
> +  IN VOID                       *ClientInterface,
> +  IN EFI_TEST_LEVEL             TestLevel,
> +  IN EFI_HANDLE                 SupportHandle
> +  )
> +{
> +  EFI_STANDARD_TEST_LIBRARY_PROTOCOL   *StandardLib;
> +  EFI_STATUS                           Status;
> +  EFI_DEBUG_SUPPORT_PROTOCOL           *DebugSupport;
> +  EFI_TEST_ASSERTION                   AssertionType;
> +
> +  DebugSupport = (EFI_DEBUG_SUPPORT_PROTOCOL *)ClientInterface;
> +
> +  if (DebugSupport->Isa != PlatformIsa) {
> +    return EFI_SUCCESS;
> +  }
> +
> +  //
> +  // Get the Standard Library Interface
> +  //
> +  Status = gtBS->HandleProtocol (
> +                   SupportHandle,
> +                   &gEfiStandardTestLibraryGuid,
> +                   (VOID **) &StandardLib
> +                   );
> +
> +  if (EFI_ERROR(Status)) {
> +    StandardLib->RecordAssertion (
> +                   StandardLib,
> +                   EFI_TEST_ASSERTION_FAILED,
> +                   gTestGenericFailureGuid,
> +                   L"BS.HandleProtocol - Handle standard test library",
> +                   L"%a:%d:Status - %r",
> +                   __FILE__,
> +                   (UINTN)__LINE__,
> +                   Status
> +                   );
> +    return Status;
> +  }
> +
> +  //
> +  // Assertion Point 3.4.2.1
> +  // Invoke RegisterExceptionCallback() to install an interrupt handler function.
> +  //
> +  InvokedExceptionCallback = FALSE;
> +  // FIXME: Is it normal that we use EXCEPT_IA32_BREAKPOINT here?
> +  // Shouldn't we define proper constants for ARM exceptions in DebugSupportProtocol.h file?
> +  Status = DebugSupport->RegisterExceptionCallback (DebugSupport, 0, ExceptionCallback, EXCEPT_IA32_BREAKPOINT);
> +
> +  if ((Status == EFI_SUCCESS) || (Status == EFI_ALREADY_STARTED)) {
> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
> +  } else {
> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
> +  }
> +
> +  StandardLib->RecordAssertion (
> +                 StandardLib,
> +                 AssertionType,
> +                 gDebugSupportBBTestFunctionAssertionGuid009,
> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Invoke this function and verify interface correctness",
> +                 L"%a:%d:Status - %r",
> +                 __FILE__,
> +                 (UINTN)__LINE__,
> +                 Status
> +                 );
> +
> +  //
> +  // If the callback function is already registed, return
> +  //
> +  if (EFI_ERROR(Status)) {
> +    return EFI_SUCCESS;
> +  }
> +
> +  //
> +  // Test the callback function registed.
> +  //
> +
> +  //
> +  // Call SoftwareBreak to invoke the interrupt handler function.
> +  //
> +  SoftwareBreak ();
> +
> +  if (InvokedExceptionCallback == FALSE) {
> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
> +  } else {
> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
> +  }
> +
> +  StandardLib->RecordAssertion (
> +                 StandardLib,
> +                 AssertionType,
> +                 gDebugSupportBBTestFunctionAssertionGuid010,
> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Verify the callback function was invoked.",
> +                 L"%a:%d:Status - %r",
> +                 __FILE__,
> +                 (UINTN)__LINE__,
> +                 Status
> +                 );
> +
> +  //
> +  // Assertion Point 3.4.2.2
> +  // Invoke RegisterPeriodicCallback() to install the Periodic interrupt handler function.
> +  // Verify the two callback functions can be both invoked.
> +  //
> +  InvokedExceptionCallback = FALSE;
> +  InvokedPeriodicCallback  = FALSE;
> +
> +  Status = DebugSupport->RegisterPeriodicCallback (DebugSupport, 0, PeriodicCallback);
> +  if (EFI_ERROR(Status)) {
> +    return Status;
> +  }
> +
> +  //
> +  // Wait the PeriodicCallback to be invoked.
> +  //
> +  gtBS->Stall (500000);
> +
> +  //
> +  // Call SoftwareBreak to invoke the interrupt handler function.
> +  //
> +  SoftwareBreak ();
> +
> +  if ((InvokedExceptionCallback == TRUE) && (InvokedPeriodicCallback == TRUE)) {
> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
> +  } else {
> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
> +  }
> +
> +  StandardLib->RecordAssertion (
> +                 StandardLib,
> +                 AssertionType,
> +                 gDebugSupportBBTestFunctionAssertionGuid011,
> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Verify the two callback functions can be both invoked.",
> +                 L"%a:%d:Status - %r",
> +                 __FILE__,
> +                 (UINTN)__LINE__,
> +                 Status
> +                 );
> +
> +  //
> +  // Uninstall the Periodic callback function.
> +  //
> +  Status = DebugSupport->RegisterPeriodicCallback (DebugSupport, 0, NULL);
> +  if (EFI_ERROR(Status)) {
> +    return Status;
> +  }
> +
> +  //
> +  // Assertion Point 3.4.2.3
> +  // Invoke RegisterExceptionCallback() to install another interrupt handler function.
> +  //
> +  Status = DebugSupport->RegisterExceptionCallback (DebugSupport, 0, ExceptionCallback1, EXCEPT_IA32_BREAKPOINT);
> +
> +  if (Status != EFI_ALREADY_STARTED) {
> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
> +  } else {
> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
> +  }
> +
> +  StandardLib->RecordAssertion (
> +                 StandardLib,
> +                 AssertionType,
> +                 gDebugSupportBBTestFunctionAssertionGuid012,
> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Register another callback function.",
> +                 L"%a:%d:Status - %r",
> +                 __FILE__,
> +                 (UINTN)__LINE__,
> +                 Status
> +                 );
> +
> +  //
> +  // Assertion Point 3.4.2.4
> +  // Invoke RegisterExceptionCallback() to unstall the interrupt handler function.
> +  //
> +  Status = DebugSupport->RegisterExceptionCallback (DebugSupport, 0, NULL, EXCEPT_IA32_BREAKPOINT);
> +
> +  if (EFI_ERROR(Status)) {
> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
> +  } else {
> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
> +  }
> +
> +  StandardLib->RecordAssertion (
> +                 StandardLib,
> +                 AssertionType,
> +                 gDebugSupportBBTestFunctionAssertionGuid013,
> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Invoke this function to uninstall the interrupt handler function",
> +                 L"%a:%d:Status - %r",
> +                 __FILE__,
> +                 (UINTN)__LINE__,
> +                 Status
> +                 );
> +
> +  InvokedExceptionCallback = FALSE;
> +
> +  //
> +  // Call SoftwareBreak to invoke the interrupt handler function.
> +  //
> +  SoftwareBreak ();
> +
> +  if (InvokedExceptionCallback != FALSE) {
> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
> +  } else {
> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
> +  }
> +
> +  StandardLib->RecordAssertion (
> +                 StandardLib,
> +                 AssertionType,
> +                 gDebugSupportBBTestFunctionAssertionGuid014,
> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Verify the callback function wasn't invoked",
> +                 L"%a:%d:Status - %r",
> +                 __FILE__,
> +                 (UINTN)__LINE__,
> +                 Status
> +                 );
> +
> +  return EFI_SUCCESS;
> +}
> +
> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c
> new file mode 100644
> index 00000000..8334f601
> --- /dev/null
> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c
> @@ -0,0 +1,30 @@
> +/** @file
> +
> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
> +  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD License
> +  which accompanies this distribution.  The full text of the license may be found at 
> +  http://opensource.org/licenses/bsd-license.php
> + 
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> + 
> +**/
> +/*++
> +
> +Module Name:
> +
> +  PlatformIsa.c
> +
> +Abstract:
> +
> +  Platform related Isa definition.
> +
> +--*/
> +
> +#include "DebugSupportBBTestMain.h"
> +
> +EFI_INSTRUCTION_SET_ARCHITECTURE PlatformIsa = IsaAArch64;
> +
> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c
> new file mode 100644
> index 00000000..1c1940e5
> --- /dev/null
> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c
> @@ -0,0 +1,51 @@
> +/** @file
> +
> +  Copyright 2006 - 2010 Unified EFI, Inc.<BR>
> +  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD License
> +  which accompanies this distribution.  The full text of the license may be found at 
> +  http://opensource.org/licenses/bsd-license.php
> + 
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> + 
> +**/
> +/**
> + *  Ipf Source file for Mask/Unmask TimerInterrupt.
> + */
> +/*++
> +
> +Module Name:
> +  TimerInterrupt.c
> +
> +Abstract:
> +  Ipf Source file for Mask/Unmask TimerInterrupt.
> +
> +Author(s):
> +
> +
> +References:
> +  EFI Specification 1.10
> +  EFI/Tiano DXE Test Case Writer's Guide
> +
> +Revision History:
> +  Initial 10-20-2002
> +  Version 0.01
> +
> +--*/
> +
> +#include "UsbHcTest.h"
> +
> +VOID MaskTimerInterrupt()
> +{
> +  // TBD
> +  return;
> +}
> +
> +VOID UnmaskTimerInterrupt()
> +{
> +  // TBD
> +  return;
> +}
> diff --git a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h
> new file mode 100644
> index 00000000..ff781aee
> --- /dev/null
> +++ b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h
> @@ -0,0 +1,55 @@
> +/** @file
> +
> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
> +  Copyright (c) 2010 - 2012, ARM Ltd. All rights reserved.<BR>
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD License
> +  which accompanies this distribution.  The full text of the license may be found at 
> +  http://opensource.org/licenses/bsd-license.php
> + 
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> + 
> +**/
> +/*++
> +
> +Module Name:
> +
> +  EntsLibPlat.h
> +
> +Abstract:
> +
> +  AArch64 specific defines
> +
> +--*/
> +
> +#ifndef _EFI_LIB_PLAT_H_
> +#define _EFI_LIB_PLAT_H_

No leading _.

/
    Leif

> +
> +#define MIN_ALIGNMENT_SIZE  8
> +
> +VOID
> +EntsInitializeLibPlatform (
> +  IN EFI_HANDLE           ImageHandle,
> +  IN EFI_SYSTEM_TABLE     *SystemTable
> +  )
> +/*++
> +
> +Routine Description:
> +
> +  Initialize platform.
> +
> +Arguments:
> +
> +  ImageHandle           - The image handle.
> +  SystemTable           - The system table.
> +
> +Returns:
> +
> +  None.
> +
> +--*/
> +;
> +
> +#endif
> diff --git a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c
> new file mode 100644
> index 00000000..70a509a4
> --- /dev/null
> +++ b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c
> @@ -0,0 +1,55 @@
> +/** @file
> +
> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
> +  Copyright (c) 2010 - 2012, ARM Ltd. All rights reserved.<BR>
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD License
> +  which accompanies this distribution.  The full text of the license may be found at 
> +  http://opensource.org/licenses/bsd-license.php
> + 
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> + 
> +**/
> +/*++
> +
> +Module Name:
> +
> +  InitPlat.c
> +
> +Abstract:
> +
> +  Math routines for compatibility with native EFI library routines.
> +
> +--*/
> +
> +#include "Efi.h"
> +#include "EntsLibPlat.h"
> +
> +VOID
> +EntsInitializeLibPlatform (
> +  IN EFI_HANDLE           ImageHandle,
> +  IN EFI_SYSTEM_TABLE     *SystemTable
> +  )
> +/*++
> +
> +Routine Description:
> +
> +  Initialize platform.
> +
> +Arguments:
> +
> +  ImageHandle           - The image handle.
> +  SystemTable           - The system table.
> +
> +Returns:
> +
> +  None.
> +
> +--*/
> +{
> +  //
> +  // No platform-specific initializations
> +  //
> +}
> -- 
> 2.28.0
> 
> 
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg
  2020-12-01 16:17 [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg Daniel Schaefer
                   ` (2 preceding siblings ...)
  2020-12-01 16:59 ` [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg Heinrich Schuchardt
@ 2020-12-02 12:07 ` Leif Lindholm
  3 siblings, 0 replies; 18+ messages in thread
From: Leif Lindholm @ 2020-12-02 12:07 UTC (permalink / raw)
  To: Daniel Schaefer
  Cc: devel, Heinrich Schuchardt, Abner Chang, Gilbert Chen, Eric Jin,
	G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

On Wed, Dec 02, 2020 at 00:17:50 +0800, Daniel Schaefer wrote:
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042
> 
> With this patch series we can build the UEFI SCT for RISCV64. It was confirmed
> to be working on the U-Boot UEFI implementation by Heinrich.
> It hasn't been tested on EDK2 yet.
> 
> Build requirements are the same as for the EDK2 RISCV64 port and detailed here:
> https://github.com/riscv/riscv-uefi-edk2-docs
> 
> The second patch is a big one because it adds architecture specific files by
> copying them from the Aarch64 directory. Only a single file, an assembly file
> needed modifications. I'm not sure why the other ones are in an architecture
> specific directory. They're all C files and seem to be generic. We can probably
> unify them.

It seems to me this can be trivially unified for all !x86 platforms,
and I don't think it would take much more to unify for all platforms.
Certainly, looking at the code you copy, that could already do with
some cleanup of its own.

/
    Leif

> Cc: Leif Lindholm <leif@nuviainc.com>
> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Cc: Abner Chang <abner.chang@hpe.com>
> Cc: Gilbert Chen <gilbert.chen@hpe.com>
> Cc: Eric Jin <eric.jin@intel.com>
> Cc: G Edhaya Chandran <Edhaya.Chandran@arm.com>
> Cc: Barton Gao <gaojie@byosoft.com.cn>
> Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
> 
> Daniel Schaefer (2):
>   SctPkg: Add RISCV64 support
>   SctPkg: Enable RISCV64 support using AARCH64 sources
> 
>  uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h                                                                     |   3 +
>  uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h                                                                        |  32 +++
>  uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c                                                                          |  45 ++++
>  uefi-sct/SctPkg/Library/SctLib/SctLib.inf                                                                                  |   6 +
>  uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S                                                                           |  45 ++++
>  uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c                                                                       | 182 +++++++++++++
>  uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf                                                                                   |   6 +
>  uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c                                                                            |  88 +++++++
>  uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c                                                                             |  68 +++++
>  uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c                                                                               | 134 ++++++++++
>  uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h                                                                               |  48 ++++
>  uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf                                                                             |   7 +
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf                                |   6 +
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c             | 137 ++++++++++
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c | 276 ++++++++++++++++++++
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c                                 |  30 +++
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf                                              |   4 +
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c                                     |  51 ++++
>  uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf                                                |   4 +
>  uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf                                                   |   5 +
>  uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h                                         |  55 ++++
>  uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c                                            |  55 ++++
>  uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile                                                                            |   3 +
>  uefi-sct/SctPkg/UEFI/IHV_SCT.dsc                                                                                           |  14 +-
>  uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h                                                                               |  62 ++++-
>  uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc                                                                                          |  14 +-
>  uefi-sct/SctPkg/build.sh                                                                                                   |  10 +-
>  27 files changed, 1386 insertions(+), 4 deletions(-)
>  create mode 100644 uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h
>  create mode 100644 uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c
>  create mode 100644 uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
>  create mode 100644 uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c
>  create mode 100644 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c
>  create mode 100644 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c
>  create mode 100644 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c
>  create mode 100644 uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h
>  create mode 100644 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c
>  create mode 100644 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
>  create mode 100644 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c
>  create mode 100644 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c
>  create mode 100644 uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h
>  create mode 100644 uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c
> 
> -- 
> 2.28.0
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg
  2020-12-01 17:37     ` Heinrich Schuchardt
@ 2021-02-08 14:30       ` Daniel Schaefer
  2021-02-08 15:50         ` Heinrich Schuchardt
  0 siblings, 1 reply; 18+ messages in thread
From: Daniel Schaefer @ 2021-02-08 14:30 UTC (permalink / raw)
  To: Heinrich Schuchardt, devel
  Cc: Leif Lindholm, Abner Chang, Gilbert Chen, Eric Jin,
	G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

On 12/2/20 1:37 AM, Heinrich Schuchardt wrote:
> On 12/1/20 6:11 PM, Daniel Schaefer wrote:
>> On 12/2/20 12:59 AM, Heinrich Schuchardt wrote:
>>> On 12/1/20 5:17 PM, Daniel Schaefer wrote:
>>>> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042
>>>>
>>>> With this patch series we can build the UEFI SCT for RISCV64. It was
>>>> confirmed
>>>> to be working on the U-Boot UEFI implementation by Heinrich.
>>>> It hasn't been tested on EDK2 yet.
>>>>
>>>> Build requirements are the same as for the EDK2 RISCV64 port and
>>>> detailed here:
>>>> https://github.com/riscv/riscv-uefi-edk2-docs
>>>>
>>>> The second patch is a big one because it adds architecture specific
>>>> files by
>>>> copying them from the Aarch64 directory. Only a single file, an
>>>> assembly file
>>>> needed modifications. I'm not sure why the other ones are in an
>>>> architecture
>>>> specific directory. They're all C files and seem to be generic. We
>>>> can probably
>>>> unify them.
>>>
>>> Hello Daniel,
>>>
>>> thanks a lot for your patches.
>>>
>>> You address the uefi-sct/SctPkg/TestCase/UEFI/EFI directory.
>>>
>>> Are you planning future patches for uefi-sct/SctPkg/TestCase/UEFI/IHV
>>> too?
>>
>> I grepped the repo for strings related to arm64 and aarch64. I ported
>> what I found.
>> Do you see anything that's not ported?
> 
> uefi-sct/SctPkg/UEFI/IHV_SCT.dsc is the only IHV related file with
> AARCH64 in it and that one is covered by your patch series.
> 
>>
>> The only thing I see, is in
>> Protocol/UsbIo/BlackBoxTest/UsbIoTestConformance.c
>> where some code is not used for ARM because:
>>
>>    // Note: This function uses the EDKII Glu library from EDKII
>> compatibility pkg.
>>
>>    // which is not ported to ARM yet. Hence for the time being just
>> return success.
>>
>>
>> I'm not yet sure what library that's referring to, but most likely it's
>> also
>> not implemented for RISC-V.
> 
> I assume this refers to:
> https://github.com/tianocore/edk/tree/master/Foundation/Library/EdkIIGlueLib
> 
> The files of this library are in edk2/MdePkg/Library now.

Wow, that code is ancient then. I'm not gonna ifdef it out for RISC-V.
If it works for x86 it might work for RISC-V now.
Maybe the ARM people can try it on ARM first ;)

>> Thanks for testing!
>> Does the SCT result look like what you expect? Or are some tests failing
>> that you expect to succeed?
> 
> Not all tests have run yet. Running SCT on QEMU is really slow.
> 
> But from what I can see there is no difference to AARCH64 results on QEMU.

Sounds great! I assume all the tests have succeeded now?

> Best regards
> 
> Heinrich
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-devel] [edk2-test PATCH v1 2/2] SctPkg: Enable RISCV64 support using AARCH64 sources
  2020-12-02 12:04   ` [edk2-devel] " Leif Lindholm
@ 2021-02-08 15:09     ` Daniel Schaefer
  2021-02-08 17:04       ` Heinrich Schuchardt
  0 siblings, 1 reply; 18+ messages in thread
From: Daniel Schaefer @ 2021-02-08 15:09 UTC (permalink / raw)
  To: Leif Lindholm, devel
  Cc: Heinrich Schuchardt, Abner Chang, Gilbert Chen, Eric Jin,
	G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

Hi Leif,

thanks very much for the review!
I've cleaned up the patchset and addressed the issues. I'll send out another set soon.
See comments below.

Thanks,
Daniel

On 12/2/20 8:04 PM, Leif Lindholm wrote:
> On Wed, Dec 02, 2020 at 00:17:52 +0800, Daniel Schaefer wrote:
>> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042
>>
>> TODO: Need to check whether we can avoid copying Aarch64 sources.
>>
>> Cc: Leif Lindholm <leif@nuviainc.com>
>> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> Cc: Abner Chang <abner.chang@hpe.com>
>> Cc: Gilbert Chen <gilbert.chen@hpe.com>
>> Cc: Eric Jin <eric.jin@intel.com>
>> Cc: G Edhaya Chandran <Edhaya.Chandran@arm.com>
>> Cc: Barton Gao <gaojie@byosoft.com.cn>
>> Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
>> Signed-off-by: Daniel Schaefer <daniel.schaefer@hpe.com>
>> ---
>>   uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h                                                                        |  32 +++
>>   uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c                                                                          |  45 ++++
>>   uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S                                                                           |  45 ++++
>>   uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c                                                                       | 182 +++++++++++++
>>   uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c                                                                            |  88 +++++++
>>   uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c                                                                             |  68 +++++
>>   uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c                                                                               | 134 ++++++++++
>>   uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h                                                                               |  48 ++++
>>   uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c             | 137 ++++++++++
>>   uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c | 276 ++++++++++++++++++++
>>   uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c                                 |  30 +++
>>   uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c                                     |  51 ++++
>>   uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h                                         |  55 ++++
>>   uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c                                            |  55 ++++
>>   14 files changed, 1246 insertions(+)
>>
>> diff --git a/uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h b/uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h
>> new file mode 100644
>> index 00000000..ee7c656b
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h
>> @@ -0,0 +1,32 @@
>> +/** @file
>> +
>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>> +  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials
>> +  are licensed and made available under the terms and conditions of the BSD License
>> +  which accompanies this distribution.  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +
>> +**/
>> +/*++
>> +
>> +Module Name:
>> +
>> +  SctLibPlat.h
>> +
>> +Abstract:
>> +
>> +  AArch64 specific defines
> 
> *cough*

For the next patch series I went through everything and made sure that there's no Aarch64 or ARM anymore.

>> +
>> +--*/
>> +
>> +#ifndef _EFI_LIB_PLAT_H_
>> +#define _EFI_LIB_PLAT_H_
> 
> No leading _ in macros.

This is a common pattern in the code. Even in EDK2.

>> +
>> +#define MIN_ALIGNMENT_SIZE  8
>> +
>> +#endif
>> diff --git a/uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c b/uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c
>> new file mode 100644
>> index 00000000..a48bb2f3
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c
>> @@ -0,0 +1,45 @@
>> +/** @file
>> +
>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>> +  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials
>> +  are licensed and made available under the terms and conditions of the BSD License
>> +  which accompanies this distribution.  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +
>> +**/
>> +/*++
>> +
>> +Module Name:
>> +
>> +  initplat.c
>> +
>> +Abstract:
>> +
>> +  Math routines for compatibility with native EFI library routines.
>> +
>> +--*/
>> +
>> +#include "SctLibInternal.h"
>> +
>> +VOID
>> +InitializeLibPlatform (
>> +    IN EFI_HANDLE           ImageHandle,
>> +    IN EFI_SYSTEM_TABLE     *SystemTable
>> +    )
>> +
>> +{
>> +  // No platform-specific initializations
>> +}
>> +
>> +UINT64
>> +SctReadTsc (
>> +  VOID
>> +  )
>> +{
>> +  return 0;
>> +}
>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
>> new file mode 100644
>> index 00000000..8bc2c624
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
>> @@ -0,0 +1,45 @@
>> +## @file
>> +#
>> +#  Copyright 2010 - 2012 Unified EFI, Inc.<BR>
>> +#  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
>> +#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP.<BR>
>> +#
>> +#  This program and the accompanying materials
>> +#  are licensed and made available under the terms and conditions of the BSD License
>> +#  which accompanies this distribution.  The full text of the license may be found at
>> +#  http://opensource.org/licenses/bsd-license.php
>> +#
>> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +#
>> +##
>> +#
>> +#
>> +#/*++
>> +#
>> +# Module Name:
>> +#
>> +#  GoVirtual.S
>> +#
>> +#--*/
>> +#start of the code section
>> +.text
>> +/* FIXME: Should alignment be different on Aarch64? */
> 
> 1) FIXME
> 2) Aarch64.

I have no idea why the alignment would be 3 on other platforms, so I don't know how to fix it.
If anyone knows more, please let me know. I'll just change the comment to say Riscv64.

>> +.align 3
>> +
>> +.global JumpToTestFunc
>> +.type JumpToTestFunc, %function
>> +
>> +#------------------------------------------------------------------------------
>> +# VOID
>> +# JumpToTestFunc (
>> +#   IN  UINTN  FuncPointer,
>> +#   IN  UNITN  ConfigInfo
>> +#   )
>> +# TODO: Make sure this code is correct
> 
> No TODO.
> Should this set really be called an RFC?

Yes, sorry, it's more of an RFC. I wanted to get it out before Heinrich's talk at OSFC, so he could mention it.
The code works as confirmed by Heinrich, I just hadn't cleaned it up yet.

>> +JumpToTestFunc:
>> +	mv x2, x0
>> +	mv x0, x1
>> +
>> +	// Jump to Virtual function
>> +	jalr x2
>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c
>> new file mode 100644
>> index 00000000..397b3514
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c
>> @@ -0,0 +1,182 @@
>> +/** @file
>> +
>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>> +  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials
>> +  are licensed and made available under the terms and conditions of the BSD License
>> +  which accompanies this distribution.  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +
>> +**/
>> +/*++
>> +
>> +Module Name:
>> +
>> +  VirtualMemory.c
>> +
>> +--*/
>> +
>> +#include "SCRTApp.h"
>> +
>> +#define VIRT_TO_PHYS_OFFSET       (0x80000000)     //2G
>> +
>> +BOOLEAN     HighAddress = FALSE;
>> +UINTN       PageTable   = 0;
>> +
>> +
>> +VOID
>> +ConvertRuntimeFuncPtr (
>> +  IN OUT UINTN      *VirtualFunc
>> +  )
>> +/*++
>> +
>> +Routine Description:
>> +
>> +  Change RuntimeTestFunc physical address to virtual address
>> +
>> +Arguments:
>> +
>> +  VirtualFunc  - On input, RuntimeTestFunc physical address.
>> +                 On output, RuntimeTest virtual address.
>> +
>> +Returns:
>> +
>> +  NONE
>> +
>> +--*/
>> +{
>> +	/*Note: It is presumed that on ARM v5, V6 and V7 architectures
>> +	 * the MMU is configured and enabled in PEI phase. As VirtualFunc
>> +	 * is already mapped to virtual memory, don't have to do anything here.
>> +	 */
>> +  /* FIXME: Is it the same on ARM v8? */
> 
> FIXME?
> (Even if it's copied, it's wrong :)
> ARM in general.

Fixed. Even in Riscv64 we enabled identity mapped MMU before PEI.

>> +}
>> +
>> +
>> +EFI_STATUS
>> +DoMemoryAllocation (
>> +  IN UINTN PhysicalFunc
>> +  )
>> +/*++
>> +
>> +Routine Description:
>> +
>> +  Allocate memory and create the PageTable to set up physical-virtual map.
>> +
>> +Arguments:
>> +
>> +  PhysicalFunc  - Physical address where RuntimeTestFunc locates.
>> +
>> +Returns:
>> +
>> +  EFI_STATUS
>> +
>> +--*/
>> +{
>> +  EFI_STATUS                  Status;
>> +  EFI_PHYSICAL_ADDRESS        AllocateMemory;
>> +
>> +  //create new page tables or use existing page tables.
>> +  //
>> +  // Allocate PageTable memory close to this Application image location in
>> +  // the system memory. In this way, it is safe for page table memory.
>> +  //
>> +  AllocateMemory = PhysicalFunc;
>> +
>> +  Status = tBS->AllocatePages (
>> +                  AllocateMaxAddress,
>> +                  EfiRuntimeServicesData,
>> +                  1,
>> +                  &AllocateMemory
>> +                  );
>> +
>> +  if (EFI_ERROR(Status)) {
>> +    return Status;
>> +  }
>> +
>> +  PageTable = (UINTN)AllocateMemory;
>> +  return EFI_SUCCESS;
>> +}
>> +
>> +
>> +VOID
>> +PrepareVirtualAddressMap (
>> +  IN UINTN                       MemoryMapSize,
>> +  IN UINTN                       DescriptorSize,
>> +  IN EFI_MEMORY_DESCRIPTOR       *MemoryMap,
>> +  IN EFI_MEMORY_DESCRIPTOR       *VirtualMemoryMap,
>> +  IN OUT UINTN                   *VirtualMapSize
>> +  )
>> +/*++
>> +
>> +Routine Description:
>> +
>> +  Construct VirtualAddressMap from physical address to virtual address
>> +
>> +Arguments:
>> +
>> +  MemoryMapSize     - The size, in bytes, of the MemoryMap buffer
>> +  DescriptorSize    - The size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR
>> +  MemoryMap         - A pointer to the current memory map
>> +  VirtualMemoryMap  - A pointer to the modified virtual memory map
>> +  VirtualMapSize    - A pointer to the size, in bytes, of the VirtualMemoryMap buffer
>> +
>> +Returns:
>> +
>> +  NONE
>> +
>> +--*/
>> +{
>> +  UINTN    Index;
>> +  *VirtualMapSize        = 0;
>> +
>> +  //
>> +  // Copy entries that need runtime mapping to construct virtualMemoryMap
>> +  //
>> +  for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {
>> +    if ((MemoryMap->Attribute & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) {
>> +      SctCopyMem ((VOID *) VirtualMemoryMap, (VOID *) MemoryMap, DescriptorSize);
>> +      VirtualMemoryMap->VirtualStart  = VirtualMemoryMap->PhysicalStart;
>> +      *VirtualMapSize += DescriptorSize;
>> +      VirtualMemoryMap = NextMemoryDescriptor (VirtualMemoryMap, DescriptorSize);
>> +    }
>> +
>> +    MemoryMap = NextMemoryDescriptor (MemoryMap, DescriptorSize);
>> +  }
>> +}
>> +
>> +
>> +
>> +VOID
>> +JumpVirtualMode(
>> +  IN UINTN VirtualFunc,
>> +  IN UINTN HandOffAddr
>> +  )
>> +/*++
>> +
>> +Routine Description:
>> +
>> +  Enable virtual addressing mode, and jump to RuntimeTestFunc in virtual address
>> +
>> +Arguments:
>> +
>> +  VirtualFunc  - RuntimeTestFunc virtual address
>> +  HandOffAddr  - Configuration Data Address
>> +
>> +Returns:
>> +
>> +  NONE
>> +
>> +--*/
>> +{
>> +  //
>> +  // Note: It is assumed that the MMU and page tables are configured on ARM platforms
>> +  // based on ARM v5 v6 and v7 architecture.
>> +  //
>> +  /* FIXME: Is it the same on ARM v8? */
>> +	JumpToTestFunc(VirtualFunc, HandOffAddr);
> 
> Again.

Same.

>> +}
>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c
>> new file mode 100644
>> index 00000000..6161d596
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c
>> @@ -0,0 +1,88 @@
>> +/** @file
>> +
>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>> +  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials
>> +  are licensed and made available under the terms and conditions of the BSD License
>> +  which accompanies this distribution.  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +
>> +**/
>> +
>> +/*++
>> +
>> +Module Name:
>> +
>> +  Debug.c
>> +
>> +--*/
>> +
>> +#include "SCRTDriver.h"
>> +
>> +UINTN                 mHandOffPtr        =  0;
>> +EFI_PHYSICAL_ADDRESS  mIoPortSpaceAddress = 0;
>> +
>> +
>> +EFI_STATUS
>> +ConsumeHandOff (
>> +  IN  UINTN         HandOffAddr,
>> +  OUT CONF_INFO     *ConfigData
>> +  )
>> +{
>> +   RUNTIME_HANDOFF   *HandOffPtr;
>> +   //
>> +   // First fix the memory address of hand off data.
>> +   //
>> +   FixAddress(&HandOffAddr);
>> +   mHandOffPtr = HandOffAddr;
>> +   HandOffPtr  = (RUNTIME_HANDOFF*)mHandOffPtr;
>> +   *ConfigData =  HandOffPtr->ConfigureInfo;
>> +
>> +   if (!HandOffPtr->DebuggerInfo.MmioFlag){
>> +     //
>> +     // If debug port is I/O mapped, fix IoBase Address.
>> +     //
>> +     FixAddress(&HandOffPtr->DebuggerInfo.IoBase);
>> +     mIoPortSpaceAddress = HandOffPtr->DebuggerInfo.IoBase;
> 
> Looks redundant on !x86
> 
>> +   } else {
>> +     //
>> +     // If debug port is MMIO, fix MmioBase Address.
>> +     //
>> +     FixAddress(&HandOffPtr->DebuggerInfo.MmioBase);
>> +   }
>> +
>> +   return EFI_SUCCESS;
>> +}
>> +
>> +
>> +EFI_STATUS
>> +Send2UART (
>> +  CHAR8                *String
>> +  )
>> +{
>> +  //
>> +  // TODO: On ARM platforms use platform specific functions to
>> +  // write the data to UART.
>> +  //
> 
> Ye gods...

Reminder that this is copied from the ARM sources.
In this case I'll just replace ARM by RISC-V.

>> +  return EFI_SUCCESS;
>> +}
>> +
>> +
>> +
>> +EFI_STATUS
>> +DebugWorker (
>> +  IN CHAR8    *String
>> +  )
>> +{
>> +  EFI_STATUS    Status;
>> +
>> +  //
>> +  // Send text message to registered UART.
>> +  //
>> +  Status = Send2UART(String);
>> +  return Status;
>> +}
>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c
>> new file mode 100644
>> index 00000000..cc8d9869
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c
>> @@ -0,0 +1,68 @@
>> +/** @file
>> +
>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>> +  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials
>> +  are licensed and made available under the terms and conditions of the BSD License
>> +  which accompanies this distribution.  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +
>> +**/
>> +
>> +/*++
>> +
>> +Module Name:
>> +
>> +  Dump.c
>> +
>> +--*/
>> +
>> +#include "SCRTDriver.h"
>> +
>> +VOID
>> +DumpRuntimeTable()
>> +{
>> +  SctAPrint ("\n================Dump Runtime Table===============\n");
>> +  SctAPrint ("Header Signature = 0x%x\n", VRT->Hdr.Signature);
>> +
>> +  SctAPrint ("\n================GetTime Service==============\n");
>> +  SctAPrint ("GetTime @ 0x%x\n", VRT->GetTime);
>> +
>> +  SctAPrint ("\n================SetTime Service==============\n");
>> +  SctAPrint ("SetTime @ 0x%x\n", VRT->SetTime);
>> +
>> +  SctAPrint ("\n================GetWakeupTime Service==============\n");
>> +  SctAPrint ("GetWakeupTime @ 0x%x\n", VRT->GetWakeupTime);
>> +
>> +  SctAPrint ("\n================SetWakeupTime Service==============\n");
>> +  SctAPrint ("SetWakeupTime @ 0x%x\n", VRT->SetWakeupTime);
>> +
>> +  SctAPrint ("\n================GetVariable Service==============\n");
>> +  SctAPrint ("GetVariable @ 0x%x\n", VRT->GetVariable);
>> +
>> +  SctAPrint ("\n================GetNextVariableName Service==============\n");
>> +  SctAPrint ("GetNextVariableName @ 0x%x\n", VRT->GetNextVariableName);
>> +
>> +  SctAPrint ("\n================SetVariable Service==============\n");
>> +  SctAPrint ("SetVariable @ 0x%x\n", VRT->SetVariable);
>> +
>> +  SctAPrint ("\n================GetNextHighMonotonicCount Service==============\n");
>> +  SctAPrint ("GetNextHighMonotonicCount @ 0x%x\n", VRT->GetNextHighMonotonicCount);
>> +
>> +  SctAPrint ("\n================ResetSystem Service==============\n");
>> +  SctAPrint ("ResetSystem @ 0x%x\n", VRT->ResetSystem);
>> +#if 0
> 
> Better to delete if not usable, but why disabled for AArch64 in the
> first place?

Not sure. It's also commented out in the X86 and IPF source files.
I'll keep it. I think it would be more confusing if RISC-V was the only platform
that didn't have this.

>> +  SctAPrint ("\n================UpdateCapsule Service==============\n");
>> +  SctAPrint ("UpdateCapsule @ 0x%x\n", VRT->UpdateCapsule);
>> +
>> +  SctAPrint ("\n================QueryCapsuleCapabilities Service==============\n");
>> +  SctAPrint ("QueryCapsuleCapabilities @ 0x%x\n", VRT->QueryCapsuleCapabilities);
>> +
>> +  SctAPrint ("\n================QueryVariableInfo Service==============\n");
>> +  SctAPrint ("QueryVariableInfo @ 0x%x\n", VRT->QueryVariableInfo);
>> +#endif
>> +}
>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c
>> new file mode 100644
>> index 00000000..b925e151
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c
>> @@ -0,0 +1,134 @@
>> +/** @file
>> +
>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>> +  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>
> 
> More trailing spaces than usual in line above.
> (The below block has 3 of them in every copy.)

This pattern is present in almost all files in the repo.
Should we follow up with a second patch series to fix that?
In this repo there are tons of things to clean up...
Some files have CRLF and an additional LF at the end of every line.

>> +
>> +  This program and the accompanying materials
>> +  are licensed and made available under the terms and conditions of the BSD License
>> +  which accompanies this distribution.  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +
>> +**/
>> +
>> +/*++
>> +
>> +Module Name:
>> +
>> +  Io.c
>> +
>> +--*/
>> +
>> +#include "Io.h"
>> +
>> +EFI_STATUS
>> +EFIAPI
>> +CpuIoServiceWrite (
>> +  IN EFI_PEI_CPU_IO_PPI_WIDTH  Width,
>> +  IN UINT64                     UserAddress,
>> +  IN UINTN                      Count,
>> +  IN VOID                       *UserBuffer
>> +  )
>> +/*++
>> +
>> +Routine Description:
>> +
>> +  Perform the port I/O write service
>> +
>> +Arguments:
>> +
>> +  Width   - Width of the port I/O operation
>> +  Address - Base address of the port I/O operation
>> +  Count   - Count of the number of accesses to perform
>> +  Buffer  - Pointer to the source buffer from which to write data
>> +
>> +Returns:
>> +
>> +  EFI_SUCCESS           - The data was written.
>> +  EFI_INVALID_PARAMETER - Width is invalid.
>> +  EFI_INVALID_PARAMETER - Buffer is NULL.
>> +  EFI_UNSUPPORTED       - The Buffer is not aligned for the given Width.
>> +  EFI_UNSUPPORTED       - The address range specified by Address, Width,
>> +                          and Count is not valid.
>> +
>> +--*/
>> +{
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +
>> +EFI_STATUS
>> +EfiIoWrite (
>> +  IN     EFI_PEI_CPU_IO_PPI_WIDTH  Width,
>> +  IN     UINT64                     Address,
>> +  IN     UINTN                      Count,
>> +  IN OUT VOID                       *Buffer
>> +  )
>> +/*++
>> +
>> +Routine Description:
>> +  Perform an IO write into Buffer.
>> +
>> +Arguments:
>> +  Width   - Width of write transaction, and repeat operation to use
>> +  Address - IO address to write
>> +  Count   - Number of times to write the IO address.
>> +  Buffer  - Buffer to write data from. size is Width * Count
>> +
>> +Returns:
>> +  Status code
>> +
>> +--*/
>> +{
>> +  return CpuIoServiceWrite(Width, Address, Count, Buffer);
>> +}
>> +
>> +
>> +EFI_STATUS
>> +EfiIoRead (
>> +  IN     EFI_PEI_CPU_IO_PPI_WIDTH  Width,
>> +  IN     UINT64                     Address,
>> +  IN     UINTN                      Count,
>> +  IN OUT VOID                       *Buffer
>> +  )
>> +/*++
>> +
>> +Routine Description:
>> +  Perform an IO read into Buffer.
>> +
>> +Arguments:
>> +  Width   - Width of read transaction, and repeat operation to use
>> +  Address - IO address to read
>> +  Count   - Number of times to read the IO address.
>> +  Buffer  - Buffer to read data into. size is Width * Count
>> +
>> +Returns:
>> +  Status code
>> +
>> +--*/
>> +{
>> +  return EFI_UNSUPPORTED;
>> +}
>> +
>> +
>> +VOID
>> +FixAddress (
>> +  IN UINTN     *PhyAddress
>> +  )
>> +{
>> +		//
>> +		//Note: On ARM platforms don't have to do this as all the functions are virtually mapped.
>> +		//
> 
> ARM
> 
>> +}
>> +
>> +// Quick port to ARM
>> +
>> +VOID
>> +Port80 (
>> +  UINT8 Number
>> +  )
>> +{
>> +  //EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Port80 %02x", Number));
> 
> Eew.

That function is used in some tests, that's why it's here and in both ARMs.

>> +}
>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h
>> new file mode 100644
>> index 00000000..1e78b3e4
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h
>> @@ -0,0 +1,48 @@
>> +/** @file
>> +
>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>> +  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials
>> +  are licensed and made available under the terms and conditions of the BSD License
>> +  which accompanies this distribution.  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +
> 
> Trailing spaces.
> 
>> +**/
>> +
>> +/*++
>> +
>> +Module Name:
>> +
>> +  Debug.h
>> +
>> +--*/
>> +
>> +#ifndef _IA32_IO_ACCESS_H
>> +#define _IA32_IO_ACCESS_H
> 
> Srsly?

Reminder again, that this is a file that I copied ;)
This header wasn't necessary so I removed in in my next patch series.

>> +
>> +#include "SCRTDriver.h"
>> +
>> +#define IA32_MAX_IO_ADDRESS   0xFFFF
>> +
>> +#define IA32API
>> +
>> +
>> +typedef union {
>> +  UINT8  VOLATILE  *buf;
>> +  UINT8  VOLATILE  *ui8;
>> +  UINT16 VOLATILE  *ui16;
>> +  UINT32 VOLATILE  *ui32;
>> +  UINT64 VOLATILE  *ui64;
>> +  UINTN  VOLATILE  ui;
>> +} PTR;
>> +
>> +// This address is assuming a pure PC architecture. Not required?
>> +#define   VIRT_TO_PHYS_OFFSET            (0x80000000)     //2G
>> +
>> +
>> +
>> +#endif
>> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c
>> new file mode 100644
>> index 00000000..96ee7b57
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c
>> @@ -0,0 +1,137 @@
>> +/** @file
>> +
>> +  Copyright 2006 - 2016 Unified EFI, Inc.<BR>
>> +  Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials
>> +  are licensed and made available under the terms and conditions of the BSD License
>> +  which accompanies this distribution.  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +
>> +**/
>> +/*++
>> +
>> +Module Name:
>> +
>> +  DebugSupportBBTestCacheFunction.c
>> +
>> +Abstract:
>> +
>> +  Interface Function Test Cases of Debug Support Protocol
>> +
>> +--*/
>> +
>> +
>> +#include "DebugSupportBBTestMain.h"
>> +
>> +/**
>> + *  Entrypoint for EFI_DEBUG_SUPPORT_PROTOCOL.InvalidateInstructionCache() Function Test.
>> + *  @param This a pointer of EFI_BB_TEST_PROTOCOL.
>> + *  @param ClientInterface a pointer to the interface to be tested.
>> + *  @param TestLevel test "thoroughness" control.
>> + *  @param SupportHandle a handle containing protocols required.
>> + *  @return EFI_SUCCESS Finish the test successfully.
>> + */
>> +//
>> +// TDS 3.5
>> +//
>> +EFI_STATUS
>> +BBTestInvalidateInstructionCacheFunctionAutoTest (
>> +  IN EFI_BB_TEST_PROTOCOL       *This,
>> +  IN VOID                       *ClientInterface,
>> +  IN EFI_TEST_LEVEL             TestLevel,
>> +  IN EFI_HANDLE                 SupportHandle
>> +  )
>> +{
>> +  EFI_STANDARD_TEST_LIBRARY_PROTOCOL   *StandardLib;
>> +  EFI_STATUS                           Status;
>> +  EFI_DEBUG_SUPPORT_PROTOCOL           *DebugSupport;
>> +  EFI_TEST_ASSERTION                   AssertionType;
>> +  UINT64                               Start;
>> +  UINT64                               Length;
>> +  UINTN                                MaxProcessorIndex;
>> +  UINTN                                ProcessorIndex;
>> +
>> +  //
>> +  // Get the Standard Library Interface
>> +  //
>> +  Status = gtBS->HandleProtocol (
>> +                   SupportHandle,
>> +                   &gEfiStandardTestLibraryGuid,
>> +                   (VOID **) &StandardLib
>> +                   );
>> +
>> +  if (EFI_ERROR(Status)) {
>> +    StandardLib->RecordAssertion (
>> +                   StandardLib,
>> +                   EFI_TEST_ASSERTION_FAILED,
>> +                   gTestGenericFailureGuid,
>> +                   L"BS.HandleProtocol - Handle standard test library",
>> +                   L"%a:%d:Status - %r",
>> +                   __FILE__,
>> +                   (UINTN)__LINE__,
>> +                   Status
>> +                   );
>> +    return Status;
>> +  }
>> +
>> +  DebugSupport = (EFI_DEBUG_SUPPORT_PROTOCOL *)ClientInterface;
>> +
>> +  if (DebugSupport->Isa != PlatformIsa) {
>> +    return EFI_SUCCESS;
>> +  }
>> +
>> +  Status = DebugSupport->GetMaximumProcessorIndex (DebugSupport, &MaxProcessorIndex);
>> +  if (EFI_ERROR(Status)) {
>> +    StandardLib->RecordAssertion (
>> +                   StandardLib,
>> +                   EFI_TEST_ASSERTION_FAILED,
>> +                   gTestGenericFailureGuid,
>> +                   L"EFI_DEBUG_SUPPORT_PROTOCOL.GetMaximumProcessorIndex",
>> +                   L"%a:%d:Status - %r",
>> +                   __FILE__,
>> +                   (UINTN)__LINE__,
>> +                   Status
>> +                   );
>> +    return Status;
>> +  }
>> +
>> +  for (ProcessorIndex = 0; ProcessorIndex <= MaxProcessorIndex; ProcessorIndex++) {
>> +
>> +    //
>> +    // Assertion Point 3.5.2.1
>> +    // Invoke InvalidateInstructionCache and verify interface correctness.
>> +    //
>> +
>> +    // The Physical base of the memory range to be invalidated.
>> +    Start  = 0x0;
>> +
>> +    // The minimum number of bytes in the processor's instruction cache to be invalidated.
>> +    Length = 0x0;
>> +
>> +    Status = DebugSupport->InvalidateInstructionCache (DebugSupport, ProcessorIndex, (VOID*)&Start, Length);
>> +
>> +    if (EFI_ERROR(Status)) {
>> +      AssertionType = EFI_TEST_ASSERTION_FAILED;
>> +    } else {
>> +      AssertionType = EFI_TEST_ASSERTION_PASSED;
>> +    }
>> +
>> +    StandardLib->RecordAssertion (
>> +                 StandardLib,
>> +                 AssertionType,
>> +                 gDebugSupportBBTestFunctionAssertionGuid015,
>> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.InvalidateInstructionCache - Invoke this function and verify interface correctness",
>> +                 L"%a:%d:Status - %r",
>> +                 __FILE__,
>> +                 (UINTN)__LINE__,
>> +                 Status
>> +                 );
>> +  }
>> +
>> +  return EFI_SUCCESS;
>> +}
>> +
>> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
>> new file mode 100644
>> index 00000000..c27c0c0c
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
>> @@ -0,0 +1,276 @@
>> +/** @file
>> +
>> +  Copyright 2006 - 2016 Unified EFI, Inc.<BR>
>> +  Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials
>> +  are licensed and made available under the terms and conditions of the BSD License
>> +  which accompanies this distribution.  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +
>> +**/
>> +/*++
>> +
>> +Module Name:
>> +
>> +  DebugSupportBBExceptionCallbackFunction.c
>> +
>> +Abstract:
>> +
>> +  Interface Function Test Cases of Debug Support Protocol
>> +
>> +--*/
>> +
>> +
>> +#include "DebugSupportBBTestMain.h"
>> +
>> +extern volatile  UINTN InvokedExceptionCallback;
>> +extern volatile  UINTN InvokedPeriodicCallback;
>> +
>> +extern EFI_INSTRUCTION_SET_ARCHITECTURE PlatformIsa;
>> +
>> +void
>> +SoftwareBreak (
>> +  void
>> +  )
>> +{
>> +  // Not ported to ARM yet
> 
> Eew.
> 
>> +  ASSERT (FALSE);
>> +}
>> +
>> +/**
>> + *  Entrypoint for EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback() Function Test.
>> + *  @param This a pointer of EFI_BB_TEST_PROTOCOL.
>> + *  @param ClientInterface a pointer to the interface to be tested.
>> + *  @param TestLevel test "thoroughness" control.
>> + *  @param SupportHandle a handle containing protocols required.
>> + *  @return EFI_SUCCESS Finish the test successfully.
>> + */
>> +//
>> +// TDS 3.4
>> +//
>> +EFI_STATUS
>> +BBTestRegisterExceptionCallbackFunctionManualTest (
>> +  IN EFI_BB_TEST_PROTOCOL       *This,
>> +  IN VOID                       *ClientInterface,
>> +  IN EFI_TEST_LEVEL             TestLevel,
>> +  IN EFI_HANDLE                 SupportHandle
>> +  )
>> +{
>> +  EFI_STANDARD_TEST_LIBRARY_PROTOCOL   *StandardLib;
>> +  EFI_STATUS                           Status;
>> +  EFI_DEBUG_SUPPORT_PROTOCOL           *DebugSupport;
>> +  EFI_TEST_ASSERTION                   AssertionType;
>> +
>> +  DebugSupport = (EFI_DEBUG_SUPPORT_PROTOCOL *)ClientInterface;
>> +
>> +  if (DebugSupport->Isa != PlatformIsa) {
>> +    return EFI_SUCCESS;
>> +  }
>> +
>> +  //
>> +  // Get the Standard Library Interface
>> +  //
>> +  Status = gtBS->HandleProtocol (
>> +                   SupportHandle,
>> +                   &gEfiStandardTestLibraryGuid,
>> +                   (VOID **) &StandardLib
>> +                   );
>> +
>> +  if (EFI_ERROR(Status)) {
>> +    StandardLib->RecordAssertion (
>> +                   StandardLib,
>> +                   EFI_TEST_ASSERTION_FAILED,
>> +                   gTestGenericFailureGuid,
>> +                   L"BS.HandleProtocol - Handle standard test library",
>> +                   L"%a:%d:Status - %r",
>> +                   __FILE__,
>> +                   (UINTN)__LINE__,
>> +                   Status
>> +                   );
>> +    return Status;
>> +  }
>> +
>> +  //
>> +  // Assertion Point 3.4.2.1
>> +  // Invoke RegisterExceptionCallback() to install an interrupt handler function.
>> +  //
>> +  InvokedExceptionCallback = FALSE;
>> +  // FIXME: Is it normal that we use EXCEPT_IA32_BREAKPOINT here?
>> +  // Shouldn't we define proper constants for ARM exceptions in DebugSupportProtocol.h file?
>> +  Status = DebugSupport->RegisterExceptionCallback (DebugSupport, 0, ExceptionCallback, EXCEPT_IA32_BREAKPOINT);
>> +
>> +  if ((Status == EFI_SUCCESS) || (Status == EFI_ALREADY_STARTED)) {
>> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
>> +  } else {
>> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
>> +  }
>> +
>> +  StandardLib->RecordAssertion (
>> +                 StandardLib,
>> +                 AssertionType,
>> +                 gDebugSupportBBTestFunctionAssertionGuid009,
>> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Invoke this function and verify interface correctness",
>> +                 L"%a:%d:Status - %r",
>> +                 __FILE__,
>> +                 (UINTN)__LINE__,
>> +                 Status
>> +                 );
>> +
>> +  //
>> +  // If the callback function is already registed, return
>> +  //
>> +  if (EFI_ERROR(Status)) {
>> +    return EFI_SUCCESS;
>> +  }
>> +
>> +  //
>> +  // Test the callback function registed.
>> +  //
>> +
>> +  //
>> +  // Call SoftwareBreak to invoke the interrupt handler function.
>> +  //
>> +  SoftwareBreak ();
>> +
>> +  if (InvokedExceptionCallback == FALSE) {
>> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
>> +  } else {
>> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
>> +  }
>> +
>> +  StandardLib->RecordAssertion (
>> +                 StandardLib,
>> +                 AssertionType,
>> +                 gDebugSupportBBTestFunctionAssertionGuid010,
>> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Verify the callback function was invoked.",
>> +                 L"%a:%d:Status - %r",
>> +                 __FILE__,
>> +                 (UINTN)__LINE__,
>> +                 Status
>> +                 );
>> +
>> +  //
>> +  // Assertion Point 3.4.2.2
>> +  // Invoke RegisterPeriodicCallback() to install the Periodic interrupt handler function.
>> +  // Verify the two callback functions can be both invoked.
>> +  //
>> +  InvokedExceptionCallback = FALSE;
>> +  InvokedPeriodicCallback  = FALSE;
>> +
>> +  Status = DebugSupport->RegisterPeriodicCallback (DebugSupport, 0, PeriodicCallback);
>> +  if (EFI_ERROR(Status)) {
>> +    return Status;
>> +  }
>> +
>> +  //
>> +  // Wait the PeriodicCallback to be invoked.
>> +  //
>> +  gtBS->Stall (500000);
>> +
>> +  //
>> +  // Call SoftwareBreak to invoke the interrupt handler function.
>> +  //
>> +  SoftwareBreak ();
>> +
>> +  if ((InvokedExceptionCallback == TRUE) && (InvokedPeriodicCallback == TRUE)) {
>> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
>> +  } else {
>> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
>> +  }
>> +
>> +  StandardLib->RecordAssertion (
>> +                 StandardLib,
>> +                 AssertionType,
>> +                 gDebugSupportBBTestFunctionAssertionGuid011,
>> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Verify the two callback functions can be both invoked.",
>> +                 L"%a:%d:Status - %r",
>> +                 __FILE__,
>> +                 (UINTN)__LINE__,
>> +                 Status
>> +                 );
>> +
>> +  //
>> +  // Uninstall the Periodic callback function.
>> +  //
>> +  Status = DebugSupport->RegisterPeriodicCallback (DebugSupport, 0, NULL);
>> +  if (EFI_ERROR(Status)) {
>> +    return Status;
>> +  }
>> +
>> +  //
>> +  // Assertion Point 3.4.2.3
>> +  // Invoke RegisterExceptionCallback() to install another interrupt handler function.
>> +  //
>> +  Status = DebugSupport->RegisterExceptionCallback (DebugSupport, 0, ExceptionCallback1, EXCEPT_IA32_BREAKPOINT);
>> +
>> +  if (Status != EFI_ALREADY_STARTED) {
>> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
>> +  } else {
>> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
>> +  }
>> +
>> +  StandardLib->RecordAssertion (
>> +                 StandardLib,
>> +                 AssertionType,
>> +                 gDebugSupportBBTestFunctionAssertionGuid012,
>> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Register another callback function.",
>> +                 L"%a:%d:Status - %r",
>> +                 __FILE__,
>> +                 (UINTN)__LINE__,
>> +                 Status
>> +                 );
>> +
>> +  //
>> +  // Assertion Point 3.4.2.4
>> +  // Invoke RegisterExceptionCallback() to unstall the interrupt handler function.
>> +  //
>> +  Status = DebugSupport->RegisterExceptionCallback (DebugSupport, 0, NULL, EXCEPT_IA32_BREAKPOINT);
>> +
>> +  if (EFI_ERROR(Status)) {
>> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
>> +  } else {
>> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
>> +  }
>> +
>> +  StandardLib->RecordAssertion (
>> +                 StandardLib,
>> +                 AssertionType,
>> +                 gDebugSupportBBTestFunctionAssertionGuid013,
>> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Invoke this function to uninstall the interrupt handler function",
>> +                 L"%a:%d:Status - %r",
>> +                 __FILE__,
>> +                 (UINTN)__LINE__,
>> +                 Status
>> +                 );
>> +
>> +  InvokedExceptionCallback = FALSE;
>> +
>> +  //
>> +  // Call SoftwareBreak to invoke the interrupt handler function.
>> +  //
>> +  SoftwareBreak ();
>> +
>> +  if (InvokedExceptionCallback != FALSE) {
>> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
>> +  } else {
>> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
>> +  }
>> +
>> +  StandardLib->RecordAssertion (
>> +                 StandardLib,
>> +                 AssertionType,
>> +                 gDebugSupportBBTestFunctionAssertionGuid014,
>> +                 L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Verify the callback function wasn't invoked",
>> +                 L"%a:%d:Status - %r",
>> +                 __FILE__,
>> +                 (UINTN)__LINE__,
>> +                 Status
>> +                 );
>> +
>> +  return EFI_SUCCESS;
>> +}
>> +
>> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c
>> new file mode 100644
>> index 00000000..8334f601
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c
>> @@ -0,0 +1,30 @@
>> +/** @file
>> +
>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>> +  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials
>> +  are licensed and made available under the terms and conditions of the BSD License
>> +  which accompanies this distribution.  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +
>> +**/
>> +/*++
>> +
>> +Module Name:
>> +
>> +  PlatformIsa.c
>> +
>> +Abstract:
>> +
>> +  Platform related Isa definition.
>> +
>> +--*/
>> +
>> +#include "DebugSupportBBTestMain.h"
>> +
>> +EFI_INSTRUCTION_SET_ARCHITECTURE PlatformIsa = IsaAArch64;
>> +
>> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c
>> new file mode 100644
>> index 00000000..1c1940e5
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c
>> @@ -0,0 +1,51 @@
>> +/** @file
>> +
>> +  Copyright 2006 - 2010 Unified EFI, Inc.<BR>
>> +  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials
>> +  are licensed and made available under the terms and conditions of the BSD License
>> +  which accompanies this distribution.  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +
>> +**/
>> +/**
>> + *  Ipf Source file for Mask/Unmask TimerInterrupt.
>> + */
>> +/*++
>> +
>> +Module Name:
>> +  TimerInterrupt.c
>> +
>> +Abstract:
>> +  Ipf Source file for Mask/Unmask TimerInterrupt.
>> +
>> +Author(s):
>> +
>> +
>> +References:
>> +  EFI Specification 1.10
>> +  EFI/Tiano DXE Test Case Writer's Guide
>> +
>> +Revision History:
>> +  Initial 10-20-2002
>> +  Version 0.01
>> +
>> +--*/
>> +
>> +#include "UsbHcTest.h"
>> +
>> +VOID MaskTimerInterrupt()
>> +{
>> +  // TBD
>> +  return;
>> +}
>> +
>> +VOID UnmaskTimerInterrupt()
>> +{
>> +  // TBD
>> +  return;
>> +}
>> diff --git a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h
>> new file mode 100644
>> index 00000000..ff781aee
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h
>> @@ -0,0 +1,55 @@
>> +/** @file
>> +
>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>> +  Copyright (c) 2010 - 2012, ARM Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials
>> +  are licensed and made available under the terms and conditions of the BSD License
>> +  which accompanies this distribution.  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +
>> +**/
>> +/*++
>> +
>> +Module Name:
>> +
>> +  EntsLibPlat.h
>> +
>> +Abstract:
>> +
>> +  AArch64 specific defines
>> +
>> +--*/
>> +
>> +#ifndef _EFI_LIB_PLAT_H_
>> +#define _EFI_LIB_PLAT_H_
> 
> No leading _.
> 
> /
>      Leif
> 
>> +
>> +#define MIN_ALIGNMENT_SIZE  8
>> +
>> +VOID
>> +EntsInitializeLibPlatform (
>> +  IN EFI_HANDLE           ImageHandle,
>> +  IN EFI_SYSTEM_TABLE     *SystemTable
>> +  )
>> +/*++
>> +
>> +Routine Description:
>> +
>> +  Initialize platform.
>> +
>> +Arguments:
>> +
>> +  ImageHandle           - The image handle.
>> +  SystemTable           - The system table.
>> +
>> +Returns:
>> +
>> +  None.
>> +
>> +--*/
>> +;
>> +
>> +#endif
>> diff --git a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c
>> new file mode 100644
>> index 00000000..70a509a4
>> --- /dev/null
>> +++ b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c
>> @@ -0,0 +1,55 @@
>> +/** @file
>> +
>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>> +  Copyright (c) 2010 - 2012, ARM Ltd. All rights reserved.<BR>
>> +
>> +  This program and the accompanying materials
>> +  are licensed and made available under the terms and conditions of the BSD License
>> +  which accompanies this distribution.  The full text of the license may be found at
>> +  http://opensource.org/licenses/bsd-license.php
>> +
>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>> +
>> +**/
>> +/*++
>> +
>> +Module Name:
>> +
>> +  InitPlat.c
>> +
>> +Abstract:
>> +
>> +  Math routines for compatibility with native EFI library routines.
>> +
>> +--*/
>> +
>> +#include "Efi.h"
>> +#include "EntsLibPlat.h"
>> +
>> +VOID
>> +EntsInitializeLibPlatform (
>> +  IN EFI_HANDLE           ImageHandle,
>> +  IN EFI_SYSTEM_TABLE     *SystemTable
>> +  )
>> +/*++
>> +
>> +Routine Description:
>> +
>> +  Initialize platform.
>> +
>> +Arguments:
>> +
>> +  ImageHandle           - The image handle.
>> +  SystemTable           - The system table.
>> +
>> +Returns:
>> +
>> +  None.
>> +
>> +--*/
>> +{
>> +  //
>> +  // No platform-specific initializations
>> +  //
>> +}
>> -- 
>> 2.28.0
>>
>>
>>
>> 
>>
>>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-devel] [edk2-test PATCH v1 1/2] SctPkg: Add RISCV64 support
  2020-12-02 11:44   ` [edk2-devel] " Leif Lindholm
@ 2021-02-08 15:09     ` Daniel Schaefer
  0 siblings, 0 replies; 18+ messages in thread
From: Daniel Schaefer @ 2021-02-08 15:09 UTC (permalink / raw)
  To: devel, leif
  Cc: Heinrich Schuchardt, Abner Chang, Gilbert Chen, Eric Jin,
	G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

On 12/2/20 7:44 PM, Leif Lindholm wrote:
> On Wed, Dec 02, 2020 at 00:17:51 +0800, Daniel Schaefer wrote:
>> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042
>>
>> TODO: Need to check whether we can avoid copying Aarch64 sources.
>>
>> Cc: Leif Lindholm <leif@nuviainc.com>
>> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> Cc: Abner Chang <abner.chang@hpe.com>
>> Cc: Gilbert Chen <gilbert.chen@hpe.com>
>> Cc: Eric Jin <eric.jin@intel.com>
>> Cc: G Edhaya Chandran <Edhaya.Chandran@arm.com>
>> Cc: Barton Gao <gaojie@byosoft.com.cn>
>> Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
>> Signed-off-by: Daniel Schaefer <daniel.schaefer@hpe.com>
>> ---
>>   uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h                                      |  3 +
>>   uefi-sct/SctPkg/Library/SctLib/SctLib.inf                                                   |  6 ++
>>   uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf                                                    |  6 ++
>>   uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf                                              |  7 +++
>>   uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf |  6 ++
>>   uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf               |  4 ++
>>   uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf                 |  4 ++
>>   uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf                    |  5 ++
>>   uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile                                             |  3 +
>>   uefi-sct/SctPkg/UEFI/IHV_SCT.dsc                                                            | 14 ++++-
>>   uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h                                                | 62 +++++++++++++++++++-
>>   uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc                                                           | 14 ++++-
>>   uefi-sct/SctPkg/build.sh                                                                    | 10 +++-
>>   13 files changed, 140 insertions(+), 4 deletions(-)
>>
>> diff --git a/uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h b/uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h
>> index a7815580..3a7c8f31 100644
>> --- a/uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h
>> +++ b/uefi-sct/SctPkg/Application/InstallSct/InstallSctDef.h
>> @@ -32,6 +32,9 @@
>>   #elif defined(EFIAARCH64)
>>     #define INSTALL_SCT_PLATFORM_SHORT_NAME   L"aarch64"
>>     #define INSTALL_SCT_PLATFORM_NAME         L"AARCH64"
>> +#elif defined(EFIRISCV64)
>> +  #define INSTALL_SCT_PLATFORM_SHORT_NAME   L"riscv64"
>> +  #define INSTALL_SCT_PLATFORM_NAME         L"RISCV64"
>>   #else
>>     #error "Architecture not supported"
>>   #endif
>> diff --git a/uefi-sct/SctPkg/Library/SctLib/SctLib.inf b/uefi-sct/SctPkg/Library/SctLib/SctLib.inf
>> index 23cb77fb..6f59d974 100644
>> --- a/uefi-sct/SctPkg/Library/SctLib/SctLib.inf
>> +++ b/uefi-sct/SctPkg/Library/SctLib/SctLib.inf
>> @@ -62,6 +62,12 @@
>>     Aarch64/initplat.c
>>     Math.c
>>   
>> +# TODO: Copied source from AARCH64, need to check if they need to be adjusted
> 
> TODOs need to go, throughout.

All resolved in the next patch series.

>> +[sources.RISCV64]
>> +  Riscv64/SctLibPlat.h
>> +  Riscv64/initplat.c
>> +  Math.c
>> +
>>   [sources.ia32]
>>     ia32/SctLibPlat.h
>>     ia32/initplat.c
>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf b/uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf
>> index 7aca6e30..66de4cac 100644
>> --- a/uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf
>> +++ b/uefi-sct/SctPkg/SCRT/SCRTApp/SCRTApp.inf
>> @@ -39,6 +39,12 @@
>>     Aarch64/GoVirtual.asm | RVCT
>>     Aarch64/GoVirtual.S | GCC
>>   
>> +# TODO: Copied source from AARCH64, need to check if they need to be adjusted
>> +#       ASM is adjusted but not sure if it is correct
>> +[sources.RISCV64]
>> +  Riscv64/VirtualMemory.c
>> +  Riscv64/GoVirtual.S | GCC
>> +
>>   [sources.ia32]
>>     ia32/VirtualMemory.c
>>     ia32/GoVirtual.asm | MSFT
>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf b/uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf
>> index ad0eb0f8..bc0ade5b 100644
>> --- a/uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf
>> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/SCRTDriver.inf
>> @@ -69,6 +69,13 @@
>>     Aarch64/Dump.c
>>     Aarch64/Debug.c
>>   
>> +# TODO: Copied source from AARCH64, need to check if they need to be adjusted
>> +[sources.RISCV64]
>> +  Riscv64/Io.c
>> +  Riscv64/Io.h
>> +  Riscv64/Dump.c
>> +  Riscv64/Debug.c
>> +
>>   [sources.common]
>>     Guid.h
>>     Guid.c
>> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf
>> index 799f86fd..7010c7f1 100644
>> --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf
>> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/DebugSupportBBTest.inf
>> @@ -67,6 +67,12 @@
>>     Aarch64/DebugSupportBBTestExceptionCallbackFunction.c
>>     Aarch64/DebugSupportBBTestCacheFunction.c
>>   
>> +# TODO: Copied source from AARCH64, need to check if they need to be adjusted
>> +[sources.RISCV64]
>> +  Riscv64/PlatformIsa.c
>> +  Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
>> +  Riscv64/DebugSupportBBTestCacheFunction.c
>> +
>>   [Packages]
>>     SctPkg/SctPkg.dec
>>     SctPkg/UEFI/UEFI.dec
>> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf
>> index e8118739..e42acd29 100644
>> --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf
>> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/Usb2Hc/BlackBoxTest/Usb2HcTest.inf
>> @@ -55,6 +55,10 @@
>>   #[sources.Aarch64]
>>   #  IPF/TimerInterrupt.c
>>   
>> +# TODO: Seems like almost all archs can use the IPF code, need to check
>> +[sources.Riscv64]
>> +  IPF/TimerInterrupt.c
>> +
>>   [Packages]
>>     MdePkg/MdePkg.dec
>>     SctPkg/SctPkg.dec
>> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf
>> index efc438c1..0d47536f 100644
>> --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf
>> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/UsbHcTest.inf
>> @@ -55,6 +55,10 @@
>>   [sources.Aarch64]
>>     Aarch64/TimerInterrupt.c
>>   
>> +# TODO: Copied source from AARCH64, need to check if they need to be adjusted
>> +[sources.RISCV64]
>> +  Riscv64/TimerInterrupt.c
>> +
>>   [Packages]
>>     MdePkg/MdePkg.dec
>>     SctPkg/SctPkg.dec
>> diff --git a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf
>> index 23f12d1a..1b2a92f2 100644
>> --- a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf
>> +++ b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/EntsLib.inf
>> @@ -66,6 +66,11 @@
>>     Aarch64/EntsLibPlat.h
>>     Aarch64/InitPlat.c
>>   
>> +# TODO: Copied source from AARCH64, need to check if they need to be adjusted
>> +[sources.RISCV64]
>> +  Riscv64/EntsLibPlat.h
>> +  Riscv64/InitPlat.c
>> +
>>   [Packages]
>>     MdePkg/MdePkg.dec
>>     SctPkg/SctPkg.dec
>> diff --git a/uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile b/uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile
>> index c235f313..e49284e7 100644
>> --- a/uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile
>> +++ b/uefi-sct/SctPkg/Tools/Source/GenBin/GNUmakefile
>> @@ -31,6 +31,9 @@ ifndef ARCH
>>     ifneq (,$(findstring arm,$(uname_m)))
>>       ARCH=ARM
>>     endif
>> +  ifneq (,$(findstring riscv64,$(uname_m)))
>> +    ARCH=RISCV64
>> +  endif
>>     ifndef ARCH
>>       $(info Could not detected ARCH from uname results)
>>       $(error ARCH is not defined!)
>> diff --git a/uefi-sct/SctPkg/UEFI/IHV_SCT.dsc b/uefi-sct/SctPkg/UEFI/IHV_SCT.dsc
>> index f9e86264..2f373c5f 100644
>> --- a/uefi-sct/SctPkg/UEFI/IHV_SCT.dsc
>> +++ b/uefi-sct/SctPkg/UEFI/IHV_SCT.dsc
>> @@ -42,7 +42,7 @@
>>     PLATFORM_VERSION               = 0.1
>>     DSC_SPECIFICATION              = 0x00010005
>>     OUTPUT_DIRECTORY               = Build/IhvSct
>> -  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64
>> +  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64|RISCV64
>>     BUILD_TARGETS                  = DEBUG|RELEASE
>>     SKUID_IDENTIFIER               = DEFAULT
>>   
>> @@ -109,6 +109,12 @@
>>     *_*_AARCH64_PP_FLAGS         = -D EFIAARCH64 $(GCC_VER_MACRO)
>>     RVCT:*_*_AARCH64_DLINK_FLAGS = --muldefweak
>>   
>> +  *_*_RISCV64_CC_FLAGS         = -D EFIRISCV64 $(GCC_VER_MACRO)
>> +  GCC:*_*_RISCV64_CC_FLAGS  = -D EFIRISCV64 $(GCC_VER_MACRO) -ffreestanding -nostdinc -nostdlib -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error
> 
> These flags do not look RISCV64-specific.
> If there are bugs to be fixed in common code, they should be fixed.
> If there are too many to usefully test, then the flags should be set
> for
> GCC:*_*_*_CC_FLAGS

Okay sure, I'll clean it up for all architectures.

>> +  *_*_RISCV64_VFRPP_FLAGS      = -D EFIRISCV64 $(GCC_VER_MACRO)
>> +  *_*_RISCV64_APP_FLAGS        = -D EFIRISCV64 $(GCC_VER_MACRO)
>> +  *_*_RISCV64_PP_FLAGS         = -D EFIRISCV64 $(GCC_VER_MACRO)
>> +
>>     DEBUG_*_*_CC_FLAGS  = -DEFI_DEBUG
>>     RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG
>>   
>> @@ -124,6 +130,9 @@
>>   [Libraries.AARCH64]
>>     ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
>>   
>> +[Libraries.RISCV64]
>> +  ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
>> +
>>   [Libraries.IA32,Libraries.X64]
>>   
>>   [LibraryClasses.common]
>> @@ -146,6 +155,9 @@
>>   [LibraryClasses.AARCH64]
>>     NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
>>   
>> +[LibraryClasses.RISCV64]
>> +  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
>> +
>>   [LibraryClasses.IA32]
>>   
>>   ###############################################################################
>> diff --git a/uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h b/uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h
>> index 7fba87ae..fb11bda4 100644
>> --- a/uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h
>> +++ b/uefi-sct/SctPkg/UEFI/Protocol/DebugSupport.h
>> @@ -607,6 +607,60 @@ typedef struct {
>>     UINT64  FAR;  // Fault Address Register
>>   } EFI_SYSTEM_CONTEXT_AARCH64;
>>   
>> +///
>> +/// RISC-V processor exception types.
>> +///
>> +#define EXCEPT_RISCV_INST_MISALIGNED              0
>> +#define EXCEPT_RISCV_INST_ACCESS_FAULT            1
>> +#define EXCEPT_RISCV_ILLEGAL_INST                 2
>> +#define EXCEPT_RISCV_BREAKPOINT                   3
>> +#define EXCEPT_RISCV_LOAD_ADDRESS_MISALIGNED      4
>> +#define EXCEPT_RISCV_LOAD_ACCESS_FAULT            5
>> +#define EXCEPT_RISCV_STORE_AMO_ADDRESS_MISALIGNED 6
>> +#define EXCEPT_RISCV_STORE_AMO_ACCESS_FAULT       7
>> +#define EXCEPT_RISCV_ENV_CALL_FROM_UMODE          8
>> +#define EXCEPT_RISCV_ENV_CALL_FROM_SMODE          9
>> +#define EXCEPT_RISCV_ENV_CALL_FROM_HMODE          10
>> +#define EXCEPT_RISCV_ENV_CALL_FROM_MMODE          11
>> +
>> +#define EXCEPT_RISCV_SOFTWARE_INT       0x0
>> +#define EXCEPT_RISCV_TIMER_INT          0x1
>> +
>> +typedef struct {
>> +  UINT64  X0;
>> +  UINT64  X1;
>> +  UINT64  X2;
>> +  UINT64  X3;
>> +  UINT64  X4;
>> +  UINT64  X5;
>> +  UINT64  X6;
>> +  UINT64  X7;
>> +  UINT64  X8;
>> +  UINT64  X9;
>> +  UINT64  X10;
>> +  UINT64  X11;
>> +  UINT64  X12;
>> +  UINT64  X13;
>> +  UINT64  X14;
>> +  UINT64  X15;
>> +  UINT64  X16;
>> +  UINT64  X17;
>> +  UINT64  X18;
>> +  UINT64  X19;
>> +  UINT64  X20;
>> +  UINT64  X21;
>> +  UINT64  X22;
>> +  UINT64  X23;
>> +  UINT64  X24;
>> +  UINT64  X25;
>> +  UINT64  X26;
>> +  UINT64  X27;
>> +  UINT64  X28;
>> +  UINT64  X29;
>> +  UINT64  X30;
>> +  UINT64  X31;
>> +} EFI_SYSTEM_CONTEXT_RISCV64;
>> +
>>   //
>>   // Universal EFI_SYSTEM_CONTEXT definition
>>   //
>> @@ -618,6 +672,7 @@ union {
>>     EFI_SYSTEM_CONTEXT_IPF                  *SystemContextIpf;
>>     EFI_SYSTEM_CONTEXT_ARM                  *SystemContextArm;
>>     EFI_SYSTEM_CONTEXT_AARCH64              *SystemContextAArch64;
>> +  EFI_SYSTEM_CONTEXT_RISCV64              *SystemContextRiscV64;
>>   } EFI_SYSTEM_CONTEXT;
>>   
>>   //
>> @@ -645,6 +700,10 @@ VOID
>>   #define IMAGE_FILE_MACHINE_EBC             0x0EBC
>>   #define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED  0x01c2
>>   #define IMAGE_FILE_MACHINE_ARM64           0xAA64
>> +#define IMAGE_FILE_MACHINE_RISCV32         0x5032
>> +#define IMAGE_FILE_MACHINE_RISCV64         0x5064
>> +#define IMAGE_FILE_MACHINE_RISCV128        0x5128
> 
> This set is not adding support for RISCV32/RISCV128, so no real point
> adding those #defines.

Ok, sure.

>> +
>>   
>>   typedef
>>   enum {
>> @@ -653,7 +712,8 @@ enum {
>>     IsaIpf  = IMAGE_FILE_MACHINE_IA64,
>>     IsaEbc  = IMAGE_FILE_MACHINE_EBC,
>>     IsaArm  = IMAGE_FILE_MACHINE_ARMTHUMB_MIXED, ///< 0x01c2
>> -  IsaAArch64  = IMAGE_FILE_MACHINE_ARM64       ///< 0xAA64
>> +  IsaAArch64  = IMAGE_FILE_MACHINE_ARM64,      ///< 0xAA64
>> +  IsaRiscv64  = IMAGE_FILE_MACHINE_RISCV64
> 
> Add the doxygen comment to match the others.
> 
>>   } EFI_INSTRUCTION_SET_ARCHITECTURE;
>>   
>>   typedef struct _EFI_DEBUG_SUPPORT_PROTOCOL EFI_DEBUG_SUPPORT_PROTOCOL;;
>> diff --git a/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc b/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc
>> index 2e97687b..666f06dd 100644
>> --- a/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc
>> +++ b/uefi-sct/SctPkg/UEFI/UEFI_SCT.dsc
>> @@ -42,7 +42,7 @@
>>     PLATFORM_VERSION               = 0.1
>>     DSC_SPECIFICATION              = 0x00010005
>>     OUTPUT_DIRECTORY               = Build/UefiSct
>> -  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64
>> +  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64|RISCV64
>>     BUILD_TARGETS                  = DEBUG|RELEASE
>>     SKUID_IDENTIFIER               = DEFAULT
>>     
>> @@ -112,6 +112,12 @@
>>     *_*_AARCH64_PP_FLAGS         = -D EFIAARCH64 $(GCC_VER_MACRO)
>>     RVCT:*_*_AARCH64_DLINK_FLAGS = --muldefweak
>>   
>> +  *_*_RISCV64_CC_FLAGS         = -D EFIRISCV64 $(GCC_VER_MACRO)
>> +  GCC:*_*_RISCV64_CC_FLAGS     = -D EFIRISCV64 $(GCC_VER_MACRO) -ffreestanding -nostdinc -nostdlib -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error
> 
> Same as above.

Done.

> /
>      Leif
> 
>> +  *_*_RISCV64_VFRPP_FLAGS      = -D EFIRISCV64 $(GCC_VER_MACRO)
>> +  *_*_RISCV64_APP_FLAGS        = -D EFIRISCV64 $(GCC_VER_MACRO)
>> +  *_*_RISCV64_PP_FLAGS         = -D EFIRISCV64 $(GCC_VER_MACRO)
>> +
>>     DEBUG_*_*_CC_FLAGS  = -DEFI_DEBUG
>>     RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG
>>   
>> @@ -129,6 +135,9 @@
>>   [Libraries.AARCH64]
>>     ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
>>   
>> +[Libraries.RISCV64]
>> +  ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
>> +
>>   [LibraryClasses.common]
>>     UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
>>     UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
>> @@ -157,6 +166,9 @@
>>   [LibraryClasses.AARCH64]
>>     NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
>>   
>> +[LibraryClasses.RISCV64]
>> +  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
>> +
>>   ###############################################################################
>>   #
>>   # These are the components that will be built by the master makefile
>> diff --git a/uefi-sct/SctPkg/build.sh b/uefi-sct/SctPkg/build.sh
>> index cad17ccd..3d61daed 100755
>> --- a/uefi-sct/SctPkg/build.sh
>> +++ b/uefi-sct/SctPkg/build.sh
>> @@ -22,6 +22,8 @@ function get_build_arch
>>   	        BUILD_ARCH=ARM;;
>>   	    aarch64*)
>>   	        BUILD_ARCH=AARCH64;;
>> +	    riscv64*)
>> +	        BUILD_ARCH=RISCV64;;
>>   	    *)
>>   	        BUILD_ARCH=other;;
>>   	esac
>> @@ -47,6 +49,12 @@ function set_cross_compile
>>   	    else
>>   	        TEMP_CROSS_COMPILE=arm-linux-gnueabihf-
>>   	    fi
>> +	elif [ "$SCT_TARGET_ARCH" == "RISCV64" ]; then
>> +	    if [ X"$CROSS_COMPILE_64" != X"" ]; then
>> +	        TEMP_CROSS_COMPILE="$CROSS_COMPILE_64"
>> +	    else
>> +	        TEMP_CROSS_COMPILE=riscv64-unknown-elf-
>> +	    fi
>>   	else
>>   	    echo "Unsupported target architecture '$SCT_TARGET_ARCH'!" >&2
>>   	fi
>> @@ -110,7 +118,7 @@ PrintUsage() {
>>   	#Print Help
>>   	#
>>   	echo "Usage:"
>> -	echo "    $0 <architecture (ARM, AARCH64, X64, etc)> \
>> +	echo "    $0 <architecture (ARM, AARCH64, X64, RISCV64, etc)> \
>>   <toolchain name (RVCT or ARMGCC or GCC*)> \
>>   [build type (RELEASE OR DEBUG, DEFAULT: DEBUG)]"
>>   }
>> -- 
>> 2.28.0
>>
>>
>>
>>
>>
>>
> 
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg
  2021-02-08 14:30       ` Daniel Schaefer
@ 2021-02-08 15:50         ` Heinrich Schuchardt
  0 siblings, 0 replies; 18+ messages in thread
From: Heinrich Schuchardt @ 2021-02-08 15:50 UTC (permalink / raw)
  To: Daniel Schaefer, devel
  Cc: Leif Lindholm, Abner Chang, Gilbert Chen, Eric Jin,
	G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

On 08.02.21 15:30, Daniel Schaefer wrote:
> On 12/2/20 1:37 AM, Heinrich Schuchardt wrote:
>> On 12/1/20 6:11 PM, Daniel Schaefer wrote:
>>> On 12/2/20 12:59 AM, Heinrich Schuchardt wrote:
>>>> On 12/1/20 5:17 PM, Daniel Schaefer wrote:
>>>>> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042
>>>>>
>>>>> With this patch series we can build the UEFI SCT for RISCV64. It was
>>>>> confirmed
>>>>> to be working on the U-Boot UEFI implementation by Heinrich.
>>>>> It hasn't been tested on EDK2 yet.
>>>>>
>>>>> Build requirements are the same as for the EDK2 RISCV64 port and
>>>>> detailed here:
>>>>> https://github.com/riscv/riscv-uefi-edk2-docs
>>>>>
>>>>> The second patch is a big one because it adds architecture specific
>>>>> files by
>>>>> copying them from the Aarch64 directory. Only a single file, an
>>>>> assembly file
>>>>> needed modifications. I'm not sure why the other ones are in an
>>>>> architecture
>>>>> specific directory. They're all C files and seem to be generic. We
>>>>> can probably
>>>>> unify them.
>>>>
>>>> Hello Daniel,
>>>>
>>>> thanks a lot for your patches.
>>>>
>>>> You address the uefi-sct/SctPkg/TestCase/UEFI/EFI directory.
>>>>
>>>> Are you planning future patches for uefi-sct/SctPkg/TestCase/UEFI/IHV
>>>> too?
>>>
>>> I grepped the repo for strings related to arm64 and aarch64. I ported
>>> what I found.
>>> Do you see anything that's not ported?
>>
>> uefi-sct/SctPkg/UEFI/IHV_SCT.dsc is the only IHV related file with
>> AARCH64 in it and that one is covered by your patch series.
>>
>>>
>>> The only thing I see, is in
>>> Protocol/UsbIo/BlackBoxTest/UsbIoTestConformance.c
>>> where some code is not used for ARM because:
>>>
>>>    // Note: This function uses the EDKII Glu library from EDKII
>>> compatibility pkg.
>>>
>>>    // which is not ported to ARM yet. Hence for the time being just
>>> return success.
>>>
>>>
>>> I'm not yet sure what library that's referring to, but most likely it's
>>> also
>>> not implemented for RISC-V.
>>
>> I assume this refers to:
>> https://github.com/tianocore/edk/tree/master/Foundation/Library/EdkIIGlueLib
>>
>>
>> The files of this library are in edk2/MdePkg/Library now.
>
> Wow, that code is ancient then. I'm not gonna ifdef it out for RISC-V.
> If it works for x86 it might work for RISC-V now.
> Maybe the ARM people can try it on ARM first ;)
>
>>> Thanks for testing!
>>> Does the SCT result look like what you expect? Or are some tests failing
>>> that you expect to succeed?
>>
>> Not all tests have run yet. Running SCT on QEMU is really slow.
>>
>> But from what I can see there is no difference to AARCH64 results on
>> QEMU.
>
> Sounds great! I assume all the tests have succeeded now?

The SCT version built for RISC-V with you patches returned equivalent
results to ARM for U-Boot.

Best regards

Heinrich

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-devel] [edk2-test PATCH v1 2/2] SctPkg: Enable RISCV64 support using AARCH64 sources
  2021-02-08 15:09     ` Daniel Schaefer
@ 2021-02-08 17:04       ` Heinrich Schuchardt
  2021-02-09 12:42         ` Leif Lindholm
  0 siblings, 1 reply; 18+ messages in thread
From: Heinrich Schuchardt @ 2021-02-08 17:04 UTC (permalink / raw)
  To: Daniel Schaefer, Leif Lindholm, devel
  Cc: Abner Chang, Gilbert Chen, Eric Jin, G Edhaya Chandran,
	Barton Gao, Samer El-Haj-Mahmoud

On 08.02.21 16:09, Daniel Schaefer wrote:
> Hi Leif,
>
> thanks very much for the review!
> I've cleaned up the patchset and addressed the issues. I'll send out
> another set soon.
> See comments below.
>
> Thanks,
> Daniel
>
> On 12/2/20 8:04 PM, Leif Lindholm wrote:
>> On Wed, Dec 02, 2020 at 00:17:52 +0800, Daniel Schaefer wrote:
>>> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3042
>>>
>>> TODO: Need to check whether we can avoid copying Aarch64 sources.
>>>
>>> Cc: Leif Lindholm <leif@nuviainc.com>
>>> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
>>> Cc: Abner Chang <abner.chang@hpe.com>
>>> Cc: Gilbert Chen <gilbert.chen@hpe.com>
>>> Cc: Eric Jin <eric.jin@intel.com>
>>> Cc: G Edhaya Chandran <Edhaya.Chandran@arm.com>
>>> Cc: Barton Gao <gaojie@byosoft.com.cn>
>>> Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
>>> Signed-off-by: Daniel Schaefer <daniel.schaefer@hpe.com>
>>> ---
>>>  
>>> uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h                                                                       
>>> |  32 +++
>>>  
>>> uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c                                                                         
>>> |  45 ++++
>>>  
>>> uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S                                                                          
>>> |  45 ++++
>>>  
>>> uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c                                                                      
>>> | 182 +++++++++++++
>>>  
>>> uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c                                                                           
>>> |  88 +++++++
>>>  
>>> uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c                                                                            
>>> |  68 +++++
>>>  
>>> uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c                                                                              
>>> | 134 ++++++++++
>>>  
>>> uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h                                                                              
>>> |  48 ++++
>>>  
>>> uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c            
>>> | 137 ++++++++++
>>>  
>>> uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
>>> | 276 ++++++++++++++++++++
>>>  
>>> uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c                                
>>> |  30 +++
>>>  
>>> uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c                                    
>>> |  51 ++++
>>>  
>>> uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h                                        
>>> |  55 ++++
>>>  
>>> uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c                                           
>>> |  55 ++++
>>>   14 files changed, 1246 insertions(+)
>>>
>>> diff --git a/uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h
>>> b/uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h
>>> new file mode 100644
>>> index 00000000..ee7c656b
>>> --- /dev/null
>>> +++ b/uefi-sct/SctPkg/Library/SctLib/Riscv64/SctLibPlat.h
>>> @@ -0,0 +1,32 @@
>>> +/** @file
>>> +
>>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>>> +  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
>>> +
>>> +  This program and the accompanying materials
>>> +  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +  which accompanies this distribution.  The full text of the license
>>> may be found at
>>> +  http://opensource.org/licenses/bsd-license.php
>>> +
>>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +
>>> +**/
>>> +/*++
>>> +
>>> +Module Name:
>>> +
>>> +  SctLibPlat.h
>>> +
>>> +Abstract:
>>> +
>>> +  AArch64 specific defines
>>
>> *cough*
>
> For the next patch series I went through everything and made sure that
> there's no Aarch64 or ARM anymore.
>
>>> +
>>> +--*/
>>> +
>>> +#ifndef _EFI_LIB_PLAT_H_
>>> +#define _EFI_LIB_PLAT_H_
>>
>> No leading _ in macros.
>
> This is a common pattern in the code. Even in EDK2.
>
>>> +
>>> +#define MIN_ALIGNMENT_SIZE  8
>>> +
>>> +#endif
>>> diff --git a/uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c
>>> b/uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c
>>> new file mode 100644
>>> index 00000000..a48bb2f3
>>> --- /dev/null
>>> +++ b/uefi-sct/SctPkg/Library/SctLib/Riscv64/initplat.c
>>> @@ -0,0 +1,45 @@
>>> +/** @file
>>> +
>>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>>> +  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
>>> +
>>> +  This program and the accompanying materials
>>> +  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +  which accompanies this distribution.  The full text of the license
>>> may be found at
>>> +  http://opensource.org/licenses/bsd-license.php
>>> +
>>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +
>>> +**/
>>> +/*++
>>> +
>>> +Module Name:
>>> +
>>> +  initplat.c
>>> +
>>> +Abstract:
>>> +
>>> +  Math routines for compatibility with native EFI library routines.
>>> +
>>> +--*/
>>> +
>>> +#include "SctLibInternal.h"
>>> +
>>> +VOID
>>> +InitializeLibPlatform (
>>> +    IN EFI_HANDLE           ImageHandle,
>>> +    IN EFI_SYSTEM_TABLE     *SystemTable
>>> +    )
>>> +
>>> +{
>>> +  // No platform-specific initializations
>>> +}
>>> +
>>> +UINT64
>>> +SctReadTsc (
>>> +  VOID
>>> +  )
>>> +{
>>> +  return 0;
>>> +}
>>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
>>> b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
>>> new file mode 100644
>>> index 00000000..8bc2c624
>>> --- /dev/null
>>> +++ b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
>>> @@ -0,0 +1,45 @@
>>> +## @file
>>> +#
>>> +#  Copyright 2010 - 2012 Unified EFI, Inc.<BR>
>>> +#  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
>>> +#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP.<BR>
>>> +#
>>> +#  This program and the accompanying materials
>>> +#  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +#  which accompanies this distribution.  The full text of the
>>> license may be found at
>>> +#  http://opensource.org/licenses/bsd-license.php
>>> +#
>>> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
>>> BASIS,
>>> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +#
>>> +##
>>> +#
>>> +#
>>> +#/*++
>>> +#
>>> +# Module Name:
>>> +#
>>> +#  GoVirtual.S
>>> +#
>>> +#--*/
>>> +#start of the code section
>>> +.text
>>> +/* FIXME: Should alignment be different on Aarch64? */
>>
>> 1) FIXME
>> 2) Aarch64.
>
> I have no idea why the alignment would be 3 on other platforms, so I
> don't know how to fix it.
> If anyone knows more, please let me know. I'll just change the comment
> to say Riscv64.
>
>>> +.align 3

Both on Aarch64 and on RISC-V an odd alignment value makes no sense.

.align 8 should do no harm. But is it needed?

Best regards

Heinrich


>>> +
>>> +.global JumpToTestFunc
>>> +.type JumpToTestFunc, %function
>>> +
>>> +#------------------------------------------------------------------------------
>>>
>>> +# VOID
>>> +# JumpToTestFunc (
>>> +#   IN  UINTN  FuncPointer,
>>> +#   IN  UNITN  ConfigInfo
>>> +#   )
>>> +# TODO: Make sure this code is correct
>>
>> No TODO.
>> Should this set really be called an RFC?
>
> Yes, sorry, it's more of an RFC. I wanted to get it out before
> Heinrich's talk at OSFC, so he could mention it.
> The code works as confirmed by Heinrich, I just hadn't cleaned it up yet.
>
>>> +JumpToTestFunc:
>>> +    mv x2, x0
>>> +    mv x0, x1
>>> +
>>> +    // Jump to Virtual function
>>> +    jalr x2
>>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c
>>> b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c
>>> new file mode 100644
>>> index 00000000..397b3514
>>> --- /dev/null
>>> +++ b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/VirtualMemory.c
>>> @@ -0,0 +1,182 @@
>>> +/** @file
>>> +
>>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>>> +  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
>>> +
>>> +  This program and the accompanying materials
>>> +  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +  which accompanies this distribution.  The full text of the license
>>> may be found at
>>> +  http://opensource.org/licenses/bsd-license.php
>>> +
>>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +
>>> +**/
>>> +/*++
>>> +
>>> +Module Name:
>>> +
>>> +  VirtualMemory.c
>>> +
>>> +--*/
>>> +
>>> +#include "SCRTApp.h"
>>> +
>>> +#define VIRT_TO_PHYS_OFFSET       (0x80000000)     //2G
>>> +
>>> +BOOLEAN     HighAddress = FALSE;
>>> +UINTN       PageTable   = 0;
>>> +
>>> +
>>> +VOID
>>> +ConvertRuntimeFuncPtr (
>>> +  IN OUT UINTN      *VirtualFunc
>>> +  )
>>> +/*++
>>> +
>>> +Routine Description:
>>> +
>>> +  Change RuntimeTestFunc physical address to virtual address
>>> +
>>> +Arguments:
>>> +
>>> +  VirtualFunc  - On input, RuntimeTestFunc physical address.
>>> +                 On output, RuntimeTest virtual address.
>>> +
>>> +Returns:
>>> +
>>> +  NONE
>>> +
>>> +--*/
>>> +{
>>> +    /*Note: It is presumed that on ARM v5, V6 and V7 architectures
>>> +     * the MMU is configured and enabled in PEI phase. As VirtualFunc
>>> +     * is already mapped to virtual memory, don't have to do
>>> anything here.
>>> +     */
>>> +  /* FIXME: Is it the same on ARM v8? */
>>
>> FIXME?
>> (Even if it's copied, it's wrong :)
>> ARM in general.
>
> Fixed. Even in Riscv64 we enabled identity mapped MMU before PEI.
>
>>> +}
>>> +
>>> +
>>> +EFI_STATUS
>>> +DoMemoryAllocation (
>>> +  IN UINTN PhysicalFunc
>>> +  )
>>> +/*++
>>> +
>>> +Routine Description:
>>> +
>>> +  Allocate memory and create the PageTable to set up
>>> physical-virtual map.
>>> +
>>> +Arguments:
>>> +
>>> +  PhysicalFunc  - Physical address where RuntimeTestFunc locates.
>>> +
>>> +Returns:
>>> +
>>> +  EFI_STATUS
>>> +
>>> +--*/
>>> +{
>>> +  EFI_STATUS                  Status;
>>> +  EFI_PHYSICAL_ADDRESS        AllocateMemory;
>>> +
>>> +  //create new page tables or use existing page tables.
>>> +  //
>>> +  // Allocate PageTable memory close to this Application image
>>> location in
>>> +  // the system memory. In this way, it is safe for page table memory.
>>> +  //
>>> +  AllocateMemory = PhysicalFunc;
>>> +
>>> +  Status = tBS->AllocatePages (
>>> +                  AllocateMaxAddress,
>>> +                  EfiRuntimeServicesData,
>>> +                  1,
>>> +                  &AllocateMemory
>>> +                  );
>>> +
>>> +  if (EFI_ERROR(Status)) {
>>> +    return Status;
>>> +  }
>>> +
>>> +  PageTable = (UINTN)AllocateMemory;
>>> +  return EFI_SUCCESS;
>>> +}
>>> +
>>> +
>>> +VOID
>>> +PrepareVirtualAddressMap (
>>> +  IN UINTN                       MemoryMapSize,
>>> +  IN UINTN                       DescriptorSize,
>>> +  IN EFI_MEMORY_DESCRIPTOR       *MemoryMap,
>>> +  IN EFI_MEMORY_DESCRIPTOR       *VirtualMemoryMap,
>>> +  IN OUT UINTN                   *VirtualMapSize
>>> +  )
>>> +/*++
>>> +
>>> +Routine Description:
>>> +
>>> +  Construct VirtualAddressMap from physical address to virtual address
>>> +
>>> +Arguments:
>>> +
>>> +  MemoryMapSize     - The size, in bytes, of the MemoryMap buffer
>>> +  DescriptorSize    - The size, in bytes, of an individual
>>> EFI_MEMORY_DESCRIPTOR
>>> +  MemoryMap         - A pointer to the current memory map
>>> +  VirtualMemoryMap  - A pointer to the modified virtual memory map
>>> +  VirtualMapSize    - A pointer to the size, in bytes, of the
>>> VirtualMemoryMap buffer
>>> +
>>> +Returns:
>>> +
>>> +  NONE
>>> +
>>> +--*/
>>> +{
>>> +  UINTN    Index;
>>> +  *VirtualMapSize        = 0;
>>> +
>>> +  //
>>> +  // Copy entries that need runtime mapping to construct
>>> virtualMemoryMap
>>> +  //
>>> +  for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {
>>> +    if ((MemoryMap->Attribute & EFI_MEMORY_RUNTIME) ==
>>> EFI_MEMORY_RUNTIME) {
>>> +      SctCopyMem ((VOID *) VirtualMemoryMap, (VOID *) MemoryMap,
>>> DescriptorSize);
>>> +      VirtualMemoryMap->VirtualStart  =
>>> VirtualMemoryMap->PhysicalStart;
>>> +      *VirtualMapSize += DescriptorSize;
>>> +      VirtualMemoryMap = NextMemoryDescriptor (VirtualMemoryMap,
>>> DescriptorSize);
>>> +    }
>>> +
>>> +    MemoryMap = NextMemoryDescriptor (MemoryMap, DescriptorSize);
>>> +  }
>>> +}
>>> +
>>> +
>>> +
>>> +VOID
>>> +JumpVirtualMode(
>>> +  IN UINTN VirtualFunc,
>>> +  IN UINTN HandOffAddr
>>> +  )
>>> +/*++
>>> +
>>> +Routine Description:
>>> +
>>> +  Enable virtual addressing mode, and jump to RuntimeTestFunc in
>>> virtual address
>>> +
>>> +Arguments:
>>> +
>>> +  VirtualFunc  - RuntimeTestFunc virtual address
>>> +  HandOffAddr  - Configuration Data Address
>>> +
>>> +Returns:
>>> +
>>> +  NONE
>>> +
>>> +--*/
>>> +{
>>> +  //
>>> +  // Note: It is assumed that the MMU and page tables are configured
>>> on ARM platforms
>>> +  // based on ARM v5 v6 and v7 architecture.
>>> +  //
>>> +  /* FIXME: Is it the same on ARM v8? */
>>> +    JumpToTestFunc(VirtualFunc, HandOffAddr);
>>
>> Again.
>
> Same.
>
>>> +}
>>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c
>>> b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c
>>> new file mode 100644
>>> index 00000000..6161d596
>>> --- /dev/null
>>> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Debug.c
>>> @@ -0,0 +1,88 @@
>>> +/** @file
>>> +
>>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>>> +  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>
>>> +
>>> +  This program and the accompanying materials
>>> +  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +  which accompanies this distribution.  The full text of the license
>>> may be found at
>>> +  http://opensource.org/licenses/bsd-license.php
>>> +
>>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +
>>> +**/
>>> +
>>> +/*++
>>> +
>>> +Module Name:
>>> +
>>> +  Debug.c
>>> +
>>> +--*/
>>> +
>>> +#include "SCRTDriver.h"
>>> +
>>> +UINTN                 mHandOffPtr        =  0;
>>> +EFI_PHYSICAL_ADDRESS  mIoPortSpaceAddress = 0;
>>> +
>>> +
>>> +EFI_STATUS
>>> +ConsumeHandOff (
>>> +  IN  UINTN         HandOffAddr,
>>> +  OUT CONF_INFO     *ConfigData
>>> +  )
>>> +{
>>> +   RUNTIME_HANDOFF   *HandOffPtr;
>>> +   //
>>> +   // First fix the memory address of hand off data.
>>> +   //
>>> +   FixAddress(&HandOffAddr);
>>> +   mHandOffPtr = HandOffAddr;
>>> +   HandOffPtr  = (RUNTIME_HANDOFF*)mHandOffPtr;
>>> +   *ConfigData =  HandOffPtr->ConfigureInfo;
>>> +
>>> +   if (!HandOffPtr->DebuggerInfo.MmioFlag){
>>> +     //
>>> +     // If debug port is I/O mapped, fix IoBase Address.
>>> +     //
>>> +     FixAddress(&HandOffPtr->DebuggerInfo.IoBase);
>>> +     mIoPortSpaceAddress = HandOffPtr->DebuggerInfo.IoBase;
>>
>> Looks redundant on !x86
>>
>>> +   } else {
>>> +     //
>>> +     // If debug port is MMIO, fix MmioBase Address.
>>> +     //
>>> +     FixAddress(&HandOffPtr->DebuggerInfo.MmioBase);
>>> +   }
>>> +
>>> +   return EFI_SUCCESS;
>>> +}
>>> +
>>> +
>>> +EFI_STATUS
>>> +Send2UART (
>>> +  CHAR8                *String
>>> +  )
>>> +{
>>> +  //
>>> +  // TODO: On ARM platforms use platform specific functions to
>>> +  // write the data to UART.
>>> +  //
>>
>> Ye gods...
>
> Reminder that this is copied from the ARM sources.
> In this case I'll just replace ARM by RISC-V.
>
>>> +  return EFI_SUCCESS;
>>> +}
>>> +
>>> +
>>> +
>>> +EFI_STATUS
>>> +DebugWorker (
>>> +  IN CHAR8    *String
>>> +  )
>>> +{
>>> +  EFI_STATUS    Status;
>>> +
>>> +  //
>>> +  // Send text message to registered UART.
>>> +  //
>>> +  Status = Send2UART(String);
>>> +  return Status;
>>> +}
>>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c
>>> b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c
>>> new file mode 100644
>>> index 00000000..cc8d9869
>>> --- /dev/null
>>> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Dump.c
>>> @@ -0,0 +1,68 @@
>>> +/** @file
>>> +
>>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>>> +  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>
>>> +
>>> +  This program and the accompanying materials
>>> +  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +  which accompanies this distribution.  The full text of the license
>>> may be found at
>>> +  http://opensource.org/licenses/bsd-license.php
>>> +
>>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +
>>> +**/
>>> +
>>> +/*++
>>> +
>>> +Module Name:
>>> +
>>> +  Dump.c
>>> +
>>> +--*/
>>> +
>>> +#include "SCRTDriver.h"
>>> +
>>> +VOID
>>> +DumpRuntimeTable()
>>> +{
>>> +  SctAPrint ("\n================Dump Runtime Table===============\n");
>>> +  SctAPrint ("Header Signature = 0x%x\n", VRT->Hdr.Signature);
>>> +
>>> +  SctAPrint ("\n================GetTime Service==============\n");
>>> +  SctAPrint ("GetTime @ 0x%x\n", VRT->GetTime);
>>> +
>>> +  SctAPrint ("\n================SetTime Service==============\n");
>>> +  SctAPrint ("SetTime @ 0x%x\n", VRT->SetTime);
>>> +
>>> +  SctAPrint ("\n================GetWakeupTime
>>> Service==============\n");
>>> +  SctAPrint ("GetWakeupTime @ 0x%x\n", VRT->GetWakeupTime);
>>> +
>>> +  SctAPrint ("\n================SetWakeupTime
>>> Service==============\n");
>>> +  SctAPrint ("SetWakeupTime @ 0x%x\n", VRT->SetWakeupTime);
>>> +
>>> +  SctAPrint ("\n================GetVariable Service==============\n");
>>> +  SctAPrint ("GetVariable @ 0x%x\n", VRT->GetVariable);
>>> +
>>> +  SctAPrint ("\n================GetNextVariableName
>>> Service==============\n");
>>> +  SctAPrint ("GetNextVariableName @ 0x%x\n", VRT->GetNextVariableName);
>>> +
>>> +  SctAPrint ("\n================SetVariable Service==============\n");
>>> +  SctAPrint ("SetVariable @ 0x%x\n", VRT->SetVariable);
>>> +
>>> +  SctAPrint ("\n================GetNextHighMonotonicCount
>>> Service==============\n");
>>> +  SctAPrint ("GetNextHighMonotonicCount @ 0x%x\n",
>>> VRT->GetNextHighMonotonicCount);
>>> +
>>> +  SctAPrint ("\n================ResetSystem Service==============\n");
>>> +  SctAPrint ("ResetSystem @ 0x%x\n", VRT->ResetSystem);
>>> +#if 0
>>
>> Better to delete if not usable, but why disabled for AArch64 in the
>> first place?
>
> Not sure. It's also commented out in the X86 and IPF source files.
> I'll keep it. I think it would be more confusing if RISC-V was the only
> platform
> that didn't have this.
>
>>> +  SctAPrint ("\n================UpdateCapsule
>>> Service==============\n");
>>> +  SctAPrint ("UpdateCapsule @ 0x%x\n", VRT->UpdateCapsule);
>>> +
>>> +  SctAPrint ("\n================QueryCapsuleCapabilities
>>> Service==============\n");
>>> +  SctAPrint ("QueryCapsuleCapabilities @ 0x%x\n",
>>> VRT->QueryCapsuleCapabilities);
>>> +
>>> +  SctAPrint ("\n================QueryVariableInfo
>>> Service==============\n");
>>> +  SctAPrint ("QueryVariableInfo @ 0x%x\n", VRT->QueryVariableInfo);
>>> +#endif
>>> +}
>>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c
>>> b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c
>>> new file mode 100644
>>> index 00000000..b925e151
>>> --- /dev/null
>>> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.c
>>> @@ -0,0 +1,134 @@
>>> +/** @file
>>> +
>>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>>> +  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>
>>
>> More trailing spaces than usual in line above.
>> (The below block has 3 of them in every copy.)
>
> This pattern is present in almost all files in the repo.
> Should we follow up with a second patch series to fix that?
> In this repo there are tons of things to clean up...
> Some files have CRLF and an additional LF at the end of every line.
>
>>> +
>>> +  This program and the accompanying materials
>>> +  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +  which accompanies this distribution.  The full text of the license
>>> may be found at
>>> +  http://opensource.org/licenses/bsd-license.php
>>> +
>>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +
>>> +**/
>>> +
>>> +/*++
>>> +
>>> +Module Name:
>>> +
>>> +  Io.c
>>> +
>>> +--*/
>>> +
>>> +#include "Io.h"
>>> +
>>> +EFI_STATUS
>>> +EFIAPI
>>> +CpuIoServiceWrite (
>>> +  IN EFI_PEI_CPU_IO_PPI_WIDTH  Width,
>>> +  IN UINT64                     UserAddress,
>>> +  IN UINTN                      Count,
>>> +  IN VOID                       *UserBuffer
>>> +  )
>>> +/*++
>>> +
>>> +Routine Description:
>>> +
>>> +  Perform the port I/O write service
>>> +
>>> +Arguments:
>>> +
>>> +  Width   - Width of the port I/O operation
>>> +  Address - Base address of the port I/O operation
>>> +  Count   - Count of the number of accesses to perform
>>> +  Buffer  - Pointer to the source buffer from which to write data
>>> +
>>> +Returns:
>>> +
>>> +  EFI_SUCCESS           - The data was written.
>>> +  EFI_INVALID_PARAMETER - Width is invalid.
>>> +  EFI_INVALID_PARAMETER - Buffer is NULL.
>>> +  EFI_UNSUPPORTED       - The Buffer is not aligned for the given
>>> Width.
>>> +  EFI_UNSUPPORTED       - The address range specified by Address,
>>> Width,
>>> +                          and Count is not valid.
>>> +
>>> +--*/
>>> +{
>>> +  return EFI_UNSUPPORTED;
>>> +}
>>> +
>>> +
>>> +EFI_STATUS
>>> +EfiIoWrite (
>>> +  IN     EFI_PEI_CPU_IO_PPI_WIDTH  Width,
>>> +  IN     UINT64                     Address,
>>> +  IN     UINTN                      Count,
>>> +  IN OUT VOID                       *Buffer
>>> +  )
>>> +/*++
>>> +
>>> +Routine Description:
>>> +  Perform an IO write into Buffer.
>>> +
>>> +Arguments:
>>> +  Width   - Width of write transaction, and repeat operation to use
>>> +  Address - IO address to write
>>> +  Count   - Number of times to write the IO address.
>>> +  Buffer  - Buffer to write data from. size is Width * Count
>>> +
>>> +Returns:
>>> +  Status code
>>> +
>>> +--*/
>>> +{
>>> +  return CpuIoServiceWrite(Width, Address, Count, Buffer);
>>> +}
>>> +
>>> +
>>> +EFI_STATUS
>>> +EfiIoRead (
>>> +  IN     EFI_PEI_CPU_IO_PPI_WIDTH  Width,
>>> +  IN     UINT64                     Address,
>>> +  IN     UINTN                      Count,
>>> +  IN OUT VOID                       *Buffer
>>> +  )
>>> +/*++
>>> +
>>> +Routine Description:
>>> +  Perform an IO read into Buffer.
>>> +
>>> +Arguments:
>>> +  Width   - Width of read transaction, and repeat operation to use
>>> +  Address - IO address to read
>>> +  Count   - Number of times to read the IO address.
>>> +  Buffer  - Buffer to read data into. size is Width * Count
>>> +
>>> +Returns:
>>> +  Status code
>>> +
>>> +--*/
>>> +{
>>> +  return EFI_UNSUPPORTED;
>>> +}
>>> +
>>> +
>>> +VOID
>>> +FixAddress (
>>> +  IN UINTN     *PhyAddress
>>> +  )
>>> +{
>>> +        //
>>> +        //Note: On ARM platforms don't have to do this as all the
>>> functions are virtually mapped.
>>> +        //
>>
>> ARM
>>
>>> +}
>>> +
>>> +// Quick port to ARM
>>> +
>>> +VOID
>>> +Port80 (
>>> +  UINT8 Number
>>> +  )
>>> +{
>>> +  //EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Port80 %02x", Number));
>>
>> Eew.
>
> That function is used in some tests, that's why it's here and in both ARMs.
>
>>> +}
>>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h
>>> b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h
>>> new file mode 100644
>>> index 00000000..1e78b3e4
>>> --- /dev/null
>>> +++ b/uefi-sct/SctPkg/SCRT/SCRTDriver/Riscv64/Io.h
>>> @@ -0,0 +1,48 @@
>>> +/** @file
>>> +
>>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>>> +  Copyright (c) 2011 - 2012 ARM Ltd. All rights reserved.<BR>
>>> +
>>> +  This program and the accompanying materials
>>> +  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +  which accompanies this distribution.  The full text of the license
>>> may be found at
>>> +  http://opensource.org/licenses/bsd-license.php
>>> +
>>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +
>>
>> Trailing spaces.
>>
>>> +**/
>>> +
>>> +/*++
>>> +
>>> +Module Name:
>>> +
>>> +  Debug.h
>>> +
>>> +--*/
>>> +
>>> +#ifndef _IA32_IO_ACCESS_H
>>> +#define _IA32_IO_ACCESS_H
>>
>> Srsly?
>
> Reminder again, that this is a file that I copied ;)
> This header wasn't necessary so I removed in in my next patch series.
>
>>> +
>>> +#include "SCRTDriver.h"
>>> +
>>> +#define IA32_MAX_IO_ADDRESS   0xFFFF
>>> +
>>> +#define IA32API
>>> +
>>> +
>>> +typedef union {
>>> +  UINT8  VOLATILE  *buf;
>>> +  UINT8  VOLATILE  *ui8;
>>> +  UINT16 VOLATILE  *ui16;
>>> +  UINT32 VOLATILE  *ui32;
>>> +  UINT64 VOLATILE  *ui64;
>>> +  UINTN  VOLATILE  ui;
>>> +} PTR;
>>> +
>>> +// This address is assuming a pure PC architecture. Not required?
>>> +#define   VIRT_TO_PHYS_OFFSET            (0x80000000)     //2G
>>> +
>>> +
>>> +
>>> +#endif
>>> diff --git
>>> a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c
>>> b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c
>>>
>>> new file mode 100644
>>> index 00000000..96ee7b57
>>> --- /dev/null
>>> +++
>>> b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestCacheFunction.c
>>>
>>> @@ -0,0 +1,137 @@
>>> +/** @file
>>> +
>>> +  Copyright 2006 - 2016 Unified EFI, Inc.<BR>
>>> +  Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.<BR>
>>> +
>>> +  This program and the accompanying materials
>>> +  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +  which accompanies this distribution.  The full text of the license
>>> may be found at
>>> +  http://opensource.org/licenses/bsd-license.php
>>> +
>>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +
>>> +**/
>>> +/*++
>>> +
>>> +Module Name:
>>> +
>>> +  DebugSupportBBTestCacheFunction.c
>>> +
>>> +Abstract:
>>> +
>>> +  Interface Function Test Cases of Debug Support Protocol
>>> +
>>> +--*/
>>> +
>>> +
>>> +#include "DebugSupportBBTestMain.h"
>>> +
>>> +/**
>>> + *  Entrypoint for
>>> EFI_DEBUG_SUPPORT_PROTOCOL.InvalidateInstructionCache() Function Test.
>>> + *  @param This a pointer of EFI_BB_TEST_PROTOCOL.
>>> + *  @param ClientInterface a pointer to the interface to be tested.
>>> + *  @param TestLevel test "thoroughness" control.
>>> + *  @param SupportHandle a handle containing protocols required.
>>> + *  @return EFI_SUCCESS Finish the test successfully.
>>> + */
>>> +//
>>> +// TDS 3.5
>>> +//
>>> +EFI_STATUS
>>> +BBTestInvalidateInstructionCacheFunctionAutoTest (
>>> +  IN EFI_BB_TEST_PROTOCOL       *This,
>>> +  IN VOID                       *ClientInterface,
>>> +  IN EFI_TEST_LEVEL             TestLevel,
>>> +  IN EFI_HANDLE                 SupportHandle
>>> +  )
>>> +{
>>> +  EFI_STANDARD_TEST_LIBRARY_PROTOCOL   *StandardLib;
>>> +  EFI_STATUS                           Status;
>>> +  EFI_DEBUG_SUPPORT_PROTOCOL           *DebugSupport;
>>> +  EFI_TEST_ASSERTION                   AssertionType;
>>> +  UINT64                               Start;
>>> +  UINT64                               Length;
>>> +  UINTN                                MaxProcessorIndex;
>>> +  UINTN                                ProcessorIndex;
>>> +
>>> +  //
>>> +  // Get the Standard Library Interface
>>> +  //
>>> +  Status = gtBS->HandleProtocol (
>>> +                   SupportHandle,
>>> +                   &gEfiStandardTestLibraryGuid,
>>> +                   (VOID **) &StandardLib
>>> +                   );
>>> +
>>> +  if (EFI_ERROR(Status)) {
>>> +    StandardLib->RecordAssertion (
>>> +                   StandardLib,
>>> +                   EFI_TEST_ASSERTION_FAILED,
>>> +                   gTestGenericFailureGuid,
>>> +                   L"BS.HandleProtocol - Handle standard test library",
>>> +                   L"%a:%d:Status - %r",
>>> +                   __FILE__,
>>> +                   (UINTN)__LINE__,
>>> +                   Status
>>> +                   );
>>> +    return Status;
>>> +  }
>>> +
>>> +  DebugSupport = (EFI_DEBUG_SUPPORT_PROTOCOL *)ClientInterface;
>>> +
>>> +  if (DebugSupport->Isa != PlatformIsa) {
>>> +    return EFI_SUCCESS;
>>> +  }
>>> +
>>> +  Status = DebugSupport->GetMaximumProcessorIndex (DebugSupport,
>>> &MaxProcessorIndex);
>>> +  if (EFI_ERROR(Status)) {
>>> +    StandardLib->RecordAssertion (
>>> +                   StandardLib,
>>> +                   EFI_TEST_ASSERTION_FAILED,
>>> +                   gTestGenericFailureGuid,
>>> +                  
>>> L"EFI_DEBUG_SUPPORT_PROTOCOL.GetMaximumProcessorIndex",
>>> +                   L"%a:%d:Status - %r",
>>> +                   __FILE__,
>>> +                   (UINTN)__LINE__,
>>> +                   Status
>>> +                   );
>>> +    return Status;
>>> +  }
>>> +
>>> +  for (ProcessorIndex = 0; ProcessorIndex <= MaxProcessorIndex;
>>> ProcessorIndex++) {
>>> +
>>> +    //
>>> +    // Assertion Point 3.5.2.1
>>> +    // Invoke InvalidateInstructionCache and verify interface
>>> correctness.
>>> +    //
>>> +
>>> +    // The Physical base of the memory range to be invalidated.
>>> +    Start  = 0x0;
>>> +
>>> +    // The minimum number of bytes in the processor's instruction
>>> cache to be invalidated.
>>> +    Length = 0x0;
>>> +
>>> +    Status = DebugSupport->InvalidateInstructionCache (DebugSupport,
>>> ProcessorIndex, (VOID*)&Start, Length);
>>> +
>>> +    if (EFI_ERROR(Status)) {
>>> +      AssertionType = EFI_TEST_ASSERTION_FAILED;
>>> +    } else {
>>> +      AssertionType = EFI_TEST_ASSERTION_PASSED;
>>> +    }
>>> +
>>> +    StandardLib->RecordAssertion (
>>> +                 StandardLib,
>>> +                 AssertionType,
>>> +                 gDebugSupportBBTestFunctionAssertionGuid015,
>>> +                
>>> L"EFI_DEBUG_SUPPORT_PROTOCOL.InvalidateInstructionCache - Invoke this
>>> function and verify interface correctness",
>>> +                 L"%a:%d:Status - %r",
>>> +                 __FILE__,
>>> +                 (UINTN)__LINE__,
>>> +                 Status
>>> +                 );
>>> +  }
>>> +
>>> +  return EFI_SUCCESS;
>>> +}
>>> +
>>> diff --git
>>> a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
>>> b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
>>>
>>> new file mode 100644
>>> index 00000000..c27c0c0c
>>> --- /dev/null
>>> +++
>>> b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/DebugSupportBBTestExceptionCallbackFunction.c
>>>
>>> @@ -0,0 +1,276 @@
>>> +/** @file
>>> +
>>> +  Copyright 2006 - 2016 Unified EFI, Inc.<BR>
>>> +  Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.<BR>
>>> +
>>> +  This program and the accompanying materials
>>> +  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +  which accompanies this distribution.  The full text of the license
>>> may be found at
>>> +  http://opensource.org/licenses/bsd-license.php
>>> +
>>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +
>>> +**/
>>> +/*++
>>> +
>>> +Module Name:
>>> +
>>> +  DebugSupportBBExceptionCallbackFunction.c
>>> +
>>> +Abstract:
>>> +
>>> +  Interface Function Test Cases of Debug Support Protocol
>>> +
>>> +--*/
>>> +
>>> +
>>> +#include "DebugSupportBBTestMain.h"
>>> +
>>> +extern volatile  UINTN InvokedExceptionCallback;
>>> +extern volatile  UINTN InvokedPeriodicCallback;
>>> +
>>> +extern EFI_INSTRUCTION_SET_ARCHITECTURE PlatformIsa;
>>> +
>>> +void
>>> +SoftwareBreak (
>>> +  void
>>> +  )
>>> +{
>>> +  // Not ported to ARM yet
>>
>> Eew.
>>
>>> +  ASSERT (FALSE);
>>> +}
>>> +
>>> +/**
>>> + *  Entrypoint for
>>> EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback() Function Test.
>>> + *  @param This a pointer of EFI_BB_TEST_PROTOCOL.
>>> + *  @param ClientInterface a pointer to the interface to be tested.
>>> + *  @param TestLevel test "thoroughness" control.
>>> + *  @param SupportHandle a handle containing protocols required.
>>> + *  @return EFI_SUCCESS Finish the test successfully.
>>> + */
>>> +//
>>> +// TDS 3.4
>>> +//
>>> +EFI_STATUS
>>> +BBTestRegisterExceptionCallbackFunctionManualTest (
>>> +  IN EFI_BB_TEST_PROTOCOL       *This,
>>> +  IN VOID                       *ClientInterface,
>>> +  IN EFI_TEST_LEVEL             TestLevel,
>>> +  IN EFI_HANDLE                 SupportHandle
>>> +  )
>>> +{
>>> +  EFI_STANDARD_TEST_LIBRARY_PROTOCOL   *StandardLib;
>>> +  EFI_STATUS                           Status;
>>> +  EFI_DEBUG_SUPPORT_PROTOCOL           *DebugSupport;
>>> +  EFI_TEST_ASSERTION                   AssertionType;
>>> +
>>> +  DebugSupport = (EFI_DEBUG_SUPPORT_PROTOCOL *)ClientInterface;
>>> +
>>> +  if (DebugSupport->Isa != PlatformIsa) {
>>> +    return EFI_SUCCESS;
>>> +  }
>>> +
>>> +  //
>>> +  // Get the Standard Library Interface
>>> +  //
>>> +  Status = gtBS->HandleProtocol (
>>> +                   SupportHandle,
>>> +                   &gEfiStandardTestLibraryGuid,
>>> +                   (VOID **) &StandardLib
>>> +                   );
>>> +
>>> +  if (EFI_ERROR(Status)) {
>>> +    StandardLib->RecordAssertion (
>>> +                   StandardLib,
>>> +                   EFI_TEST_ASSERTION_FAILED,
>>> +                   gTestGenericFailureGuid,
>>> +                   L"BS.HandleProtocol - Handle standard test library",
>>> +                   L"%a:%d:Status - %r",
>>> +                   __FILE__,
>>> +                   (UINTN)__LINE__,
>>> +                   Status
>>> +                   );
>>> +    return Status;
>>> +  }
>>> +
>>> +  //
>>> +  // Assertion Point 3.4.2.1
>>> +  // Invoke RegisterExceptionCallback() to install an interrupt
>>> handler function.
>>> +  //
>>> +  InvokedExceptionCallback = FALSE;
>>> +  // FIXME: Is it normal that we use EXCEPT_IA32_BREAKPOINT here?
>>> +  // Shouldn't we define proper constants for ARM exceptions in
>>> DebugSupportProtocol.h file?
>>> +  Status = DebugSupport->RegisterExceptionCallback (DebugSupport, 0,
>>> ExceptionCallback, EXCEPT_IA32_BREAKPOINT);
>>> +
>>> +  if ((Status == EFI_SUCCESS) || (Status == EFI_ALREADY_STARTED)) {
>>> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
>>> +  } else {
>>> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
>>> +  }
>>> +
>>> +  StandardLib->RecordAssertion (
>>> +                 StandardLib,
>>> +                 AssertionType,
>>> +                 gDebugSupportBBTestFunctionAssertionGuid009,
>>> +                
>>> L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Invoke this
>>> function and verify interface correctness",
>>> +                 L"%a:%d:Status - %r",
>>> +                 __FILE__,
>>> +                 (UINTN)__LINE__,
>>> +                 Status
>>> +                 );
>>> +
>>> +  //
>>> +  // If the callback function is already registed, return
>>> +  //
>>> +  if (EFI_ERROR(Status)) {
>>> +    return EFI_SUCCESS;
>>> +  }
>>> +
>>> +  //
>>> +  // Test the callback function registed.
>>> +  //
>>> +
>>> +  //
>>> +  // Call SoftwareBreak to invoke the interrupt handler function.
>>> +  //
>>> +  SoftwareBreak ();
>>> +
>>> +  if (InvokedExceptionCallback == FALSE) {
>>> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
>>> +  } else {
>>> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
>>> +  }
>>> +
>>> +  StandardLib->RecordAssertion (
>>> +                 StandardLib,
>>> +                 AssertionType,
>>> +                 gDebugSupportBBTestFunctionAssertionGuid010,
>>> +                
>>> L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Verify the
>>> callback function was invoked.",
>>> +                 L"%a:%d:Status - %r",
>>> +                 __FILE__,
>>> +                 (UINTN)__LINE__,
>>> +                 Status
>>> +                 );
>>> +
>>> +  //
>>> +  // Assertion Point 3.4.2.2
>>> +  // Invoke RegisterPeriodicCallback() to install the Periodic
>>> interrupt handler function.
>>> +  // Verify the two callback functions can be both invoked.
>>> +  //
>>> +  InvokedExceptionCallback = FALSE;
>>> +  InvokedPeriodicCallback  = FALSE;
>>> +
>>> +  Status = DebugSupport->RegisterPeriodicCallback (DebugSupport, 0,
>>> PeriodicCallback);
>>> +  if (EFI_ERROR(Status)) {
>>> +    return Status;
>>> +  }
>>> +
>>> +  //
>>> +  // Wait the PeriodicCallback to be invoked.
>>> +  //
>>> +  gtBS->Stall (500000);
>>> +
>>> +  //
>>> +  // Call SoftwareBreak to invoke the interrupt handler function.
>>> +  //
>>> +  SoftwareBreak ();
>>> +
>>> +  if ((InvokedExceptionCallback == TRUE) && (InvokedPeriodicCallback
>>> == TRUE)) {
>>> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
>>> +  } else {
>>> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
>>> +  }
>>> +
>>> +  StandardLib->RecordAssertion (
>>> +                 StandardLib,
>>> +                 AssertionType,
>>> +                 gDebugSupportBBTestFunctionAssertionGuid011,
>>> +                
>>> L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Verify the
>>> two callback functions can be both invoked.",
>>> +                 L"%a:%d:Status - %r",
>>> +                 __FILE__,
>>> +                 (UINTN)__LINE__,
>>> +                 Status
>>> +                 );
>>> +
>>> +  //
>>> +  // Uninstall the Periodic callback function.
>>> +  //
>>> +  Status = DebugSupport->RegisterPeriodicCallback (DebugSupport, 0,
>>> NULL);
>>> +  if (EFI_ERROR(Status)) {
>>> +    return Status;
>>> +  }
>>> +
>>> +  //
>>> +  // Assertion Point 3.4.2.3
>>> +  // Invoke RegisterExceptionCallback() to install another interrupt
>>> handler function.
>>> +  //
>>> +  Status = DebugSupport->RegisterExceptionCallback (DebugSupport, 0,
>>> ExceptionCallback1, EXCEPT_IA32_BREAKPOINT);
>>> +
>>> +  if (Status != EFI_ALREADY_STARTED) {
>>> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
>>> +  } else {
>>> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
>>> +  }
>>> +
>>> +  StandardLib->RecordAssertion (
>>> +                 StandardLib,
>>> +                 AssertionType,
>>> +                 gDebugSupportBBTestFunctionAssertionGuid012,
>>> +                
>>> L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Register
>>> another callback function.",
>>> +                 L"%a:%d:Status - %r",
>>> +                 __FILE__,
>>> +                 (UINTN)__LINE__,
>>> +                 Status
>>> +                 );
>>> +
>>> +  //
>>> +  // Assertion Point 3.4.2.4
>>> +  // Invoke RegisterExceptionCallback() to unstall the interrupt
>>> handler function.
>>> +  //
>>> +  Status = DebugSupport->RegisterExceptionCallback (DebugSupport, 0,
>>> NULL, EXCEPT_IA32_BREAKPOINT);
>>> +
>>> +  if (EFI_ERROR(Status)) {
>>> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
>>> +  } else {
>>> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
>>> +  }
>>> +
>>> +  StandardLib->RecordAssertion (
>>> +                 StandardLib,
>>> +                 AssertionType,
>>> +                 gDebugSupportBBTestFunctionAssertionGuid013,
>>> +                
>>> L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Invoke this
>>> function to uninstall the interrupt handler function",
>>> +                 L"%a:%d:Status - %r",
>>> +                 __FILE__,
>>> +                 (UINTN)__LINE__,
>>> +                 Status
>>> +                 );
>>> +
>>> +  InvokedExceptionCallback = FALSE;
>>> +
>>> +  //
>>> +  // Call SoftwareBreak to invoke the interrupt handler function.
>>> +  //
>>> +  SoftwareBreak ();
>>> +
>>> +  if (InvokedExceptionCallback != FALSE) {
>>> +    AssertionType = EFI_TEST_ASSERTION_FAILED;
>>> +  } else {
>>> +    AssertionType = EFI_TEST_ASSERTION_PASSED;
>>> +  }
>>> +
>>> +  StandardLib->RecordAssertion (
>>> +                 StandardLib,
>>> +                 AssertionType,
>>> +                 gDebugSupportBBTestFunctionAssertionGuid014,
>>> +                
>>> L"EFI_DEBUG_SUPPORT_PROTOCOL.RegisterExceptionCallback - Verify the
>>> callback function wasn't invoked",
>>> +                 L"%a:%d:Status - %r",
>>> +                 __FILE__,
>>> +                 (UINTN)__LINE__,
>>> +                 Status
>>> +                 );
>>> +
>>> +  return EFI_SUCCESS;
>>> +}
>>> +
>>> diff --git
>>> a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c
>>> b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c
>>>
>>> new file mode 100644
>>> index 00000000..8334f601
>>> --- /dev/null
>>> +++
>>> b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DebugSupport/BlackBoxTest/Riscv64/PlatformIsa.c
>>>
>>> @@ -0,0 +1,30 @@
>>> +/** @file
>>> +
>>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>>> +  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
>>> +
>>> +  This program and the accompanying materials
>>> +  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +  which accompanies this distribution.  The full text of the license
>>> may be found at
>>> +  http://opensource.org/licenses/bsd-license.php
>>> +
>>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +
>>> +**/
>>> +/*++
>>> +
>>> +Module Name:
>>> +
>>> +  PlatformIsa.c
>>> +
>>> +Abstract:
>>> +
>>> +  Platform related Isa definition.
>>> +
>>> +--*/
>>> +
>>> +#include "DebugSupportBBTestMain.h"
>>> +
>>> +EFI_INSTRUCTION_SET_ARCHITECTURE PlatformIsa = IsaAArch64;
>>> +
>>> diff --git
>>> a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c
>>> b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c
>>>
>>> new file mode 100644
>>> index 00000000..1c1940e5
>>> --- /dev/null
>>> +++
>>> b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/UsbHc/BlackBoxTest/Riscv64/TimerInterrupt.c
>>>
>>> @@ -0,0 +1,51 @@
>>> +/** @file
>>> +
>>> +  Copyright 2006 - 2010 Unified EFI, Inc.<BR>
>>> +  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
>>> +
>>> +  This program and the accompanying materials
>>> +  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +  which accompanies this distribution.  The full text of the license
>>> may be found at
>>> +  http://opensource.org/licenses/bsd-license.php
>>> +
>>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +
>>> +**/
>>> +/**
>>> + *  Ipf Source file for Mask/Unmask TimerInterrupt.
>>> + */
>>> +/*++
>>> +
>>> +Module Name:
>>> +  TimerInterrupt.c
>>> +
>>> +Abstract:
>>> +  Ipf Source file for Mask/Unmask TimerInterrupt.
>>> +
>>> +Author(s):
>>> +
>>> +
>>> +References:
>>> +  EFI Specification 1.10
>>> +  EFI/Tiano DXE Test Case Writer's Guide
>>> +
>>> +Revision History:
>>> +  Initial 10-20-2002
>>> +  Version 0.01
>>> +
>>> +--*/
>>> +
>>> +#include "UsbHcTest.h"
>>> +
>>> +VOID MaskTimerInterrupt()
>>> +{
>>> +  // TBD
>>> +  return;
>>> +}
>>> +
>>> +VOID UnmaskTimerInterrupt()
>>> +{
>>> +  // TBD
>>> +  return;
>>> +}
>>> diff --git
>>> a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h
>>> b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h
>>>
>>> new file mode 100644
>>> index 00000000..ff781aee
>>> --- /dev/null
>>> +++
>>> b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/EntsLibPlat.h
>>>
>>> @@ -0,0 +1,55 @@
>>> +/** @file
>>> +
>>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>>> +  Copyright (c) 2010 - 2012, ARM Ltd. All rights reserved.<BR>
>>> +
>>> +  This program and the accompanying materials
>>> +  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +  which accompanies this distribution.  The full text of the license
>>> may be found at
>>> +  http://opensource.org/licenses/bsd-license.php
>>> +
>>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +
>>> +**/
>>> +/*++
>>> +
>>> +Module Name:
>>> +
>>> +  EntsLibPlat.h
>>> +
>>> +Abstract:
>>> +
>>> +  AArch64 specific defines
>>> +
>>> +--*/
>>> +
>>> +#ifndef _EFI_LIB_PLAT_H_
>>> +#define _EFI_LIB_PLAT_H_
>>
>> No leading _.
>>
>> /
>>      Leif
>>
>>> +
>>> +#define MIN_ALIGNMENT_SIZE  8
>>> +
>>> +VOID
>>> +EntsInitializeLibPlatform (
>>> +  IN EFI_HANDLE           ImageHandle,
>>> +  IN EFI_SYSTEM_TABLE     *SystemTable
>>> +  )
>>> +/*++
>>> +
>>> +Routine Description:
>>> +
>>> +  Initialize platform.
>>> +
>>> +Arguments:
>>> +
>>> +  ImageHandle           - The image handle.
>>> +  SystemTable           - The system table.
>>> +
>>> +Returns:
>>> +
>>> +  None.
>>> +
>>> +--*/
>>> +;
>>> +
>>> +#endif
>>> diff --git
>>> a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c
>>> b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c
>>>
>>> new file mode 100644
>>> index 00000000..70a509a4
>>> --- /dev/null
>>> +++
>>> b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasLib/Riscv64/InitPlat.c
>>>
>>> @@ -0,0 +1,55 @@
>>> +/** @file
>>> +
>>> +  Copyright 2006 - 2012 Unified EFI, Inc.<BR>
>>> +  Copyright (c) 2010 - 2012, ARM Ltd. All rights reserved.<BR>
>>> +
>>> +  This program and the accompanying materials
>>> +  are licensed and made available under the terms and conditions of
>>> the BSD License
>>> +  which accompanies this distribution.  The full text of the license
>>> may be found at
>>> +  http://opensource.org/licenses/bsd-license.php
>>> +
>>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
>>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>> OR IMPLIED.
>>> +
>>> +**/
>>> +/*++
>>> +
>>> +Module Name:
>>> +
>>> +  InitPlat.c
>>> +
>>> +Abstract:
>>> +
>>> +  Math routines for compatibility with native EFI library routines.
>>> +
>>> +--*/
>>> +
>>> +#include "Efi.h"
>>> +#include "EntsLibPlat.h"
>>> +
>>> +VOID
>>> +EntsInitializeLibPlatform (
>>> +  IN EFI_HANDLE           ImageHandle,
>>> +  IN EFI_SYSTEM_TABLE     *SystemTable
>>> +  )
>>> +/*++
>>> +
>>> +Routine Description:
>>> +
>>> +  Initialize platform.
>>> +
>>> +Arguments:
>>> +
>>> +  ImageHandle           - The image handle.
>>> +  SystemTable           - The system table.
>>> +
>>> +Returns:
>>> +
>>> +  None.
>>> +
>>> +--*/
>>> +{
>>> +  //
>>> +  // No platform-specific initializations
>>> +  //
>>> +}
>>> -- 
>>> 2.28.0
>>>
>>>
>>>
>>> 
>>>
>>>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-devel] [edk2-test PATCH v1 2/2] SctPkg: Enable RISCV64 support using AARCH64 sources
  2021-02-08 17:04       ` Heinrich Schuchardt
@ 2021-02-09 12:42         ` Leif Lindholm
  2021-02-09 13:47           ` Heinrich Schuchardt
  0 siblings, 1 reply; 18+ messages in thread
From: Leif Lindholm @ 2021-02-09 12:42 UTC (permalink / raw)
  To: Heinrich Schuchardt
  Cc: Daniel Schaefer, devel, Abner Chang, Gilbert Chen, Eric Jin,
	G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

On Mon, Feb 08, 2021 at 18:04:45 +0100, Heinrich Schuchardt wrote:
> >>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
> >>> b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
> >>> new file mode 100644
> >>> index 00000000..8bc2c624
> >>> --- /dev/null
> >>> +++ b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
> >>> @@ -0,0 +1,45 @@
> >>> +## @file
> >>> +#
> >>> +#  Copyright 2010 - 2012 Unified EFI, Inc.<BR>
> >>> +#  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
> >>> +#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP.<BR>
> >>> +#
> >>> +#  This program and the accompanying materials
> >>> +#  are licensed and made available under the terms and conditions of
> >>> the BSD License
> >>> +#  which accompanies this distribution.  The full text of the
> >>> license may be found at
> >>> +#  http://opensource.org/licenses/bsd-license.php
> >>> +#
> >>> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> >>> BASIS,
> >>> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
> >>> OR IMPLIED.
> >>> +#
> >>> +##
> >>> +#
> >>> +#
> >>> +#/*++
> >>> +#
> >>> +# Module Name:
> >>> +#
> >>> +#  GoVirtual.S
> >>> +#
> >>> +#--*/
> >>> +#start of the code section
> >>> +.text
> >>> +/* FIXME: Should alignment be different on Aarch64? */
> >>
> >> 1) FIXME
> >> 2) Aarch64.
> >
> > I have no idea why the alignment would be 3 on other platforms, so I
> > don't know how to fix it.
> > If anyone knows more, please let me know. I'll just change the comment
> > to say Riscv64.
> >
> >>> +.align 3
> 
> Both on Aarch64 and on RISC-V an odd alignment value makes no sense.
> 
> .align 8 should do no harm. But is it needed?

The glory of the GAS .align directive is that its meaning differs
between architectures and executable formats. On ARM/AArch64, as well
as on RISC-V (I think?) the alignment is described as a power of 2.

So .align 3 on ARM and others are the same as .align 8 on x86 (ELF)
and others.

(It might not be a bad idea to start replacing .align directives with
.baligh to reduce confusion.)

I haven't looked into whether 8-byte alignment is actually required by
the code here.

/
    Leif

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-devel] [edk2-test PATCH v1 2/2] SctPkg: Enable RISCV64 support using AARCH64 sources
  2021-02-09 12:42         ` Leif Lindholm
@ 2021-02-09 13:47           ` Heinrich Schuchardt
  2021-02-09 14:58             ` Leif Lindholm
  0 siblings, 1 reply; 18+ messages in thread
From: Heinrich Schuchardt @ 2021-02-09 13:47 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: Daniel Schaefer, devel, Abner Chang, Gilbert Chen, Eric Jin,
	G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

On 09.02.21 13:42, Leif Lindholm wrote:
> On Mon, Feb 08, 2021 at 18:04:45 +0100, Heinrich Schuchardt wrote:
>>>>> diff --git a/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
>>>>> b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
>>>>> new file mode 100644
>>>>> index 00000000..8bc2c624
>>>>> --- /dev/null
>>>>> +++ b/uefi-sct/SctPkg/SCRT/SCRTApp/Riscv64/GoVirtual.S
>>>>> @@ -0,0 +1,45 @@
>>>>> +## @file
>>>>> +#
>>>>> +#  Copyright 2010 - 2012 Unified EFI, Inc.<BR>
>>>>> +#  Copyright (c) 2012, ARM Ltd. All rights reserved.<BR>
>>>>> +#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP.<BR>
>>>>> +#
>>>>> +#  This program and the accompanying materials
>>>>> +#  are licensed and made available under the terms and conditions of
>>>>> the BSD License
>>>>> +#  which accompanies this distribution.  The full text of the
>>>>> license may be found at
>>>>> +#  http://opensource.org/licenses/bsd-license.php
>>>>> +#
>>>>> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
>>>>> BASIS,
>>>>> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
>>>>> OR IMPLIED.
>>>>> +#
>>>>> +##
>>>>> +#
>>>>> +#
>>>>> +#/*++
>>>>> +#
>>>>> +# Module Name:
>>>>> +#
>>>>> +#  GoVirtual.S
>>>>> +#
>>>>> +#--*/
>>>>> +#start of the code section
>>>>> +.text
>>>>> +/* FIXME: Should alignment be different on Aarch64? */
>>>>
>>>> 1) FIXME
>>>> 2) Aarch64.
>>>
>>> I have no idea why the alignment would be 3 on other platforms, so I
>>> don't know how to fix it.
>>> If anyone knows more, please let me know. I'll just change the comment
>>> to say Riscv64.
>>>
>>>>> +.align 3
>>
>> Both on Aarch64 and on RISC-V an odd alignment value makes no sense.
>>
>> .align 8 should do no harm. But is it needed?
>
> The glory of the GAS .align directive is that its meaning differs
> between architectures and executable formats. On ARM/AArch64, as well
> as on RISC-V (I think?) the alignment is described as a power of 2.
>
> So .align 3 on ARM and others are the same as .align 8 on x86 (ELF)
> and others.
>
> (It might not be a bad idea to start replacing .align directives with
> .baligh to reduce confusion.)

Thanks for pointing out the different meanings of .align. They are
documented in binutils-2.36/gas/doc/as.info chapter 7.3.

.balign is GNU assembler specific.

Do we have to consider other assemblers here?

Best regards

Heinrich

>
> I haven't looked into whether 8-byte alignment is actually required by
> the code here.
>
> /
>     Leif
>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-devel] [edk2-test PATCH v1 2/2] SctPkg: Enable RISCV64 support using AARCH64 sources
  2021-02-09 13:47           ` Heinrich Schuchardt
@ 2021-02-09 14:58             ` Leif Lindholm
  2021-02-09 15:11               ` Daniel Schaefer
  0 siblings, 1 reply; 18+ messages in thread
From: Leif Lindholm @ 2021-02-09 14:58 UTC (permalink / raw)
  To: Heinrich Schuchardt
  Cc: Daniel Schaefer, devel, Abner Chang, Gilbert Chen, Eric Jin,
	G Edhaya Chandran, Barton Gao, Samer El-Haj-Mahmoud

On Tue, Feb 09, 2021 at 14:47:46 +0100, Heinrich Schuchardt wrote:
> >>> I have no idea why the alignment would be 3 on other platforms, so I
> >>> don't know how to fix it.
> >>> If anyone knows more, please let me know. I'll just change the comment
> >>> to say Riscv64.
> >>>
> >>>>> +.align 3
> >>
> >> Both on Aarch64 and on RISC-V an odd alignment value makes no sense.
> >>
> >> .align 8 should do no harm. But is it needed?
> >
> > The glory of the GAS .align directive is that its meaning differs
> > between architectures and executable formats. On ARM/AArch64, as well
> > as on RISC-V (I think?) the alignment is described as a power of 2.
> >
> > So .align 3 on ARM and others are the same as .align 8 on x86 (ELF)
> > and others.
> >
> > (It might not be a bad idea to start replacing .align directives with
> > .baligh to reduce confusion.)
> 
> Thanks for pointing out the different meanings of .align. They are
> documented in binutils-2.36/gas/doc/as.info chapter 7.3.
> 
> .balign is GNU assembler specific.
> 
> Do we have to consider other assemblers here?

I don't think so.
The GNU family of toolchains are the only ones using .s/.S sources.
Unless there are GNU-compatible assemblers that don't support the
directive.

Visual Studio uses .asm on ARM* and .nasm on x86.

/
    Leif

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [edk2-devel] [edk2-test PATCH v1 2/2] SctPkg: Enable RISCV64 support using AARCH64 sources
  2021-02-09 14:58             ` Leif Lindholm
@ 2021-02-09 15:11               ` Daniel Schaefer
  0 siblings, 0 replies; 18+ messages in thread
From: Daniel Schaefer @ 2021-02-09 15:11 UTC (permalink / raw)
  To: Leif Lindholm, Heinrich Schuchardt
  Cc: devel, Abner Chang, Gilbert Chen, Eric Jin, G Edhaya Chandran,
	Barton Gao, Samer El-Haj-Mahmoud

On 2/9/21 10:58 PM, Leif Lindholm wrote:
> On Tue, Feb 09, 2021 at 14:47:46 +0100, Heinrich Schuchardt wrote:
>>>>> I have no idea why the alignment would be 3 on other platforms, so I
>>>>> don't know how to fix it.
>>>>> If anyone knows more, please let me know. I'll just change the comment
>>>>> to say Riscv64.
>>>>>
>>>>>>> +.align 3
>>>>
>>>> Both on Aarch64 and on RISC-V an odd alignment value makes no sense.
>>>>
>>>> .align 8 should do no harm. But is it needed?

No idea why it was added for Arm and Aarch64 copied it.
It's not there for the other architectures. Let's remove it.

>>> The glory of the GAS .align directive is that its meaning differs
>>> between architectures and executable formats. On ARM/AArch64, as well
>>> as on RISC-V (I think?) the alignment is described as a power of 2.
>>>
>>> So .align 3 on ARM and others are the same as .align 8 on x86 (ELF)
>>> and others.
>>>
>>> (It might not be a bad idea to start replacing .align directives with
>>> .baligh to reduce confusion.)
>>
>> Thanks for pointing out the different meanings of .align. They are
>> documented in binutils-2.36/gas/doc/as.info chapter 7.3.
>>
>> .balign is GNU assembler specific.
>>
>> Do we have to consider other assemblers here?
> 
> I don't think so.
> The GNU family of toolchains are the only ones using .s/.S sources.
> Unless there are GNU-compatible assemblers that don't support the
> directive.
> 
> Visual Studio uses .asm on ARM* and .nasm on x86.
> 
> /
>      Leif
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-02-09 15:11 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-01 16:17 [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg Daniel Schaefer
2020-12-01 16:17 ` [edk2-test PATCH v1 1/2] SctPkg: Add RISCV64 support Daniel Schaefer
2020-12-02 11:44   ` [edk2-devel] " Leif Lindholm
2021-02-08 15:09     ` Daniel Schaefer
2020-12-01 16:17 ` [edk2-test PATCH v1 2/2] SctPkg: Enable RISCV64 support using AARCH64 sources Daniel Schaefer
2020-12-02 12:04   ` [edk2-devel] " Leif Lindholm
2021-02-08 15:09     ` Daniel Schaefer
2021-02-08 17:04       ` Heinrich Schuchardt
2021-02-09 12:42         ` Leif Lindholm
2021-02-09 13:47           ` Heinrich Schuchardt
2021-02-09 14:58             ` Leif Lindholm
2021-02-09 15:11               ` Daniel Schaefer
2020-12-01 16:59 ` [edk2-test PATCH v1 0/2] Add RISCV64 support to SctPkg Heinrich Schuchardt
2020-12-01 17:11   ` Daniel Schaefer
2020-12-01 17:37     ` Heinrich Schuchardt
2021-02-08 14:30       ` Daniel Schaefer
2021-02-08 15:50         ` Heinrich Schuchardt
2020-12-02 12:07 ` Leif Lindholm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox