From patchwork Wed Apr 20 06:49:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619350 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=IjJ7uBP3; 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 4KjrtL1gKGz9sG0 for ; Wed, 20 Apr 2022 16:51:22 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtL0Fp4z301s for ; Wed, 20 Apr 2022 16:51:22 +1000 (AEST) 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=IjJ7uBP3; 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::1033; helo=mail-pj1-x1033.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=IjJ7uBP3; dkim-atps=neutral Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) (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 4KjrtJ3SmYz2xmQ for ; Wed, 20 Apr 2022 16:51:20 +1000 (AEST) Received: by mail-pj1-x1033.google.com with SMTP id md20-20020a17090b23d400b001cb70ef790dso4133105pjb.5 for ; Tue, 19 Apr 2022 23:51:20 -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=K49LXvLNHXhkBntNkST5z/kJam4sc9snCqXnda0c+l8=; b=IjJ7uBP3+WSsvxWOZg0UWCczXSba9l4PEp9rfq9blyA1Z0SzqKXP/Vepx/b/o5STII IcczDRn5HH2xye6/UBWn3sLLSKjvYINFqUfIIbk+mIVYS91iAMcz5WXMHTkbq0knp3K/ pHAkJvqc7XbQ4DAwR/zP49AyhqqKPdJIHsxPLQ0Y+gfcVFc5xt9MnERv/fHIzgvId5od BTmOVC5xvMBa0Pap1OQfG7JjHPDLriRnuR9+0Fi10gganuTELPgPH3pvnb/QYKVNZOt5 kUKF7IpugsLITKJ1E2ykFPoH8DVxlILzQxZ/RrEtq6Mekag/t25y8i9L5Ye3CzDU6f2B b72w== 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=K49LXvLNHXhkBntNkST5z/kJam4sc9snCqXnda0c+l8=; b=lO8YiVGYHDOPpei7PS/bnLH4MlsJUhMtk6D3W8dK7VkeIX4g/ZNvaRhx4ia+h/FvDj xsYhhUwiZJ4Ri2d5FmPq28GOCMPO1ROvusbxA64PlsYY7GW2j9Uf7HoswWMPp7+VFW9F dAW3tpFZT/tgG8k/DPYh4pO7DdVZU3nflU76VyWV4c2AlMF+DIi30gzo6JULiiorIEJR KCRYxOxbsnJQfg+2imD+SyCNhJ0DvSKzo/4JTMNuvS0ndJyBdyD5pmmGiZS30VOYCjFk m1Ctz/peYyXNYpCokATcE7/6uvUWGT0H0WaM7HYSblTF4Uqu8EzOQel4lgumuEx/2+1c UQxg== X-Gm-Message-State: AOAM53133MPUYM9iVDEuTINbnWZSkf7ZVYIoKQyAy51cB6MnEcE5erby pI4qNA+6oErQehX29sqELPdafRdAxcdBng== X-Google-Smtp-Source: ABdhPJy4IROdywEj6/XqWWpsOZuIP6gKeBVXEBMOkt9CGRLxvwLA2DQkOhJjgPynxibT7VaUAdYIpw== X-Received: by 2002:a17:90b:38c4:b0:1d2:66cf:568f with SMTP id nn4-20020a17090b38c400b001d266cf568fmr2770706pjb.18.1650437478728; Tue, 19 Apr 2022 23:51:18 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:18 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:57 +1000 Message-Id: <20220420065013.222816-24-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 23/39] gdbserver: breakpoint instruction test current host 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, because a processor can switch endian asynchronously and at any time (e.g., after the gdbserver has started). We don't support endian-agnostic breakpoints unfortunately because bswap32(attn) is an illegal instruction. Signed-off-by: Nicholas Piggin Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index d7ceac8d..4572c689 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"); memcpy(data, attn_opcode, 4); @@ -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)