From patchwork Wed Apr 25 23:45:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 904807 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="Omp0GrWC"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40Wcmw6nm2z9s0W for ; Thu, 26 Apr 2018 10:06:40 +1000 (AEST) Received: from localhost ([::1]:39651 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBUQo-0003eR-V2 for incoming@patchwork.ozlabs.org; Wed, 25 Apr 2018 20:06:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46941) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBU9w-000633-Qv for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:49:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBU9u-0005gc-1p for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:49:12 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:46826) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBU9t-0005gA-Rq for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:49:09 -0400 Received: by mail-pf0-x243.google.com with SMTP id p12so595641pff.13 for ; Wed, 25 Apr 2018 16:49:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LMAcqRiEx+EbkFh6zynGN6fCfi9obCgZkva5ri28p1M=; b=Omp0GrWC9432wWCkY4Nr07ecqSpGObnKsu8Pfu15Jo+jzfXlBJhfmNn7th/6g2fiMp FJOgsNOJ94T/JpQ2guTfqcovRI3FWAsoRDsn9xko2wOx/JbYRd+F24ryD8/Fdziug0cQ WAVudtdUIVHWjBITeWsZ2OCt/FpsEVmRvlm951+W3NH/wjsk9SuaFiS1IAOsLLf7Xiid 41dkQY0d65isQMh6MZH67A1wU4NzELYngCENvexoFsXlrm6NsVTkQ8LnjxNaAw+dY3hn z/tHI/C1FmHaTp0UeRzlnVceKwJMkH4xZ4qTEF6AO9pNGOTeXQjsXB83pWVIIZXo1ZOh sWZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LMAcqRiEx+EbkFh6zynGN6fCfi9obCgZkva5ri28p1M=; b=aMzQXg6VFQn+YJNPwpRMbZRaPBY4pJO/EBj0vxyY90soKkaCkumD6ExO3oowTxXzAa TJeARwHXTTZ1jIbZgl6bt4+iBePZzSD77YsUw71iqLBDz35jVqjRKpS9PqtedYAuMZHs Hls3PdyxN0oONM7uBO/U8qBjV9sGgEzKaBXCYvaUgRz1FwqLvOwfu9Om+i8JnARFvQOJ xCqoM0kCO5dLqn1S1hx1tg1+zN7OejanDdkdvNymAf+zcwFLwAm8YzJlvGKXReXTgPyY M5trUrWBZympKx4VCwExUps8j2zAvPoNcBEORCTSmhA53SoZO1Vbo5AURrkjajTgFtUf HF3Q== X-Gm-Message-State: ALQs6tBzO68ZAREEyuOOzrqv3BFJjthkEc0Tcoqd85iAQYL3UjiaEkVj 6Tx4Qr1EnpxRaZBeeOI8MrjBFg8VGb8= X-Google-Smtp-Source: AIpwx480LS40c07dZdKeUpOrKF/gj7ORrWyHIYwRFvFtGwCrE/4RE2jNPz2g0AfhSF5N307Y7/mwVw== X-Received: by 10.99.114.78 with SMTP id c14mr24321966pgn.199.1524700148860; Wed, 25 Apr 2018 16:49:08 -0700 (PDT) Received: from localhost.localdomain (122-58-167-38-fibre.bb.spark.co.nz. [122.58.167.38]) by smtp.gmail.com with ESMTPSA id e10sm29577549pfn.67.2018.04.25.16.49.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Apr 2018 16:49:08 -0700 (PDT) From: Michael Clark To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 11:45:36 +1200 Message-Id: <1524699938-6764-34-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1524699938-6764-1-git-send-email-mjc@sifive.com> References: <1524699938-6764-1-git-send-email-mjc@sifive.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PATCH v8 33/35] RISC-V: Add public API for the CSR dispatch table 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: Sagar Karandikar , Bastian Koppelmann , Palmer Dabbelt , Michael Clark , Alistair Francis , patches@groups.riscv.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This allows hardware and/or derived cpu instances to override or implement new CSR operations. Cc: Sagar Karandikar Cc: Bastian Koppelmann Cc: Palmer Dabbelt Cc: Alistair Francis Signed-off-by: Michael Clark --- target/riscv/cpu.h | 18 ++++++++++++++++++ target/riscv/csr.c | 35 ++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 6fb0014..4030530 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -301,6 +301,24 @@ static inline target_ulong csr_read_helper(CPURISCVState *env, int csrno) return val; } +typedef int (*riscv_csr_predicate_fn)(CPURISCVState *env, int csrno); +typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, + target_ulong *ret_value); +typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, + target_ulong new_value); +typedef int (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, + target_ulong *ret_value, target_ulong new_value, target_ulong write_mask); + +typedef struct { + riscv_csr_predicate_fn predicate; + riscv_csr_read_fn read; + riscv_csr_write_fn write; + riscv_csr_op_fn op; +} riscv_csr_operations; + +void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops); +void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops); + #include "exec/cpu-all.h" #endif /* RISCV_CPU_H */ diff --git a/target/riscv/csr.c b/target/riscv/csr.c index da66908..25a7e26 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -23,28 +23,29 @@ #include "qemu/main-loop.h" #include "exec/exec-all.h" +/* CSR function table */ -/* Control and Status Register function table forward declaration */ +static riscv_csr_operations csr_ops[]; -typedef int (*riscv_csr_predicate_fn)(CPURISCVState *env, int csrno); -typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, - target_ulong *ret_value); -typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, - target_ulong new_value); -typedef int (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, - target_ulong *ret_value, target_ulong new_value, target_ulong write_mask); +/* CSR function table constants */ -typedef struct { - riscv_csr_predicate_fn predicate; - riscv_csr_read_fn read; - riscv_csr_write_fn write; - riscv_csr_op_fn op; -} riscv_csr_operations; +enum { + CSR_TABLE_SIZE = 0xfff +}; + +/* CSR function table public API */ -static const riscv_csr_operations csr_ops[]; +void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops) +{ + *ops = csr_ops[csrno & CSR_TABLE_SIZE]; +} +void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops) +{ + csr_ops[csrno & CSR_TABLE_SIZE] = *ops; +} -/* Predicates */ +/* CSR function table predicates (private) */ static int fs(CPURISCVState *env, int csrno) { @@ -780,7 +781,7 @@ int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value, /* Control and Status Register function table */ -static const riscv_csr_operations csr_ops[0xfff] = { +static riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* User Floating-Point CSRs */ [CSR_FFLAGS] = { fs, read_fflags, write_fflags }, [CSR_FRM] = { fs, read_frm, write_frm },