From patchwork Thu May 31 05:29:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rashmica Gupta X-Patchwork-Id: 923193 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40xGHr03Mqz9s08 for ; Thu, 31 May 2018 15:30:00 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="cReQrUm7"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40xGHq4fmDzDrbm for ; Thu, 31 May 2018 15:29:59 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="cReQrUm7"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c00::233; helo=mail-pf0-x233.google.com; envelope-from=rashmica.g@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="cReQrUm7"; dkim-atps=neutral Received: from mail-pf0-x233.google.com (mail-pf0-x233.google.com [IPv6:2607:f8b0:400e:c00::233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40xGHj4cKtzDrbK for ; Thu, 31 May 2018 15:29:53 +1000 (AEST) Received: by mail-pf0-x233.google.com with SMTP id f189-v6so10188903pfa.7 for ; Wed, 30 May 2018 22:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ukerlp/kV68vz983rUSsSaWaZx4+ELKoeZFSnhduZ7c=; b=cReQrUm7MIOdrwh9rpn8/F4RUUhUbig89xySgy1VwrAkfp28lfnrfMRkJEQgRiw7rt tKT/I9dUW9/C4YjB4BqctUCkyiL0t/A2nd4UB94wDJVFRoyneoulIit0ENdKiW8rY3or F5RelzhXtos/uzsqmh7yJO/Dp3WaKX/0GVs2U4Zt4AZNnzybhn3nZoO6cc1+BgqJgn5q 5ll4Hme9lo+omUJA5UPVjygNt6W8iE4kxxcndloQEuLqbXVlVzKib9Yc7eJBRpXnLFex u83glw9beewZQG6kJ/+1gCAYENTDbqK4YAt9XynY07PYBHDZncAdjyqEaGxOCGSOFFB8 5zUw== 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=Ukerlp/kV68vz983rUSsSaWaZx4+ELKoeZFSnhduZ7c=; b=ZwLjfeJEKGMUOp2zWDcUtRVQuq1eqG104mTbTro0gJhn0a7qWve7HxS/ORmhYgUSzt Bam2CHm5+CmJ2KL38dr3MCL4nmtwGoQvPPlHaj/7xkx9w9LjuzvaaqrCbDDE5sK3IXTD J3rb5avr7gAdevoZS5Rug4zEM0Ejo5OSMVUQ0z1SzcJOiyLiXzK2JJ6zXYnvTnjQQLFX 12dxp9bnBgqHP8yWfhqkk+q4Fn2CnbXTnV0QK3ezqYqUbmg5/CWD9aXEpCbfE6HUMEjB /W0c35ZkDG4kTWDyiQ7OKhpc1ZAjJMGPQs2eAiJYd3BJDOSzXPmfBZkmmUbEIpZmvzgX sHqA== X-Gm-Message-State: ALKqPwcoPOhDhjSseTxdndue2CYZjYO9L/NADSZ7Y90xdpCD3UAg4nb5 b2PuKtPcvM3zv1hXC4057ndYjg== X-Google-Smtp-Source: ADUXVKITFY3NcCWuxG9rgkBZODOb3D2C70ReD9Spw21Cf3Qewq8TThH7jLwnNXHr4Zgd67mtF+n3kA== X-Received: by 2002:a63:449:: with SMTP id 70-v6mr4418608pge.229.1527744591635; Wed, 30 May 2018 22:29:51 -0700 (PDT) Received: from rashmica.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id h10-v6sm4500515pgc.28.2018.05.30.22.29.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 May 2018 22:29:51 -0700 (PDT) From: Rashmica Gupta To: pdbg@lists.ozlabs.org Date: Thu, 31 May 2018 15:29:12 +1000 Message-Id: <20180531052915.31171-7-rashmica.g@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180531052915.31171-1-rashmica.g@gmail.com> References: <20180531052915.31171-1-rashmica.g@gmail.com> Subject: [Pdbg] [PATCH 07/10] libpdbg: Add in mtocrf and putcr function X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Rashmica Gupta --- libpdbg/chip.c | 36 ++++++++++++++++++++++++++++++++++++ libpdbg/libpdbg.h | 1 + libpdbg/operations.h | 1 + 3 files changed, 38 insertions(+) diff --git a/libpdbg/chip.c b/libpdbg/chip.c index b698bcd..a4642fd 100644 --- a/libpdbg/chip.c +++ b/libpdbg/chip.c @@ -60,6 +60,20 @@ static uint64_t mfocrf(uint64_t reg, uint64_t cr) return MFOCRF_OPCODE | (reg << 21) | (1U << (12 + cr)); } +static uint64_t mtocrf(uint64_t cr, uint64_t reg) +{ + if (reg > 31) { + PR_ERROR("Invalid register specified for mfocrf\n"); + exit(1); + } + if (cr > 7) { + PR_ERROR("Invalid CR field specified\n"); + exit(1); + } + + return MTOCRF_OPCODE | (reg << 21) | (1U << (12 + cr)); +} + static uint64_t mfnia(uint64_t reg) { if (reg > 31) { @@ -368,6 +382,28 @@ int ram_getcr(struct pdbg_target *thread, uint64_t *value) return 0; } +int ram_putcr_field(struct pdbg_target *thread, int cr, uint64_t value) +{ + uint64_t opcodes[] = {mfspr(0, 277), mtocrf(cr, 0)}; + uint64_t results[] = {value, 0}; + + CHECK_ERR(ram_instructions(thread, opcodes, results, ARRAY_SIZE(opcodes), 0)); + return 0; +} + +int ram_putcr(struct pdbg_target *thread, uint64_t value) +{ + uint64_t cr_field; + int i; + + for (i = 0; i < 8; i++){ + cr_field = value & (0xf << 4*i); + ram_putcr_field(thread, i, cr_field); + } + + return 0; +} + int ram_putmsr(struct pdbg_target *thread, uint64_t value) { uint64_t opcodes[] = {mfspr(0, 277), mtmsr(0)}; diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 7f09caa..14645a3 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -141,6 +141,7 @@ int ram_putspr(struct pdbg_target *target, int spr, uint64_t val); int ram_putgpr(struct pdbg_target *target, int spr, uint64_t val); int ram_getmsr(struct pdbg_target *target, uint64_t *val); int ram_getcr(struct pdbg_target *thread, uint64_t *value); +int ram_putcr(struct pdbg_target *thread, uint64_t value); int ram_getnia(struct pdbg_target *target, uint64_t *val); int ram_getspr(struct pdbg_target *target, int spr, uint64_t *val); int ram_getgpr(struct pdbg_target *target, int gpr, uint64_t *val); diff --git a/libpdbg/operations.h b/libpdbg/operations.h index c7e3218..74baed8 100644 --- a/libpdbg/operations.h +++ b/libpdbg/operations.h @@ -73,6 +73,7 @@ #define MFXERF2_OPCODE 0x00000210UL #define MFXERF3_OPCODE 0x00000310UL #define MFOCRF_OPCODE 0x7c100026UL +#define MTOCRF_OPCODE 0x7C100120UL #define MFSPR_MASK (MFSPR_OPCODE | ((0x1f) << 16) | ((0x3e0) << 6)) #define MFXER_OPCODE (MFSPR_OPCODE | ((1 & 0x1f) << 16) | ((1 & 0x3e0) << 6)) #define MTXER_OPCODE (MTSPR_OPCODE | ((1 & 0x1f) << 16) | ((1 & 0x3e0) << 6))