Skip to contentSkip to conversation

MIPS64 user mode emulation in QEMU with Cavium specific instruction support

PATCH In review [email protected] 2 participants 13 messages Aug 15, 2011 – Aug 17, 2011

lore
Share & tools
lore
#0 lore raw

cover MIPS64 user mode emulation in QEMU with Cavium specific instruction support

From: Khansa Butt <[email protected]>

This is the team work of Ehsan-ul-Haq, Abdul Qadeer, Abdul Waheed, Khansa Butt from HPCN Lab KICS UET Lahore.

Cavium Networks's Octeon processors are based on MIPS64r2
We have Implemented 27 user mode Cavium specific instructions.
Richard Henderson told me that QEMU does not support 64-bit
address spaces in user mode from a 32-bit host. so this code will work
only on 64 bit host. Although we did some workaround to run MIPS64 on 32 x86 and it can be generlized for other architectures. We will submit that after this submission. This development work is tested for 64 bit X86 and working fine all Cavium specific instructions are also tested. teast cases can be provided if required. Octeon binaries (ELF) can be downloaded from below links 1)http://dl.dropbox.com/u/19530066/hw_mips 2)http://dl.dropbox.com/u/19530066/matmul
If you have any objection regarding the Implementation of
Cavium instructions please read following notes.

Notes
*****

The detail of some instructions are as follows
1)seq rd,rs,rt
seq-->rd = 1 if rs = rt
is equivalent to
xor rd,rs,rt
sltiu rd,rd,1
2)exts rt,rs,p,lenm1
rt = sign-extend(rs<p+lenm1:p>,lenm1)

Quoted 1 line

From reference manual of Cavium Networks

"Bit locations p + lenm1 to p are extracted from rs and the result is written into the lowest bits of destination register rt. The remaining bits in rt are a sign-extension of the most-significant bit of the bit field (i.e. rt<63:lenm1> are all duplicates of the source-register bit rs<p+lenm1>)." so we can't use any of 8,16 or 32 bit sign extention tcg function. To sign extend according to msb of bit field we have our own implementation
3)dmul rd,rs,rt
This instruction is included in gen_arith() because it is three operand double word multiply instruction.

Signature · 1 line
1.7.3.4
#1 lore raw

PATCH 1/4 linux-user:Support for MIPS64 user mode emulation in QEMU

From: Khansa Butt <[email protected]>

---
 configure                             |    1 +
 default-configs/mips64-linux-user.mak |    1 +
 linux-user/main.c                     |   21 +++++++++++++++++++--
 linux-user/mips64/syscall.h           |    2 ++
 linux-user/signal.c                   |    2 --
 5 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 default-configs/mips64-linux-user.mak
configure +1 -0
index 0c67a4a..14a1f58 100755
@@ -884,6 +884,7 @@ m68k-linux-user \
 microblaze-linux-user \
 microblazeel-linux-user \
 mips-linux-user \
+mips64-linux-user \
 mipsel-linux-user \
 ppc-linux-user \
 ppc64-linux-user \
default-configs/mips64-linux-user.mak new file +1 -0
new file mode 100644
index 0000000..1598bfc
@@ -0,0 +1 @@
+# Default configuration for mips64-linux-user
linux-user/main.c +19 -2
index 8e15474..8f14605 100644
@@ -2068,7 +2068,8 @@ static int do_store_exclusive(CPUMIPSState *env)
 void cpu_loop(CPUMIPSState *env)
 {
     target_siginfo_t info;
-    int trapnr, ret;
+    int trapnr;
+    abi_long ret;
     unsigned int syscall_num;
 
     for(;;) {
@@ -2077,8 +2078,23 @@ void cpu_loop(CPUMIPSState *env)
         cpu_exec_end(env);
         switch(trapnr) {
         case EXCP_SYSCALL:
-            syscall_num = env->active_tc.gpr[2] - 4000;
             env->active_tc.PC += 4;
+#if defined(TARGET_MIPS64)
+            syscall_num = env->active_tc.gpr[2] - 5000;
+            /* MIPS64 has eight argument registers so there is
+             * no need to get arguments from stack
+             */
+            ret = do_syscall(env, env->active_tc.gpr[2],
+                             env->active_tc.gpr[4],
+                             env->active_tc.gpr[5],
+                             env->active_tc.gpr[6],
+                             env->active_tc.gpr[7],
+                             env->active_tc.gpr[8],
+                             env->active_tc.gpr[9],
+                             env->active_tc.gpr[10],
+                             env->active_tc.gpr[11]);
+#else
+            syscall_num = env->active_tc.gpr[2] - 4000;
             if (syscall_num >= sizeof(mips_syscall_args)) {
                 ret = -TARGET_ENOSYS;
             } else {
@@ -2105,6 +2121,7 @@ void cpu_loop(CPUMIPSState *env)
                                  env->active_tc.gpr[7],
                                  arg5, arg6, arg7, arg8);
             }
+#endif
             if (ret == -TARGET_QEMU_ESIGRETURN) {
                 /* Returning from a successful sigreturn syscall.
                    Avoid clobbering register state.  */
linux-user/mips64/syscall.h +2 -0
index 668a2b9..96f03da 100644
@@ -218,4 +218,6 @@ struct target_pt_regs {
 
 
 
+#define TARGET_QEMU_ESIGRETURN 255
+
 #define UNAME_MACHINE "mips64"
linux-user/signal.c +0 -2
index 07ad07a..b23922d 100644
@@ -2415,8 +2415,6 @@ void sparc64_get_context(CPUSPARCState *env)
 #endif
 #elif defined(TARGET_ABI_MIPSN64)
 
-# warning signal handling not implemented
-
 static void setup_frame(int sig, struct target_sigaction *ka,
 			target_sigset_t *set, CPUState *env)
 {
Signature · 1 line
1.7.3.4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] linux-user:Support for MIPS64 user mode emulation in QEMU

linux-user/signal.c void sparc64_get_context(CPUSPARCState *env) · line 2419

Quoted 2 lines · On 08/15/2011 04:25 AM, [email protected] wrote:
linux-user/signal.c +0 -2
-# warning signal handling not implemented
-

Why? It's still true. Just configure with --disable-werror.

r~

#3 lore raw

PATCH 2/4 Octeon cpu definitions in target-mips and Octeon specific changes in set_thread_area syscall

In reply to [email protected]

From: Khansa Butt <[email protected]>

---
 linux-user/syscall.c         |    5 +++++
 target-mips/mips-defs.h      |    2 ++
 target-mips/translate_init.c |   24 ++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 0 deletions(-)
linux-user/syscall.c +5 -0
index 73f9baa..90ace4b 100644
@@ -7653,6 +7653,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_set_thread_area:
 #if defined(TARGET_MIPS)
       ((CPUMIPSState *) cpu_env)->tls_value = arg1;
+      if (((CPUMIPSState *) cpu_env)->insn_flags & CPU_OCTEON) {
+          /* tls entry is moved to k0 so that this can be used later
+             currently this thing is tested only for Octeon */
+          ((CPUMIPSState *) cpu_env)->active_tc.gpr[26] = arg1;
+      }
       ret = 0;
       break;
 #elif defined(TARGET_CRIS)
target-mips/mips-defs.h +2 -0
index bf094a3..e1ec2b2 100644
@@ -41,6 +41,7 @@
 #define 	ASE_MICROMIPS	0x00080000
 
 /* Chip specific instructions. */
+#define         INSN_OCTEON  0x10000000
 #define		INSN_LOONGSON2E  0x20000000
 #define		INSN_LOONGSON2F  0x40000000
 #define		INSN_VR54XX	0x80000000
@@ -53,6 +54,7 @@
 #define		CPU_VR54XX	(CPU_MIPS4 | INSN_VR54XX)
 #define		CPU_LOONGSON2E  (CPU_MIPS3 | INSN_LOONGSON2E)
 #define		CPU_LOONGSON2F  (CPU_MIPS3 | INSN_LOONGSON2F)
+#define         CPU_OCTEON      (CPU_MIPS64R2 | INSN_OCTEON)
 
 #define		CPU_MIPS5	(CPU_MIPS4 | ISA_MIPS5)
 
target-mips/translate_init.c +24 -0
index d55c522..7d7e1e9 100644
@@ -451,6 +451,30 @@ static const mips_def_t mips_defs[] =
         .mmu_type = MMU_TYPE_R4000,
     },
     {
+        .name = "octeon",
+        .CP0_PRid = 0x0d30,
+        .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) | (0x2 << CP0C0_AT) |
+                       (MMU_TYPE_R4000 << CP0C0_MT),
+        .CP0_Config1 = MIPS_CONFIG1 | (63 << CP0C1_MMU) |
+                       (2 << CP0C1_IS) | (4 << CP0C1_IL) | (3 << CP0C1_IA) |
+                       (2 << CP0C1_DS) | (4 << CP0C1_DL) | (3 << CP0C1_DA) |
+                       (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
+        .CP0_Config2 = MIPS_CONFIG2,
+        .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_LPA),
+        .CP0_LLAddr_rw_bitmask = 0,
+        .CP0_LLAddr_shift = 0,
+        .SYNCI_Step = 32,
+        .CCRes = 2,
+        .CP0_Status_rw_bitmask = 0x36FBFFFF,
+        .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_3D) | (1 << FCR0_PS) |
+                    (1 << FCR0_L) | (1 << FCR0_W) | (1 << FCR0_D) |
+                    (1 << FCR0_S) | (0x00 << FCR0_PRID) | (0x0 << FCR0_REV),
+        .SEGBITS = 49,
+        .PABITS = 49,
+        .insn_flags = CPU_OCTEON | ASE_MIPS3D,
+        .mmu_type = MMU_TYPE_R4000,
+    },
+    {
         .name = "Loongson-2E",
         .CP0_PRid = 0x6302,
         /*64KB I-cache and d-cache. 4 way with 32 bit cache line size*/
Signature · 1 line
1.7.3.4
#4 lore raw

Re: [Qemu-devel] [PATCH 2/4] Octeon cpu definitions in target-mips and Octeon specific changes in set_thread_area syscall

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 7660

Quoted 6 lines · On 08/15/2011 04:25 AM, [email protected] wrote:
       ((CPUMIPSState *) cpu_env)->tls_value = arg1;
linux-user/syscall.c +5 -0
+      if (((CPUMIPSState *) cpu_env)->insn_flags & CPU_OCTEON) {
+          /* tls entry is moved to k0 so that this can be used later
+             currently this thing is tested only for Octeon */
+          ((CPUMIPSState *) cpu_env)->active_tc.gpr[26] = arg1;
+      }

You wanted INSN_OCTEON, not CPU_OCTEON, which includes CPU_MIPS64R2.

That said, this is *not* in the current linux kernel. And I question the wisdom of changing the user-space ABI for TLS for a single CPU.

I think you'd better leave this out until it's actually accepted upstream.

r~

#5 lore raw

Re: [Qemu-devel] [PATCH 2/4] Octeon cpu definitions in target-mips and Octeon specific changes in set_thread_area syscall

Quoted 8 lines · Richard Henderson

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 7660

Quoted 6 lines · On 08/15/2011 04:25 AM, [email protected] wrote:
       ((CPUMIPSState *) cpu_env)->tls_value = arg1;
linux-user/syscall.c +5 -0
+      if (((CPUMIPSState *) cpu_env)->insn_flags & CPU_OCTEON) {
+          /* tls entry is moved to k0 so that this can be used later
+             currently this thing is tested only for Octeon */
+          ((CPUMIPSState *) cpu_env)->active_tc.gpr[26] = arg1;
+      }
Quoted 7 lines

You wanted INSN_OCTEON, not CPU_OCTEON, which includes CPU_MIPS64R2.

That said, this is *not* in the current linux kernel. And I question the wisdom of changing the user-space ABI for TLS for a single CPU.

I think you'd better leave this out until it's actually accepted upstream.

with out above fix Octeon user mode binary can not be correctly run on QEMU. This was the behavior on actual hardware which we noticed when we were debugging the
user mode binary on Octeon board.
(there are instructions in user mode ELF of Octeon which read k0 and k1 values)

Quoted 4 lines

r~

#6 lore raw

Re: [Qemu-devel] [PATCH 2/4] Octeon cpu definitions in target-mips and Octeon specific changes in set_thread_area syscall

Quoted 5 lines · Khansa Butt

with out above fix Octeon user mode binary can not be correctly run on QEMU. This was the behavior on actual hardware which we noticed when we were debugging the user mode binary on Octeon board. (there are instructions in user mode ELF of Octeon which read k0 and k1 values)

So you're running a modified compiler, libc, and kernel as well?

Because if I look in Linux 3.1-rc2, arch/mips/kernel/syscall.c, set_thread_area and arch/mips/kernel/process.c, copy_thread, I see no evidence that any mips variant uses k0 or k1 for TLS.

You should keep this change alongside whatever modified runtime you are using. It does not belong upstream in QEMU until your changes are accepted upstream in linux as well.

r~

#7 lore raw

PATCH 3/4 target-mips:Support for Cavium specific instructions

In reply to [email protected]

From: Ehsan-ul-Haq, Abdul Qadeer, Abdul Waheed, Khansa Butt <[email protected]>

---
 target-mips/cpu.h       |    7 +
 target-mips/helper.h    |    5 +
 target-mips/machine.c   |   12 ++
 target-mips/op_helper.c |   72 ++++++++
 target-mips/translate.c |  434 ++++++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 525 insertions(+), 5 deletions(-)
target-mips/cpu.h +7 -0
index c5f70fa..385f6d3 100644
@@ -173,6 +173,13 @@ struct TCState {
     target_ulong CP0_TCSchedule;
     target_ulong CP0_TCScheFBack;
     int32_t CP0_Debug_tcstatus;
+    /* Multiplier registers for Octeon */
+    target_ulong MPL0;
+    target_ulong MPL1;
+    target_ulong MPL2;
+    target_ulong P0;
+    target_ulong P1;
+    target_ulong P2;
 };
 
 typedef struct CPUMIPSState CPUMIPSState;
target-mips/helper.h +5 -0
index 297ab64..e892d39 100644
@@ -8,7 +8,12 @@ DEF_HELPER_3(ldl, tl, tl, tl, int)
 DEF_HELPER_3(ldr, tl, tl, tl, int)
 DEF_HELPER_3(sdl, void, tl, tl, int)
 DEF_HELPER_3(sdr, void, tl, tl, int)
+DEF_HELPER_2(v3mulu, tl, tl, tl)
+DEF_HELPER_2(vmulu, tl, tl, tl)
+DEF_HELPER_1(dpop, tl, tl)
 #endif
+DEF_HELPER_1(pop, tl, tl);
+
 DEF_HELPER_3(lwl, tl, tl, tl, int)
 DEF_HELPER_3(lwr, tl, tl, tl, int)
 DEF_HELPER_3(swl, void, tl, tl, int)
target-mips/machine.c +12 -0
index be72b36..a274ce2 100644
@@ -25,6 +25,12 @@ static void save_tc(QEMUFile *f, TCState *tc)
     qemu_put_betls(f, &tc->CP0_TCSchedule);
     qemu_put_betls(f, &tc->CP0_TCScheFBack);
     qemu_put_sbe32s(f, &tc->CP0_Debug_tcstatus);
+    qemu_put_betls(f, &tc->MPL0);
+    qemu_put_betls(f, &tc->MPL1);
+    qemu_put_betls(f, &tc->P0);
+    qemu_put_betls(f, &tc->P1);
+    qemu_put_betls(f, &tc->P2);
+
 }
 
 static void save_fpu(QEMUFile *f, CPUMIPSFPUContext *fpu)
@@ -173,6 +179,12 @@ static void load_tc(QEMUFile *f, TCState *tc)
     qemu_get_betls(f, &tc->CP0_TCSchedule);
     qemu_get_betls(f, &tc->CP0_TCScheFBack);
     qemu_get_sbe32s(f, &tc->CP0_Debug_tcstatus);
+    qemu_get_betls(f, &tc->MPL0);
+    qemu_get_betls(f, &tc->MPL1);
+    qemu_get_betls(f, &tc->MPL2);
+    qemu_get_betls(f, &tc->P0);
+    qemu_get_betls(f, &tc->P1);
+    qemu_get_betls(f, &tc->P2);
 }
 
 static void load_fpu(QEMUFile *f, CPUMIPSFPUContext *fpu)
target-mips/op_helper.c +72 -0

80 lines not on this page · raw message

target-mips/translate.c +429 -5

515 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#8 lore raw

Re: [Qemu-devel] [PATCH 3/4] target-mips:Support for Cavium specific instructions

target-mips/translate.c static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc, · line 1452

Quoted 3 lines

}

target-mips/translate.c +2 -0
+#if defined(TARGET_MIPS64)
+/* set on equal/not equal immidiate */

You need blank lines between all of these functions. Also, "immediate" is misspelled.

target-mips/translate.c static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc, · line 1469

Quoted 4 lines
target-mips/translate.c +4 -0
+    tcg_gen_xori_tl(t0, t0, uimm);
+    switch (opc) {
+    case OPC_SEQI:
+        tcg_gen_setcondi_tl(TCG_COND_LT, cpu_gpr[rt], t0, 1);

For both gen_set_imm and gen_set, you're thinking about these operations how you'd implement them with mips native insns. For TCG this should be

  tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_gpr[rt], cpu_gpr[rs], uimm);

target-mips/translate.c static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc, · line 1588

Quoted 2 lines
target-mips/translate.c +2 -0
+/* Store atomic add */
+/* FIXME: something else should be done for emulating SMP system. */

See how EXCP_SC is used here in the translator and in linux-user/main.c.

Quoted 9 lines
target-mips/translate.c +9 -0
+/* Cavium specific extract instructions */
+static void gen_exts(CPUState *env, DisasContext *ctx, uint32_t opc, int rt,
+                      int rs, int lsb, int msb)
+{
+    TCGv t0 = tcg_temp_new();
+    TCGv t1 = tcg_temp_new();
+    target_ulong mask;
+    gen_load_gpr(t1, rs);
+    switch (opc) {

target-mips/translate.c static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc, · line 1657

Quoted 10 lines
target-mips/translate.c +10 -0
+    case OPC_EXTS:
+        tcg_gen_shri_tl(t0, t1, lsb);
+        tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
+        /* To sign extened the remaining bits according to
+           the msb of the bit field */
+        mask = 1ULL << msb;
+        tcg_gen_andi_tl(t1, t0, mask);
+        tcg_gen_addi_tl(t1, t1, -1);
+        tcg_gen_orc_tl(t0, t0, t1);
+        gen_store_gpr(t0, rt);

This can be implemented with exactly two shifts:

    lshift = 64 - msb - 1;
    rshift = lshift + lsb;

    tcg_gen_shli_tl(t0, t0, lshift);
    tcg_gen_sari_tl(to, to, rshift);
Quoted 19 lines
     OPC_MUL      = 0x02 | OPC_SPECIAL2,
target-mips/translate.c +18 -0
+    /* Cavium Specific Instructions */
+    OPC_BADDU    = 0x28 | OPC_SPECIAL2,
+    OPC_DMUL     = 0x03 | OPC_SPECIAL2,
+    OPC_EXTS     = 0x3a | OPC_SPECIAL2,
+    OPC_EXTS32   = 0x3b | OPC_SPECIAL2,
+    OPC_CINS     = 0x32 | OPC_SPECIAL2,
+    OPC_CINS32   = 0x33 | OPC_SPECIAL2,
+    OPC_SEQI     = 0x2e | OPC_SPECIAL2,
+    OPC_SNEI     = 0x2f | OPC_SPECIAL2,
+    OPC_MTM0     = 0x08 | OPC_SPECIAL2,
+    OPC_MTM1     = 0x0c | OPC_SPECIAL2,
+    OPC_MTM2     = 0x0d | OPC_SPECIAL2,
+    OPC_MTP0     = 0x09 | OPC_SPECIAL2,
+    OPC_MTP1     = 0x0a | OPC_SPECIAL2,
+    OPC_MTP2     = 0x0b | OPC_SPECIAL2,
+    OPC_V3MULU   = 0x11 | OPC_SPECIAL2,
+    OPC_VMM0     = 0x10 | OPC_SPECIAL2,
+    OPC_VMULU    = 0x0f | OPC_SPECIAL2,

target-mips/translate.c enum { · line 299

Quoted 10 lines
target-mips/translate.c +7 -0
+    OPC_POP      = 0X2C | OPC_SPECIAL2,
+    OPC_DPOP     = 0X2D | OPC_SPECIAL2,
+    OPC_SEQ      = 0x2a | OPC_SPECIAL2,
+    OPC_SNE      = 0x2b | OPC_SPECIAL2,
+    OPC_SAA      = 0x18 | OPC_SPECIAL2,
+    OPC_SAAD     = 0x19 | OPC_SPECIAL2,
+/**************************************/
     OPC_MSUB     = 0x04 | OPC_SPECIAL2,
     OPC_MSUBU    = 0x05 | OPC_SPECIAL2,
     /* Loongson 2F */

You'll notice that there are already nicely separated sections there in the enums for SPECIAL2, and you've dropped yours right in the middle. Don't do that. Nor the ***** thing.

r~

#9 lore raw

PATCH 4/4 Addition of Cavium instruction in disassembler

In reply to [email protected]

From: Khansa Butt <[email protected]>

---
 disas.c                 |    4 +++
 mips-dis.c              |   61 +++++++++++++++++++++++++++++++++++++++++++++++
 target-mips/translate.c |    3 ++
 3 files changed, 68 insertions(+), 0 deletions(-)
disas.c +4 -0
index 1334b8e..0137657 100644
@@ -140,6 +140,7 @@ print_insn_thumb1(bfd_vma pc, disassemble_info *info)
     i386 - nonzero means 16 bit code
     arm  - nonzero means thumb code
     ppc  - nonzero means little endian
+    mips64 - zero means standard MIPS ISA, 1 means Octeon CPU.
     other targets - unused
  */
 void target_disas(FILE *out, target_ulong code, target_ulong size, int flags)
@@ -196,6 +197,9 @@ void target_disas(FILE *out, target_ulong code, target_ulong size, int flags)
     print_insn = print_insn_m68k;
 #elif defined(TARGET_MIPS)
 #ifdef TARGET_WORDS_BIGENDIAN
+    if (flags)
+        disasm_info.flags = flags << 16;
+        print_insn = print_insn_big_mips;
     print_insn = print_insn_big_mips;
 #else
     print_insn = print_insn_little_mips;
mips-dis.c +61 -0

109 lines not on this page · raw message

target-mips/translate.c +3 -0
index 2df8c3e..65786a1 100644
@@ -12860,6 +12860,9 @@ done_generating:
     LOG_DISAS("\n");
     if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
         qemu_log("IN: %s\n", lookup_symbol(pc_start));
+        if (env->insn_flags & CPU_OCTEON)
+            log_target_disas(pc_start, ctx.pc - pc_start, 1);
+        else
         log_target_disas(pc_start, ctx.pc - pc_start, 0);
         qemu_log("\n");
     }
Signature · 1 line
1.7.3.4
#10 lore raw

Re: [Qemu-devel] [PATCH 4/4] Addition of Cavium instruction in disassembler

Quoted 8 lines · On 08/15/2011 04:25 AM, [email protected] wrote:

index 1334b8e..0137657 100644

disas.c +1 -0
@@ -140,6 +140,7 @@ print_insn_thumb1(bfd_vma pc, disassemble_info *info)
     i386 - nonzero means 16 bit code
     arm  - nonzero means thumb code
     ppc  - nonzero means little endian
+    mips64 - zero means standard MIPS ISA, 1 means Octeon CPU.

...

disas.c done_generating: · line 12866

Quoted 9 lines

+++ b/target-mips/translate.c

disas.c +3 -0
@@ -12860,6 +12860,9 @@ done_generating:
     LOG_DISAS("\n");
     if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
         qemu_log("IN: %s\n", lookup_symbol(pc_start));
+        if (env->insn_flags & CPU_OCTEON)
+            log_target_disas(pc_start, ctx.pc - pc_start, 1);
+        else
         log_target_disas(pc_start, ctx.pc - pc_start, 0);

disas.c has access to cpu.h. You'd do well to avoid a magic number here and pass along env->insn_flags right from the beginning, and...

disas.c void target_disas(FILE *out, target_ulong code, target_ulong size, int flags) · line 203

Quoted 8 lines
disas.c +3 -0
@@ -196,6 +197,9 @@ void target_disas(FILE *out, target_ulong code, target_ulong size, int flags)
     print_insn = print_insn_m68k;
 #elif defined(TARGET_MIPS)
 #ifdef TARGET_WORDS_BIGENDIAN
+    if (flags)
+        disasm_info.flags = flags << 16;
+        print_insn = print_insn_big_mips;
     print_insn = print_insn_big_mips;

Notice anything funny here in the last two lines?
Notice anything incorrect about the coding style?

It's a bit sad that we're limited to pre-GPLv3, because we're going to get more and more out of sync with the binutils disassembler. But that said, let's not go out of our way to totally change the style.

Give mips-dis.c access to target-mips/mips-defs.h. Map between that and the existing membership field in struct mips_opcode. Put some real code back into OPCODE_IS_MEMBER.

r~

#11 lore raw

Re: [Qemu-devel] [PATCH 4/4] Addition of Cavium instruction in disassembler

Quoted 33 lines · Richard Henderson
Quoted 8 lines · On 08/15/2011 04:25 AM, [email protected] wrote:

index 1334b8e..0137657 100644

disas.c +1 -0
@@ -140,6 +140,7 @@ print_insn_thumb1(bfd_vma pc, disassemble_info *info)
     i386 - nonzero means 16 bit code
     arm  - nonzero means thumb code
     ppc  - nonzero means little endian
+    mips64 - zero means standard MIPS ISA, 1 means Octeon CPU.

...

disas.c done_generating: · line 12866

Quoted 9 lines

+++ b/target-mips/translate.c

disas.c +3 -0
@@ -12860,6 +12860,9 @@ done_generating:
     LOG_DISAS("\n");
     if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
         qemu_log("IN: %s\n", lookup_symbol(pc_start));
+        if (env->insn_flags & CPU_OCTEON)
+            log_target_disas(pc_start, ctx.pc - pc_start, 1);
+        else
         log_target_disas(pc_start, ctx.pc - pc_start, 0);

disas.c has access to cpu.h. You'd do well to avoid a magic number here and pass along env->insn_flags right from the beginning, and...

disas.c void target_disas(FILE *out, target_ulong code,

Quoted 1 line
disas.c +0 -0
@@ -196,6 +197,9 @@ void target_disas(FILE *out, target_ulong code,

target_ulong size, int flags)

disas.c void target_disas(FILE *out, target_ulong code, target_ulong size, int flags) · line 203

Quoted 7 lines
disas.c +3 -0
     print_insn = print_insn_m68k;
 #elif defined(TARGET_MIPS)
 #ifdef TARGET_WORDS_BIGENDIAN
+    if (flags)
+        disasm_info.flags = flags << 16;
+        print_insn = print_insn_big_mips;
     print_insn = print_insn_big_mips;
Quoted 2 lines

Notice anything funny here in the last two lines?

I 'm sorry for this stupid thing as I was in a hurry because of lot of things.

Quoted 6 lines

Notice anything incorrect about the coding style?

It's a bit sad that we're limited to pre-GPLv3, because we're going to get more and more out of sync with the binutils disassembler. But that said, let's not go out of our way to totally change the style.

If I pass env->insn_flags to target_disas() how can I pass this flag info
from disas.c to mips-dis.c. can i do following thing for MIPS in disas.c

if (flags & 0xFFFF) {
        disasm_info.mach = flags & 0xFFFF;
Quoted 5 lines

Give mips-dis.c access to target-mips/mips-defs.h. Map between that and the existing membership field in struct mips_opcode. Put some real code back into OPCODE_IS_MEMBER.

how can I make mips-defs.h 's definitions visible to mips-dis.c? there are lot of similar definitions in both so will it not create problem.

Actually some of Cavium 's instructions have same Opcode field as Loongson and COP2 instructions. whenever Cavium 's instruction comes, there is a need
to pass info from translate.c to mips-dis.c so that correct instruction would be
selected. but at the same time other MIPS standard instructions should also
print in the log as Cavium 's ISA includes MIPS64r2.
I'm sorry i'm bothering you for this. But i'm stuck with this how to correctly print
Cavium instructions instead of Loongson , A workaround that is acceptable to
mips maintainer as well.

Quoted 5 lines

r~

#12 lore raw

Re: [Qemu-devel] [PATCH 4/4] Addition of Cavium instruction in disassembler

Quoted 4 lines · Khansa Butt

If I pass env->insn_flags to target_disas() how can I pass this flag info
from disas.c to mips-dis.c. can i do following thing for MIPS in disas.c

if (flags & 0xFFFF) {
        disasm_info.mach = flags & 0xFFFF;

Well, I'd have written this as

  disasm_info.mach = flags;

I see no reason for the AND or IF.

Quoted 1 line

how can I make mips-defs.h 's definitions visible to mips-dis.c?

#include?

r~