From patchwork Tue Mar 29 15:49:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610704 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=nwZk8zgU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYtb4MtDz9sFk for ; Wed, 30 Mar 2022 02:50:31 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtb3SC0z2y7V for ; Wed, 30 Mar 2022 02:50:31 +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=nwZk8zgU; 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::102c; helo=mail-pj1-x102c.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=nwZk8zgU; dkim-atps=neutral Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) (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 4KSYtY20JCz2yHB for ; Wed, 30 Mar 2022 02:50:29 +1100 (AEDT) Received: by mail-pj1-x102c.google.com with SMTP id gp15-20020a17090adf0f00b001c7cd11b0b3so2253144pjb.3 for ; Tue, 29 Mar 2022 08:50:29 -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=2Vs3d0+ooCHI5JNMyR7Iu3dpsUGxg8c1vpE7uKkQI/U=; b=nwZk8zgUN9vpfyM5uGVTLeoyevHUbTdOKcYtKLp2VxtU7dW3GtTKoYx0GVkAXO6krY 0b08veL/1t3zTYQJbqlRd7mPrjDuEjxvt+aBQNxEWwoPJERfBUzuPhSqjX7+MQifANRg 9nnMtxEIri/K82eGCNFiVObaqnxcDjECkeYJB9Yhpz2rBLMzTE3lzOyjNOI2X7H2/s2V O+zt0s86YSMMVXdNBlVdPkN8PconwsliHcrMaz32fq7VMpuVhOcDvR8vj7uzxelNMGSJ 1xGci2lQQ7wdjhBS2ICQSgzIQNoM7puccdGFEWMM5RV27CLFxo0/DEzRQ1XRcfm5fWhr aAYA== 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=2Vs3d0+ooCHI5JNMyR7Iu3dpsUGxg8c1vpE7uKkQI/U=; b=T5fxaksHnN1NxYws7zJRawpQhX1DCHcKZXnsQ6G9Dwo0fP1/Z55aatqz6po9JNGRkA dcjvLnH/PUgQZTmU52/fSfWdD1O93zD1EyvJdQewDEpPuWsnTPkneuw8bJM97BmlXa+E xBsIMXaTVyHizngdQ41eYrS5gsD6bNiwu2AjPu2SZ7W2ds1cg5OM5qI95P8TVbfjockg cN2cDxIxgvQxb2xETjKq1zrhRqcMBeLnMGIlYkx23KInbqt4F1oG0tfvnSZWzLETubGg sLSR4iYzfVOGfbjqi825EQxRfPMbcdYeLM/J3/6KmFkGEOS+i6WaRXtfRXL4umQVmEyJ 8wcw== X-Gm-Message-State: AOAM531HXYomIYT+5WOG+2Z6h9FSS6uSd+VIIMv/Kk5L+aDCg2Lpvpj4 yTJrW17FYsazvZLXjUyzxIz6P3y64k4= X-Google-Smtp-Source: ABdhPJzRnFWc+1Ovo1PWTovVJb9ClHx5rqkHhER5pHDQSna6O9nXieu4Bps2lZDy/QByJA386ZGWEQ== X-Received: by 2002:a17:903:18c:b0:154:9ee:ced3 with SMTP id z12-20020a170903018c00b0015409eeced3mr30962120plg.170.1648569026932; Tue, 29 Mar 2022 08:50:26 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:26 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:15 +1000 Message-Id: <20220329154931.493851-23-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 22/38] gdbserver: test endian when it is required 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" Rather than testing endian once at start-up, test it when a breakpoint is being installed. This may give a bit better chance of the correct endian being used if a processor switches endian after the gdbserver is started. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 1843517..29ba52a 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -47,7 +47,6 @@ static struct pdbg_target *adu_target; static struct timeval timeout; static int poll_interval = 100; static int fd = -1; -static int littleendian = 1; enum client_state {IDLE, SIGNAL_WAIT}; static enum client_state state = IDLE; @@ -395,11 +394,6 @@ static void put_mem(uint64_t *stack, void *priv) 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 *)(unsigned long)stack[2]; @@ -412,6 +406,19 @@ static void put_mem(uint64_t *stack, void *priv) } if (len == 4 && !memcmp(data, gdb_break_opcode, 4)) { + uint64_t msr; + + /* Check endianess in MSR */ + err = thread_getmsr(thread_target, &msr); + if (err) { + PR_ERROR("Couldn't read the MSR. Are all threads on this chiplet quiesced?\n"); + goto out; + } + if (msr & 1) { /* little endian */ + attn_opcode[1] = 0x02; + attn_opcode[2] = 0x00; + } + /* 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 @@ -419,6 +426,7 @@ static void put_mem(uint64_t *stack, void *priv) * * TODO: Upstream a patch to gdb so that it uses the * right opcode for baremetal debug. */ + PR_INFO("Breakpoint opcode detected, replacing with attn\n"); data = attn_opcode; @@ -723,8 +731,6 @@ int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_ static int gdbserver(uint16_t port) { struct pdbg_target *target, *adu, *thread = NULL; - uint64_t msr; - int rc; for_each_path_target_class("thread", target) { if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED) @@ -758,14 +764,6 @@ static int gdbserver(uint16_t port) PR_WARNING("Breakpoints may cause host crashes on POWER9 and should not be used\n"); } - /* Check endianess in MSR */ - rc = thread_getmsr(thread, &msr); - if (rc) { - PR_ERROR("Couldn't read the MSR. Are all threads on this chiplet quiesced?\n"); - return 1; - } - littleendian = 0x01 & msr; - /* Select ADU target */ pdbg_for_each_class_target("mem", adu) { if (pdbg_target_probe(adu) == PDBG_TARGET_ENABLED)