Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/arm/target_elf.h | 4 ++++
linux-user/loader.h | 2 +-
linux-user/arm/elfload.c | 46 +++++++++++++++++++++++++++++++++++
linux-user/elfload.c | 48 -------------------------------------
4 files changed, 51 insertions(+), 49 deletions(-)
diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
index 58ff6a0986..bb9875fa2d 100644
--- a/linux-user/arm/target_elf.h
+++ b/linux-user/arm/target_elf.h
@@ -7,8 +7,12 @@
#ifndef ARM_TARGET_ELF_H
#define ARM_TARGET_ELF_H
+
+#define HI_COMMPAGE (intptr_t)0xffff0f00u
+
static inline const char *cpu_get_model(uint32_t eflags)
{
return "any";
}
+
#endif
diff --git a/linux-user/loader.h b/linux-user/loader.h
index e5e317ab76..28eebf2f0b 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -102,7 +102,7 @@ const char *elf_hwcap_str(uint32_t bit);
const char *elf_hwcap2_str(uint32_t bit);
const char *get_elf_platform(CPUState *cs);
const char *get_elf_base_platform(CPUState *cs);
-#if defined(TARGET_X86_64)
+#if defined(TARGET_X86_64) || defined(TARGET_ARM)
bool init_guest_commpage(void);
#endif
diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
index 8573e46f2c..ad0d88a7e0 100644
--- a/linux-user/arm/elfload.c
+++ b/linux-user/arm/elfload.c
@@ -3,6 +3,8 @@
#include "qemu/osdep.h"
#include "qemu.h"
#include "loader.h"
+#include "user-internals.h"
+#include "target_elf.h"
#include "target/arm/cpu-features.h"
@@ -194,3 +196,47 @@ const char *get_elf_platform(CPUState *cs)
#undef END
}
+
+bool init_guest_commpage(void)
+{
+ ARMCPU *cpu = ARM_CPU(thread_cpu);
+ int host_page_size = qemu_real_host_page_size();
+ abi_ptr commpage;
+ void *want;
+ void *addr;
+
+ /*
+ * M-profile allocates maximum of 2GB address space, so can never
+ * allocate the commpage. Skip it.
+ */
+ if (arm_feature(&cpu->env, ARM_FEATURE_M)) {
+ return true;
+ }
+
+ commpage = HI_COMMPAGE & -host_page_size;
+ want = g2h_untagged(commpage);
+ addr = mmap(want, host_page_size, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE |
+ (commpage < reserved_va ? MAP_FIXED : MAP_FIXED_NOREPLACE),
+ -1, 0);
+
+ if (addr == MAP_FAILED) {
+ perror("Allocating guest commpage");
+ exit(EXIT_FAILURE);
+ }
+ if (addr != want) {
+ return false;
+ }
+
+ /* Set kernel helper versions; rest of page is 0. */
+ __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu));
+
+ if (mprotect(addr, host_page_size, PROT_READ)) {
+ perror("Protecting guest commpage");
+ exit(EXIT_FAILURE);
+ }
+
+ page_set_flags(commpage, commpage | (host_page_size - 1),
+ PAGE_READ | PAGE_EXEC | PAGE_VALID);
+ return true;
+}
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 297151e4fa..714b70757c 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -208,54 +208,6 @@ typedef abi_int target_pid_t;
#define USE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
-/* The commpage only exists for 32 bit kernels */
-
-#define HI_COMMPAGE (intptr_t)0xffff0f00u
-
-static bool init_guest_commpage(void)
-{
- ARMCPU *cpu = ARM_CPU(thread_cpu);
- int host_page_size = qemu_real_host_page_size();
- abi_ptr commpage;
- void *want;
- void *addr;
-
- /*
- * M-profile allocates maximum of 2GB address space, so can never
- * allocate the commpage. Skip it.
- */
- if (arm_feature(&cpu->env, ARM_FEATURE_M)) {
- return true;
- }
-
- commpage = HI_COMMPAGE & -host_page_size;
- want = g2h_untagged(commpage);
- addr = mmap(want, host_page_size, PROT_READ | PROT_WRITE,
- MAP_ANONYMOUS | MAP_PRIVATE |
- (commpage < reserved_va ? MAP_FIXED : MAP_FIXED_NOREPLACE),
- -1, 0);
-
- if (addr == MAP_FAILED) {
- perror("Allocating guest commpage");
- exit(EXIT_FAILURE);
- }
- if (addr != want) {
- return false;
- }
-
- /* Set kernel helper versions; rest of page is 0. */
- __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu));
-
- if (mprotect(addr, host_page_size, PROT_READ)) {
- perror("Protecting guest commpage");
- exit(EXIT_FAILURE);
- }
-
- page_set_flags(commpage, commpage | (host_page_size - 1),
- PAGE_READ | PAGE_EXEC | PAGE_VALID);
- return true;
-}
-
#if TARGET_BIG_ENDIAN
#include "elf.h"
#include "vdso-be8.c.inc"
--
2.43.0