Skip to contentSkip to conversation

S/390 support

PATCH In review Ulrich Hecht 5 participants 25 messages Oct 21, 2009 – Nov 18, 2009 exec and binfmt

lore
Share & tools
lore
#0 lore raw

cover S/390 support

Here's the patches again, split and fixed as suggested by Aurelien. It should now be possible to apply host and target support separately. See the individual patches for details on what has changed.

CU
Uli

Ulrich Hecht (12):
TCG "sync" op
S/390 disassembler fixes
S/390 CPU emulation
S/390 host build system support
S/390 target build system support
S/390 host support for TCG
linux-user: S/390 64-bit (s390x) support
linux-user: don't do locking in single-threaded processes
linux-user: dup3, fallocate syscalls
linux-user: define a couple of syscalls for non-uid16 targets
linux-user: getpriority errno fix
enable CPU_QuadU for s390x

 configure                        |   58 +-
 cpu-all.h                        |    2 +-
 cpu-defs.h                       |    8 +
 cpu-exec.c                       |   16 +-
 disas.c                          |    3 +
 dyngen-exec.h                    |    2 +-
 linux-user/elfload.c             |   18 +
 linux-user/main.c                |   89 ++
 linux-user/s390x/syscall.h       |   25 +
 linux-user/s390x/syscall_nr.h    |  348 +++++
 linux-user/s390x/target_signal.h |   26 +
 linux-user/s390x/termbits.h      |  283 ++++
 linux-user/signal.c              |  314 +++++
 linux-user/syscall.c             |  156 ++-
 linux-user/syscall_defs.h        |   56 +-
 qemu-binfmt-conf.sh              |    5 +-
 s390-dis.c                       |    4 +-
 s390x.ld                         |  194 +++
 target-s390x/cpu.h               |  118 ++
 target-s390x/exec.h              |   51 +
 target-s390x/helper.c            |   63 +
 target-s390x/helpers.h           |  128 ++
 target-s390x/op_helper.c         | 1639 ++++++++++++++++++++++
 target-s390x/translate.c         | 2834 ++++++++++++++++++++++++++++++++++++++
 tcg/s390/tcg-target.c            | 1145 +++++++++++++++
 tcg/s390/tcg-target.h            |   76 +
 tcg/tcg-op.h                     |   12 +
 tcg/tcg-opc.h                    |    2 +
 tcg/tcg.c                        |    6 +
 29 files changed, 7640 insertions(+), 41 deletions(-)
 create mode 100644 linux-user/s390x/syscall.h
 create mode 100644 linux-user/s390x/syscall_nr.h
 create mode 100644 linux-user/s390x/target_signal.h
 create mode 100644 linux-user/s390x/termbits.h
 create mode 100644 s390x.ld
 create mode 100644 target-s390x/cpu.h
 create mode 100644 target-s390x/exec.h
 create mode 100644 target-s390x/helper.c
 create mode 100644 target-s390x/helpers.h
 create mode 100644 target-s390x/op_helper.c
 create mode 100644 target-s390x/translate.c
 create mode 100644 tcg/s390/tcg-target.c
 create mode 100644 tcg/s390/tcg-target.h
#1 lore raw

PATCH 1/12 TCG "sync" op

sync allows concurrent accesses to locations in memory through different TCG variables. This comes in handy when you are emulating CPU registers that can be used as either 32 or 64 bit, as TCG doesn't know anything about aliases. See the s390x target for an example.

Fixed sync_i64 build failure on 32-bit targets.

---
 tcg/tcg-op.h  |   12 ++++++++++++
 tcg/tcg-opc.h |    2 ++
 tcg/tcg.c     |    6 ++++++
 3 files changed, 20 insertions(+), 0 deletions(-)
tcg/tcg-op.h +12 -0
index faf2e8b..c1b4710 100644
@@ -316,6 +316,18 @@ static inline void tcg_gen_br(int label)
     tcg_gen_op1i(INDEX_op_br, label);
 }
 
+static inline void tcg_gen_sync_i32(TCGv_i32 arg)
+{
+    tcg_gen_op1_i32(INDEX_op_sync_i32, arg);
+}
+
+#if TCG_TARGET_REG_BITS == 64
+static inline void tcg_gen_sync_i64(TCGv_i64 arg)
+{
+    tcg_gen_op1_i64(INDEX_op_sync_i64, arg);
+}
+#endif
+
 static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
 {
     if (!TCGV_EQUAL_I32(ret, arg))
tcg/tcg-opc.h +2 -0
index b7f3fd7..5dcdeba 100644
@@ -40,6 +40,7 @@ DEF2(call, 0, 1, 2, TCG_OPF_SIDE_EFFECTS) /* variable number of parameters */
 DEF2(jmp, 0, 1, 0, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
 DEF2(br, 0, 0, 1, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
 
+DEF2(sync_i32, 0, 1, 0, 0)
 DEF2(mov_i32, 1, 1, 0, 0)
 DEF2(movi_i32, 1, 0, 1, 0)
 /* load/store */
@@ -109,6 +110,7 @@ DEF2(neg_i32, 1, 1, 0, 0)
 #endif
 
 #if TCG_TARGET_REG_BITS == 64
+DEF2(sync_i64, 0, 1, 0, 0)
 DEF2(mov_i64, 1, 1, 0, 0)
 DEF2(movi_i64, 1, 0, 1, 0)
 /* load/store */
tcg/tcg.c +6 -0
index 3c0e296..8eb60f8 100644
@@ -1930,6 +1930,12 @@ static inline int tcg_gen_code_common(TCGContext *s, uint8_t *gen_code_buf,
         //        dump_regs(s);
 #endif
         switch(opc) {
+        case INDEX_op_sync_i32:
+#if TCG_TARGET_REG_BITS == 64
+        case INDEX_op_sync_i64:
+#endif
+            temp_save(s, args[0], s->reserved_regs);
+            break;
         case INDEX_op_mov_i32:
 #if TCG_TARGET_REG_BITS == 64
         case INDEX_op_mov_i64:
Signature · 1 line
1.6.2.1
#2 lore raw

PATCH 2/12 S/390 disassembler fixes

enable zArch (64-bit) instructions
enable disassembler for both s390 and s390x

---
 configure  |    2 +-
 disas.c    |    3 +++
 s390-dis.c |    4 ++--
 3 files changed, 6 insertions(+), 3 deletions(-)
configure +1 -1
index ca6d45c..350c742 100755
@@ -2386,7 +2386,7 @@ for i in $ARCH $TARGET_BASE_ARCH ; do
   ppc*)
     echo "CONFIG_PPC_DIS=y"  >> $config_target_mak
   ;;
-  s390)
+  s390*)
     echo "CONFIG_S390_DIS=y"  >> $config_target_mak
   ;;
   sh4)
disas.c +3 -0
index ce342bc..14c8901 100644
@@ -195,6 +195,9 @@ void target_disas(FILE *out, target_ulong code, target_ulong size, int flags)
 #elif defined(TARGET_CRIS)
     disasm_info.mach = bfd_mach_cris_v32;
     print_insn = print_insn_crisv32;
+#elif defined(TARGET_S390X)
+    disasm_info.mach = bfd_mach_s390_64;
+    print_insn = print_insn_s390;
 #elif defined(TARGET_MICROBLAZE)
     disasm_info.mach = bfd_arch_microblaze;
     print_insn = print_insn_microblaze;
s390-dis.c +2 -2
index 86dd84f..9a73a57 100644
@@ -191,10 +191,10 @@ init_disasm (struct disassemble_info *info)
 //  switch (info->mach)
 //    {
 //    case bfd_mach_s390_31:
-      current_arch_mask = 1 << S390_OPCODE_ESA;
+//      current_arch_mask = 1 << S390_OPCODE_ESA;
 //      break;
 //    case bfd_mach_s390_64:
-//      current_arch_mask = 1 << S390_OPCODE_ZARCH;
+      current_arch_mask = 1 << S390_OPCODE_ZARCH;
 //      break;
 //    default:
 //      abort ();
Signature · 1 line
1.6.2.1
#3 lore raw

PATCH 3/12 S/390 CPU emulation

Currently only does userspace with 64-bit addressing, but it's quite good at that.

replaced always_inline with inline
split off disassembler stuff
use CPU_DoubleU for FP regs
replace FP128 with CPU_QuadU
move cpu_s390x_init() to translate.c
use C-style comments
coding style fixes
build on 32-bit hosts (although dlg aborts there due to lack of a portable 128 -> 64/64 bit division routine)
abort unimplemented EXECUTEs properly
remove superfluous abs tests
pull loads out of helper functions
generate proper specification exception
use HOST_WORDS_BIGENDIAN instead of WORDS_BIGENDIAN
fixed some temp leaks
do away with TVGv comparisons
do away with some superfluous sign extensions
TCGv type fixes
observe singlestep_enabled
fixed some temp leaks

---
 cpu-exec.c               |    2 +
 target-s390x/cpu.h       |  118 ++
 target-s390x/exec.h      |   51 +
 target-s390x/helper.c    |   63 +
 target-s390x/helpers.h   |  128 +++
 target-s390x/op_helper.c | 1639 +++++++++++++++++++++++++++
 target-s390x/translate.c | 2834 ++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 4835 insertions(+), 0 deletions(-)
 create mode 100644 target-s390x/cpu.h
 create mode 100644 target-s390x/exec.h
 create mode 100644 target-s390x/helper.c
 create mode 100644 target-s390x/helpers.h
 create mode 100644 target-s390x/op_helper.c
 create mode 100644 target-s390x/translate.c
cpu-exec.c +2 -0
index 8aa92c7..6b3391c 100644
@@ -249,6 +249,7 @@ int cpu_exec(CPUState *env1)
 #elif defined(TARGET_MIPS)
 #elif defined(TARGET_SH4)
 #elif defined(TARGET_CRIS)
+#elif defined(TARGET_S390X)
     /* XXXXX */
 #else
 #error unsupported target CPU
@@ -673,6 +674,7 @@ int cpu_exec(CPUState *env1)
 #elif defined(TARGET_SH4)
 #elif defined(TARGET_ALPHA)
 #elif defined(TARGET_CRIS)
+#elif defined(TARGET_S390X)
     /* XXXXX */
 #else
 #error unsupported target CPU
target-s390x/cpu.h new file +118 -0

118 lines not on this page · raw message

target-s390x/exec.h new file +51 -0

51 lines not on this page · raw message

target-s390x/helper.c new file +63 -0

63 lines not on this page · raw message

target-s390x/helpers.h new file +128 -0

128 lines not on this page · raw message

target-s390x/op_helper.c new file +1639 -0

1,639 lines not on this page · raw message

target-s390x/translate.c new file +2834 -0

987 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.6.2.1

Part of the diff is not shown here. View the raw message.

#4 lore raw

PATCH 4/12 S/390 host build system support

changes to configure and makefiles for S/390 host support

---
 configure |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
configure +8 -3
index 350c742..df984a3 100755
@@ -157,9 +157,12 @@ case "$cpu" in
   parisc|parisc64)
     cpu="hppa"
   ;;
-  s390*)
+  s390)
     cpu="s390"
   ;;
+  s390x)
+    cpu="s390x"
+  ;;
   sparc|sun4[cdmuv])
     cpu="sparc"
   ;;
@@ -855,7 +858,7 @@ fi
 # host long bits test
 hostlongbits="32"
 case "$cpu" in
-  x86_64|alpha|ia64|sparc64|ppc64)
+  x86_64|alpha|ia64|sparc64|ppc64|s390x)
     hostlongbits=64
   ;;
 esac
@@ -1819,7 +1822,7 @@ echo >> $config_host_mak
 echo "CONFIG_QEMU_SHAREDIR=\"$prefix$datasuffix\"" >> $config_host_mak
 
 case "$cpu" in
-  i386|x86_64|alpha|cris|hppa|ia64|m68k|microblaze|mips|mips64|ppc|ppc64|s390|sparc|sparc64)
+  i386|x86_64|alpha|cris|hppa|ia64|m68k|microblaze|mips|mips64|ppc|ppc64|s390|s390x|sparc|sparc64)
     ARCH=$cpu
   ;;
   armv4b|armv4l)
@@ -2351,6 +2354,8 @@ ldflags=""
 
 if test "$ARCH" = "sparc64" ; then
   cflags="-I\$(SRC_PATH)/tcg/sparc $cflags"
+elif test "$ARCH" = "s390x" ; then
+  cflags="-I\$(SRC_PATH)/tcg/s390 $cflags"
 else
   cflags="-I\$(SRC_PATH)/tcg/\$(ARCH) $cflags"
 fi
Signature · 1 line
1.6.2.1
#5 lore raw

PATCH 5/12 S/390 target build system support

changes to configure and makefiles for S/390 target support

---
 configure |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
configure +7 -2
index df984a3..64be51f 100755
@@ -793,6 +793,7 @@ sh4eb-linux-user \
 sparc-linux-user \
 sparc64-linux-user \
 sparc32plus-linux-user \
+s390x-linux-user \
 "
     fi
 # the following are Darwin specific
@@ -2093,7 +2094,7 @@ target_arch2=`echo $target | cut -d '-' -f 1`
 target_bigendian="no"
 
 case "$target_arch2" in
-  armeb|m68k|microblaze|mips|mipsn32|mips64|ppc|ppcemb|ppc64|ppc64abi32|sh4eb|sparc|sparc64|sparc32plus)
+  armeb|m68k|microblaze|mips|mipsn32|mips64|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus)
   target_bigendian=yes
   ;;
 esac
@@ -2253,6 +2254,10 @@ case "$target_arch2" in
     echo "TARGET_ABI32=y" >> $config_target_mak
     target_phys_bits=64
   ;;
+  s390x)
+    target_nptl="yes"
+    target_phys_bits=64
+  ;;
   *)
     echo "Unsupported target CPU"
     exit 1
@@ -2321,7 +2326,7 @@ if test ! -z "$gdb_xml_files" ; then
 fi
 
 case "$target_arch2" in
-  arm|armeb|m68k|microblaze|mips|mipsel|mipsn32|mipsn32el|mips64|mips64el|ppc|ppc64|ppc64abi32|ppcemb|sparc|sparc64|sparc32plus)
+  arm|armeb|m68k|microblaze|mips|mipsel|mipsn32|mipsn32el|mips64|mips64el|ppc|ppc64|ppc64abi32|ppcemb|s390x|sparc|sparc64|sparc32plus)
     echo "CONFIG_SOFTFLOAT=y" >> $config_target_mak
     ;;
   *)
Signature · 1 line
1.6.2.1
#6 lore raw

PATCH 6/12 S/390 host support for TCG

S/390 TCG code generator as posted before

improvements since last time:
- don't use R0 (often means "zero", not "register zero")
- optimized add_i32 immediate
- formatted for better compliance with the QEMU coding style

---
 dyngen-exec.h         |    2 +-
 linux-user/syscall.c  |    2 +-
 s390x.ld              |  194 +++++++++
 tcg/s390/tcg-target.c | 1145 +++++++++++++++++++++++++++++++++++++++++++++++++
 tcg/s390/tcg-target.h |   76 ++++
 5 files changed, 1417 insertions(+), 2 deletions(-)
 create mode 100644 s390x.ld
 create mode 100644 tcg/s390/tcg-target.c
 create mode 100644 tcg/s390/tcg-target.h
dyngen-exec.h +1 -1
index 86e61c3..0353f36 100644
@@ -117,7 +117,7 @@ extern int printf(const char *, ...);
 
 /* The return address may point to the start of the next instruction.
    Subtracting one gets us the call instruction itself.  */
-#if defined(__s390__)
+#if defined(__s390__) && !defined(__s390x__)
 # define GETPC() ((void*)(((unsigned long)__builtin_return_address(0) & 0x7fffffffUL) - 1))
 #elif defined(__arm__)
 /* Thumb return addresses have the low bit set, so we need to subtract two.
linux-user/syscall.c +1 -1
index bf06d14..45ccef9 100644
@@ -183,7 +183,7 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,	\
 #define __NR_sys_inotify_add_watch __NR_inotify_add_watch
 #define __NR_sys_inotify_rm_watch __NR_inotify_rm_watch
 
-#if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__)
+#if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__) || defined(__s390x__)
 #define __NR__llseek __NR_lseek
 #endif
 
s390x.ld new file +194 -0

194 lines not on this page · raw message

tcg/s390/tcg-target.c new file +1145 -0

1,145 lines not on this page · raw message

tcg/s390/tcg-target.h new file +76 -0

76 lines not on this page · raw message

Signature · 1 line
1.6.2.1
#7 lore raw

PATCH 7/12 linux-user: S/390 64-bit (s390x) support

code for running 64-bit S/390 Linux binaries

use CPU_DoubleU for FP regs
proper specification exception (SIGILL) handling

---
 linux-user/elfload.c             |   18 ++
 linux-user/main.c                |   89 ++++++++++
 linux-user/s390x/syscall.h       |   25 +++
 linux-user/s390x/syscall_nr.h    |  348 ++++++++++++++++++++++++++++++++++++++
 linux-user/s390x/target_signal.h |   26 +++
 linux-user/s390x/termbits.h      |  283 +++++++++++++++++++++++++++++++
 linux-user/signal.c              |  314 ++++++++++++++++++++++++++++++++++
 linux-user/syscall.c             |   16 ++-
 linux-user/syscall_defs.h        |   56 ++++++-
 qemu-binfmt-conf.sh              |    5 +-
 10 files changed, 1173 insertions(+), 7 deletions(-)
 create mode 100644 linux-user/s390x/syscall.h
 create mode 100644 linux-user/s390x/syscall_nr.h
 create mode 100644 linux-user/s390x/target_signal.h
 create mode 100644 linux-user/s390x/termbits.h
linux-user/elfload.c +18 -0
index 62a3f2a..90e9268 100644
@@ -679,6 +679,24 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 
 #endif /* TARGET_ALPHA */
 
+#ifdef TARGET_S390X
+
+#define ELF_START_MMAP (0x20000000000ULL)
+
+#define elf_check_arch(x) ( (x) == ELF_ARCH )
+
+#define ELF_CLASS	ELFCLASS64
+#define ELF_DATA	ELFDATA2MSB
+#define ELF_ARCH	EM_S390
+
+static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+{
+    regs->psw.addr = infop->entry;
+    regs->gprs[15] = infop->start_stack;
+}
+
+#endif /* TARGET_S390X */
+
 #ifndef ELF_PLATFORM
 #define ELF_PLATFORM (NULL)
 #endif
linux-user/main.c +89 -0

101 lines not on this page · raw message

linux-user/s390x/syscall.h new file +25 -0
new file mode 100644
index 0000000..a3812a8
@@ -0,0 +1,25 @@
+/* this typedef defines how a Program Status Word looks like */
+typedef struct
+{
+    abi_ulong mask;
+    abi_ulong addr;
+} __attribute__ ((aligned(8))) target_psw_t;
+
+/*
+ * The pt_regs struct defines the way the registers are stored on
+ * the stack during a system call.
+ */
+
+#define TARGET_NUM_GPRS        16
+
+struct target_pt_regs
+{
+    abi_ulong args[1];
+    target_psw_t psw;
+    abi_ulong gprs[TARGET_NUM_GPRS];
+    abi_ulong orig_gpr2;
+    unsigned short ilc;
+    unsigned short trap;
+};
+
+#define UNAME_MACHINE "s390x"
linux-user/s390x/syscall_nr.h new file +348 -0

348 lines not on this page · raw message

linux-user/s390x/target_signal.h new file +26 -0
new file mode 100644
index 0000000..b4816b0
@@ -0,0 +1,26 @@
+#ifndef TARGET_SIGNAL_H
+#define TARGET_SIGNAL_H
+
+#include "cpu.h"
+
+typedef struct target_sigaltstack {
+    abi_ulong ss_sp;
+    int ss_flags;
+    abi_ulong ss_size;
+} target_stack_t;
+
+/*
+ * sigaltstack controls
+ */
+#define TARGET_SS_ONSTACK      1
+#define TARGET_SS_DISABLE      2
+
+#define TARGET_MINSIGSTKSZ     2048
+#define TARGET_SIGSTKSZ        8192
+
+static inline abi_ulong get_sp_from_cpustate(CPUS390XState *state)
+{
+   return state->regs[15];
+}
+
+#endif /* TARGET_SIGNAL_H */
linux-user/s390x/termbits.h new file +283 -0

283 lines not on this page · raw message

linux-user/signal.c +314 -0

320 lines not on this page · raw message

linux-user/syscall.c +12 -4
index 45ccef9..617e031 100644
@@ -5102,7 +5102,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             ret = get_errno(settimeofday(&tv, NULL));
         }
         break;
-#ifdef TARGET_NR_select
+#if defined(TARGET_NR_select) && !defined(TARGET_S390X) && !defined(TARGET_S390)
     case TARGET_NR_select:
         {
             struct target_sel_arg_struct *sel;
@@ -5209,7 +5209,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #endif
 #ifdef TARGET_NR_mmap
     case TARGET_NR_mmap:
-#if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE)
+#if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) || \
+    defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE) \
+    || defined(TARGET_S390X)
         {
             abi_ulong *v;
             abi_ulong v1, v2, v3, v4, v5, v6;
@@ -5694,6 +5696,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4));
 #elif defined(TARGET_CRIS)
         ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg4, arg5));
+#elif defined(TARGET_S390X)
+        ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg5, arg4));
 #else
         ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5));
 #endif
@@ -5898,8 +5902,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif /* TARGET_NR_getdents64 */
-#ifdef TARGET_NR__newselect
+#if defined(TARGET_NR__newselect) || defined(TARGET_S390X)
+#ifdef TARGET_S390X
+    case TARGET_NR_select:
+#else
     case TARGET_NR__newselect:
+#endif
         ret = do_select(arg1, arg2, arg3, arg4, arg5);
         break;
 #endif
@@ -6124,7 +6132,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_sigaltstack:
 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \
     defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \
-    defined(TARGET_M68K)
+    defined(TARGET_M68K) || defined(TARGET_S390X)
         ret = do_sigaltstack(arg1, arg2, get_sp_from_cpustate((CPUState *)cpu_env));
         break;
 #else
linux-user/syscall_defs.h +54 -2

80 lines not on this page · raw message

qemu-binfmt-conf.sh +4 -1
index 941f0cf..5678771 100644
@@ -1,5 +1,5 @@
 #!/bin/sh
-# enable automatic i386/ARM/M68K/MIPS/SPARC/PPC program execution by the kernel
+# enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390 program execution by the kernel
 
 # load the binfmt_misc module
 if [ ! -d /proc/sys/fs/binfmt_misc ]; then
@@ -57,3 +57,6 @@ if [ $cpu != "mips" ] ; then
     echo   ':mips64:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips64:' > /proc/sys/fs/binfmt_misc/register
     echo   ':mips64el:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mips64el:' > /proc/sys/fs/binfmt_misc/register
 fi
+if [ $cpu != "s390x" ] ; then
+    echo   ':s390x:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-s390x:' > /proc/sys/fs/binfmt_misc/register
+fi
Signature · 1 line
1.6.2.1
#8 lore raw

PATCH 8/12 linux-user: don't do locking in single-threaded processes

Skips setting the tb_lock if a process doesn't have more than one thread, which is usually the case. Results in about 20% performance gain (measured with the s390x target, but the effect should be similar with other targets).

---
 cpu-defs.h           |    8 ++++++++
 cpu-exec.c           |   14 ++++++++++++--
 linux-user/syscall.c |    1 +
 3 files changed, 21 insertions(+), 2 deletions(-)
cpu-defs.h +8 -0
index 95068b5..c50c59e 100644
@@ -135,6 +135,13 @@ typedef struct CPUWatchpoint {
 } CPUWatchpoint;
 
 #define CPU_TEMP_BUF_NLONGS 128
+
+#ifdef CONFIG_USER_ONLY
+#define MULTITHREAD uint32_t multithreaded;
+#else
+#define MULTITHREAD
+#endif
+
 #define CPU_COMMON                                                      \
     struct TranslationBlock *current_tb; /* currently executing TB  */  \
     /* soft mmu support */                                              \
@@ -149,6 +156,7 @@ typedef struct CPUWatchpoint {
     uint32_t stop;   /* Stop request */                                 \
     uint32_t stopped; /* Artificially stopped */                        \
     uint32_t interrupt_request;                                         \
+    MULTITHREAD /* needs locking when accessing TBs */                  \
     volatile sig_atomic_t exit_request;                                 \
     /* The meaning of the MMU modes is defined in the target code. */   \
     CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE];                  \
cpu-exec.c +12 -2
index 6b3391c..3fe2725 100644
@@ -219,6 +219,9 @@ int cpu_exec(CPUState *env1)
     TranslationBlock *tb;
     uint8_t *tc_ptr;
     unsigned long next_tb;
+#ifdef CONFIG_USER_ONLY
+    uint32_t multithreaded;
+#endif
 
     if (cpu_halted(env1) == EXCP_HALTED)
         return EXCP_HALTED;
@@ -576,7 +579,11 @@ int cpu_exec(CPUState *env1)
 #endif
                 }
 #endif
-                spin_lock(&tb_lock);
+#ifdef CONFIG_USER_ONLY
+                multithreaded = env->multithreaded;
+                if (multithreaded)
+#endif
+                    spin_lock(&tb_lock);
                 tb = tb_find_fast();
                 /* Note: we do it here to avoid a gcc bug on Mac OS X when
                    doing it in tb_find_slow */
@@ -600,7 +607,10 @@ int cpu_exec(CPUState *env1)
                     tb_add_jump((TranslationBlock *)(next_tb & ~3), next_tb & 3, tb);
                 }
                 }
-                spin_unlock(&tb_lock);
+#ifdef CONFIG_USER_ONLY
+                if (multithreaded)
+#endif
+                    spin_unlock(&tb_lock);
                 env->current_tb = tb;
 
                 /* cpu_interrupt might be called while translating the
linux-user/syscall.c +1 -0
index 617e031..f2a53d5 100644
@@ -3549,6 +3549,7 @@ static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp,
         ts = qemu_mallocz(sizeof(TaskState) + NEW_STACK_SIZE);
         init_task_state(ts);
         new_stack = ts->stack;
+        env->multithreaded = 1;
         /* we create a new CPU instance. */
         new_env = cpu_copy(env);
         /* Init regs that differ from the parent.  */
Signature · 1 line
1.6.2.1
#9 lore raw

PATCH 9/12 linux-user: dup3, fallocate syscalls

implementations of dup3 and fallocate that are good enough to fool LTP

dup3 check, fallocate check fixed
use compile_prog

---
 configure            |   36 ++++++++++++++++++++++++++++++++++++
 linux-user/syscall.c |   10 ++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)
configure +36 -0
index 64be51f..30ecd8f 100755
@@ -1573,6 +1573,36 @@ if compile_prog "" "" ; then
   eventfd=yes
 fi
 
+# check for fallocate
+fallocate=no
+cat > $TMPC << EOF
+#include <fcntl.h>
+
+int main(void)
+{
+    fallocate(0, 0, 0, 0);
+    return 0;
+}
+EOF
+if compile_prog "" "" ; then
+  fallocate=yes
+fi
+
+# check for dup3
+dup3=no
+cat > $TMPC << EOF
+#include <unistd.h>
+
+int main(void)
+{
+    dup3(0, 0, 0);
+    return 0;
+}
+EOF
+if compile_prog "" "" ; then
+  dup3=yes
+fi
+
 # Check if tools are available to build documentation.
 if test "$docs" != "no" ; then
   if test -x "`which texi2html 2>/dev/null`" -a \
@@ -1954,6 +1984,12 @@ fi
 if test "$eventfd" = "yes" ; then
   echo "CONFIG_EVENTFD=y" >> $config_host_mak
 fi
+if test "$fallocate" = "yes" ; then
+  echo "CONFIG_FALLOCATE=y" >> $config_host_mak
+fi
+if test "$dup3" = "yes" ; then
+  echo "CONFIG_DUP3=y" >> $config_host_mak
+fi
 if test "$inotify" = "yes" ; then
   echo "CONFIG_INOTIFY=y" >> $config_host_mak
 fi
linux-user/syscall.c +10 -0
index f2a53d5..4991154 100644
@@ -4747,6 +4747,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_dup2:
         ret = get_errno(dup2(arg1, arg2));
         break;
+#if defined(TARGET_NR_dup3) && defined(CONFIG_DUP3)
+    case TARGET_NR_dup3:
+        ret = get_errno(dup3(arg1, arg2, arg3));
+        break;
+#endif
 #ifdef TARGET_NR_getppid /* not on alpha */
     case TARGET_NR_getppid:
         ret = get_errno(getppid());
@@ -7022,6 +7027,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 #endif /* CONFIG_EVENTFD  */
+#if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
+    case TARGET_NR_fallocate:
+        ret = get_errno(fallocate(arg1, arg2, arg3, arg4));
+        break;
+#endif
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);
Signature · 1 line
1.6.2.1
#10 lore raw

PATCH 10/12 linux-user: define a couple of syscalls for non-uid16 targets

Quite a number of syscalls are only defined on systems with USE_UID16 defined; this patch defines them on other systems as well.

Fixes a large number of uid/gid-related testcases on the s390x target (and most likely on other targets as well)

---
 linux-user/syscall.c |  125 ++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 105 insertions(+), 20 deletions(-)
linux-user/syscall.c +105 -20
index 4991154..da6f2e1 100644
@@ -307,7 +307,7 @@ static int sys_fchmodat(int dirfd, const char *pathname, mode_t mode)
   return (fchmodat(dirfd, pathname, mode, 0));
 }
 #endif
-#if defined(TARGET_NR_fchownat) && defined(USE_UID16)
+#if defined(TARGET_NR_fchownat)
 static int sys_fchownat(int dirfd, const char *pathname, uid_t owner,
     gid_t group, int flags)
 {
@@ -416,7 +416,7 @@ _syscall3(int,sys_faccessat,int,dirfd,const char *,pathname,int,mode)
 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
 _syscall3(int,sys_fchmodat,int,dirfd,const char *,pathname, mode_t,mode)
 #endif
-#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) && defined(USE_UID16)
+#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
 _syscall5(int,sys_fchownat,int,dirfd,const char *,pathname,
           uid_t,owner,gid_t,group,int,flags)
 #endif
@@ -6371,18 +6371,35 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_setfsgid:
         ret = get_errno(setfsgid(arg1));
         break;
+#else /* USE_UID16 */
+#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
+    case TARGET_NR_fchownat:
+        if (!(p = lock_user_string(arg2))) 
+            goto efault;
+        ret = get_errno(sys_fchownat(arg1, p, arg3, arg4, arg5));
+        unlock_user(p, arg2, 0);
+        break;
+#endif
 #endif /* USE_UID16 */
 
-#ifdef TARGET_NR_lchown32
+#if defined(TARGET_NR_lchown32) || !defined(USE_UID16)
+#if defined(TARGET_NR_lchown32)
     case TARGET_NR_lchown32:
+#else
+    case TARGET_NR_lchown:
+#endif
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(lchown(p, arg2, arg3));
         unlock_user(p, arg1, 0);
         break;
 #endif
-#ifdef TARGET_NR_getuid32
+#if defined(TARGET_NR_getuid32) || (defined(TARGET_NR_getuid) && !defined(USE_UID16))
+#if defined(TARGET_NR_getuid32)
     case TARGET_NR_getuid32:
+#else
+    case TARGET_NR_getuid:
+#endif
         ret = get_errno(getuid());
         break;
 #endif
@@ -6410,33 +6427,57 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
-#ifdef TARGET_NR_getgid32
+#if defined(TARGET_NR_getgid32) || (defined(TARGET_NR_getgid) && !defined(USE_UID16))
+#if defined(TARGET_NR_getgid32)
     case TARGET_NR_getgid32:
+#else
+    case TARGET_NR_getgid:
+#endif
         ret = get_errno(getgid());
         break;
 #endif
-#ifdef TARGET_NR_geteuid32
+#if defined(TARGET_NR_geteuid32) || (defined(TARGET_NR_geteuid) && !defined(USE_UID16))
+#if defined(TARGET_NR_geteuid32)
     case TARGET_NR_geteuid32:
+#else
+    case TARGET_NR_geteuid:
+#endif
         ret = get_errno(geteuid());
         break;
 #endif
-#ifdef TARGET_NR_getegid32
+#if defined(TARGET_NR_getegid32) || (defined(TARGET_NR_getegid) && !defined(USE_UID16))
+#if defined(TARGET_NR_getegid32)
     case TARGET_NR_getegid32:
+#else
+    case TARGET_NR_getegid:
+#endif
         ret = get_errno(getegid());
         break;
 #endif
-#ifdef TARGET_NR_setreuid32
+#if defined(TARGET_NR_setreuid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setreuid32)
     case TARGET_NR_setreuid32:
+#else
+    case TARGET_NR_setreuid:
+#endif
         ret = get_errno(setreuid(arg1, arg2));
         break;
 #endif
-#ifdef TARGET_NR_setregid32
+#if defined(TARGET_NR_setregid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setregid32)
     case TARGET_NR_setregid32:
+#else
+    case TARGET_NR_setregid:
+#endif
         ret = get_errno(setregid(arg1, arg2));
         break;
 #endif
-#ifdef TARGET_NR_getgroups32
+#if defined(TARGET_NR_getgroups32) || !defined(USE_UID16)
+#if defined(TARGET_NR_getgroups32)
     case TARGET_NR_getgroups32:
+#else
+    case TARGET_NR_getgroups:
+#endif
         {
             int gidsetsize = arg1;
             uint32_t *target_grouplist;
@@ -6460,8 +6501,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
-#ifdef TARGET_NR_setgroups32
+#if defined(TARGET_NR_setgroups32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setgroups32)
     case TARGET_NR_setgroups32:
+#else
+    case TARGET_NR_setgroups:
+#endif
         {
             int gidsetsize = arg1;
             uint32_t *target_grouplist;
@@ -6481,18 +6526,30 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
-#ifdef TARGET_NR_fchown32
+#if defined(TARGET_NR_fchown32) || !defined(USE_UID16)
+#if defined(TARGET_NR_fchown32)
     case TARGET_NR_fchown32:
+#else
+    case TARGET_NR_fchown:
+#endif
         ret = get_errno(fchown(arg1, arg2, arg3));
         break;
 #endif
-#ifdef TARGET_NR_setresuid32
+#if defined(TARGET_NR_setresuid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setresuid32)
     case TARGET_NR_setresuid32:
+#else
+    case TARGET_NR_setresuid:
+#endif
         ret = get_errno(setresuid(arg1, arg2, arg3));
         break;
 #endif
-#ifdef TARGET_NR_getresuid32
+#if defined(TARGET_NR_getresuid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_getresuid32)
     case TARGET_NR_getresuid32:
+#else
+    case TARGET_NR_getresuid:
+#endif
         {
             uid_t ruid, euid, suid;
             ret = get_errno(getresuid(&ruid, &euid, &suid));
@@ -6505,13 +6562,21 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
-#ifdef TARGET_NR_setresgid32
+#if defined(TARGET_NR_setresgid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setresgid32)
     case TARGET_NR_setresgid32:
+#else
+    case TARGET_NR_setresgid:
+#endif
         ret = get_errno(setresgid(arg1, arg2, arg3));
         break;
 #endif
+#if defined(TARGET_NR_getresgid32) || !defined(USE_UID16)
 #ifdef TARGET_NR_getresgid32
     case TARGET_NR_getresgid32:
+#else
+    case TARGET_NR_getresgid:
+#endif
         {
             gid_t rgid, egid, sgid;
             ret = get_errno(getresgid(&rgid, &egid, &sgid));
@@ -6524,31 +6589,51 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
-#ifdef TARGET_NR_chown32
+#if defined(TARGET_NR_chown32) || !defined(USE_UID16)
+#if defined(TARGET_NR_chown32)
     case TARGET_NR_chown32:
+#else
+    case TARGET_NR_chown:
+#endif
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(chown(p, arg2, arg3));
         unlock_user(p, arg1, 0);
         break;
 #endif
-#ifdef TARGET_NR_setuid32
+#if defined(TARGET_NR_setuid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setuid32)
     case TARGET_NR_setuid32:
+#else
+    case TARGET_NR_setuid:
+#endif
         ret = get_errno(setuid(arg1));
         break;
 #endif
-#ifdef TARGET_NR_setgid32
+#if defined(TARGET_NR_setgid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setgid32)
     case TARGET_NR_setgid32:
+#else
+    case TARGET_NR_setgid:
+#endif
         ret = get_errno(setgid(arg1));
         break;
 #endif
-#ifdef TARGET_NR_setfsuid32
+#if defined(TARGET_NR_setfsuid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setfsuid32)
     case TARGET_NR_setfsuid32:
+#else
+    case TARGET_NR_setfsuid:
+#endif
         ret = get_errno(setfsuid(arg1));
         break;
 #endif
-#ifdef TARGET_NR_setfsgid32
+#if defined(TARGET_NR_setfsgid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setfsgid32)
     case TARGET_NR_setfsgid32:
+#else
+    case TARGET_NR_setfsgid:
+#endif
         ret = get_errno(setfsgid(arg1));
         break;
 #endif
Signature · 1 line
1.6.2.1
#11 lore raw

PATCH 11/12 linux-user: getpriority errno fix

getpriority returned wrong errno; fixes LTP test getpriority02.

---
 linux-user/syscall.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
linux-user/syscall.c +1 -1
index da6f2e1..455c3fd 100644
@@ -5314,7 +5314,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         /* libc does special remapping of the return value of
          * sys_getpriority() so it's just easiest to call
          * sys_getpriority() directly rather than through libc. */
-        ret = sys_getpriority(arg1, arg2);
+        ret = get_errno(sys_getpriority(arg1, arg2));
         break;
     case TARGET_NR_setpriority:
         ret = get_errno(setpriority(arg1, arg2, arg3));
Signature · 1 line
1.6.2.1
#12 lore raw

PATCH 12/12 enable CPU_QuadU for s390x

---
 cpu-all.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
cpu-all.h +1 -1
index ebe8bfb..d245dd2 100644
@@ -138,7 +138,7 @@ typedef union {
     uint64_t ll;
 } CPU_DoubleU;
 
-#ifdef TARGET_SPARC
+#if defined(TARGET_SPARC) || defined(TARGET_S390X)
 typedef union {
     float128 q;
 #if defined(HOST_WORDS_BIGENDIAN) \
Signature · 1 line
1.6.2.1
#13 lore raw

Re: [Qemu-devel] [PATCH 02/12] S/390 disassembler fixes

In reply to Ulrich Hecht
Quoted 44 lines · Ulrich Hecht

enable zArch (64-bit) instructions
enable disassembler for both s390 and s390x

---
 configure  |    2 +-
 disas.c    |    3 +++
 s390-dis.c |    4 ++--
 3 files changed, 6 insertions(+), 3 deletions(-)
configure +1 -1
index ca6d45c..350c742 100755
@@ -2386,7 +2386,7 @@ for i in $ARCH $TARGET_BASE_ARCH ; do
   ppc*)
     echo "CONFIG_PPC_DIS=y"  >> $config_target_mak
   ;;
-  s390)
+  s390*)
     echo "CONFIG_S390_DIS=y"  >> $config_target_mak
   ;;
   sh4)
disas.c +3 -0
index ce342bc..14c8901 100644
@@ -195,6 +195,9 @@ void target_disas(FILE *out, target_ulong code, target_ulong size, int flags)
 #elif defined(TARGET_CRIS)
     disasm_info.mach = bfd_mach_cris_v32;
     print_insn = print_insn_crisv32;
+#elif defined(TARGET_S390X)
+    disasm_info.mach = bfd_mach_s390_64;
+    print_insn = print_insn_s390;
 #elif defined(TARGET_MICROBLAZE)
     disasm_info.mach = bfd_arch_microblaze;
     print_insn = print_insn_microblaze;
s390-dis.c +0 -0
index 86dd84f..9a73a57 100644
@@ -191,10 +191,10 @@ init_disasm (struct disassemble_info *info)
 //  switch (info->mach)
 //    {

s390-dis.c init_disasm (struct disassemble_info *info) · line 200

Quoted 10 lines
s390-dis.c +2 -2
 //    case bfd_mach_s390_31:
-      current_arch_mask = 1 << S390_OPCODE_ESA;
+//      current_arch_mask = 1 << S390_OPCODE_ESA;
 //      break;
 //    case bfd_mach_s390_64:
-//      current_arch_mask = 1 << S390_OPCODE_ZARCH;
+      current_arch_mask = 1 << S390_OPCODE_ZARCH;
 //      break;
 //    default:
 //      abort ();

I do wonder why we keep everything commented, and not use the case at all? Especially given above, the code does:

    disasm_info.mach = bfd_mach_s390_64;
Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#14 lore raw

[Qemu-devel] Re: [PATCH 01/12] TCG "sync" op

In reply to Ulrich Hecht
Quoted 6 lines · Ulrich Hecht

sync allows concurrent accesses to locations in memory through different TCG variables. This comes in handy when you are emulating CPU registers that can be used as either 32 or 64 bit, as TCG doesn't know anything about aliases. See the s390x target for an example.

Fixed sync_i64 build failure on 32-bit targets.

Looking more in details to the use case of this patch, I think it can be useful in QEMU. However I don't feel very comfortable in merging it without having the opinion of more persons. Paul, Malc Blue Swirl or others, any opinion?

Anyway this patch should come with (simple) documentation to drop into tcg/README.

Otherwise, please find my comments inline.

Quoted 20 lines
---
 tcg/tcg-op.h  |   12 ++++++++++++
 tcg/tcg-opc.h |    2 ++
 tcg/tcg.c     |    6 ++++++
 3 files changed, 20 insertions(+), 0 deletions(-)
tcg/tcg-op.h +5 -0
index faf2e8b..c1b4710 100644
@@ -316,6 +316,18 @@ static inline void tcg_gen_br(int label)
     tcg_gen_op1i(INDEX_op_br, label);
 }
 
+static inline void tcg_gen_sync_i32(TCGv_i32 arg)
+{
+    tcg_gen_op1_i32(INDEX_op_sync_i32, arg);
+}
+

tcg/tcg-op.h static inline void tcg_gen_br(int label) · line 333

Quoted 10 lines
tcg/tcg-op.h +7 -0
+#if TCG_TARGET_REG_BITS == 64
+static inline void tcg_gen_sync_i64(TCGv_i64 arg)
+{
+    tcg_gen_op1_i64(INDEX_op_sync_i64, arg);
+}
+#endif
+
 static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
 {
     if (!TCGV_EQUAL_I32(ret, arg))

You may also want to add a sync_tl as a #define at the end of the file.

Quoted 25 lines
tcg/tcg-opc.h +2 -0
index b7f3fd7..5dcdeba 100644
@@ -40,6 +40,7 @@ DEF2(call, 0, 1, 2, TCG_OPF_SIDE_EFFECTS) /* variable number of parameters */
 DEF2(jmp, 0, 1, 0, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
 DEF2(br, 0, 0, 1, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
 
+DEF2(sync_i32, 0, 1, 0, 0)
 DEF2(mov_i32, 1, 1, 0, 0)
 DEF2(movi_i32, 1, 0, 1, 0)
 /* load/store */
@@ -109,6 +110,7 @@ DEF2(neg_i32, 1, 1, 0, 0)
 #endif
 
 #if TCG_TARGET_REG_BITS == 64
+DEF2(sync_i64, 0, 1, 0, 0)
 DEF2(mov_i64, 1, 1, 0, 0)
 DEF2(movi_i64, 1, 0, 1, 0)
 /* load/store */
tcg/tcg.c +0 -0
index 3c0e296..8eb60f8 100644

tcg/tcg.c static inline int tcg_gen_code_common(TCGContext *s, uint8_t *gen_code_buf, · line 1938

Quoted 9 lines
tcg/tcg.c +6 -0
@@ -1930,6 +1930,12 @@ static inline int tcg_gen_code_common(TCGContext *s, uint8_t *gen_code_buf,
         //        dump_regs(s);
 #endif
         switch(opc) {
+        case INDEX_op_sync_i32:
+#if TCG_TARGET_REG_BITS == 64
+        case INDEX_op_sync_i64:
+#endif
+            temp_save(s, args[0], s->reserved_regs);
+            break;

This won't work for fixed register. You should probably add something like:

    if (s->temps[args[0]].fixed_reg) {
        tcg_abort();
    }
Quoted 7 lines
tcg/tcg.c +0 -0
         case INDEX_op_mov_i32:
 #if TCG_TARGET_REG_BITS == 64
         case INDEX_op_mov_i64:
Signature · 1 line
1.6.2.1
Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#15 lore raw

Re: [Qemu-devel] Re: [PATCH 01/12] TCG "sync" op

Quoted 6 lines · Aurelien Jarno
Quoted 5 lines · Ulrich Hecht

sync allows concurrent accesses to locations in memory through different TCG variables. This comes in handy when you are emulating CPU registers that can be used as either 32 or 64 bit, as TCG doesn't know anything about aliases. See the s390x target for an example.

Quoted 6 lines
Quoted 1 line

Fixed sync_i64 build failure on 32-bit targets.

Looking more in details to the use case of this patch, I think it can be useful in QEMU. However I don't feel very comfortable in merging it without having the opinion of more persons. Paul, Malc Blue Swirl or others, any opinion?

I don't really understand the problem/solution so no - no opinion.

[..snip..]

Signature · 1 line
mailto:[email protected]
#16 lore raw

Re: [Qemu-devel] Re: [PATCH 01/12] TCG "sync" op

In reply to Aurelien Jarno
Quoted 6 lines · Aurelien Jarno
Quoted 5 lines · Ulrich Hecht

sync allows concurrent accesses to locations in memory through different TCG variables. This comes in handy when you are emulating CPU registers that can be used as either 32 or 64 bit, as TCG doesn't know anything about aliases. See the s390x target for an example.

Quoted 6 lines
Quoted 1 line

Fixed sync_i64 build failure on 32-bit targets.

Looking more in details to the use case of this patch, I think it can be useful in QEMU. However I don't feel very comfortable in merging it without having the opinion of more persons. Paul, Malc Blue Swirl or others, any opinion?

I don't think this is the right solution.

IIUC the basic problem is that we have a register file where adjacent pairs of 32-bit registers are also accessed as a 64-bit value. This is something many other targets need to do (at least ARM, PPC, MIPS and SPARC).

While sync appears attractive as a quick hack to achieve this, I think it is liable to be abused, and cause us serious pain long-term. If you need an easy solution then use ld/st (as with ARM VFP registers). If you want a good solution then fix whichever bit of TCG makes accessing a pair of registers horribly slow. We already have some support for this (concat_i32_i64).

Paul

#17 lore raw

Re: [Qemu-devel] Re: [PATCH 01/12] TCG "sync" op

Quoted 23 lines · Paul Brook
Quoted 7 lines · Aurelien Jarno
Quoted 5 lines · Ulrich Hecht

sync allows concurrent accesses to locations in memory through different TCG variables. This comes in handy when you are emulating CPU registers that can be used as either 32 or 64 bit, as TCG doesn't know anything about aliases. See the s390x target for an example.

Quoted 7 lines
Quoted 2 lines

Fixed sync_i64 build failure on 32-bit targets.

Looking more in details to the use case of this patch, I think it can be useful in QEMU. However I don't feel very comfortable in merging it without having the opinion of more persons. Paul, Malc Blue Swirl or others, any opinion?

I don't think this is the right solution.

IIUC the basic problem is that we have a register file where adjacent pairs of 32-bit registers are also accessed as a 64-bit value. This is something many other targets need to do (at least ARM, PPC, MIPS and SPARC).

Quoted 6 lines

While sync appears attractive as a quick hack to achieve this, I think it is liable to be abused, and cause us serious pain long-term. If you need an easy solution then use ld/st (as with ARM VFP registers). If you want a good solution then fix whichever bit of TCG makes accessing a pair of registers horribly slow. We already have some support for this (concat_i32_i64).

Could we please include it nevertheless? I don't want to see S390 TCG and KVM targets not included because of this sync operation.

If you like, add some big fat warning around it and maybe break compilation if anyone but the s390 target uses that sync op, but let's not keep a whole target from inclusion because of a single feature that _might_ one day affect others.

Alex

#18 lore raw

Re: [Qemu-devel] Re: [PATCH 01/12] TCG "sync" op

Quoted 7 lines
Quoted 6 lines

While sync appears attractive as a quick hack to achieve this, I think it is liable to be abused, and cause us serious pain long-term. If you need an easy solution then use ld/st (as with ARM VFP registers). If you want a good solution then fix whichever bit of TCG makes accessing a pair of registers horribly slow. We already have some support for this (concat_i32_i64).

Quoted 7 lines

Could we please include it nevertheless? I don't want to see S390 TCG and KVM targets not included because of this sync operation.

If you like, add some big fat warning around it and maybe break compilation if anyone but the s390 target uses that sync op, but let's not keep a whole target from inclusion because of a single feature that _might_ one day affect others.

I'd rather not include sync, and instead use the explicit ld/st code you already wrote.

Paul

#19 lore raw

Re: [Qemu-devel] Re: [PATCH 01/12] TCG "sync" op

Quoted 10 lines · Paul Brook
Quoted 10 lines
Quoted 7 lines

While sync appears attractive as a quick hack to achieve this, I think it is liable to be abused, and cause us serious pain long-term. If you need an easy solution then use ld/st (as with ARM VFP registers). If you want a good solution then fix whichever bit of TCG makes accessing a pair of registers horribly slow. We already have some support for this (concat_i32_i64).

Could we please include it nevertheless? I don't want to see S390 TCG and KVM targets not included because of this sync operation.

Quoted 9 lines
Quoted 5 lines

If you like, add some big fat warning around it and maybe break compilation if anyone but the s390 target uses that sync op, but let's not keep a whole target from inclusion because of a single feature that _might_ one day affect others.

I'd rather not include sync, and instead use the explicit ld/st code you already wrote.

As long as the KVM code comes in I'm good. I don't really care that much about the TCG parts and only need them to have the build system surroundings set up.

So yes, I don't care about sync. As long as we finally get any solution here I'm good, but patches lying around for weeks surely doesn't help qemu.

Alex

#20 lore raw

Re: [Qemu-devel] Re: [PATCH 01/12] TCG "sync" op

In reply to Paul Brook
Quoted 20 lines · Paul Brook
Quoted 6 lines · Aurelien Jarno
Quoted 5 lines · Ulrich Hecht

sync allows concurrent accesses to locations in memory through different TCG variables. This comes in handy when you are emulating CPU registers that can be used as either 32 or 64 bit, as TCG doesn't know anything about aliases. See the s390x target for an example.

Quoted 6 lines
Quoted 1 line

Fixed sync_i64 build failure on 32-bit targets.

Looking more in details to the use case of this patch, I think it can be useful in QEMU. However I don't feel very comfortable in merging it without having the opinion of more persons. Paul, Malc Blue Swirl or others, any opinion?

I don't think this is the right solution.

IIUC the basic problem is that we have a register file where adjacent pairs of 32-bit registers are also accessed as a 64-bit value. This is something many other targets need to do (at least ARM, PPC, MIPS and SPARC).

Quoted 6 lines

While sync appears attractive as a quick hack to achieve this, I think it is liable to be abused, and cause us serious pain long-term. If you need an easy solution then use ld/st (as with ARM VFP registers). If you want a good solution then fix whichever bit of TCG makes accessing a pair of registers horribly slow. We already have some support for this (concat_i32_i64).

What is probably needed here are merge_low and merge_high ops, merging a 32-bit value into the low or high part of a 64-bit value, leaving the other part unchanged. Not sure we can really optimize that on x86/x86_64 compared to standard TCG code though.

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#21 lore raw

Re: [Qemu-devel] Re: [PATCH 01/12] TCG "sync" op

Quoted 28 lines · Aurelien Jarno
Quoted 20 lines · Paul Brook
Quoted 6 lines · Aurelien Jarno
Quoted 5 lines · Ulrich Hecht

sync allows concurrent accesses to locations in memory through different TCG variables. This comes in handy when you are emulating CPU registers that can be used as either 32 or 64 bit, as TCG doesn't know anything about aliases. See the s390x target for an example.

Quoted 6 lines
Quoted 1 line

Fixed sync_i64 build failure on 32-bit targets.

Looking more in details to the use case of this patch, I think it can be useful in QEMU. However I don't feel very comfortable in merging it without having the opinion of more persons. Paul, Malc Blue Swirl or others, any opinion?

I don't think this is the right solution.

IIUC the basic problem is that we have a register file where adjacent pairs of 32-bit registers are also accessed as a 64-bit value. This is something many other targets need to do (at least ARM, PPC, MIPS and SPARC).

Quoted 6 lines

While sync appears attractive as a quick hack to achieve this, I think it is liable to be abused, and cause us serious pain long-term. If you need an easy solution then use ld/st (as with ARM VFP registers). If you want a good solution then fix whichever bit of TCG makes accessing a pair of registers horribly slow. We already have some support for this (concat_i32_i64).

Quoted 4 lines

What is probably needed here are merge_low and merge_high ops, merging a 32-bit value into the low or high part of a 64-bit value, leaving the other part unchanged. Not sure we can really optimize that on x86/x86_64 compared to standard TCG code though.

Maybe I got the whole point wrong but isn't this about having 2 virtual register sets for the same target registers? So you'd have:

TCGvar my_reg_32;
TCGvar my_reg_64;

and whenever you work with either of them you want to have the correct value present in both (cut off for 32bit, extended for 64 bit).

So what's really necessary is some internal coupling and dirty log of variables within TCG so it knows that an access to the 64 bit of a coupled variable means it needs to sync the 32 bit value over and vice versa. Then magically everything would just work as expected.

Or am I totally wrong here?

Alex

#22 lore raw

Re: [Qemu-devel] Re: [PATCH 01/12] TCG "sync" op

Quoted 55 lines · Alexander Graf
Quoted 39 lines · Aurelien Jarno
Quoted 26 lines · Paul Brook
Quoted 9 lines · Aurelien Jarno
Quoted 8 lines · Ulrich Hecht

sync allows concurrent accesses to locations in memory through different
TCG variables. This comes in handy when you are emulating CPU registers
that can be used as either 32 or 64 bit, as TCG doesn't know anything
about aliases. See the s390x target for an example.

Quoted 7 lines
Quoted 1 line

Fixed sync_i64 build failure on 32-bit targets.

Looking more in details to the use case of this patch, I think it can be
useful in QEMU. However I don't feel very comfortable in merging it without having the opinion of more persons. Paul, Malc Blue Swirl or others, any opinion?

I don't think this is the right solution.

IIUC the basic problem is that we have a register file where adjacent pairs of
32-bit registers are also accessed as a 64-bit value. This is something many
other targets need to do (at least ARM, PPC, MIPS and SPARC).

Quoted 11 lines

While sync appears attractive as a quick hack to achieve this, I think it is
liable to be abused, and cause us serious pain long-term. If you need an easy
solution then use ld/st (as with ARM VFP registers). If you want a good
solution then fix whichever bit of TCG makes accessing a pair of registers
horribly slow. We already have some support for this (concat_i32_i64).

Quoted 6 lines

What is probably needed here are merge_low and merge_high ops, merging a
32-bit value into the low or high part of a 64-bit value, leaving the other part unchanged. Not sure we can really optimize that on x86/ x86_64
compared to standard TCG code though.

Maybe I got the whole point wrong but isn't this about having 2 virtual register sets for the same target registers? So you'd have:

TCGvar my_reg_32;
TCGvar my_reg_64;

Quoted 8 lines

and whenever you work with either of them you want to have the correct value present in both (cut off for 32bit, extended for 64 bit).

So what's really necessary is some internal coupling and dirty log of variables within TCG so it knows that an access to the 64 bit of a coupled variable means it needs to sync the 32 bit value over and vice versa. Then magically everything would just work as expected.

That's an option, basically keeping the list (or only one ?) of aliased TCG variables for each of them, and freeing the others before using one.

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#23 lore raw

Re: [Qemu-devel] Re: [PATCH 01/12] TCG "sync" op

Quoted 70 lines · Aurelien Jarno
Quoted 58 lines · Alexander Graf
Quoted 42 lines · Aurelien Jarno
Quoted 28 lines · Paul Brook
Quoted 10 lines · Aurelien Jarno
Quoted 8 lines · Ulrich Hecht

sync allows concurrent accesses to locations in memory through different
TCG variables. This comes in handy when you are emulating CPU registers
that can be used as either 32 or 64 bit, as TCG doesn't know anything
about aliases. See the s390x target for an example.

Quoted 8 lines
Quoted 2 lines

Fixed sync_i64 build failure on 32-bit targets.

Looking more in details to the use case of this patch, I think it can be
useful in QEMU. However I don't feel very comfortable in merging it without having the opinion of more persons. Paul, Malc Blue Swirl or others, any opinion?

I don't think this is the right solution.

IIUC the basic problem is that we have a register file where adjacent pairs of
32-bit registers are also accessed as a 64-bit value. This is something many
other targets need to do (at least ARM, PPC, MIPS and SPARC).

Quoted 12 lines

While sync appears attractive as a quick hack to achieve this, I think it is
liable to be abused, and cause us serious pain long-term. If you need an easy
solution then use ld/st (as with ARM VFP registers). If you want a good
solution then fix whichever bit of TCG makes accessing a pair of registers
horribly slow. We already have some support for this (concat_i32_i64).

Quoted 7 lines

What is probably needed here are merge_low and merge_high ops, merging a
32-bit value into the low or high part of a 64-bit value, leaving the other part unchanged. Not sure we can really optimize that on x86/ x86_64
compared to standard TCG code though.

Maybe I got the whole point wrong but isn't this about having 2 virtual register sets for the same target registers? So you'd have:

TCGvar my_reg_32;
TCGvar my_reg_64;

Quoted 9 lines

and whenever you work with either of them you want to have the correct value present in both (cut off for 32bit, extended for 64 bit).

So what's really necessary is some internal coupling and dirty log of variables within TCG so it knows that an access to the 64 bit of a coupled variable means it needs to sync the 32 bit value over and vice versa. Then magically everything would just work as expected.

Quoted 3 lines

That's an option, basically keeping the list (or only one ?) of aliased TCG variables for each of them, and freeing the others before using one.

Yeah, only one. I don't think this should be getting overengineered (and thus slow) :-).
Doesn't really sound hard, does it? Any TCG magicians around? :)

Alex

#24 lore raw

Re: [Qemu-devel] Re: [PATCH 01/12] TCG "sync" op

Quoted 6 lines
Quoted 2 lines

That's an option, basically keeping the list (or only one ?) of aliased TCG variables for each of them, and freeing the others before using one.

Yeah, only one. I don't think this should be getting overengineered (and thus slow) :-).
Doesn't really sound hard, does it? Any TCG magicians around? :)

Maybe. This is the sort of thing that tends to get harder the more you think about it.

Paul