From patchwork Fri Jun 3 00:40:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Rolnik X-Patchwork-Id: 9151435 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 9BDB160467 for ; Fri, 3 Jun 2016 00:44:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8361628328 for ; Fri, 3 Jun 2016 00:44:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7850228331; Fri, 3 Jun 2016 00:44:39 +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 1F3AD28328 for ; Fri, 3 Jun 2016 00:44:38 +0000 (UTC) Received: from localhost ([::1]:51112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8dE5-0000wI-8n for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Jun 2016 20:44:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8dAs-0006vh-UJ for qemu-devel@nongnu.org; Thu, 02 Jun 2016 20:41:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8dAq-0007c0-Kq for qemu-devel@nongnu.org; Thu, 02 Jun 2016 20:41:17 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36601) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8dAq-0007bV-6f for qemu-devel@nongnu.org; Thu, 02 Jun 2016 20:41:16 -0400 Received: by mail-wm0-x243.google.com with SMTP id a20so8287214wma.3 for ; Thu, 02 Jun 2016 17:41:16 -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=7pZVeGLsywq+9Ybf4zYG9L1BC3e6NHmltQrme59DnS0=; b=tPCzfJgg6gvQ8YJmCK/9LBV4pNyuUgF7zB26SaauasXgy3s2LpzlAU+V18o49GS1vF 0ofY7+mmB+Wri5wNTtooDZea0bi4JAEKgSkMjzm3C7HKnZbnGYaH0sI63Bpl2T+faaT/ C/SfJ1XCIBSJbeF9mdHnNW8bmq7fiiJnUS1aE9HM3XrmMMOMaCFE9FloVFP99jvVofl/ eYz8t4TOwJ30MkEkx89ocu0tTH+PoopFZYa3LmP2hI0+51VezWJMWWt+H/rkWCFwcVz1 RdwDAGth2D43JrO/U4uz9Y2XaGU5b087oxpnHeBdgF2UsbYsTACfQSu+hZIxmxdkEMxI ol1Q== 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=7pZVeGLsywq+9Ybf4zYG9L1BC3e6NHmltQrme59DnS0=; b=AxrOoVuVpvCtmSuaZB/p1RlcvMJ3OOmbZ3OkPFn9yVcRYlgj8VLr3bHbXz2HPRriCM uYNl6l+qFS5rJbI2AwbGdskJdabSfHcLlbFJYZwVIiFtRLfP970C/FAW5tb3PjZ76rHJ 3s8rjvAT+rdQH9IqMG0CNE1rJvT99FEyBR7+a5Pq6/8Lx+4nMX3tKjNBtpOMu7ejmPj+ TD8OkpFH+ATZeIgfVFhY13m1MwhvsxkznsmcdD1ZJ+Yrs50QRZAb/ghKsWKXqV8Lh+PY KUYOiTYDwjPy6V9yhHLVXNuBTncX7H/3eKVTlWY3br7OCqWF0SG/50IW3NvCshfNeV0/ kgTg== X-Gm-Message-State: ALyK8tKrImPOVwXArxQMa3xPHfg7ddnVQFsThIks0Yha70Ru4iHXgutnni14Qa4fopdr6w== X-Received: by 10.28.1.9 with SMTP id 9mr1229702wmb.34.1464914475543; Thu, 02 Jun 2016 17:41:15 -0700 (PDT) Received: from a0999b0126e1.ant.amazon.com ([94.230.86.227]) by smtp.gmail.com with ESMTPSA id i190sm42677210wmf.10.2016.06.02.17.41.14 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 02 Jun 2016 17:41:15 -0700 (PDT) From: Michael Rolnik X-Google-Original-From: Michael Rolnik To: qemu-devel@nongnu.org Date: Fri, 3 Jun 2016 03:40:17 +0300 Message-Id: <1464914420-17875-7-git-send-email-rolnik@amazon.com> X-Mailer: git-send-email 2.4.9 (Apple Git-60) In-Reply-To: <1464914420-17875-1-git-send-email-rolnik@amazon.com> References: <1464914420-17875-1-git-send-email-rolnik@amazon.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH 6/9] 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: Michael Rolnik , Michael Rolnik 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 | 117 +++++++++++++++++++++++++++++++++++++++++++++++----- target-avr/helper.h | 5 +++ 2 files changed, 111 insertions(+), 11 deletions(-) diff --git a/target-avr/helper.c b/target-avr/helper.c index bb47a87..b93589a 100644 --- a/target-avr/helper.c +++ b/target-avr/helper.c @@ -31,7 +31,7 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request) { - CPUClass *cc = CPU_GET_CLASS(cs); + CPUClass *cc = CPU_GET_CLASS(cs); AVRCPU *cpu = AVR_CPU(cs); CPUAVRState *env = &cpu->env; @@ -49,7 +49,7 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request) } if (interrupt_request & CPU_INTERRUPT_HARD) { if (cpu_interrupts_enabled(env) && env->intsrc != 0) { - int index = __builtin_ffs(env->intsrc) - 1; + int index = __builtin_ffs(env->intsrc) - 1; cs->exception_index = EXCP_INT(index); cc->do_interrupt(cs); @@ -64,18 +64,18 @@ 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; - int vector; - int size = avr_feature(env, AVR_FEATURE_JMP_CALL) ? 2 : 1; - int base = 0; /* TODO: where to get it */ + uint32_t ret = env->pc; + int vector; + int size = avr_feature(env, AVR_FEATURE_JMP_CALL) ? 2 : 1; + int base = 0; /* TODO: where to get it */ if (cs->exception_index == EXCP_RESET) { - vector = 0; + vector = 0; } else if (env->intsrc != 0) { - vector = __builtin_ffs(env->intsrc); + vector = __builtin_ffs(env->intsrc); } if (avr_feature(env, AVR_FEATURE_3_BYTE_PC)) { @@ -95,7 +95,7 @@ void avr_cpu_do_interrupt(CPUState *cs) env->pc = base + vector * size; } - env->sregI = 0; /* clear Global Interrupt Flag */ + env->sregI = 0; /* clear Global Interrupt Flag */ cs->exception_index = -1; } @@ -136,6 +136,21 @@ void tlb_fill(CPUState *cs, target_ulong vaddr, int is_write, int mmu_idx, uintp 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)); + + cs->exception_index = EXCP_DEBUG; + cpu_dump_state(cs, stderr, fprintf, 0); + cpu_loop_exit(cs); +} void helper_debug(CPUAVRState *env) { @@ -145,3 +160,83 @@ void helper_debug(CPUAVRState *env) cpu_loop_exit(cs); } +void helper_wdr(CPUAVRState *env) +{ + CPUState *cs = CPU(avr_env_get_cpu(env)); + + cs->exception_index = EXCP_DEBUG; + cpu_loop_exit(cs); +} + +target_ulong helper_inb(CPUAVRState *env, uint32_t port) +{ + printf("in: io[%02x]\n", port); + + switch (port) { + case 0x3b: { + return env->rampZ; /* RAMPZ */ + } + case 0x3d: { /* SPL */ + return env->sp & 0x00ff; + } + case 0x3e: { /* SPH */ + return env->sp >> 8; + } + case 0x3f: { /* SREG */ + uint8_t sreg; + sreg = (env->sregC & 0x01) << 0 + | (env->sregZ & 0x01) << 1 + | (env->sregN & 0x01) << 2 + | (env->sregV & 0x01) << 3 + | (env->sregS & 0x01) << 4 + | (env->sregH & 0x01) << 5 + | (env->sregT & 0x01) << 6 + | (env->sregI & 0x01) << 7; + return sreg; + } + } + return 0; +} + +void helper_outb(CPUAVRState *env, uint32_t port, uint32_t data) +{ + printf("out:%02x -> io[%02x]\n", data, port); + + 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 0x3b: { + env->rampZ = data & 0x01; /* RAMPZ */ + break; + } + case 0x3d: { /* SPL */ + if (avr_feature(env, AVR_FEATURE_2_BYTE_SP)) { + env->sp = (env->sp & 0xff00) | (data); + } + break; + } + case 0x3e: { /* SPH */ + env->sp = (env->sp & 0x00ff) | (data << 8); + break; + } + case 0x3f: { /* SREG */ + env->sregC = (data >> 0) & 0x01; + env->sregZ = (data >> 1) & 0x01; + env->sregN = (data >> 2) & 0x01; + env->sregV = (data >> 3) & 0x01; + env->sregS = (data >> 4) & 0x01; + env->sregH = (data >> 5) & 0x01; + env->sregT = (data >> 6) & 0x01; + env->sregI = (data >> 7) & 0x01; + break; + } + } +} + diff --git a/target-avr/helper.h b/target-avr/helper.h index b5ef3bf..82f440a 100644 --- a/target-avr/helper.h +++ b/target-avr/helper.h @@ -18,4 +18,9 @@ * */ +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)