diff mbox series

[15/16] efi: LoongArch: Define LoongArch bits everywhere

Message ID 20240522-loongarch-v1-15-1407e0b69678@flygoat.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series LoongArch initial support | expand

Commit Message

Jiaxun Yang May 22, 2024, 3:34 p.m. UTC
They are all coming from UEFI spec, Microsoft PE sepc,
or IANA websites.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 boot/bootmeth_efi.c                               | 2 ++
 include/asm-generic/pe.h                          | 2 ++
 include/config_distro_bootcmd.h                   | 5 +++++
 include/efi_default_filename.h                    | 2 ++
 lib/efi_loader/efi_image_loader.c                 | 7 +++++++
 lib/efi_loader/efi_runtime.c                      | 4 ++++
 lib/efi_selftest/efi_selftest_miniapp_exception.c | 2 ++
 7 files changed, 24 insertions(+)

Comments

Heinrich Schuchardt May 23, 2024, 4:14 p.m. UTC | #1
On 22.05.24 17:34, Jiaxun Yang wrote:
> They are all coming from UEFI spec, Microsoft PE sepc,

%s/PE sepc/PE-COFF specification/

> or IANA websites.
>
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
>   boot/bootmeth_efi.c                               | 2 ++
>   include/asm-generic/pe.h                          | 2 ++
>   include/config_distro_bootcmd.h                   | 5 +++++
>   include/efi_default_filename.h                    | 2 ++
>   lib/efi_loader/efi_image_loader.c                 | 7 +++++++
>   lib/efi_loader/efi_runtime.c                      | 4 ++++
>   lib/efi_selftest/efi_selftest_miniapp_exception.c | 2 ++
>   7 files changed, 24 insertions(+)
>
> diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c
> index aebc5207fc01..b0207dac49c5 100644
> --- a/boot/bootmeth_efi.c
> +++ b/boot/bootmeth_efi.c
> @@ -41,6 +41,8 @@ static int get_efi_pxe_arch(void)
>   		return 0x19;
>   	else if (IS_ENABLED(CONFIG_ARCH_RV64I))
>   		return 0x1b;
> +	else if (IS_ENABLED(CONFIG_ARCH_LA64))
> +		return 0x27;
>   	else if (IS_ENABLED(CONFIG_SANDBOX))
>   		return 0;	/* not used */
>
> diff --git a/include/asm-generic/pe.h b/include/asm-generic/pe.h
> index cd5b6ad62bf0..fb93f2621715 100644
> --- a/include/asm-generic/pe.h
> +++ b/include/asm-generic/pe.h
> @@ -38,6 +38,8 @@
>   #define IMAGE_FILE_MACHINE_ARM64		0xaa64
>   #define IMAGE_FILE_MACHINE_RISCV32		0x5032
>   #define IMAGE_FILE_MACHINE_RISCV64		0x5064
> +#define IMAGE_FILE_MACHINE_LOONGARCH32	0x6232
> +#define IMAGE_FILE_MACHINE_LOONGARCH64	0x6264
>
>   /* Header magic constants */
>   #define IMAGE_NT_OPTIONAL_HDR32_MAGIC		0x010b
> diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h
> index 2a136b96a6d9..f8c3a4bb70ae 100644
> --- a/include/config_distro_bootcmd.h
> +++ b/include/config_distro_bootcmd.h
> @@ -118,6 +118,8 @@
>   #define BOOTEFI_NAME "bootriscv32.efi"
>   #elif defined(CONFIG_ARCH_RV64I)
>   #define BOOTEFI_NAME "bootriscv64.efi"
> +#elif defined(CONFIG_ARCH_LA64)
> +#define BOOTEFI_NAME "bootloongarch64.efi"
>   #endif
>   #endif
>
> @@ -366,6 +368,9 @@
>   #elif defined(CONFIG_ARCH_RV64I) || ((defined(__riscv) && __riscv_xlen == 64))
>   #define BOOTENV_EFI_PXE_ARCH "0x1b"
>   #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00027:UNDI:003000"
> +#elif defined(CONFIG_ARCH_LA64) || defined(__loongarch64)

Looking at
https://loongson.github.io/LoongArch-Documentation/LoongArch-toolchain-conventions-EN.html:

There the following symbols are mentioned:

__loongarch__
__loongarch_grlen


Table 15.
C/C++ Built-in Macros Provided for Compatibility with Historical Code
marks __loongarch64 as deprecated.

> +#define BOOTENV_EFI_PXE_ARCH "0x27"
> +#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00039:UNDI:003000"

Where are the 32bit defines?

Cf.
https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml

0x00 0x25 	LoongArch 32-bit UEFI
0x00 0x26 	LoongArch 32-bit UEFI boot from http
0x00 0x27 	LoongArch 64-bit UEFI
0x00 0x28 	LoongArch 64-bit UEFI boot from http

>   #elif defined(CONFIG_SANDBOX)
>   # error "sandbox EFI support is only supported on ARM and x86"
>   #else
> diff --git a/include/efi_default_filename.h b/include/efi_default_filename.h
> index 77932984b557..fac25039fd31 100644
> --- a/include/efi_default_filename.h
> +++ b/include/efi_default_filename.h
> @@ -47,6 +47,8 @@
>   #define BOOTEFI_NAME "BOOTRISCV32.EFI"
>   #elif defined(CONFIG_ARCH_RV64I)
>   #define BOOTEFI_NAME "BOOTRISCV64.EFI"
> +#elif defined(CONFIG_ARCH_LA64)
> +#define BOOTEFI_NAME "BOOTLOONGARCH64.EFI"
>   #else
>   #error Unsupported UEFI architecture
>   #endif
> diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c
> index 604243603289..cb0619f27e8a 100644
> --- a/lib/efi_loader/efi_image_loader.c
> +++ b/lib/efi_loader/efi_image_loader.c
> @@ -50,6 +50,13 @@ static int machines[] = {
>   #if defined(__riscv) && (__riscv_xlen == 64)
>   	IMAGE_FILE_MACHINE_RISCV64,
>   #endif
> +
> +#if defined(__loongarch64)

marks __loongarch64 is deprecated.

> +	IMAGE_FILE_MACHINE_LOONGARCH64,
> +#endif
> +#if defined(__loongarch32)

ditto

> +	IMAGE_FILE_MACHINE_LOONGARCH32,
> +#endif
>   	0 };
>
>   /**
> diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
> index 011bcd04836d..45bdf45b5812 100644
> --- a/lib/efi_loader/efi_runtime.c
> +++ b/lib/efi_loader/efi_runtime.c
> @@ -76,6 +76,10 @@ struct dyn_sym {
>   #else
>   #error unknown riscv target
>   #endif
> +#elif defined(__loongarch__)
> +#define R_RELATIVE	R_LARCH_RELATIVE
> +#define R_MASK		0xffffffffULL
> +#define IS_RELA		1
>   #else
>   #error Need to add relocation awareness
>   #endif
> diff --git a/lib/efi_selftest/efi_selftest_miniapp_exception.c b/lib/efi_selftest/efi_selftest_miniapp_exception.c
> index f668cdac4ab2..1e500a5ccc35 100644
> --- a/lib/efi_selftest/efi_selftest_miniapp_exception.c
> +++ b/lib/efi_selftest/efi_selftest_miniapp_exception.c
> @@ -35,6 +35,8 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
>   	asm volatile (".word 0xffffffff\n");
>   #elif defined(CONFIG_X86)
>   	asm volatile (".word 0xffff\n");
> +#elif defined(CONFIG_LOONGARCH)
> +	asm volatile ("break 0xf\n");

Can we use an undefined instruction here as for the other architectures,
please.

Best regards

Heinrich

>   #elif defined(CONFIG_SANDBOX)
>   #if (HOST_ARCH == HOST_ARCH_ARM || HOST_ARCH == HOST_ARCH_AARCH64)
>   	asm volatile (".word 0xe7f7defb\n");
>
Jiaxun Yang May 23, 2024, 4:25 p.m. UTC | #2
在2024年5月23日五月 下午5:14,Heinrich Schuchardt写道:
[...]
> Looking at
> https://loongson.github.io/LoongArch-Documentation/LoongArch-toolchain-conventions-EN.html:
>
> There the following symbols are mentioned:
>
> __loongarch__
> __loongarch_grlen
>
>
> Table 15.
> C/C++ Built-in Macros Provided for Compatibility with Historical Code
> marks __loongarch64 as deprecated.

Thanks, will use new macros instead.

>
>> +#define BOOTENV_EFI_PXE_ARCH "0x27"
>> +#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00039:UNDI:003000"
>
> Where are the 32bit defines?

Since we don't have CONFIG_ARCH_LA32 in U-Boot yet I leave 32 bit alone.
Those will need to be added when we get 32-bit ready.

>
> Cf.
> https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml
>
> 0x00 0x25 	LoongArch 32-bit UEFI
> 0x00 0x26 	LoongArch 32-bit UEFI boot from http
> 0x00 0x27 	LoongArch 64-bit UEFI
> 0x00 0x28 	LoongArch 64-bit UEFI boot from http
>
[...]
>> +#elif defined(CONFIG_LOONGARCH)
>> +	asm volatile ("break 0xf\n");
>
> Can we use an undefined instruction here as for the other architectures,
> please.

LoongArch have way too many hidden opcodes that is not documented & will
not trigger exception. It's pretty hard for me to identify an opcode that
can trigger exception on all hardware (and including future hardware).

Meanwhile, breakpoint instruction with an invalid hint can always generate
an SIGILL.

Thanks
>
> Best regards
>
> Heinrich
>
>>   #elif defined(CONFIG_SANDBOX)
>>   #if (HOST_ARCH == HOST_ARCH_ARM || HOST_ARCH == HOST_ARCH_AARCH64)
>>   	asm volatile (".word 0xe7f7defb\n");
>>
diff mbox series

Patch

diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c
index aebc5207fc01..b0207dac49c5 100644
--- a/boot/bootmeth_efi.c
+++ b/boot/bootmeth_efi.c
@@ -41,6 +41,8 @@  static int get_efi_pxe_arch(void)
 		return 0x19;
 	else if (IS_ENABLED(CONFIG_ARCH_RV64I))
 		return 0x1b;
+	else if (IS_ENABLED(CONFIG_ARCH_LA64))
+		return 0x27;
 	else if (IS_ENABLED(CONFIG_SANDBOX))
 		return 0;	/* not used */
 
diff --git a/include/asm-generic/pe.h b/include/asm-generic/pe.h
index cd5b6ad62bf0..fb93f2621715 100644
--- a/include/asm-generic/pe.h
+++ b/include/asm-generic/pe.h
@@ -38,6 +38,8 @@ 
 #define IMAGE_FILE_MACHINE_ARM64		0xaa64
 #define IMAGE_FILE_MACHINE_RISCV32		0x5032
 #define IMAGE_FILE_MACHINE_RISCV64		0x5064
+#define IMAGE_FILE_MACHINE_LOONGARCH32	0x6232
+#define IMAGE_FILE_MACHINE_LOONGARCH64	0x6264
 
 /* Header magic constants */
 #define IMAGE_NT_OPTIONAL_HDR32_MAGIC		0x010b
diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h
index 2a136b96a6d9..f8c3a4bb70ae 100644
--- a/include/config_distro_bootcmd.h
+++ b/include/config_distro_bootcmd.h
@@ -118,6 +118,8 @@ 
 #define BOOTEFI_NAME "bootriscv32.efi"
 #elif defined(CONFIG_ARCH_RV64I)
 #define BOOTEFI_NAME "bootriscv64.efi"
+#elif defined(CONFIG_ARCH_LA64)
+#define BOOTEFI_NAME "bootloongarch64.efi"
 #endif
 #endif
 
@@ -366,6 +368,9 @@ 
 #elif defined(CONFIG_ARCH_RV64I) || ((defined(__riscv) && __riscv_xlen == 64))
 #define BOOTENV_EFI_PXE_ARCH "0x1b"
 #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00027:UNDI:003000"
+#elif defined(CONFIG_ARCH_LA64) || defined(__loongarch64)
+#define BOOTENV_EFI_PXE_ARCH "0x27"
+#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00039:UNDI:003000"
 #elif defined(CONFIG_SANDBOX)
 # error "sandbox EFI support is only supported on ARM and x86"
 #else
diff --git a/include/efi_default_filename.h b/include/efi_default_filename.h
index 77932984b557..fac25039fd31 100644
--- a/include/efi_default_filename.h
+++ b/include/efi_default_filename.h
@@ -47,6 +47,8 @@ 
 #define BOOTEFI_NAME "BOOTRISCV32.EFI"
 #elif defined(CONFIG_ARCH_RV64I)
 #define BOOTEFI_NAME "BOOTRISCV64.EFI"
+#elif defined(CONFIG_ARCH_LA64)
+#define BOOTEFI_NAME "BOOTLOONGARCH64.EFI"
 #else
 #error Unsupported UEFI architecture
 #endif
diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c
index 604243603289..cb0619f27e8a 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -50,6 +50,13 @@  static int machines[] = {
 #if defined(__riscv) && (__riscv_xlen == 64)
 	IMAGE_FILE_MACHINE_RISCV64,
 #endif
+
+#if defined(__loongarch64)
+	IMAGE_FILE_MACHINE_LOONGARCH64,
+#endif
+#if defined(__loongarch32)
+	IMAGE_FILE_MACHINE_LOONGARCH32,
+#endif
 	0 };
 
 /**
diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index 011bcd04836d..45bdf45b5812 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -76,6 +76,10 @@  struct dyn_sym {
 #else
 #error unknown riscv target
 #endif
+#elif defined(__loongarch__)
+#define R_RELATIVE	R_LARCH_RELATIVE
+#define R_MASK		0xffffffffULL
+#define IS_RELA		1
 #else
 #error Need to add relocation awareness
 #endif
diff --git a/lib/efi_selftest/efi_selftest_miniapp_exception.c b/lib/efi_selftest/efi_selftest_miniapp_exception.c
index f668cdac4ab2..1e500a5ccc35 100644
--- a/lib/efi_selftest/efi_selftest_miniapp_exception.c
+++ b/lib/efi_selftest/efi_selftest_miniapp_exception.c
@@ -35,6 +35,8 @@  efi_status_t EFIAPI efi_main(efi_handle_t handle,
 	asm volatile (".word 0xffffffff\n");
 #elif defined(CONFIG_X86)
 	asm volatile (".word 0xffff\n");
+#elif defined(CONFIG_LOONGARCH)
+	asm volatile ("break 0xf\n");
 #elif defined(CONFIG_SANDBOX)
 #if (HOST_ARCH == HOST_ARCH_ARM || HOST_ARCH == HOST_ARCH_AARCH64)
 	asm volatile (".word 0xe7f7defb\n");