Skip to contentSkip to conversation

target-tilegx: Firstly add TILE-Gx with minimized features

PATCH Superseded Chen Gang 2 participants 10 messages Mar 18, 2015 – Mar 20, 2015 1 message not in the archive

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Chen Gang

author
#1 lore raw

PATCH v6 1/6 target-tilegx: Firstly add TILE-Gx with minimized features

In reply to a message not in the archive

It is the configure and build system support for TILE-Gx (tilegx will be used in configure and real sub-directory name).

At present, it is linux-user only, and can finish the first system call (uname) execution in __libc_start_main().

---
 configure                             |    3 +
 default-configs/tilegx-linux-user.mak |    1 +
 target-tilegx/Makefile.objs           |    1 +
 target-tilegx/cpu-qom.h               |   73 ++
 target-tilegx/cpu.c                   |  149 +++
 target-tilegx/cpu.h                   |   94 ++
 target-tilegx/helper.c                |   31 +
 target-tilegx/helper.h                |    1 +
 target-tilegx/opcode_tilegx.h         | 1406 ++++++++++++++++++++++++++
 target-tilegx/translate.c             | 1735 +++++++++++++++++++++++++++++++++
 10 files changed, 3494 insertions(+)
 create mode 100644 default-configs/tilegx-linux-user.mak
 create mode 100644 target-tilegx/Makefile.objs
 create mode 100644 target-tilegx/cpu-qom.h
 create mode 100644 target-tilegx/cpu.c
 create mode 100644 target-tilegx/cpu.h
 create mode 100644 target-tilegx/helper.c
 create mode 100644 target-tilegx/helper.h
 create mode 100644 target-tilegx/opcode_tilegx.h
 create mode 100644 target-tilegx/translate.c
configure +3 -0
index f74a6fd..1121098 100755
@@ -5215,6 +5215,9 @@ case "$target_name" in
   s390x)
     gdb_xml_files="s390x-core64.xml s390-acr.xml s390-fpr.xml"
   ;;
+  tilegx)
+    TARGET_ARCH=tilegx
+  ;;
   unicore32)
   ;;
   xtensa|xtensaeb)
default-configs/tilegx-linux-user.mak new file +1 -0
new file mode 100644
index 0000000..3e47493
@@ -0,0 +1 @@
+# Default configuration for tilegx-linux-user
target-tilegx/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..8b3dc76
@@ -0,0 +1 @@
+obj-y += cpu.o translate.o helper.o
target-tilegx/cpu-qom.h new file +73 -0

73 lines not on this page · raw message

target-tilegx/cpu.c new file +149 -0

149 lines not on this page · raw message

target-tilegx/cpu.h new file +94 -0

94 lines not on this page · raw message

target-tilegx/helper.c new file +31 -0
new file mode 100644
index 0000000..ffac2b9
@@ -0,0 +1,31 @@
+/*
+ * QEMU TILE-Gx helpers
+ *
+ *  Copyright (c) 2015 Chen Gang
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+#include "cpu.h"
+#include "qemu-common.h"
+#include "exec/helper-proto.h"
+
+void helper_exception(CPUTLGState *env, uint32_t excp)
+{
+    CPUState *cs = CPU(tilegx_env_get_cpu(env));
+
+    cs->exception_index = excp;
+    cpu_loop_exit(cs);
+}
target-tilegx/helper.h new file +1 -0
new file mode 100644
index 0000000..36d1cd9
@@ -0,0 +1 @@
+DEF_HELPER_2(exception, noreturn, env, i32)
target-tilegx/opcode_tilegx.h new file +1406 -0

1,406 lines not on this page · raw message

target-tilegx/translate.c new file +1735 -0

1,235 lines not on this page · raw message

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

Signature · 1 line
1.9.3

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

author
#6 lore raw

PATCH v6 2/6 linux-user: tilegx: Firstly add architecture related features

In reply to a message not in the archive

They are based on Linux kernel tilegx architecture for 64 bit binary, also based on tilegx ABI reference document.

---
 linux-user/tilegx/syscall.h    |  80 ++++++++++++
 linux-user/tilegx/syscall_nr.h | 278 ++++++++++++++++++++++++++++++++++++++++
 linux-user/tilegx/termbits.h   | 285 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 643 insertions(+)
 create mode 100644 linux-user/tilegx/syscall.h
 create mode 100644 linux-user/tilegx/syscall_nr.h
 create mode 100644 linux-user/tilegx/termbits.h
linux-user/tilegx/syscall.h new file +80 -0
new file mode 100644
index 0000000..561e158
@@ -0,0 +1,80 @@
+#ifndef TILEGX_SYSCALLS_H
+#define TILEGX_SYSCALLS_H
+
+#define UNAME_MACHINE "tilegx"
+#define UNAME_MINIMUM_RELEASE "3.19"
+
+/* We use tilegx to keep things similar to the kernel sources.  */
+typedef uint64_t tilegx_reg_t;
+
+struct target_pt_regs {
+
+    /* Can be as parameters */
+    tilegx_reg_t r0;  /* Also for return value, both function and system call */
+    tilegx_reg_t r1;
+    tilegx_reg_t r2;
+    tilegx_reg_t r3;
+    tilegx_reg_t r4;
+    tilegx_reg_t r5;
+    tilegx_reg_t r6;
+    tilegx_reg_t r7;
+    tilegx_reg_t r8;
+    tilegx_reg_t r9;
+
+    /* Normal using, caller saved */
+    tilegx_reg_t r10;  /* Also for system call */
+    tilegx_reg_t r11;
+    tilegx_reg_t r12;
+    tilegx_reg_t r13;
+    tilegx_reg_t r14;
+    tilegx_reg_t r15;
+    tilegx_reg_t r16;
+    tilegx_reg_t r17;
+    tilegx_reg_t r18;
+    tilegx_reg_t r19;
+    tilegx_reg_t r20;
+    tilegx_reg_t r21;
+    tilegx_reg_t r22;
+    tilegx_reg_t r23;
+    tilegx_reg_t r24;
+    tilegx_reg_t r25;
+    tilegx_reg_t r26;
+    tilegx_reg_t r27;
+    tilegx_reg_t r28;
+    tilegx_reg_t r29;
+
+    /* Normal using, callee saved */
+    tilegx_reg_t r30;
+    tilegx_reg_t r31;
+    tilegx_reg_t r32;
+    tilegx_reg_t r33;
+    tilegx_reg_t r34;
+    tilegx_reg_t r35;
+    tilegx_reg_t r36;
+    tilegx_reg_t r37;
+    tilegx_reg_t r38;
+    tilegx_reg_t r39;
+    tilegx_reg_t r40;
+    tilegx_reg_t r41;
+    tilegx_reg_t r42;
+    tilegx_reg_t r43;
+    tilegx_reg_t r44;
+    tilegx_reg_t r45;
+    tilegx_reg_t r46;
+    tilegx_reg_t r47;
+    tilegx_reg_t r48;
+    tilegx_reg_t r49;
+    tilegx_reg_t r50;
+    tilegx_reg_t r51;
+
+    /* Control using */
+    tilegx_reg_t r52;    /* optional frame pointer */
+    tilegx_reg_t tp;     /* thread-local data */
+    tilegx_reg_t sp;     /* stack pointer */
+    tilegx_reg_t lr;     /* lr pointer */
+};
+
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
+
+#endif
linux-user/tilegx/syscall_nr.h new file +278 -0

278 lines not on this page · raw message

linux-user/tilegx/termbits.h new file +285 -0

285 lines not on this page · raw message

Signature · 1 line
1.9.3
author
#7 lore raw

PATCH v6 3/6 linux-user: tilegx: Add target features support within qemu

In reply to a message not in the archive

They are for target features within qemu which independent from outside.

---
 linux-user/tilegx/target_cpu.h     | 35 +++++++++++++++++++++++++++
 linux-user/tilegx/target_signal.h  | 28 ++++++++++++++++++++++
 linux-user/tilegx/target_structs.h | 48 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+)
 create mode 100644 linux-user/tilegx/target_cpu.h
 create mode 100644 linux-user/tilegx/target_signal.h
 create mode 100644 linux-user/tilegx/target_structs.h
linux-user/tilegx/target_cpu.h new file +35 -0
new file mode 100644
index 0000000..c96e81d
@@ -0,0 +1,35 @@
+/*
+ * TILE-Gx specific CPU ABI and functions for linux-user
+ *
+ * Copyright (c) 2015 Chen Gang
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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 Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef TARGET_CPU_H
+#define TARGET_CPU_H
+
+static inline void cpu_clone_regs(CPUTLGState *env, target_ulong newsp)
+{
+    if (newsp) {
+        env->regs[TILEGX_R_SP] = newsp;
+    }
+    env->regs[TILEGX_R_RE] = 0;
+}
+
+static inline void cpu_set_tls(CPUTLGState *env, target_ulong newtls)
+{
+    env->regs[TILEGX_R_TP] = newtls;
+}
+
+#endif
linux-user/tilegx/target_signal.h new file +28 -0
new file mode 100644
index 0000000..fbab216
@@ -0,0 +1,28 @@
+#ifndef TARGET_SIGNAL_H
+#define TARGET_SIGNAL_H
+
+#include "cpu.h"
+
+/* this struct defines a stack used during syscall handling */
+
+typedef struct target_sigaltstack {
+    abi_ulong ss_sp;
+    abi_ulong ss_size;
+    abi_long ss_flags;
+} 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(CPUTLGState *state)
+{
+    return state->regs[TILEGX_R_SP];
+}
+
+#endif /* TARGET_SIGNAL_H */
linux-user/tilegx/target_structs.h new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
1.9.3
author
#8 lore raw

PATCH v6 4/6 linux-user: Support tilegx architecture in syscall

In reply to a message not in the archive

Add tilegx architecture in "syscall_defs.h", all related features (ioctrl, and stat) are based on Linux kernel tilegx 64-bit implementation.

---
 linux-user/syscall_defs.h | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)
linux-user/syscall_defs.h +34 -4
index edd5f3c..023f4b5 100644
@@ -64,8 +64,9 @@
 #endif
 
 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SH4) \
-    || defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_UNICORE32) \
-    || defined(TARGET_S390X) || defined(TARGET_OPENRISC)
+    || defined(TARGET_M68K) || defined(TARGET_CRIS) \
+    || defined(TARGET_UNICORE32) || defined(TARGET_S390X) \
+    || defined(TARGET_OPENRISC) || defined(TARGET_TILEGX)
 
 #define TARGET_IOC_SIZEBITS	14
 #define TARGET_IOC_DIRBITS	2
@@ -365,7 +366,8 @@ int do_sigaction(int sig, const struct target_sigaction *act,
     || defined(TARGET_PPC) || defined(TARGET_MIPS) || defined(TARGET_SH4) \
     || defined(TARGET_M68K) || defined(TARGET_ALPHA) || defined(TARGET_CRIS) \
     || defined(TARGET_MICROBLAZE) || defined(TARGET_UNICORE32) \
-    || defined(TARGET_S390X) || defined(TARGET_OPENRISC)
+    || defined(TARGET_S390X) || defined(TARGET_OPENRISC) \
+    || defined(TARGET_TILEGX)
 
 #if defined(TARGET_SPARC)
 #define TARGET_SA_NOCLDSTOP    8u
@@ -1922,6 +1924,32 @@ struct target_stat64 {
     unsigned int __unused5;
 };
 
+#elif defined(TARGET_TILEGX)
+
+/* Copy from Linux kernel "uapi/asm-generic/stat.h" */
+struct target_stat {
+        abi_ulong st_dev;               /* Device.  */
+        abi_ulong st_ino;               /* File serial number.  */
+        unsigned int st_mode;           /* File mode.  */
+        unsigned int st_nlink;          /* Link count.  */
+        unsigned int st_uid;            /* User ID of the file's owner.  */
+        unsigned int st_gid;            /* Group ID of the file's group. */
+        abi_ulong st_rdev;              /* Device number, if device.  */
+        abi_ulong __pad1;
+        abi_long  st_size;              /* Size of file, in bytes.  */
+        int st_blksize;                 /* Optimal block size for I/O.  */
+        int __pad2;
+        abi_long st_blocks;             /* Number 512-byte blocks allocated. */
+        abi_long target_st_atime;       /* Time of last access.  */
+        abi_ulong target_st_atime_nsec;
+        abi_long target_st_mtime;       /* Time of last modification.  */
+        abi_ulong target_st_mtime_nsec;
+        abi_long target_st_ctime;       /* Time of last status change.  */
+        abi_ulong target_st_ctime_nsec;
+        unsigned int __unused4;
+        unsigned int __unused5;
+};
+
 #else
 #error unsupported CPU
 #endif
@@ -2264,7 +2292,9 @@ struct target_flock {
 struct target_flock64 {
 	short  l_type;
 	short  l_whence;
-#if defined(TARGET_PPC) || defined(TARGET_X86_64) || defined(TARGET_MIPS) || defined(TARGET_SPARC) || defined(TARGET_HPPA) || defined (TARGET_MICROBLAZE)
+#if defined(TARGET_PPC) || defined(TARGET_X86_64) || defined(TARGET_MIPS) \
+    || defined(TARGET_SPARC) || defined(TARGET_HPPA) \
+    || defined(TARGET_MICROBLAZE) || defined(TARGET_TILEGX)
         int __pad;
 #endif
 	unsigned long long l_start;
Signature · 1 line
1.9.3
author
#9 lore raw

PATCH v6 5/6 linux-user: Support tilegx architecture in linux-user

In reply to a message not in the archive

Add main working flow feature, system call processing feature, and elf64 tilegx binary loading feature, based on Linux kernel tilegx 64-bit implementation.

---
 include/elf.h        |  2 ++
 linux-user/elfload.c | 23 ++++++++++++++
 linux-user/main.c    | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+)
include/elf.h +2 -0
index 3e75f05..154144e 100644
@@ -133,6 +133,8 @@ typedef int64_t  Elf64_Sxword;
 
 #define EM_AARCH64  183
 
+#define EM_TILEGX   191 /* TILE-Gx */
+
 /* This is the info that is needed to parse the dynamic section of the file */
 #define DT_NULL		0
 #define DT_NEEDED	1
linux-user/elfload.c +23 -0
index 399c021..2571cb8 100644
@@ -1189,6 +1189,29 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 
 #endif /* TARGET_S390X */
 
+#ifdef TARGET_TILEGX
+
+/* 42 bits real used address, a half for user mode */
+#define ELF_START_MMAP (0x00000020000000000ULL)
+
+#define elf_check_arch(x) ((x) == EM_TILEGX)
+
+#define ELF_CLASS   ELFCLASS64
+#define ELF_DATA    ELFDATA2LSB
+#define ELF_ARCH    EM_TILEGX
+
+static inline void init_thread(struct target_pt_regs *regs,
+                               struct image_info *infop)
+{
+    regs->lr = infop->entry;
+    regs->sp = infop->start_stack;
+
+}
+
+#define ELF_EXEC_PAGESIZE        65536 /* TILE-Gx page size is 64KB */
+
+#endif /* TARGET_TILEGX */
+
 #ifndef ELF_PLATFORM
 #define ELF_PLATFORM (NULL)
 #endif
linux-user/main.c +86 -0

98 lines not on this page · raw message

Signature · 1 line
1.9.3
author
#10 lore raw

PATCH v6 6/6 linux-user/syscall.c: conditionalize syscalls which are not defined in tilegx

In reply to a message not in the archive

For tilegx, several syscall macros are not supported, so switch them to avoid building break.

---
 linux-user/syscall.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)
linux-user/syscall.c +49 -1
index 5720195..d1a00ad 100644
@@ -213,7 +213,7 @@ static int gettid(void) {
     return -ENOSYS;
 }
 #endif
-#ifdef __NR_getdents
+#if defined(TARGET_NR_getdents) && defined(__NR_getdents)
 _syscall3(int, sys_getdents, uint, fd, struct linux_dirent *, dirp, uint, count);
 #endif
 #if !defined(__NR_getdents) || \
@@ -5580,6 +5580,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = get_errno(write(arg1, p, arg3));
         unlock_user(p, arg2, 0);
         break;
+#ifdef TARGET_NR_open
     case TARGET_NR_open:
         if (!(p = lock_user_string(arg1)))
             goto efault;
@@ -5588,6 +5589,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
                                   arg3));
         unlock_user(p, arg1, 0);
         break;
+#endif
     case TARGET_NR_openat:
         if (!(p = lock_user_string(arg2)))
             goto efault;
@@ -5602,9 +5604,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_brk:
         ret = do_brk(arg1);
         break;
+#ifdef TARGET_NR_fork
     case TARGET_NR_fork:
         ret = get_errno(do_fork(cpu_env, SIGCHLD, 0, 0, 0, 0));
         break;
+#endif
 #ifdef TARGET_NR_waitpid
     case TARGET_NR_waitpid:
         {
@@ -5639,6 +5643,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         unlock_user(p, arg1, 0);
         break;
 #endif
+#ifdef TARGET_NR_link
     case TARGET_NR_link:
         {
             void * p2;
@@ -5652,6 +5657,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             unlock_user(p, arg1, 0);
         }
         break;
+#endif
 #if defined(TARGET_NR_linkat)
     case TARGET_NR_linkat:
         {
@@ -5669,12 +5675,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
+#ifdef TARGET_NR_unlink
     case TARGET_NR_unlink:
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(unlink(p));
         unlock_user(p, arg1, 0);
         break;
+#endif
 #if defined(TARGET_NR_unlinkat)
     case TARGET_NR_unlinkat:
         if (!(p = lock_user_string(arg2)))
@@ -5791,12 +5799,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
+#ifdef TARGET_NR_mknod
     case TARGET_NR_mknod:
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(mknod(p, arg2, arg3));
         unlock_user(p, arg1, 0);
         break;
+#endif
 #if defined(TARGET_NR_mknodat)
     case TARGET_NR_mknodat:
         if (!(p = lock_user_string(arg2)))
@@ -5805,12 +5815,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         unlock_user(p, arg2, 0);
         break;
 #endif
+#ifdef TARGET_NR_chmod
     case TARGET_NR_chmod:
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(chmod(p, arg2));
         unlock_user(p, arg1, 0);
         break;
+#endif
 #ifdef TARGET_NR_break
     case TARGET_NR_break:
         goto unimplemented;
@@ -5945,6 +5957,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
+#ifdef TARGET_NR_utimes
     case TARGET_NR_utimes:
         {
             struct timeval *tvp, tv[2];
@@ -5963,6 +5976,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             unlock_user(p, arg1, 0);
         }
         break;
+#endif
 #if defined(TARGET_NR_futimesat)
     case TARGET_NR_futimesat:
         {
@@ -5991,12 +6005,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_gtty:
         goto unimplemented;
 #endif
+#ifdef TARGET_NR_access
     case TARGET_NR_access:
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(access(path(p), arg2));
         unlock_user(p, arg1, 0);
         break;
+#endif
 #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
     case TARGET_NR_faccessat:
         if (!(p = lock_user_string(arg2)))
@@ -6021,6 +6037,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_kill:
         ret = get_errno(kill(arg1, target_to_host_signal(arg2)));
         break;
+#ifdef TARGET_NR_rename
     case TARGET_NR_rename:
         {
             void *p2;
@@ -6034,6 +6051,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             unlock_user(p, arg1, 0);
         }
         break;
+#endif
 #if defined(TARGET_NR_renameat)
     case TARGET_NR_renameat:
         {
@@ -6049,12 +6067,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
+#ifdef TARGET_NR_mkdir
     case TARGET_NR_mkdir:
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(mkdir(p, arg2));
         unlock_user(p, arg1, 0);
         break;
+#endif
 #if defined(TARGET_NR_mkdirat)
     case TARGET_NR_mkdirat:
         if (!(p = lock_user_string(arg2)))
@@ -6063,18 +6083,22 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         unlock_user(p, arg2, 0);
         break;
 #endif
+#ifdef TARGET_NR_rmdir
     case TARGET_NR_rmdir:
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(rmdir(p));
         unlock_user(p, arg1, 0);
         break;
+#endif
     case TARGET_NR_dup:
         ret = get_errno(dup(arg1));
         break;
+#ifdef TARGET_NR_pipe
     case TARGET_NR_pipe:
         ret = do_pipe(cpu_env, arg1, 0, 0);
         break;
+#endif
 #ifdef TARGET_NR_pipe2
     case TARGET_NR_pipe2:
         ret = do_pipe(cpu_env, arg1,
@@ -6159,11 +6183,15 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = get_errno(chroot(p));
         unlock_user(p, arg1, 0);
         break;
+#ifdef TARGET_NR_ustat
     case TARGET_NR_ustat:
         goto unimplemented;
+#endif
+#ifdef TARGET_NR_dup2
     case TARGET_NR_dup2:
         ret = get_errno(dup2(arg1, arg2));
         break;
+#endif
 #if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
     case TARGET_NR_dup3:
         ret = get_errno(dup3(arg1, arg2, arg3));
@@ -6174,12 +6202,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = get_errno(getppid());
         break;
 #endif
+#ifdef TARGET_NR_getpgrp
     case TARGET_NR_getpgrp:
         ret = get_errno(getpgrp());
         break;
     case TARGET_NR_setsid:
         ret = get_errno(setsid());
         break;
+#endif
 #ifdef TARGET_NR_sigaction
     case TARGET_NR_sigaction:
         {
@@ -6752,6 +6782,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
+#ifdef TARGET_NR_symlink
     case TARGET_NR_symlink:
         {
             void *p2;
@@ -6765,6 +6796,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             unlock_user(p, arg1, 0);
         }
         break;
+#endif
 #if defined(TARGET_NR_symlinkat)
     case TARGET_NR_symlinkat:
         {
@@ -6784,6 +6816,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_oldlstat:
         goto unimplemented;
 #endif
+#ifdef TARGET_NR_readlink
     case TARGET_NR_readlink:
         {
             void *p2;
@@ -6814,6 +6847,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             unlock_user(p, arg1, 0);
         }
         break;
+#endif
 #if defined(TARGET_NR_readlinkat)
     case TARGET_NR_readlinkat:
         {
@@ -7213,22 +7247,28 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             }
         }
         break;
+#ifdef TARGET_NR_stat
     case TARGET_NR_stat:
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(stat(path(p), &st));
         unlock_user(p, arg1, 0);
         goto do_stat;
+#endif
+#ifdef TARGET_NR_lstat
     case TARGET_NR_lstat:
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(lstat(path(p), &st));
         unlock_user(p, arg1, 0);
         goto do_stat;
+#endif
     case TARGET_NR_fstat:
         {
             ret = get_errno(fstat(arg1, &st));
+#if defined(TARGET_NR_stat) || defined(TARGET_NR_lstat)
         do_stat:
+#endif
             if (!is_error(ret)) {
                 struct target_stat *target_st;
 
@@ -7516,6 +7556,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
+#ifdef TARGET_NR_getdents
     case TARGET_NR_getdents:
 #ifdef __NR_getdents
 #if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
@@ -7646,6 +7687,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
 #endif
         break;
+#endif /* TARGET_NR_getdents */
 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
     case TARGET_NR_getdents64:
         {
@@ -7785,11 +7827,13 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = get_errno(fdatasync(arg1));
         break;
 #endif
+#ifdef TARGET_NR__sysctl
     case TARGET_NR__sysctl:
         /* We don't implement this, but ENOTDIR is always a safe
            return value. */
         ret = -TARGET_ENOTDIR;
         break;
+#endif
     case TARGET_NR_sched_getaffinity:
         {
             unsigned int mask_size;
@@ -8236,12 +8280,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             ret = host_to_target_stat64(cpu_env, arg3, &st);
         break;
 #endif
+#ifdef TARGET_NR_lchown
     case TARGET_NR_lchown:
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(lchown(p, low2highuid(arg2), low2highgid(arg3)));
         unlock_user(p, arg1, 0);
         break;
+#endif
 #ifdef TARGET_NR_getuid
     case TARGET_NR_getuid:
         ret = get_errno(high2lowuid(getuid()));
@@ -8364,12 +8410,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
+#ifdef TARGET_NR_chown
     case TARGET_NR_chown:
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(chown(p, low2highuid(arg2), low2highgid(arg3)));
         unlock_user(p, arg1, 0);
         break;
+#endif
     case TARGET_NR_setuid:
         ret = get_errno(setuid(low2highuid(arg1)));
         break;
Signature · 1 line
1.9.3
#2 lore raw
In reply to Chen Gang

target-tilegx/translate.c line 120

Quoted 13 lines · Chen Gang
target-tilegx/translate.c new file +13 -0
+static void gen_fnop(void)
+{
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "(f)nop\n");
+}
+
+static void gen_cmpltui(struct DisasContext *dc,
+                        uint8_t rdst, uint8_t rsrc, int8_t imm8)
+{
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "cmpltui r%d, r%d, %d\n",
+                  rdst, rsrc, imm8);
+    tcg_gen_setcondi_i64(TCG_COND_LTU, dest_gr(dc, rdst), load_gr(dc, rsrc),
+                        (uint64_t)imm8);
+}

Wow, this is a lot more than before. Good progress.

Quoted 16 lines
target-tilegx/translate.c new file +16 -0
+/*
+ * The related functional description for bfextu in isa document:
+ *
+ * uint64_t mask = 0;
+ * mask = (-1ULL) ^ ((-1ULL << ((BFEnd - BFStart) & 63)) << 1);
+ * uint64_t rot_src = (((uint64_t) rf[SrcA]) >> BFStart)
+ *                    | (rf[SrcA] << (64 - BFStart));
+ * rf[Dest] = rot_src & mask;
+ */
+static void gen_bfextu(struct DisasContext *dc, uint8_t rdst, uint8_t rsrc,
+                       int8_t start, int8_t end)
+{
+    TCGv mask = tcg_temp_new_i64();
+    TCGv tmp = dest_gr(dc, rdst);
+
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "bfextu r%d, r%d, %d, %d\n",

target-tilegx/translate.c line 246

Quoted 10 lines
target-tilegx/translate.c new file +10 -0
+                  rdst, rsrc, start, end);
+
+    tcg_gen_movi_i64(tmp, -1ULL);
+    tcg_gen_movi_i64(mask, end);
+
+    tcg_gen_subi_i64(mask, mask, start);
+    tcg_gen_andi_i64(mask, mask, 63);
+    tcg_gen_shl_i64(mask, tmp, mask);
+    tcg_gen_shli_i64(mask, mask, 1);
+    tcg_gen_xori_i64(mask, mask, -1ULL);

This computation of MASK is only dependent on START and END, which are known at translation time. Thus you should perform this computation at translation time here in C, rather than defer the computation with TCG opcodes.

target-tilegx/translate.c line 249

Quoted 2 lines
target-tilegx/translate.c new file +2 -0
+    tcg_gen_rotli_i64(tmp, load_gr(dc, rsrc), start);
+    tcg_gen_and_i64(tmp, tmp, mask);

Which then makes this tcg_gen_andi_i64.

target-tilegx/translate.c line 313

Quoted 13 lines
target-tilegx/translate.c new file +13 -0
+static void gen_mulx(struct DisasContext *dc,
+                     uint8_t rdst, uint8_t rsrc, uint8_t rsrcb)
+{
+    TCGv tmp = tcg_temp_new_i64();
+    TCGv vdst = dest_gr(dc, rdst);
+
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "mulx r%d, r%d, r%d\n", rdst, rsrc, rsrcb);
+
+    tcg_gen_ext32s_i64(vdst, load_gr(dc, rsrc));
+    tcg_gen_ext32s_i64(tmp, load_gr(dc, rsrcb));
+
+    tcg_gen_mul_i64(tmp, vdst, tmp);
+    tcg_gen_ext32s_i64(vdst, tmp);

Note that you don't need the extensions prior to the MUL. The high 32-bits of the inputs don't affect the low 32-bits of the product.

target-tilegx/translate.c line 357

Quoted 7 lines
target-tilegx/translate.c new file +7 -0
+static void gen_shl16insli(struct DisasContext *dc,
+                           uint8_t rdst, uint8_t rsrc, uint16_t uimm16)
+{
+    TCGv vdst = dest_gr(dc, rdst);
+
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "shl16insli r%d, r%d, %llx\n",
+                  rdst, rsrc, (long long)uimm16);

Do not cast to long long. Print with just %x.

target-tilegx/translate.c line 378

Quoted 11 lines
target-tilegx/translate.c new file +11 -0
+static int gen_beqz(struct DisasContext *dc, uint8_t rsrc, int32_t off)
+{
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "beqz(t) r%d, %d\n", rsrc, off);
+
+    dc->jmp.dest = tcg_temp_new_i64();
+    dc->jmp.val1 = tcg_temp_new_i64();
+    dc->jmp.val2 = tcg_temp_new_i64();
+
+    dc->jmp.cond = TCG_COND_EQ;
+    tcg_gen_movi_i64(dc->jmp.dest,
+                     dc->pc + (int64_t)off * TILEGX_BUNDLE_SIZE_IN_BYTES);

It will be helpful for the disassembly if you print the destination of the branch rather than the offset.

Quoted 1 line

+ qemu_log_mask(LOG_UNIMP, "UNIMP rrr_1_opcode_y0, %16.16llx\n", bundle);

You shouldn't use "llx". You need to use PRIx64 instead. This will enable proper operation on Windows.

This patch set is just about ready for approval (though I don't imagine it will be merged until the qemu 2.4 development cycle).

r~

author
#3 lore raw
Quoted 17 lines · Richard Henderson

target-tilegx/translate.c line 120

Quoted 13 lines · Chen Gang
target-tilegx/translate.c new file +13 -0
+static void gen_fnop(void)
+{
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "(f)nop\n");
+}
+
+static void gen_cmpltui(struct DisasContext *dc,
+                        uint8_t rdst, uint8_t rsrc, int8_t imm8)
+{
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "cmpltui r%d, r%d, %d\n",
+                  rdst, rsrc, imm8);
+    tcg_gen_setcondi_i64(TCG_COND_LTU, dest_gr(dc, rdst), load_gr(dc, rsrc),
+                        (uint64_t)imm8);
+}

Wow, this is a lot more than before. Good progress.

OK, thanks. Because I am hunting the new jobs during these days, so I have more time resources on open source (at least, within this month). :-)

Quoted 31 lines
Quoted 16 lines
target-tilegx/translate.c new file +16 -0
+/*
+ * The related functional description for bfextu in isa document:
+ *
+ * uint64_t mask = 0;
+ * mask = (-1ULL) ^ ((-1ULL << ((BFEnd - BFStart) & 63)) << 1);
+ * uint64_t rot_src = (((uint64_t) rf[SrcA]) >> BFStart)
+ *                    | (rf[SrcA] << (64 - BFStart));
+ * rf[Dest] = rot_src & mask;
+ */
+static void gen_bfextu(struct DisasContext *dc, uint8_t rdst, uint8_t rsrc,
+                       int8_t start, int8_t end)
+{
+    TCGv mask = tcg_temp_new_i64();
+    TCGv tmp = dest_gr(dc, rdst);
+
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "bfextu r%d, r%d, %d, %d\n",

target-tilegx/translate.c line 246

Quoted 10 lines
target-tilegx/translate.c new file +10 -0
+                  rdst, rsrc, start, end);
+
+    tcg_gen_movi_i64(tmp, -1ULL);
+    tcg_gen_movi_i64(mask, end);
+
+    tcg_gen_subi_i64(mask, mask, start);
+    tcg_gen_andi_i64(mask, mask, 63);
+    tcg_gen_shl_i64(mask, tmp, mask);
+    tcg_gen_shli_i64(mask, mask, 1);
+    tcg_gen_xori_i64(mask, mask, -1ULL);

This computation of MASK is only dependent on START and END, which are known at translation time. Thus you should perform this computation at translation time here in C, rather than defer the computation with TCG opcodes.

Quoted 5 lines

target-tilegx/translate.c line 249

Quoted 2 lines
target-tilegx/translate.c new file +2 -0
+    tcg_gen_rotli_i64(tmp, load_gr(dc, rsrc), start);
+    tcg_gen_and_i64(tmp, tmp, mask);

Which then makes this tcg_gen_andi_i64.

OK, thanks, really it is.

Quoted 8 lines
Quoted 8 lines
target-tilegx/translate.c new file +8 -0
+static void gen_mulx(struct DisasContext *dc,
+                     uint8_t rdst, uint8_t rsrc, uint8_t rsrcb)
+{
+    TCGv tmp = tcg_temp_new_i64();
+    TCGv vdst = dest_gr(dc, rdst);
+
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "mulx r%d, r%d, r%d\n", rdst, rsrc, rsrcb);
+
Quoted 9 lines

target-tilegx/translate.c line 313

Quoted 5 lines
target-tilegx/translate.c new file +5 -0
+    tcg_gen_ext32s_i64(vdst, load_gr(dc, rsrc));
+    tcg_gen_ext32s_i64(tmp, load_gr(dc, rsrcb));
+
+    tcg_gen_mul_i64(tmp, vdst, tmp);
+    tcg_gen_ext32s_i64(vdst, tmp);

Note that you don't need the extensions prior to the MUL. The high 32-bits of the inputs don't affect the low 32-bits of the product.

For me, I am not quite sure about it, the related functional description is:

  rf[Dest] = signExtend32 ((int32_t) rf[SrcA] * (int32_t) rf[SrcB]);

Do you mean it is equal to:

  rf[Dest] = signExtend32 (rf[SrcA] * rf[SrcB]);
Quoted 10 lines

target-tilegx/translate.c line 357

Quoted 7 lines
target-tilegx/translate.c new file +7 -0
+static void gen_shl16insli(struct DisasContext *dc,
+                           uint8_t rdst, uint8_t rsrc, uint16_t uimm16)
+{
+    TCGv vdst = dest_gr(dc, rdst);
+
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "shl16insli r%d, r%d, %llx\n",
+                  rdst, rsrc, (long long)uimm16);

Do not cast to long long. Print with just %x.

OK, thanks.

Quoted 6 lines
Quoted 6 lines
target-tilegx/translate.c new file +6 -0
+static int gen_beqz(struct DisasContext *dc, uint8_t rsrc, int32_t off)
+{
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "beqz(t) r%d, %d\n", rsrc, off);
+
+    dc->jmp.dest = tcg_temp_new_i64();
+    dc->jmp.val1 = tcg_temp_new_i64();
Quoted 9 lines

target-tilegx/translate.c line 378

Quoted 5 lines
target-tilegx/translate.c new file +5 -0
+    dc->jmp.val2 = tcg_temp_new_i64();
+
+    dc->jmp.cond = TCG_COND_EQ;
+    tcg_gen_movi_i64(dc->jmp.dest,
+                     dc->pc + (int64_t)off * TILEGX_BUNDLE_SIZE_IN_BYTES);

It will be helpful for the disassembly if you print the destination of the branch rather than the offset.

OK, thanks.

Quoted 5 lines
Quoted 1 line

+ qemu_log_mask(LOG_UNIMP, "UNIMP rrr_1_opcode_y0, %16.16llx\n", bundle);

You shouldn't use "llx". You need to use PRIx64 instead. This will enable proper operation on Windows.

OK, thanks.

Quoted 3 lines

This patch set is just about ready for approval (though I don't imagine it will be merged until the qemu 2.4 development cycle).

OK, thanks. And I shall try to send patch v7 for the left issues within 2 days (2015-03-20).

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
#4 lore raw
Quoted 8 lines · Chen Gang

For me, I am not quite sure about it, the related functional description is:

  rf[Dest] = signExtend32 ((int32_t) rf[SrcA] * (int32_t) rf[SrcB]);

Do you mean it is equal to:

  rf[Dest] = signExtend32 (rf[SrcA] * rf[SrcB]);

Yes, of course.

Think about how multiplication works. Bit N of the input cannot affect any output bit in [N-1,0]. Thus the first sign-extend cannot affect the output.

r~

author
#5 lore raw
Quoted 6 lines · Richard Henderson
Quoted 5 lines · Chen Gang

For me, I am not quite sure about it, the related functional description is:

  rf[Dest] = signExtend32 ((int32_t) rf[SrcA] * (int32_t) rf[SrcB]);
Quoted 9 lines
Quoted 3 lines

Do you mean it is equal to:

  rf[Dest] = signExtend32 (rf[SrcA] * rf[SrcB]);

Yes, of course.

Think about how multiplication works. Bit N of the input cannot affect any output bit in [N-1,0]. Thus the first sign-extend cannot affect the output.

OK, thanks. I shall skip the first type cast in patch v8.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed