From patchwork Mon Mar 14 04:17:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1604901 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Rt0hi9J3; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KH3Dm4lttz9sG2 for ; Mon, 14 Mar 2022 15:18:16 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KH3Dm3bj5z30Gj for ; Mon, 14 Mar 2022 15:18:16 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Rt0hi9J3; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::434; helo=mail-pf1-x434.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Rt0hi9J3; dkim-atps=neutral Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KH3Dg376cz30Qv for ; Mon, 14 Mar 2022 15:18:11 +1100 (AEDT) Received: by mail-pf1-x434.google.com with SMTP id z16so13194589pfh.3 for ; Sun, 13 Mar 2022 21:18:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WE+5Oy8LnUjLfotIHlQ4RbVXzmfromG3EyS5MCfQ+Yc=; b=Rt0hi9J3EYAySWOzrkRz1jUoVI+CqmPso4ralFTl1Zx2hRE7iN+jzF7tcWHo5m6owH 41G7KOYUzxBJyjUd+99PqOI/rGII+ZhrBSgw4HBcJ4XMsupoMTjDYq3dUoqQIXlo1SPP 9dHY5HpAftlie0rMua9tnytYwjIuZVPN7cjjAO6925Sd4lVOTcXlwNQ4eBXWAYM+3B6t iBUpV9eT5V6GjpL/pmn+TFmDk26UO8HHxftRRMuCFsEFus3LV6R6KLhMR+4A7rjPdQfZ ZgAiaOLn1xO5/NIdDjqaRUzG7Pc7CG6flB0ryimksNZuz4lPtEN+8vnVQaNL8DGC2tQA SPSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WE+5Oy8LnUjLfotIHlQ4RbVXzmfromG3EyS5MCfQ+Yc=; b=3v+t4BT72HOP4lQBc/VQ31hVmuxMXTtNwWOX0Lg4pLirD7YlG3rLg7vupNAjkxeuqC F4FV8UwfdOvULHmlYwcrIkeY2+t+Z3Rd9gJqm/FSApFuY9gcFlC+Iu9/VabCAd/d8oJ5 vHPhWN0BI8SY136G2EHwQVmSHbGX2/tUM9hDX3pMoDxcSW0id8hh7W1842KXBjgSqDsX ckQbIR5p7Ze7yP7K1S81LMb84t6zaDF1llhWsOQYx23fHUB6aDOBirMeCwQocqzUpaIF q3BbsXxbbszui577RC8hCHNBkiCTsyQXO23E+IjAoOZwTxUz4f+0cHMsoRT0KwV9LkFO Yxrg== X-Gm-Message-State: AOAM530q4sMyEWelwgxLt34qYiztRy5Ww41I0friR3wh1TQzmvYNeGrz mu00LbQKPfUqGMzUDWzik1N6fD9AKys= X-Google-Smtp-Source: ABdhPJwy+Isgv/HgiXGiU6UV+TrZWMhhizQ8BmKMs75xiPIEXP7d5fIDCPWCqsCU4hoLogE+C+EUcw== X-Received: by 2002:a63:1c8:0:b0:380:189b:1e66 with SMTP id 191-20020a6301c8000000b00380189b1e66mr18143266pgb.71.1647231489734; Sun, 13 Mar 2022 21:18:09 -0700 (PDT) Received: from bobo.ibm.com (110-175-148-108.static.tpgi.com.au. [110.175.148.108]) by smtp.gmail.com with ESMTPSA id d16-20020a056a00245000b004f771b48736sm14283018pfj.194.2022.03.13.21.18.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Mar 2022 21:18:09 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Mon, 14 Mar 2022 14:17:34 +1000 Message-Id: <20220314041735.542867-15-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220314041735.542867-1-npiggin@gmail.com> References: <20220314041735.542867-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH 13/14] gdbserver: use read-modify-write for put_mem that is not 8-byte aligned X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 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: Nicholas Piggin Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Not all targets have memory access that can support arbitrary byte writes. Use RMW for put_mem commands that are not 8-byte aligned. This should really either be done in the target accessor, or at least an alignment capability should be exposed to the caller. But for now this will allow sbefifo mem ops to work to set breakpoints (4-byte writes). Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index a37e997..e8aab70 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -281,15 +282,15 @@ out: static void put_mem(uint64_t *stack, void *priv) { uint64_t addr, len; + uint64_t start_addr, end_addr; + uint64_t align = 8; + uint32_t *insn; uint8_t *data; + uint8_t *buf; uint8_t attn_opcode[] = {0x00, 0x00, 0x02, 0x00}; + uint8_t gdb_break_opcode[] = {0x7d, 0x82, 0x10, 0x08}; int err = 0; - if (littleendian) { - attn_opcode[1] = 0x02; - attn_opcode[2] = 0x00; - } - addr = stack[0]; len = stack[1]; data = (uint8_t *) &stack[2]; @@ -301,8 +302,7 @@ static void put_mem(uint64_t *stack, void *priv) goto out; } - - if (len == 4 && stack[2] == 0x0810827d) { + if (len == 4 && !memcmp(data, gdb_break_opcode, 4)) { /* According to linux-ppc-low.c gdb only uses this * op-code for sw break points so we replace it with * the correct attn opcode which is what we need for @@ -318,17 +318,27 @@ static void put_mem(uint64_t *stack, void *priv) err = 2; goto out; } - } else { - stack[2] = __builtin_bswap64(stack[2]) >> 32; } - PR_INFO("put_mem 0x%016" PRIx64 " = 0x%016" PRIx64 "\n", addr, stack[2]); + if (len == 4 && littleendian) { + insn = (uint32_t *)data; + *insn = bswap_32(*insn); + } - if (mem_write(adu_target, addr, data, len, 0, false)) { + start_addr = addr & ~(align - 1); + end_addr = (addr + len + (align - 1)) & ~(align - 1); + if (addr != start_addr || (addr + len) != end_addr) { + buf = malloc(end_addr - start_addr); + mem_read(adu_target, start_addr, buf, end_addr - start_addr, 0, false); + memcpy(buf + (addr - start_addr), data, len); + } else { + buf = data; + } + + if (mem_write(adu_target, start_addr, buf, end_addr - start_addr, 0, false)) { PR_ERROR("Unable to write memory\n"); err = 3; } - out: if (err) send_response(fd, ERROR(EPERM));