Received: from eggs.gnu.org ([2001:4830:134:3::10]:59300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNY05-0002dU-2b for qemu-devel@nongnu.org; Thu, 14 Jul 2016 00:11:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNY03-00030F-V1 for qemu-devel@nongnu.org; Thu, 14 Jul 2016 00:11:48 -0400 Received: from mail-pa0-x242.google.com ([2607:f8b0:400e:c03::242]:36193) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNY03-0002zz-OD for qemu-devel@nongnu.org; Thu, 14 Jul 2016 00:11:47 -0400 Received: by mail-pa0-x242.google.com with SMTP id ez1so582531pab.3 for ; Wed, 13 Jul 2016 21:11:47 -0700 (PDT) From: Michael Rolnik Date: Wed, 13 Jul 2016 21:10:57 -0700 Message-Id: <1468469461-18661-6-git-send-email-mrolnik@gmail.com> In-Reply-To: <1468469461-18661-1-git-send-email-mrolnik@gmail.com> References: <1468469461-18661-1-git-send-email-mrolnik@gmail.com> Subject: [Qemu-devel] [PATCH v11 5/9] target-avr: adding AVR interrupt handling List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: rth@twiddle.net, peter.maydell@linaro.org, Michael Rolnik Signed-off-by: Michael Rolnik --- target-avr/helper.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/target-avr/helper.c b/target-avr/helper.c index ffc9378..3e61193 100644 --- a/target-avr/helper.c +++ b/target-avr/helper.c @@ -31,11 +31,68 @@ 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 = ctz32(env->intsrc); + 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_w; + int vector = 0; + 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 = ctz32(env->intsrc) + 1; + } + + 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); + } 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); + } else { + stb_phys(cs->as, env->sp--, (ret & 0x0000ff)); + } + + env->pc_w = base + vector * size; + env->sregI = 0; /* clear Global Interrupt Flag */ + + cs->exception_index = -1; } int avr_cpu_memory_rw_debug(CPUState *cs, vaddr addr, uint8_t *buf, -- 2.4.9 (Apple Git-60)