Skip to contentSkip to conversation

Execute _start and reach to the first function call successfully

PATCH In review Chen Gang 3 participants 7 messages Mar 14, 2015 – Mar 17, 2015

lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH v3 1/1 Execute _start and reach to the first function call successfully

QEMU TILE-Gx can decode bundle, disassemble code, and generate tcg code for 1st TB block (__start). Then directly jump to __libc_start_main (2nd TB block).

In __libc_start_main, it can continue executing to the first function call _dl_aux_init().

---
 target-tilegx/cpu-qom.h   |   2 +
 target-tilegx/cpu.c       |   4 -
 target-tilegx/cpu.h       |  22 +-
 target-tilegx/translate.c | 790 +++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 798 insertions(+), 20 deletions(-)
target-tilegx/cpu-qom.h +2 -0
index 4ee11e1..5615c3b 100644
@@ -68,4 +68,6 @@ static inline TileGXCPU *tilegx_env_get_cpu(CPUTLGState *env)
 
 #define ENV_GET_CPU(e) CPU(tilegx_env_get_cpu(e))
 
+#define ENV_OFFSET offsetof(TileGXCPU, env)
+
 #endif
target-tilegx/cpu.c +0 -4
index cf46b8b..8255fdc 100644
@@ -69,10 +69,6 @@ static void tilegx_cpu_realizefn(DeviceState *dev, Error **errp)
     tcc->parent_realize(dev, errp);
 }
 
-static void tilegx_tcg_init(void)
-{
-}
-
 static void tilegx_cpu_initfn(Object *obj)
 {
     CPUState *cs = CPU(obj);
target-tilegx/cpu.h +14 -8
index 87dc56b..93e16c3 100644
@@ -30,16 +30,21 @@
 #include "fpu/softfloat.h"
 
 /* TILE-Gx register alias */
-#define TILEGX_R_RE  0   /*  0 register, for function/syscall return value */
-#define TILEGX_R_NR  10  /* 10 register, for syscall number */
-#define TILEGX_R_BP  52  /* 52 register, optional frame pointer */
-#define TILEGX_R_TP  53  /* TP register, thread local storage data */
-#define TILEGX_R_SP  54  /* SP register, stack pointer */
-#define TILEGX_R_LR  55  /* LR register, may save pc, but it is not pc */
+#define TILEGX_R_RE    0   /*  0 register, for function/syscall return value */
+#define TILEGX_R_NR    10  /* 10 register, for syscall number */
+#define TILEGX_R_BP    52  /* 52 register, optional frame pointer */
+#define TILEGX_R_TP    53  /* TP register, thread local storage data */
+#define TILEGX_R_SP    54  /* SP register, stack pointer */
+#define TILEGX_R_LR    55  /* LR register, may save pc, but it is not pc */
+#define TILEGX_R_ZERO  63  /* Zero register, always zero */
+#define TILEGX_R_COUNT 56  /* Only 56 registers are really useful */
+#define TILEGX_R_NOREG 255 /* Invalid register value */
+
 
 typedef struct CPUTLGState {
-    uint64_t regs[56];
-    uint64_t pc;
+    uint64_t regs[TILEGX_R_COUNT]; /* Common used registers by outside */
+    uint64_t pc;                   /* Current pc */
+
     CPU_COMMON
 } CPUTLGState;
 
@@ -54,6 +59,7 @@ typedef struct CPUTLGState {
 
 #include "exec/cpu-all.h"
 
+void tilegx_tcg_init(void);
 int cpu_tilegx_exec(CPUTLGState *s);
 int cpu_tilegx_signal_handler(int host_signum, void *pinfo, void *puc);
 
target-tilegx/translate.c +782 -8

801 lines not on this page · raw message

Signature · 1 line
1.9.3
#1 lore raw
Quoted 13 lines · Chen Gang

QEMU TILE-Gx can decode bundle, disassemble code, and generate tcg code for 1st TB block (__start). Then directly jump to __libc_start_main (2nd TB block).

In __libc_start_main, it can continue executing to the first function call _dl_aux_init().

/* TILE-Gx register alias */

target-tilegx/cpu.h +0 -5
-#define TILEGX_R_RE  0   /*  0 register, for function/syscall return value */
-#define TILEGX_R_NR  10  /* 10 register, for syscall number */
-#define TILEGX_R_BP  52  /* 52 register, optional frame pointer */
-#define TILEGX_R_TP  53  /* TP register, thread local storage data */
-#define TILEGX_R_SP  54  /* SP register, stack pointer */

target-tilegx/cpu.h line 41

Quoted 10 lines
target-tilegx/cpu.h +9 -1
-#define TILEGX_R_LR  55  /* LR register, may save pc, but it is not pc */
+#define TILEGX_R_RE    0   /*  0 register, for function/syscall return value */
+#define TILEGX_R_NR    10  /* 10 register, for syscall number */
+#define TILEGX_R_BP    52  /* 52 register, optional frame pointer */
+#define TILEGX_R_TP    53  /* TP register, thread local storage data */
+#define TILEGX_R_SP    54  /* SP register, stack pointer */
+#define TILEGX_R_LR    55  /* LR register, may save pc, but it is not pc */
+#define TILEGX_R_ZERO  63  /* Zero register, always zero */
+#define TILEGX_R_COUNT 56  /* Only 56 registers are really useful */
+#define TILEGX_R_NOREG 255 /* Invalid register value */

This appears to be changing code that was introduced in a previous patch (which one? this patch doesn't appear to be part of a series). Don't do that -- just get it right in the first place.

-- PMM

author
#2 lore raw
Quoted 21 lines · Peter Maydell
Quoted 20 lines · Chen Gang

QEMU TILE-Gx can decode bundle, disassemble code, and generate tcg code for 1st TB block (__start). Then directly jump to __libc_start_main (2nd TB block).

In __libc_start_main, it can continue executing to the first function call _dl_aux_init().

/* TILE-Gx register alias */

target-tilegx/cpu.h +6 -6
-#define TILEGX_R_RE  0   /*  0 register, for function/syscall return value */
-#define TILEGX_R_NR  10  /* 10 register, for syscall number */
-#define TILEGX_R_BP  52  /* 52 register, optional frame pointer */
-#define TILEGX_R_TP  53  /* TP register, thread local storage data */
-#define TILEGX_R_SP  54  /* SP register, stack pointer */
-#define TILEGX_R_LR  55  /* LR register, may save pc, but it is not pc */
+#define TILEGX_R_RE    0   /*  0 register, for function/syscall return value */
+#define TILEGX_R_NR    10  /* 10 register, for syscall number */
+#define TILEGX_R_BP    52  /* 52 register, optional frame pointer */
+#define TILEGX_R_TP    53  /* TP register, thread local storage data */
+#define TILEGX_R_SP    54  /* SP register, stack pointer */
+#define TILEGX_R_LR    55  /* LR register, may save pc, but it is not pc */
Quoted 9 lines

target-tilegx/cpu.h line 41

Quoted 3 lines
target-tilegx/cpu.h +3 -0
+#define TILEGX_R_ZERO  63  /* Zero register, always zero */
+#define TILEGX_R_COUNT 56  /* Only 56 registers are really useful */
+#define TILEGX_R_NOREG 255 /* Invalid register value */

This appears to be changing code that was introduced in a previous patch (which one? this patch doesn't appear to be part of a series). Don't do that -- just get it right in the first place.

OK, thanks. And next, I shall try to send the whole tilegx patches again (it is about 6-8 patches), within 2015-03-18.

Thanks.

Signature · 3 lines
Chen Gang

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

OK, thanks. And next, I shall try to send the whole tilegx patches again (it is about 6-8 patches), within 2015-03-18.

When you do so, make sure it's against the *current* master tree.

Your patch set doesn't compile at all at the moment, after

commit 2994fd96d986578a342f2342501b4ad30f6d0a85

Author: Eduardo Habkost <[email protected]>
Date:   Thu Feb 26 17:37:49 2015 -0300

cpu: Make cpu_init() return QOM CPUState object

changed the return type of cpu_init.

In addition, one of your patches is going to need to copy over the linux opcodes_tilegx.h header file. Perhaps you forgot to "git add" the file when you created this "v3 Execute" patch?

r~

author
#4 lore raw
Quoted 9 lines · Richard Henderson
Quoted 2 lines · Chen Gang

OK, thanks. And next, I shall try to send the whole tilegx patches again (it is about 6-8 patches), within 2015-03-18.

When you do so, make sure it's against the *current* master tree.

Your patch set doesn't compile at all at the moment, after

Quoted 9 lines

commit 2994fd96d986578a342f2342501b4ad30f6d0a85

Author: Eduardo Habkost <[email protected]>
Date:   Thu Feb 26 17:37:49 2015 -0300

cpu: Make cpu_init() return QOM CPUState object

changed the return type of cpu_init.

OK, thanks, I shall merge current code to the latest master version.

Quoted 3 lines

In addition, one of your patches is going to need to copy over the linux opcodes_tilegx.h header file. Perhaps you forgot to "git add" the file when you created this "v3 Execute" patch?

Oh, sorry, I forgot it in patch v3.

And I shall send the tilegx patches within today (2015-03-18).

Thanks.

Signature · 3 lines
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
#5 lore raw
In reply to Chen Gang
Quoted 13 lines · Chen Gang
target-tilegx/translate.c +13 -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  FNOP_UNARY_OPCODE_Y0:
+            if (!get_SrcA_Y0(bundle) && !get_Dest_Y0(bundle)) {
+                gen_fnop();
+                return;
+            }
+            break;
+        default:

target-tilegx/translate.c line 278

Quoted 10 lines
target-tilegx/translate.c +10 -0
+            break;
+        }
+        break;
+    default:
+        break;
+    }
+
+    qemu_log_mask(LOG_UNIMP, "UNIMP rrr_1_opcode_y0, %16.16llx\n", bundle);
+    dc->exception = TILEGX_EXCP_OPCODE_UNIMPLEMENT;
+}

I think it would be helpful if, in the first patch, you put all of the opcode symbols into the proper place in the switch statements. That way it's easy to tell at a glance what has yet to be implemented. For instance, for this function you'd put

$ grep _UNARY opcode_tilegx.h  | grep _Y0
  CNTLZ_UNARY_OPCODE_Y0 = 1,
  CNTTZ_UNARY_OPCODE_Y0 = 2,
  FNOP_UNARY_OPCODE_Y0 = 3,
  FSINGLE_PACK1_UNARY_OPCODE_Y0 = 4,
  NOP_UNARY_OPCODE_Y0 = 5,
  PCNT_UNARY_OPCODE_Y0 = 6,
  REVBITS_UNARY_OPCODE_Y0 = 7,
  REVBYTES_UNARY_OPCODE_Y0 = 8,
  TBLIDXB0_UNARY_OPCODE_Y0 = 9,
  TBLIDXB1_UNARY_OPCODE_Y0 = 10,
  TBLIDXB2_UNARY_OPCODE_Y0 = 11,
  TBLIDXB3_UNARY_OPCODE_Y0 = 12,

in the get_UnaryOpcodeExtension_Y0 switch statement and

$ grep _RRR_1 opcode_tilegx.h  | grep _Y0
  SHL1ADD_RRR_1_OPCODE_Y0 = 0,
  SHL2ADD_RRR_1_OPCODE_Y0 = 1,
  SHL3ADD_RRR_1_OPCODE_Y0 = 2,
  UNARY_RRR_1_OPCODE_Y0 = 3,

in the get_RRROpcodeExtension_Y0 switch statement.

Likewise with all of the other "decode" functions that contain a switch.

target-tilegx/translate.c line 119

Quoted 2 lines
target-tilegx/translate.c +2 -0
+    qemu_log("fnop\n");
+    qemu_log("addi r%d, r%d, %d\n", rdst, rsrc, imm8);

Again, use qemu_log_mask(CPU_LOG_TB_IN_ASM).

r~

author
#6 lore raw
Quoted 52 lines · Richard Henderson
Quoted 13 lines · Chen Gang
target-tilegx/translate.c +13 -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  FNOP_UNARY_OPCODE_Y0:
+            if (!get_SrcA_Y0(bundle) && !get_Dest_Y0(bundle)) {
+                gen_fnop();
+                return;
+            }
+            break;
+        default:

target-tilegx/translate.c line 278

Quoted 10 lines
target-tilegx/translate.c +10 -0
+            break;
+        }
+        break;
+    default:
+        break;
+    }
+
+    qemu_log_mask(LOG_UNIMP, "UNIMP rrr_1_opcode_y0, %16.16llx\n", bundle);
+    dc->exception = TILEGX_EXCP_OPCODE_UNIMPLEMENT;
+}

I think it would be helpful if, in the first patch, you put all of the opcode symbols into the proper place in the switch statements. That way it's easy to tell at a glance what has yet to be implemented. For instance, for this function you'd put

$ grep _UNARY opcode_tilegx.h  | grep _Y0
  CNTLZ_UNARY_OPCODE_Y0 = 1,
  CNTTZ_UNARY_OPCODE_Y0 = 2,
  FNOP_UNARY_OPCODE_Y0 = 3,
  FSINGLE_PACK1_UNARY_OPCODE_Y0 = 4,
  NOP_UNARY_OPCODE_Y0 = 5,
  PCNT_UNARY_OPCODE_Y0 = 6,
  REVBITS_UNARY_OPCODE_Y0 = 7,
  REVBYTES_UNARY_OPCODE_Y0 = 8,
  TBLIDXB0_UNARY_OPCODE_Y0 = 9,
  TBLIDXB1_UNARY_OPCODE_Y0 = 10,
  TBLIDXB2_UNARY_OPCODE_Y0 = 11,
  TBLIDXB3_UNARY_OPCODE_Y0 = 12,

in the get_UnaryOpcodeExtension_Y0 switch statement and

$ grep _RRR_1 opcode_tilegx.h  | grep _Y0
  SHL1ADD_RRR_1_OPCODE_Y0 = 0,
  SHL2ADD_RRR_1_OPCODE_Y0 = 1,
  SHL3ADD_RRR_1_OPCODE_Y0 = 2,
  UNARY_RRR_1_OPCODE_Y0 = 3,
Quoted 4 lines

in the get_RRROpcodeExtension_Y0 switch statement.

Likewise with all of the other "decode" functions that contain a switch.

OK, thanks. It is a good idea to me.

Quoted 5 lines

target-tilegx/translate.c line 119

Quoted 2 lines
target-tilegx/translate.c +2 -0
+    qemu_log("fnop\n");
+    qemu_log("addi r%d, r%d, %d\n", rdst, rsrc, imm8);

Again, use qemu_log_mask(CPU_LOG_TB_IN_ASM).

OK, thanks. I shall use qemu_log_mask in all areas within tilegx.

Thanks.

Signature · 3 lines
Chen Gang

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