Skip to contentSkip to conversation

MIPS64 user mode emulation in QEMU with Cavium specific instruction support

PATCH In review [email protected] 3 participants 9 messages Jul 5, 2011 – Aug 13, 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/3 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                   |    4 ++--
 linux-user/syscall.c                  |    5 +++++
 6 files changed, 30 insertions(+), 4 deletions(-)
 create mode 100644 default-configs/mips64-linux-user.mak
configure +1 -0
index 88159ac..ad4c321 100755
@@ -866,6 +866,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 289054b..a3ed752 100644
@@ -2041,7 +2041,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(;;) {
@@ -2050,8 +2051,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 = -ENOSYS;
             } else {
@@ -2078,6 +2094,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 +2 -2
index 7d168e1..48a22e0 100644
@@ -2414,8 +2414,8 @@ void sparc64_get_context(CPUSPARCState *env)
 }
 #endif
 #elif defined(TARGET_ABI_MIPSN64)
-
-# warning signal handling not implemented
+/* Signal handling will be Implemented soon
+# warning signal handling not implemented */
 
 static void setup_frame(int sig, struct target_sigaction *ka,
 			target_sigset_t *set, CPUState *env)
linux-user/syscall.c +5 -0
index fed7a8f..339dede 100644
@@ -7584,6 +7584,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)
Signature · 1 line
1.7.3.4
#2 lore raw

PATCH 2/3 target-mips:Adding Octeon cpu definitions

In reply to [email protected]

From: Khansa Butt <[email protected]>

---
 target-mips/mips-defs.h      |    2 ++
 target-mips/translate.c      |    1 +
 target-mips/translate_init.c |   24 ++++++++++++++++++++++++
 3 files changed, 27 insertions(+), 0 deletions(-)
target-mips/mips-defs.h +2 -0
index bf094a3..6fec935 100644
@@ -44,6 +44,7 @@
 #define		INSN_LOONGSON2E  0x20000000
 #define		INSN_LOONGSON2F  0x40000000
 #define		INSN_VR54XX	0x80000000
+#define         INSN_OCTEON 0x10000000
 
 /* MIPS CPU defines. */
 #define		CPU_MIPS1	(ISA_MIPS1)
@@ -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.c +1 -0
index 2848c6a..eb108bc 100644
@@ -12693,6 +12693,7 @@ void cpu_reset (CPUMIPSState *env)
         env->hflags |= MIPS_HFLAG_FPU;
     }
 #ifdef TARGET_MIPS64
+    env->hflags |=  MIPS_HFLAG_UX;
     if (env->active_fpu.fcr0 & (1 << FCR0_F64)) {
         env->hflags |= MIPS_HFLAG_F64;
     }
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
#3 lore raw

Re: [Qemu-devel] [PATCH 2/3] target-mips:Adding Octeon cpu definitions

I'm not a MIPS expert, but some attempt at review anyway...

target-mips/mips-defs.h line 47

Quoted 9 lines · On 5 July 2011 10:19, <[email protected]> wrote:
target-mips/mips-defs.h +1 -0
index bf094a3..6fec935 100644
@@ -44,6 +44,7 @@
  #define                INSN_LOONGSON2E  0x20000000
  #define                INSN_LOONGSON2F  0x40000000
  #define                INSN_VR54XX     0x80000000
+#define         INSN_OCTEON 0x10000000

...why not put this at the top of this set of INSN defines so they are in numerical order?

target-mips/mips-defs.h line 57

Quoted 7 lines
target-mips/mips-defs.h +1 -0
  /* MIPS CPU defines. */
  #define                CPU_MIPS1       (ISA_MIPS1)
@@ -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)

You're using this define in the linux-user patch, which means you have your patches in the wrong order. The code has to compile at every point after each individual patch, not just after the entire set has been applied.

(Also the linux-user patch doesn't apply to master any more so you'll need to rebase it anyway.)

Quoted 7 lines
target-mips/mips-defs.h +0 -0
  #define                CPU_MIPS5       (CPU_MIPS4 | ISA_MIPS5)
 
target-mips/translate.c +0 -0
index 2848c6a..eb108bc 100644

target-mips/translate.c void cpu_reset (CPUMIPSState *env) · line 12699

Quoted 7 lines
target-mips/translate.c +1 -0
@@ -12693,6 +12693,7 @@ void cpu_reset (CPUMIPSState *env)
         env->hflags |= MIPS_HFLAG_FPU;
     }
  #ifdef TARGET_MIPS64
+    env->hflags |=  MIPS_HFLAG_UX;
     if (env->active_fpu.fcr0 & (1 << FCR0_F64)) {
         env->hflags |= MIPS_HFLAG_F64;
     }

This change looks suspiciously like a lurking bug fix not related to adding the Octeon CPU definition. My guess is that it should probably be in its own patch with a proper justification.

-- PMM

#4 lore raw

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

In reply to [email protected]

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

---
 host-utils.c            |    1 +
 target-mips/cpu.h       |    7 +
 target-mips/helper.h    |    5 +
 target-mips/op_helper.c |   67 +++++++
 target-mips/translate.c |  443 ++++++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 514 insertions(+), 9 deletions(-)
host-utils.c +1 -0
index dc96123..1128698 100644
@@ -102,4 +102,5 @@ void muls64 (uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b)
            a, b, *phigh, *plow);
 #endif
 }
+
 #endif /* !defined(__x86_64__) */
target-mips/cpu.h +7 -0
index b0ac4da..8e75e9b 100644
@@ -171,6 +171,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/op_helper.c +67 -0

74 lines not on this page · raw message

target-mips/translate.c +434 -9

552 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#5 lore raw

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

Quoted 7 lines · On 5 July 2011 10:19, <[email protected]> wrote:

---
 host-utils.c            |    1 +
 target-mips/cpu.h       |    7 +
 target-mips/helper.h    |    5 +
 target-mips/op_helper.c |   67 +++++++
 target-mips/translate.c |  443 ++++++++++++++++++++++++++++++++++++++++++++++-

 5 files changed, 514 insertions(+), 9 deletions(-)

Don't you also need to add support for the new instructions to the disassembler in mips-dis.c ?

host-utils.c void muls64 (uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b) · line 106

Quoted 10 lines
host-utils.c +1 -0
index dc96123..1128698 100644
@@ -102,4 +102,5 @@ void muls64 (uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b)
            a, b, *phigh, *plow);
  #endif
  }
+
  #endif /* !defined(__x86_64__) */

Stray random whitespace change to an unrelated file:
please drop this from the patch.

Quoted 6 lines
target-mips/cpu.h +0 -0
index b0ac4da..8e75e9b 100644
@@ -171,6 +171,13 @@ struct TCState {
     target_ulong CP0_TCSchedule;

target-mips/cpu.h struct TCState { · line 181

Quoted 10 lines
target-mips/cpu.h +7 -0
     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;
  };

If you add new fields to the CPU struct then you must also add code to save/restore them in target-mips/machine.c.

target-mips/op_helper.c void helper_dmultu (target_ulong arg1, target_ulong arg2) · line 269

Quoted 9 lines
target-mips/op_helper.c +1 -0
index 6b966b1..a1893d1 100644
@@ -266,7 +266,74 @@ void helper_dmultu (target_ulong arg1, target_ulong arg2)
  {
     mulu64(&(env->active_tc.LO[0]), &(env->active_tc.HI[0]), arg1, arg2);
  }
+static void addc(uint64_t res[], uint64_t a, int i)

Can you leave blank lines between function definitions, please? (here and also in a few places below)

Quoted 11 lines
target-mips/translate.c +0 -0
index eb108bc..b480665 100644
@@ -69,6 +69,11 @@ enum {
     OPC_JAL      = (0x03 << 26),
     OPC_JALS     = OPC_JAL | 0x5,

    OPC_BEQ      = (0x04 << 26),  /* Unconditional if rs = rt = 0 (B) */
+    /* Cavium Specific */
+    OPC_BBIT1    = (0x3a << 26),  /* jump on bit set, cavium specific */
+    OPC_BBIT132  = (0x3e << 26),  /* jump on bit set(for upper 32 bits) */

Space before the '(' in the comment, please.

Quoted 2 lines

+    OPC_BBIT0    = (0x32 << 26),  /* jump on bit clear, cavium specific */
+    OPC_BBIT032  = (0x36 << 26),  /* jump on bit clear(for upper 32 bits) */

Ditto.

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

Quoted 6 lines
target-mips/translate.c +1 -1
@@ -482,7 +512,7 @@ enum {
  static TCGv_ptr cpu_env;
  static TCGv cpu_gpr[32], cpu_PC;
  static TCGv cpu_HI[MIPS_DSP_ACC], cpu_LO[MIPS_DSP_ACC], cpu_ACX[MIPS_DSP_ACC];
-static TCGv cpu_dspctrl, btarget, bcond;
+static TCGv cpu_dspctrl, btarget, bcond, mpl0, mpl1, mpl2, p0, p1, p2;

p0/p1/p2 are awful names for global variables -- far too short. mpl0/mpl1/mpl2 aren't a great deal better.

Also it looks like at least some of these aren't really used very often -- you should consider just doing loads/stores to env+offset the way we do for most other cpu fields.

Quoted 18 lines
target-mips/translate.c +18 -0
+/* set on equal/not equal immidiate */
+static void gen_set_imm(CPUState *env, uint32_t opc,
+                        int rt, int rs, int16_t imm)
+{
+    target_ulong uimm = (target_long)imm;
+    TCGv t0;
+    const char *opn = "imm set";
+    if (rt == 0) {
+        /* If no destination, treat it as a NOP. */
+        MIPS_DEBUG("NOP");
+        return;
+    }
+    t0 = tcg_temp_new();
+    gen_load_gpr(t0, rs);
+    switch (opc) {
+    case OPC_SEQI:
+        tcg_gen_xori_tl(t0, t0, uimm);
+        tcg_gen_setcondi_tl(TCG_COND_LT, cpu_gpr[rt], t0, 1);

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

Quoted 10 lines
target-mips/translate.c +10 -0
+        opn = "seqi";
+        break;
+    case OPC_SNEI:
+        tcg_gen_xori_tl(t0, t0, uimm);
+        tcg_gen_setcondi_tl(TCG_COND_GT, cpu_gpr[rt], t0, 0);
+        opn = "snei";
+        break;
+    }
+    tcg_temp_free(t0);
+}

The tcg_gen_xori_tl() is the same in both cases of the switch, you could pull it out of the switch.

Quoted 8 lines
target-mips/translate.c +4 -0
@@ -1636,6 +1881,30 @@ static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
         }
         opn = "addu";
         break;
+    case OPC_BADDU:
+        {
+            TCGv t0 = tcg_temp_new();
+            TCGv t1 = tcg_temp_new();

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

Quoted 10 lines
target-mips/translate.c +10 -0
+            gen_load_gpr(t0, rs);
+            gen_load_gpr(t1, rt);
+            tcg_gen_add_tl(t0, t1, t0);
+            tcg_gen_ext8u_tl(t0, t0);
+            gen_store_gpr(t0, rd);
+            tcg_temp_free(t0);
+            tcg_temp_free(t1);
+        }
+       opn = "baddu";
+       break;

These should go inside the braces, please [ditto for other cases below]

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

Quoted 10 lines
target-mips/translate.c +10 -0
+    case OPC_DMUL:
+        {
+            TCGv t0 = tcg_temp_new();
+            TCGv t1 = tcg_temp_new();
+            gen_load_gpr(t0, rs);
+            gen_load_gpr(t1, rt);
+            tcg_gen_mul_i64(cpu_gpr[rd], t0, t1);
+        }
+            opn = "dmul";
+            break;

Missing tcg_temp_free()s ?

target-mips/translate.c static void gen_compute_branch (DisasContext *ctx, uint32_t opc, · line 2976

Quoted 8 lines

    case OPC_SUB:
        {
            TCGv t0 = tcg_temp_local_new();

target-mips/translate.c +1 -0
@@ -2704,6 +2973,7 @@ static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
     target_ulong btgt = -1;
     int blink = 0;
     int bcond_compute = 0;
+    target_ulong maskb; /* Used in BBIT0 and BBIT1 */

Add braces to the relevant cases and use variables local to that restricted scope -- there's no need for this to be visible for the whole function.

target-mips/translate.c static void gen_compute_branch (DisasContext *ctx, uint32_t opc, · line 3183

Quoted 8 lines
target-mips/translate.c +8 -0
+        case OPC_BBIT1:
+        case OPC_BBIT132:
+            tcg_gen_setcondi_tl(TCG_COND_NE, bcond, t0, 0);
+            goto not_likely;
+            case OPC_BBIT0:
+            case OPC_BBIT032:
+            tcg_gen_setcondi_tl(TCG_COND_EQ, bcond, t0, 0);
+            goto not_likely;

Indentation on the OPC_BBIT0, OPC_BBIT032 cases is wrong.

target-mips/translate.c static void decode_opc (CPUState *env, DisasContext *ctx, int *is_branch) · line 11951

Quoted 7 lines
target-mips/translate.c +3 -0
@@ -11637,6 +11946,9 @@ static void decode_opc (CPUState *env, DisasContext *ctx, int *is_branch)
     rd = (ctx->opcode >> 11) & 0x1f;
     sa = (ctx->opcode >> 6) & 0x1f;
     imm = (int16_t)ctx->opcode;
+    /* 10 bit Immediate value For SEQI,SNEI */
+    imm10 = (ctx->opcode >> 6) & 0x3ff;
+

Only used inside a single case, so just make it a variable scoped only to that case and decode it from opcode at that point.

target-mips/translate.c static void decode_opc (CPUState *env, DisasContext *ctx, int *is_branch) · line 12179

Quoted 7 lines
target-mips/translate.c +0 -0
@@ -11862,6 +12174,58 @@ static void decode_opc (CPUState *env, DisasContext *ctx, int *is_branch)

        case OPC_MUL:
            gen_arith(env, ctx, op1, rd, rs, rt);
            break;

target-mips/translate.c +3 -0
+#if defined(TARGET_MIPS64)
+
+        case OPC_DMUL:

This blank line is unnecessary.

Quoted 16 lines
target-mips/translate.c +0 -0
@@ -11881,13 +12245,24 @@ static void decode_opc (CPUState *env, DisasContext *ctx, int *is_branch)
             break;

        case OPC_DIV_G_2F:
        case OPC_DIVU_G_2F:
-        case OPC_MULT_G_2F:
        case OPC_MULTU_G_2F:
        case OPC_MOD_G_2F:
        case OPC_MODU_G_2F:
            check_insn(env, ctx, INSN_LOONGSON2F); gen_loongson_integer(ctx, op1, rd, rs, rt); break;
+        case OPC_MULT_G_2F:
+            if (!(env->insn_flags & CPU_OCTEON)) {
+                check_insn(env, ctx, INSN_LOONGSON2F);
+                gen_loongson_integer(ctx, op1, rd, rs, rt);
+            } else {

target-mips/translate.c static void decode_opc (CPUState *env, DisasContext *ctx, int *is_branch) · line 12265

Quoted 7 lines
target-mips/translate.c +7 -0
+#if defined(TARGET_MIPS64)
+                /* Cavium Specific vmm0 */
+                check_mips_64(ctx);
+                gen_LMI(env, ctx, op1, rs, rt, rd);
+#endif
+            }
+            break;

You could rearrange this to:
case OPC_MULT_G_2F:

#if defined(TARGET_MIPS64)
     if (OCTEON) {
         check_mips_64(ctx);
         gen_LMI(...);
     }
#endif
     /* Otherwise fall through, this is also a Loongson insn */
  case OPC_DIV_G_2F:
  case OPC_DIVU_G_2F:
  [etc]
         check_insn(env, ctx, INSN_LOONGSON2F);
         gen_loongson_integer(ctx, op1, rd, rs, rt);

...which lets you avoid duplicating the loongson code. Ditto in the DMULT/DDIV case.

-- PMM

#6 lore raw

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

Quoted 7 lines · Peter Maydell
Quoted 6 lines · On 5 July 2011 10:19, <[email protected]> wrote:
---
 host-utils.c            |    1 +
 target-mips/cpu.h       |    7 +
 target-mips/helper.h    |    5 +
 target-mips/op_helper.c |   67 +++++++
 target-mips/translate.c |  443
Quoted 7 lines

++++++++++++++++++++++++++++++++++++++++++++++-

Quoted 1 line
 5 files changed, 514 insertions(+), 9 deletions(-)

Don't you also need to add support for the new instructions to the disassembler in mips-dis.c ?

The ISA for Cavium Networks Octeon Processor consist of MIPS64r2+Cavium specific instructions. These are 27 usermode instructions which we implemented. some of its instructions have some conflicts with mips and LoongSon instructions. for example Branch on bit clear/set instructions (these are 4 instructions) consumes major opcodes of MIPS COP2 instructions (e.g, LWC2 etc). and V3MULU, VMM0 have same opcode and function fields as two of Loongson 's Instructions. To detect correct instruction in disassembling process can I add a CPU specific Flag in DisasContext so that I can pass this to log_target_disas()/disas.c and set some of top 16 bits in disassemble_info 's flags. On the basis of which I can pick correct instruction in print_insn_mips()/mips-dis.c. In future this Flag can be used for other vendor specific instruction as well.

Please guide me in this regard. If I make a separate print function for Cavium, this will not suitable for me as Cavium includes all instructions in MIPS64r2 so there will be lot of repetition.

Thanks.

#7 lore raw
In reply to [email protected]

Hi
We have developed Mips64 user mode emulation. In addition we implemented Cavium specific instruction along with octeon CPU definition. We need your support to make our contribution public ally available via making it open source. I tried to resolve the issues pointed out by Aurelien Jarno, Riku, Nathan and other friends and send the patches on Jul 5. Please review the patch series and give your feedback in the form of comments and suggestions
Thanks

Quoted 52 lines · On Tue, Jul 5, 2011 at 2:19 PM, <[email protected]> wrote:

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

--
1.7.3.4

#8 lore raw

Hi,

Quoted 7 lines · Khansa Butt

We have developed Mips64 user mode emulation. In addition we implemented Cavium specific instruction along with octeon CPU definition. We need your support to make our contribution public ally available via making it open source. I tried to resolve the issues pointed out by Aurelien Jarno, Riku, Nathan and other friends and send the patches on Jul 5. Please review the patch series and give your feedback in the form of comments and suggestions

I can only comment on the 1/3 part which touches linux-user code. I would prefer not change linux-user/signal.c just for changing code comment, but the rest of patch seems ok. However, the patch depends on changes in 2/3, so I can't apply it without the rest patches already included upstream by the target-mips maintainer.

Riku