All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/9] Add support for LoongArch
@ 2022-07-29  7:11 Xiaotian Wu
  2022-07-29  7:11 ` [PATCH v5 1/9] PE: Add LoongArch definitions Xiaotian Wu
                   ` (9 more replies)
  0 siblings, 10 replies; 18+ messages in thread
From: Xiaotian Wu @ 2022-07-29  7:11 UTC (permalink / raw)
  To: grub-devel; +Cc: git, daniel.kiper, 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.
See: https://github.com/loongarch64/grub/tree/dev/patchwork/efi

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.

v4->v5:
- Fix make distcheck failed.
- Add tests support.
- based on the last commit.

Here is the test results:

=================================
   GRUB 2.11: ./test-suite.log
=================================

# TOTAL: 82
# PASS:  52
# SKIP:  8
# XFAIL: 0
# FAIL:  2
# XPASS: 0
# ERROR: 20

The full test log is here: https://github.com/loongarch64/grub/files/9216733/test-suite.log

Xiaotian Wu (9):
  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
  tests: add support for LoongArch

 Makefile.util.def                        |   1 +
 configure.ac                             |  22 ++-
 gentpl.py                                |  25 +--
 grub-core/Makefile.am                    |   6 +
 grub-core/Makefile.core.def              |  16 ++
 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 +
 tests/ahci_test.in                       |   2 +-
 tests/ehci_test.in                       |   2 +-
 tests/ohci_test.in                       |   2 +-
 tests/partmap_test.in                    |   2 +-
 tests/pata_test.in                       |   2 +-
 tests/uhci_test.in                       |   2 +-
 tests/util/grub-shell.in                 |  16 ++
 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 ++
 43 files changed, 1170 insertions(+), 66 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] 18+ messages in thread

* [PATCH v5 1/9] PE: Add LoongArch definitions
  2022-07-29  7:11 [PATCH v5 0/9] Add support for LoongArch Xiaotian Wu
@ 2022-07-29  7:11 ` Xiaotian Wu
  2022-07-29  7:11 ` [PATCH v5 2/9] " Xiaotian Wu
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Xiaotian Wu @ 2022-07-29  7:11 UTC (permalink / raw)
  To: grub-devel; +Cc: git, daniel.kiper, 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] 18+ messages in thread

* [PATCH v5 2/9] Add LoongArch definitions
  2022-07-29  7:11 [PATCH v5 0/9] Add support for LoongArch Xiaotian Wu
  2022-07-29  7:11 ` [PATCH v5 1/9] PE: Add LoongArch definitions Xiaotian Wu
@ 2022-07-29  7:11 ` Xiaotian Wu
  2022-07-29  7:31   ` WANG Xuerui
  2022-07-29  7:11 ` [PATCH v5 3/9] LoongArch: Add setjmp implementation Xiaotian Wu
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Xiaotian Wu @ 2022-07-29  7:11 UTC (permalink / raw)
  To: grub-devel; +Cc: git, daniel.kiper, 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] 18+ messages in thread

* [PATCH v5 3/9] LoongArch: Add setjmp implementation
  2022-07-29  7:11 [PATCH v5 0/9] Add support for LoongArch Xiaotian Wu
  2022-07-29  7:11 ` [PATCH v5 1/9] PE: Add LoongArch definitions Xiaotian Wu
  2022-07-29  7:11 ` [PATCH v5 2/9] " Xiaotian Wu
@ 2022-07-29  7:11 ` Xiaotian Wu
  2022-07-29  7:11 ` [PATCH v5 4/9] LoongArch: Add early startup code Xiaotian Wu
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Xiaotian Wu @ 2022-07-29  7:11 UTC (permalink / raw)
  To: grub-devel; +Cc: git, daniel.kiper, 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] 18+ messages in thread

* [PATCH v5 4/9] LoongArch: Add early startup code
  2022-07-29  7:11 [PATCH v5 0/9] Add support for LoongArch Xiaotian Wu
                   ` (2 preceding siblings ...)
  2022-07-29  7:11 ` [PATCH v5 3/9] LoongArch: Add setjmp implementation Xiaotian Wu
@ 2022-07-29  7:11 ` Xiaotian Wu
  2022-07-29  7:11 ` [PATCH v5 5/9] LoongArch: Add stubs for Linux loading commands Xiaotian Wu
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Xiaotian Wu @ 2022-07-29  7:11 UTC (permalink / raw)
  To: grub-devel; +Cc: git, daniel.kiper, 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] 18+ messages in thread

* [PATCH v5 5/9] LoongArch: Add stubs for Linux loading commands
  2022-07-29  7:11 [PATCH v5 0/9] Add support for LoongArch Xiaotian Wu
                   ` (3 preceding siblings ...)
  2022-07-29  7:11 ` [PATCH v5 4/9] LoongArch: Add early startup code Xiaotian Wu
@ 2022-07-29  7:11 ` Xiaotian Wu
  2022-07-29  7:11 ` [PATCH v5 6/9] LoongArch: Add awareness for LoongArch relocations Xiaotian Wu
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Xiaotian Wu @ 2022-07-29  7:11 UTC (permalink / raw)
  To: grub-devel; +Cc: git, daniel.kiper, 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] 18+ messages in thread

* [PATCH v5 6/9] LoongArch: Add awareness for LoongArch relocations
  2022-07-29  7:11 [PATCH v5 0/9] Add support for LoongArch Xiaotian Wu
                   ` (4 preceding siblings ...)
  2022-07-29  7:11 ` [PATCH v5 5/9] LoongArch: Add stubs for Linux loading commands Xiaotian Wu
@ 2022-07-29  7:11 ` Xiaotian Wu
  2022-07-29  7:11 ` [PATCH v5 7/9] LoongArch: Add auxiliary files Xiaotian Wu
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Xiaotian Wu @ 2022-07-29  7:11 UTC (permalink / raw)
  To: grub-devel; +Cc: git, daniel.kiper, 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 e447fd0fa..0bf40caa6 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..55bcec7fa
--- /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/loongarch64/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 acb4d4232..cf79b1ce1 100644
--- a/include/grub/dl.h
+++ b/include/grub/dl.h
@@ -300,6 +300,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] 18+ messages in thread

* [PATCH v5 7/9] LoongArch: Add auxiliary files
  2022-07-29  7:11 [PATCH v5 0/9] Add support for LoongArch Xiaotian Wu
                   ` (5 preceding siblings ...)
  2022-07-29  7:11 ` [PATCH v5 6/9] LoongArch: Add awareness for LoongArch relocations Xiaotian Wu
@ 2022-07-29  7:11 ` Xiaotian Wu
  2022-07-29  7:12 ` [PATCH v5 8/9] LoongArch: Add to build system Xiaotian Wu
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Xiaotian Wu @ 2022-07-29  7:11 UTC (permalink / raw)
  To: grub-devel; +Cc: git, daniel.kiper, 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 d290c9a76..5a486558e 100644
--- a/grub-core/kern/efi/mm.c
+++ b/grub-core/kern/efi/mm.c
@@ -654,7 +654,8 @@ grub_efi_mm_init (void)
   grub_mm_add_region_fn = grub_efi_mm_add_regions;
 }
 
-#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] 18+ messages in thread

* [PATCH v5 8/9] LoongArch: Add to build system
  2022-07-29  7:11 [PATCH v5 0/9] Add support for LoongArch Xiaotian Wu
                   ` (6 preceding siblings ...)
  2022-07-29  7:11 ` [PATCH v5 7/9] LoongArch: Add auxiliary files Xiaotian Wu
@ 2022-07-29  7:12 ` Xiaotian Wu
  2022-07-29  7:12 ` [PATCH v5 9/9] tests: add support for LoongArch Xiaotian Wu
  2022-07-30  5:21 ` [PATCH v5 0/9] Add " Glenn Washburn
  9 siblings, 0 replies; 18+ messages in thread
From: Xiaotian Wu @ 2022-07-29  7:12 UTC (permalink / raw)
  To: grub-devel; +Cc: git, daniel.kiper, Xiaotian Wu, Zhou Yang

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
Signed-off-by: Zhou Yang <zhouyang@loongson.cn>
---
 Makefile.util.def           |  1 +
 configure.ac                | 22 ++++++++++++++++-
 gentpl.py                   | 25 ++++++++++---------
 grub-core/Makefile.am       |  6 +++++
 grub-core/Makefile.core.def | 16 ++++++++++++
 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 ++++++++++++
 12 files changed, 125 insertions(+), 38 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/configure.ac b/configure.ac
index 90f686f79..71f65a70d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -119,6 +119,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
@@ -144,6 +145,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 ;;
     *)
@@ -194,6 +196,7 @@ case "$target_cpu"-"$platform" in
   arm-coreboot) ;;
   arm-efi) ;;
   arm64-efi) ;;
+  loongarch64-efi) ;;
   riscv32-efi) ;;
   riscv64-efi) ;;
   *-emu) ;;
@@ -855,6 +858,20 @@ if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ); then
   fi
 fi
 
+if test "x$target_cpu" = xloongarch64; then
+  AC_CACHE_CHECK([whether -Wa,-mla-global-with-abs works], [grub_cv_cc_mla_global_with_abs], [
+    CFLAGS="$TARGET_CFLAGS -Wa,-mla-global-with-abs -Werror"
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+	[grub_cv_cc_mla_global_with_abs=yes],
+	[grub_cv_cc_mla_global_with_abs=no])
+  ])
+
+  if test "x$grub_cv_cc_mla_global_with_abs" = xyes; then
+    TARGET_CFLAGS="$TARGET_CFLAGS -Wa,-mla-global-with-abs"
+    TARGET_CCASFLAGS="$TARGET_CCASFLAGS -Wa,-mla-global-with-abs"
+  fi
+fi
+
 # GRUB doesn't use float or doubles at all. Yet some toolchains may decide
 # that floats are a good fit to run instead of what's written in the code.
 # Given that floating point unit is disabled (if present to begin with)
@@ -1216,7 +1233,8 @@ AC_SUBST(TARGET_LDFLAGS_OLDMAGIC)
 
 LDFLAGS="$TARGET_LDFLAGS"
 
-if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
+if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 \
+  || test "$target_cpu" = loongarch64 ; then
   # Use large model to support 4G memory
   AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
     CFLAGS="$TARGET_CFLAGS -mcmodel=large"
@@ -1996,6 +2014,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..6670603da 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;
 };
@@ -1713,6 +1726,7 @@ module = {
   extra_dist = lib/arm/setjmp.S;
   extra_dist = lib/arm64/setjmp.S;
   extra_dist = lib/riscv/setjmp.S;
+  extra_dist = lib/loongarch64/setjmp.S;
 };
 
 module = {
@@ -1814,6 +1828,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 +1925,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] 18+ messages in thread

* [PATCH v5 9/9] tests: add support for LoongArch
  2022-07-29  7:11 [PATCH v5 0/9] Add support for LoongArch Xiaotian Wu
                   ` (7 preceding siblings ...)
  2022-07-29  7:12 ` [PATCH v5 8/9] LoongArch: Add to build system Xiaotian Wu
@ 2022-07-29  7:12 ` Xiaotian Wu
  2022-08-01 22:33   ` Glenn Washburn
  2022-07-30  5:21 ` [PATCH v5 0/9] Add " Glenn Washburn
  9 siblings, 1 reply; 18+ messages in thread
From: Xiaotian Wu @ 2022-07-29  7:12 UTC (permalink / raw)
  To: grub-devel; +Cc: git, daniel.kiper, Xiaotian Wu

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
---
 tests/ahci_test.in       |  2 +-
 tests/ehci_test.in       |  2 +-
 tests/ohci_test.in       |  2 +-
 tests/partmap_test.in    |  2 +-
 tests/pata_test.in       |  2 +-
 tests/uhci_test.in       |  2 +-
 tests/util/grub-shell.in | 16 ++++++++++++++++
 7 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/tests/ahci_test.in b/tests/ahci_test.in
index 6d2e61d4e..70646a24e 100644
--- a/tests/ahci_test.in
+++ b/tests/ahci_test.in
@@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
     mips*-arc | mips*-qemu_mips)
 	exit 77;;
     # FIXME: No native drivers are available for those
-    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
+    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
 	exit 77;;
 esac
 
diff --git a/tests/ehci_test.in b/tests/ehci_test.in
index df671b4b6..bf823a5de 100644
--- a/tests/ehci_test.in
+++ b/tests/ehci_test.in
@@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
     mips*-arc | mips*-qemu_mips)
 	exit 77;;
     # FIXME: No native drivers are available for those
-    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
+    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
 	exit 77;;
 esac
 
diff --git a/tests/ohci_test.in b/tests/ohci_test.in
index 741ad881f..a40d3bc0a 100644
--- a/tests/ohci_test.in
+++ b/tests/ohci_test.in
@@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
     mips*-arc | mips*-qemu_mips)
 	exit 77;;
     # FIXME: No native drivers are available for those
-    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
+    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
 	exit 77;;
 esac
 
diff --git a/tests/partmap_test.in b/tests/partmap_test.in
index 4138e88fe..6db59ce38 100644
--- a/tests/partmap_test.in
+++ b/tests/partmap_test.in
@@ -90,7 +90,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
     mipsel-arc)
 	disk=arc/scsi0/disk0/rdisk0
 	;;
-    arm*-efi)
+    arm*-efi|loongarch64-efi)
 	disk=hd2
 	;;
     *)
diff --git a/tests/pata_test.in b/tests/pata_test.in
index 31144a8fd..4d0e7d573 100644
--- a/tests/pata_test.in
+++ b/tests/pata_test.in
@@ -33,7 +33,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
     i386-efi)
 	exit 77;;
     # FIXME: No native drivers are available for those
-    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
+    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
 	exit 77;;
     i386-ieee1275)
 	disk=hdb
diff --git a/tests/uhci_test.in b/tests/uhci_test.in
index 5aa5eb726..de199a281 100644
--- a/tests/uhci_test.in
+++ b/tests/uhci_test.in
@@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
     mips*-arc | mips*-qemu_mips)
 	exit 77;;
     # FIXME: No native drivers are available for those
-    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
+    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
 	exit 77;;
 esac
 
diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index 4828afb7c..b82c8243f 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -194,6 +194,15 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
 	disk="device virtio-blk-device,drive=hd1 -drive if=none,id=hd1,file="
 	serial_port=efi0
 	;;
+    loongarch64-efi)
+	qemu=qemu-system-loongarch64
+	boot=hd
+	console=console
+	trim=1
+	qemuopts="-machine virt -cpu la464 -smp 2 -nographic -bios /usr/share/qemu/edk2-loongarch64-code.fd $qemuopts"
+	disk="device virtio-blk-pci,drive=hd1 -drive if=none,id=hd1,file="
+	serial_port=
+	;;
     *)
 	boot=hd
 	qemu=qemu-system-i386
@@ -395,6 +404,8 @@ fi
 if [ x$boot = xhd ]; then
     if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm64-efi ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm-efi ]; then
 	device="device virtio-blk-device,drive=hd0 -drive if=none,id=hd0,file="
+    elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = loongarch64-efi ]; then
+	device="device virtio-blk-pci,drive=hd0 -drive if=none,id=hd0,file="
     elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = mips-arc ]; then
 	device="hdb "
     else
@@ -405,6 +416,8 @@ fi
 if [ x$boot = xcd ]; then
     if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm64-efi ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm-efi ]; then
 	device="device virtio-blk-device,drive=cd0 -drive if=none,id=cd0,media=cdrom,file="
+    elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = loongarch64-efi ]; then
+	device="device virtio-blk-pci,drive=cd0 -drive if=none,id=cd0,media=cdrom,file="
     elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = powerpc-ieee1275 ] && [ x$pseries != xy ] ; then
 	device="-drive if=ide,media=cdrom,file="
     else
@@ -509,6 +522,9 @@ elif [ x$boot = xemu ]; then
     test -n "$debug" || rm -rf "$rootdir"
     test -n "$debug" || rm -f "$roottar"
 else
+    if [ -n "$debug" ]; then
+      echo "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} >> /tmp/grub-shell.run
+    fi
     timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} | cat | tr -d "\r" | do_trim
 fi
 if [ x$boot = xcoreboot ]; then
-- 
2.35.1



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

* Re: [PATCH v5 2/9] Add LoongArch definitions
  2022-07-29  7:11 ` [PATCH v5 2/9] " Xiaotian Wu
@ 2022-07-29  7:31   ` WANG Xuerui
  2022-08-01  5:01     ` Xiaotian Wu
  0 siblings, 1 reply; 18+ messages in thread
From: WANG Xuerui @ 2022-07-29  7:31 UTC (permalink / raw)
  To: Xiaotian Wu, grub-devel; +Cc: git, daniel.kiper, Zhou Yang

On 2022/7/29 15:11, Xiaotian Wu wrote:
> 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
> +

Welp. This almost certainly needs some additional work, now that the 
new-style relocs [1][2] are upstreamed, and bound to be generated with 
the combo of binutils 2.40 trunk and gcc 13.0 trunk. So we'll need to 
support both flavors in order to stay compatible with both older and 
newer toolchains.

Do you think this part could be finished relatively quickly so as to not 
miss the next grub release?

[1]: 
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=6d13722a97cee3fd397e116bde3bcedbb1e220be
[2]: https://github.com/loongson/LoongArch-Documentation/pull/57

>   #ifdef GRUB_TARGET_WORDSIZE
>   #if GRUB_TARGET_WORDSIZE == 32
>   


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

* Re: [PATCH v5 0/9] Add support for LoongArch
  2022-07-29  7:11 [PATCH v5 0/9] Add support for LoongArch Xiaotian Wu
                   ` (8 preceding siblings ...)
  2022-07-29  7:12 ` [PATCH v5 9/9] tests: add support for LoongArch Xiaotian Wu
@ 2022-07-30  5:21 ` Glenn Washburn
  2022-07-30  6:43   ` 武校田
  9 siblings, 1 reply; 18+ messages in thread
From: Glenn Washburn @ 2022-07-30  5:21 UTC (permalink / raw)
  To: Xiaotian Wu; +Cc: The development of GNU GRUB, git, daniel.kiper

On Fri, 29 Jul 2022 15:11:52 +0800
Xiaotian Wu <wuxiaotian@loongson.cn> wrote:

> 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.
> See: https://github.com/loongarch64/grub/tree/dev/patchwork/efi
> 
> 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.
> 
> v4->v5:
> - Fix make distcheck failed.
> - Add tests support.
> - based on the last commit.
> 
> Here is the test results:
> 
> =================================
>    GRUB 2.11: ./test-suite.log
> =================================
> 
> # TOTAL: 82
> # PASS:  52
> # SKIP:  8
> # XFAIL: 0
> # FAIL:  2
> # XPASS: 0
> # ERROR: 20
> 
> The full test log is here: https://github.com/loongarch64/grub/files/9216733/test-suite.log

Thanks for doing this testing. What are the values passed for the
configure options --build, --host, and --target?

Also, would you be able to run these tests again on a system with as
many of the make check test prerequisites installed? They are listed in
the INSTALL file in the repository root. This would allow the testing
of various GRUB filesystem code which is not happening now (the reason
many tests fail with ERROR).

There are two actual failure in the provided log. One is the functional
test, which are not expected to be working. The other is the partmap
test, which should be working. Its not clear exactly which sub-test of
the partmap test is failing (due to output not being very verbose). If
you add 'set -x' to the top of partmap_test and rerun the tests, I can
get a clearer picture of what's going on.

Glenn

> 
> Xiaotian Wu (9):
>   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
>   tests: add support for LoongArch
> 
>  Makefile.util.def                        |   1 +
>  configure.ac                             |  22 ++-
>  gentpl.py                                |  25 +--
>  grub-core/Makefile.am                    |   6 +
>  grub-core/Makefile.core.def              |  16 ++
>  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 +
>  tests/ahci_test.in                       |   2 +-
>  tests/ehci_test.in                       |   2 +-
>  tests/ohci_test.in                       |   2 +-
>  tests/partmap_test.in                    |   2 +-
>  tests/pata_test.in                       |   2 +-
>  tests/uhci_test.in                       |   2 +-
>  tests/util/grub-shell.in                 |  16 ++
>  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 ++
>  43 files changed, 1170 insertions(+), 66 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
> 


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

* Re: Re: [PATCH v5 0/9] Add support for LoongArch
  2022-07-30  5:21 ` [PATCH v5 0/9] Add " Glenn Washburn
@ 2022-07-30  6:43   ` 武校田
  2022-08-01 22:44     ` Glenn Washburn
  0 siblings, 1 reply; 18+ messages in thread
From: 武校田 @ 2022-07-30  6:43 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: git, daniel.kiper

Thanks for your reply.

&gt; Thanks for doing this testing. What are the values passed for the
&gt; configure options --build, --host, and --target?

I compiled it on my local machine, using the Archlinux 2022.03 LoongArch
version, the iso and repository are here: https://mirrors.wsyu.edu.cn/loongarch/2022.03/

&gt; Also, would you be able to run these tests again on a system with as
&gt; many of the make check test prerequisites installed? They are listed in
&gt; the INSTALL file in the repository root. This would allow the testing
&gt; of various GRUB filesystem code which is not happening now (the reason
&gt; many tests fail with ERROR).

I will check the dependencies required by grub-fs-tester, thanks.

&gt; There are two actual failure in the provided log. One is the functional
&gt; test, which are not expected to be working. The other is the partmap
&gt; test, which should be working. Its not clear exactly which sub-test of
&gt; the partmap test is failing (due to output not being very verbose). If
&gt; you add 'set -x' to the top of partmap_test and rerun the tests, I can
&gt; get a clearer picture of what's going on.
&gt; 
&gt; Glenn
&gt; 

The details of this partmap_test are as follows:

+ echo 'Checking MSDOS partition types...'
Checking MSDOS partition types...
+ create_disk_image /tmp/tmp.N6QvM6XPXY 64
+ name=/tmp/tmp.N6QvM6XPXY
+ size=64
+ rm -f /tmp/tmp.N6QvM6XPXY
+ dd if=/dev/zero of=/tmp/tmp.N6QvM6XPXY bs=512 count=1 seek=131071 status=noxfer
记录了1+0 的读入
记录了1+0 的写出
+ parted -a none -s /tmp/tmp.N6QvM6XPXY mklabel msdos
+ list_parts part_msdos /tmp/tmp.N6QvM6XPXY /tmp/tmp.dOULt2UJMN
+ mod=part_msdos
+ shift
+ imgfile=/tmp/tmp.N6QvM6XPXY
+ shift
+ outfile=/tmp/tmp.dOULt2UJMN
+ shift
+ ./grub-shell --disk=/tmp/tmp.N6QvM6XPXY --modules=part_msdos
+ echo ls
WARNING: Image format was not specified for '/tmp/tmp.N6QvM6XPXY' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
WARNING: Image format was not specified for '/tmp/tmp.mQzmZs2ROc' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
+ cat /tmp/tmp.dOULt2UJMN
+ tr -d '\n\r'
(hd0) (hd1) (hd1,gpt3) (hd1,gpt2,msdos1) (hd1,gpt2) (hd1,gpt1) + echo

+ check_output /tmp/tmp.dOULt2UJMN hd2
+ outfile=/tmp/tmp.dOULt2UJMN
+ shift
+ for dsk in $@
+ grep '(hd2)' /tmp/tmp.dOULt2UJMN
++ cat /tmp/tmp.dOULt2UJMN
+ echo '(hd2): disk/partiton not found in: (hd0) (hd1) (hd1,gpt3) (hd1,gpt2,msdos1) (hd1,gpt2) (hd1,gpt1) '
(hd2): disk/partiton not found in: (hd0) (hd1) (hd1,gpt3) (hd1,gpt2,msdos1) (hd1,gpt2) (hd1,gpt1) 
+ exit 1
FAIL partmap_test (exit status: 1)

It looks like it can't find '(hd2)' in the output.

------------------------------
Best Regards
Xiaotian Wu


本邮件及其附件含有龙芯中科的商业秘密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制或散发)本邮件及其附件中的信息。如果您错收本邮件,请您立即电话或邮件通知发件人并删除本邮件。 
This email and its attachments contain confidential information from Loongson Technology , which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this email in error, please notify the sender by phone or email immediately and delete it. 

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

* Re: [PATCH v5 2/9] Add LoongArch definitions
  2022-07-29  7:31   ` WANG Xuerui
@ 2022-08-01  5:01     ` Xiaotian Wu
  0 siblings, 0 replies; 18+ messages in thread
From: Xiaotian Wu @ 2022-08-01  5:01 UTC (permalink / raw)
  To: WANG Xuerui, grub-devel; +Cc: git, daniel.kiper, Zhou Yang

在 2022-07-29星期五的 15:31 +0800,WANG Xuerui写道:
> On 2022/7/29 15:11, Xiaotian Wu wrote:
> > 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
> > +
> 
> Welp. This almost certainly needs some additional work, now that the 
> new-style relocs [1][2] are upstreamed, and bound to be generated
> with 
> the combo of binutils 2.40 trunk and gcc 13.0 trunk. So we'll need to
> support both flavors in order to stay compatible with both older and 
> newer toolchains.
> 
> Do you think this part could be finished relatively quickly so as to
> not 
> miss the next grub release?

Yes, the new style relocation patch is done and visible on github[1],
needs more testing and will be sent to the mailing list for review.


[1] https://github.com/loongarch64/grub/pull/5



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

* Re: [PATCH v5 9/9] tests: add support for LoongArch
  2022-07-29  7:12 ` [PATCH v5 9/9] tests: add support for LoongArch Xiaotian Wu
@ 2022-08-01 22:33   ` Glenn Washburn
  2022-08-02  4:59     ` Xiaotian Wu
  0 siblings, 1 reply; 18+ messages in thread
From: Glenn Washburn @ 2022-08-01 22:33 UTC (permalink / raw)
  To: Xiaotian Wu; +Cc: The development of GNU GRUB, git, daniel.kiper

On Fri, 29 Jul 2022 15:12:01 +0800
Xiaotian Wu <wuxiaotian@loongson.cn> wrote:

> Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
> ---
>  tests/ahci_test.in       |  2 +-
>  tests/ehci_test.in       |  2 +-
>  tests/ohci_test.in       |  2 +-
>  tests/partmap_test.in    |  2 +-
>  tests/pata_test.in       |  2 +-
>  tests/uhci_test.in       |  2 +-
>  tests/util/grub-shell.in | 16 ++++++++++++++++
>  7 files changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/tests/ahci_test.in b/tests/ahci_test.in
> index 6d2e61d4e..70646a24e 100644
> --- a/tests/ahci_test.in
> +++ b/tests/ahci_test.in
> @@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>      mips*-arc | mips*-qemu_mips)
>  	exit 77;;
>      # FIXME: No native drivers are available for those
> -    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
> +    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
>  	exit 77;;
>  esac
>  
> diff --git a/tests/ehci_test.in b/tests/ehci_test.in
> index df671b4b6..bf823a5de 100644
> --- a/tests/ehci_test.in
> +++ b/tests/ehci_test.in
> @@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>      mips*-arc | mips*-qemu_mips)
>  	exit 77;;
>      # FIXME: No native drivers are available for those
> -    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
> +    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
>  	exit 77;;
>  esac
>  
> diff --git a/tests/ohci_test.in b/tests/ohci_test.in
> index 741ad881f..a40d3bc0a 100644
> --- a/tests/ohci_test.in
> +++ b/tests/ohci_test.in
> @@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>      mips*-arc | mips*-qemu_mips)
>  	exit 77;;
>      # FIXME: No native drivers are available for those
> -    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
> +    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
>  	exit 77;;
>  esac
>  
> diff --git a/tests/partmap_test.in b/tests/partmap_test.in
> index 4138e88fe..6db59ce38 100644
> --- a/tests/partmap_test.in
> +++ b/tests/partmap_test.in
> @@ -90,7 +90,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>      mipsel-arc)
>  	disk=arc/scsi0/disk0/rdisk0
>  	;;
> -    arm*-efi)
> +    arm*-efi|loongarch64-efi)
>  	disk=hd2

The "loongarch64-efi" pattern should be separate and have "disk=hd1"
because the drive is set to show up as hd1 in the grub-shell.in changes
below.

>  	;;
>      *)
> diff --git a/tests/pata_test.in b/tests/pata_test.in
> index 31144a8fd..4d0e7d573 100644
> --- a/tests/pata_test.in
> +++ b/tests/pata_test.in
> @@ -33,7 +33,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>      i386-efi)
>  	exit 77;;
>      # FIXME: No native drivers are available for those
> -    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
> +    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
>  	exit 77;;
>      i386-ieee1275)
>  	disk=hdb
> diff --git a/tests/uhci_test.in b/tests/uhci_test.in
> index 5aa5eb726..de199a281 100644
> --- a/tests/uhci_test.in
> +++ b/tests/uhci_test.in
> @@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>      mips*-arc | mips*-qemu_mips)
>  	exit 77;;
>      # FIXME: No native drivers are available for those
> -    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
> +    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
>  	exit 77;;
>  esac
>  
> diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
> index 4828afb7c..b82c8243f 100644
> --- a/tests/util/grub-shell.in
> +++ b/tests/util/grub-shell.in
> @@ -194,6 +194,15 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>  	disk="device virtio-blk-device,drive=hd1 -drive if=none,id=hd1,file="
>  	serial_port=efi0
>  	;;
> +    loongarch64-efi)
> +	qemu=qemu-system-loongarch64
> +	boot=hd
> +	console=console
> +	trim=1
> +	qemuopts="-machine virt -cpu la464 -smp 2 -nographic -bios /usr/share/qemu/edk2-loongarch64-code.fd $qemuopts"

This would be better as:

  qemuopts="-machine virt -cpu la464 -smp 2 -nographic -L "${srcdir}"
-bios edk2-loongarch64-code.fd $qemuopts"

This allows a non-system bios to be used when placed in the grub source
directory and otherwise the file will be searched for in
/usr/share/qemu and other system paths.

> +	disk="device virtio-blk-pci,drive=hd1 -drive if=none,id=hd1,file="
> +	serial_port=
> +	;;
>      *)
>  	boot=hd
>  	qemu=qemu-system-i386
> @@ -395,6 +404,8 @@ fi
>  if [ x$boot = xhd ]; then
>      if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm64-efi ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm-efi ]; then
>  	device="device virtio-blk-device,drive=hd0 -drive if=none,id=hd0,file="
> +    elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = loongarch64-efi ]; then
> +	device="device virtio-blk-pci,drive=hd0 -drive if=none,id=hd0,file="
>      elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = mips-arc ]; then
>  	device="hdb "
>      else
> @@ -405,6 +416,8 @@ fi
>  if [ x$boot = xcd ]; then
>      if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm64-efi ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm-efi ]; then
>  	device="device virtio-blk-device,drive=cd0 -drive if=none,id=cd0,media=cdrom,file="
> +    elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = loongarch64-efi ]; then
> +	device="device virtio-blk-pci,drive=cd0 -drive if=none,id=cd0,media=cdrom,file="
>      elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = powerpc-ieee1275 ] && [ x$pseries != xy ] ; then
>  	device="-drive if=ide,media=cdrom,file="
>      else
> @@ -509,6 +522,9 @@ elif [ x$boot = xemu ]; then
>      test -n "$debug" || rm -rf "$rootdir"
>      test -n "$debug" || rm -f "$roottar"
>  else
> +    if [ -n "$debug" ]; then
> +      echo "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} >> /tmp/grub-shell.run
> +    fi

This change should not be in this patch series. I have similar
functionality that should get included in the grub-shell patch series I
have pending review.

Glenn

>      timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} | cat | tr -d "\r" | do_trim
>  fi
>  if [ x$boot = xcoreboot ]; then


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

* Re: [PATCH v5 0/9] Add support for LoongArch
  2022-07-30  6:43   ` 武校田
@ 2022-08-01 22:44     ` Glenn Washburn
  2022-08-02  4:47       ` Xiaotian Wu
  0 siblings, 1 reply; 18+ messages in thread
From: Glenn Washburn @ 2022-08-01 22:44 UTC (permalink / raw)
  To: 武校田; +Cc: The development of GNU GRUB, git, daniel.kiper

On Sat, 30 Jul 2022 14:43:02 +0800 (GMT+08:00)
武校田 <wuxiaotian@loongson.cn> wrote:

> Thanks for your reply.
> 
> &gt; Thanks for doing this testing. What are the values passed for the
> &gt; configure options --build, --host, and --target?
> 
> I compiled it on my local machine, using the Archlinux 2022.03 LoongArch
> version, the iso and repository are here: https://mirrors.wsyu.edu.cn/loongarch/2022.03/

Ok, so to be clear, build, host, and target are all loongarch
arctitecture, correct?

> 
> &gt; Also, would you be able to run these tests again on a system with as
> &gt; many of the make check test prerequisites installed? They are listed in
> &gt; the INSTALL file in the repository root. This would allow the testing
> &gt; of various GRUB filesystem code which is not happening now (the reason
> &gt; many tests fail with ERROR).
> 
> I will check the dependencies required by grub-fs-tester, thanks.
> 
> &gt; There are two actual failure in the provided log. One is the functional
> &gt; test, which are not expected to be working. The other is the partmap
> &gt; test, which should be working. Its not clear exactly which sub-test of
> &gt; the partmap test is failing (due to output not being very verbose). If
> &gt; you add 'set -x' to the top of partmap_test and rerun the tests, I can
> &gt; get a clearer picture of what's going on.
> &gt; 
> &gt; Glenn
> &gt; 
> 
> The details of this partmap_test are as follows:
> 
> + echo 'Checking MSDOS partition types...'
> Checking MSDOS partition types...
> + create_disk_image /tmp/tmp.N6QvM6XPXY 64
> + name=/tmp/tmp.N6QvM6XPXY
> + size=64
> + rm -f /tmp/tmp.N6QvM6XPXY
> + dd if=/dev/zero of=/tmp/tmp.N6QvM6XPXY bs=512 count=1 seek=131071 status=noxfer
> 记录了1+0 的读入
> 记录了1+0 的写出
> + parted -a none -s /tmp/tmp.N6QvM6XPXY mklabel msdos
> + list_parts part_msdos /tmp/tmp.N6QvM6XPXY /tmp/tmp.dOULt2UJMN
> + mod=part_msdos
> + shift
> + imgfile=/tmp/tmp.N6QvM6XPXY
> + shift
> + outfile=/tmp/tmp.dOULt2UJMN
> + shift
> + ./grub-shell --disk=/tmp/tmp.N6QvM6XPXY --modules=part_msdos
> + echo ls
> WARNING: Image format was not specified for '/tmp/tmp.N6QvM6XPXY' and probing guessed raw.
>          Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
>          Specify the 'raw' format explicitly to remove the restrictions.
> WARNING: Image format was not specified for '/tmp/tmp.mQzmZs2ROc' and probing guessed raw.
>          Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
>          Specify the 'raw' format explicitly to remove the restrictions.
> + cat /tmp/tmp.dOULt2UJMN
> + tr -d '\n\r'
> (hd0) (hd1) (hd1,gpt3) (hd1,gpt2,msdos1) (hd1,gpt2) (hd1,gpt1) + echo
> 
> + check_output /tmp/tmp.dOULt2UJMN hd2
> + outfile=/tmp/tmp.dOULt2UJMN
> + shift
> + for dsk in $@
> + grep '(hd2)' /tmp/tmp.dOULt2UJMN
> ++ cat /tmp/tmp.dOULt2UJMN
> + echo '(hd2): disk/partiton not found in: (hd0) (hd1) (hd1,gpt3) (hd1,gpt2,msdos1) (hd1,gpt2) (hd1,gpt1) '
> (hd2): disk/partiton not found in: (hd0) (hd1) (hd1,gpt3) (hd1,gpt2,msdos1) (hd1,gpt2) (hd1,gpt1) 
> + exit 1
> FAIL partmap_test (exit status: 1)
> 
> It looks like it can't find '(hd2)' in the output.

Ok, I believe my comments on patch #9 will successfully address this.

What is odd here is that the image file /tmp/tmp.N6QvM6XPXY appears to
be reused from a prior test run because at this point is should not
have gpt partitions, just an MSDOS header with no partitions. So
something seems off here.

Glenn

> 
> ------------------------------
> Best Regards
> Xiaotian Wu
> 
> 
> 本邮件及其附件含有龙芯中科的商业秘密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制或散发)本邮件及其附件中的信息。如果您错收本邮件,请您立即电话或邮件通知发件人并删除本邮件。 
> This email and its attachments contain confidential information from Loongson Technology , which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this email in error, please notify the sender by phone or email immediately and delete it. 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel


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

* Re: [PATCH v5 0/9] Add support for LoongArch
  2022-08-01 22:44     ` Glenn Washburn
@ 2022-08-02  4:47       ` Xiaotian Wu
  0 siblings, 0 replies; 18+ messages in thread
From: Xiaotian Wu @ 2022-08-02  4:47 UTC (permalink / raw)
  To: development; +Cc: The development of GNU GRUB, git, daniel.kiper


在 2022/8/2 上午6:44, Glenn Washburn 写道:
> On Sat, 30 Jul 2022 14:43:02 +0800 (GMT+08:00)
> 武校田 <wuxiaotian@loongson.cn> wrote:
>
>> Thanks for your reply.
>>
>> &gt; Thanks for doing this testing. What are the values passed for the
>> &gt; configure options --build, --host, and --target?
>>
>> I compiled it on my local machine, using the Archlinux 2022.03 LoongArch
>> version, the iso and repository are here: https://mirrors.wsyu.edu.cn/loongarch/2022.03/
> Ok, so to be clear, build, host, and target are all loongarch
> arctitecture, correct?
Yes, build, host and target are all loongarch arctitecture.
>> &gt; Also, would you be able to run these tests again on a system with as
>> &gt; many of the make check test prerequisites installed? They are listed in
>> &gt; the INSTALL file in the repository root. This would allow the testing
>> &gt; of various GRUB filesystem code which is not happening now (the reason
>> &gt; many tests fail with ERROR).
>>
>> I will check the dependencies required by grub-fs-tester, thanks.
>>
>> &gt; There are two actual failure in the provided log. One is the functional
>> &gt; test, which are not expected to be working. The other is the partmap
>> &gt; test, which should be working. Its not clear exactly which sub-test of
>> &gt; the partmap test is failing (due to output not being very verbose). If
>> &gt; you add 'set -x' to the top of partmap_test and rerun the tests, I can
>> &gt; get a clearer picture of what's going on.
>> &gt;
>> &gt; Glenn
>> &gt;
>>
>> The details of this partmap_test are as follows:
>>
>> + echo 'Checking MSDOS partition types...'
>> Checking MSDOS partition types...
>> + create_disk_image /tmp/tmp.N6QvM6XPXY 64
>> + name=/tmp/tmp.N6QvM6XPXY
>> + size=64
>> + rm -f /tmp/tmp.N6QvM6XPXY
>> + dd if=/dev/zero of=/tmp/tmp.N6QvM6XPXY bs=512 count=1 seek=131071 status=noxfer
>> 记录了1+0 的读入
>> 记录了1+0 的写出
>> + parted -a none -s /tmp/tmp.N6QvM6XPXY mklabel msdos
>> + list_parts part_msdos /tmp/tmp.N6QvM6XPXY /tmp/tmp.dOULt2UJMN
>> + mod=part_msdos
>> + shift
>> + imgfile=/tmp/tmp.N6QvM6XPXY
>> + shift
>> + outfile=/tmp/tmp.dOULt2UJMN
>> + shift
>> + ./grub-shell --disk=/tmp/tmp.N6QvM6XPXY --modules=part_msdos
>> + echo ls
>> WARNING: Image format was not specified for '/tmp/tmp.N6QvM6XPXY' and probing guessed raw.
>>           Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
>>           Specify the 'raw' format explicitly to remove the restrictions.
>> WARNING: Image format was not specified for '/tmp/tmp.mQzmZs2ROc' and probing guessed raw.
>>           Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
>>           Specify the 'raw' format explicitly to remove the restrictions.
>> + cat /tmp/tmp.dOULt2UJMN
>> + tr -d '\n\r'
>> (hd0) (hd1) (hd1,gpt3) (hd1,gpt2,msdos1) (hd1,gpt2) (hd1,gpt1) + echo
>>
>> + check_output /tmp/tmp.dOULt2UJMN hd2
>> + outfile=/tmp/tmp.dOULt2UJMN
>> + shift
>> + for dsk in $@
>> + grep '(hd2)' /tmp/tmp.dOULt2UJMN
>> ++ cat /tmp/tmp.dOULt2UJMN
>> + echo '(hd2): disk/partiton not found in: (hd0) (hd1) (hd1,gpt3) (hd1,gpt2,msdos1) (hd1,gpt2) (hd1,gpt1) '
>> (hd2): disk/partiton not found in: (hd0) (hd1) (hd1,gpt3) (hd1,gpt2,msdos1) (hd1,gpt2) (hd1,gpt1)
>> + exit 1
>> FAIL partmap_test (exit status: 1)
>>
>> It looks like it can't find '(hd2)' in the output.
> Ok, I believe my comments on patch #9 will successfully address this.
>
> What is odd here is that the image file /tmp/tmp.N6QvM6XPXY appears to
> be reused from a prior test run because at this point is should not
> have gpt partitions, just an MSDOS header with no partitions. So
> something seems off here.

Ok, thank you for your comments in #9, I think I have fixed the issue, 
and partmap_test has passed.

-- 
Best Regards
Xiaotian Wu



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

* Re: [PATCH v5 9/9] tests: add support for LoongArch
  2022-08-01 22:33   ` Glenn Washburn
@ 2022-08-02  4:59     ` Xiaotian Wu
  0 siblings, 0 replies; 18+ messages in thread
From: Xiaotian Wu @ 2022-08-02  4:59 UTC (permalink / raw)
  To: The development of GNU GRUB, Glenn Washburn; +Cc: git, daniel.kiper


在 2022/8/2 上午6:33, Glenn Washburn 写道:
> On Fri, 29 Jul 2022 15:12:01 +0800
> Xiaotian Wu <wuxiaotian@loongson.cn> wrote:
>
>> Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
>> ---
>>   tests/ahci_test.in       |  2 +-
>>   tests/ehci_test.in       |  2 +-
>>   tests/ohci_test.in       |  2 +-
>>   tests/partmap_test.in    |  2 +-
>>   tests/pata_test.in       |  2 +-
>>   tests/uhci_test.in       |  2 +-
>>   tests/util/grub-shell.in | 16 ++++++++++++++++
>>   7 files changed, 22 insertions(+), 6 deletions(-)
>>
>> diff --git a/tests/ahci_test.in b/tests/ahci_test.in
>> index 6d2e61d4e..70646a24e 100644
>> --- a/tests/ahci_test.in
>> +++ b/tests/ahci_test.in
>> @@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>>       mips*-arc | mips*-qemu_mips)
>>   	exit 77;;
>>       # FIXME: No native drivers are available for those
>> -    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
>> +    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
>>   	exit 77;;
>>   esac
>>   
>> diff --git a/tests/ehci_test.in b/tests/ehci_test.in
>> index df671b4b6..bf823a5de 100644
>> --- a/tests/ehci_test.in
>> +++ b/tests/ehci_test.in
>> @@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>>       mips*-arc | mips*-qemu_mips)
>>   	exit 77;;
>>       # FIXME: No native drivers are available for those
>> -    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
>> +    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
>>   	exit 77;;
>>   esac
>>   
>> diff --git a/tests/ohci_test.in b/tests/ohci_test.in
>> index 741ad881f..a40d3bc0a 100644
>> --- a/tests/ohci_test.in
>> +++ b/tests/ohci_test.in
>> @@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>>       mips*-arc | mips*-qemu_mips)
>>   	exit 77;;
>>       # FIXME: No native drivers are available for those
>> -    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
>> +    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
>>   	exit 77;;
>>   esac
>>   
>> diff --git a/tests/partmap_test.in b/tests/partmap_test.in
>> index 4138e88fe..6db59ce38 100644
>> --- a/tests/partmap_test.in
>> +++ b/tests/partmap_test.in
>> @@ -90,7 +90,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>>       mipsel-arc)
>>   	disk=arc/scsi0/disk0/rdisk0
>>   	;;
>> -    arm*-efi)
>> +    arm*-efi|loongarch64-efi)
>>   	disk=hd2
> The "loongarch64-efi" pattern should be separate and have "disk=hd1"
> because the drive is set to show up as hd1 in the grub-shell.in changes
> below.

This is indeed a issue. When I delete loongarch64-efi and use the 
default hd0 directly, the partmap_test passed.


>>   	;;
>>       *)
>> diff --git a/tests/pata_test.in b/tests/pata_test.in
>> index 31144a8fd..4d0e7d573 100644
>> --- a/tests/pata_test.in
>> +++ b/tests/pata_test.in
>> @@ -33,7 +33,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>>       i386-efi)
>>   	exit 77;;
>>       # FIXME: No native drivers are available for those
>> -    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
>> +    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
>>   	exit 77;;
>>       i386-ieee1275)
>>   	disk=hdb
>> diff --git a/tests/uhci_test.in b/tests/uhci_test.in
>> index 5aa5eb726..de199a281 100644
>> --- a/tests/uhci_test.in
>> +++ b/tests/uhci_test.in
>> @@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>>       mips*-arc | mips*-qemu_mips)
>>   	exit 77;;
>>       # FIXME: No native drivers are available for those
>> -    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi)
>> +    powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi | loongarch64-efi)
>>   	exit 77;;
>>   esac
>>   
>> diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
>> index 4828afb7c..b82c8243f 100644
>> --- a/tests/util/grub-shell.in
>> +++ b/tests/util/grub-shell.in
>> @@ -194,6 +194,15 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
>>   	disk="device virtio-blk-device,drive=hd1 -drive if=none,id=hd1,file="
>>   	serial_port=efi0
>>   	;;
>> +    loongarch64-efi)
>> +	qemu=qemu-system-loongarch64
>> +	boot=hd
>> +	console=console
>> +	trim=1
>> +	qemuopts="-machine virt -cpu la464 -smp 2 -nographic -bios /usr/share/qemu/edk2-loongarch64-code.fd $qemuopts"
> This would be better as:
>
>    qemuopts="-machine virt -cpu la464 -smp 2 -nographic -L "${srcdir}"
> -bios edk2-loongarch64-code.fd $qemuopts"
>
> This allows a non-system bios to be used when placed in the grub source
> directory and otherwise the file will be searched for in
> /usr/share/qemu and other system paths.
Ok, I will change it in the v6 patch series.
>> +	disk="device virtio-blk-pci,drive=hd1 -drive if=none,id=hd1,file="
>> +	serial_port=
>> +	;;
>>       *)
>>   	boot=hd
>>   	qemu=qemu-system-i386
>> @@ -395,6 +404,8 @@ fi
>>   if [ x$boot = xhd ]; then
>>       if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm64-efi ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm-efi ]; then
>>   	device="device virtio-blk-device,drive=hd0 -drive if=none,id=hd0,file="
>> +    elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = loongarch64-efi ]; then
>> +	device="device virtio-blk-pci,drive=hd0 -drive if=none,id=hd0,file="
>>       elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = mips-arc ]; then
>>   	device="hdb "
>>       else
>> @@ -405,6 +416,8 @@ fi
>>   if [ x$boot = xcd ]; then
>>       if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm64-efi ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm-efi ]; then
>>   	device="device virtio-blk-device,drive=cd0 -drive if=none,id=cd0,media=cdrom,file="
>> +    elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = loongarch64-efi ]; then
>> +	device="device virtio-blk-pci,drive=cd0 -drive if=none,id=cd0,media=cdrom,file="
>>       elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = powerpc-ieee1275 ] && [ x$pseries != xy ] ; then
>>   	device="-drive if=ide,media=cdrom,file="
>>       else
>> @@ -509,6 +522,9 @@ elif [ x$boot = xemu ]; then
>>       test -n "$debug" || rm -rf "$rootdir"
>>       test -n "$debug" || rm -f "$roottar"
>>   else
>> +    if [ -n "$debug" ]; then
>> +      echo "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} >> /tmp/grub-shell.run
>> +    fi
> This change should not be in this patch series. I have similar
> functionality that should get included in the grub-shell patch series I
> have pending review.
Sorry, this is my carelessness, this is just for my own debugging.
> Glenn
>
>>       timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} | cat | tr -d "\r" | do_trim
>>   fi
>>   if [ x$boot = xcoreboot ]; then
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

-- 
Best Regards
Xiaotian Wu



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

end of thread, other threads:[~2022-08-02  4:59 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-29  7:11 [PATCH v5 0/9] Add support for LoongArch Xiaotian Wu
2022-07-29  7:11 ` [PATCH v5 1/9] PE: Add LoongArch definitions Xiaotian Wu
2022-07-29  7:11 ` [PATCH v5 2/9] " Xiaotian Wu
2022-07-29  7:31   ` WANG Xuerui
2022-08-01  5:01     ` Xiaotian Wu
2022-07-29  7:11 ` [PATCH v5 3/9] LoongArch: Add setjmp implementation Xiaotian Wu
2022-07-29  7:11 ` [PATCH v5 4/9] LoongArch: Add early startup code Xiaotian Wu
2022-07-29  7:11 ` [PATCH v5 5/9] LoongArch: Add stubs for Linux loading commands Xiaotian Wu
2022-07-29  7:11 ` [PATCH v5 6/9] LoongArch: Add awareness for LoongArch relocations Xiaotian Wu
2022-07-29  7:11 ` [PATCH v5 7/9] LoongArch: Add auxiliary files Xiaotian Wu
2022-07-29  7:12 ` [PATCH v5 8/9] LoongArch: Add to build system Xiaotian Wu
2022-07-29  7:12 ` [PATCH v5 9/9] tests: add support for LoongArch Xiaotian Wu
2022-08-01 22:33   ` Glenn Washburn
2022-08-02  4:59     ` Xiaotian Wu
2022-07-30  5:21 ` [PATCH v5 0/9] Add " Glenn Washburn
2022-07-30  6:43   ` 武校田
2022-08-01 22:44     ` Glenn Washburn
2022-08-02  4:47       ` 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.