From: "Abner Chang" <abner.chang@hpe.com>
To: "devel@edk2.groups.io" <devel@edk2.groups.io>,
"Chang, Abner (HPS SW/FW Technologist)" <abner.chang@hpe.com>
Cc: Liming Gao <liming.gao@intel.com>,
Michael D Kinney <michael.d.kinney@intel.com>
Subject: Re: [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 07/29] MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor.
Date: Tue, 24 Sep 2019 01:53:28 +0000 [thread overview]
Message-ID: <CS1PR8401MB1192F09296DF36975AF2AB2AFF840@CS1PR8401MB1192.NAMPRD84.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <15C6EB9950232DB5.29693@groups.io>
CC Maintainers.
> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Abner Chang
> Sent: Monday, September 23, 2019 8:32 AM
> To: devel@edk2.groups.io
> Cc: Chang, Abner (HPS SW/FW Technologist) <abner.chang@hpe.com>
> Subject: [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 07/29]
> MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor.
>
> Add RISC-V RV64 BaseLib functions.
>
> Signed-off-by: Abner Chang <abner.chang@hpe.com>
> ---
> MdePkg/Include/Library/BaseLib.h | 26 ++
> MdePkg/Library/BaseLib/BaseLib.inf | 18 +-
> MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c | 27 +++
> MdePkg/Library/BaseLib/RiscV64/CpuPause.c | 29 +++
> MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c | 24 ++
> MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c | 25 ++
> MdePkg/Library/BaseLib/RiscV64/FlushCache.S | 21 ++
> MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c | 35
> +++ .../Library/BaseLib/RiscV64/InternalSwitchStack.c | 55 +++++
> MdePkg/Library/BaseLib/RiscV64/LongJump.c | 32 +++
> .../Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S | 14 ++
> MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S | 14 ++
> MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S | 32 +++
> .../Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S | 55 +++++
> MdePkg/Library/BaseLib/RiscV64/Unaligned.c | 264
> +++++++++++++++++++++
> 15 files changed, 670 insertions(+), 1 deletion(-) create mode 100644
> MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c
> create mode 100644 MdePkg/Library/BaseLib/RiscV64/CpuPause.c
> create mode 100644 MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c
> create mode 100644 MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c
> create mode 100644 MdePkg/Library/BaseLib/RiscV64/FlushCache.S
> create mode 100644 MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c
> create mode 100644 MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c
> create mode 100644 MdePkg/Library/BaseLib/RiscV64/LongJump.c
> create mode 100644
> MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S
> create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S
> create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
> create mode 100644
> MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S
> create mode 100644 MdePkg/Library/BaseLib/RiscV64/Unaligned.c
>
> diff --git a/MdePkg/Include/Library/BaseLib.h
> b/MdePkg/Include/Library/BaseLib.h
> index 2a75bc0..b8c8512 100644
> --- a/MdePkg/Include/Library/BaseLib.h
> +++ b/MdePkg/Include/Library/BaseLib.h
> @@ -4,6 +4,8 @@
>
> Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
> Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
> +Portions Copyright (c) 2016 - 2019, Hewlett Packard Enterprise
> +Development LP. All rights reserved.<BR>
> +
> SPDX-License-Identifier: BSD-2-Clause-Patent
>
> **/
> @@ -124,6 +126,30 @@ typedef struct {
>
> #endif // defined (MDE_CPU_AARCH64)
>
> +#if defined (MDE_CPU_RISCV64)
> +///
> +/// The RISC-V architecture context buffer used by SetJump() and
> LongJump().
> +///
> +typedef struct {
> + UINT64 RA;
> + UINT64 S0;
> + UINT64 S1;
> + UINT64 S2;
> + UINT64 S3;
> + UINT64 S4;
> + UINT64 S5;
> + UINT64 S6;
> + UINT64 S7;
> + UINT64 S8;
> + UINT64 S9;
> + UINT64 S10;
> + UINT64 S11;
> + UINT64 SP;
> +} BASE_LIBRARY_JUMP_BUFFER;
> +
> +#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
> +
> +#endif // defined (MDE_CPU_RISCV64)
>
> //
> // String Services
> diff --git a/MdePkg/Library/BaseLib/BaseLib.inf
> b/MdePkg/Library/BaseLib/BaseLib.inf
> index 3586beb..28d5795 100644
> --- a/MdePkg/Library/BaseLib/BaseLib.inf
> +++ b/MdePkg/Library/BaseLib/BaseLib.inf
> @@ -4,6 +4,7 @@
> # Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR> #
> Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> #
> Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
> +# Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All
> +rights reserved.<BR>
> #
> # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -20,7 +21,7 @@
> LIBRARY_CLASS = BaseLib
>
> #
> -# VALID_ARCHITECTURES = IA32 X64 EBC ARM AARCH64
> +# VALID_ARCHITECTURES = IA32 X64 EBC ARM AARCH64 RISCV64
> #
>
> [Sources]
> @@ -381,6 +382,21 @@
> AArch64/CpuBreakpoint.asm | MSFT
> AArch64/SpeculationBarrier.asm | MSFT
>
> +[Sources.RISCV64]
> + Math64.c
> + RiscV64/Unaligned.c
> + RiscV64/InternalSwitchStack.c
> + RiscV64/CpuBreakpoint.c
> + RiscV64/GetInterruptState.c
> + RiscV64/DisableInterrupts.c
> + RiscV64/EnableInterrupts.c
> + RiscV64/CpuPause.c
> + RiscV64/RiscVSetJumpLongJump.S | GCC
> + RiscV64/RiscVCpuBreakpoint.S | GCC
> + RiscV64/RiscVCpuPause.S | GCC
> + RiscV64/RiscVInterrupt.S | GCC
> + RiscV64/FlushCache.S | GCC
> +
> [Packages]
> MdePkg/MdePkg.dec
>
> diff --git a/MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c
> b/MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c
> new file mode 100644
> index 0000000..d82b1d5
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c
> @@ -0,0 +1,27 @@
> +/** @file
> + CPU breakpoint for RISC-V
> +
> + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP.
> + All rights reserved.<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent **/
> +
> +#include "BaseLibInternals.h"
> +
> +extern VOID RiscVCpuBreakpoint (VOID);
> +
> +/**
> + Generates a breakpoint on the CPU.
> +
> + Generates a breakpoint on the CPU. The breakpoint must be implemented
> + such that code can resume normal execution after the breakpoint.
> +
> +**/
> +VOID
> +EFIAPI
> +CpuBreakpoint (
> + VOID
> + )
> +{
> + RiscVCpuBreakpoint ();
> +}
> diff --git a/MdePkg/Library/BaseLib/RiscV64/CpuPause.c
> b/MdePkg/Library/BaseLib/RiscV64/CpuPause.c
> new file mode 100644
> index 0000000..8eb6b65
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/RiscV64/CpuPause.c
> @@ -0,0 +1,29 @@
> +/** @file
> + CPU pause for RISC-V
> +
> + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP.
> + All rights reserved.<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent **/
> +
> +#include "BaseLibInternals.h"
> +
> +extern VOID RiscVCpuPause (VOID);
> +
> +
> +/**
> + Requests CPU to pause for a short period of time.
> +
> + Requests CPU to pause for a short period of time. Typically used in
> + MP systems to prevent memory starvation while waiting for a spin lock.
> +
> +**/
> +VOID
> +EFIAPI
> +CpuPause (
> + VOID
> + )
> +{
> + RiscVCpuPause ();
> +}
> +
> diff --git a/MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c
> b/MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c
> new file mode 100644
> index 0000000..7ee5eb1
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c
> @@ -0,0 +1,24 @@
> +/** @file
> + CPU disable interrupt function for RISC-V
> +
> + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP.
> + All rights reserved.<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include
> +"BaseLibInternals.h"
> +
> +extern VOID RiscVDisableSupervisorModeInterrupts (VOID);
> +
> +/**
> + Disables CPU interrupts.
> +
> +**/
> +VOID
> +EFIAPI
> +DisableInterrupts (
> + VOID
> + )
> +{
> + RiscVDisableSupervisorModeInterrupts (); }
> +
> diff --git a/MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c
> b/MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c
> new file mode 100644
> index 0000000..9aa0d9a
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c
> @@ -0,0 +1,25 @@
> +/** @file
> + CPU enable interrupt function for RISC-V
> +
> + Copyright (c) 2016-2019, Hewlett Packard Enterprise Development LP.
> + All rights reserved.<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent **/
> +
> +#include "BaseLibInternals.h"
> +
> +extern VOID RiscVEnableSupervisorModeInterrupt (VOID);
> +
> +/**
> + Enables CPU interrupts.
> +
> +**/
> +VOID
> +EFIAPI
> +EnableInterrupts (
> + VOID
> + )
> +{
> + RiscVEnableSupervisorModeInterrupt (); }
> +
> diff --git a/MdePkg/Library/BaseLib/RiscV64/FlushCache.S
> b/MdePkg/Library/BaseLib/RiscV64/FlushCache.S
> new file mode 100644
> index 0000000..0ef0213
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/RiscV64/FlushCache.S
> @@ -0,0 +1,21 @@
> +//---------------------------------------------------------------------
> +---------
> +//
> +// RISC-V cache operation.
> +//
> +// Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development
> +LP. All rights reserved.<BR> // // SPDX-License-Identifier:
> +BSD-2-Clause-Patent //
> +//---------------------------------------------------------------------
> +---------
> +
> +.align 3
> +ASM_GLOBAL ASM_PFX(RiscVInvalidateInstCacheAsm)
> +ASM_GLOBAL ASM_PFX(RiscVInvalidateDataCacheAsm)
> +
> +ASM_PFX(RiscVInvalidateInstCacheAsm):
> + fence.i
> + ret
> +
> +ASM_PFX(RiscVInvalidateDataCacheAsm):
> + fence
> + ret
> diff --git a/MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c
> b/MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c
> new file mode 100644
> index 0000000..8f764fb
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c
> @@ -0,0 +1,35 @@
> +/** @file
> + CPU get interrupt state function for RISC-V
> +
> + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP.
> + All rights reserved.<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent **/
> +
> +#include "BaseLibInternals.h"
> +
> +extern UINT32 RiscVGetSupervisorModeInterrupts (VOID);
> +
> +/**
> + Retrieves the current CPU interrupt state.
> +
> + Returns TRUE is interrupts are currently enabled. Otherwise returns
> + FALSE.
> +
> + @retval TRUE CPU interrupts are enabled.
> + @retval FALSE CPU interrupts are disabled.
> +
> +**/
> +BOOLEAN
> +EFIAPI
> +GetInterruptState (
> + VOID
> + )
> +{
> + unsigned long RetValue;
> +
> + RetValue = RiscVGetSupervisorModeInterrupts ();
> + return RetValue? TRUE: FALSE;
> +}
> +
> +
> diff --git a/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c
> b/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c
> new file mode 100644
> index 0000000..1082d4e
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c
> @@ -0,0 +1,55 @@
> +/** @file
> + Switch stack function for RISC-V
> +
> + Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All
> + rights reserved.<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent **/
> +
> +#include "BaseLibInternals.h"
> +
> +/**
> + Transfers control to a function starting with a new stack.
> +
> + Transfers control to the function specified by EntryPoint using the
> + new stack specified by NewStack and passing in the parameters
> + specified by Context1 and Context2. Context1 and Context2 are
> + optional and may be NULL. The function EntryPoint must never return.
> + Marker will be ignored on IA-32, x64, and EBC.
> + IPF CPUs expect one additional parameter of type VOID * that
> + specifies the new backing store pointer.
> +
> + If EntryPoint is NULL, then ASSERT().
> + If NewStack is NULL, then ASSERT().
> +
> + @param EntryPoint A pointer to function to call with the new stack.
> + @param Context1 A pointer to the context to pass into the EntryPoint
> + function.
> + @param Context2 A pointer to the context to pass into the EntryPoint
> + function.
> + @param NewStack A pointer to the new stack to use for the EntryPoint
> + function.
> + @param Marker VA_LIST marker for the variable argument list.
> +
> +**/
> +VOID
> +EFIAPI
> +InternalSwitchStack (
> + IN SWITCH_STACK_ENTRY_POINT EntryPoint,
> + IN VOID *Context1, OPTIONAL
> + IN VOID *Context2, OPTIONAL
> + IN VOID *NewStack,
> + IN VA_LIST Marker
> + )
> +{
> + BASE_LIBRARY_JUMP_BUFFER JumpBuffer;
> +
> + DEBUG ((DEBUG_INFO, "RISC-V InternalSwitchStack Entry:%x Context1:%x
> Context2:%x NewStack%x\n", \
> + EntryPoint, Context1, Context2, NewStack));
> + JumpBuffer.RA = (UINTN)EntryPoint;
> + JumpBuffer.SP = (UINTN)NewStack - sizeof (VOID *);
> + JumpBuffer.S0 = (UINT64)(UINTN)Context1;
> + JumpBuffer.S1 = (UINT64)(UINTN)Context2;
> + LongJump (&JumpBuffer, (UINTN)-1);
> + ASSERT(FALSE);
> +}
> diff --git a/MdePkg/Library/BaseLib/RiscV64/LongJump.c
> b/MdePkg/Library/BaseLib/RiscV64/LongJump.c
> new file mode 100644
> index 0000000..a62b882
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/RiscV64/LongJump.c
> @@ -0,0 +1,32 @@
> +/** @file
> + Long jump implementation of RISC-V
> +
> + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP.
> + All rights reserved.<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent **/
> +
> +#include "BaseLibInternals.h"
> +
> +
> +/**
> + Restores the CPU context that was saved with SetJump().
> +
> + Restores the CPU context from the buffer specified by JumpBuffer.
> + This function never returns to the caller.
> + Instead is resumes execution based on the state of JumpBuffer.
> +
> + @param JumpBuffer A pointer to CPU context buffer.
> + @param Value The value to return when the SetJump() context is
> restored.
> +
> +**/
> +VOID
> +EFIAPI
> +InternalLongJump (
> + IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,
> + IN UINTN Value
> + )
> +{
> + ASSERT (FALSE);
> +}
> +
> diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S
> b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S
> new file mode 100644
> index 0000000..1a45e2a
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S
> @@ -0,0 +1,14 @@
> +//---------------------------------------------------------------------
> +---------
> +//
> +// CpuBreakpoint for RISC-V
> +//
> +// Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development
> +LP. All rights reserved.<BR> // // SPDX-License-Identifier:
> +BSD-2-Clause-Patent //
> +//---------------------------------------------------------------------
> +---------
> +
> +ASM_GLOBAL ASM_PFX(RiscVCpuBreakpoint)
> +ASM_PFX(RiscVCpuBreakpoint):
> + ebreak
> + ret
> diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S
> b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S
> new file mode 100644
> index 0000000..ceba0c0
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S
> @@ -0,0 +1,14 @@
> +//---------------------------------------------------------------------
> +---------
> +//
> +// CpuPause for RISC-V
> +//
> +// Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development
> +LP. All rights reserved.<BR> // // SPDX-License-Identifier:
> +BSD-2-Clause-Patent //
> +//---------------------------------------------------------------------
> +---------
> +
> +ASM_GLOBAL ASM_PFX(RiscVCpuPause)
> +ASM_PFX(RiscVCpuPause):
> + nop
> + ret
> diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
> b/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
> new file mode 100644
> index 0000000..8fdb544
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
> @@ -0,0 +1,32 @@
> +//---------------------------------------------------------------------
> +---------
> +//
> +// RISC-V Supervisor Mode interrupt enable/disable // // Copyright (c)
> +2016 - 2019, Hewlett Packard Enterprise Development LP. All rights
> +reserved.<BR> // // SPDX-License-Identifier: BSD-2-Clause-Patent //
> +//---------------------------------------------------------------------
> +---------
> +
> +ASM_GLOBAL ASM_PFX(RiscVDisableSupervisorModeInterrupts)
> +ASM_GLOBAL ASM_PFX(RiscVEnableSupervisorModeInterrupt)
> +ASM_GLOBAL ASM_PFX(RiscVGetSupervisorModeInterrupts)
> +
> +# define MSTATUS_SIE 0x00000002
> +# define CSR_SSTATUS 0x100
> +
> +ASM_PFX(RiscVDisableSupervisorModeInterrupts):
> + li a1, MSTATUS_SIE
> + csrc CSR_SSTATUS, a1
> + ret
> +
> +ASM_PFX(RiscVEnableSupervisorModeInterrupt):
> + li a1, MSTATUS_SIE
> + csrs CSR_SSTATUS, a1
> + ret
> +
> +ASM_PFX(RiscVGetSupervisorModeInterrupts):
> + csrr a0, CSR_SSTATUS
> + andi a0, a0, MSTATUS_SIE
> + ret
> +
> diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S
> b/MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S
> new file mode 100644
> index 0000000..e72dd7f
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S
> @@ -0,0 +1,55 @@
> +//---------------------------------------------------------------------
> +---------
> +//
> +// Set/Long jump for RISC-V
> +//
> +// Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development
> +LP. All rights reserved.<BR> // // SPDX-License-Identifier:
> +BSD-2-Clause-Patent //
> +//---------------------------------------------------------------------
> +---------
> +# define REG_S sd
> +# define REG_L ld
> +# define SZREG 8
> +.align 3
> + .globl SetJump
> +
> +SetJump:
> + REG_S ra, 0*SZREG(a0)
> + REG_S s0, 1*SZREG(a0)
> + REG_S s1, 2*SZREG(a0)
> + REG_S s2, 3*SZREG(a0)
> + REG_S s3, 4*SZREG(a0)
> + REG_S s4, 5*SZREG(a0)
> + REG_S s5, 6*SZREG(a0)
> + REG_S s6, 7*SZREG(a0)
> + REG_S s7, 8*SZREG(a0)
> + REG_S s8, 9*SZREG(a0)
> + REG_S s9, 10*SZREG(a0)
> + REG_S s10,11*SZREG(a0)
> + REG_S s11,12*SZREG(a0)
> + REG_S sp, 13*SZREG(a0)
> + li a0, 0
> + ret
> +
> + .globl InternalLongJump
> +InternalLongJump:
> + REG_L ra, 0*SZREG(a0)
> + REG_L s0, 1*SZREG(a0)
> + REG_L s1, 2*SZREG(a0)
> + REG_L s2, 3*SZREG(a0)
> + REG_L s3, 4*SZREG(a0)
> + REG_L s4, 5*SZREG(a0)
> + REG_L s5, 6*SZREG(a0)
> + REG_L s6, 7*SZREG(a0)
> + REG_L s7, 8*SZREG(a0)
> + REG_L s8, 9*SZREG(a0)
> + REG_L s9, 10*SZREG(a0)
> + REG_L s10,11*SZREG(a0)
> + REG_L s11,12*SZREG(a0)
> + REG_L sp, 13*SZREG(a0)
> +
> + add a0, s0, 0
> + add a1, s1, 0
> + add a2, s2, 0
> + add a3, s3, 0
> + ret
> diff --git a/MdePkg/Library/BaseLib/RiscV64/Unaligned.c
> b/MdePkg/Library/BaseLib/RiscV64/Unaligned.c
> new file mode 100644
> index 0000000..012d913
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/RiscV64/Unaligned.c
> @@ -0,0 +1,264 @@
> +/** @file
> + RISC-V specific functionality for (un)aligned memory read/write.
> +
> + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP.
> + All rights reserved.<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent **/
> +
> +#include "BaseLibInternals.h"
> +
> +/**
> + Reads a 16-bit value from memory that may be unaligned.
> +
> + This function returns the 16-bit value pointed to by Buffer. The
> + function guarantees that the read operation does not produce an
> alignment fault.
> +
> + If the Buffer is NULL, then ASSERT().
> +
> + @param Buffer A pointer to a 16-bit value that may be unaligned.
> +
> + @return The 16-bit value read from Buffer.
> +
> +**/
> +UINT16
> +EFIAPI
> +ReadUnaligned16 (
> + IN CONST UINT16 *Buffer
> + )
> +{
> + UINT16 Value;
> + INT8 Count;
> +
> + ASSERT (Buffer != NULL);
> +
> + for (Count = sizeof (UINT16) - 1, Value = 0; Count >= 0 ; Count --) {
> + Value = Value << 8;
> + Value |= *((UINT8*)Buffer + Count);
> + }
> + return Value;
> +}
> +
> +/**
> + Writes a 16-bit value to memory that may be unaligned.
> +
> + This function writes the 16-bit value specified by Value to Buffer.
> + Value is returned. The function guarantees that the write operation
> + does not produce an alignment fault.
> +
> + If the Buffer is NULL, then ASSERT().
> +
> + @param Buffer A pointer to a 16-bit value that may be unaligned.
> + @param Value 16-bit value to write to Buffer.
> +
> + @return The 16-bit value to write to Buffer.
> +
> +**/
> +UINT16
> +EFIAPI
> +WriteUnaligned16 (
> + OUT UINT16 *Buffer,
> + IN UINT16 Value
> + )
> +{
> + INT8 Count;
> + UINT16 ValueTemp;
> +
> + ASSERT (Buffer != NULL);
> +
> + for (Count = 0, ValueTemp = Value; Count < sizeof (UINT16) ; Count ++) {
> + *((UINT8*)Buffer + Count) = (UINT8)(ValueTemp & 0xff);
> + ValueTemp = ValueTemp >> 8;
> + }
> + return Value;
> +}
> +
> +/**
> + Reads a 24-bit value from memory that may be unaligned.
> +
> + This function returns the 24-bit value pointed to by Buffer. The
> + function guarantees that the read operation does not produce an
> alignment fault.
> +
> + If the Buffer is NULL, then ASSERT().
> +
> + @param Buffer A pointer to a 24-bit value that may be unaligned.
> +
> + @return The 24-bit value read from Buffer.
> +
> +**/
> +UINT32
> +EFIAPI
> +ReadUnaligned24 (
> + IN CONST UINT32 *Buffer
> + )
> +{
> + UINT32 Value;
> + INT8 Count;
> +
> + ASSERT (Buffer != NULL);
> + for (Count = 2, Value = 0; Count >= 0 ; Count --) {
> + Value = Value << 8;
> + Value |= *((UINT8*)Buffer + Count);
> + }
> + return Value;
> +}
> +
> +/**
> + Writes a 24-bit value to memory that may be unaligned.
> +
> + This function writes the 24-bit value specified by Value to Buffer.
> + Value is returned. The function guarantees that the write operation
> + does not produce an alignment fault.
> +
> + If the Buffer is NULL, then ASSERT().
> +
> + @param Buffer A pointer to a 24-bit value that may be unaligned.
> + @param Value 24-bit value to write to Buffer.
> +
> + @return The 24-bit value to write to Buffer.
> +
> +**/
> +UINT32
> +EFIAPI
> +WriteUnaligned24 (
> + OUT UINT32 *Buffer,
> + IN UINT32 Value
> + )
> +{
> + INT8 Count;
> + UINT32 ValueTemp;
> +
> + ASSERT (Buffer != NULL);
> + for (Count = 0, ValueTemp = Value; Count < 3 ; Count ++) {
> + *((UINT8*)Buffer + Count) = (UINT8)(ValueTemp & 0xff);
> + ValueTemp = ValueTemp >> 8;
> + }
> + return Value;
> +}
> +
> +/**
> + Reads a 32-bit value from memory that may be unaligned.
> +
> + This function returns the 32-bit value pointed to by Buffer. The
> + function guarantees that the read operation does not produce an
> alignment fault.
> +
> + If the Buffer is NULL, then ASSERT().
> +
> + @param Buffer A pointer to a 32-bit value that may be unaligned.
> +
> + @return The 32-bit value read from Buffer.
> +
> +**/
> +UINT32
> +EFIAPI
> +ReadUnaligned32 (
> + IN CONST UINT32 *Buffer
> + )
> +{
> + UINT32 Value;
> + INT8 Count;
> +
> + ASSERT (Buffer != NULL);
> +
> + for (Count = sizeof (UINT32) - 1, Value = 0; Count >= 0 ; Count --) {
> + Value = Value << 8;
> + Value |= *((UINT8*)Buffer + Count);
> + }
> + return Value;
> +}
> +
> +/**
> + Writes a 32-bit value to memory that may be unaligned.
> +
> + This function writes the 32-bit value specified by Value to Buffer.
> + Value is returned. The function guarantees that the write operation
> + does not produce an alignment fault.
> +
> + If the Buffer is NULL, then ASSERT().
> +
> + @param Buffer A pointer to a 32-bit value that may be unaligned.
> + @param Value The 32-bit value to write to Buffer.
> +
> + @return The 32-bit value to write to Buffer.
> +
> +**/
> +UINT32
> +EFIAPI
> +WriteUnaligned32 (
> + OUT UINT32 *Buffer,
> + IN UINT32 Value
> + )
> +{
> + INT8 Count;
> + UINT32 ValueTemp;
> +
> + ASSERT (Buffer != NULL);
> + for (Count = 0, ValueTemp = Value; Count < sizeof (UINT32) ; Count ++) {
> + *((UINT8*)Buffer + Count) = (UINT8)(ValueTemp & 0xff);
> + ValueTemp = ValueTemp >> 8;
> + }
> + return Value;
> +}
> +
> +/**
> + Reads a 64-bit value from memory that may be unaligned.
> +
> + This function returns the 64-bit value pointed to by Buffer. The
> + function guarantees that the read operation does not produce an
> alignment fault.
> +
> + If the Buffer is NULL, then ASSERT().
> +
> + @param Buffer A pointer to a 64-bit value that may be unaligned.
> +
> + @return The 64-bit value read from Buffer.
> +
> +**/
> +UINT64
> +EFIAPI
> +ReadUnaligned64 (
> + IN CONST UINT64 *Buffer
> + )
> +{
> + UINT64 Value;
> + INT8 Count;
> +
> + ASSERT (Buffer != NULL);
> + for (Count = sizeof (UINT64) - 1, Value = 0; Count >= 0 ; Count --) {
> + Value = Value << 8;
> + Value |= *((UINT8*)Buffer + Count);
> + }
> + return Value;
> +}
> +
> +/**
> + Writes a 64-bit value to memory that may be unaligned.
> +
> + This function writes the 64-bit value specified by Value to Buffer.
> + Value is returned. The function guarantees that the write operation
> + does not produce an alignment fault.
> +
> + If the Buffer is NULL, then ASSERT().
> +
> + @param Buffer A pointer to a 64-bit value that may be unaligned.
> + @param Value The 64-bit value to write to Buffer.
> +
> + @return The 64-bit value to write to Buffer.
> +
> +**/
> +UINT64
> +EFIAPI
> +WriteUnaligned64 (
> + OUT UINT64 *Buffer,
> + IN UINT64 Value
> + )
> +{
> + INT8 Count;
> + UINT64 ValueTemp;
> +
> + ASSERT (Buffer != NULL);
> + for (Count = 0, ValueTemp = Value; Count < sizeof (UINT64) ; Count ++) {
> + *((UINT8*)Buffer + Count) = (UINT8)(ValueTemp & 0xff);
> + ValueTemp = ValueTemp >> 8;
> + }
> + return Value;
> +}
> --
> 2.7.4
>
>
>
next prev parent reply other threads:[~2019-09-24 1:53 UTC|newest]
Thread overview: 108+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-23 0:31 [edk2-staging/RISC-V-V2 PATCH v2 00/29] RISC-V EDK2 Port on Abner Chang
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 01/29] RiscVPkg: RISC-V processor package Abner Chang
2019-09-26 22:26 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 02/29] RiscVPkg/Include: Add header files of RISC-V CPU package Abner Chang
2019-09-26 22:29 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 03/29] RiscVPkg/opensbi: EDK2 RISC-V OpenSBI support Abner Chang
2019-09-26 22:41 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 04/29] MdePkg: RISC-V RV64 binding in MdePkg Abner Chang
2019-09-26 22:44 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 05/29] MdePkg/Include: RISC-V definitions Abner Chang
2019-09-26 22:45 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 06/29] MdeModulePkg/CapsuleRuntimeDxe: Add RISCV64 arch Abner Chang
2019-09-26 22:46 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 07/29] MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor Abner Chang
2019-09-26 22:56 ` [edk2-devel] " Leif Lindholm
2019-10-14 16:47 ` Abner Chang
2019-10-14 18:23 ` Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 08/29] MdePkg/BaseCacheMaintenanceLib: RISC-V cache maintenance implementation Abner Chang
2019-10-01 8:44 ` [edk2-devel] " Philippe Mathieu-Daudé
2019-09-23 0:31 ` Abner Chang
2019-09-26 23:30 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 09/29] MdePkg/BaseIoLibIntrinsic: RISC-V I/O intrinsic functions Abner Chang
2019-09-26 23:39 ` [edk2-devel] " Leif Lindholm
2019-10-01 8:49 ` Philippe Mathieu-Daudé
2019-10-01 9:07 ` Leif Lindholm
2019-10-02 1:30 ` Abner Chang
2019-10-02 9:13 ` Leif Lindholm
2019-10-02 16:14 ` Abner Chang
2019-10-02 16:27 ` Andrew Fish
2019-10-02 16:35 ` Leif Lindholm
2019-10-03 0:52 ` Abner Chang
2019-10-03 8:38 ` Leif Lindholm
2019-10-03 11:34 ` Abner Chang
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 10/29] MdePkg/BasePeCoff: Add RISC-V PE/Coff related code Abner Chang
2019-09-26 23:46 ` [edk2-devel] " Leif Lindholm
2019-10-15 4:02 ` Abner Chang
2019-10-15 10:31 ` Leif Lindholm
2019-10-15 10:56 ` Abner Chang
[not found] ` <15CDB6324F411B37.30896@groups.io>
2019-10-15 4:26 ` Abner Chang
2019-10-15 10:41 ` Leif Lindholm
2019-10-15 10:59 ` Abner Chang
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 11/29] MdePkg/BaseCpuLib: RISC-V Base CPU library implementation Abner Chang
2019-09-26 23:47 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 12/29] MdePkg/BaseSynchronizationLib: RISC-V cache related code Abner Chang
2019-09-27 0:19 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 13/29] MdeModulePkg/Logo Abner Chang
2019-09-30 22:51 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 14/29] NetworkPkg Abner Chang
2019-09-30 22:51 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 15/29] RiscVPkg/Library: RISC-V CPU library Abner Chang
2019-09-30 18:31 ` [edk2-devel] " Leif Lindholm
2019-10-15 2:32 ` Abner Chang
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 16/29] RiscVPkg/Library: Add RISC-V exception library Abner Chang
2019-09-30 19:15 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 17/29] RiscVPkg/Library: Add RISC-V timer library Abner Chang
2019-09-30 19:46 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 18/29] RiscVPkg/Library: Add EDK2 RISC-V OpenSBI library Abner Chang
2019-09-30 20:03 ` [edk2-devel] " Leif Lindholm
2019-10-15 1:21 ` Abner Chang
2019-10-15 8:35 ` Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 19/29] RiscVPkg/Library: RISC-V platform level DxeIPL libraries Abner Chang
2019-09-30 20:15 ` [edk2-devel] " Leif Lindholm
2019-09-30 20:44 ` Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 20/29] MdeModulePkg/DxeIplPeim : RISC-V platform level DxeIPL Abner Chang
2019-09-30 20:31 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 21/29] RiscVPkg/PeiServicesTablePointerLibOpenSbi: RISC-V PEI Service Table Pointer library Abner Chang
2019-09-30 20:54 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 22/29] RiscVPkg/RiscVPlatformTempMemoryInit: RISC-V Platform Temporary Memory library Abner Chang
2019-09-30 20:56 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 23/29] RiscVPkg/CpuDxe: Add RISC-V CPU DXE driver Abner Chang
2019-09-30 21:11 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 24/29] BaseTools: BaseTools changes for RISC-V platform Abner Chang
2019-09-26 22:09 ` [edk2-devel] " Leif Lindholm
2019-10-15 6:18 ` Abner Chang
2019-10-15 10:56 ` Leif Lindholm
2019-10-15 11:13 ` Abner Chang
2019-10-16 5:06 ` Abner Chang
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 25/29] BaseTools/Scripts Abner Chang
2019-09-26 20:50 ` [edk2-devel] " Leif Lindholm
2019-10-15 6:31 ` Abner Chang
2019-10-15 11:00 ` Leif Lindholm
2019-10-15 11:03 ` Abner Chang
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 26/29] RiscVPkg/SmbiosDxe: Generic SMBIOS DXE driver for RISC-V platforms Abner Chang
2019-09-30 22:39 ` [edk2-devel] " Leif Lindholm
2019-10-14 11:27 ` Abner Chang
2019-10-14 11:56 ` Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 27/29] edk2-staging/RISC-V-V2: Add submodule Abner Chang
2019-09-26 22:24 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 28/29] edk2-staging/RISC-V-V2: Add ReadMe Abner Chang
2019-09-30 22:48 ` [edk2-devel] " Leif Lindholm
2019-09-23 0:31 ` [edk2-staging/RISC-V-V2 PATCH v2 29/29] edk2-staging: Update Maintainers.txt Abner Chang
2019-09-30 22:50 ` [edk2-devel] " Leif Lindholm
[not found] ` <15C6EB9824DD2A88.29693@groups.io>
2019-09-24 1:52 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 04/29] MdePkg: RISC-V RV64 binding in MdePkg Abner Chang
[not found] ` <15C6EB994C26E5C4.2053@groups.io>
2019-09-24 1:52 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 05/29] MdePkg/Include: RISC-V definitions Abner Chang
[not found] ` <15C6EB9950232DB5.29693@groups.io>
2019-09-24 1:53 ` Abner Chang [this message]
[not found] ` <15C6EB9A049FF8A4.24160@groups.io>
2019-09-24 1:54 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 09/29] MdePkg/BaseIoLibIntrinsic: RISC-V I/O intrinsic functions Abner Chang
[not found] ` <15C6EB9B3E887BEB.29693@groups.io>
2019-09-24 1:55 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 13/29] MdeModulePkg/Logo Abner Chang
[not found] ` <15C6EB9A40C408A0.24160@groups.io>
2019-09-24 1:56 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 10/29] MdePkg/BasePeCoff: Add RISC-V PE/Coff related code Abner Chang
[not found] ` <15C6EB9B872A5B83.24160@groups.io>
2019-09-24 1:57 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 14/29] NetworkPkg Abner Chang
[not found] ` <15C6EB99CBC780B5.2053@groups.io>
2019-09-24 1:57 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 08/29] MdePkg/BaseCacheMaintenanceLib: RISC-V cache maintenance implementation Abner Chang
[not found] ` <15C6EB9A9BD83853.2053@groups.io>
2019-09-24 1:58 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 11/29] MdePkg/BaseCpuLib: RISC-V Base CPU library implementation Abner Chang
[not found] ` <15C6EB9AEB7BB057.24160@groups.io>
2019-09-24 1:58 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 12/29] MdePkg/BaseSynchronizationLib: RISC-V cache related code Abner Chang
[not found] ` <15C6EB99608359A3.24160@groups.io>
2019-09-24 1:59 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 08/29] MdePkg/BaseCacheMaintenanceLib: RISC-V cache maintenance implementation Abner Chang
[not found] ` <15C6EB9D6C0EC3B0.29693@groups.io>
2019-09-24 2:00 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 20/29] MdeModulePkg/DxeIplPeim : RISC-V platform level DxeIPL Abner Chang
[not found] ` <15C6EB98AD6CCCEB.24160@groups.io>
2019-09-24 2:01 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 06/29] MdeModulePkg/CapsuleRuntimeDxe: Add RISCV64 arch Abner Chang
[not found] ` <15C6EB9F04387439.29693@groups.io>
2019-09-24 2:02 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 25/29] BaseTools/Scripts Abner Chang
2019-09-26 22:22 ` [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 00/29] RISC-V EDK2 Port on Leif Lindholm
2019-10-15 6:39 ` Abner Chang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CS1PR8401MB1192F09296DF36975AF2AB2AFF840@CS1PR8401MB1192.NAMPRD84.PROD.OUTLOOK.COM \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox