From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Thomas Huth <huth@tuxfamily.org>, Laurent Vivier <laurent@vivier.eu>
Subject: [Qemu-devel] [PATCH v5 07/17] target/m68k: add chk and chk2
Date: Tue, 2 Jan 2018 02:10:22 +0100 [thread overview]
Message-ID: <20180102011032.30056-8-laurent@vivier.eu> (raw)
In-Reply-To: <20180102011032.30056-1-laurent@vivier.eu>
chk and chk2 compares a value to boundaries, and
triggers a CHK exception if the values is out of bounds.
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/main.c | 7 +++
target/m68k/cpu.c | 2 +
target/m68k/cpu.h | 1 +
target/m68k/translate.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 146 insertions(+), 1 deletion(-)
diff --git a/linux-user/main.c b/linux-user/main.c
index 71696ed33d..99a551b04f 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -2985,6 +2985,13 @@ void cpu_loop(CPUM68KState *env)
info._sifields._sigfault._addr = env->pc;
queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
break;
+ case EXCP_CHK:
+ info.si_signo = TARGET_SIGFPE;
+ info.si_errno = 0;
+ info.si_code = TARGET_FPE_INTOVF;
+ info._sifields._sigfault._addr = env->pc;
+ queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+ break;
case EXCP_DIV0:
info.si_signo = TARGET_SIGFPE;
info.si_errno = 0;
diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
index 0a3dd83548..57ffcb2114 100644
--- a/target/m68k/cpu.c
+++ b/target/m68k/cpu.c
@@ -134,6 +134,7 @@ static void m68020_cpu_initfn(Object *obj)
m68k_set_feature(env, M68K_FEATURE_CAS);
m68k_set_feature(env, M68K_FEATURE_BKPT);
m68k_set_feature(env, M68K_FEATURE_RTD);
+ m68k_set_feature(env, M68K_FEATURE_CHK2);
}
#define m68030_cpu_initfn m68020_cpu_initfn
#define m68040_cpu_initfn m68020_cpu_initfn
@@ -156,6 +157,7 @@ static void m68060_cpu_initfn(Object *obj)
m68k_set_feature(env, M68K_FEATURE_CAS);
m68k_set_feature(env, M68K_FEATURE_BKPT);
m68k_set_feature(env, M68K_FEATURE_RTD);
+ m68k_set_feature(env, M68K_FEATURE_CHK2);
}
static void m5208_cpu_initfn(Object *obj)
diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
index acc2629216..42c358d1a7 100644
--- a/target/m68k/cpu.h
+++ b/target/m68k/cpu.h
@@ -304,6 +304,7 @@ enum m68k_features {
M68K_FEATURE_CAS,
M68K_FEATURE_BKPT,
M68K_FEATURE_RTD,
+ M68K_FEATURE_CHK2,
};
static inline int m68k_feature(CPUM68KState *env, int feature)
diff --git a/target/m68k/translate.c b/target/m68k/translate.c
index a1e424e3db..6ef4c3a53c 100644
--- a/target/m68k/translate.c
+++ b/target/m68k/translate.c
@@ -4203,6 +4203,140 @@ DISAS_INSN(ff1)
gen_helper_ff1(reg, reg);
}
+DISAS_INSN(chk)
+{
+ TCGv tsrc, src, reg;
+ int opsize;
+ TCGLabel *l1, *l2;
+
+ switch ((insn >> 7) & 3) {
+ case 3:
+ opsize = OS_WORD;
+ break;
+ case 2:
+ if (m68k_feature(env, M68K_FEATURE_CHK2)) {
+ opsize = OS_LONG;
+ break;
+ }
+ /* fallthru */
+ default:
+ gen_exception(s, s->insn_pc, EXCP_ILLEGAL);
+ return;
+ }
+ SRC_EA(env, tsrc, opsize, 1, NULL);
+ src = tcg_temp_local_new();
+ tcg_gen_mov_i32(src, tsrc);
+
+ reg = tcg_temp_local_new();
+ gen_ext(reg, DREG(insn, 9), opsize, 1);
+ gen_flush_flags(s);
+ update_cc_op(s);
+
+ l1 = gen_new_label();
+ l2 = gen_new_label();
+ tcg_gen_brcondi_i32(TCG_COND_GE, reg, 0, l1);
+ tcg_gen_movi_i32(QREG_CC_N, -1);
+ tcg_gen_movi_i32(QREG_PC, s->pc);
+ gen_raise_exception(EXCP_CHK);
+ tcg_gen_br(l2);
+ gen_set_label(l1);
+ tcg_gen_brcond_i32(TCG_COND_LE, reg, src, l2);
+ tcg_gen_movi_i32(QREG_CC_N, 0);
+ tcg_gen_movi_i32(QREG_PC, s->pc);
+ gen_raise_exception(EXCP_CHK);
+ gen_set_label(l2);
+ tcg_temp_free(src);
+ tcg_temp_free(reg);
+}
+
+DISAS_INSN(chk2)
+{
+ uint16_t ext;
+ TCGv addr1, addr2, bound1, bound2, res1, res2, reg, one, tmp;
+ int opsize;
+ TCGLabel *l1;
+
+ switch ((insn >> 9) & 3) {
+ case 0:
+ opsize = OS_BYTE;
+ break;
+ case 1:
+ opsize = OS_WORD;
+ break;
+ case 2:
+ opsize = OS_LONG;
+ break;
+ default:
+ gen_exception(s, s->insn_pc, EXCP_ILLEGAL);
+ return;
+ }
+
+ ext = read_im16(env, s);
+ if ((ext & 0x0800) == 0) {
+ gen_exception(s, s->insn_pc, EXCP_ILLEGAL);
+ return;
+ }
+
+ addr1 = gen_lea(env, s, insn, OS_UNSIZED);
+ addr2 = tcg_temp_new();
+ tcg_gen_addi_i32(addr2, addr1, opsize_bytes(opsize));
+
+ bound1 = gen_load(s, opsize, addr1, 1);
+ tcg_temp_free(addr1);
+ bound2 = gen_load(s, opsize, addr2, 1);
+ tcg_temp_free(addr2);
+
+ reg = tcg_temp_new();
+ if (ext & 0x8000) {
+ tcg_gen_mov_i32(reg, AREG(ext, 12));
+ } else {
+ gen_ext(reg, DREG(ext, 12), opsize, 1);
+ }
+
+ gen_flush_flags(s);
+
+ /* Z is set if reg is equal to either bound, cleared otherwise,
+ * QREG_CC_Z is 0 if Z is true, 1 if Z if false
+ */
+ tmp = tcg_const_i32(0);
+ tcg_gen_setcond_i32(TCG_COND_NE, QREG_CC_Z, reg, bound1);
+ tcg_gen_movcond_i32(TCG_COND_EQ, QREG_CC_Z, reg, bound2, tmp, QREG_CC_Z);
+
+ /* from real m68040:
+ * if bound1 <= bound2, trap if reg < bound1 or reg > bound2
+ * if bound1 > bound2, trap if reg > bound2 and reg < bound1
+ */
+ one = tcg_const_i32(1);
+
+ /* reg < bound1 or reg > bound2 */
+ res1 = tcg_temp_new();
+ tcg_gen_setcond_i32(TCG_COND_LT, res1, reg, bound1);
+ tcg_gen_movcond_i32(TCG_COND_GT, res1, reg, bound2, one, res1);
+
+ /* reg > bound2 and reg < bound1 */
+ res2 = tcg_temp_new();
+ tcg_gen_setcond_i32(TCG_COND_GT, res2, reg, bound2);
+ tcg_gen_setcond_i32(TCG_COND_LT, tmp, reg, bound1);
+ tcg_gen_and_i32(res2, res2, tmp);
+ tcg_temp_free(tmp);
+
+ /* if bound1 <= bound2, C = res1 else C = res2 */
+ tcg_gen_movcond_i32(TCG_COND_LE, QREG_CC_C, bound1, bound2, res1, res2);
+
+ tcg_temp_free(res1);
+ tcg_temp_free(res2);
+ tcg_temp_free(bound1);
+ tcg_temp_free(bound2);
+ tcg_temp_free(reg);
+
+ update_cc_op(s);
+ l1 = gen_new_label();
+ tcg_gen_brcond_i32(TCG_COND_NE, QREG_CC_C, one, l1);
+ tcg_gen_movi_i32(QREG_PC, s->pc);
+ gen_raise_exception(EXCP_CHK);
+ gen_set_label(l1);
+}
+
static TCGv gen_get_sr(DisasContext *s)
{
TCGv ccr;
@@ -5306,7 +5440,7 @@ void register_m68k_insns (CPUM68KState *env)
BASE(undef, 0000, 0000);
INSN(arith_im, 0080, fff8, CF_ISA_A);
INSN(arith_im, 0000, ff00, M68000);
- INSN(undef, 00c0, ffc0, M68000);
+ INSN(chk2, 00c0, f9c0, CHK2);
INSN(bitrev, 00c0, fff8, CF_ISA_APLUSC);
BASE(bitop_reg, 0100, f1c0);
BASE(bitop_reg, 0140, f1c0);
@@ -5339,6 +5473,7 @@ void register_m68k_insns (CPUM68KState *env)
BASE(move, 1000, f000);
BASE(move, 2000, f000);
BASE(move, 3000, f000);
+ INSN(chk, 4000, f040, M68000);
INSN(strldsr, 40e7, ffff, CF_ISA_APLUSC);
INSN(negx, 4080, fff8, CF_ISA_A);
INSN(negx, 4000, ff00, M68000);
--
2.14.3
next prev parent reply other threads:[~2018-01-02 1:10 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-02 1:10 [Qemu-devel] [PATCH v5 00/17] target/m68k: supervisor mode (part 1) Laurent Vivier
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 01/17] target-m68k: sync CC_OP before gen_jmp_tb() Laurent Vivier
2018-01-02 16:01 ` Richard Henderson
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 02/17] target/m68k: fix gen_get_ccr() Laurent Vivier
2018-01-02 16:04 ` Richard Henderson
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 03/17] linux-user, m68k: correctly manage SR in context Laurent Vivier
2018-01-02 16:06 ` Richard Henderson
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 04/17] target-m68k: use insn_pc to generate instruction fault address Laurent Vivier
2018-01-02 16:08 ` Richard Henderson
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 05/17] target/m68k: add CPU_LOG_INT trace Laurent Vivier
2018-01-02 16:10 ` Richard Henderson
2018-01-02 18:37 ` Laurent Vivier
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 06/17] target/m68k: manage 680x0 stack frames Laurent Vivier
2018-01-02 16:16 ` Richard Henderson
2018-01-02 1:10 ` Laurent Vivier [this message]
2018-01-02 16:41 ` [Qemu-devel] [PATCH v5 07/17] target/m68k: add chk and chk2 Richard Henderson
2018-01-02 23:33 ` Laurent Vivier
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 08/17] target/m68k: add move16 Laurent Vivier
2018-01-02 16:50 ` Richard Henderson
2018-01-02 18:42 ` Laurent Vivier
2018-01-02 23:49 ` Richard Henderson
2018-01-02 23:53 ` Laurent Vivier
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 09/17] target/m68k: softmmu cleanup Laurent Vivier
2018-01-02 16:52 ` Richard Henderson
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 10/17] target/m68k: add cpush/cinv Laurent Vivier
2018-01-02 16:53 ` Richard Henderson
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 11/17] target/m68k: add reset Laurent Vivier
2018-01-02 16:54 ` Richard Henderson
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 12/17] target/m68k: implement fsave/frestore Laurent Vivier
2018-01-02 16:58 ` Richard Henderson
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 13/17] target/m68k: move CCR/SR functions Laurent Vivier
2018-01-02 17:00 ` Richard Henderson
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 14/17] target/m68k: add 680x0 "move to SR" instruction Laurent Vivier
2018-01-02 17:02 ` Richard Henderson
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 15/17] target/m68k: add andi/ori/eori to SR/CCR Laurent Vivier
2018-01-02 17:06 ` Richard Henderson
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 16/17] target/m68k: add the Interrupt Stack Pointer Laurent Vivier
2018-01-02 17:13 ` Richard Henderson
2018-01-02 18:50 ` Laurent Vivier
2018-01-02 1:10 ` [Qemu-devel] [PATCH v5 17/17] target/m68k: fix m68k_cpu_dump_state() Laurent Vivier
2018-01-02 17:14 ` Richard Henderson
2018-01-02 1:31 ` [Qemu-devel] [PATCH v5 00/17] target/m68k: supervisor mode (part 1) no-reply
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=20180102011032.30056-8-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=huth@tuxfamily.org \
--cc=qemu-devel@nongnu.org \
/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).