Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add support for LoongArch #1

Open
wants to merge 2 commits into
base: la64/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Make.common
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,27 @@ ifeq ($(ARCH), aarch64)
LD_CODE = aarch64elf
endif

ifeq ($(ARCH), loongarch64)
GNUEFI_CFLAGS += -DEFILOONGARCH64
FORMAT = -O binary
FORMAT_DRIVER = -O binary
SUBSYSTEM_LDFLAG = -defsym=EFI_SUBSYSTEM=0xa
LDFLAGS += --warn-common --no-undefined --fatal-warnings

ARCH_CFLAGS = -fno-merge-constants -ffreestanding -DEFILOONGARCH64
ifeq ($(MAKEWITH),TIANO)
ARCH_CFLAGS += -mcmodel=large -Wno-address -Wno-missing-braces -Wno-array-bounds -ffunction-sections -fdata-sections
endif
ifeq ($(MAKEWITH),GNUEFI)
ARCH_CFLAGS += -fno-stack-check
endif
ARCHDIR = LoongArch64
UC_ARCH = LOONGARCH64
FILENAME_CODE = loongarch64
LD_CODE = loongarch64elf
endif


# GNU-EFI compilation path uses .o files for compiled object code
%.o: %.c
$(CC) $(CFLAGS) $(ARCH_CFLAGS) $(GNUEFI_CFLAGS) $(LOCAL_GNUEFI_CFLAGS) \
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ tiano:
ifneq ($(ARCH),aarch64)
+make MAKEWITH=TIANO -C $(GPTSYNC_DIR) -f Make.tiano
endif
ifneq ($(ARCH),loongarch64)
+make MAKEWITH=TIANO -C $(GPTSYNC_DIR) -f Make.tiano
endif
# +make MAKEWITH=TIANO -C $(FS_DIR)

all_tiano: tiano fs_tiano
Expand Down
5 changes: 4 additions & 1 deletion RefindPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PLATFORM_GUID = d6365e1c-b895-426d-a012-46769b2d02a3
PLATFORM_VERSION = 4.5.0
DSC_SPECIFICATION = 0x00010006
SUPPORTED_ARCHITECTURES = IA32|IPF|X64|EBC|ARM|AARCH64
SUPPORTED_ARCHITECTURES = IA32|IPF|X64|EBC|ARM|AARCH64|LOONGARCH64
BUILD_TARGETS = DEBUG|RELEASE
SKUID_IDENTIFIER = DEFAULT

Expand Down Expand Up @@ -75,6 +75,9 @@
[LibraryClasses.AARCH64]
CompilerIntrinsicsLib|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf

[LibraryClasses.LOONGARCH64]
CompilerIntrinsicsLib|LoongArchPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf

[Components]
RefindPkg/refind.inf
RefindPkg/gptsync.inf
Expand Down
5 changes: 5 additions & 0 deletions filesystems/Make.gnuefi
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ ifeq ($(HOSTARCH),aarch64)
SUBSYSTEM_LDFLAG = -defsym=EFI_SUBSYSTEM=0xb
endif

ifeq ($(HOSTARCH),loongarch64)
# Set symbol for driver
SUBSYSTEM_LDFLAG = -defsym=EFI_SUBSYSTEM=0xb
endif

$(SHLIB_TARGET): $(OBJS)
$(LD) $(GNUEFI_LDFLAGS) $(SUBSYSTEM_LDFLAG) $(OBJS) -o $@ $(LOCAL_LIBS) $(GNUEFI_LIBS)

Expand Down
9 changes: 9 additions & 0 deletions filesystems/btrfs.inf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
# Comment out CompilerIntrinsicsLib when compiling for AARCH64 using UDK2014
CompilerIntrinsicsLib

[LibraryClasses.LOONGARCH64]
BaseStackCheckLib
# Comment out CompilerIntrinsicsLib when compiling for LOONGARCH64 using UDK2014
CompilerIntrinsicsLib

[Guids]

[Ppis]
Expand All @@ -74,3 +79,7 @@
[BuildOptions.AARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=btrfs
GCC:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=btrfs

[BuildOptions.LOONGARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=btrfs
GCC:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=btrfs
9 changes: 9 additions & 0 deletions filesystems/ext2.inf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
# Comment out CompilerIntrinsicsLib when compiling for AARCH64 using UDK2014
CompilerIntrinsicsLib

[LibraryClasses.LOONGARCH64]
BaseStackCheckLib
# Comment out CompilerIntrinsicsLib when compiling for LOONGARCH64 using UDK2014
CompilerIntrinsicsLib

[Guids]

[Ppis]
Expand All @@ -71,3 +76,7 @@
[BuildOptions.AARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=ext2
GCC:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=ext2

[BuildOptions.LOONGARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=ext2
GCC:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=ext2
9 changes: 9 additions & 0 deletions filesystems/ext4.inf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
# Comment out CompilerIntrinsicsLib when compiling for AARCH64 using UDK2014
CompilerIntrinsicsLib

[LibraryClasses.LOONGARCH64]
BaseStackCheckLib
# Comment out CompilerIntrinsicsLib when compiling for LOONGARCH64 using UDK2014
CompilerIntrinsicsLib

[Guids]

[Ppis]
Expand All @@ -72,3 +77,7 @@
[BuildOptions.AARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=ext4
GCC:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=ext4

[BuildOptions.LOONGARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=ext4
GCC:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=ext4
2 changes: 1 addition & 1 deletion filesystems/fsw_efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#include "../include/refit_call_wrapper.h"
#include "../include/version.h"

#define DEBUG_LEVEL 0
#define DEBUG_LEVEL 1

#ifndef FSTYPE
/** The file system type name to use. */
Expand Down
9 changes: 9 additions & 0 deletions filesystems/hfs.inf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
# Comment out CompilerIntrinsicsLib when compiling for AARCH64 using UDK2014
CompilerIntrinsicsLib

[LibraryClasses.LOONGARCH64]
BaseStackCheckLib
# Comment out CompilerIntrinsicsLib when compiling for LOONGARCH64 using UDK2014
CompilerIntrinsicsLib

[Guids]

[Ppis]
Expand All @@ -72,3 +77,7 @@
[BuildOptions.AARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=hfs
GCC:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=hfs

[BuildOptions.LOONGARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=hfs
GCC:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=hfs
9 changes: 9 additions & 0 deletions filesystems/iso9660.inf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
# Comment out CompilerIntrinsicsLib when compiling for AARCH64 using UDK2014
CompilerIntrinsicsLib

[LibraryClasses.LOONGARCH64]
BaseStackCheckLib
# Comment out CompilerIntrinsicsLib when compiling for LOONGARCH64 using UDK2014
CompilerIntrinsicsLib

[Guids]

[Ppis]
Expand All @@ -72,3 +77,7 @@
[BuildOptions.AARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=iso9660
GCC:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=iso9660

[BuildOptions.LOONGARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=iso9660
GCC:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=iso9660
9 changes: 9 additions & 0 deletions filesystems/ntfs.inf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
# Comment out CompilerIntrinsicsLib when compiling for AARCH64 using UDK2014
CompilerIntrinsicsLib

[LibraryClasses.LOONGARCH64]
BaseStackCheckLib
# Comment out CompilerIntrinsicsLib when compiling for LOONGARCH64 using UDK2014
CompilerIntrinsicsLib

[Guids]

[Ppis]
Expand All @@ -72,3 +77,7 @@
[BuildOptions.AARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=ntfs
GCC:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=ntfs

[BuildOptions.LOONGARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=ntfs
GCC:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=ntfs
9 changes: 9 additions & 0 deletions filesystems/reiserfs.inf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
# Comment out CompilerIntrinsicsLib when compiling for AARCH64 using UDK2014
CompilerIntrinsicsLib

[LibraryClasses.LOONGARCH64]
BaseStackCheckLib
# Comment out CompilerIntrinsicsLib when compiling for LOONGARCH64 using UDK2014
CompilerIntrinsicsLib

[Guids]

[Ppis]
Expand All @@ -72,3 +77,7 @@
[BuildOptions.AARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=reiserfs
GCC:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO -DFSTYPE=reiserfs

[BuildOptions.LOONGARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=reiserfs
GCC:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO -DFSTYPE=reiserfs
9 changes: 9 additions & 0 deletions gptsync.inf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
# Comment out CompilerIntrinsicsLib when compiling for AARCH64 using UDK2014
CompilerIntrinsicsLib

[LibraryClasses.LOONGARCH64]
BaseStackCheckLib
# Comment out CompilerIntrinsicsLib when compiling for LOONGARCH64 using UDK2014
CompilerIntrinsicsLib

[Guids]
gEfiAcpiTableGuid
gEfiAcpi10TableGuid
Expand Down Expand Up @@ -135,3 +140,7 @@
[BuildOptions.AARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO
GCC:*_*_*_CC_FLAGS = -Os -DEFIAARCH64 -D__MAKEWITH_TIANO

[BuildOptions.LOONGARCH64]
XCODE:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO
GCC:*_*_*_CC_FLAGS = -Os -DEFILOONGARCH64 -D__MAKEWITH_TIANO
4 changes: 4 additions & 0 deletions gptsync/Make.gnuefi
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ ifeq ($(ARCH),aarch64)
TARGET = gptsync_aa64.efi
endif

ifeq ($(ARCH),loongarch64)
TARGET = gptsync_loongarch64.efi
endif

all: $(TARGET)

SHLIB_TARGET = $(subst .efi,.so,$(TARGET))
Expand Down
4 changes: 4 additions & 0 deletions gptsync/Make.tiano
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ ifeq ($(ARCH),aarch64)
ALL_EFILIBS += $(EFILIB)/BaseStackCheckLib/BaseStackCheckLib/OUTPUT/BaseStackCheckLib.lib
endif

ifeq ($(ARCH),loongarch64)
ALL_EFILIBS += $(EFILIB)/BaseStackCheckLib/BaseStackCheckLib/OUTPUT/BaseStackCheckLib.lib
endif

TIANO_INCLUDE_DIRS = -I $(TIANOBASE)/MdePkg \
-I $(TIANOBASE)/MdePkg/Include \
-I $(TIANOBASE)/MdePkg/Include/$(ARCHDIR) \
Expand Down
2 changes: 1 addition & 1 deletion gptsync/gptsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
//


#if defined(EFI32) || defined(EFIX64) || defined(EFIAARCH64)
#if defined(EFI32) || defined(EFIX64) || defined(EFIAARCH64) || defined(EFILOONGARCH64)
#define CONFIG_EFI
#endif

Expand Down
2 changes: 1 addition & 1 deletion include/refit_call_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#ifdef __MAKEWITH_GNUEFI

#if defined (EFIX64) | defined (AARCH64)
#if defined (EFIX64) | defined (AARCH64) | defined (LOONGARCH64)
# define refit_call1_wrapper(f, a1) \
uefi_call_wrapper(f, 1, (UINT64)(a1))
# define refit_call2_wrapper(f, a1, a2) \
Expand Down
2 changes: 1 addition & 1 deletion libeg/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
// A value of 4096 should keep us within limits on 32-bit systems, but I've
// seen some minor artifacts at this level, so give it a bit more precision
// on 64-bit systems....
#if defined(EFIX64) | defined(EFIAARCH64)
#if defined(EFIX64) | defined(EFIAARCH64) | defined(EFILOONGARCH64)
#define FP_MULTIPLIER (UINTN) 65536
#else
#define FP_MULTIPLIER (UINTN) 4096
Expand Down
13 changes: 13 additions & 0 deletions mkdistrib
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ MakeZipBinary() {
# Don't copy gptsync_aa64.efi because it won't build in cross-compile environment
# and because it's likely to be useless on ARM64.

# Build the ARM64 binaries
ARCH=loongarch64 make -j1
ARCH=loongarch64 make fs
mkdir -p refind-bin-$Version/refind/drivers_loongarch64
cp --preserve=timestamps drivers_loongarch64/*_loongarch64.efi refind-bin-$Version/refind/drivers_loongarch64/
cp --preserve=timestamps filesystems/LICENSE*txt refind-bin-$Version/refind/drivers_loongarch64/
cp refind/refind_loongarch64.efi refind-bin-$Version/refind/refind_loongarch64.efi
cp refind/refind_loongarch64.efi $StartDir/
mkdir -p refind-bin-$Version/refind/tools_loongarch64
# Don't copy gptsync_loongarch64.efi because it won't build in cross-compile environment
# and because it's likely to be useless on ARM64.


# Build the IA32 binaries
make clean
ARCH=ia32 make -j1
Expand Down
3 changes: 3 additions & 0 deletions mvrefind
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ DeterminePlatform() {
i?86)
Platform="ia32"
;;
loongarch64)
Platform="loongarch64"
;;
*)
echo "Unsupported CPU type; aborting!"
exit 1
Expand Down
Loading