From patchwork Mon Aug 20 05:12:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 959502 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41v24v6twlz9s89 for ; Mon, 20 Aug 2018 15:13:03 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="OgmdOw4H"; 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 41v24v56RDzF0xR for ; Mon, 20 Aug 2018 15:13:03 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="OgmdOw4H"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41v24q0pbFzDqp5 for ; Mon, 20 Aug 2018 15:12:59 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="OgmdOw4H"; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 41v24p4yTmz9s4s; Mon, 20 Aug 2018 15:12:58 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1534741978; bh=CtM/Eqw53WGxQQeeyfghlt++qYTBjNbG4ApiY4rGdY4=; h=From:To:Cc:Subject:Date:From; b=OgmdOw4HsviHglzKCz4+j+c9VAKqJGu+SWY6+QrKFNiNN8HAJWkXCCMtrYtH5XcOu ek+E5DUWf8R8GVtgCCThUN2rvRVt7XPOw4FBMg3ZYCIX/HBhbYUz9etMCiy2TFYqH6 zvA+nIRo26Dkbv7gaDcQOwCBtQVzdTt+ArkgTVN2+Q6T3O7WVT+BLHK4U+yRpPJk/M +POloRNGVFfKGzJfs7zWgtfSFNB5yG8hhv9j55WTTXQx4dlm1BGuuAYlztNHSSmcQ9 +XYardN3FyZd0ZJkQudrD9BbHUEPb/J4idyKhLMRFxkTfridP+BPNzB6GkwuaA06lr 7T+wQr3zsVQtA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Mon, 20 Aug 2018 15:12:56 +1000 Message-Id: <20180820051256.1285595-1-amitay@ozlabs.org> X-Mailer: git-send-email 2.17.1 Subject: [Pdbg] [PATCH] adu: Fix calculation of bytes read in getmem X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" This avoids the condition addr-start_addr > size. The number of bytes of memory read must be <= requested size. Since output variable correctly captures the number of bytes read, use that to indicate progress tick. addr0 +-------+-------+-------+-------+ ^ ^ | | start_addr start_addr + size ----|--------|-------|----| output * * * * progress tick Signed-off-by: Amitay Isaacs --- libpdbg/adu.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/libpdbg/adu.c b/libpdbg/adu.c index 9f175f8..4f2949f 100644 --- a/libpdbg/adu.c +++ b/libpdbg/adu.c @@ -100,33 +100,45 @@ int __adu_getmem(struct pdbg_target *adu_target, uint64_t start_addr, uint8_t *output, uint64_t size, bool ci) { struct adu *adu; + uint8_t *output0; int rc = 0; - uint64_t addr; + uint64_t addr0, addr; assert(!strcmp(adu_target->class, "adu")); adu = target_to_adu(adu_target); + output0 = output; + + /* Align start address to 8-byte boundary */ + addr0 = 8 * (start_addr / 8); + /* We read data in 8-byte aligned chunks */ - for (addr = 8*(start_addr / 8); addr < start_addr + size; addr += 8) { + for (addr = addr0; addr < start_addr + size; addr += 8) { uint64_t data; if (adu->getmem(adu, addr, &data, ci)) return -1; - pdbg_progress_tick(addr - start_addr, size); - /* ADU returns data in big-endian form in the register */ data = __builtin_bswap64(data); if (addr < start_addr) { - memcpy(output, ((uint8_t *) &data) + (start_addr - addr), 8 - (start_addr - addr)); - output += 8 - (start_addr - addr); + size_t offset = start_addr - addr; + size_t n = (size <= 8-offset ? size : 8-offset); + + memcpy(output, ((uint8_t *) &data) + offset, n); + output += n; } else if (addr + 8 > start_addr + size) { - memcpy(output, &data, start_addr + size - addr); + uint64_t offset = start_addr + size - addr; + + memcpy(output, &data, offset); + output += offset; } else { memcpy(output, &data, 8); output += 8; } + + pdbg_progress_tick(output - output0, size); } pdbg_progress_tick(size, size);