All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/8] Add support for LoongArch
@ 2022-07-01  9:50 Xiaotian Wu
  2022-07-01  9:50 ` [PATCH v4 1/8] PE: Add LoongArch definitions Xiaotian Wu
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Xiaotian Wu @ 2022-07-01  9:50 UTC (permalink / raw)
  To: grub-devel; +Cc: git, Xiaotian Wu

LoongArch is a new Loongson 3A5000 CPU instruction set, you can read
documents[1] or visit the development community[2] to get more information.

[1]: https://loongson.github.io/LoongArch-Documentation/README-EN.html
[2]: https://github.com/loongson

This patch series will add the basic support for LoongArch architecture, it can
compile on LoongArch and display the GRUB UI.

The full LoongArch patch has two parts, this is the first part.
The second part needs to wait for the LoadFile2 patch to be merged upstream first.

Please review the patches, thank you.

v1->v2:
- rebase on the last commit.
- fix some errors.
- change the year to 2022 for the new files.

v2->v3:
- based on the last commit.
- add a comment to setjmp.S
- complete LoongArch support for grub-mkrescue

v3->v4:
- based on the last commit.

Xiaotian Wu (8):
  PE: Add LoongArch definitions
  Add LoongArch definitions
  LoongArch: Add setjmp implementation
  LoongArch: Add early startup code
  LoongArch: Add stubs for Linux loading commands
  LoongArch: Add awareness for LoongArch relocations
  LoongArch: Add auxiliary files
  LoongArch: Add to build system

 Makefile.util.def                        |   1 +
 conf/Makefile.common                     |   3 +
 configure.ac                             |   5 +
 gentpl.py                                |  25 +--
 grub-core/Makefile.am                    |   6 +
 grub-core/Makefile.core.def              |  15 ++
 grub-core/kern/dl.c                      |   9 +-
 grub-core/kern/efi/mm.c                  |   3 +-
 grub-core/kern/loongarch64/cache.c       |  39 +++++
 grub-core/kern/loongarch64/cache_flush.S |  33 ++++
 grub-core/kern/loongarch64/dl.c          | 102 ++++++++++++
 grub-core/kern/loongarch64/dl_helper.c   | 198 +++++++++++++++++++++++
 grub-core/kern/loongarch64/efi/init.c    |  77 +++++++++
 grub-core/kern/loongarch64/efi/startup.S |  34 ++++
 grub-core/lib/efi/halt.c                 |   2 +-
 grub-core/lib/loongarch64/setjmp.S       |  69 ++++++++
 grub-core/lib/setjmp.S                   |   2 +
 grub-core/loader/loongarch64/linux.c     |  59 +++++++
 include/grub/dl.h                        |   1 +
 include/grub/efi/api.h                   |   2 +-
 include/grub/efi/efi.h                   |   2 +-
 include/grub/efi/pe32.h                  |  36 +++--
 include/grub/elf.h                       |  23 +++
 include/grub/loongarch64/efi/memory.h    |  24 +++
 include/grub/loongarch64/linux.h         |  31 ++++
 include/grub/loongarch64/reloc.h         | 107 ++++++++++++
 include/grub/loongarch64/setjmp.h        |  27 ++++
 include/grub/loongarch64/time.h          |  28 ++++
 include/grub/loongarch64/types.h         |  34 ++++
 include/grub/util/install.h              |   1 +
 util/grub-install-common.c               |  49 +++---
 util/grub-install.c                      |  16 ++
 util/grub-mkimagexx.c                    |  79 +++++++++
 util/grub-mknetdir.c                     |   1 +
 util/grub-mkrescue.c                     |   8 +
 util/grub-module-verifier.c              |  26 +++
 util/mkimage.c                           |  16 ++
 37 files changed, 1134 insertions(+), 59 deletions(-)
 create mode 100644 grub-core/kern/loongarch64/cache.c
 create mode 100644 grub-core/kern/loongarch64/cache_flush.S
 create mode 100644 grub-core/kern/loongarch64/dl.c
 create mode 100644 grub-core/kern/loongarch64/dl_helper.c
 create mode 100644 grub-core/kern/loongarch64/efi/init.c
 create mode 100644 grub-core/kern/loongarch64/efi/startup.S
 create mode 100644 grub-core/lib/loongarch64/setjmp.S
 create mode 100644 grub-core/loader/loongarch64/linux.c
 create mode 100644 include/grub/loongarch64/efi/memory.h
 create mode 100644 include/grub/loongarch64/linux.h
 create mode 100644 include/grub/loongarch64/reloc.h
 create mode 100644 include/grub/loongarch64/setjmp.h
 create mode 100644 include/grub/loongarch64/time.h
 create mode 100644 include/grub/loongarch64/types.h

-- 
2.35.1



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

* [PATCH v4 1/8] PE: Add LoongArch definitions
  2022-07-01  9:50 [PATCH v4 0/8] Add support for LoongArch Xiaotian Wu
@ 2022-07-01  9:50 ` Xiaotian Wu
  2022-07-01  9:50 ` [PATCH v4 2/8] " Xiaotian Wu
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Xiaotian Wu @ 2022-07-01  9:50 UTC (permalink / raw)
  To: grub-devel; +Cc: git, Xiaotian Wu, Zhou Yang

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
Signed-off-by: Zhou Yang <zhouyang@loongson.cn>
---
 include/grub/efi/pe32.h | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h
index 0ed8781f0..de56edef6 100644
--- a/include/grub/efi/pe32.h
+++ b/include/grub/efi/pe32.h
@@ -77,6 +77,8 @@ struct grub_pe32_coff_header
 #define GRUB_PE32_MACHINE_X86_64		0x8664
 #define GRUB_PE32_MACHINE_ARMTHUMB_MIXED	0x01c2
 #define GRUB_PE32_MACHINE_ARM64			0xAA64
+#define GRUB_PE32_MACHINE_LOONGARCH32		0x6232
+#define GRUB_PE32_MACHINE_LOONGARCH64		0x6264
 #define GRUB_PE32_MACHINE_RISCV32		0x5032
 #define GRUB_PE32_MACHINE_RISCV64		0x5064
 
@@ -283,22 +285,24 @@ struct grub_pe32_fixup_block
 
 #define GRUB_PE32_FIXUP_ENTRY(type, offset)	(((type) << 12) | (offset))
 
-#define GRUB_PE32_REL_BASED_ABSOLUTE	0
-#define GRUB_PE32_REL_BASED_HIGH	1
-#define GRUB_PE32_REL_BASED_LOW		2
-#define GRUB_PE32_REL_BASED_HIGHLOW	3
-#define GRUB_PE32_REL_BASED_HIGHADJ	4
-#define GRUB_PE32_REL_BASED_MIPS_JMPADDR 5
-#define GRUB_PE32_REL_BASED_ARM_MOV32A  5
-#define GRUB_PE32_REL_BASED_RISCV_HI20	5
-#define GRUB_PE32_REL_BASED_SECTION	6
-#define GRUB_PE32_REL_BASED_REL		7
-#define GRUB_PE32_REL_BASED_ARM_MOV32T  7
-#define GRUB_PE32_REL_BASED_RISCV_LOW12I 7
-#define GRUB_PE32_REL_BASED_RISCV_LOW12S 8
-#define GRUB_PE32_REL_BASED_IA64_IMM64	9
-#define GRUB_PE32_REL_BASED_DIR64	10
-#define GRUB_PE32_REL_BASED_HIGH3ADJ	11
+#define GRUB_PE32_REL_BASED_ABSOLUTE		0
+#define GRUB_PE32_REL_BASED_HIGH		1
+#define GRUB_PE32_REL_BASED_LOW			2
+#define GRUB_PE32_REL_BASED_HIGHLOW		3
+#define GRUB_PE32_REL_BASED_HIGHADJ		4
+#define GRUB_PE32_REL_BASED_MIPS_JMPADDR	5
+#define GRUB_PE32_REL_BASED_ARM_MOV32A  	5
+#define GRUB_PE32_REL_BASED_RISCV_HI20		5
+#define GRUB_PE32_REL_BASED_SECTION		6
+#define GRUB_PE32_REL_BASED_REL			7
+#define GRUB_PE32_REL_BASED_ARM_MOV32T  	7
+#define GRUB_PE32_REL_BASED_RISCV_LOW12I	7
+#define GRUB_PE32_REL_BASED_RISCV_LOW12S	8
+#define GRUB_PE32_REL_BASED_LOONGARCH32_MARK_LA	8
+#define GRUB_PE32_REL_BASED_LOONGARCH64_MARK_LA	8
+#define GRUB_PE32_REL_BASED_IA64_IMM64		9
+#define GRUB_PE32_REL_BASED_DIR64		10
+#define GRUB_PE32_REL_BASED_HIGH3ADJ		11
 
 struct grub_pe32_symbol
 {
-- 
2.35.1



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

* [PATCH v4 2/8] Add LoongArch definitions
  2022-07-01  9:50 [PATCH v4 0/8] Add support for LoongArch Xiaotian Wu
  2022-07-01  9:50 ` [PATCH v4 1/8] PE: Add LoongArch definitions Xiaotian Wu
@ 2022-07-01  9:50 ` Xiaotian Wu
  2022-07-01  9:50 ` [PATCH v4 3/8] LoongArch: Add setjmp implementation Xiaotian Wu
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Xiaotian Wu @ 2022-07-01  9:50 UTC (permalink / raw)
  To: grub-devel; +Cc: git, Xiaotian Wu, Zhou Yang

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
Signed-off-by: Zhou Yang <zhouyang@loongson.cn>
---
 include/grub/elf.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/include/grub/elf.h b/include/grub/elf.h
index c478933ee..1c8d4f5d5 100644
--- a/include/grub/elf.h
+++ b/include/grub/elf.h
@@ -248,6 +248,7 @@ typedef struct
 #define EM_NUM		95
 #define EM_AARCH64	183		/* ARM 64-bit architecture */
 #define EM_RISCV	243		/* RISC-V */
+#define EM_LOONGARCH	258		/* LoongArch */
 
 /* If it is necessary to assign new unofficial EM_* values, please
    pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the
@@ -2531,6 +2532,28 @@ typedef Elf32_Addr Elf32_Conflict;
 #define R_RISCV_SET32           56
 #define R_RISCV_32_PCREL        57
 
+/* LoongArch relocations */
+#define R_LARCH_NONE			      0
+#define R_LARCH_64			      2
+#define R_LARCH_MARK_LA			      20
+#define R_LARCH_SOP_PUSH_PCREL		      22
+#define R_LARCH_SOP_PUSH_ABSOLUTE	      23
+#define R_LARCH_SOP_PUSH_PLT_PCREL	      29
+#define R_LARCH_SOP_SUB			      32
+#define R_LARCH_SOP_SL			      33
+#define R_LARCH_SOP_SR			      34
+#define R_LARCH_SOP_ADD			      35
+#define R_LARCH_SOP_AND			      36
+#define R_LARCH_SOP_IF_ELSE		      37
+#define R_LARCH_SOP_POP_32_S_10_5	      38
+#define R_LARCH_SOP_POP_32_U_10_12	      39
+#define R_LARCH_SOP_POP_32_S_10_12	      40
+#define R_LARCH_SOP_POP_32_S_10_16	      41
+#define R_LARCH_SOP_POP_32_S_10_16_S2	      42
+#define R_LARCH_SOP_POP_32_S_5_20	      43
+#define R_LARCH_SOP_POP_32_S_0_5_10_16_S2     44
+#define R_LARCH_SOP_POP_32_S_0_10_10_16_S2    45
+
 #ifdef GRUB_TARGET_WORDSIZE
 #if GRUB_TARGET_WORDSIZE == 32
 
-- 
2.35.1



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

* [PATCH v4 3/8] LoongArch: Add setjmp implementation
  2022-07-01  9:50 [PATCH v4 0/8] Add support for LoongArch Xiaotian Wu
  2022-07-01  9:50 ` [PATCH v4 1/8] PE: Add LoongArch definitions Xiaotian Wu
  2022-07-01  9:50 ` [PATCH v4 2/8] " Xiaotian Wu
@ 2022-07-01  9:50 ` Xiaotian Wu
  2022-07-01  9:50 ` [PATCH v4 4/8] LoongArch: Add early startup code Xiaotian Wu
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Xiaotian Wu @ 2022-07-01  9:50 UTC (permalink / raw)
  To: grub-devel; +Cc: git, Xiaotian Wu, Zhou Yang, Sun Haiyong

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
Signed-off-by: Zhou Yang <zhouyang@loongson.cn>
Signed-off-by: Sun Haiyong <sunhaiyong@loongson.cn>
---
 grub-core/lib/loongarch64/setjmp.S | 69 ++++++++++++++++++++++++++++++
 grub-core/lib/setjmp.S             |  2 +
 include/grub/loongarch64/setjmp.h  | 27 ++++++++++++
 3 files changed, 98 insertions(+)
 create mode 100644 grub-core/lib/loongarch64/setjmp.S
 create mode 100644 include/grub/loongarch64/setjmp.h

diff --git a/grub-core/lib/loongarch64/setjmp.S b/grub-core/lib/loongarch64/setjmp.S
new file mode 100644
index 000000000..41d58f569
--- /dev/null
+++ b/grub-core/lib/loongarch64/setjmp.S
@@ -0,0 +1,69 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/dl.h>
+
+	.file	"setjmp.S"
+
+GRUB_MOD_LICENSE "GPLv3+"
+
+	.text
+
+/*
+ * int grub_setjmp (jmp_buf env)
+ */
+FUNCTION(grub_setjmp)
+	st.d $s0, $a0, 0x0
+	st.d $s1, $a0, 0x8
+	st.d $s2, $a0, 0x10
+	st.d $s3, $a0, 0x18
+	st.d $s4, $a0, 0x20
+	st.d $s5, $a0, 0x28
+	st.d $s6, $a0, 0x30
+	st.d $s7, $a0, 0x38
+	st.d $s8, $a0, 0x40
+	st.d $fp, $a0, 0x48
+	st.d $sp, $a0, 0x50
+	st.d $ra, $a0, 0x58
+
+	move $a0, $zero
+	jr   $ra
+
+/*
+ * void grub_longjmp (jmp_buf env, int val)
+ */
+FUNCTION(grub_longjmp)
+	ld.d $s0, $a0, 0x0
+	ld.d $s1, $a0, 0x8
+	ld.d $s2, $a0, 0x10
+	ld.d $s3, $a0, 0x18
+	ld.d $s4, $a0, 0x20
+	ld.d $s5, $a0, 0x28
+	ld.d $s6, $a0, 0x30
+	ld.d $s7, $a0, 0x38
+	ld.d $s8, $a0, 0x40
+	ld.d $fp, $a0, 0x48
+	ld.d $sp, $a0, 0x50
+	ld.d $ra, $a0, 0x58
+
+	/* Return 1 if passed 0, otherwise returns the value in place. */
+	li.w $a0, 1
+	beqz $a1, 1f
+	move $a0, $a1
+1:
+	jr   $ra
diff --git a/grub-core/lib/setjmp.S b/grub-core/lib/setjmp.S
index 9c8721088..cba1d546d 100644
--- a/grub-core/lib/setjmp.S
+++ b/grub-core/lib/setjmp.S
@@ -19,6 +19,8 @@
 #include "./arm/setjmp.S"
 #elif defined(__aarch64__)
 #include "./arm64/setjmp.S"
+#elif defined(__loongarch64)
+#include "./loongarch64/setjmp.S"
 #elif defined(__riscv)
 #include "./riscv/setjmp.S"
 #else
diff --git a/include/grub/loongarch64/setjmp.h b/include/grub/loongarch64/setjmp.h
new file mode 100644
index 000000000..cb3e17763
--- /dev/null
+++ b/include/grub/loongarch64/setjmp.h
@@ -0,0 +1,27 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SETJMP_CPU_HEADER
+#define GRUB_SETJMP_CPU_HEADER	1
+
+typedef grub_uint64_t grub_jmp_buf[12];
+
+int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE;
+void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn));
+
+#endif /* ! GRUB_SETJMP_CPU_HEADER */
-- 
2.35.1



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

* [PATCH v4 4/8] LoongArch: Add early startup code
  2022-07-01  9:50 [PATCH v4 0/8] Add support for LoongArch Xiaotian Wu
                   ` (2 preceding siblings ...)
  2022-07-01  9:50 ` [PATCH v4 3/8] LoongArch: Add setjmp implementation Xiaotian Wu
@ 2022-07-01  9:50 ` Xiaotian Wu
  2022-07-01  9:50 ` [PATCH v4 5/8] LoongArch: Add stubs for Linux loading commands Xiaotian Wu
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Xiaotian Wu @ 2022-07-01  9:50 UTC (permalink / raw)
  To: grub-devel; +Cc: git, Xiaotian Wu, Zhou Yang

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
Signed-off-by: Zhou Yang <zhouyang@loongson.cn>
---
 grub-core/kern/loongarch64/efi/startup.S | 34 ++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 grub-core/kern/loongarch64/efi/startup.S

diff --git a/grub-core/kern/loongarch64/efi/startup.S b/grub-core/kern/loongarch64/efi/startup.S
new file mode 100644
index 000000000..fc8123f8c
--- /dev/null
+++ b/grub-core/kern/loongarch64/efi/startup.S
@@ -0,0 +1,34 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/symbol.h>
+
+	.file 	"startup.S"
+	.text
+
+FUNCTION(_start)
+	/*
+	 *  EFI_SYSTEM_TABLE and EFI_HANDLE are passed in $a1/$a0.
+	 */
+
+	la 		$a2, EXT_C(grub_efi_image_handle)
+	st.d		$a0, $a2, 0
+	la		$a2, EXT_C(grub_efi_system_table)
+	st.d		$a1, $a2, 0
+
+	b		EXT_C(grub_main)
-- 
2.35.1



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

* [PATCH v4 5/8] LoongArch: Add stubs for Linux loading commands
  2022-07-01  9:50 [PATCH v4 0/8] Add support for LoongArch Xiaotian Wu
                   ` (3 preceding siblings ...)
  2022-07-01  9:50 ` [PATCH v4 4/8] LoongArch: Add early startup code Xiaotian Wu
@ 2022-07-01  9:50 ` Xiaotian Wu
  2022-07-01  9:50 ` [PATCH v4 6/8] LoongArch: Add awareness for LoongArch relocations Xiaotian Wu
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Xiaotian Wu @ 2022-07-01  9:50 UTC (permalink / raw)
  To: grub-devel; +Cc: git, Xiaotian Wu

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
---
 grub-core/loader/loongarch64/linux.c | 59 ++++++++++++++++++++++++++++
 include/grub/loongarch64/linux.h     | 31 +++++++++++++++
 2 files changed, 90 insertions(+)
 create mode 100644 grub-core/loader/loongarch64/linux.c
 create mode 100644 include/grub/loongarch64/linux.h

diff --git a/grub-core/loader/loongarch64/linux.c b/grub-core/loader/loongarch64/linux.c
new file mode 100644
index 000000000..d9d39a20c
--- /dev/null
+++ b/grub-core/loader/loongarch64/linux.c
@@ -0,0 +1,59 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/command.h>
+#include <grub/dl.h>
+#include <grub/lib/cmdline.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static grub_err_t
+grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
+		 int argc __attribute__ ((unused)),
+		 char *argv[] __attribute__ ((unused)))
+{
+  grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet"));
+
+  return grub_errno;
+}
+
+static grub_err_t
+grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
+		int argc __attribute__ ((unused)),
+		char *argv[] __attribute__ ((unused)))
+{
+  grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet"));
+
+  return grub_errno;
+}
+
+static grub_command_t cmd_linux, cmd_initrd;
+
+GRUB_MOD_INIT (linux)
+{
+  cmd_linux = grub_register_command ("linux", grub_cmd_linux,
+				     N_("FILE [ARGS...]"), N_("Load Linux."));
+  cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
+				      N_("FILE"), N_("Load initrd."));
+}
+
+GRUB_MOD_FINI (linux)
+{
+  grub_unregister_command (cmd_linux);
+  grub_unregister_command (cmd_initrd);
+}
diff --git a/include/grub/loongarch64/linux.h b/include/grub/loongarch64/linux.h
new file mode 100644
index 000000000..76fe693f4
--- /dev/null
+++ b/include/grub/loongarch64/linux.h
@@ -0,0 +1,31 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_LOONGARCH64_LINUX_HEADER
+#define GRUB_LOONGARCH64_LINUX_HEADER 1
+
+struct linux_loongarch64_kernel_header
+{
+  /*
+   * TODO
+   */
+};
+
+#define linux_arch_kernel_header linux_loongarch64_kernel_header
+
+#endif /* ! GRUB_LOONGARCH64_LINUX_HEADER */
-- 
2.35.1



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

* [PATCH v4 6/8] LoongArch: Add awareness for LoongArch relocations
  2022-07-01  9:50 [PATCH v4 0/8] Add support for LoongArch Xiaotian Wu
                   ` (4 preceding siblings ...)
  2022-07-01  9:50 ` [PATCH v4 5/8] LoongArch: Add stubs for Linux loading commands Xiaotian Wu
@ 2022-07-01  9:50 ` Xiaotian Wu
  2022-07-01  9:50 ` [PATCH v4 7/8] LoongArch: Add auxiliary files Xiaotian Wu
  2022-07-01  9:50 ` [PATCH v4 8/8] LoongArch: Add to build system Xiaotian Wu
  7 siblings, 0 replies; 9+ messages in thread
From: Xiaotian Wu @ 2022-07-01  9:50 UTC (permalink / raw)
  To: grub-devel; +Cc: git, Xiaotian Wu, Zhou Yang

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
Signed-off-by: Zhou Yang <zhouyang@loongson.cn>
---
 grub-core/kern/dl.c                    |   9 +-
 grub-core/kern/loongarch64/dl.c        | 102 +++++++++++++
 grub-core/kern/loongarch64/dl_helper.c | 198 +++++++++++++++++++++++++
 include/grub/dl.h                      |   1 +
 util/grub-mkimagexx.c                  |  79 ++++++++++
 util/grub-module-verifier.c            |  26 ++++
 6 files changed, 412 insertions(+), 3 deletions(-)
 create mode 100644 grub-core/kern/loongarch64/dl.c
 create mode 100644 grub-core/kern/loongarch64/dl_helper.c

diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
index b1d3a103e..41b5bba00 100644
--- a/grub-core/kern/dl.c
+++ b/grub-core/kern/dl.c
@@ -225,7 +225,8 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
   unsigned i;
   const Elf_Shdr *s;
   grub_size_t tsize = 0, talign = 1;
-#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv)
+#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) && \
+  !defined (__loongarch__)
   grub_size_t tramp;
   grub_size_t got;
   grub_err_t err;
@@ -241,7 +242,8 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
 	talign = s->sh_addralign;
     }
 
-#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv)
+#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) && \
+  !defined (__loongarch__)
   err = grub_arch_dl_get_tramp_got_size (e, &tramp, &got);
   if (err)
     return err;
@@ -304,7 +306,8 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
 	  mod->segment = seg;
 	}
     }
-#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv)
+#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) && \
+  !defined (__loongarch__)
   ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, GRUB_ARCH_DL_TRAMP_ALIGN);
   mod->tramp = ptr;
   mod->trampptr = ptr;
diff --git a/grub-core/kern/loongarch64/dl.c b/grub-core/kern/loongarch64/dl.c
new file mode 100644
index 000000000..3a6aa91cd
--- /dev/null
+++ b/grub-core/kern/loongarch64/dl.c
@@ -0,0 +1,102 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/dl.h>
+#include <grub/elf.h>
+#include <grub/misc.h>
+#include <grub/err.h>
+#include <grub/types.h>
+#include <grub/mm.h>
+#include <grub/i18n.h>
+#include <grub/cpu/reloc.h>
+
+/* Check if EHDR is a valid ELF header.  */
+grub_err_t
+grub_arch_dl_check_header (void *ehdr)
+{
+  Elf_Ehdr *e = ehdr;
+
+  /* Check the magic numbers.  */
+  if (e->e_ident[EI_CLASS] != ELFCLASS64
+      || e->e_ident[EI_DATA] != ELFDATA2LSB || e->e_machine != EM_LOONGARCH)
+    return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
+
+  return GRUB_ERR_NONE;
+}
+
+#pragma GCC diagnostic ignored "-Wcast-align"
+
+/*
+ * Unified function for both REL and RELA.
+ */
+grub_err_t
+grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
+			       Elf_Shdr *s, grub_dl_segment_t seg)
+{
+  Elf_Rel *rel, *max;
+  struct grub_loongarch64_stack stack;
+  grub_loongarch64_stack_init (&stack);
+
+  for (rel = (Elf_Rel *) ((char *) ehdr + s->sh_offset),
+	 max = (Elf_Rel *) ((char *) rel + s->sh_size);
+       rel < max;
+       rel = (Elf_Rel *) ((char *) rel + s->sh_entsize))
+    {
+      Elf_Sym *sym;
+      grub_uint64_t *place;
+      grub_uint64_t sym_addr;
+
+      if (rel->r_offset >= seg->size)
+	return grub_error (GRUB_ERR_BAD_MODULE,
+			   "reloc offset is outside the segment");
+
+      sym = (Elf_Sym *) ((char*)mod->symtab
+			 + mod->symsize * ELF_R_SYM (rel->r_info));
+
+      sym_addr = sym->st_value;
+      if (s->sh_type == SHT_RELA)
+	sym_addr += ((Elf_Rela *) rel)->r_addend;
+
+      place = (grub_uint64_t *) ((grub_addr_t)seg->addr + rel->r_offset);
+
+      switch (ELF_R_TYPE (rel->r_info))
+	{
+	case R_LARCH_64:
+	  *place = sym_addr;
+	  break;
+	case R_LARCH_MARK_LA:
+	  break;
+	case R_LARCH_SOP_PUSH_PCREL:
+	case R_LARCH_SOP_PUSH_PLT_PCREL:
+	  grub_loongarch64_sop_push (&stack, sym_addr - (grub_uint64_t)place);
+	  break;
+	GRUB_LOONGARCH64_RELOCATION (&stack, place, sym_addr)
+	default:
+	  {
+	    char rel_info[17]; /* log16(2^64) = 16, plus NUL.  */
+
+	    grub_snprintf (rel_info, sizeof (rel_info) - 1, "%" PRIxGRUB_UINT64_T,
+			   (grub_uint64_t) ELF_R_TYPE (rel->r_info));
+	    return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+			       N_("relocation 0x%s is not implemented yet"), rel_info);
+	  }
+	  break;
+	}
+    }
+  return GRUB_ERR_NONE;
+}
diff --git a/grub-core/kern/loongarch64/dl_helper.c b/grub-core/kern/loongarch64/dl_helper.c
new file mode 100644
index 000000000..becc89565
--- /dev/null
+++ b/grub-core/kern/loongarch64/dl_helper.c
@@ -0,0 +1,198 @@
+/* dl_helper.c - relocation helper functions for modules and grub-mkimage */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/dl.h>
+#include <grub/elf.h>
+#include <grub/misc.h>
+#include <grub/err.h>
+#include <grub/mm.h>
+#include <grub/i18n.h>
+#include <grub/cpu/reloc.h>
+
+static void grub_loongarch64_stack_push (grub_loongarch64_stack_t stack, grub_uint64_t x);
+static grub_uint64_t grub_loongarch64_stack_pop (grub_loongarch64_stack_t stack);
+
+void
+grub_loongarch64_stack_init (grub_loongarch64_stack_t stack)
+{
+  stack->top = -1;
+  stack->count = LOONGARCH64_STACK_MAX;
+}
+
+static void
+grub_loongarch64_stack_push (grub_loongarch64_stack_t stack, grub_uint64_t x)
+{
+  if (stack->top == stack->count)
+    return;
+  stack->data[++stack->top] = x;
+}
+
+static grub_uint64_t
+grub_loongarch64_stack_pop (grub_loongarch64_stack_t stack)
+{
+  if (stack->top == -1)
+    return -1;
+  return stack->data[stack->top--];
+}
+
+void
+grub_loongarch64_sop_push (grub_loongarch64_stack_t stack, grub_int64_t offset)
+{
+  grub_loongarch64_stack_push (stack, offset);
+}
+
+/* opr2 = pop (), opr1 = pop (), push (opr1 - opr2) */
+void
+grub_loongarch64_sop_sub (grub_loongarch64_stack_t stack)
+{
+  grub_uint64_t a, b;
+  b = grub_loongarch64_stack_pop (stack);
+  a = grub_loongarch64_stack_pop (stack);
+  grub_loongarch64_stack_push (stack, a - b);
+}
+
+/* opr2 = pop (), opr1 = pop (), push (opr1 << opr2) */
+void
+grub_loongarch64_sop_sl (grub_loongarch64_stack_t stack)
+{
+  grub_uint64_t a, b;
+  b = grub_loongarch64_stack_pop (stack);
+  a = grub_loongarch64_stack_pop (stack);
+  grub_loongarch64_stack_push (stack, a << b);
+}
+
+/* opr2 = pop (), opr1 = pop (), push (opr1 >> opr2) */
+void
+grub_loongarch64_sop_sr (grub_loongarch64_stack_t stack)
+{
+  grub_uint64_t a, b;
+  b = grub_loongarch64_stack_pop (stack);
+  a = grub_loongarch64_stack_pop (stack);
+  grub_loongarch64_stack_push (stack, a >> b);
+}
+
+/* opr2 = pop (), opr1 = pop (), push (opr1 + opr2) */
+void
+grub_loongarch64_sop_add (grub_loongarch64_stack_t stack)
+{
+  grub_uint64_t a, b;
+  b = grub_loongarch64_stack_pop (stack);
+  a = grub_loongarch64_stack_pop (stack);
+  grub_loongarch64_stack_push (stack, a + b);
+}
+
+/* opr2 = pop (), opr1 = pop (), push (opr1 & opr2) */
+void
+grub_loongarch64_sop_and (grub_loongarch64_stack_t stack)
+{
+  grub_uint64_t a, b;
+  b = grub_loongarch64_stack_pop (stack);
+  a = grub_loongarch64_stack_pop (stack);
+  grub_loongarch64_stack_push (stack, a & b);
+}
+
+/* opr3 = pop (), opr2 = pop (), opr1 = pop (), push (opr1 ? opr2 : opr3) */
+void
+grub_loongarch64_sop_if_else (grub_loongarch64_stack_t stack)
+{
+  grub_uint64_t a, b, c;
+  c = grub_loongarch64_stack_pop (stack);
+  b = grub_loongarch64_stack_pop (stack);
+  a = grub_loongarch64_stack_pop (stack);
+
+  if (a) {
+      grub_loongarch64_stack_push (stack, b);
+  } else {
+      grub_loongarch64_stack_push (stack, c);
+  }
+}
+
+/* opr1 = pop (), (*(uint32_t *) PC) [14 ... 10] = opr1 [4 ... 0] */
+void
+grub_loongarch64_sop_32_s_10_5 (grub_loongarch64_stack_t stack,
+				grub_uint64_t *place)
+{
+  grub_uint64_t a = grub_loongarch64_stack_pop (stack);
+  *place |= ((a & 0x1f) << 10);
+}
+
+/* opr1 = pop (), (*(uint32_t *) PC) [21 ... 10] = opr1 [11 ... 0] */
+void
+grub_loongarch64_sop_32_u_10_12 (grub_loongarch64_stack_t stack,
+				 grub_uint64_t *place)
+{
+  grub_uint64_t a = grub_loongarch64_stack_pop (stack);
+  *place = *place | ((a & 0xfff) << 10);
+}
+
+/* opr1 = pop (), (*(uint32_t *) PC) [21 ... 10] = opr1 [11 ... 0] */
+void
+grub_loongarch64_sop_32_s_10_12 (grub_loongarch64_stack_t stack,
+				 grub_uint64_t *place)
+{
+  grub_uint64_t a = grub_loongarch64_stack_pop (stack);
+  *place = (*place) | ((a & 0xfff) << 10);
+}
+
+/* opr1 = pop (), (*(uint32_t *) PC) [25 ... 10] = opr1 [15 ... 0] */
+void
+grub_loongarch64_sop_32_s_10_16 (grub_loongarch64_stack_t stack,
+				 grub_uint64_t *place)
+{
+  grub_uint64_t a = grub_loongarch64_stack_pop (stack);
+  *place = (*place) | ((a & 0xffff) << 10);
+}
+
+/* opr1 = pop (), (*(uint32_t *) PC) [25 ... 10] = opr1 [17 ... 2] */
+void
+grub_loongarch64_sop_32_s_10_16_s2 (grub_loongarch64_stack_t stack,
+				    grub_uint64_t *place)
+{
+  grub_uint64_t a = grub_loongarch64_stack_pop (stack);
+  *place = (*place) | (((a >> 2) & 0xffff) << 10);
+}
+
+/* opr1 = pop (), (*(uint32_t *) PC) [24 ... 5] = opr1 [19 ... 0] */
+void
+grub_loongarch64_sop_32_s_5_20 (grub_loongarch64_stack_t stack, grub_uint64_t *place)
+{
+  grub_uint64_t a = grub_loongarch64_stack_pop (stack);
+  *place = (*place) | ((a & 0xfffff)<<5);
+}
+
+/* opr1 = pop (), (*(uint32_t *) PC) [4 ... 0] = opr1 [22 ... 18] */
+void
+grub_loongarch64_sop_32_s_0_5_10_16_s2 (grub_loongarch64_stack_t stack,
+					grub_uint64_t *place)
+{
+  grub_uint64_t a = grub_loongarch64_stack_pop (stack);
+
+  *place =(*place) | (((a >> 2) & 0xffff) << 10);
+  *place =(*place) | ((a >> 18) & 0x1f);
+}
+
+/* opr1 = pop (), (*(uint32_t *) PC) [9 ... 0] = opr1 [27 ... 18] */
+void
+grub_loongarch64_sop_32_s_0_10_10_16_s2 (grub_loongarch64_stack_t stack,
+					 grub_uint64_t *place)
+{
+  grub_uint64_t a = grub_loongarch64_stack_pop (stack);
+  *place =(*place) | (((a >> 2) & 0xffff) << 10);
+  *place =(*place) | ((a >> 18) & 0x3ff);
+}
diff --git a/include/grub/dl.h b/include/grub/dl.h
index d0f4115fe..63c5fb66f 100644
--- a/include/grub/dl.h
+++ b/include/grub/dl.h
@@ -301,6 +301,7 @@ grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
 #endif
 
 #if defined (__aarch64__) || defined (__sparc__) || \
+    defined (__loongarch64) || \
     (defined(__riscv) && (__riscv_xlen == 64))
 #define GRUB_ARCH_DL_TRAMP_ALIGN 8
 #define GRUB_ARCH_DL_GOT_ALIGN 8
diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
index a1927e786..358b9ab47 100644
--- a/util/grub-mkimagexx.c
+++ b/util/grub-mkimagexx.c
@@ -44,6 +44,7 @@
 #include <grub/arm/reloc.h>
 #include <grub/arm64/reloc.h>
 #include <grub/ia64/reloc.h>
+#include <grub/loongarch64/reloc.h>
 #include <grub/osdep/hostfile.h>
 #include <grub/util/install.h>
 #include <grub/util/mkimage.h>
@@ -784,6 +785,8 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd,
   struct grub_ia64_trampoline *tr = (void *) (pe_target + tramp_off);
   grub_uint64_t *gpptr = (void *) (pe_target + got_off);
   unsigned unmatched_adr_got_page = 0;
+  struct grub_loongarch64_stack stack;
+  grub_loongarch64_stack_init (&stack);
 #define MASK19 ((1 << 19) - 1)
 #else
   grub_uint32_t *tr = (void *) (pe_target + tramp_off);
@@ -1123,6 +1126,31 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd,
 		   }
 	       break;
 	       }
+	     case EM_LOONGARCH:
+	       {
+		 sym_addr += addend;
+		 switch (ELF_R_TYPE (info))
+		   {
+		   case R_LARCH_64:
+		     *target = grub_host_to_target64 (grub_target_to_host64 (*target) + sym_addr);
+		     break;
+		   case R_LARCH_MARK_LA:
+		     break;
+		   case R_LARCH_SOP_PUSH_PCREL:
+		   case R_LARCH_SOP_PUSH_PLT_PCREL:
+		     grub_loongarch64_sop_push (&stack, sym_addr
+						-(target_section_addr
+						  +offset
+						  +image_target->vaddr_offset));
+		     break;
+		   GRUB_LOONGARCH64_RELOCATION (&stack, target, sym_addr)
+		   default:
+		     grub_util_error (_("relocation 0x%x is not implemented yet"),
+				      (unsigned int) ELF_R_TYPE (info));
+		     break;
+		   }
+		 break;
+	       }
 #endif
 #if defined(MKIMAGE_ELF32)
 	     case EM_ARM:
@@ -1667,6 +1695,57 @@ translate_relocation_pe (struct translate_context *ctx,
 			   (unsigned int) ELF_R_TYPE (info));
 	  break;
 	}
+#endif /* defined(MKIMAGE_ELF64) */
+      break;
+    case EM_LOONGARCH:
+#if defined(MKIMAGE_ELF64)
+      switch (ELF_R_TYPE (info))
+	{
+	case R_LARCH_64:
+	  {
+	    ctx->current_address = add_fixup_entry (&ctx->lst,
+						    GRUB_PE32_REL_BASED_DIR64,
+						    addr, 0, ctx->current_address,
+						    image_target);
+	  }
+	  break;
+	case R_LARCH_MARK_LA:
+	  {
+	    ctx->current_address = add_fixup_entry (&ctx->lst,
+						    GRUB_PE32_REL_BASED_LOONGARCH64_MARK_LA,
+						    addr, 0, ctx->current_address,
+						    image_target);
+	  }
+	  break;
+	  /* Relative relocations do not require fixup entries. */
+	case R_LARCH_NONE:
+	case R_LARCH_SOP_PUSH_PCREL:
+	case R_LARCH_SOP_PUSH_ABSOLUTE:
+	case R_LARCH_SOP_PUSH_PLT_PCREL:
+	case R_LARCH_SOP_SUB:
+	case R_LARCH_SOP_SL:
+	case R_LARCH_SOP_SR:
+	case R_LARCH_SOP_ADD:
+	case R_LARCH_SOP_AND:
+	case R_LARCH_SOP_IF_ELSE:
+	case R_LARCH_SOP_POP_32_S_10_5:
+	case R_LARCH_SOP_POP_32_U_10_12:
+	case R_LARCH_SOP_POP_32_S_10_12:
+	case R_LARCH_SOP_POP_32_S_10_16:
+	case R_LARCH_SOP_POP_32_S_10_16_S2:
+	case R_LARCH_SOP_POP_32_S_5_20:
+	case R_LARCH_SOP_POP_32_S_0_5_10_16_S2:
+	case R_LARCH_SOP_POP_32_S_0_10_10_16_S2:
+	  grub_util_info ("  %s:  not adding fixup: 0x%08x : 0x%08x",
+			  __FUNCTION__,
+			  (unsigned int) addr,
+			  (unsigned int) ctx->current_address);
+	  break;
+	default:
+	  grub_util_error (_("relocation 0x%x is not implemented yet"),
+			   (unsigned int) ELF_R_TYPE (info));
+	  break;
+	}
 #endif /* defined(MKIMAGE_ELF64) */
       break;
 #if defined(MKIMAGE_ELF32)
diff --git a/util/grub-module-verifier.c b/util/grub-module-verifier.c
index 163529ca9..b510461fa 100644
--- a/util/grub-module-verifier.c
+++ b/util/grub-module-verifier.c
@@ -119,6 +119,32 @@ struct grub_module_verifier_arch archs[] = {
       R_AARCH64_PREL32,
       -1
     } },
+  { "loongarch64", 8, 0, EM_LOONGARCH, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
+      R_LARCH_NONE,
+      R_LARCH_64,
+      R_LARCH_MARK_LA,
+      R_LARCH_SOP_PUSH_PCREL,
+      R_LARCH_SOP_PUSH_ABSOLUTE,
+      R_LARCH_SOP_PUSH_PLT_PCREL,
+      R_LARCH_SOP_SUB,
+      R_LARCH_SOP_SL,
+      R_LARCH_SOP_SR,
+      R_LARCH_SOP_ADD,
+      R_LARCH_SOP_AND,
+      R_LARCH_SOP_IF_ELSE,
+      R_LARCH_SOP_POP_32_S_10_5,
+      R_LARCH_SOP_POP_32_U_10_12,
+      R_LARCH_SOP_POP_32_S_10_12,
+      R_LARCH_SOP_POP_32_S_10_16,
+      R_LARCH_SOP_POP_32_S_10_16_S2,
+      R_LARCH_SOP_POP_32_S_5_20,
+      R_LARCH_SOP_POP_32_S_0_5_10_16_S2,
+      R_LARCH_SOP_POP_32_S_0_10_10_16_S2,
+      -1
+    }, (int[]){
+      -1
+    }
+  },
   { "riscv32", 4, 0, EM_RISCV, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
       R_RISCV_32,
       R_RISCV_64,
-- 
2.35.1



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

* [PATCH v4 7/8] LoongArch: Add auxiliary files
  2022-07-01  9:50 [PATCH v4 0/8] Add support for LoongArch Xiaotian Wu
                   ` (5 preceding siblings ...)
  2022-07-01  9:50 ` [PATCH v4 6/8] LoongArch: Add awareness for LoongArch relocations Xiaotian Wu
@ 2022-07-01  9:50 ` Xiaotian Wu
  2022-07-01  9:50 ` [PATCH v4 8/8] LoongArch: Add to build system Xiaotian Wu
  7 siblings, 0 replies; 9+ messages in thread
From: Xiaotian Wu @ 2022-07-01  9:50 UTC (permalink / raw)
  To: grub-devel; +Cc: git, Xiaotian Wu, Zhou Yang

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
Signed-off-by: Zhou Yang <zhouyang@loongson.cn>
---
 grub-core/kern/efi/mm.c                  |   3 +-
 grub-core/kern/loongarch64/cache.c       |  39 +++++++++
 grub-core/kern/loongarch64/cache_flush.S |  33 +++++++
 grub-core/kern/loongarch64/efi/init.c    |  77 ++++++++++++++++
 grub-core/lib/efi/halt.c                 |   2 +-
 include/grub/efi/efi.h                   |   2 +-
 include/grub/loongarch64/efi/memory.h    |  24 +++++
 include/grub/loongarch64/reloc.h         | 107 +++++++++++++++++++++++
 include/grub/loongarch64/time.h          |  28 ++++++
 include/grub/loongarch64/types.h         |  34 +++++++
 10 files changed, 346 insertions(+), 3 deletions(-)
 create mode 100644 grub-core/kern/loongarch64/cache.c
 create mode 100644 grub-core/kern/loongarch64/cache_flush.S
 create mode 100644 grub-core/kern/loongarch64/efi/init.c
 create mode 100644 include/grub/loongarch64/efi/memory.h
 create mode 100644 include/grub/loongarch64/reloc.h
 create mode 100644 include/grub/loongarch64/time.h
 create mode 100644 include/grub/loongarch64/types.h

diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
index d8e411454..1dce99882 100644
--- a/grub-core/kern/efi/mm.c
+++ b/grub-core/kern/efi/mm.c
@@ -659,7 +659,8 @@ grub_efi_mm_init (void)
 		       2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
 }
 
-#if defined (__aarch64__) || defined (__arm__) || defined (__riscv)
+#if defined (__aarch64__) || defined (__arm__) || defined (__riscv) || \
+  defined (__loongarch__)
 grub_err_t
 grub_efi_get_ram_base(grub_addr_t *base_addr)
 {
diff --git a/grub-core/kern/loongarch64/cache.c b/grub-core/kern/loongarch64/cache.c
new file mode 100644
index 000000000..43d314df9
--- /dev/null
+++ b/grub-core/kern/loongarch64/cache.c
@@ -0,0 +1,39 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/cache.h>
+#include <grub/misc.h>
+
+/* Prototypes for asm functions. */
+void grub_arch_clean_dcache_range (void);
+void grub_arch_invalidate_icache_range (void);
+
+void
+grub_arch_sync_caches (void *address __attribute__((unused)),
+		       grub_size_t len __attribute__((unused)))
+{
+  grub_arch_clean_dcache_range ();
+  grub_arch_invalidate_icache_range ();
+}
+
+void
+grub_arch_sync_dma_caches (volatile void *address __attribute__((unused)),
+			   grub_size_t len __attribute__((unused)))
+{
+  /* DMA non-coherent devices not supported yet */
+}
diff --git a/grub-core/kern/loongarch64/cache_flush.S b/grub-core/kern/loongarch64/cache_flush.S
new file mode 100644
index 000000000..43b97d822
--- /dev/null
+++ b/grub-core/kern/loongarch64/cache_flush.S
@@ -0,0 +1,33 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/symbol.h>
+
+	.file	"cache_flush.S"
+	.text
+/*
+ * No further work to do because cache consistency is maintained by hardware on
+ * LoongArch.
+ */
+FUNCTION(grub_arch_clean_dcache_range)
+	dbar 0
+	jr $ra
+
+FUNCTION(grub_arch_invalidate_icache_range)
+	ibar 0
+	jr $ra
diff --git a/grub-core/kern/loongarch64/efi/init.c b/grub-core/kern/loongarch64/efi/init.c
new file mode 100644
index 000000000..8cbeafaba
--- /dev/null
+++ b/grub-core/kern/loongarch64/efi/init.c
@@ -0,0 +1,77 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/env.h>
+#include <grub/kernel.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/time.h>
+#include <grub/efi/efi.h>
+#include <grub/loader.h>
+
+#define EFI_TIMER_PERIOD_MILLISECONDS(ms) ((grub_uint64_t)(ms * 10000))
+
+static grub_uint64_t tmr;
+static grub_efi_event_t tmr_evt;
+
+static grub_uint64_t
+grub_efi_get_time_ms (void)
+{
+  return tmr;
+}
+
+static void
+grub_loongson_increment_timer (grub_efi_event_t event __attribute__ ((unused)),
+			       void *context __attribute__ ((unused)))
+{
+  tmr += 10;
+}
+
+void
+grub_machine_init (void)
+{
+  grub_efi_boot_services_t *b;
+
+  grub_efi_init ();
+
+  b = grub_efi_system_table->boot_services;
+  efi_call_5 (b->create_event, GRUB_EFI_EVT_TIMER | GRUB_EFI_EVT_NOTIFY_SIGNAL,
+	      GRUB_EFI_TPL_CALLBACK, grub_loongson_increment_timer, NULL, &tmr_evt);
+  efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_PERIODIC, EFI_TIMER_PERIOD_MILLISECONDS(10));
+
+  grub_install_get_time_ms (grub_efi_get_time_ms);
+}
+
+void
+grub_machine_fini (int flags)
+{
+  grub_efi_boot_services_t *b;
+
+  if (!(flags & GRUB_LOADER_FLAG_NORETURN))
+    return;
+
+  b = grub_efi_system_table->boot_services;
+
+  efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_CANCEL, 0);
+  efi_call_1 (b->close_event, tmr_evt);
+
+  grub_efi_fini ();
+
+  if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY))
+    grub_efi_memory_fini ();
+}
diff --git a/grub-core/lib/efi/halt.c b/grub-core/lib/efi/halt.c
index 29d413641..e6356894a 100644
--- a/grub-core/lib/efi/halt.c
+++ b/grub-core/lib/efi/halt.c
@@ -31,7 +31,7 @@ grub_halt (void)
   grub_machine_fini (GRUB_LOADER_FLAG_NORETURN |
 		     GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY);
 #if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__) && \
-    !defined(__riscv)
+    !defined(__loongarch__) && !defined(__riscv)
   grub_acpi_halt ();
 #endif
   efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
index eb2dfdfce..6f1a6254e 100644
--- a/include/grub/efi/efi.h
+++ b/include/grub/efi/efi.h
@@ -98,7 +98,7 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd,
 						char **device,
 						char **path);
 
-#if defined(__arm__) || defined(__aarch64__) || defined(__riscv)
+#if defined(__arm__) || defined(__aarch64__) || defined(__riscv) || defined(__loongarch__)
 void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);
 grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);
 #include <grub/cpu/linux.h>
diff --git a/include/grub/loongarch64/efi/memory.h b/include/grub/loongarch64/efi/memory.h
new file mode 100644
index 000000000..ca8dbfea5
--- /dev/null
+++ b/include/grub/loongarch64/efi/memory.h
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MEMORY_CPU_HEADER
+#include <grub/efi/memory.h>
+
+#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL
+
+#endif /* ! GRUB_MEMORY_CPU_HEADER */
diff --git a/include/grub/loongarch64/reloc.h b/include/grub/loongarch64/reloc.h
new file mode 100644
index 000000000..3f6b0792a
--- /dev/null
+++ b/include/grub/loongarch64/reloc.h
@@ -0,0 +1,107 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_LOONGARCH64_RELOC_H
+#define GRUB_LOONGARCH64_RELOC_H 1
+#include <grub/types.h>
+
+#define LOONGARCH64_STACK_MAX 16
+
+struct grub_loongarch64_stack
+{
+  grub_uint64_t data[LOONGARCH64_STACK_MAX];
+  int count;
+  int top;
+};
+
+typedef struct grub_loongarch64_stack* grub_loongarch64_stack_t;
+
+void grub_loongarch64_stack_init	     (grub_loongarch64_stack_t stack);
+void grub_loongarch64_sop_push		     (grub_loongarch64_stack_t stack,
+					      grub_int64_t offset);
+void grub_loongarch64_sop_sub		     (grub_loongarch64_stack_t stack);
+void grub_loongarch64_sop_sl		     (grub_loongarch64_stack_t stack);
+void grub_loongarch64_sop_sr		     (grub_loongarch64_stack_t stack);
+void grub_loongarch64_sop_add		     (grub_loongarch64_stack_t stack);
+void grub_loongarch64_sop_and		     (grub_loongarch64_stack_t stack);
+void grub_loongarch64_sop_if_else	     (grub_loongarch64_stack_t stack);
+void grub_loongarch64_sop_32_s_10_5	     (grub_loongarch64_stack_t stack,
+					      grub_uint64_t *place);
+void grub_loongarch64_sop_32_u_10_12	     (grub_loongarch64_stack_t stack,
+					      grub_uint64_t *place);
+void grub_loongarch64_sop_32_s_10_12	     (grub_loongarch64_stack_t stack,
+					      grub_uint64_t *place);
+void grub_loongarch64_sop_32_s_10_16	     (grub_loongarch64_stack_t stack,
+					      grub_uint64_t *place);
+void grub_loongarch64_sop_32_s_10_16_s2	     (grub_loongarch64_stack_t stack,
+					      grub_uint64_t *place);
+void grub_loongarch64_sop_32_s_5_20	     (grub_loongarch64_stack_t stack,
+					      grub_uint64_t *place);
+void grub_loongarch64_sop_32_s_0_5_10_16_s2  (grub_loongarch64_stack_t stack,
+					      grub_uint64_t *place);
+void grub_loongarch64_sop_32_s_0_10_10_16_s2 (grub_loongarch64_stack_t stack,
+					      grub_uint64_t *place);
+
+#define GRUB_LOONGARCH64_RELOCATION(STACK, PLACE, OFFSET)	\
+  case R_LARCH_SOP_PUSH_ABSOLUTE:				\
+    grub_loongarch64_sop_push (STACK, OFFSET);			\
+    break;							\
+  case R_LARCH_SOP_SUB:						\
+    grub_loongarch64_sop_sub (STACK);				\
+    break;							\
+  case R_LARCH_SOP_SL:		      				\
+    grub_loongarch64_sop_sl (STACK);				\
+    break;			      				\
+  case R_LARCH_SOP_SR:		      				\
+    grub_loongarch64_sop_sr (STACK);				\
+    break;					    		\
+  case R_LARCH_SOP_ADD:		      		    		\
+    grub_loongarch64_sop_add (STACK); 		    		\
+    break;			      		    		\
+  case R_LARCH_SOP_AND:		      		    		\
+    grub_loongarch64_sop_and (STACK);		    		\
+    break;					    		\
+  case R_LARCH_SOP_IF_ELSE:			    		\
+    grub_loongarch64_sop_if_else (STACK);	    		\
+    break;					    		\
+  case R_LARCH_SOP_POP_32_S_10_5:		    		\
+    grub_loongarch64_sop_32_s_10_5 (STACK, PLACE);  		\
+    break;					    		\
+  case R_LARCH_SOP_POP_32_U_10_12:		    		\
+    grub_loongarch64_sop_32_u_10_12 (STACK, PLACE);		\
+    break;							\
+  case R_LARCH_SOP_POP_32_S_10_12:				\
+    grub_loongarch64_sop_32_s_10_12 (STACK, PLACE);		\
+    break;							\
+  case R_LARCH_SOP_POP_32_S_10_16:				\
+    grub_loongarch64_sop_32_s_10_16 (STACK, PLACE);		\
+    break;							\
+  case R_LARCH_SOP_POP_32_S_10_16_S2:				\
+    grub_loongarch64_sop_32_s_10_16_s2 (STACK, PLACE);		\
+    break;							\
+  case R_LARCH_SOP_POP_32_S_5_20:				\
+    grub_loongarch64_sop_32_s_5_20 (STACK, PLACE);		\
+    break;							\
+  case R_LARCH_SOP_POP_32_S_0_5_10_16_S2:			\
+    grub_loongarch64_sop_32_s_0_5_10_16_s2 (STACK, PLACE);	\
+    break;							\
+  case R_LARCH_SOP_POP_32_S_0_10_10_16_S2:			\
+    grub_loongarch64_sop_32_s_0_10_10_16_s2 (STACK, PLACE);	\
+    break;
+
+#endif /* GRUB_LOONGARCH64_RELOC_H */
diff --git a/include/grub/loongarch64/time.h b/include/grub/loongarch64/time.h
new file mode 100644
index 000000000..e5724bd83
--- /dev/null
+++ b/include/grub/loongarch64/time.h
@@ -0,0 +1,28 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_TIME_HEADER
+#define KERNEL_CPU_TIME_HEADER	1
+
+static inline void
+grub_cpu_idle(void)
+{
+  __asm__ __volatile__("idle 0");
+}
+
+#endif
diff --git a/include/grub/loongarch64/types.h b/include/grub/loongarch64/types.h
new file mode 100644
index 000000000..a9e09171a
--- /dev/null
+++ b/include/grub/loongarch64/types.h
@@ -0,0 +1,34 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2022 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TYPES_CPU_HEADER
+#define GRUB_TYPES_CPU_HEADER	1
+
+/* The size of void *.  */
+#define GRUB_TARGET_SIZEOF_VOID_P	8
+
+/* The size of long.  */
+#define GRUB_TARGET_SIZEOF_LONG		8
+
+/* LoongArch is little-endian.  */
+#undef GRUB_TARGET_WORDS_BIGENDIAN
+
+/* Unaligned accesses are only supported if MMU is enabled.  */
+#undef GRUB_HAVE_UNALIGNED_ACCESS
+
+#endif /* ! GRUB_TYPES_CPU_HEADER */
-- 
2.35.1



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

* [PATCH v4 8/8] LoongArch: Add to build system
  2022-07-01  9:50 [PATCH v4 0/8] Add support for LoongArch Xiaotian Wu
                   ` (6 preceding siblings ...)
  2022-07-01  9:50 ` [PATCH v4 7/8] LoongArch: Add auxiliary files Xiaotian Wu
@ 2022-07-01  9:50 ` Xiaotian Wu
  7 siblings, 0 replies; 9+ messages in thread
From: Xiaotian Wu @ 2022-07-01  9:50 UTC (permalink / raw)
  To: grub-devel; +Cc: git, Xiaotian Wu, Zhou Yang

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
Signed-off-by: Zhou Yang <zhouyang@loongson.cn>
---
 Makefile.util.def           |  1 +
 conf/Makefile.common        |  3 +++
 configure.ac                |  5 ++++
 gentpl.py                   | 25 ++++++++++---------
 grub-core/Makefile.am       |  6 +++++
 grub-core/Makefile.core.def | 15 ++++++++++++
 include/grub/efi/api.h      |  2 +-
 include/grub/util/install.h |  1 +
 util/grub-install-common.c  | 49 +++++++++++++++++++------------------
 util/grub-install.c         | 16 ++++++++++++
 util/grub-mknetdir.c        |  1 +
 util/grub-mkrescue.c        |  8 ++++++
 util/mkimage.c              | 16 ++++++++++++
 13 files changed, 111 insertions(+), 37 deletions(-)

diff --git a/Makefile.util.def b/Makefile.util.def
index d919c562c..765c6fea2 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -163,6 +163,7 @@ library = {
   common = grub-core/kern/ia64/dl_helper.c;
   common = grub-core/kern/arm/dl_helper.c;
   common = grub-core/kern/arm64/dl_helper.c;
+  common = grub-core/kern/loongarch64/dl_helper.c;
   common = grub-core/lib/minilzo/minilzo.c;
   common = grub-core/lib/xzembed/xz_dec_bcj.c;
   common = grub-core/lib/xzembed/xz_dec_lzma2.c;
diff --git a/conf/Makefile.common b/conf/Makefile.common
index 2d8f1bf2e..fad6d5ae0 100644
--- a/conf/Makefile.common
+++ b/conf/Makefile.common
@@ -17,6 +17,9 @@ endif
 if COND_arm64
   CFLAGS_PLATFORM += -mcmodel=large
 endif
+if COND_loongarch64
+  CPPFLAGS_PLATFORM = -Wa,-mla-global-with-abs -mcmodel=large
+endif
 if COND_powerpc_ieee1275
   CFLAGS_PLATFORM += -mcpu=powerpc
 endif
diff --git a/configure.ac b/configure.ac
index 57fb70945..c2340c8fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -115,6 +115,7 @@ case "$target_cpu" in
 		;;
   arm*)		target_cpu=arm ;;
   aarch64*)	target_cpu=arm64 ;;
+  loongarch64)	target_cpu=loongarch64 ;;
   riscv32*)	target_cpu=riscv32 ;;
   riscv64*)	target_cpu=riscv64 ;;
 esac
@@ -140,6 +141,7 @@ if test "x$with_platform" = x; then
     ia64-*) platform=efi ;;
     arm-*) platform=uboot ;;
     arm64-*) platform=efi ;;
+    loongarch64-*) platform=efi;;
     riscv32-*) platform=efi ;;
     riscv64-*) platform=efi ;;
     *)
@@ -190,6 +192,7 @@ case "$target_cpu"-"$platform" in
   arm-coreboot) ;;
   arm-efi) ;;
   arm64-efi) ;;
+  loongarch64-efi) ;;
   riscv32-efi) ;;
   riscv64-efi) ;;
   *-emu) ;;
@@ -1987,6 +1990,8 @@ AM_CONDITIONAL([COND_i386_coreboot], [test x$target_cpu = xi386 -a x$platform =
 AM_CONDITIONAL([COND_i386_multiboot], [test x$target_cpu = xi386 -a x$platform = xmultiboot])
 AM_CONDITIONAL([COND_i386_xen], [test x$target_cpu = xi386 -a x$platform = xxen])
 AM_CONDITIONAL([COND_i386_xen_pvh], [test x$target_cpu = xi386 -a x$platform = xxen_pvh])
+AM_CONDITIONAL([COND_loongarch64], [test x$target_cpu = xloongarch64])
+AM_CONDITIONAL([COND_loongarch64_efi], [test x$target_cpu = xloongarch64 -a x$platform = xefi])
 AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = xmipsel])
 AM_CONDITIONAL([COND_mips_arc], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")"  -a x$platform = xarc])
 AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmipsel -a x$platform = xloongson])
diff --git a/gentpl.py b/gentpl.py
index 9f51e4fb6..fa53e17e8 100644
--- a/gentpl.py
+++ b/gentpl.py
@@ -32,27 +32,28 @@ GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
                    "mips_loongson", "sparc64_ieee1275",
                    "powerpc_ieee1275", "mips_arc", "ia64_efi",
                    "mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi",
-                   "arm_coreboot", "riscv32_efi", "riscv64_efi" ]
+                   "arm_coreboot", "loongarch64_efi", "riscv32_efi", "riscv64_efi" ]
 
 GROUPS = {}
 
 GROUPS["common"]   = GRUB_PLATFORMS[:]
 
 # Groups based on CPU
-GROUPS["i386"]     = [ "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275" ]
-GROUPS["x86_64"]   = [ "x86_64_efi" ]
-GROUPS["x86"]      = GROUPS["i386"] + GROUPS["x86_64"]
-GROUPS["mips"]     = [ "mips_loongson", "mips_qemu_mips", "mips_arc" ]
-GROUPS["sparc64"]  = [ "sparc64_ieee1275" ]
-GROUPS["powerpc"]  = [ "powerpc_ieee1275" ]
-GROUPS["arm"]      = [ "arm_uboot", "arm_efi", "arm_coreboot" ]
-GROUPS["arm64"]    = [ "arm64_efi" ]
-GROUPS["riscv32"]  = [ "riscv32_efi" ]
-GROUPS["riscv64"]  = [ "riscv64_efi" ]
+GROUPS["i386"]        = [ "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275" ]
+GROUPS["x86_64"]      = [ "x86_64_efi" ]
+GROUPS["x86"]         = GROUPS["i386"] + GROUPS["x86_64"]
+GROUPS["mips"]        = [ "mips_loongson", "mips_qemu_mips", "mips_arc" ]
+GROUPS["sparc64"]     = [ "sparc64_ieee1275" ]
+GROUPS["powerpc"]     = [ "powerpc_ieee1275" ]
+GROUPS["arm"]         = [ "arm_uboot", "arm_efi", "arm_coreboot" ]
+GROUPS["arm64"]       = [ "arm64_efi" ]
+GROUPS["loongarch64"] = [ "loongarch64_efi" ]
+GROUPS["riscv32"]     = [ "riscv32_efi" ]
+GROUPS["riscv64"]     = [ "riscv64_efi" ]
 
 # Groups based on firmware
 GROUPS["efi"]  = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi",
-		   "riscv32_efi", "riscv64_efi" ]
+		   "loongarch64_efi", "riscv32_efi", "riscv64_efi" ]
 GROUPS["ieee1275"]   = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ]
 GROUPS["uboot"] = [ "arm_uboot" ]
 GROUPS["xen"]  = [ "i386_xen", "x86_64_xen" ]
diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am
index ee88e44e9..aa933b93c 100644
--- a/grub-core/Makefile.am
+++ b/grub-core/Makefile.am
@@ -288,6 +288,12 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
 endif
 
+if COND_loongarch64_efi
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
+endif
+
 if COND_riscv32_efi
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 715994872..1ec7eefa7 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -67,6 +67,9 @@ kernel = {
   arm64_efi_ldflags          = '-Wl,-r';
   arm64_efi_stripflags       = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame';
 
+  loongarch64_efi_ldflags      = '-Wl,-r';
+  loongarch64_efi_stripflags   = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame';
+
   riscv32_efi_ldflags      = '-Wl,-r';
   riscv32_efi_stripflags   = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame';
 
@@ -122,6 +125,7 @@ kernel = {
   arm_coreboot_startup = kern/arm/startup.S;
   arm_efi_startup = kern/arm/efi/startup.S;
   arm64_efi_startup = kern/arm64/efi/startup.S;
+  loongarch64_efi_startup = kern/loongarch64/efi/startup.S;
   riscv32_efi_startup = kern/riscv/efi/startup.S;
   riscv64_efi_startup = kern/riscv/efi/startup.S;
 
@@ -260,6 +264,9 @@ kernel = {
   arm64_efi = kern/arm64/efi/init.c;
   arm64_efi = kern/efi/fdt.c;
 
+  loongarch64_efi = kern/loongarch64/efi/init.c;
+  loongarch64_efi = kern/efi/fdt.c;
+
   riscv32_efi = kern/riscv/efi/init.c;
   riscv32_efi = kern/efi/fdt.c;
 
@@ -338,6 +345,11 @@ kernel = {
   arm64 = kern/arm64/dl.c;
   arm64 = kern/arm64/dl_helper.c;
 
+  loongarch64 = kern/loongarch64/cache.c;
+  loongarch64 = kern/loongarch64/cache_flush.S;
+  loongarch64 = kern/loongarch64/dl.c;
+  loongarch64 = kern/loongarch64/dl_helper.c;
+
   riscv32 = kern/riscv/cache.c;
   riscv32 = kern/riscv/cache_flush.S;
   riscv32 = kern/riscv/dl.c;
@@ -832,6 +844,7 @@ module = {
   enable = arm64_efi;
   enable = arm_uboot;
   enable = arm_coreboot;
+  enable = loongarch64_efi;
   enable = riscv32_efi;
   enable = riscv64_efi;
 };
@@ -1814,6 +1827,7 @@ module = {
   arm_efi = loader/arm64/linux.c;
   arm_uboot = loader/arm/linux.c;
   arm64 = loader/arm64/linux.c;
+  loongarch64 = loader/loongarch64/linux.c;
   riscv32 = loader/riscv/linux.c;
   riscv64 = loader/riscv/linux.c;
   common = loader/linux.c;
@@ -1910,6 +1924,7 @@ module = {
   enable = ia64_efi;
   enable = arm_efi;
   enable = arm64_efi;
+  enable = loongarch64_efi;
   enable = riscv32_efi;
   enable = riscv64_efi;
   enable = mips;
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
index d4cadd8b5..553d557fe 100644
--- a/include/grub/efi/api.h
+++ b/include/grub/efi/api.h
@@ -1745,7 +1745,7 @@ typedef struct grub_efi_rng_protocol grub_efi_rng_protocol_t;
 
 #if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \
   || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \
-  || defined(__riscv)
+  || defined(__riscv) || defined (__loongarch__)
 
 #define efi_call_0(func)		func()
 #define efi_call_1(func, a)		func(a)
diff --git a/include/grub/util/install.h b/include/grub/util/install.h
index 7d7445af9..35cf17a8d 100644
--- a/include/grub/util/install.h
+++ b/include/grub/util/install.h
@@ -107,6 +107,7 @@ enum grub_install_plat
     GRUB_INSTALL_PLATFORM_I386_XEN_PVH,
     GRUB_INSTALL_PLATFORM_ARM64_EFI,
     GRUB_INSTALL_PLATFORM_ARM_COREBOOT,
+    GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI,
     GRUB_INSTALL_PLATFORM_RISCV32_EFI,
     GRUB_INSTALL_PLATFORM_RISCV64_EFI,
     GRUB_INSTALL_PLATFORM_MAX
diff --git a/util/grub-install-common.c b/util/grub-install-common.c
index 347558bf5..20d56ee12 100644
--- a/util/grub-install-common.c
+++ b/util/grub-install-common.c
@@ -881,30 +881,31 @@ static struct
   const char *platform;
 } platforms[GRUB_INSTALL_PLATFORM_MAX] =
   {
-    [GRUB_INSTALL_PLATFORM_I386_PC] =          { "i386",    "pc"        },
-    [GRUB_INSTALL_PLATFORM_I386_EFI] =         { "i386",    "efi"       },
-    [GRUB_INSTALL_PLATFORM_I386_QEMU] =        { "i386",    "qemu"      },
-    [GRUB_INSTALL_PLATFORM_I386_COREBOOT] =    { "i386",    "coreboot"  },
-    [GRUB_INSTALL_PLATFORM_I386_MULTIBOOT] =   { "i386",    "multiboot" },
-    [GRUB_INSTALL_PLATFORM_I386_IEEE1275] =    { "i386",    "ieee1275"  },
-    [GRUB_INSTALL_PLATFORM_X86_64_EFI] =       { "x86_64",  "efi"       },
-    [GRUB_INSTALL_PLATFORM_I386_XEN] =         { "i386",    "xen"       },
-    [GRUB_INSTALL_PLATFORM_X86_64_XEN] =       { "x86_64",  "xen"       },
-    [GRUB_INSTALL_PLATFORM_I386_XEN_PVH] =     { "i386",    "xen_pvh"   },
-    [GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON] =  { "mipsel",  "loongson"  },
-    [GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS] = { "mipsel",  "qemu_mips" },
-    [GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS] =   { "mips",    "qemu_mips" },
-    [GRUB_INSTALL_PLATFORM_MIPSEL_ARC] =       { "mipsel",  "arc"       },
-    [GRUB_INSTALL_PLATFORM_MIPS_ARC] =         { "mips",    "arc"       },
-    [GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275] = { "sparc64", "ieee1275"  },
-    [GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275] = { "powerpc", "ieee1275"  },
-    [GRUB_INSTALL_PLATFORM_IA64_EFI] =         { "ia64",    "efi"       },
-    [GRUB_INSTALL_PLATFORM_ARM_EFI] =          { "arm",     "efi"       },
-    [GRUB_INSTALL_PLATFORM_ARM64_EFI] =        { "arm64",   "efi"       },
-    [GRUB_INSTALL_PLATFORM_ARM_UBOOT] =        { "arm",     "uboot"     },
-    [GRUB_INSTALL_PLATFORM_ARM_COREBOOT] =     { "arm",     "coreboot"  },
-    [GRUB_INSTALL_PLATFORM_RISCV32_EFI] =      { "riscv32", "efi"       },
-    [GRUB_INSTALL_PLATFORM_RISCV64_EFI] =      { "riscv64", "efi"       },
+    [GRUB_INSTALL_PLATFORM_I386_PC] =          { "i386",        "pc"        },
+    [GRUB_INSTALL_PLATFORM_I386_EFI] =         { "i386",        "efi"       },
+    [GRUB_INSTALL_PLATFORM_I386_QEMU] =        { "i386",        "qemu"      },
+    [GRUB_INSTALL_PLATFORM_I386_COREBOOT] =    { "i386",        "coreboot"  },
+    [GRUB_INSTALL_PLATFORM_I386_MULTIBOOT] =   { "i386",        "multiboot" },
+    [GRUB_INSTALL_PLATFORM_I386_IEEE1275] =    { "i386",        "ieee1275"  },
+    [GRUB_INSTALL_PLATFORM_X86_64_EFI] =       { "x86_64",      "efi"       },
+    [GRUB_INSTALL_PLATFORM_I386_XEN] =         { "i386",        "xen"       },
+    [GRUB_INSTALL_PLATFORM_X86_64_XEN] =       { "x86_64",      "xen"       },
+    [GRUB_INSTALL_PLATFORM_I386_XEN_PVH] =     { "i386",        "xen_pvh"   },
+    [GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON] =  { "mipsel",      "loongson"  },
+    [GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS] = { "mipsel",      "qemu_mips" },
+    [GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS] =   { "mips",        "qemu_mips" },
+    [GRUB_INSTALL_PLATFORM_MIPSEL_ARC] =       { "mipsel",      "arc"       },
+    [GRUB_INSTALL_PLATFORM_MIPS_ARC] =         { "mips",        "arc"       },
+    [GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275] = { "sparc64",     "ieee1275"  },
+    [GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275] = { "powerpc",     "ieee1275"  },
+    [GRUB_INSTALL_PLATFORM_IA64_EFI] =         { "ia64",        "efi"       },
+    [GRUB_INSTALL_PLATFORM_ARM_EFI] =          { "arm",         "efi"       },
+    [GRUB_INSTALL_PLATFORM_ARM64_EFI] =        { "arm64",       "efi"       },
+    [GRUB_INSTALL_PLATFORM_ARM_UBOOT] =        { "arm",         "uboot"     },
+    [GRUB_INSTALL_PLATFORM_ARM_COREBOOT] =     { "arm",         "coreboot"  },
+    [GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI] =  { "loongarch64", "efi"       },
+    [GRUB_INSTALL_PLATFORM_RISCV32_EFI] =      { "riscv32",     "efi"       },
+    [GRUB_INSTALL_PLATFORM_RISCV64_EFI] =      { "riscv64",     "efi"       },
   };
 
 char *
diff --git a/util/grub-install.c b/util/grub-install.c
index 7b04bd3c5..aa868e6b5 100644
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -324,6 +324,8 @@ get_default_platform (void)
    return "arm64-efi";
 #elif defined (__amd64__) || defined (__x86_64__) || defined (__i386__)
    return grub_install_get_default_x86_platform ();
+#elif defined (__loongarch64)
+   return "loongarch64-efi";
 #elif defined (__riscv)
 #if __riscv_xlen == 32
    return "riscv32-efi";
@@ -485,6 +487,7 @@ have_bootdev (enum grub_install_plat pl)
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
@@ -910,6 +913,7 @@ main (int argc, char *argv[])
     case GRUB_INSTALL_PLATFORM_X86_64_EFI:
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
@@ -957,6 +961,7 @@ main (int argc, char *argv[])
     case GRUB_INSTALL_PLATFORM_X86_64_EFI:
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
@@ -1012,6 +1017,7 @@ main (int argc, char *argv[])
     case GRUB_INSTALL_PLATFORM_X86_64_EFI:
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
@@ -1132,6 +1138,9 @@ main (int argc, char *argv[])
 	    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
 	      efi_file = "BOOTAA64.EFI";
 	      break;
+	    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
+	      efi_file = "BOOTLOONGARCH64.EFI";
+	      break;
 	    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
 	      efi_file = "BOOTRISCV32.EFI";
 	      break;
@@ -1165,6 +1174,9 @@ main (int argc, char *argv[])
 	    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
 	      efi_file = "grubaa64.efi";
 	      break;
+	    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
+	      efi_file = "grubloongarch64.efi";
+	      break;
 	    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
 	      efi_file = "grubriscv32.efi";
 	      break;
@@ -1473,6 +1485,7 @@ main (int argc, char *argv[])
 		  case GRUB_INSTALL_PLATFORM_X86_64_EFI:
 		  case GRUB_INSTALL_PLATFORM_ARM_EFI:
 		  case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+		  case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
 		  case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
 		  case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
 		  case GRUB_INSTALL_PLATFORM_IA64_EFI:
@@ -1568,6 +1581,7 @@ main (int argc, char *argv[])
     case GRUB_INSTALL_PLATFORM_X86_64_EFI:
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
@@ -1673,6 +1687,7 @@ main (int argc, char *argv[])
       break;
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
@@ -1927,6 +1942,7 @@ main (int argc, char *argv[])
       /* FALLTHROUGH */
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
     case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
diff --git a/util/grub-mknetdir.c b/util/grub-mknetdir.c
index d609ff94c..46f304c2b 100644
--- a/util/grub-mknetdir.c
+++ b/util/grub-mknetdir.c
@@ -108,6 +108,7 @@ static const struct
     [GRUB_INSTALL_PLATFORM_IA64_EFI] = { "ia64-efi", "efinet", ".efi" },
     [GRUB_INSTALL_PLATFORM_ARM_EFI] = { "arm-efi", "efinet", ".efi" },
     [GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64-efi", "efinet", ".efi" },
+    [GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI] = { "loongarch64-efi", "efinet", ".efi" },
     [GRUB_INSTALL_PLATFORM_RISCV32_EFI] = { "riscv32-efi", "efinet", ".efi" },
     [GRUB_INSTALL_PLATFORM_RISCV64_EFI] = { "riscv64-efi", "efinet", ".efi" },
   };
diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c
index ba89b1394..145aeed74 100644
--- a/util/grub-mkrescue.c
+++ b/util/grub-mkrescue.c
@@ -542,6 +542,7 @@ main (int argc, char *argv[])
 	  || source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI]
 	  || source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI]
 	  || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI]
+	  || source_dirs[GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI]
 	  || source_dirs[GRUB_INSTALL_PLATFORM_RISCV32_EFI]
 	  || source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI]
 	  || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
@@ -742,6 +743,7 @@ main (int argc, char *argv[])
       || source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI]
       || source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI]
       || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI]
+      || source_dirs[GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI]
       || source_dirs[GRUB_INSTALL_PLATFORM_RISCV32_EFI]
       || source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI])
     {
@@ -778,6 +780,12 @@ main (int argc, char *argv[])
 			     imgname);
       free (imgname);
 
+      imgname = grub_util_path_concat (2, efidir_efi_boot, "bootloongarch64.efi");
+      make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI,
+			     "loongarch64-efi",
+			     imgname);
+      free (imgname);
+
       imgname = grub_util_path_concat (2, efidir_efi_boot, "bootriscv32.efi");
       make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_RISCV32_EFI, "riscv32-efi",
 			     imgname);
diff --git a/util/mkimage.c b/util/mkimage.c
index 43078c71c..4237383ac 100644
--- a/util/mkimage.c
+++ b/util/mkimage.c
@@ -622,6 +622,22 @@ static const struct grub_install_image_target_desc image_targets[] =
       .pe_target = GRUB_PE32_MACHINE_ARM64,
       .elf_target = EM_AARCH64,
     },
+    {
+      .dirname = "loongarch64-efi",
+      .names = { "loongarch64-efi", NULL },
+      .voidp_sizeof = 8,
+      .bigendian = 0,
+      .id = IMAGE_EFI,
+      .flags = PLATFORM_FLAGS_NONE,
+      .total_module_size = TARGET_NO_FIELD,
+      .decompressor_compressed_size = TARGET_NO_FIELD,
+      .decompressor_uncompressed_size = TARGET_NO_FIELD,
+      .decompressor_uncompressed_addr = TARGET_NO_FIELD,
+      .section_align = GRUB_PE32_SECTION_ALIGNMENT,
+      .vaddr_offset = EFI64_HEADER_SIZE,
+      .pe_target = GRUB_PE32_MACHINE_LOONGARCH64,
+      .elf_target = EM_LOONGARCH,
+    },
     {
       .dirname = "riscv32-efi",
       .names = { "riscv32-efi", NULL },
-- 
2.35.1



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

end of thread, other threads:[~2022-07-01  9:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01  9:50 [PATCH v4 0/8] Add support for LoongArch Xiaotian Wu
2022-07-01  9:50 ` [PATCH v4 1/8] PE: Add LoongArch definitions Xiaotian Wu
2022-07-01  9:50 ` [PATCH v4 2/8] " Xiaotian Wu
2022-07-01  9:50 ` [PATCH v4 3/8] LoongArch: Add setjmp implementation Xiaotian Wu
2022-07-01  9:50 ` [PATCH v4 4/8] LoongArch: Add early startup code Xiaotian Wu
2022-07-01  9:50 ` [PATCH v4 5/8] LoongArch: Add stubs for Linux loading commands Xiaotian Wu
2022-07-01  9:50 ` [PATCH v4 6/8] LoongArch: Add awareness for LoongArch relocations Xiaotian Wu
2022-07-01  9:50 ` [PATCH v4 7/8] LoongArch: Add auxiliary files Xiaotian Wu
2022-07-01  9:50 ` [PATCH v4 8/8] LoongArch: Add to build system Xiaotian Wu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.