[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v8 20/29] linux-user: Add LoongArch elf support
From: |
Song Gao |
Subject: |
[PATCH v8 20/29] linux-user: Add LoongArch elf support |
Date: |
Mon, 1 Nov 2021 17:51:42 +0800 |
Signed-off-by: Song Gao <gaosong@loongson.cn>
Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
---
include/elf.h | 2 ++
linux-user/elfload.c | 58 +++++++++++++++++++++++++++++++++++++
linux-user/loongarch64/target_elf.h | 14 +++++++++
3 files changed, 74 insertions(+)
create mode 100644 linux-user/loongarch64/target_elf.h
diff --git a/include/elf.h b/include/elf.h
index 811bf4a..3a4bcb6 100644
--- a/include/elf.h
+++ b/include/elf.h
@@ -182,6 +182,8 @@ typedef struct mips_elf_abiflags_v0 {
#define EM_NANOMIPS 249 /* Wave Computing nanoMIPS */
+#define EM_LOONGARCH 258 /* LoongArch */
+
/*
* This is an interim value that we will use until the committee comes
* up with a final number.
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index f9b8261..b703300 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -914,6 +914,64 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
const CPUPPCState *en
#endif
+#ifdef TARGET_LOONGARCH64
+
+#define ELF_START_MMAP 0x80000000
+
+#define ELF_CLASS ELFCLASS64
+#define ELF_ARCH EM_LOONGARCH
+
+#define elf_check_arch(x) ((x) == EM_LOONGARCH)
+static inline void init_thread(struct target_pt_regs *regs,
+ struct image_info *infop)
+{
+ regs->csr_crmd = 2 << 3;
+ regs->csr_era = infop->entry;
+ regs->regs[3] = infop->start_stack;
+}
+
+/* See linux kernel: arch/loongarch/include/asm/elf.h. */
+#define ELF_NREG 45
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+/* See linux kernel: arch/loongarch/include/asm/reg.h. */
+enum {
+ TARGET_EF_R0 = 0,
+ TARGET_EF_CSR_ERA = TARGET_EF_R0 + 32,
+ TARGET_EF_CSR_BADVADDR = TARGET_EF_R0 + 33,
+};
+
+/* See linux kernel: arch/loongarch/kernel/process.c:loongarch_dump_regs64. */
+static void elf_core_copy_regs(target_elf_gregset_t *regs,
+ const CPULoongArchState *env)
+{
+ int i;
+
+ for (i = 0; i < TARGET_EF_R0; i++) {
+ (*regs)[i] = 0;
+ }
+ (*regs)[TARGET_EF_R0] = 0;
+
+ for (i = 1; i < ARRAY_SIZE(env->gpr); i++) {
+ (*regs)[TARGET_EF_R0 + i] = tswapreg(env->gpr[i]);
+ }
+
+ (*regs)[TARGET_EF_CSR_ERA] = tswapreg(env->pc);
+ (*regs)[TARGET_EF_CSR_BADVADDR] = tswapreg(env->badaddr);
+}
+
+#define USE_ELF_CORE_DUMP
+#define ELF_EXEC_PAGESIZE 4096
+
+#define ELF_HWCAP get_elf_hwcap()
+
+static uint32_t get_elf_hwcap(void)
+{
+ return 0;
+}
+
+#endif /* TARGET_LOONGARCH64 */
+
#ifdef TARGET_MIPS
#define ELF_START_MMAP 0x80000000
diff --git a/linux-user/loongarch64/target_elf.h
b/linux-user/loongarch64/target_elf.h
new file mode 100644
index 0000000..7c88394
--- /dev/null
+++ b/linux-user/loongarch64/target_elf.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2021 Loongson Technology Corporation Limited
+ *
+ * SPDX-License-Identifier: LGPL-2.1+
+ */
+
+
+#ifndef LOONGARCH_TARGET_ELF_H
+#define LOONGARCH_TARGET_ELF_H
+static inline const char *cpu_get_model(uint32_t eflags)
+{
+ return "Loongson-3A5000";
+}
+#endif
--
1.8.3.1
- [PATCH v8 09/29] target/loongarch: Add fixed point extra instruction translation, (continued)
- [PATCH v8 09/29] target/loongarch: Add fixed point extra instruction translation, Song Gao, 2021/11/01
- [PATCH v8 08/29] target/loongarch: Add fixed point atomic instruction translation, Song Gao, 2021/11/01
- [PATCH v8 10/29] target/loongarch: Add floating point arithmetic instruction translation, Song Gao, 2021/11/01
- [PATCH v8 12/29] target/loongarch: Add floating point conversion instruction translation, Song Gao, 2021/11/01
- [PATCH v8 11/29] target/loongarch: Add floating point comparison instruction translation, Song Gao, 2021/11/01
- [PATCH v8 14/29] target/loongarch: Add floating point load/store instruction translation, Song Gao, 2021/11/01
- [PATCH v8 24/29] default-configs: Add loongarch linux-user support, Song Gao, 2021/11/01
- [PATCH v8 17/29] linux-user: Add LoongArch generic header files, Song Gao, 2021/11/01
- [PATCH v8 29/29] linux-user: Add safe syscall handling for loongarch64 hosts, Song Gao, 2021/11/01
- [PATCH v8 15/29] target/loongarch: Add branch instruction translation, Song Gao, 2021/11/01
- [PATCH v8 20/29] linux-user: Add LoongArch elf support,
Song Gao <=
- [PATCH v8 26/29] target/loongarch: 'make check-tcg' support, Song Gao, 2021/11/01
- [PATCH v8 13/29] target/loongarch: Add floating point move instruction translation, Song Gao, 2021/11/01
- [PATCH v8 18/29] linux-user: Add LoongArch specific structures, Song Gao, 2021/11/01
- [PATCH v8 16/29] target/loongarch: Add disassembler, Song Gao, 2021/11/01
- [PATCH v8 19/29] linux-user: Add LoongArch signal support, Song Gao, 2021/11/01
- [PATCH v8 22/29] linux-user: Add LoongArch cpu_loop support, Song Gao, 2021/11/01
- [PATCH v8 28/29] accel/tcg/user-exec: Implement CPU-specific signal handler for loongarch64 hosts, Song Gao, 2021/11/01