From patchwork Thu Jun 2 20:06:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Rolnik X-Patchwork-Id: 9151173 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 24ED860221 for ; Thu, 2 Jun 2016 20:31:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 164B92656B for ; Thu, 2 Jun 2016 20:31:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AF9328328; Thu, 2 Jun 2016 20:31: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 000722656B for ; Thu, 2 Jun 2016 20:31:00 +0000 (UTC) Received: from localhost ([::1]:50235 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8ZGe-0002CF-4G for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Jun 2016 16:31:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Ytt-0006ME-UH for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:07:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8Ytk-0003mX-OH for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:07:29 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:35768) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Ytk-0003mJ-3W for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:07:20 -0400 Received: by mail-wm0-x241.google.com with SMTP id e3so18540262wme.2 for ; Thu, 02 Jun 2016 13:07:20 -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=hI5sreyH2jGj5j92ocTP8YvkQxax+BxayicSlIZVDQc=; b=UnQICKVxdrCCAjcfOgz9/9u0XKF9cu1inAKaoszQonuuGsfaFGpQJLPfjVjI/o95Nv 3U1igWxxhHga8zZqSQ0bDZ5JI972XH/W/Czt4SWX/v+Uj+Ev0cEcvkiJIdv9gl4A5swV AiEoT9sgcWzgrwl7FWYMH9iIlbSUd6CxWfbmLtN3lp6PguWrHB5af28zxOUMmixx/0pN 0rFSuqcgM9OHgYQxAAtR58toqSCH//FLHoohuQOWARAhkrtkoW/xLB/t3v5pXaz5U+cS LmNT2Ylhy55Z8XF+3kFmxqd8CsRLy1w8np7YxWUHAoSguN15sb68EK+GIJq2W65z7FrU NVqw== 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=hI5sreyH2jGj5j92ocTP8YvkQxax+BxayicSlIZVDQc=; b=kwm2dYc5KsjGEYMUiCHCU58SlmbgsWc0Dam87Dl/aObwBwnkwAcVQQyKd4QhJNpRKX jvWK5NxtlmKtqNLdRifcKXVNe3BcF0Gt0HtAhXjOi1/j+KiDJy8jdzqP3m6JgisHqAiQ xt7qI7YQsL1UnlPA+drrjxYbIFWaYsdVsmB5CHCdHEA8hENApDK2H8U7xI+J20tw7dh8 67mGmREQKgJTLBkPdOdnPctmYfYbn2/2CvvV675awVTrzoXXJkdnQMeTKl5OuwRuxI0S jEZdmYm1He/EJQYgKElyNr1ClS66WJe6D7huGkjlJUhnaqXBXiRVB1uebWrcwhy26+WW rYAQ== X-Gm-Message-State: ALyK8tKP6zWIWBHutWVFZF/UDj/2ENBUpeFaJYSyJdPU8h7k1fMDnfgih8w0VgH7UGUvDA== X-Received: by 10.194.104.138 with SMTP id ge10mr9655927wjb.85.1464898039326; Thu, 02 Jun 2016 13:07:19 -0700 (PDT) Received: from a0999b0126e1.ant.amazon.com ([94.230.86.227]) by smtp.gmail.com with ESMTPSA id i4sm2127090wjj.49.2016.06.02.13.07.18 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 02 Jun 2016 13:07:18 -0700 (PDT) From: Michael Rolnik X-Google-Original-From: Michael Rolnik To: qemu-devel@nongnu.org Date: Thu, 2 Jun 2016 23:06:57 +0300 Message-Id: <1464898022-97990-5-git-send-email-rolnik@amazon.com> X-Mailer: git-send-email 2.4.9 (Apple Git-60) In-Reply-To: <1464898022-97990-1-git-send-email-rolnik@amazon.com> References: <1464898022-97990-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::241 Subject: [Qemu-devel] [PATCH 05/10] target-avr: adding AVR interrupt handling 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 | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/target-avr/helper.c b/target-avr/helper.c index aec37af..ed22b37 100644 --- a/target-avr/helper.c +++ b/target-avr/helper.c @@ -33,12 +33,74 @@ bool avr_cpu_exec_interrupt( CPUState *cs, int interrupt_request) { - return false; + CPUClass *cc = CPU_GET_CLASS(cs); + AVRCPU *cpu = AVR_CPU(cs); + CPUAVRState *env = &cpu->env; + + bool ret = false; + + if (interrupt_request & CPU_INTERRUPT_RESET) { + if (cpu_interrupts_enabled(env)) { + cs->exception_index = EXCP_RESET; + cc->do_interrupt(cs); + + cs->interrupt_request &= ~CPU_INTERRUPT_RESET; + + ret = true; + } + } + if (interrupt_request & CPU_INTERRUPT_HARD) { + if (cpu_interrupts_enabled(env) && env->intsrc != 0) { + int index = __builtin_ffs(env->intsrc) - 1; + cs->exception_index = EXCP_INT(index); + cc->do_interrupt(cs); + + env->intsrc &= env->intsrc - 1; /* clear the interrupt */ + cs->interrupt_request &= ~CPU_INTERRUPT_HARD; + + ret = true; + } + } + return ret; } void avr_cpu_do_interrupt( CPUState *cs) { + 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 */ + + if (cs->exception_index == EXCP_RESET) { + vector = 0; + } else if (env->intsrc != 0) { + vector = __builtin_ffs(env->intsrc); + } + + 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); + + env->pc = base + vector * size; + } 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); + + env->pc = base + vector * size; + } else { + stb_phys(cs->as, env->sp--, (ret & 0x0000ff)); + + env->pc = base + vector * size; + } + + env->sregI = 0; /* clear Global Interrupt Flag */ + + cs->exception_index = -1; } int avr_cpu_memory_rw_debug(