All of lore.kernel.org
 help / color / mirror / Atom feed
From: imp@bsdimp.com
To: qemu-devel@nongnu.org
Cc: kevans@freebsd.org,
	Richard Henderson <richard.henderson@linaro.org>,
	Warner Losh <imp@bsdimp.com>
Subject: [PATCH v3 06/43] bsd-user: Remove all non-x86 code from elfload.c
Date: Thu,  2 Sep 2021 17:46:52 -0600	[thread overview]
Message-ID: <20210902234729.76141-7-imp@bsdimp.com> (raw)
In-Reply-To: <20210902234729.76141-1-imp@bsdimp.com>

From: Warner Losh <imp@bsdimp.com>

bsd-user only builds x86 at the moment. Remove all non x86 code from
elfload.c. We'll move the x86 code to {i386,x86_64}/target_arch_elf.h
and bring it that support code from the forked bsd-user when the time
comes.

Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 bsd-user/elfload.c | 347 +--------------------------------------------
 1 file changed, 2 insertions(+), 345 deletions(-)

diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index ae62f3aab3..fffa24f041 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -23,15 +23,6 @@
 #include "disas/disas.h"
 #include "qemu/path.h"
 
-#ifdef _ARCH_PPC64
-#undef ARCH_DLINFO
-#undef ELF_PLATFORM
-#undef ELF_HWCAP
-#undef ELF_CLASS
-#undef ELF_DATA
-#undef ELF_ARCH
-#endif
-
 /* from personality.h */
 
 /*
@@ -144,7 +135,7 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
     }
 }
 
-#else
+#else /* !TARGET_X86_64 */
 
 #define ELF_START_MMAP 0x80000000
 
@@ -174,343 +165,13 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
        A value of 0 tells we have no such handler.  */
     regs->edx = 0;
 }
-#endif
-
-#define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE       4096
-
-#endif
-
-#ifdef TARGET_ARM
-
-#define ELF_START_MMAP 0x80000000
-
-#define elf_check_arch(x) ((x) == EM_ARM)
-
-#define ELF_CLASS       ELFCLASS32
-#ifdef TARGET_WORDS_BIGENDIAN
-#define ELF_DATA        ELFDATA2MSB
-#else
-#define ELF_DATA        ELFDATA2LSB
-#endif
-#define ELF_ARCH        EM_ARM
-
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
-{
-    abi_long stack = infop->start_stack;
-    memset(regs, 0, sizeof(*regs));
-    regs->ARM_cpsr = 0x10;
-    if (infop->entry & 1)
-        regs->ARM_cpsr |= CPSR_T;
-    regs->ARM_pc = infop->entry & 0xfffffffe;
-    regs->ARM_sp = infop->start_stack;
-    /* FIXME - what to for failure of get_user()? */
-    get_user_ual(regs->ARM_r2, stack + 8); /* envp */
-    get_user_ual(regs->ARM_r1, stack + 4); /* envp */
-    /* XXX: it seems that r0 is zeroed after ! */
-    regs->ARM_r0 = 0;
-    /* For uClinux PIC binaries.  */
-    /* XXX: Linux does this only on ARM with no MMU (do we care ?) */
-    regs->ARM_r10 = infop->start_data;
-}
-
-#define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE       4096
-
-enum
-{
-  ARM_HWCAP_ARM_SWP       = 1 << 0,
-  ARM_HWCAP_ARM_HALF      = 1 << 1,
-  ARM_HWCAP_ARM_THUMB     = 1 << 2,
-  ARM_HWCAP_ARM_26BIT     = 1 << 3,
-  ARM_HWCAP_ARM_FAST_MULT = 1 << 4,
-  ARM_HWCAP_ARM_FPA       = 1 << 5,
-  ARM_HWCAP_ARM_VFP       = 1 << 6,
-  ARM_HWCAP_ARM_EDSP      = 1 << 7,
-};
-
-#define ELF_HWCAP (ARM_HWCAP_ARM_SWP | ARM_HWCAP_ARM_HALF              \
-                    | ARM_HWCAP_ARM_THUMB | ARM_HWCAP_ARM_FAST_MULT     \
-                    | ARM_HWCAP_ARM_FPA | ARM_HWCAP_ARM_VFP)
-
-#endif
-
-#ifdef TARGET_SPARC
-#ifdef TARGET_SPARC64
-
-#define ELF_START_MMAP 0x80000000
-
-#ifndef TARGET_ABI32
-#define elf_check_arch(x) ((x) == EM_SPARCV9 || (x) == EM_SPARC32PLUS)
-#else
-#define elf_check_arch(x) ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
-#endif
-
-#define ELF_CLASS   ELFCLASS64
-#define ELF_DATA    ELFDATA2MSB
-#define ELF_ARCH    EM_SPARCV9
-
-#define STACK_BIAS              2047
-
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
-{
-#ifndef TARGET_ABI32
-    regs->tstate = 0;
-#endif
-    regs->pc = infop->entry;
-    regs->npc = regs->pc + 4;
-    regs->y = 0;
-#ifdef TARGET_ABI32
-    regs->u_regs[14] = infop->start_stack - 16 * 4;
-#else
-    if (personality(infop->personality) == PER_LINUX32)
-        regs->u_regs[14] = infop->start_stack - 16 * 4;
-    else {
-        regs->u_regs[14] = infop->start_stack - 16 * 8 - STACK_BIAS;
-        if (bsd_type == target_freebsd) {
-            regs->u_regs[8] = infop->start_stack;
-            regs->u_regs[11] = infop->start_stack;
-        }
-    }
-#endif
-}
-
-#else
-#define ELF_START_MMAP 0x80000000
-
-#define elf_check_arch(x) ((x) == EM_SPARC)
-
-#define ELF_CLASS   ELFCLASS32
-#define ELF_DATA    ELFDATA2MSB
-#define ELF_ARCH    EM_SPARC
-
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
-{
-    regs->psr = 0;
-    regs->pc = infop->entry;
-    regs->npc = regs->pc + 4;
-    regs->y = 0;
-    regs->u_regs[14] = infop->start_stack - 16 * 4;
-}
-
-#endif
-#endif
-
-#ifdef TARGET_PPC
-
-#define ELF_START_MMAP 0x80000000
-
-#if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
-
-#define elf_check_arch(x) ((x) == EM_PPC64)
-
-#define ELF_CLASS       ELFCLASS64
-
-#else
-
-#define elf_check_arch(x) ((x) == EM_PPC)
-
-#define ELF_CLASS       ELFCLASS32
-
-#endif
-
-#ifdef TARGET_WORDS_BIGENDIAN
-#define ELF_DATA        ELFDATA2MSB
-#else
-#define ELF_DATA        ELFDATA2LSB
-#endif
-#define ELF_ARCH        EM_PPC
-
-/*
- * We need to put in some extra aux table entries to tell glibc what
- * the cache block size is, so it can use the dcbz instruction safely.
- */
-#define AT_DCACHEBSIZE          19
-#define AT_ICACHEBSIZE          20
-#define AT_UCACHEBSIZE          21
-/* A special ignored type value for PPC, for glibc compatibility.  */
-#define AT_IGNOREPPC            22
-/*
- * The requirements here are:
- * - keep the final alignment of sp (sp & 0xf)
- * - make sure the 32-bit value at the first 16 byte aligned position of
- *   AUXV is greater than 16 for glibc compatibility.
- *   AT_IGNOREPPC is used for that.
- * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
- *   even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
- */
-#define DLINFO_ARCH_ITEMS       5
-#define ARCH_DLINFO                                                     \
-do {                                                                    \
-        NEW_AUX_ENT(AT_DCACHEBSIZE, 0x20);                              \
-        NEW_AUX_ENT(AT_ICACHEBSIZE, 0x20);                              \
-        NEW_AUX_ENT(AT_UCACHEBSIZE, 0);                                 \
-        /*                                                              \
-         * Now handle glibc compatibility.                              \
-         */                                                             \
-        NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);                        \
-        NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);                        \
- } while (0)
-
-static inline void init_thread(struct target_pt_regs *_regs, struct image_info *infop)
-{
-    abi_ulong pos = infop->start_stack;
-    abi_ulong tmp;
-#if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
-    abi_ulong entry, toc;
-#endif
-
-    _regs->gpr[1] = infop->start_stack;
-#if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
-    get_user_u64(entry, infop->entry);
-    entry += infop->load_addr;
-    get_user_u64(toc, infop->entry + 8);
-    toc += infop->load_addr;
-    _regs->gpr[2] = toc;
-    infop->entry = entry;
-#endif
-    _regs->nip = infop->entry;
-    /* Note that isn't exactly what regular kernel does
-     * but this is what the ABI wants and is needed to allow
-     * execution of PPC BSD programs.
-     */
-    /* FIXME - what to for failure of get_user()? */
-    get_user_ual(_regs->gpr[3], pos);
-    pos += sizeof(abi_ulong);
-    _regs->gpr[4] = pos;
-    for (tmp = 1; tmp != 0; pos += sizeof(abi_ulong)) {
-        get_user_ual(tmp, pos);
-    }
-    _regs->gpr[5] = pos;
-}
+#endif /* !TARGET_X86_64 */
 
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
 #endif
 
-#ifdef TARGET_MIPS
-
-#define ELF_START_MMAP 0x80000000
-
-#define elf_check_arch(x) ((x) == EM_MIPS)
-
-#ifdef TARGET_MIPS64
-#define ELF_CLASS   ELFCLASS64
-#else
-#define ELF_CLASS   ELFCLASS32
-#endif
-#ifdef TARGET_WORDS_BIGENDIAN
-#define ELF_DATA        ELFDATA2MSB
-#else
-#define ELF_DATA        ELFDATA2LSB
-#endif
-#define ELF_ARCH    EM_MIPS
-
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
-{
-    regs->cp0_status = 2 << CP0St_KSU;
-    regs->cp0_epc = infop->entry;
-    regs->regs[29] = infop->start_stack;
-}
-
-#define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE        4096
-
-#endif /* TARGET_MIPS */
-
-#ifdef TARGET_SH4
-
-#define ELF_START_MMAP 0x80000000
-
-#define elf_check_arch(x) ((x) == EM_SH)
-
-#define ELF_CLASS ELFCLASS32
-#define ELF_DATA  ELFDATA2LSB
-#define ELF_ARCH  EM_SH
-
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
-{
-  /* Check other registers XXXXX */
-  regs->pc = infop->entry;
-  regs->regs[15] = infop->start_stack;
-}
-
-#define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE        4096
-
-#endif
-
-#ifdef TARGET_CRIS
-
-#define ELF_START_MMAP 0x80000000
-
-#define elf_check_arch(x) ((x) == EM_CRIS)
-
-#define ELF_CLASS ELFCLASS32
-#define ELF_DATA  ELFDATA2LSB
-#define ELF_ARCH  EM_CRIS
-
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
-{
-  regs->erp = infop->entry;
-}
-
-#define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE        8192
-
-#endif
-
-#ifdef TARGET_M68K
-
-#define ELF_START_MMAP 0x80000000
-
-#define elf_check_arch(x) ((x) == EM_68K)
-
-#define ELF_CLASS       ELFCLASS32
-#define ELF_DATA        ELFDATA2MSB
-#define ELF_ARCH        EM_68K
-
-/* ??? Does this need to do anything?
-#define ELF_PLAT_INIT(_r) */
-
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
-{
-    regs->usp = infop->start_stack;
-    regs->sr = 0;
-    regs->pc = infop->entry;
-}
-
-#define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE       8192
-
-#endif
-
-#ifdef TARGET_ALPHA
-
-#define ELF_START_MMAP (0x30000000000ULL)
-
-#define elf_check_arch(x) ((x) == ELF_ARCH)
-
-#define ELF_CLASS      ELFCLASS64
-#define ELF_DATA       ELFDATA2MSB
-#define ELF_ARCH       EM_ALPHA
-
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
-{
-    regs->pc = infop->entry;
-    regs->ps = 8;
-    regs->usp = infop->start_stack;
-    regs->unique = infop->start_data; /* ? */
-    printf("Set unique value to " TARGET_FMT_lx " (" TARGET_FMT_lx ")\n",
-           regs->unique, infop->start_data);
-}
-
-#define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE        8192
-
-#endif /* TARGET_ALPHA */
-
 #ifndef ELF_PLATFORM
 #define ELF_PLATFORM (NULL)
 #endif
@@ -1119,10 +780,6 @@ static void load_symbols(struct elfhdr *hdr, int fd)
             }
             continue;
         }
-#if defined(TARGET_ARM) || defined(TARGET_MIPS)
-        /* The bottom address bit marks a Thumb or MIPS16 symbol.  */
-        syms[i].st_value &= ~(target_ulong)1;
-#endif
         i++;
     }
 
-- 
2.32.0



  parent reply	other threads:[~2021-09-02 23:50 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-02 23:46 [PATCH v3 00/43] bsd-user updates to run hello world imp
2021-09-02 23:46 ` [PATCH v3 01/43] bsd-user: remove sparc and sparc64 imp
2021-09-02 23:46 ` [PATCH v3 02/43] bsd-user: add copyright header to elfload.c imp
2021-09-02 23:46 ` [PATCH v3 03/43] bsd-user: Add Stacey's copyright to main.c imp
2021-09-02 23:46 ` [PATCH v3 04/43] bsd-user: add license to bsdload.c imp
2021-09-02 23:46 ` [PATCH v3 05/43] bsd-user: style nits: bsdload.c whitespace to qemu standard imp
2021-09-02 23:46 ` imp [this message]
2021-09-02 23:46 ` [PATCH v3 07/43] bsd-user: move arch specific defines out of elfload.c imp
2021-09-02 23:46 ` [PATCH v3 08/43] bsd-user: pass the bsd_param into loader_exec imp
2021-09-02 23:46 ` [PATCH v3 09/43] bsd-user: Fix calculation of size to allocate imp
2021-09-02 23:46 ` [PATCH v3 10/43] bsd-user: implement path searching imp
2021-09-05 10:11   ` Richard Henderson
2021-09-02 23:46 ` [PATCH v3 11/43] bsd-user: Eliminate elf personality imp
2021-09-02 23:46 ` [PATCH v3 12/43] bsd-user: remove a.out support imp
2021-09-02 23:46 ` [PATCH v3 13/43] bsd-user: TARGET_NGROUPS unused in this file, remove imp
2021-09-02 23:47 ` [PATCH v3 14/43] bsd-user: elfload: simplify bswap a bit imp
2021-09-02 23:47 ` [PATCH v3 15/43] bsd-user: assume pthreads and support of __thread imp
2021-09-02 23:47 ` [PATCH v3 16/43] bsd-user: add host-os.h imp
2021-09-02 23:47 ` [PATCH v3 17/43] bsd-user: Include host-os.h from main imp
2021-09-02 23:47 ` [PATCH v3 18/43] bsd-user: save the path to the qemu emulator imp
2021-09-05 19:04   ` Kyle Evans
2021-09-02 23:47 ` [PATCH v3 19/43] bsd-user: start to move target CPU functions to target_arch* imp
2021-09-02 23:47 ` [PATCH v3 20/43] bsd-user: Move per-cpu code into target_arch_cpu.h imp
2021-09-05 10:13   ` Richard Henderson
2021-09-02 23:47 ` [PATCH v3 21/43] bsd-user: pull in target_arch_thread.h update target_arch_elf.h imp
2021-09-05 19:03   ` Kyle Evans
2021-09-02 23:47 ` [PATCH v3 22/43] bsd-user: Include more things in qemu.h imp
2021-09-05 10:14   ` Richard Henderson
2021-09-02 23:47 ` [PATCH v3 23/43] bsd-user: define max args in terms of pages imp
2021-09-02 23:47 ` [PATCH v3 24/43] bsd-user: Create target specific vmparam.h imp
2021-09-02 23:47 ` [PATCH v3 25/43] bsd-user: Add system independent stack, data and text limiting imp
2021-09-02 23:47 ` [PATCH v3 26/43] bsd-user: *BSD specific siginfo defintions imp
2021-09-05 19:01   ` Kyle Evans
2021-09-02 23:47 ` [PATCH v3 27/43] bsd-user: Implement --seed and initialize random state imp
2021-09-05 10:32   ` Richard Henderson
2021-09-05 14:34     ` Warner Losh
2021-09-02 23:47 ` [PATCH v3 28/43] bsd-user: Move stack initializtion into a per-os file imp
2021-09-02 23:47 ` [PATCH v3 29/43] bsd-user: Add architecture specific signal tramp code imp
2021-09-02 23:47 ` [PATCH v3 30/43] bsd-user: elf cleanup imp
2021-09-05 19:00   ` Kyle Evans
2021-09-02 23:47 ` [PATCH v3 31/43] bsd-user: Remove dead #ifdefs from elfload.c imp
2021-09-02 23:47 ` [PATCH v3 32/43] bsd-user: Rewrite target system call definintion glue imp
2021-09-05 10:33   ` Richard Henderson
2021-09-05 14:38     ` Warner Losh
2021-09-05 18:58   ` Kyle Evans
2021-09-02 23:47 ` [PATCH v3 33/43] bsd-user: Make cpu_model and cpu_type visible to all of main.c imp
2021-09-05 18:57   ` Kyle Evans
2021-09-05 22:44     ` Warner Losh
2021-09-02 23:47 ` [PATCH v3 34/43] bsd-user: update debugging in mmap.c imp
2021-09-05 18:53   ` Kyle Evans
2021-09-02 23:47 ` [PATCH v3 35/43] bsd-user: Add target_arch_reg to describe a target's register set imp
2021-09-02 23:47 ` [PATCH v3 36/43] bsd-user: Add target_os_user.h to capture the user/kernel structures imp
2021-09-05 18:52   ` Kyle Evans
2021-09-02 23:47 ` [PATCH v3 37/43] bsd-user: add stubbed out core dump support imp
2021-09-05 10:34   ` Richard Henderson
2021-09-02 23:47 ` [PATCH v3 38/43] bsd-user: elfload.c style catch up patch imp
2021-09-02 23:47 ` [PATCH v3 39/43] bsd-user: Refactor load_elf_sections and is_target_elf_binary imp
2021-09-05 18:50   ` Kyle Evans
2021-09-02 23:47 ` [PATCH v3 40/43] bsd-user: move qemu_log to later in the file imp
2021-09-05 18:42   ` Kyle Evans
2021-09-02 23:47 ` [PATCH v3 41/43] bsd-user: Implement interlock for atomic operations imp
2021-09-02 23:47 ` [PATCH v3 42/43] bsd-user: Add '-0 argv0' option to bsd-user/main.c imp
2021-09-02 23:47 ` [PATCH v3 43/43] bsd-user: Update mapping to handle reserved and starting conditions imp
2021-09-05 18:39   ` Kyle Evans

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210902234729.76141-7-imp@bsdimp.com \
    --to=imp@bsdimp.com \
    --cc=kevans@freebsd.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.