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 <l...@nuviainc.com>
Cc: Heinrich Schuchardt <xypron.g...@gmx.de>
Cc: Abner Chang <abner.ch...@hpe.com>
Cc: Gilbert Chen <gilbert.c...@hpe.com>
Cc: Eric Jin <eric....@intel.com>
Cc: G Edhaya Chandran <edhaya.chand...@arm.com>
Cc: Barton Gao <gao...@byosoft.com.cn>
Cc: Samer El-Haj-Mahmoud <samer.el-haj-mahm...@arm.com>
Signed-off-by: Daniel Schaefer <daniel.schae...@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













-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#71468): https://edk2.groups.io/g/devel/message/71468
Mute This Topic: https://groups.io/mt/78637294/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to