From: Aleksandar Markovic <aleksandar.markovic@rt-rk.com>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
Michael Rolnik <mrolnik@gmail.com>,
Aleksandar Markovic <aleksandar.m.mail@gmail.com>
Subject: [PATCH rc4 14/29] target/avr: Add instruction translation - CPU main translation function
Date: Fri, 31 Jan 2020 01:02:58 +0100 [thread overview]
Message-ID: <1580428993-4767-15-git-send-email-aleksandar.markovic@rt-rk.com> (raw)
In-Reply-To: <1580428993-4767-1-git-send-email-aleksandar.markovic@rt-rk.com>
From: Michael Rolnik <mrolnik@gmail.com>
Co-developed-by: Richard Henderson <richard.henderson@linaro.org>
Co-developed-by: Michael Rolnik <mrolnik@gmail.com>
Signed-off-by: Michael Rolnik <mrolnik@gmail.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Aleksandar Markovic <aleksandar.m.mail@gmail.com>
---
target/avr/translate.c | 234 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 234 insertions(+)
diff --git a/target/avr/translate.c b/target/avr/translate.c
index 4c68007..af88bb2 100644
--- a/target/avr/translate.c
+++ b/target/avr/translate.c
@@ -2749,3 +2749,237 @@ static bool trans_WDR(DisasContext *ctx, arg_WDR *a)
return true;
}
+
+
+void avr_cpu_tcg_init(void)
+{
+ int i;
+
+#define AVR_REG_OFFS(x) offsetof(CPUAVRState, x)
+ cpu_pc = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(pc_w), "pc");
+ cpu_Cf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregC), "Cf");
+ cpu_Zf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregZ), "Zf");
+ cpu_Nf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregN), "Nf");
+ cpu_Vf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregV), "Vf");
+ cpu_Sf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregS), "Sf");
+ cpu_Hf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregH), "Hf");
+ cpu_Tf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregT), "Tf");
+ cpu_If = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregI), "If");
+ cpu_rampD = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(rampD), "rampD");
+ cpu_rampX = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(rampX), "rampX");
+ cpu_rampY = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(rampY), "rampY");
+ cpu_rampZ = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(rampZ), "rampZ");
+ cpu_eind = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(eind), "eind");
+ cpu_sp = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sp), "sp");
+ cpu_skip = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(skip), "skip");
+
+ for (i = 0; i < NUMBER_OF_CPU_REGISTERS; i++) {
+ cpu_r[i] = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(r[i]),
+ reg_names[i]);
+ }
+#undef AVR_REG_OFFS
+}
+
+static void translate(DisasContext *ctx)
+{
+ uint32_t opcode = next_word(ctx);
+
+ if (!decode_insn(ctx, opcode)) {
+ gen_helper_unsupported(cpu_env);
+ ctx->bstate = DISAS_NORETURN;
+ }
+}
+
+/* Standardize the cpu_skip condition to NE. */
+static bool canonicalize_skip(DisasContext *ctx)
+{
+ switch (ctx->skip_cond) {
+ case TCG_COND_NEVER:
+ /* Normal case: cpu_skip is known to be false. */
+ return false;
+
+ case TCG_COND_ALWAYS:
+ /*
+ * Breakpoint case: cpu_skip is known to be true, via TB_FLAGS_SKIP.
+ * The breakpoint is on the instruction being skipped, at the start
+ * of the TranslationBlock. No need to update.
+ */
+ return false;
+
+ case TCG_COND_NE:
+ if (ctx->skip_var1 == NULL) {
+ tcg_gen_mov_tl(cpu_skip, ctx->skip_var0);
+ } else {
+ tcg_gen_xor_tl(cpu_skip, ctx->skip_var0, ctx->skip_var1);
+ ctx->skip_var1 = NULL;
+ }
+ break;
+
+ default:
+ /* Convert to a NE condition vs 0. */
+ if (ctx->skip_var1 == NULL) {
+ tcg_gen_setcondi_tl(ctx->skip_cond, cpu_skip, ctx->skip_var0, 0);
+ } else {
+ tcg_gen_setcond_tl(ctx->skip_cond, cpu_skip,
+ ctx->skip_var0, ctx->skip_var1);
+ ctx->skip_var1 = NULL;
+ }
+ ctx->skip_cond = TCG_COND_NE;
+ break;
+ }
+ if (ctx->free_skip_var0) {
+ tcg_temp_free(ctx->skip_var0);
+ ctx->free_skip_var0 = false;
+ }
+ ctx->skip_var0 = cpu_skip;
+ return true;
+}
+
+void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns)
+{
+ CPUAVRState *env = cs->env_ptr;
+ DisasContext ctx = {
+ .tb = tb,
+ .cs = cs,
+ .env = env,
+ .memidx = 0,
+ .bstate = DISAS_NEXT,
+ .skip_cond = TCG_COND_NEVER,
+ .singlestep = cs->singlestep_enabled,
+ };
+ target_ulong pc_start = tb->pc / 2;
+ int num_insns = 0;
+
+ if (tb->flags & TB_FLAGS_FULL_ACCESS) {
+ /*
+ * This flag is set by ST/LD instruction we will regenerate it ONLY
+ * with mem/cpu memory access instead of mem access
+ */
+ max_insns = 1;
+ }
+ if (ctx.singlestep) {
+ max_insns = 1;
+ }
+
+ gen_tb_start(tb);
+
+ ctx.npc = pc_start;
+ if (tb->flags & TB_FLAGS_SKIP) {
+ ctx.skip_cond = TCG_COND_ALWAYS;
+ ctx.skip_var0 = cpu_skip;
+ }
+
+ do {
+ TCGLabel *skip_label = NULL;
+
+ /* translate current instruction */
+ tcg_gen_insn_start(ctx.npc);
+ num_insns++;
+
+ /*
+ * this is due to some strange GDB behavior
+ * let's assume main has address 0x100
+ * b main - sets breakpoint at address 0x00000100 (code)
+ * b *0x100 - sets breakpoint at address 0x00800100 (data)
+ */
+ if (unlikely(!ctx.singlestep &&
+ (cpu_breakpoint_test(cs, OFFSET_CODE + ctx.npc * 2, BP_ANY) ||
+ cpu_breakpoint_test(cs, OFFSET_DATA + ctx.npc * 2, BP_ANY)))) {
+ canonicalize_skip(&ctx);
+ tcg_gen_movi_tl(cpu_pc, ctx.npc);
+ gen_helper_debug(cpu_env);
+ goto done_generating;
+ }
+
+ /* Conditionally skip the next instruction, if indicated. */
+ if (ctx.skip_cond != TCG_COND_NEVER) {
+ skip_label = gen_new_label();
+ if (ctx.skip_var0 == cpu_skip) {
+ /*
+ * Copy cpu_skip so that we may zero it before the branch.
+ * This ensures that cpu_skip is non-zero after the label
+ * if and only if the skipped insn itself sets a skip.
+ */
+ ctx.free_skip_var0 = true;
+ ctx.skip_var0 = tcg_temp_new();
+ tcg_gen_mov_tl(ctx.skip_var0, cpu_skip);
+ tcg_gen_movi_tl(cpu_skip, 0);
+ }
+ if (ctx.skip_var1 == NULL) {
+ tcg_gen_brcondi_tl(ctx.skip_cond, ctx.skip_var0, 0, skip_label);
+ } else {
+ tcg_gen_brcond_tl(ctx.skip_cond, ctx.skip_var0,
+ ctx.skip_var1, skip_label);
+ ctx.skip_var1 = NULL;
+ }
+ if (ctx.free_skip_var0) {
+ tcg_temp_free(ctx.skip_var0);
+ ctx.free_skip_var0 = false;
+ }
+ ctx.skip_cond = TCG_COND_NEVER;
+ ctx.skip_var0 = NULL;
+ }
+
+ translate(&ctx);
+
+ if (skip_label) {
+ canonicalize_skip(&ctx);
+ gen_set_label(skip_label);
+ if (ctx.bstate == DISAS_NORETURN) {
+ ctx.bstate = DISAS_CHAIN;
+ }
+ }
+ } while (ctx.bstate == DISAS_NEXT
+ && num_insns < max_insns
+ && (ctx.npc - pc_start) * 2 < TARGET_PAGE_SIZE - 4
+ && !tcg_op_buf_full());
+
+ if (tb->cflags & CF_LAST_IO) {
+ gen_io_end();
+ }
+
+ bool nonconst_skip = canonicalize_skip(&ctx);
+
+ switch (ctx.bstate) {
+ case DISAS_NORETURN:
+ assert(!nonconst_skip);
+ break;
+ case DISAS_NEXT:
+ case DISAS_TOO_MANY:
+ case DISAS_CHAIN:
+ if (!nonconst_skip) {
+ /* Note gen_goto_tb checks singlestep. */
+ gen_goto_tb(&ctx, 1, ctx.npc);
+ break;
+ }
+ tcg_gen_movi_tl(cpu_pc, ctx.npc);
+ /* fall through */
+ case DISAS_LOOKUP:
+ if (!ctx.singlestep) {
+ tcg_gen_lookup_and_goto_ptr();
+ break;
+ }
+ /* fall through */
+ case DISAS_EXIT:
+ if (ctx.singlestep) {
+ gen_helper_debug(cpu_env);
+ } else {
+ tcg_gen_exit_tb(NULL, 0);
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+done_generating:
+ gen_tb_end(tb, num_insns);
+
+ tb->size = (ctx.npc - pc_start) * 2;
+ tb->icount = num_insns;
+}
+
+void restore_state_to_opc(CPUAVRState *env, TranslationBlock *tb,
+ target_ulong *data)
+{
+ env->pc_w = data[0];
+}
--
2.7.4
next prev parent reply other threads:[~2020-01-31 0:08 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-31 0:02 [PATCH rc4 00/29] target/avr merger Aleksandar Markovic
2020-01-31 0:02 ` [PATCH rc4 01/29] target/avr: Add basic parameters for new AVR platform Aleksandar Markovic
2020-01-31 18:47 ` Aleksandar Markovic
2020-01-31 19:23 ` Aleksandar Markovic
2020-01-31 20:07 ` Aleksandar Markovic
2020-01-31 0:02 ` [PATCH rc4 02/29] target/avr: Introduce AVR CPU class object Aleksandar Markovic
2020-01-31 0:02 ` [PATCH rc4 03/29] target/avr: Add migration support Aleksandar Markovic
2020-01-31 0:02 ` [PATCH rc4 04/29] target/avr: Add GDB support Aleksandar Markovic
2020-01-31 0:02 ` [PATCH rc4 05/29] target/avr: Introduce enumeration AVRFeature Aleksandar Markovic
2020-01-31 0:02 ` [PATCH rc4 06/29] target/avr: Add defintions of AVR core types Aleksandar Markovic
2020-02-02 15:40 ` Joaquin de Andres
2020-02-08 7:35 ` Aleksandar Markovic
2020-02-10 7:39 ` Michael Rolnik
2020-02-21 11:03 ` Michael Rolnik
2020-02-21 15:31 ` Aleksandar Markovic
2020-02-27 8:38 ` Michael Rolnik
2020-03-06 13:34 ` Michael Rolnik
2020-06-16 8:56 ` Philippe Mathieu-Daudé
2020-06-29 9:51 ` Philippe Mathieu-Daudé
2020-01-31 0:02 ` [PATCH rc4 07/29] target/avr: Add instruction helpers Aleksandar Markovic
2020-02-01 12:27 ` Aleksandar Markovic
2020-01-31 0:02 ` [PATCH rc4 08/29] target/avr: Add instruction translation - Register definitions Aleksandar Markovic
2020-01-31 0:02 ` [PATCH rc4 09/29] target/avr: Add instruction translation - Arithmetic and Logic Instructions Aleksandar Markovic
2020-01-31 0:02 ` [PATCH rc4 10/29] target/avr: Add instruction translation - Branch Instructions Aleksandar Markovic
2020-01-31 0:02 ` [PATCH rc4 11/29] target/avr: Add instruction translation - Data Transfer Instructions Aleksandar Markovic
2020-01-31 0:02 ` [PATCH rc4 12/29] target/avr: Add instruction translation - Bit and Bit-test Instructions Aleksandar Markovic
2020-01-31 0:02 ` [PATCH rc4 13/29] target/avr: Add instruction translation - MCU Control Instructions Aleksandar Markovic
2020-01-31 0:02 ` Aleksandar Markovic [this message]
2020-01-31 0:02 ` [PATCH rc4 15/29] target/avr: Add instruction disassembly function Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 16/29] hw/char: Add limited support for AVR USART peripheral Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 17/29] hw/timer: Add limited support for AVR 16-bit timer peripheral Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 18/29] hw/misc: Add limited support for AVR power device Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 19/29] target/avr: Add section about AVR into QEMU documentation Aleksandar Markovic
2020-02-01 13:19 ` Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 20/29] target/avr: Register AVR support with the rest of QEMU Aleksandar Markovic
2020-01-31 0:23 ` Philippe Mathieu-Daudé
2020-01-31 0:27 ` Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 21/29] target/avr: Add machine none test Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 22/29] target/avr: Update MAINTAINERS file Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 23/29] hw/avr: Add helper to load raw/ELF firmware binaries Aleksandar Markovic
2020-01-31 0:20 ` Philippe Mathieu-Daudé
2020-01-31 0:26 ` Aleksandar Markovic
2020-01-31 0:28 ` Philippe Mathieu-Daudé
2020-01-31 0:30 ` Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 24/29] hw/avr: Add some ATmega microcontrollers Aleksandar Markovic
2020-01-31 1:56 ` Aleksandar Markovic
2020-01-31 3:09 ` Philippe Mathieu-Daudé
2020-01-31 3:45 ` Aleksandar Markovic
2020-01-31 4:11 ` Aleksandar Markovic
2020-01-31 9:35 ` Thomas Huth
2020-01-31 9:40 ` Aleksandar Markovic
2020-01-31 10:45 ` Philippe Mathieu-Daudé
2020-01-31 11:07 ` Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 25/29] hw/avr: Add some Arduino boards Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 26/29] target/avr: Update build system Aleksandar Markovic
2020-02-04 22:58 ` Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 27/29] tests/boot-serial-test: Test some Arduino boards (AVR based) Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 28/29] tests/acceptance: Test the Arduino MEGA2560 board Aleksandar Markovic
2020-01-31 0:03 ` [PATCH rc4 29/29] .travis.yml: Run the AVR acceptance tests Aleksandar Markovic
2020-01-31 0:12 ` [PATCH rc4 00/29] target/avr merger Aleksandar Markovic
2020-01-31 1:23 ` Philippe Mathieu-Daudé
2020-01-31 14:43 ` Michael Rolnik
2020-01-31 1:09 ` [PATCH 0/2] !fixup target/avr merger-rc4 Philippe Mathieu-Daudé
2020-01-31 1:09 ` [PATCH 1/2] !fixup "hw/misc: Add limited support for AVR power device" Philippe Mathieu-Daudé
2020-01-31 11:27 ` Alex Bennée
2020-01-31 12:39 ` Philippe Mathieu-Daudé
2020-01-31 14:52 ` Alex Bennée
2020-01-31 1:09 ` [PATCH 2/2] !fixup "hw/timer: Add limited support for AVR 16-bit timer peripheral" Philippe Mathieu-Daudé
2020-01-31 11:31 ` Alex Bennée
2020-01-31 1:12 ` [PATCH 0/2] !fixup target/avr merger-rc4 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=1580428993-4767-15-git-send-email-aleksandar.markovic@rt-rk.com \
--to=aleksandar.markovic@rt-rk.com \
--cc=aleksandar.m.mail@gmail.com \
--cc=mrolnik@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).