From patchwork Thu Jun 2 20:04:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Rolnik X-Patchwork-Id: 9151149 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 8A62D60467 for ; Thu, 2 Jun 2016 20:14:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CBAF2656B for ; Thu, 2 Jun 2016 20:14:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7197C28328; Thu, 2 Jun 2016 20:14:31 +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 1102F2656B for ; Thu, 2 Jun 2016 20:14:31 +0000 (UTC) Received: from localhost ([::1]:50126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Z0g-0004D7-5M for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Jun 2016 16:14:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54493) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Yr4-0003TP-QA for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:04:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8Yqu-00039Q-N3 for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:04:33 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:33157) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Yqu-00038k-G1 for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:04:24 -0400 Received: by mail-wm0-x243.google.com with SMTP id a136so18637934wme.0 for ; Thu, 02 Jun 2016 13:04: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=hI5sreyH2jGj5j92ocTP8YvkQxax+BxayicSlIZVDQc=; b=ffFfNvyDgHdrJGs6f+LnY5mP3qpddC1bvPgiD38eQryjsPOlwOMbaQpXgZtCne2ZSk pUPAxniAUYq492AVbwyKrbZXb1Fuj2HRqiq2c8VNQGFk0gXd46kqX2Je1ExzfLHmSd2Q iik9QFCqRHE8JeduZ680tbgj9C74oqQfUjpqjGpV/kRvXZ3GpBU4cJy1s8vAaODmCm1u H8/pM8mSZIUYV2lWE3uExicaK8cr1dDY5oHUlCGyqKqfUcg7nuzmm72fsEuiMbuB5CFR z32e0M3DH4kBs3ED9/uMVcY60uIkqLC6ImnovseRmsgwX2Bo82DksXosy9p9LLsSf7/O 9Mkg== 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=QIYQHF7BRCeTh53otYf8wcW9ysd4DcuHWBCnZ9j5sA8x1S97aqPoVueX20xbHOqaB0 j7AUnKjnV5rmFYi1wcGcw0YN6dsGGignaDTwDipSET54iO73NjABv/t3wC/4qcERcw99 P+36vEtTn3Txsm9FkfmVHR0fX4MD2O2Z4y8EKToAG/qmymX/33h2i9ULmouoTq23TmNu 3EXJObBmP6TrArZMWjxM2lMaFwp9x2S12IArmfGyEOEmFbXKsKJrtZP0rqnTsJndJ/EZ UP6X2hZ6rfQt4//MSe2RaXLjftw3eP41ymyj+TLM6vWBOlItXS7iD+7rl2rf2Er037cn AnbA== X-Gm-Message-State: ALyK8tLhcPQl9mVZJs5boZ0sGfsGl/VVdze6GvJYmrefvjsrkA15Q6BfCSZoJZBI3wpeEQ== X-Received: by 10.194.107.202 with SMTP id he10mr10313840wjb.165.1464897863902; Thu, 02 Jun 2016 13:04:23 -0700 (PDT) Received: from a0999b0126e1.ant.amazon.com ([94.230.86.227]) by smtp.gmail.com with ESMTPSA id lf9sm2114488wjc.44.2016.06.02.13.04.22 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 02 Jun 2016 13:04:23 -0700 (PDT) From: Michael Rolnik X-Google-Original-From: Michael Rolnik To: qemu-devel@nongnu.org Date: Thu, 2 Jun 2016 23:04:01 +0300 Message-Id: <1464897846-97364-5-git-send-email-rolnik@amazon.com> X-Mailer: git-send-email 2.4.9 (Apple Git-60) In-Reply-To: <1464897846-97364-1-git-send-email-rolnik@amazon.com> References: <1464897846-97364-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 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(