From patchwork Sun Jul 24 17:11:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 106538 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 89AEFB6F75 for ; Mon, 25 Jul 2011 03:32:22 +1000 (EST) Received: from localhost ([::1]:58379 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ql2H6-0002Qm-1s for incoming@patchwork.ozlabs.org; Sun, 24 Jul 2011 13:15:32 -0400 Received: from eggs.gnu.org ([140.186.70.92]:57773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ql2Gq-0001wa-7j for qemu-devel@nongnu.org; Sun, 24 Jul 2011 13:15:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ql2Gi-0005X2-GK for qemu-devel@nongnu.org; Sun, 24 Jul 2011 13:15:11 -0400 Received: from mail-fx0-f47.google.com ([209.85.161.47]:59235) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ql2Gi-0005Nr-Be for qemu-devel@nongnu.org; Sun, 24 Jul 2011 13:15:08 -0400 Received: by fxg11 with SMTP id 11so8355663fxg.34 for ; Sun, 24 Jul 2011 10:13:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=jim+v7Tff67PJhrtgzCVLt9LtNL6EpxSFoZQkRFcUIw=; b=jtAFPgIRanRwFUNwfVx4S1v+jGt0/88JIIBwvj38iC0Lz+nu7BlBgPSXm38KEvjlJw Ikz41G6CHHzCH3bY3B6ht6aJ3RzQjmsVZoLh/0Viod3ZKjaZ1mZ54y+xkx3QHfZpRrd1 p2oieElcOW9elazWobpOOtmpe5Aww6bkABTsw= Received: by 10.204.8.89 with SMTP id g25mr1029315bkg.10.1311527637590; Sun, 24 Jul 2011 10:13:57 -0700 (PDT) Received: from octofox.metropolis ([188.134.19.124]) by mx.google.com with ESMTPS id r24sm1071603bkr.59.2011.07.24.10.13.55 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 24 Jul 2011 10:13:57 -0700 (PDT) Received: by octofox.metropolis (sSMTP sendmail emulation); Sun, 24 Jul 2011 21:13:54 +0400 From: Max Filippov To: qemu-devel@nongnu.org Date: Sun, 24 Jul 2011 21:11:05 +0400 Message-Id: <1311527469-12963-28-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1311527469-12963-1-git-send-email-jcmvbkbc@gmail.com> References: <1311527469-12963-1-git-send-email-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.161.47 Cc: jcmvbkbc@gmail.com Subject: [Qemu-devel] [PATCH v2 27/31] target-xtensa: implement relocatable vectors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org See ISA, 4.4.3 for details. Vector addresses recorded in core configuration are absolute values that correspond to default VECBASE value. Signed-off-by: Max Filippov --- target-xtensa/cpu.h | 2 ++ target-xtensa/helper.c | 18 ++++++++++++++++-- target-xtensa/translate.c | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/target-xtensa/cpu.h b/target-xtensa/cpu.h index a1d4e6d..30b36fc 100644 --- a/target-xtensa/cpu.h +++ b/target-xtensa/cpu.h @@ -123,6 +123,7 @@ enum { INTCLEAR = 227, INTENABLE = 228, PS = 230, + VECBASE = 231, EXCCAUSE = 232, CCOUNT = 234, PRID = 235, @@ -218,6 +219,7 @@ typedef struct XtensaConfig { unsigned nareg; int excm_level; int ndepc; + uint32_t vecbase; uint32_t exception_vector[EXC_MAX]; unsigned ninterrupt; unsigned nlevel; diff --git a/target-xtensa/helper.c b/target-xtensa/helper.c index b0bcee8..3ca0d61 100644 --- a/target-xtensa/helper.c +++ b/target-xtensa/helper.c @@ -40,6 +40,7 @@ void cpu_reset(CPUXtensaState *env) env->pc = env->config->exception_vector[EXC_RESET]; env->sregs[LITBASE] &= ~1; env->sregs[PS] = 0x1f; + env->sregs[VECBASE] = env->config->vecbase; env->pending_irq_level = 0; } @@ -53,6 +54,7 @@ static const XtensaConfig core_config[] = { .nareg = 64, .ndepc = 1, .excm_level = 16, + .vecbase = 0x5fff8400, .exception_vector = { [EXC_RESET] = 0x5fff8000, [EXC_WINDOW_OVERFLOW4] = 0x5fff8400, @@ -139,6 +141,16 @@ target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr) return addr; } +static uint32_t relocated_vector(CPUState *env, uint32_t vector) +{ + if (xtensa_option_enabled(env->config, + XTENSA_OPTION_RELOCATABLE_VECTOR)) { + return vector - env->config->vecbase + env->sregs[VECBASE]; + } else { + return vector; + } +} + /*! * Handle penging IRQ. * For the high priority interrupt jump to the corresponding interrupt vector. @@ -158,7 +170,8 @@ static bool handle_interrupt(CPUState *env) if (level > 1) { env->sregs[EPC1 + level - 1] = env->pc; env->sregs[EPS2 + level - 2] = env->sregs[PS]; - env->pc = env->config->interrupt_vector[level]; + env->pc = relocated_vector(env, + env->config->interrupt_vector[level]); } else { handled = false; env->sregs[EXCCAUSE] = LEVEL1_INTERRUPT_CAUSE; @@ -199,7 +212,8 @@ void do_interrupt(CPUState *env) case EXC_USER: case EXC_DOUBLE: if (env->config->exception_vector[env->exception_index]) { - env->pc = env->config->exception_vector[env->exception_index]; + env->pc = relocated_vector(env, + env->config->exception_vector[env->exception_index]); env->exception_taken = 1; } else { qemu_log("%s(pc = %08x) bad exception_index: %d\n", diff --git a/target-xtensa/translate.c b/target-xtensa/translate.c index 83e4a4f..3c750ef 100644 --- a/target-xtensa/translate.c +++ b/target-xtensa/translate.c @@ -106,6 +106,7 @@ static const char * const sregnames[256] = { [INTCLEAR] = "INTCLEAR", [INTENABLE] = "INTENABLE", [PS] = "PS", + [VECBASE] = "VECBASE", [EXCCAUSE] = "EXCCAUSE", [CCOUNT] = "CCOUNT", [PRID] = "PRID",