qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: imp@bsdimp.com
To: qemu-devel@nongnu.org
Cc: Stacey Son <sson@FreeBSD.org>, Warner Losh <imp@FreeBSD.org>,
	Warner Losh <imp@bsdimp.com>
Subject: [PATCH v2 21/43] bsd-user: pull in target_arch_thread.h update target_arch_elf.h
Date: Thu, 26 Aug 2021 15:11:39 -0600	[thread overview]
Message-ID: <20210826211201.98877-22-imp@bsdimp.com> (raw)
In-Reply-To: <20210826211201.98877-1-imp@bsdimp.com>

From: Warner Losh <imp@FreeBSD.org>

Update target_arch_elf.h to remove thread_init. Move its contents to
target_arch_thread.h and rename to target_thread_init(). Update
elfload.c to call it. Create thread_os_thread.h to hold the os specific
parts of the thread and threat manipulation routines. Currently, it just
includes target_arch_thread.h. target_arch_thread.h contains the at the
moment unused target_thread_set_upcall which will be used in the future
when creating actual thread (i386 has this stubbed, but other
architectures in the bsd-user tree have real ones). FreeBSD doesn't do
AT_HWCAP, so remove that code. Linux does, and this code came from there.

These changes are all interrelated and could be brokend own, but seem to
represent a reviewable changeset since most of the change is boiler
plate.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/elfload.c                   |  4 ++-
 bsd-user/freebsd/target_os_thread.h  | 25 +++++++++++++++
 bsd-user/i386/target_arch_elf.h      | 47 ++--------------------------
 bsd-user/i386/target_arch_thread.h   | 47 ++++++++++++++++++++++++++++
 bsd-user/netbsd/target_os_thread.h   | 25 +++++++++++++++
 bsd-user/openbsd/target_os_thread.h  | 25 +++++++++++++++
 bsd-user/x86_64/target_arch_elf.h    | 35 ++-------------------
 bsd-user/x86_64/target_arch_thread.h | 40 +++++++++++++++++++++++
 8 files changed, 171 insertions(+), 77 deletions(-)
 create mode 100644 bsd-user/freebsd/target_os_thread.h
 create mode 100644 bsd-user/i386/target_arch_thread.h
 create mode 100644 bsd-user/netbsd/target_os_thread.h
 create mode 100644 bsd-user/openbsd/target_os_thread.h
 create mode 100644 bsd-user/x86_64/target_arch_thread.h

diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index 8a6a72bf05..70a0f81f3d 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -24,6 +24,7 @@
 #include "qemu/path.h"
 
 #include "target_arch_elf.h"
+#include "target_os_thread.h"
 
 /* this flag is uneffective under linux too, should be deleted */
 #ifndef MAP_DENYWRITE
@@ -1001,5 +1002,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,
 
 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop)
 {
-    init_thread(regs, infop);
+
+    target_thread_init(regs, infop);
 }
diff --git a/bsd-user/freebsd/target_os_thread.h b/bsd-user/freebsd/target_os_thread.h
new file mode 100644
index 0000000000..77433acdff
--- /dev/null
+++ b/bsd-user/freebsd/target_os_thread.h
@@ -0,0 +1,25 @@
+/*
+ *  FreeBSD thread dependent code and definitions
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program 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 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _TARGET_OS_THREAD_H_
+#define _TARGET_OS_THREAD_H_
+
+#include "target_arch_thread.h"
+
+#endif /* !_TARGET_OS_THREAD_H_ */
diff --git a/bsd-user/i386/target_arch_elf.h b/bsd-user/i386/target_arch_elf.h
index 84fbc8ba4c..eb760e07fa 100644
--- a/bsd-user/i386/target_arch_elf.h
+++ b/bsd-user/i386/target_arch_elf.h
@@ -19,57 +19,16 @@
 #ifndef _TARGET_ARCH_ELF_H_
 #define _TARGET_ARCH_ELF_H_
 
-#define ELF_PLATFORM get_elf_platform()
-
-static const char *get_elf_platform(void)
-{
-    static char elf_platform[] = "i386";
-    int family = object_property_get_int(OBJECT(thread_cpu), "family", NULL);
-    if (family > 6)
-        family = 6;
-    if (family >= 3)
-        elf_platform[1] = '0' + family;
-    return elf_platform;
-}
-
-#define ELF_HWCAP get_elf_hwcap()
-
-static uint32_t get_elf_hwcap(void)
-{
-    X86CPU *cpu = X86_CPU(thread_cpu);
-
-    return cpu->env.features[FEAT_1_EDX];
-}
-
 #define ELF_START_MMAP 0x80000000
-
-/*
- * This is used to ensure we don't load something for the wrong architecture.
- */
+#define ELF_ET_DYN_LOAD_ADDR    0x01001000
 #define elf_check_arch(x) (((x) == EM_386) || ((x) == EM_486))
 
-/*
- * These are used to set parameters in the core dumps.
- */
+#define ELF_HWCAP       0 /* FreeBSD doesn't do AT_HWCAP{,2} on x86 */
+
 #define ELF_CLASS       ELFCLASS32
 #define ELF_DATA        ELFDATA2LSB
 #define ELF_ARCH        EM_386
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
-{
-    regs->esp = infop->start_stack;
-    regs->eip = infop->entry;
-
-    /* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program
-       starts %edx contains a pointer to a function which might be
-       registered using `atexit'.  This provides a mean for the
-       dynamic linker to call DT_FINI functions for shared libraries
-       that have been loaded before the code runs.
-
-       A value of 0 tells we have no such handler.  */
-    regs->edx = 0;
-}
-
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
diff --git a/bsd-user/i386/target_arch_thread.h b/bsd-user/i386/target_arch_thread.h
new file mode 100644
index 0000000000..e65e476f75
--- /dev/null
+++ b/bsd-user/i386/target_arch_thread.h
@@ -0,0 +1,47 @@
+/*
+ *  i386 thread support
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program 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 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _TARGET_ARCH_THREAD_H_
+#define _TARGET_ARCH_THREAD_H_
+
+/* Compare to vm_machdep.c cpu_set_upcall_kse() */
+static inline void target_thread_set_upcall(CPUX86State *regs, abi_ulong entry,
+    abi_ulong arg, abi_ulong stack_base, abi_ulong stack_size)
+{
+    /* XXX */
+}
+
+static inline void target_thread_init(struct target_pt_regs *regs,
+        struct image_info *infop)
+{
+    regs->esp = infop->start_stack;
+    regs->eip = infop->entry;
+
+    /*
+     * SVR4/i386 ABI (pages 3-31, 3-32) says that when the program starts %edx
+     * contains a pointer to a function which might be registered using
+     * `atexit'.  This provides a mean for the dynamic linker to call DT_FINI
+     * functions for shared libraries that have been loaded before the code
+     * runs.
+     *
+     * A value of 0 tells we have no such handler.
+     */
+    regs->edx = 0;
+}
+
+#endif /* !_TARGET_ARCH_THREAD_H_ */
diff --git a/bsd-user/netbsd/target_os_thread.h b/bsd-user/netbsd/target_os_thread.h
new file mode 100644
index 0000000000..904dd1bf78
--- /dev/null
+++ b/bsd-user/netbsd/target_os_thread.h
@@ -0,0 +1,25 @@
+/*
+ *  NetBSD thread dependent code and definitions
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program 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 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _TARGET_OS_THREAD_H_
+#define _TARGET_OS_THREAD_H_
+
+#include "target_arch_thread.h"
+
+#endif /* !_TARGET_OS_THREAD_H_ */
diff --git a/bsd-user/openbsd/target_os_thread.h b/bsd-user/openbsd/target_os_thread.h
new file mode 100644
index 0000000000..01ed0d9fc8
--- /dev/null
+++ b/bsd-user/openbsd/target_os_thread.h
@@ -0,0 +1,25 @@
+/*
+ *  OpenBSD thread dependent code and definitions
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program 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 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _TARGET_OS_THREAD_H_
+#define _TARGET_OS_THREAD_H_
+
+#include "target_arch_thread.h"
+
+#endif /* !_TARGET_OS_THREAD_H_ */
diff --git a/bsd-user/x86_64/target_arch_elf.h b/bsd-user/x86_64/target_arch_elf.h
index 202bf2c447..c2f8553962 100644
--- a/bsd-user/x86_64/target_arch_elf.h
+++ b/bsd-user/x86_64/target_arch_elf.h
@@ -19,45 +19,16 @@
 #ifndef _TARGET_ARCH_ELF_H_
 #define _TARGET_ARCH_ELF_H_
 
-#define ELF_PLATFORM get_elf_platform()
-
-static const char *get_elf_platform(void)
-{
-    static char elf_platform[] = "i386";
-    int family = object_property_get_int(OBJECT(thread_cpu), "family", NULL);
-    if (family > 6)
-        family = 6;
-    if (family >= 3)
-        elf_platform[1] = '0' + family;
-    return elf_platform;
-}
-
-#define ELF_HWCAP get_elf_hwcap()
-
-static uint32_t get_elf_hwcap(void)
-{
-    X86CPU *cpu = X86_CPU(thread_cpu);
-
-    return cpu->env.features[FEAT_1_EDX];
-}
-
 #define ELF_START_MMAP 0x2aaaaab000ULL
+#define ELF_ET_DYN_LOAD_ADDR    0x01021000
 #define elf_check_arch(x) (((x) == ELF_ARCH))
 
+#define ELF_HWCAP      0 /* FreeBSD doesn't do AT_HWCAP{,2} on x86 */
+
 #define ELF_CLASS      ELFCLASS64
 #define ELF_DATA       ELFDATA2LSB
 #define ELF_ARCH       EM_X86_64
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
-{
-    regs->rax = 0;
-    regs->rsp = infop->start_stack;
-    regs->rip = infop->entry;
-    if (bsd_type == target_freebsd) {
-        regs->rdi = infop->start_stack;
-    }
-}
-
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
diff --git a/bsd-user/x86_64/target_arch_thread.h b/bsd-user/x86_64/target_arch_thread.h
new file mode 100644
index 0000000000..d105e43fd3
--- /dev/null
+++ b/bsd-user/x86_64/target_arch_thread.h
@@ -0,0 +1,40 @@
+/*
+ *  x86_64 thread support
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program 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 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _TARGET_ARCH_THREAD_H_
+#define _TARGET_ARCH_THREAD_H_
+
+/* Compare to vm_machdep.c cpu_set_upcall_kse() */
+static inline void target_thread_set_upcall(CPUX86State *regs, abi_ulong entry,
+    abi_ulong arg, abi_ulong stack_base, abi_ulong stack_size)
+{
+    /* XXX */
+}
+
+static inline void target_thread_init(struct target_pt_regs *regs,
+    struct image_info *infop)
+{
+    regs->rax = 0;
+    regs->rsp = infop->start_stack;
+    regs->rip = infop->entry;
+    if (bsd_type == target_freebsd) {
+        regs->rdi = infop->start_stack;
+    }
+}
+
+#endif /* !_TARGET_ARCH_THREAD_H_ */
-- 
2.32.0



  parent reply	other threads:[~2021-08-26 21:37 UTC|newest]

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

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=20210826211201.98877-22-imp@bsdimp.com \
    --to=imp@bsdimp.com \
    --cc=imp@FreeBSD.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sson@FreeBSD.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).