From patchwork Wed Jun 22 09:51:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Rolnik X-Patchwork-Id: 9192319 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0C8CC60756 for ; Wed, 22 Jun 2016 10:02:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED64E283DF for ; Wed, 22 Jun 2016 10:02:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2305283E6; Wed, 22 Jun 2016 10:02:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0266D283A6 for ; Wed, 22 Jun 2016 10:02:01 +0000 (UTC) Received: from localhost ([::1]:56890 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFeyu-0003uY-Pu for patchwork-qemu-devel@patchwork.kernel.org; Wed, 22 Jun 2016 06:02:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFepg-0002MG-08 for qemu-devel@nongnu.org; Wed, 22 Jun 2016 05:52:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFepd-0006IR-8L for qemu-devel@nongnu.org; Wed, 22 Jun 2016 05:52:26 -0400 Received: from mail-lb0-x243.google.com ([2a00:1450:4010:c04::243]:34763) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFepc-0006IJ-RU for qemu-devel@nongnu.org; Wed, 22 Jun 2016 05:52:25 -0400 Received: by mail-lb0-x243.google.com with SMTP id w10so3831636lbo.1 for ; Wed, 22 Jun 2016 02:52:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=k1TgdE+PusiX2D97r9wIOnSWGJJs4AcQJXvB6PR5tfA=; b=aCegOoxh7oqZMrNij7y4M6AeP7d06DQErmCtQ4nl3qTCwoqgVevuolEPH8FSseCmg3 GwcxrG3ffY0HJ3SH13rfBHesIdeYyNYo2UzOaB5yYyJFfuRatH6C3iEvlVzZZsVAG3t2 WDEuiCCu44m+aXO8u4C+dpQmesT1wx/xk6FnX3qINYZ31up51PTju+x3J/MF9N1Kg2Wo C4dqVAoWGPVDuhWZYYexLSjkdj0Roty7/nW7pBedYhSR6Hcihz06XpFKHjEbDJyB1nWB bHl3n+jg1JoSFJtJ+eP9mm3Iraf1JPqjdOTx/cjpVvFkcEyyssmP6pvFU8fvfm9v+c+a 7OtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=k1TgdE+PusiX2D97r9wIOnSWGJJs4AcQJXvB6PR5tfA=; b=mV7STklBI5voKv0YKK2jkZPgp8bPMRNe3VdvjmOmeK64xchC+As2a6QR9Xyk/lKGXW +9vG7+TfeoqVCDwNvbXpYH1IRFHSUMr1K9x2dBPcaEXlDTIOrNSx31Y9HbKqGkMHOYOL pdBoWvETf3PUL5jQl41/xV0cSDOqAL14ZvlPHNjEoQpstu0HAxWStnwMcX50ofVeWyUG dX37OIZOQxSJnZ39GDkSXxEKJd9e/5KnwR6zQcY59bX5nfzCpC4RiedaHcchf8og/Pv9 Id/XSssJ/s70H5Y+riQ5r2MlK7oO51+qf6QoN4S0qwNEucdxox4lzgEicFuvMw2r0kBN biqA== X-Gm-Message-State: ALyK8tJkNl/YqhQGIfIbHE4A5/8O2RUjwCh/UVLhjDiPdnRK/Hy+6w33ByTgSvWYNzt5Ug== X-Received: by 10.194.246.70 with SMTP id xu6mr18114923wjc.124.1466589143926; Wed, 22 Jun 2016 02:52:23 -0700 (PDT) Received: from a0999b0126e1.ant.amazon.com ([5.102.195.79]) by smtp.gmail.com with ESMTPSA id b187sm7215976wmg.15.2016.06.22.02.52.22 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 Jun 2016 02:52:23 -0700 (PDT) From: Michael Rolnik To: qemu-devel@nongnu.org Date: Wed, 22 Jun 2016 12:51:51 +0300 Message-Id: <1466589115-57738-7-git-send-email-mrolnik@gmail.com> X-Mailer: git-send-email 2.4.9 (Apple Git-60) In-Reply-To: <1466589115-57738-1-git-send-email-mrolnik@gmail.com> References: <1466589115-57738-1-git-send-email-mrolnik@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::243 Subject: [Qemu-devel] [PATCH v9 06/10] target-avr: adding helpers for IN, OUT, SLEEP, WBR & unsupported instructions 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, Michael Rolnik , rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Michael Rolnik --- target-avr/helper.c | 222 +++++++++++++++++++++++++++++++++++++++++++++++++--- target-avr/helper.h | 6 ++ 2 files changed, 215 insertions(+), 13 deletions(-) diff --git a/target-avr/helper.c b/target-avr/helper.c index 060b2f0..1a324cb 100644 --- a/target-avr/helper.c +++ b/target-avr/helper.c @@ -42,14 +42,14 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request) cs->exception_index = EXCP_RESET; cc->do_interrupt(cs); - cs->interrupt_request &= ~CPU_INTERRUPT_RESET; + cs->interrupt_request &= ~CPU_INTERRUPT_RESET; ret = true; } } if (interrupt_request & CPU_INTERRUPT_HARD) { if (cpu_interrupts_enabled(env) && env->intsrc != 0) { - int index = ctz32(env->intsrc); + int index = ctz32(env->intsrc); cs->exception_index = EXCP_INT(index); cc->do_interrupt(cs); @@ -64,8 +64,8 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request) void avr_cpu_do_interrupt(CPUState *cs) { - AVRCPU *cpu = AVR_CPU(cs); - CPUAVRState *env = &cpu->env; + AVRCPU *cpu = AVR_CPU(cs); + CPUAVRState *env = &cpu->env; uint32_t ret = env->pc_w; int vector = 0; @@ -79,14 +79,14 @@ void avr_cpu_do_interrupt(CPUState *cs) } if (avr_feature(env, AVR_FEATURE_3_BYTE_PC)) { - stb_phys(cs->as, env->sp--, (ret & 0x0000ff)); - stb_phys(cs->as, env->sp--, (ret & 0x00ff00) >> 8); - stb_phys(cs->as, env->sp--, (ret & 0xff0000) >> 16); + cpu_stb_data(env, env->sp--, (ret & 0x0000ff)); + cpu_stb_data(env, env->sp--, (ret & 0x00ff00) >> 8); + cpu_stb_data(env, env->sp--, (ret & 0xff0000) >> 16); } else if (avr_feature(env, AVR_FEATURE_2_BYTE_PC)) { - stb_phys(cs->as, env->sp--, (ret & 0x0000ff)); - stb_phys(cs->as, env->sp--, (ret & 0x00ff00) >> 8); + cpu_stb_data(env, env->sp--, (ret & 0x0000ff)); + cpu_stb_data(env, env->sp--, (ret & 0x00ff00) >> 8); } else { - stb_phys(cs->as, env->sp--, (ret & 0x0000ff)); + cpu_stb_data(env, env->sp--, (ret & 0x0000ff)); } env->pc_w = base + vector * size; @@ -124,15 +124,55 @@ void tlb_fill(CPUState *cs, target_ulong vaddr, int is_write, vaddr &= TARGET_PAGE_MASK; if (mmu_idx == MMU_CODE_IDX) { - paddr = PHYS_BASE_CODE + vaddr; + paddr = PHYS_BASE_CODE + vaddr - VIRT_BASE_CODE; prot = PAGE_READ | PAGE_EXEC; } else { - paddr = PHYS_BASE_DATA + vaddr; - prot = PAGE_READ | PAGE_WRITE; +#if VIRT_BASE_REGS == 0 + if (vaddr < VIRT_BASE_REGS + SIZE_REGS) { +#else + if (VIRT_BASE_REGS <= vaddr && vaddr < VIRT_BASE_REGS + SIZE_REGS) { +#endif + /* + this is a write into CPU registers, exit and rebuilt this TB + to use full write + */ + AVRCPU *cpu = AVR_CPU(cs); + CPUAVRState *env = &cpu->env; + env->fullwr = 1; + cpu_loop_exit_restore(cs, retaddr); + } else { + /* + this is a write into memory. nothing special + */ + paddr = PHYS_BASE_DATA + vaddr - VIRT_BASE_DATA; + prot = PAGE_READ | PAGE_WRITE; + } } tlb_set_page_with_attrs(cs, vaddr, paddr, attrs, prot, mmu_idx, page_size); } +void helper_sleep(CPUAVRState *env) +{ + CPUState *cs = CPU(avr_env_get_cpu(env)); + + cs->exception_index = EXCP_HLT; + cpu_loop_exit(cs); +} +void helper_unsupported(CPUAVRState *env) +{ + CPUState *cs = CPU(avr_env_get_cpu(env)); + + /* + I count not find what happens on the real platform, so + it's EXCP_DEBUG for meanwhile + */ + cs->exception_index = EXCP_DEBUG; + if (qemu_loglevel_mask(LOG_UNIMP)) { + qemu_log("UNSUPPORTED\n"); + cpu_dump_state(cs, qemu_logfile, fprintf, 0); + } + cpu_loop_exit(cs); +} void helper_debug(CPUAVRState *env) { @@ -142,3 +182,159 @@ void helper_debug(CPUAVRState *env) cpu_loop_exit(cs); } +void helper_wdr(CPUAVRState *env) +{ + CPUState *cs = CPU(avr_env_get_cpu(env)); + + /* + WD is not implemented yet, placeholder + */ + cs->exception_index = EXCP_DEBUG; + cpu_loop_exit(cs); +} + +target_ulong helper_inb(CPUAVRState *env, uint32_t port) +{ + target_ulong data = 0; + + switch (port) { + case 0x38: { + data = 0xff & (env->rampD >> 16); /* RAMPD */ + break; + } + case 0x39: { + data = 0xff & (env->rampX >> 16); /* RAMPX */ + break; + } + case 0x3a: { + data = 0xff & (env->rampY >> 16); /* RAMPY */ + break; + } + case 0x3b: { + data = 0xff & (env->rampZ >> 16); /* RAMPZ */ + break; + } + case 0x3c: { + data = 0xff & (env->eind >> 16); /* EIND */ + break; + } + case 0x3d: { /* SPL */ + data = env->sp & 0x00ff; + break; + } + case 0x3e: { /* SPH */ + data = env->sp >> 8; + break; + } + case 0x3f: { /* SREG */ + data = cpu_get_sreg(env); + break; + } + default: { + /* + CPU does not know how to read this register, pass it to the + device/board + */ + + cpu_physical_memory_read(PHYS_BASE_REGS + port + OFFS_IOREGS, + &data, 1); + } + } + + if (port < IO_REGS) { + env->io[port] = data; /* make a copy for SBI, SBIC, SBIS & CBI */ + } + + return data; +} + +void helper_fullwr(CPUAVRState *env, uint32_t data, uint32_t addr) +{ +#if VIRT_BASE_REGS == 0 + if (addr <= VIRT_BASE_REGS + SIZE_REGS) { +#else + if (VIRT_BASE_REGS <= addr && addr <= VIRT_BASE_REGS + SIZE_REGS) { +#endif + /* + write CPU REGS/IO REGS/EXT IO REGS + */ + cpu_physical_memory_write(PHYS_BASE_REGS + addr - VIRT_BASE_REGS, + &data, 1); + } else { + /* + write memory + */ + cpu_physical_memory_write(PHYS_BASE_DATA + addr - VIRT_BASE_DATA, + &data, 1); + } +} + +void helper_outb(CPUAVRState *env, uint32_t port, uint32_t data) +{ + data &= 0x000000ff; + + switch (port) { + case 0x04: { + qemu_irq irq; + CPUState *cpu = CPU(avr_env_get_cpu(env)); + irq = qdev_get_gpio_in(DEVICE(cpu), 3); + qemu_set_irq(irq, 1); + break; + } + case 0x38: { + if (avr_feature(env, AVR_FEATURE_RAMPD)) { + env->rampD = (data & 0xff) << 16; /* RAMPD */ + } + break; + } + case 0x39: { + if (avr_feature(env, AVR_FEATURE_RAMPX)) { + env->rampX = (data & 0xff) << 16; /* RAMPX */ + } + break; + } + case 0x3a: { + if (avr_feature(env, AVR_FEATURE_RAMPY)) { + env->rampY = (data & 0xff) << 16; /* RAMPY */ + } + break; + } + case 0x3b: { + if (avr_feature(env, AVR_FEATURE_RAMPZ)) { + env->rampZ = (data & 0xff) << 16; /* RAMPZ */ + } + break; + } + case 0x3c: { + env->eind = (data & 0xff) << 16; /* EIDN */ + break; + } + case 0x3d: { /* SPL */ + env->sp = (env->sp & 0xff00) | (data); + break; + } + case 0x3e: { /* SPH */ + if (avr_feature(env, AVR_FEATURE_2_BYTE_SP)) { + env->sp = (env->sp & 0x00ff) | (data << 8); + } + break; + } + case 0x3f: { /* SREG */ + cpu_set_sreg(env, data); + break; + } + default: { + /* + CPU does not know how to write this register, pass it to the + device/board + */ + cpu_physical_memory_write(PHYS_BASE_REGS + port + OFFS_IOREGS, + &data, 1); + } + } + + if (port < IO_REGS) { + env->io[port] = data; /* make a copy for SBI, SBIC, SBIS & CBI */ + } +} + diff --git a/target-avr/helper.h b/target-avr/helper.h index b5ef3bf..19e0ab7 100644 --- a/target-avr/helper.h +++ b/target-avr/helper.h @@ -18,4 +18,10 @@ * */ +DEF_HELPER_1(wdr, void, env) DEF_HELPER_1(debug, void, env) +DEF_HELPER_1(sleep, void, env) +DEF_HELPER_1(unsupported, void, env) +DEF_HELPER_3(outb, void, env, i32, i32) +DEF_HELPER_2(inb, tl, env, i32) +DEF_HELPER_3(fullwr, void, env, i32, i32)