From patchwork Mon Oct 21 22:37:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Rolnik X-Patchwork-Id: 1180897 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="qchYu9mh"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46xs5D4w3Nz9sP3 for ; Tue, 22 Oct 2019 09:39:28 +1100 (AEDT) Received: from localhost ([::1]:48516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMgKk-000369-1K for incoming@patchwork.ozlabs.org; Mon, 21 Oct 2019 18:39:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51941) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMgJE-0001l6-FM for qemu-devel@nongnu.org; Mon, 21 Oct 2019 18:37:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iMgJD-00010o-2O for qemu-devel@nongnu.org; Mon, 21 Oct 2019 18:37:52 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:45191) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iMgJC-00010e-PJ for qemu-devel@nongnu.org; Mon, 21 Oct 2019 18:37:50 -0400 Received: by mail-wr1-x441.google.com with SMTP id q13so10761044wrs.12 for ; Mon, 21 Oct 2019 15:37:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BGvkLFU66e7VXKZNz1ZYyyXcitOZp+YBucUP/E/zH5s=; b=qchYu9mhAwdsaLK5ICZRfxnLwH8pcbX+ayXs+7jprEYlsWf1LLoptrIbHMnD0H5RRH zUhHsYf5f3/5h8PbLtH1HJeqz59WufzBLGnXizrJqSnH85vS0WzRWRsok6Wl9SKnyeMY O6RerpeKtiECGyQ/BBpvyFKAKsuQN3+31ZkIKA265yFE4Ry9V17RGsDkm2qn/TkQEGhl zzThETMuPXuNFZaiBdX4GQErrHRcmxIZZmV7gLwxUZKuP28PM+JzNDkPpPfrP9AxkHUc e6TGEnv0Xef3Mcz1JYwQia+RHiWZpd2zSCkZFAJmweN7wkL5o9ykfoG3Rv8qDov0lWb+ zisw== 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=BGvkLFU66e7VXKZNz1ZYyyXcitOZp+YBucUP/E/zH5s=; b=d49jrcQ2kWXJYFK03nVYbj4SSYQ4qqFLPZMWxW0fcvGbc9lUTdVBmEykpBcXPkFHvJ w1Q5lmjHWQJKpY+kz2bVgmiAMTeR2UHcIO3JhN+i1RYq3iT3xTlt2zfrHUK6ycXsEYOB C81hL++vYK9TH1VeMF5dH1RmVu4e+eYkUzVImdVAb0Urdtydv5GCbND6K8g4xF94FG1f 66rkI2fOWjPeyxG3MrsxR6SAj68azVJ1d8mNApQqbX6B2BwSbxak2KkPPtDaxtFp0F9U 7AlM1eyT7C7t39TjCUPt0tzVXrzlxZBQ+vmkqFZqO0ab2hIn7Zk+CbuVuqiLrHDxR4CA nDVg== X-Gm-Message-State: APjAAAVawSZ4EYJcOtPZrmDcONuZ7RuuHxeH3OH7taGrh19S/xAKZpuq iJ6Y1XCh/tQd3CzVlJF2O1KQ4PvAwQhvPQ== X-Google-Smtp-Source: APXvYqzyGDOpVaJhvxrtAVgPUPCmGpqywZUnKOyC3uqdn3Wna6XWSDYwNbdR8HI3oqcpQpVpN9PUrw== X-Received: by 2002:a5d:4b42:: with SMTP id w2mr449115wrs.360.1571697469318; Mon, 21 Oct 2019 15:37:49 -0700 (PDT) Received: from 8c859074c0ff.ant.amazon.com.com (bzq-109-65-50-254.red.bezeqint.net. [109.65.50.254]) by smtp.gmail.com with ESMTPSA id q66sm16951271wme.39.2019.10.21.15.37.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Oct 2019 15:37:48 -0700 (PDT) From: Michael Rolnik To: qemu-devel@nongnu.org Subject: [PATCH v33 08/13] target/avr: Add instruction translation - MCU Control Instructions Date: Tue, 22 Oct 2019 01:37:06 +0300 Message-Id: <20191021223711.66955-9-mrolnik@gmail.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20191021223711.66955-1-mrolnik@gmail.com> References: <20191021223711.66955-1-mrolnik@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thuth@redhat.com, Michael Rolnik , richard.henderson@linaro.org, dovgaluk@ispras.ru, imammedo@redhat.com, philmd@redhat.com, aleksandar.m.mail@gmail.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This includes: - BREAK - NOP - SLEEP - WDR Signed-off-by: Michael Rolnik --- target/avr/translate.c | 174 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/target/avr/translate.c b/target/avr/translate.c index 19540634df..21ba6004ee 100644 --- a/target/avr/translate.c +++ b/target/avr/translate.c @@ -368,6 +368,115 @@ static bool trans_ADC(DisasContext *ctx, arg_ADC *a) } +static void gen_jmp_ez(DisasContext *ctx) +{ + tcg_gen_deposit_tl(cpu_pc, cpu_r[30], cpu_r[31], 8, 8); + tcg_gen_or_tl(cpu_pc, cpu_pc, cpu_eind); + ctx->bstate = DISAS_LOOKUP; +} + + +static void gen_jmp_z(DisasContext *ctx) +{ + tcg_gen_deposit_tl(cpu_pc, cpu_r[30], cpu_r[31], 8, 8); + ctx->bstate = DISAS_LOOKUP; +} + + +/* + * in the gen_set_addr & gen_get_addr functions + * H assumed to be in 0x00ff0000 format + * M assumed to be in 0x000000ff format + * L assumed to be in 0x000000ff format + */ +static void gen_set_addr(TCGv addr, TCGv H, TCGv M, TCGv L) +{ + + tcg_gen_andi_tl(L, addr, 0x000000ff); + + tcg_gen_andi_tl(M, addr, 0x0000ff00); + tcg_gen_shri_tl(M, M, 8); + + tcg_gen_andi_tl(H, addr, 0x00ff0000); +} + + +static void gen_set_xaddr(TCGv addr) +{ + gen_set_addr(addr, cpu_rampX, cpu_r[27], cpu_r[26]); +} + + +static void gen_set_yaddr(TCGv addr) +{ + gen_set_addr(addr, cpu_rampY, cpu_r[29], cpu_r[28]); +} + + +static void gen_set_zaddr(TCGv addr) +{ + gen_set_addr(addr, cpu_rampZ, cpu_r[31], cpu_r[30]); +} + + +static TCGv gen_get_addr(TCGv H, TCGv M, TCGv L) +{ + TCGv addr = tcg_temp_new_i32(); + + tcg_gen_deposit_tl(addr, M, H, 8, 8); + tcg_gen_deposit_tl(addr, L, addr, 8, 16); + + return addr; +} + + +static TCGv gen_get_xaddr(void) +{ + return gen_get_addr(cpu_rampX, cpu_r[27], cpu_r[26]); +} + + +static TCGv gen_get_yaddr(void) +{ + return gen_get_addr(cpu_rampY, cpu_r[29], cpu_r[28]); +} + + +static TCGv gen_get_zaddr(void) +{ + return gen_get_addr(cpu_rampZ, cpu_r[31], cpu_r[30]); +} + + +/* + * Load one byte indirect from data space to register and stores an clear + * the bits in data space specified by the register. The instruction can only + * be used towards internal SRAM. The data location is pointed to by the Z (16 + * bits) Pointer Register in the Register File. Memory access is limited to the + * current data segment of 64KB. To access another data segment in devices with + * more than 64KB data space, the RAMPZ in register in the I/O area has to be + * changed. The Z-pointer Register is left unchanged by the operation. This + * instruction is especially suited for clearing status bits stored in SRAM. + */ +static void gen_data_store(DisasContext *ctx, TCGv data, TCGv addr) +{ + if (ctx->tb->flags & TB_FLAGS_FULL_ACCESS) { + gen_helper_fullwr(cpu_env, data, addr); + } else { + tcg_gen_qemu_st8(data, addr, MMU_DATA_IDX); /* mem[addr] = data */ + } +} + +static void gen_data_load(DisasContext *ctx, TCGv data, TCGv addr) +{ + if (ctx->tb->flags & TB_FLAGS_FULL_ACCESS) { + gen_helper_fullrd(data, cpu_env, addr); + } else { + tcg_gen_qemu_ld8u(data, addr, MMU_DATA_IDX); /* data = mem[addr] */ + } +} + + /* * Subtracts an immediate value (0-63) from a register pair and places the * result in the register pair. This instruction operates on the upper four @@ -2606,3 +2715,68 @@ static bool trans_BCLR(DisasContext *ctx, arg_BCLR *a) return true; } + + +/* + * The BREAK instruction is used by the On-chip Debug system, and is + * normally not used in the application software. When the BREAK instruction is + * executed, the AVR CPU is set in the Stopped Mode. This gives the On-chip + * Debugger access to internal resources. If any Lock bits are set, or either + * the JTAGEN or OCDEN Fuses are unprogrammed, the CPU will treat the BREAK + * instruction as a NOP and will not enter the Stopped mode. This instruction + * is not available in all devices. Refer to the device specific instruction + * set summary. + */ +static bool trans_BREAK(DisasContext *ctx, arg_BREAK *a) +{ + if (!avr_have_feature(ctx, AVR_FEATURE_BREAK)) { + return true; + } + +#ifdef BREAKPOINT_ON_BREAK + tcg_gen_movi_tl(cpu_pc, ctx->npc - 1); + gen_helper_debug(cpu_env); + ctx->bstate = DISAS_EXIT; +#else + /* NOP */ +#endif + + return true; +} + + +/* + * This instruction performs a single cycle No Operation. + */ +static bool trans_NOP(DisasContext *ctx, arg_NOP *a) +{ + + /* NOP */ + + return true; +} + + +/* + * This instruction sets the circuit in sleep mode defined by the MCU + * Control Register. + */ +static bool trans_SLEEP(DisasContext *ctx, arg_SLEEP *a) +{ + gen_helper_sleep(cpu_env); + ctx->bstate = DISAS_NORETURN; + return true; +} + + +/* + * This instruction resets the Watchdog Timer. This instruction must be + * executed within a limited time given by the WD prescaler. See the Watchdog + * Timer hardware specification. + */ +static bool trans_WDR(DisasContext *ctx, arg_WDR *a) +{ + gen_helper_wdr(cpu_env); + + return true; +}