[PATCH v14 01/10] PE: Add LoongArch definitions

2023-04-07 Thread Xiaotian Wu
Add PE machine types [1] and relocation types [2] for LoongArch to
the current in-repo definitions.

[1]: 
https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types
[2]: 
https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#base-relocation-types

Signed-off-by: Zhou Yang 
Signed-off-by: Xiaotian Wu 
---
 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 98c4ff177..101859af1 100644
--- a/include/grub/efi/pe32.h
+++ b/include/grub/efi/pe32.h
@@ -88,6 +88,8 @@ struct grub_pe32_coff_header
 #define GRUB_PE32_MACHINE_X86_64   0x8664
 #define GRUB_PE32_MACHINE_ARMTHUMB_MIXED   0x01c2
 #define GRUB_PE32_MACHINE_ARM640xAA64
+#define GRUB_PE32_MACHINE_LOONGARCH32  0x6232
+#define GRUB_PE32_MACHINE_LOONGARCH64  0x6264
 #define GRUB_PE32_MACHINE_RISCV32  0x5032
 #define GRUB_PE32_MACHINE_RISCV64  0x5064
 
@@ -291,22 +293,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_LOW2
-#define GRUB_PE32_REL_BASED_HIGHLOW3
-#define GRUB_PE32_REL_BASED_HIGHADJ4
-#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_SECTION6
-#define GRUB_PE32_REL_BASED_REL7
-#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_LOW2
+#define GRUB_PE32_REL_BASED_HIGHLOW3
+#define GRUB_PE32_REL_BASED_HIGHADJ4
+#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_SECTION6
+#define GRUB_PE32_REL_BASED_REL7
+#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_LA8
+#define GRUB_PE32_REL_BASED_LOONGARCH64_MARK_LA8
+#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.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v14 00/10] Add LoongArch support

2023-04-07 Thread 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 adds support for the Loongarch architecture, which can
compile and run the linux-6.2+ kernel on LoongArch.

Please review the patches, thank you.

Xiaotian Wu (10):
  PE: Add LoongArch definitions
  ELF: Add LoongArch definitions
  LoongArch: Add setjmp implementation
  LoongArch: Add early startup code
  LoongArch: Add support for ELF psABI v1.00 relocations
  LoongArch: Add support for ELF psABI v2.00 relocations
  LoongArch: Add auxiliary files
  LoongArch: Add to build system
  tests: Fix timezone inconsistency in squashfs_test
  tests: Add LoongArch to various test cases

 Makefile.util.def|   1 +
 configure.ac |  23 +-
 gentpl.py|  27 +--
 grub-core/Makefile.am|   6 +
 grub-core/Makefile.core.def  |  17 ++
 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  | 150 +
 grub-core/kern/loongarch64/dl_helper.c   | 261 +++
 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 +
 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   |  30 +++
 include/grub/loongarch64/efi/memory.h|  24 +++
 include/grub/loongarch64/reloc.h | 113 ++
 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/pata_test.in   |   2 +-
 tests/uhci_test.in   |   2 +-
 tests/util/grub-fs-tester.in |   2 +-
 tests/util/grub-shell.in |  14 ++
 util/grub-install-common.c   |  49 ++---
 util/grub-install.c  |  16 ++
 util/grub-mkimagexx.c| 126 +++
 util/grub-mknetdir.c |   1 +
 util/grub-mkrescue.c |   8 +
 util/grub-module-verifier.c  |  33 +++
 util/mkimage.c   |  16 ++
 41 files changed, 1259 insertions(+), 67 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 include/grub/loongarch64/efi/memory.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.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v14 04/10] LoongArch: Add early startup code

2023-04-07 Thread Xiaotian Wu
On entry, we need to save the system table pointer as well as our image
handle. Add an early startup file that saves them and then brings us
into our main function.

Signed-off-by: Zhou Yang 
Signed-off-by: Xiaotian Wu 
---
 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 0..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 .
+ */
+
+#include 
+
+   .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.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v14 02/10] ELF: Add LoongArch definitions

2023-04-07 Thread Xiaotian Wu
Add ELF e_machine ID [1] and relocations types [2] for LoongArch to
the current in-repo definitions.

[1]: 
https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_e_machine_identifies_the_machine
[2]: 
https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_relocations

Signed-off-by: Zhou Yang 
Signed-off-by: Xiaotian Wu 
---
 include/grub/elf.h | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/include/grub/elf.h b/include/grub/elf.h
index e6f073bc9..c36d7dab2 100644
--- a/include/grub/elf.h
+++ b/include/grub/elf.h
@@ -252,6 +252,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
@@ -2536,6 +2537,28 @@ typedef Elf32_Addr Elf32_Conflict;
 #define R_RISCV_SET32   56
 #define R_RISCV_32_PCREL57
 
+/* 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_ABSOLUTE23
+#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_538
+#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_S242
+#define R_LARCH_SOP_POP_32_S_5_2043
+#define R_LARCH_SOP_POP_32_S_0_5_10_16_S2 44
+#define R_LARCH_SOP_POP_32_S_0_10_10_16_S245
+
 extern grub_err_t grub_elf32_get_shnum (Elf32_Ehdr *e, Elf32_Shnum *shnum);
 extern grub_err_t grub_elf32_get_shstrndx (Elf32_Ehdr *e, Elf32_Word 
*shstrndx);
 extern grub_err_t grub_elf32_get_phnum (Elf32_Ehdr *e, Elf32_Word *phnum);
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v14 03/10] LoongArch: Add setjmp implementation

2023-04-07 Thread Xiaotian Wu
This patch adds a setjmp implementation for LoongArch.

Signed-off-by: Zhou Yang 
Signed-off-by: Sun Haiyong 
Signed-off-by: Xiaotian Wu 
---
 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 0..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 .
+ */
+
+#include 
+
+   .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..ffb26df79 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(__loongarch_lp64)
+#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 0..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 .
+ */
+
+#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.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v14 05/10] LoongArch: Add support for ELF psABI v1.00 relocations

2023-04-07 Thread Xiaotian Wu
This patch adds support of the stack-based LoongArch relocations
throughout grub, including tools, dynamic linkage, and support for
conversion of ELF relocations into PE ones. A stack machine is required
to handle these per the spec [1] (see the R_LARCH_SOP types), of which
a simple implementation is included.

These relocations are produced by binutils 2.38 and 2.39, while the
newer v2.00 relocs require more recent toolchain (binutils 2.40+ & gcc
13+, or LLVM 16+). GCC 13 has not been officially released as of early
2023, so support for v1.00 relocs are expected to stay relevant for a
while.

[1]: 
https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_relocations

Signed-off-by: Zhou Yang 
Signed-off-by: Xiaotian Wu 
---
 grub-core/kern/dl.c|   9 +-
 grub-core/kern/loongarch64/dl.c| 102 +
 grub-core/kern/loongarch64/dl_helper.c | 202 +
 include/grub/dl.h  |   1 +
 include/grub/loongarch64/reloc.h   | 107 +
 util/grub-mkimagexx.c  |  79 ++
 util/grub-module-verifier.c|  26 
 7 files changed, 523 insertions(+), 3 deletions(-)
 create mode 100644 grub-core/kern/loongarch64/dl.c
 create mode 100644 grub-core/kern/loongarch64/dl_helper.c
 create mode 100644 include/grub/loongarch64/reloc.h

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 0..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 .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* 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-

[PATCH v14 06/10] LoongArch: Add support for ELF psABI v2.00 relocations

2023-04-07 Thread Xiaotian Wu
A new set of relocation types was added in the LoongArch ELF psABI v2.00
spec [1][2] to replace the stack-based scheme in v1.00. Toolchain
support is available from binutils 2.40 and gcc 13 onwards.

This patch adds support for the new relocation types, that are simpler
to handle (in particular, stack operations are gone). Support for the
v1.00 relocs are kept for now, for compatibility with older toolchains.

[1]: https://github.com/loongson/LoongArch-Documentation/pull/57
[2]: 
https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_appendix_revision_history

Signed-off-by: Xiaotian Wu 
---
 configure.ac   | 15 +++
 grub-core/kern/loongarch64/dl.c| 54 +--
 grub-core/kern/loongarch64/dl_helper.c | 59 ++
 include/grub/elf.h |  7 +++
 include/grub/loongarch64/reloc.h   |  6 +++
 util/grub-mkimagexx.c  | 49 -
 util/grub-module-verifier.c|  7 +++
 7 files changed, 193 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index ca42ff8f7..1ded95ca3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -860,6 +860,21 @@ 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 _mno_explicit_relocs works], 
[grub_cv_cc_mno_explicit_relocs], [
+CFLAGS="$TARGET_CFLAGS -mno-explicit-relocs -Werror"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+   [grub_cv_cc_mno_explicit_relocs=yes],
+   [grub_cv_cc_mno_explicit_relocs=no])
+  ])
+  if test "x$grub_cv_cc_mno_explicit_relocs" = xyes; then
+TARGET_CFLAGS="$TARGET_CFLAGS -mno-explicit-relocs -fno-plt"
+TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-explicit-relocs -fno-plt"
+  fi
+  TARGET_CFLAGS="$TARGET_CFLAGS -Wa,-mla-global-with-abs"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -Wa,-mla-global-with-abs"
+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)
diff --git a/grub-core/kern/loongarch64/dl.c b/grub-core/kern/loongarch64/dl.c
index 3a6aa91cd..47196a219 100644
--- a/grub-core/kern/loongarch64/dl.c
+++ b/grub-core/kern/loongarch64/dl.c
@@ -58,7 +58,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
rel = (Elf_Rel *) ((char *) rel + s->sh_entsize))
 {
   Elf_Sym *sym;
-  grub_uint64_t *place;
+  void *place;
   grub_uint64_t sym_addr;
 
   if (rel->r_offset >= seg->size)
@@ -72,12 +72,19 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
   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);
+  place = (void *) ((grub_addr_t)seg->addr + rel->r_offset);
 
   switch (ELF_R_TYPE (rel->r_info))
{
case R_LARCH_64:
- *place = sym_addr;
+ {
+   grub_uint64_t *abs_place = place;
+
+   grub_dprintf ("dl", "reloc_abs64 %p => 0x%016llx, %p\n",
+ place, (unsigned long long) sym_addr, abs_place);
+
+   *abs_place += (grub_uint64_t) sym_addr;
+ }
  break;
case R_LARCH_MARK_LA:
  break;
@@ -85,6 +92,47 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
case R_LARCH_SOP_PUSH_PLT_PCREL:
  grub_loongarch64_sop_push (&stack, sym_addr - (grub_uint64_t)place);
  break;
+   case R_LARCH_B26:
+ {
+   grub_uint32_t *abs_place = place;
+   grub_ssize_t off = sym_addr - (grub_addr_t) place;
+
+   grub_loongarch64_b26 (abs_place, off);
+ }
+ break;
+   case R_LARCH_ABS_HI20:
+ {
+   grub_uint32_t *abs_place = place;
+   grub_loongarch64_xxx_hi20 (abs_place, sym_addr);
+ }
+ break;
+   case R_LARCH_ABS64_LO20:
+ {
+   grub_uint32_t *abs_place = place;
+   grub_loongarch64_xxx64_lo20 (abs_place, sym_addr);
+ }
+ break;
+   case R_LARCH_ABS64_HI12:
+ {
+   grub_uint32_t *abs_place = place;
+   grub_loongarch64_xxx64_hi12 (abs_place, sym_addr);
+ }
+ break;
+   case R_LARCH_PCALA_HI20:
+ {
+   grub_uint32_t *abs_place = place;
+   grub_int32_t off = (((sym_addr + 0x800) & ~0xfffULL) - 
((grub_addr_t)place & ~0xfffULL));
+
+   grub_loongarch64_xxx_hi20 (abs_place, off);
+ }
+ break;
+   case R_LARCH_ABS_LO12:
+   case R_LARCH_PCALA_LO12:
+ {
+   grub_uint32_t *abs_place = place;
+   grub_loongarch64_xxx_lo12 (abs_place, sym_addr);
+ }
+ break;
GRUB_LOONGARCH64_RELOCATION (&stack, place, sym_addr)
default:
  

LUKS multiple passphrase retries

2023-04-07 Thread Simon Perry via Grub-devel

Hi there,

I've recently moved to using a LUKS2 encrypted boot and it's working 
great, however one of the frustrating things is that you get dropped to 
grub rescue after a single failed passphrase attempt.


I see there was a patch proposed back in 2019, but it didn't seem to 
progress any further (and the guy's git repo has since disappeared).


https://lists.gnu.org/archive/html/grub-devel/2019-08/msg00015.html

Anyway, I was wondering if any future consideration would be given to 
adding a feature allowing multiple retries when entering a passphrase?


Appreciate your time.

Cheers.

--
Simon Perry (aka Pezz)

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v14 07/10] LoongArch: Add auxiliary files

2023-04-07 Thread Xiaotian Wu
Add support for manipulating architectural cache and timers, and EFI
memory maps.

Signed-off-by: Zhou Yang 
Signed-off-by: Xiaotian Wu 
---
 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/time.h  | 28 +
 include/grub/loongarch64/types.h | 34 +++
 9 files changed, 239 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/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 3705b8b1b..ac13e95e9 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 0..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 .
+ */
+
+#include 
+#include 
+
+/* 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 0..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 .
+ */
+
+#include 
+
+   .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 0..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,
+ 

[PATCH v14 08/10] LoongArch: Add to build system

2023-04-07 Thread Xiaotian Wu
This patch adds LoongArch to the grub build system and various tools,
so grub can be built on LoongArch as a UEFI application.

Signed-off-by: Zhou Yang 
Signed-off-by: Xiaotian Wu 
---
 Makefile.util.def   |  1 +
 configure.ac|  8 +-
 gentpl.py   | 27 ++--
 grub-core/Makefile.am   |  6 +
 grub-core/Makefile.core.def | 17 +
 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, 113 insertions(+), 39 deletions(-)

diff --git a/Makefile.util.def b/Makefile.util.def
index beaef1168..fdbd58c8f 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 1ded95ca3..d9f088d12 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) ;;
@@ -1236,7 +1239,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"
@@ -2021,6 +2025,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 88abe5b0a..d0470b3b2 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"

[PATCH v14 09/10] tests: Fix timezone inconsistency in squashfs_test

2023-04-07 Thread Xiaotian Wu
The image timestamp was not returned in UTC, but the following logic
expected and used UTC.

This patch fixes the test failure like described below:

  unsquashfs -s 
/tmp/grub-fs-tester.20230407111703613257436.squash4_gzip.9R4/squash4_gzip_512_4096_1_0.img
  grep '^Creation'
  awk '{print $6 " " $7 " " $8 " " $9 " " $10; }'
  FSTIME='Fri Apr 7 11:17:05 2023'
  date -d 'Fri Apr 7 11:17:05 2023' -u '+%Y-%m-%d %H:%M:%S'
  FSTIME='2023-04-07 11:17:05'
  date -d '2023-04-07 11:17:05 UTC -1 second' -u '+%Y-%m-%d %H:%M:%S'
  FSTIMEM1='2023-04-07 11:17:04'
  date -d '2023-04-07 11:17:05 UTC -2 second' -u '+%Y-%m-%d %H:%M:%S'
  FSTIMEM2='2023-04-07 11:17:03'
  date -d '2023-04-07 11:17:05 UTC -3 second' -u '+%Y-%m-%d %H:%M:%S'
  FSTIMEM3='2023-04-07 11:17:02'
  grep -F 'Last modification time 2023-04-07 11:17:05'
  echo 'Device loop0: Filesystem type squash4 - Last modification time 
2023-04-07 03:17:05 Friday - Sector size 512B - Total size 10680KiB'
  echo 'Device loop0: Filesystem type squash4 - Last modification time 
2023-04-07 03:17:05 Friday - Sector size 512B - Total size 10680KiB'
  grep -F 'Last modification time 2023-04-07 11:17:04'
  echo 'Device loop0: Filesystem type squash4 - Last modification time 
2023-04-07 03:17:05 Friday - Sector size 512B - Total size 10680KiB'
  grep -F 'Last modification time 2023-04-07 11:17:03'
  echo 'Device loop0: Filesystem type squash4 - Last modification time 
2023-04-07 03:17:05 Friday - Sector size 512B - Total size 10680KiB'
  grep -F 'Last modification time 2023-04-07 11:17:02'
  echo FSTIME FAIL

Signed-off-by: Xiaotian Wu 
---
 tests/util/grub-fs-tester.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/util/grub-fs-tester.in b/tests/util/grub-fs-tester.in
index 064464eb2..64638d2e9 100644
--- a/tests/util/grub-fs-tester.in
+++ b/tests/util/grub-fs-tester.in
@@ -1454,7 +1454,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" 
"$MAXLOGSECSIZE" 1); do
# Creating the squash image may take more than a few
# seconds. Use the more accurate timestamp from the
# superblock.
-   FSTIME="$(unsquashfs -s "${FSIMAGEP}0.img" | grep 
^Creation | awk '{print $6 " " $7 " " $8 " " $9 " " $10; }')"
+   FSTIME="$(unsquashfs -UTC -s "${FSIMAGEP}0.img" | grep 
^Creation | awk '{print $6 " " $7 " " $8 " " $9 " " $10; }')"
FSTIME="$(date -d "$FSTIME" -u '+%Y-%m-%d %H:%M:%S')";;
*)
FSTIME="$(TZ=UTC ls --time-style="+%Y-%m-%d_%H:%M:%S" 
-l -d "${FSIMAGEP}0.img"|awk '{print $6; }'|sed 's,_, ,g')";;
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v14 10/10] tests: Add LoongArch to various test cases

2023-04-07 Thread Xiaotian Wu
The test results of running "make check" with qemu 7.2 are as follows:
  
  Testsuite summary for GRUB 2.11
  
  # TOTAL: 85
  # PASS:  57
  # SKIP:  8
  # XFAIL: 0
  # FAIL:  1
  # XPASS: 0
  # ERROR: 19
  

These ERROR cases need to be run as root user:
  ERROR: ext234_test
  ERROR: hfsplus_test
  ERROR: ntfs_test
  ERROR: reiserfs_test
  ERROR: fat_test
  ERROR: minixfs_test
  ERROR: xfs_test
  ERROR: f2fs_test
  ERROR: nilfs2_test
  ERROR: romfs_test
  ERROR: exfat_test
  ERROR: udf_test
  ERROR: hfs_test
  ERROR: jfs_test
  ERROR: btrfs_test
  ERROR: zfs_test
  ERROR: luks1_test
  ERROR: luks2_test
  ERROR: grub_cmd_cryptomount

These test cases are skipped:
  SKIP: pata_test
  SKIP: ahci_test
  SKIP: uhci_test
  SKIP: ohci_test
  SKIP: ehci_test
  SKIP: fddboot_test
  SKIP: netboot_test
  SKIP: pseries_test

This test case fails because of: qemu-system-loongarch64: ram_size must be 
greater than 1G.
  FAIL: grub_func_test

Signed-off-by: Xiaotian Wu 
---
 tests/ahci_test.in   |  2 +-
 tests/ehci_test.in   |  2 +-
 tests/ohci_test.in   |  2 +-
 tests/pata_test.in   |  2 +-
 tests/uhci_test.in   |  2 +-
 tests/util/grub-shell.in | 14 ++
 6 files changed, 19 insertions(+), 5 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/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 75f71dc1a..bbeb63ef4 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -208,6 +208,16 @@ 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-loongarch-cpu -smp 4 -nographic -m 
4G \
+ -bios /usr/share/edk2/loongarch64/QEMU_CODE.fd $qemuopts"
+   disk="device virtio-blk-pci,drive=hd1 -drive if=none,id=hd1,file="
+   serial_port=
+   ;;
 *)
boot=hd
qemu=qemu-system-i386
@@ -423,6 +433,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