qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Aleksandar Markovic <aleksandar.markovic@rt-rk.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, philippe.mathieu.daude@gmail.com,
	aurelien@aurel32.net, richard.henderson@linaro.org,
	amarkovic@wavecomp.com, dnikolic@wavecomp.com,
	smarkovic@wavecomp.com, pjovanovic@wavecomp.com,
	pburton@wavecomp.com
Subject: [Qemu-devel] [PATCH v11 08/46] target/mips: Add emulation of nanoMIPS 16-bit branch instructions
Date: Mon, 20 Aug 2018 20:16:16 +0200	[thread overview]
Message-ID: <1534789014-8310-9-git-send-email-aleksandar.markovic@rt-rk.com> (raw)
In-Reply-To: <1534789014-8310-1-git-send-email-aleksandar.markovic@rt-rk.com>

From: Stefan Markovic <smarkovic@wavecomp.com>

Add emulation of nanoMIPS 16-bit branch instructions.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Yongbok Kim <yongbok.kim@mips.com>
Signed-off-by: Aleksandar Markovic <amarkovic@wavecomp.com>
Signed-off-by: Stefan Markovic <smarkovic@wavecomp.com>
---
 target/mips/translate.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 158 insertions(+)

diff --git a/target/mips/translate.c b/target/mips/translate.c
index 261680e..b0bbf4c 100644
--- a/target/mips/translate.c
+++ b/target/mips/translate.c
@@ -4564,6 +4564,128 @@ static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
     tcg_temp_free(t1);
 }
 
+
+/* nanoMIPS Branches */
+static void gen_compute_branch_nm(DisasContext *ctx, uint32_t opc,
+                                int insn_bytes,
+                                int rs, int rt, int32_t offset)
+{
+    target_ulong btgt = -1;
+    int bcond_compute = 0;
+    TCGv t0 = tcg_temp_new();
+    TCGv t1 = tcg_temp_new();
+
+    /* Load needed operands */
+    switch (opc) {
+    case OPC_BEQ:
+    case OPC_BNE:
+        /* Compare two registers */
+        if (rs != rt) {
+            gen_load_gpr(t0, rs);
+            gen_load_gpr(t1, rt);
+            bcond_compute = 1;
+        }
+        btgt = ctx->base.pc_next + insn_bytes + offset;
+        break;
+    case OPC_BGEZAL:
+        /* Compare to zero */
+        if (rs != 0) {
+            gen_load_gpr(t0, rs);
+            bcond_compute = 1;
+        }
+        btgt = ctx->base.pc_next + insn_bytes + offset;
+        break;
+    case OPC_BPOSGE32:
+        tcg_gen_andi_tl(t0, cpu_dspctrl, 0x3F);
+        bcond_compute = 1;
+        btgt = ctx->base.pc_next + insn_bytes + offset;
+        break;
+    case OPC_JR:
+    case OPC_JALR:
+        /* Jump to register */
+        if (offset != 0 && offset != 16) {
+            /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
+               others are reserved. */
+            MIPS_INVAL("jump hint");
+            generate_exception_end(ctx, EXCP_RI);
+            goto out;
+        }
+        gen_load_gpr(btarget, rs);
+        break;
+    default:
+        MIPS_INVAL("branch/jump");
+        generate_exception_end(ctx, EXCP_RI);
+        goto out;
+    }
+    if (bcond_compute == 0) {
+        /* No condition to be computed */
+        switch (opc) {
+        case OPC_BEQ:     /* rx == rx        */
+            /* Always take */
+            ctx->hflags |= MIPS_HFLAG_B;
+            break;
+        case OPC_BGEZAL:  /* 0 >= 0          */
+            /* Always take and link */
+            tcg_gen_movi_tl(cpu_gpr[31],
+                            ctx->base.pc_next + insn_bytes);
+            ctx->hflags |= MIPS_HFLAG_B;
+            break;
+        case OPC_BNE:     /* rx != rx        */
+            tcg_gen_movi_tl(cpu_gpr[31], ctx->base.pc_next + 8);
+            /* Skip the instruction in the delay slot */
+            ctx->base.pc_next += 4;
+            goto out;
+        case OPC_JR:
+            ctx->hflags |= MIPS_HFLAG_BR;
+            break;
+        case OPC_JALR:
+            if (rt > 0) {
+                tcg_gen_movi_tl(cpu_gpr[rt],
+                                ctx->base.pc_next + insn_bytes);
+            }
+            ctx->hflags |= MIPS_HFLAG_BR;
+            break;
+        default:
+            MIPS_INVAL("branch/jump");
+            generate_exception_end(ctx, EXCP_RI);
+            goto out;
+        }
+    } else {
+        switch (opc) {
+        case OPC_BEQ:
+            tcg_gen_setcond_tl(TCG_COND_EQ, bcond, t0, t1);
+            goto not_likely;
+        case OPC_BNE:
+            tcg_gen_setcond_tl(TCG_COND_NE, bcond, t0, t1);
+            goto not_likely;
+        case OPC_BGEZAL:
+            tcg_gen_setcondi_tl(TCG_COND_GE, bcond, t0, 0);
+            tcg_gen_movi_tl(cpu_gpr[31],
+                            ctx->base.pc_next + insn_bytes);
+            goto not_likely;
+        case OPC_BPOSGE32:
+            tcg_gen_setcondi_tl(TCG_COND_GE, bcond, t0, 32);
+        not_likely:
+            ctx->hflags |= MIPS_HFLAG_BC;
+            break;
+        default:
+            MIPS_INVAL("conditional branch/jump");
+            generate_exception_end(ctx, EXCP_RI);
+            goto out;
+        }
+    }
+
+    ctx->btarget = btgt;
+
+ out:
+    if (insn_bytes == 2) {
+        ctx->hflags |= MIPS_HFLAG_B16;
+    }
+    tcg_temp_free(t0);
+    tcg_temp_free(t1);
+}
+
+
 /* special3 bitfield operations */
 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
                         int rs, int lsb, int msb)
@@ -16729,14 +16851,50 @@ static int decode_nanomips_opc(CPUMIPSState *env, DisasContext *ctx)
     case NM_SWGP16:
         break;
     case NM_BC16:
+        gen_compute_branch_nm(ctx, OPC_BEQ, 2, 0, 0,
+                           (sextract32(ctx->opcode, 0, 1) << 10) |
+                           (extract32(ctx->opcode, 1, 9) << 1));
         break;
     case NM_BALC16:
+        gen_compute_branch_nm(ctx, OPC_BGEZAL, 2, 0, 0,
+                           (sextract32(ctx->opcode, 0, 1) << 10) |
+                           (extract32(ctx->opcode, 1, 9) << 1));
         break;
     case NM_BEQZC16:
+        gen_compute_branch_nm(ctx, OPC_BEQ, 2, rt, 0,
+                           (sextract32(ctx->opcode, 0, 1) << 7) |
+                           (extract32(ctx->opcode, 1, 6) << 1));
         break;
     case NM_BNEZC16:
+        gen_compute_branch_nm(ctx, OPC_BNE, 2, rt, 0,
+                           (sextract32(ctx->opcode, 0, 1) << 7) |
+                           (extract32(ctx->opcode, 1, 6) << 1));
         break;
     case NM_P16_BR:
+        switch (ctx->opcode & 0xf) {
+        case 0:
+            /* P16.JRC */
+            switch (extract32(ctx->opcode, 4, 1)) {
+            case NM_JRC:
+                gen_compute_branch_nm(ctx, OPC_JR, 2,
+                                   extract32(ctx->opcode, 5, 5), 0, 0);
+                break;
+            case NM_JALRC16:
+                gen_compute_branch_nm(ctx, OPC_JALR, 2,
+                                   extract32(ctx->opcode, 5, 5), 31, 0);
+                break;
+            }
+            break;
+        default:
+            {
+                /* P16.BRI */
+                uint32_t opc = extract32(ctx->opcode, 4, 3) <
+                               extract32(ctx->opcode, 7, 3) ? OPC_BEQ : OPC_BNE;
+                gen_compute_branch_nm(ctx, opc, 2, rs, rt,
+                                   extract32(ctx->opcode, 0, 4) << 1);
+            }
+            break;
+        }
         break;
     case NM_P16_SR:
         break;
-- 
2.7.4

  parent reply	other threads:[~2018-08-20 18:32 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-20 18:16 [Qemu-devel] [PATCH v11 00/46] Add nanoMIPS support - core functionality and system mode Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 01/46] target/mips: Add preprocessor constants for nanoMIPS Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 02/46] target/mips: Add nanoMIPS base instruction set opcodes Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 03/46] target/mips: Add nanoMIPS DSP ASE opcodes Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 04/46] target/mips: Prevent switching mode related to Config3 ISA bit for nanoMIPS Aleksandar Markovic
2018-08-21 11:05   ` Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 05/46] target/mips: Add placeholder and invocation of decode_nanomips_opc() Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 06/46] target/mips: Add nanoMIPS decoding and extraction utilities Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 07/46] target/mips: Add emulation of nanoMIPS 16-bit arithmetic instructions Aleksandar Markovic
2018-08-20 18:16 ` Aleksandar Markovic [this message]
2021-05-29 13:52   ` [PATCH v11 08/46] target/mips: Add emulation of nanoMIPS 16-bit branch instructions Philippe Mathieu-Daudé
2021-05-29 14:20     ` Philippe Mathieu-Daudé
2021-06-04 12:00       ` Aleksandar Rikalo
2021-06-04 23:25       ` Faraz Shahbazker
2021-06-04 23:52     ` Faraz Shahbazker
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 09/46] target/mips: Add emulation of nanoMIPS 16-bit shift instructions Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 10/46] target/mips: Add emulation of nanoMIPS 16-bit misc instructions Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 11/46] target/mips: Add emulation of nanoMIPS 16-bit load and store instructions Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 12/46] target/mips: Add emulation of nanoMIPS 16-bit logic instructions Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 13/46] target/mips: Add emulation of nanoMIPS 16-bit save and restore instructions Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 14/46] target/mips: Add emulation of some common nanoMIPS 32-bit instructions Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 15/46] target/mips: Add emulation of nanoMIPS instructions MOVE.P and MOVE.PREV Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 16/46] target/mips: Add emulation of nanoMIPS 48-bit instructions Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 17/46] target/mips: Add emulation of nanoMIPS FP instructions Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 18/46] target/mips: Add emulation of misc nanoMIPS instructions (pool32a0) Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 19/46] target/mips: Add emulation of misc nanoMIPS instructions (pool32axf) Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 20/46] target/mips: Add emulation of misc nanoMIPS instructions (p_lsx) Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 21/46] target/mips: Implement emulation of nanoMIPS ROTX instruction Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 22/46] target/mips: Implement emulation of nanoMIPS EXTW instruction Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 23/46] target/mips: Add emulation of nanoMIPS 32-bit load and store instructions Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 24/46] target/mips: Add CP0 Config3 and Config5 fields to DisasContext structure Aleksandar Markovic
2018-08-21 11:04   ` Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 25/46] target/mips: Implement emulation of nanoMIPS LLWP/SCWP pair Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 26/46] target/mips: Add emulation of nanoMIPS 32-bit branch instructions Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 27/46] target/mips: Fix pre-nanoMIPS MT ASE instructions availability control Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 28/46] target/mips: Implement MT ASE support for nanoMIPS Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 29/46] target/mips: Add emulation of DSP ASE for nanoMIPS - part 1 Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 30/46] target/mips: Add emulation of DSP ASE for nanoMIPS - part 2 Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 31/46] target/mips: Add emulation of DSP ASE for nanoMIPS - part 3 Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 32/46] target/mips: Add emulation of DSP ASE for nanoMIPS - part 4 Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 33/46] target/mips: Add emulation of DSP ASE for nanoMIPS - part 5 Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 34/46] target/mips: Add emulation of DSP ASE for nanoMIPS - part 6 Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 35/46] target/mips: Add availability control via bit NMS Aleksandar Markovic
2018-08-21 11:02   ` Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 36/46] disas: Add support for nanoMIPS platform Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 37/46] target/mips: Add updating BadInstr and BadInstrX for nanoMIPS Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 38/46] target/mips: Fix ERET/ERETNC behavior related to ADEL exception Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 39/46] elf: Add EM_NANOMIPS value as a valid one for e_machine field Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 40/46] elf: Relax MIPS' elf_check_arch() to accept EM_NANOMIPS too Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 41/46] elf: On elf loading, treat both EM_MIPS and EM_NANOMIPS as legal for MIPS Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 42/46] elf: Don't check FCR31_NAN2008 bit for nanoMIPS Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 43/46] mips_malta: Add basic nanoMIPS boot code for Malta board Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 44/46] mips_malta: Add setting up GT64120 BARs to the nanoMIPS bootloader Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 45/46] mips_malta: Fix semihosting argument passing for nanoMIPS bare metal Aleksandar Markovic
2018-08-20 18:16 ` [Qemu-devel] [PATCH v11 46/46] target/mips: Add definition of nanoMIPS I7200 CPU Aleksandar Markovic
2018-08-21 11:16 ` [Qemu-devel] [PATCH v11 00/46] Add nanoMIPS support - core functionality and system mode Aleksandar Markovic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1534789014-8310-9-git-send-email-aleksandar.markovic@rt-rk.com \
    --to=aleksandar.markovic@rt-rk.com \
    --cc=amarkovic@wavecomp.com \
    --cc=aurelien@aurel32.net \
    --cc=dnikolic@wavecomp.com \
    --cc=pburton@wavecomp.com \
    --cc=peter.maydell@linaro.org \
    --cc=philippe.mathieu.daude@gmail.com \
    --cc=pjovanovic@wavecomp.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=smarkovic@wavecomp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).