Received: from eggs.gnu.org ([2001:4830:134:3::10]:49582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bl1CG-0005SH-0M for qemu-devel@nongnu.org; Fri, 16 Sep 2016 18:01:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bl1CE-0001lK-5V for qemu-devel@nongnu.org; Fri, 16 Sep 2016 18:01:22 -0400 Received: from mail-yw0-x244.google.com ([2607:f8b0:4002:c05::244]:33319) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bl1CE-0001kz-1y for qemu-devel@nongnu.org; Fri, 16 Sep 2016 18:01:22 -0400 Received: by mail-yw0-x244.google.com with SMTP id g192so4997659ywh.0 for ; Fri, 16 Sep 2016 15:01:21 -0700 (PDT) Sender: Richard Henderson From: Richard Henderson Date: Fri, 16 Sep 2016 15:00:34 -0700 Message-Id: <1474063242-27419-6-git-send-email-rth@twiddle.net> In-Reply-To: <1474063242-27419-1-git-send-email-rth@twiddle.net> References: <1474063242-27419-1-git-send-email-rth@twiddle.net> Subject: [Qemu-devel] [PATCH v18 05/13] target-avr: adding AVR interrupt handling List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: mrolnik@gmail.com From: Michael Rolnik Signed-off-by: Michael Rolnik Message-Id: <1471522070-77598-6-git-send-email-mrolnik@gmail.com> Signed-off-by: Richard Henderson --- target-avr/helper.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/target-avr/helper.c b/target-avr/helper.c index c187193..61255fd 100644 --- a/target-avr/helper.c +++ b/target-avr/helper.c @@ -32,11 +32,66 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request) { bool ret = false; + CPUClass *cc = CPU_GET_CLASS(cs); + AVRCPU *cpu = AVR_CPU(cs); + CPUAVRState *env = &cpu->env; + + 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)) { + 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)) { + cpu_stb_data(env, env->sp--, (ret & 0x0000ff)); + cpu_stb_data(env, env->sp--, (ret & 0x00ff00) >> 8); + } else { + cpu_stb_data(env, 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.7.4