Skip to contentSkip to conversation

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

PATCH In review Chen Gang 3 participants 14 messages Mar 20, 2015 – Mar 21, 2015 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Chen Gang

author
#1 lore raw

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

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             | 1764 +++++++++++++++++++++++++++++++++
 10 files changed, 3523 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 589798e..a8704ec 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 +1764 -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.

#2 lore raw
Quoted 9 lines · Chen Gang
target-tilegx/translate.c new file +9 -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;
+ */

target-tilegx/translate.c line 239

Quoted 10 lines
target-tilegx/translate.c new file +10 -0
+static void gen_bfextu(struct DisasContext *dc, uint8_t rdst, uint8_t rsrc,
+                       int8_t start, int8_t end)
+{
+    uint64_t mask = (-1ULL) ^ ((-1ULL << ((end - start) & 63)) << 1);
+    TCGv tmp = dest_gr(dc, rdst);
+
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "bfextu r%d, r%d, %d, %d\n",
+                  rdst, rsrc, start, end);
+
+    tcg_gen_rotli_i64(tmp, load_gr(dc, rsrc), start);

Wrong direction rotate: rotri.

Quoted 21 lines
target-tilegx/translate.c new file +21 -0
+static void decode_rrr_1_opcode_y0(struct DisasContext *dc,
+                                   tilegx_bundle_bits bundle)
+{
+    switch (get_RRROpcodeExtension_Y0(bundle)) {
+    case UNARY_RRR_1_OPCODE_Y0:
+        switch (get_UnaryOpcodeExtension_Y0(bundle)) {
+        case NOP_UNARY_OPCODE_Y0:
+        case  FNOP_UNARY_OPCODE_Y0:
+            if (!get_SrcA_Y0(bundle) && !get_Dest_Y0(bundle)) {
+                gen_fnop();
+                return;
+            }
+            break;
+        case CNTLZ_UNARY_OPCODE_Y0:
+        case CNTTZ_UNARY_OPCODE_Y0:
+        case FSINGLE_PACK1_UNARY_OPCODE_Y0:
+        case PCNT_UNARY_OPCODE_Y0:
+        case REVBITS_UNARY_OPCODE_Y0:
+        case REVBYTES_UNARY_OPCODE_Y0:
+        case TBLIDXB0_UNARY_OPCODE_Y0:
+        case TBLIDXB1_UNARY_OPCODE_Y0:

target-tilegx/translate.c line 539

Quoted 10 lines
target-tilegx/translate.c new file +10 -0
+        case TBLIDXB2_UNARY_OPCODE_Y0:
+        case TBLIDXB3_UNARY_OPCODE_Y0:
+        default:
+            break;
+        }
+        break;
+    case SHL1ADD_RRR_1_OPCODE_Y0:
+    case SHL2ADD_RRR_1_OPCODE_Y0:
+    case SHL3ADD_RRR_1_OPCODE_Y0:
+    case RRR_1_OPCODE_Y0:

RRR_1_OPCODE_Y0 doesn't belong. It's the main opcode that brought us here.

target-tilegx/translate.c line 545

Quoted 6 lines
target-tilegx/translate.c new file +6 -0
+    default:
+        break;
+    }
+
+    qemu_log_mask(LOG_UNIMP, "UNIMP rrr_1_opcode_y0, [" TARGET_FMT_lx "]\n",
+                  (uint64_t)bundle);

Eh, TARGET_FMT_lx is tied to TARGET_LONG_BITS, and you're not using target_long but uint64_t. I think it would be better to use "%016" PRIx64 directly, or create your own macro for this file.

r~

author
#3 lore raw
Quoted 14 lines · Richard Henderson
Quoted 13 lines · Chen Gang
target-tilegx/translate.c new file +13 -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)
+{
+    uint64_t mask = (-1ULL) ^ ((-1ULL << ((end - start) & 63)) << 1);
Quoted 9 lines

target-tilegx/translate.c line 239

Quoted 6 lines
target-tilegx/translate.c new file +6 -0
+    TCGv tmp = dest_gr(dc, rdst);
+
+    qemu_log_mask(CPU_LOG_TB_IN_ASM, "bfextu r%d, r%d, %d, %d\n",
+                  rdst, rsrc, start, end);
+
+    tcg_gen_rotli_i64(tmp, load_gr(dc, rsrc), start);

Wrong direction rotate: rotri.

OK, thank you very much!!

Quoted 25 lines
Quoted 25 lines
target-tilegx/translate.c new file +25 -0
+static void decode_rrr_1_opcode_y0(struct DisasContext *dc,
+                                   tilegx_bundle_bits bundle)
+{
+    switch (get_RRROpcodeExtension_Y0(bundle)) {
+    case UNARY_RRR_1_OPCODE_Y0:
+        switch (get_UnaryOpcodeExtension_Y0(bundle)) {
+        case NOP_UNARY_OPCODE_Y0:
+        case  FNOP_UNARY_OPCODE_Y0:
+            if (!get_SrcA_Y0(bundle) && !get_Dest_Y0(bundle)) {
+                gen_fnop();
+                return;
+            }
+            break;
+        case CNTLZ_UNARY_OPCODE_Y0:
+        case CNTTZ_UNARY_OPCODE_Y0:
+        case FSINGLE_PACK1_UNARY_OPCODE_Y0:
+        case PCNT_UNARY_OPCODE_Y0:
+        case REVBITS_UNARY_OPCODE_Y0:
+        case REVBYTES_UNARY_OPCODE_Y0:
+        case TBLIDXB0_UNARY_OPCODE_Y0:
+        case TBLIDXB1_UNARY_OPCODE_Y0:
+        case TBLIDXB2_UNARY_OPCODE_Y0:
+        case TBLIDXB3_UNARY_OPCODE_Y0:
+        default:
+            break;
Quoted 9 lines

target-tilegx/translate.c line 539

Quoted 6 lines
target-tilegx/translate.c new file +6 -0
+        }
+        break;
+    case SHL1ADD_RRR_1_OPCODE_Y0:
+    case SHL2ADD_RRR_1_OPCODE_Y0:
+    case SHL3ADD_RRR_1_OPCODE_Y0:
+    case RRR_1_OPCODE_Y0:

RRR_1_OPCODE_Y0 doesn't belong. It's the main opcode that brought us here.

OK, thanks.

Quoted 11 lines

target-tilegx/translate.c line 545

Quoted 6 lines
target-tilegx/translate.c new file +6 -0
+    default:
+        break;
+    }
+
+    qemu_log_mask(LOG_UNIMP, "UNIMP rrr_1_opcode_y0, [" TARGET_FMT_lx "]\n",
+                  (uint64_t)bundle);

Eh, TARGET_FMT_lx is tied to TARGET_LONG_BITS, and you're not using target_long but uint64_t. I think it would be better to use "%016" PRIx64 directly, or create your own macro for this file.

Oh, really, 'bundle' is defined as 'tilegx_bundle_bits' which is not for "target long" (in 32-bit tilepro, 'tilepro_bundle_bits' is also 64-bit).

I shall define FMT64X for it within 'translate.c', just like:

tests/tcg/test-i386.c:53:#define FMT64X "%016" PRIx64

Thanks.

Signature · 3 lines
Chen Gang

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

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().

Quoted 12 lines
---
 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             | 1764 +++++++++++++++++++++++++++++++++
 10 files changed, 3523 insertions(+)

If you have any patch which has a diffstat like this then you *must* split it up into separate patches. Even 1000 lines is really too long to be easily reviewable, and this patch is now over three times that size! Most patches should be 250 lines or less, really, unless they're very mechanical.

-- PMM

author
#5 lore raw
Quoted 21 lines · Peter Maydell
Quoted 7 lines · Chen Gang

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().

Quoted 12 lines
---
 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             | 1764 +++++++++++++++++++++++++++++++++
 10 files changed, 3523 insertions(+)
Quoted 7 lines

If you have any patch which has a diffstat like this then you *must* split it up into separate patches. Even 1000 lines is really too long to be easily reviewable, and this patch is now over three times that size! Most patches should be 250 lines or less, really, unless they're very mechanical.

OK, thanks. I shall try to split it into 3 patches in patch v8.

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
#6 lore raw
Quoted 12 lines · Chen Gang
Quoted 10 lines · Peter Maydell
Quoted 1 line · Chen Gang
 10 files changed, 3523 insertions(+)

If you have any patch which has a diffstat like this then you *must* split it up into separate patches. Even 1000 lines is really too long to be easily reviewable, and this patch is now over three times that size! Most patches should be 250 lines or less, really, unless they're very mechanical.

Quoted 1 line

OK, thanks. I shall try to split it into 3 patches in patch v8.

Even 3 would still leave at least one of them more than 1000 lines. I would suggest that you should be thinking more like turning this one into 7 or 8 patches.

-- PMM

author
#7 lore raw
Quoted 13 lines · Peter Maydell
Quoted 12 lines · Chen Gang
Quoted 10 lines · Peter Maydell
Quoted 1 line · Chen Gang
 10 files changed, 3523 insertions(+)

If you have any patch which has a diffstat like this then you *must* split it up into separate patches. Even 1000 lines is really too long to be easily reviewable, and this patch is now over three times that size! Most patches should be 250 lines or less, really, unless they're very mechanical.

Quoted 6 lines
Quoted 1 line

OK, thanks. I shall try to split it into 3 patches in patch v8.

Even 3 would still leave at least one of them more than 1000 lines. I would suggest that you should be thinking more like turning this one into 7 or 8 patches.

For 'opcode_tilegx.h', it comes from Linux kernel which is already more than 1000 lines. For me, I still suggest to let it within one patch.

For 'translate.c', I try to split it into 3 patches:

- parsing bundle and decode to the first level of pipe,

- parsing 2nd level of pipe.

- generate tcg code.

For the left files:

- 'configure', 'Makefile.obj', 'tilegx-linux-user.mak' are in a patch.

- 'cpu*' are in a patch

- 'help.*' are in a patch.

Welcome any additional ideas, and I shall try to send it within 2 days (2015-03-22).

Thanks.

Signature · 3 lines
Chen Gang

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

For 'opcode_tilegx.h', it comes from Linux kernel which is already more than 1000 lines. For me, I still suggest to let it within one patch.

Right, for that sort of special case you should put it in a single patch which is just "Import copy of whatever.h from Linux kernel", and which has nothing else in it except for the imported file or files, and which makes no QEMU specific changes to those files. Then people can skim through that patch quickly knowing they don't have to look for any changes or extras that do need review. (If there is some tweak that needs to be made for QEMU's purposes that can go in a subsequent patch.)

Quoted 8 lines

For 'translate.c', I try to split it into 3 patches:

- parsing bundle and decode to the first level of pipe,

- parsing 2nd level of pipe.

- generate tcg code.

Quoted 7 lines

For the left files:

- 'configure', 'Makefile.obj', 'tilegx-linux-user.mak' are in a patch.

- 'cpu*' are in a patch

- 'help.*' are in a patch.

I would suggest that rather than having "cpu* in one patch and help* in another" (ie a split by file), you split things functionally, so you might have a patch adding "support for instruction group foo" which includes everything needed for those instructions including the translate.c changes and the helper functions that get called by the generated code.

Remember to make sure that everything still compiles at every step in the patch series.

-- PMM

author
#9 lore raw
Quoted 4 lines · Peter Maydell
Quoted 2 lines · Chen Gang

For 'opcode_tilegx.h', it comes from Linux kernel which is already more than 1000 lines. For me, I still suggest to let it within one patch.

Quoted 9 lines

Right, for that sort of special case you should put it in a single patch which is just "Import copy of whatever.h from Linux kernel", and which has nothing else in it except for the imported file or files, and which makes no QEMU specific changes to those files. Then people can skim through that patch quickly knowing they don't have to look for any changes or extras that do need review. (If there is some tweak that needs to be made for QEMU's purposes that can go in a subsequent patch.)

OK, thanks (at present, opcode_tilegx.h has no any changes, it is only a copy from Linux kernel).

Quoted 16 lines
Quoted 8 lines

For 'translate.c', I try to split it into 3 patches:

- parsing bundle and decode to the first level of pipe,

- parsing 2nd level of pipe.

- generate tcg code.

Quoted 7 lines

For the left files:

- 'configure', 'Makefile.obj', 'tilegx-linux-user.mak' are in a patch.

- 'cpu*' are in a patch

- 'help.*' are in a patch.

Quoted 8 lines

I would suggest that rather than having "cpu* in one patch and help* in another" (ie a split by file), you split things functionally, so you might have a patch adding "support for instruction group foo" which includes everything needed for those instructions including the translate.c changes and the helper functions that get called by the generated code.

OK, thanks. But I have sent patches v8, please help check them, if they are really not suitable (about splitting patch), please let me know.

Quoted 3 lines

Remember to make sure that everything still compiles at every step in the patch series.

For translate.c, it has three patches, each patch can pass compiling (but the other patches in patch v8 can not). Please help check patches v8 for more details, if they are really not suitable, please let me know.

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
author
#10 lore raw

PATCH v7 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
#11 lore raw

PATCH v7 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
#12 lore raw

PATCH v7 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
#13 lore raw

PATCH v7 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
#14 lore raw

PATCH v7 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