From patchwork Mon May 14 22:27:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 135787 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp206118lji; Mon, 14 May 2018 15:38:36 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoXgrx3hOwzeMuEfC0vT4dnjMyKx2OT/joBMH4Ra14ogWdPGdVjaQBbAnpM5eFPHg/ymnk3 X-Received: by 2002:a0c:e4d2:: with SMTP id g18-v6mr10698829qvm.80.1526337516493; Mon, 14 May 2018 15:38:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526337516; cv=none; d=google.com; s=arc-20160816; b=yHphZLUecW/PLoOxfL4M1X9tmL7lHvCI0aPxcGLlQjmEYq3QGiGjcQISoX0NVI2YVX SThcRMpENHPr1bOcKGuit419G5Fda5esbIU8jDRXs66bFG/AM/EQUkOH1u5RQNthULDR pgeyfksCf6NCT1YK9abIuvNzg3hT2j5ECRnqd/Wa5dgCxs320doc2r3lndfj/OZtWr6v 4MypXa8iegFSJ4xIQRaxUPpbs7ieKW4YKniKZAtgjVmeGtib6VzyEjsOTVU2fRCO/ew1 XPoAzaSBrJQREOq7xSw8IcoSq7q/Gxk0EdTc78k1RzLle3Lqe3yRu5fXUzKJpuYukm8P YhAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=TPUPpKE33UqawMoHM5CuhjqMYNYOZLQ1fMoOLv2SBh4=; b=Jl3mIkE3X3CLGAHBq2hHG07GYwE9fbJnCIKuBn86Wafhf4QN8FQgGfvFJGT/vrYp9o EW643jA90R45hAo7Km7njyrhq0nUjlr2b+sM36If4PiXwakcwb07JgjWxBYxVUa77bhi lU0+NXALlD70Eht+vtaWyKCalKswZ1oomnrJJNHbyur2RCuhBjCRlu1uQra2G35kyo4R fbyaCpPGzYVcvUm4ecOBcCIgU6NDxZh520J+mHR1x7Vw0FP43fzPvGdpCsMSllxUMOCU PW2M4kkx6GukCnmD17wNVZzTbFWxPXmuyN/d7lEGPfOl1xh+/QEh0n3wurB5SNehS3tg pN0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QDpTtQBj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s6-v6si7173103qtb.240.2018.05.14.15.38.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 14 May 2018 15:38:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QDpTtQBj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIM71-0004Rt-RH for patch@linaro.org; Mon, 14 May 2018 18:38:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fILwE-00047w-IH for qemu-devel@nongnu.org; Mon, 14 May 2018 18:27:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fILwC-0008Lh-PV for qemu-devel@nongnu.org; Mon, 14 May 2018 18:27:26 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:44457) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fILwC-0008LA-HE for qemu-devel@nongnu.org; Mon, 14 May 2018 18:27:24 -0400 Received: by mail-pf0-x243.google.com with SMTP id q22-v6so6677855pff.11 for ; Mon, 14 May 2018 15:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TPUPpKE33UqawMoHM5CuhjqMYNYOZLQ1fMoOLv2SBh4=; b=QDpTtQBjHkFc1KUXwqk2zZQP1oOZS8txobUOIzH7lGTGp8luKKjfouWefbKsPvliR6 yIW5PUuKPL9BJOVKCtdN3lUbmdVsO9EY8nlrItHWpjAjnaYl+X+3O05k9kTPhhycQF1y PW6/GEeZTUGeRgbXnYAXct59g9C1+K8w1s/FI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TPUPpKE33UqawMoHM5CuhjqMYNYOZLQ1fMoOLv2SBh4=; b=LRVR7L6T5X7a6Vrv+nONoEjPT38FWtGB6Wgt2J8UV09esY0Ew/mBD9wA0PX5OoApRv norI0Pss36abamVnHmSRXTSKmgQXW99nhwvcbXIbWVuaL+5j5zvEX+qO80ZZSy7Fum8R Jy/E6llq1MM5ZXDVNFk2BEIdkzdjahhB8Y8ZCONf3ApsTCOZ06KGHvOnX4zT+HVTlWGO XH0WQem7wl4WtWVb0vIkERmRkPunbJdausI/RBYWXg+FNgovMXCFeFqK+IZNQxj5vgBk FCz5DY5XrH4FWgpJ+wY+Hcj7GSP62NOueI7MGvYnLe6RBdAeh/MmfAMzELf8b9ySqeP0 kazg== X-Gm-Message-State: ALKqPwerjUPa11W9PrCkmyljc1jLllRYnVs1XZ5uoHVVk7W7D1rhXgJU //hQllmfmrMnYjst8ogbio5Xrw0pymQ= X-Received: by 2002:a65:4586:: with SMTP id o6-v6mr2462349pgq.197.1526336843162; Mon, 14 May 2018 15:27:23 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-2-170.tukw.qwest.net. [97.113.2.170]) by smtp.gmail.com with ESMTPSA id g13-v6sm19517976pfm.67.2018.05.14.15.27.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 May 2018 15:27:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 14 May 2018 15:27:05 -0700 Message-Id: <20180514222714.7982-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180514222714.7982-1-richard.henderson@linaro.org> References: <20180514222714.7982-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PULL 04/13] target/openrisc: Convert memory insns X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stafford Horne Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Acked-by: Stafford Horne Signed-off-by: Richard Henderson --- target/openrisc/translate.c | 275 +++++++++++++++++------------------ target/openrisc/insns.decode | 24 +++ 2 files changed, 160 insertions(+), 139 deletions(-) -- 2.17.0 diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c index 3a02a1d688..4f9388a4c2 100644 --- a/target/openrisc/translate.c +++ b/target/openrisc/translate.c @@ -455,51 +455,6 @@ static void gen_msbu(DisasContext *dc, TCGv srca, TCGv srcb) gen_ove_cy(dc); } -static void gen_lwa(DisasContext *dc, TCGv rd, TCGv ra, int32_t ofs) -{ - TCGv ea = tcg_temp_new(); - - tcg_gen_addi_tl(ea, ra, ofs); - tcg_gen_qemu_ld_tl(rd, ea, dc->mem_idx, MO_TEUL); - tcg_gen_mov_tl(cpu_lock_addr, ea); - tcg_gen_mov_tl(cpu_lock_value, rd); - tcg_temp_free(ea); -} - -static void gen_swa(DisasContext *dc, int b, TCGv ra, int32_t ofs) -{ - TCGv ea, val; - TCGLabel *lab_fail, *lab_done; - - ea = tcg_temp_new(); - tcg_gen_addi_tl(ea, ra, ofs); - - /* For TB_FLAGS_R0_0, the branch below invalidates the temporary assigned - to cpu_R[0]. Since l.swa is quite often immediately followed by a - branch, don't bother reallocating; finish the TB using the "real" R0. - This also takes care of RB input across the branch. */ - cpu_R[0] = cpu_R0; - - lab_fail = gen_new_label(); - lab_done = gen_new_label(); - tcg_gen_brcond_tl(TCG_COND_NE, ea, cpu_lock_addr, lab_fail); - tcg_temp_free(ea); - - val = tcg_temp_new(); - tcg_gen_atomic_cmpxchg_tl(val, cpu_lock_addr, cpu_lock_value, - cpu_R[b], dc->mem_idx, MO_TEUL); - tcg_gen_setcond_tl(TCG_COND_EQ, cpu_sr_f, val, cpu_lock_value); - tcg_temp_free(val); - - tcg_gen_br(lab_done); - - gen_set_label(lab_fail); - tcg_gen_movi_tl(cpu_sr_f, 0); - - gen_set_label(lab_done); - tcg_gen_movi_tl(cpu_lock_addr, -1); -} - static void dec_calc(DisasContext *dc, uint32_t insn) { uint32_t op0, op1, op2; @@ -738,13 +693,147 @@ static bool trans_l_jalr(DisasContext *dc, arg_l_jalr *a, uint32_t insn) return true; } +static bool trans_l_lwa(DisasContext *dc, arg_load *a, uint32_t insn) +{ + TCGv ea; + + LOG_DIS("l.lwa r%d, r%d, %d\n", a->d, a->a, a->i); + + check_r0_write(a->d); + ea = tcg_temp_new(); + tcg_gen_addi_tl(ea, cpu_R[a->a], a->i); + tcg_gen_qemu_ld_tl(cpu_R[a->d], ea, dc->mem_idx, MO_TEUL); + tcg_gen_mov_tl(cpu_lock_addr, ea); + tcg_gen_mov_tl(cpu_lock_value, cpu_R[a->d]); + tcg_temp_free(ea); + return true; +} + +static void do_load(DisasContext *dc, arg_load *a, TCGMemOp mop) +{ + TCGv ea; + + check_r0_write(a->d); + ea = tcg_temp_new(); + tcg_gen_addi_tl(ea, cpu_R[a->a], a->i); + tcg_gen_qemu_ld_tl(cpu_R[a->d], ea, dc->mem_idx, mop); + tcg_temp_free(ea); +} + +static bool trans_l_lwz(DisasContext *dc, arg_load *a, uint32_t insn) +{ + LOG_DIS("l.lwz r%d, r%d, %d\n", a->d, a->a, a->i); + do_load(dc, a, MO_TEUL); + return true; +} + +static bool trans_l_lws(DisasContext *dc, arg_load *a, uint32_t insn) +{ + LOG_DIS("l.lws r%d, r%d, %d\n", a->d, a->a, a->i); + do_load(dc, a, MO_TESL); + return true; +} + +static bool trans_l_lbz(DisasContext *dc, arg_load *a, uint32_t insn) +{ + LOG_DIS("l.lbz r%d, r%d, %d\n", a->d, a->a, a->i); + do_load(dc, a, MO_UB); + return true; +} + +static bool trans_l_lbs(DisasContext *dc, arg_load *a, uint32_t insn) +{ + LOG_DIS("l.lbs r%d, r%d, %d\n", a->d, a->a, a->i); + do_load(dc, a, MO_SB); + return true; +} + +static bool trans_l_lhz(DisasContext *dc, arg_load *a, uint32_t insn) +{ + LOG_DIS("l.lhz r%d, r%d, %d\n", a->d, a->a, a->i); + do_load(dc, a, MO_TEUW); + return true; +} + +static bool trans_l_lhs(DisasContext *dc, arg_load *a, uint32_t insn) +{ + LOG_DIS("l.lhs r%d, r%d, %d\n", a->d, a->a, a->i); + do_load(dc, a, MO_TESW); + return true; +} + +static bool trans_l_swa(DisasContext *dc, arg_store *a, uint32_t insn) +{ + TCGv ea, val; + TCGLabel *lab_fail, *lab_done; + + LOG_DIS("l.swa r%d, r%d, %d\n", a->a, a->b, a->i); + + ea = tcg_temp_new(); + tcg_gen_addi_tl(ea, cpu_R[a->a], a->i); + + /* For TB_FLAGS_R0_0, the branch below invalidates the temporary assigned + to cpu_R[0]. Since l.swa is quite often immediately followed by a + branch, don't bother reallocating; finish the TB using the "real" R0. + This also takes care of RB input across the branch. */ + cpu_R[0] = cpu_R0; + + lab_fail = gen_new_label(); + lab_done = gen_new_label(); + tcg_gen_brcond_tl(TCG_COND_NE, ea, cpu_lock_addr, lab_fail); + tcg_temp_free(ea); + + val = tcg_temp_new(); + tcg_gen_atomic_cmpxchg_tl(val, cpu_lock_addr, cpu_lock_value, + cpu_R[a->b], dc->mem_idx, MO_TEUL); + tcg_gen_setcond_tl(TCG_COND_EQ, cpu_sr_f, val, cpu_lock_value); + tcg_temp_free(val); + + tcg_gen_br(lab_done); + + gen_set_label(lab_fail); + tcg_gen_movi_tl(cpu_sr_f, 0); + + gen_set_label(lab_done); + tcg_gen_movi_tl(cpu_lock_addr, -1); + return true; +} + +static void do_store(DisasContext *dc, arg_store *a, TCGMemOp mop) +{ + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[a->a], a->i); + tcg_gen_qemu_st_tl(cpu_R[a->b], t0, dc->mem_idx, mop); + tcg_temp_free(t0); +} + +static bool trans_l_sw(DisasContext *dc, arg_store *a, uint32_t insn) +{ + LOG_DIS("l.sw r%d, r%d, %d\n", a->a, a->b, a->i); + do_store(dc, a, MO_TEUL); + return true; +} + +static bool trans_l_sb(DisasContext *dc, arg_store *a, uint32_t insn) +{ + LOG_DIS("l.sb r%d, r%d, %d\n", a->a, a->b, a->i); + do_store(dc, a, MO_UB); + return true; +} + +static bool trans_l_sh(DisasContext *dc, arg_store *a, uint32_t insn) +{ + LOG_DIS("l.sh r%d, r%d, %d\n", a->a, a->b, a->i); + do_store(dc, a, MO_TEUW); + return true; +} + static void dec_misc(DisasContext *dc, uint32_t insn) { uint32_t op0, op1; uint32_t ra, rb, rd; uint32_t L6, K5, K16, K5_11; - int32_t I16, I5_11; - TCGMemOp mop; + int32_t I16; TCGv t0; op0 = extract32(insn, 26, 6); @@ -757,7 +846,6 @@ static void dec_misc(DisasContext *dc, uint32_t insn) K16 = extract32(insn, 0, 16); I16 = (int16_t)K16; K5_11 = (extract32(insn, 21, 5) << 11) | extract32(insn, 0, 11); - I5_11 = (int16_t)K5_11; switch (op0) { case 0x05: @@ -795,12 +883,6 @@ static void dec_misc(DisasContext *dc, uint32_t insn) } break; - case 0x1b: /* l.lwa */ - LOG_DIS("l.lwa r%d, r%d, %d\n", rd, ra, I16); - check_r0_write(rd); - gen_lwa(dc, cpu_R[rd], cpu_R[ra], I16); - break; - case 0x1c: /* l.cust1 */ LOG_DIS("l.cust1\n"); break; @@ -833,53 +915,6 @@ static void dec_misc(DisasContext *dc, uint32_t insn) LOG_DIS("l.cust8\n"); break; -/* not used yet, open it when we need or64. */ -/*#ifdef TARGET_OPENRISC64 - case 0x20: l.ld - LOG_DIS("l.ld r%d, r%d, %d\n", rd, ra, I16); - check_ob64s(dc); - mop = MO_TEQ; - goto do_load; -#endif*/ - - case 0x21: /* l.lwz */ - LOG_DIS("l.lwz r%d, r%d, %d\n", rd, ra, I16); - mop = MO_TEUL; - goto do_load; - - case 0x22: /* l.lws */ - LOG_DIS("l.lws r%d, r%d, %d\n", rd, ra, I16); - mop = MO_TESL; - goto do_load; - - case 0x23: /* l.lbz */ - LOG_DIS("l.lbz r%d, r%d, %d\n", rd, ra, I16); - mop = MO_UB; - goto do_load; - - case 0x24: /* l.lbs */ - LOG_DIS("l.lbs r%d, r%d, %d\n", rd, ra, I16); - mop = MO_SB; - goto do_load; - - case 0x25: /* l.lhz */ - LOG_DIS("l.lhz r%d, r%d, %d\n", rd, ra, I16); - mop = MO_TEUW; - goto do_load; - - case 0x26: /* l.lhs */ - LOG_DIS("l.lhs r%d, r%d, %d\n", rd, ra, I16); - mop = MO_TESW; - goto do_load; - - do_load: - check_r0_write(rd); - t0 = tcg_temp_new(); - tcg_gen_addi_tl(t0, cpu_R[ra], I16); - tcg_gen_qemu_ld_tl(cpu_R[rd], t0, dc->mem_idx, mop); - tcg_temp_free(t0); - break; - case 0x27: /* l.addi */ LOG_DIS("l.addi r%d, r%d, %d\n", rd, ra, I16); check_r0_write(rd); @@ -957,44 +992,6 @@ static void dec_misc(DisasContext *dc, uint32_t insn) } break; - case 0x33: /* l.swa */ - LOG_DIS("l.swa r%d, r%d, %d\n", ra, rb, I5_11); - gen_swa(dc, rb, cpu_R[ra], I5_11); - break; - -/* not used yet, open it when we need or64. */ -/*#ifdef TARGET_OPENRISC64 - case 0x34: l.sd - LOG_DIS("l.sd r%d, r%d, %d\n", ra, rb, I5_11); - check_ob64s(dc); - mop = MO_TEQ; - goto do_store; -#endif*/ - - case 0x35: /* l.sw */ - LOG_DIS("l.sw r%d, r%d, %d\n", ra, rb, I5_11); - mop = MO_TEUL; - goto do_store; - - case 0x36: /* l.sb */ - LOG_DIS("l.sb r%d, r%d, %d\n", ra, rb, I5_11); - mop = MO_UB; - goto do_store; - - case 0x37: /* l.sh */ - LOG_DIS("l.sh r%d, r%d, %d\n", ra, rb, I5_11); - mop = MO_TEUW; - goto do_store; - - do_store: - { - TCGv t0 = tcg_temp_new(); - tcg_gen_addi_tl(t0, cpu_R[ra], I5_11); - tcg_gen_qemu_st_tl(cpu_R[rb], t0, dc->mem_idx, mop); - tcg_temp_free(t0); - } - break; - default: gen_illegal_exception(dc); break; diff --git a/target/openrisc/insns.decode b/target/openrisc/insns.decode index 8d35011eab..ba5356abe1 100644 --- a/target/openrisc/insns.decode +++ b/target/openrisc/insns.decode @@ -38,3 +38,27 @@ l_bf 000100 n:s26 l_jr 010001 ---------- b:5 ----------- l_jalr 010010 ---------- b:5 ----------- + +#### +# Memory Instructions +#### + +&load d a i +@load ...... d:5 a:5 i:s16 &load + +%store_i 21:s5 0:11 +&store a b i +@store ...... ..... a:5 b:5 ........... &store i=%store_i + +l_lwa 011011 ..... ..... ........ ........ @load +l_lwz 100001 ..... ..... ........ ........ @load +l_lws 100010 ..... ..... ........ ........ @load +l_lbz 100011 ..... ..... ........ ........ @load +l_lbs 100100 ..... ..... ........ ........ @load +l_lhz 100101 ..... ..... ........ ........ @load +l_lhs 100110 ..... ..... ........ ........ @load + +l_swa 110011 ..... ..... ........ ........ @store +l_sw 110101 ..... ..... ........ ........ @store +l_sb 110110 ..... ..... ........ ........ @store +l_sh 110111 ..... ..... ........ ........ @store