From patchwork Thu May 31 05:29:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rashmica Gupta X-Patchwork-Id: 923192 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 40xGHn34KYz9s08 for ; Thu, 31 May 2018 15:29:57 +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="tSEslhI5"; 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 40xGHn1ChFzDr30 for ; Thu, 31 May 2018 15:29:57 +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="tSEslhI5"; 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="tSEslhI5"; 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 40xGHg04BhzDrbW for ; Thu, 31 May 2018 15:29:50 +1000 (AEST) Received: by mail-pf0-x233.google.com with SMTP id a14-v6so10188641pfi.1 for ; Wed, 30 May 2018 22:29:50 -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=ws1N15ljfLNds7m5jVhLtFXwmpnRqN+x2Otm+PSG4qM=; b=tSEslhI5AC8ruWcF/DO31u6xXa1r8cwH4DBcmyktdB6TOe23cvceUc0HgsxRIWusRc dPtlL2QcZZhoMP7EI6dtgnneIeFaGP9jMd08CRDamY7hG0/9rnQSbgMCvyA70GsK7M2a Ammk6GfZsVwMV9Ym9Bim5zoIrNoD/rcKp4Vl51+v7AiDP1hJ/8oS5rcIjsgLUO3trI2i xXm//yF8Y6lvb4A/eh2b+M/XIvLqsxqxgE7FN6LwCighM5xqhJ7vpe1MJ+vU7DUYBvjt zAZLc3EoS2+uQAKyCkKcxMOCMGlq3wZuTJ/zzh4NEDPIjoAmPbwoQFpavn2Kx6QREnOi 2nZg== 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=ws1N15ljfLNds7m5jVhLtFXwmpnRqN+x2Otm+PSG4qM=; b=N12YPBHwSy6sFMuuO+KyJ633pExnAWZC7a3uoJRLVDbPSmNNuh2FjK6n5UX9xlM5W6 +bYuRfMa3TNVAchbyWfQsILpeIiqx3ljCfJR9rTNsB4dgy8829B9xJObwBpy3M8EZ4i8 InsQhBvTtLE32dWbDYNwpx0PDTzppBjomKcowgB9J+i47x9RT2wSr0RlogsK30h2jt8H NOnUEwRB1Z2N4Woq2nhSnzsP0xSbe6anUrVhNOtRz3wt0AmucWJoA7GUBGj4cjUye35V DlqC/kbjgenh4Mnu3oZE+CNDIPfSN23f/LoN5w88Z5FOZmEpbwyCXwiE7sXtaxHSec6S VT1A== X-Gm-Message-State: ALKqPwfpL8LJKcQJkoNc24/GsIM6nuCegsk184AYw7q6uTO1s2Ggm5Sm liREelbPcH/ln6jxe1tHPvugwQ== X-Google-Smtp-Source: ADUXVKLYgn3tiFrFlPjifLJBybCbYWselPzZRJgnjqlMStssh5dFoahIclHzvCxPi+UIAg/v0rAHhw== X-Received: by 2002:a63:ba1c:: with SMTP id k28-v6mr4411028pgf.179.1527744589007; Wed, 30 May 2018 22:29:49 -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.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 May 2018 22:29:48 -0700 (PDT) From: Rashmica Gupta To: pdbg@lists.ozlabs.org Date: Thu, 31 May 2018 15:29:11 +1000 Message-Id: <20180531052915.31171-6-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 06/10] libpdbg: Return if invalid register numbers are given 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" Currently if an invalid register number (eg 44) is given to the opcode functions an error is printed and the instruction with the invalid register number is returned. This means that this invalid instruction is rammed into the machine and causes the machine to reboot. So if an invalid register number is supplied, exit out. Signed-off-by: Rashmica Gupta --- libpdbg/chip.c | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/libpdbg/chip.c b/libpdbg/chip.c index f478526..b698bcd 100644 --- a/libpdbg/chip.c +++ b/libpdbg/chip.c @@ -28,66 +28,84 @@ static uint64_t mfspr(uint64_t reg, uint64_t spr) { - if (reg > 31) + if (reg > 31) { PR_ERROR("Invalid register specified for mfspr\n"); + exit(1); + } return MFSPR_OPCODE | (reg << 21) | ((spr & 0x1f) << 16) | ((spr & 0x3e0) << 6); } static uint64_t mtspr(uint64_t spr, uint64_t reg) { - if (reg > 31) + if (reg > 31) { PR_ERROR("Invalid register specified for mtspr\n"); + exit(1); + } return MTSPR_OPCODE | (reg << 21) | ((spr & 0x1f) << 16) | ((spr & 0x3e0) << 6); } static uint64_t mfocrf(uint64_t reg, uint64_t cr) { - if (reg > 31) + if (reg > 31) { PR_ERROR("Invalid register specified for mfocrf\n"); - if (cr > 7) + exit(1); + } + if (cr > 7) { PR_ERROR("Invalid CR field specified\n"); + exit(1); + } return MFOCRF_OPCODE | (reg << 21) | (1U << (12 + cr)); } static uint64_t mfnia(uint64_t reg) { - if (reg > 31) + if (reg > 31) { PR_ERROR("Invalid register specified for mfnia\n"); + exit(1); + } return MFNIA_OPCODE | (reg << 21); } static uint64_t mtnia(uint64_t reg) { - if (reg > 31) + if (reg > 31) { PR_ERROR("Invalid register specified for mtnia\n"); + exit(1); + } return MTNIA_OPCODE | (reg << 21); } static uint64_t mfmsr(uint64_t reg) { - if (reg > 31) + if (reg > 31) { PR_ERROR("Invalid register specified for mfmsr\n"); + exit(1); + } return MFMSR_OPCODE | (reg << 21); } static uint64_t mtmsr(uint64_t reg) { - if (reg > 31) + if (reg > 31) { PR_ERROR("Invalid register specified for mtmsr\n"); + exit(1); + } return MTMSR_OPCODE | (reg << 21); } static uint64_t mfxerf(uint64_t reg, uint64_t field) { - if (reg > 31) + if (reg > 31) { PR_ERROR("Invalid register specified for mfxerf\n"); + exit(1); + } switch(field) { case 0: @@ -100,14 +118,17 @@ static uint64_t mfxerf(uint64_t reg, uint64_t field) return MFXERF3_OPCODE | (reg << 21); default: PR_ERROR("Invalid XER field specified\n"); + exit(1); } return 0; } static uint64_t mtxerf(uint64_t reg, uint64_t field) { - if (reg > 31) + if (reg > 31) { PR_ERROR("Invalid register specified for mtxerf\n"); + exit(1); + } switch(field) { case 0: @@ -120,14 +141,17 @@ static uint64_t mtxerf(uint64_t reg, uint64_t field) return MTXERF3_OPCODE | (reg << 21); default: PR_ERROR("Invalid XER field specified\n"); + exit(1); } return 0; } static uint64_t ld(uint64_t rt, uint64_t ds, uint64_t ra) { - if ((rt > 31) | (ra > 31) | (ds > 0x3fff)) + if ((rt > 31) | (ra > 31) | (ds > 0x3fff)) { PR_ERROR("Invalid register specified\n"); + exit(1); + } return LD_OPCODE | (rt << 21) | (ra << 16) | (ds << 2); }