From patchwork Sun Oct 13 22:12:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 835101 Delivered-To: patch@linaro.org Received: by 2002:adf:b352:0:b0:37d:45d0:187 with SMTP id k18csp1735483wrd; Sun, 13 Oct 2024 15:16:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW9tvf8UQL/DuDQRh+WJxRTP1FK7jZGmL5mXD4PbDvNW57cr86ZTX3lU1UXdExanZmLbao1dw==@linaro.org X-Google-Smtp-Source: AGHT+IH9Trf934cbkKM7FTcSE1yOzkCefWluxD4Y1F2pGpEgBaTEWGe44M9t6yFnZiJv6WQ5gFRF X-Received: by 2002:ac8:7d0a:0:b0:45d:79af:430c with SMTP id d75a77b69052e-4604bbcf76fmr128820691cf.28.1728857777273; Sun, 13 Oct 2024 15:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728857777; cv=none; d=google.com; s=arc-20240605; b=gl47DvS22IeOLscBTR2DVhr9sRZ7efj6ppMQdyh6QbwlTagrgHmYL1m3W/WjHKC4/+ GQz/jxaesN7lMCzzE6xtMIYSHY42779CU1LbxJSEGjjXiCH/7RfmV6wUgI/lVHvrIXYL KQMuQeQyls4fTllz95Ug0Tv7a8U3AP/B7yNYF8zXbxd01SnIqn/TX7spBiuQTX84xGVu al8Na7sreW1j8+BVgEcsoWQCpdPlsMgl391HyluS1bJFVTvq61JfrWk8+3Iq63vofOUv HlUX9qxAYH/k8UgF1y0HldQcQlcQqRw29mnxHvwdCOJbQCpXetaD9PbJS53u4zMDVll7 7xyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HvIjzJygM9GXaQbwvZ4DDVniWBW4y8rSWWHM++5r4d8=; fh=o2XzhdKG+B45MJCghEfnYoypmHvLX2hd4SL6yXeiyXI=; b=PopB7t7a2eLQSyZc8A2kFkne1Hp+CQ0UoAnh41QOl4zqz1eLjAFw15IxvYwAucVZVS Xno/9e1RzmwF6/C9WDfcXmXI4uGiQe7mTCA7yxImJEaHaZjSFWSR+jldZxPfN+jm9kJ6 eh/yDWOGa0IHM8XLLbaRcMDx9QQlr9v9H6KIGKn+IHo1ouZz5ms3aFy89OWxPpDVmsYr c7gP1KeiyeGPlT8MZ1scdGPtBULNdYnHzZRZZaBWTJZkawiTDXyPijCsTbxh7qiMoIta aXIsxFCr+8RdpshKTKf+FAcSBdQYadqENox0lCVbXnVaXbMqZ0F9wBIaCAGM6BgCXx+i 8eQA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MCSbN0vG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-460427f8837si89321141cf.176.2024.10.13.15.16.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Oct 2024 15:16:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MCSbN0vG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t06pQ-00077U-Gw; Sun, 13 Oct 2024 18:12:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t06pP-00076X-4W for qemu-devel@nongnu.org; Sun, 13 Oct 2024 18:12:43 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t06pN-0000ti-D4 for qemu-devel@nongnu.org; Sun, 13 Oct 2024 18:12:42 -0400 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2e30fb8cb07so1074818a91.3 for ; Sun, 13 Oct 2024 15:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728857560; x=1729462360; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HvIjzJygM9GXaQbwvZ4DDVniWBW4y8rSWWHM++5r4d8=; b=MCSbN0vGBpp39O4DbjSYZpKBpDQcdIUxsB8piL2aUmJt+Jn1qfzgSUYmP+I3QFWS2H R9n0o2U0Ll5buFKCAQJVSzYu+JGc6OMjHUp0Sw2haxOw8qysQ4cv7I06Yrvf7deHqDyf dptfoCo/yh3Ip+7KaCQFM7Hb59WWIHB3Eu4vh/vPsTXEVLe6w/3kChO7o9jOSAiJkY6T 0/sQ1qjnpMYBGbiDyv8f9Vkb9/L+Pq4Sfw0T6ECpI7J9V8g0EOaHQbYFlW9z3bRgw59c Q2Y/43zHQ1Uo9t2YrsYSXq6xIyg3DnbcUMiWp57D+SNWt0WWtVNc6zt112bR0cESv5i0 ieuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728857560; x=1729462360; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HvIjzJygM9GXaQbwvZ4DDVniWBW4y8rSWWHM++5r4d8=; b=T2vGjS5b4smum3S0AEXwFxTpyXkvALM638hotJycYccVlb5P2avR560d4EJGcOKDa7 5zcXTVm5k4ZFoQWKGrJEotMi/OA9QorFm90u00YW48rXJJqRgukXD0t+JnrN7BaldED1 bWugWmjK5t/dSmRDnfQl5fmroFwX2yrDjopcbhsdhfWvvcfFBpGdpMkJaUQMOQAy0ZsD cDvIExnIXDmbS77bGg5FluPOTIPDi2PRYt0JYwwxIZ1xoFqzNpN3Dc6WyhgGCD1jZnfl lfy9FFzoaOqiFxe4YrNCjUyregCayaVUEbMjV5AA1vMxKspG6ehNSinaUW5bhL4Cw2gN mJZg== X-Gm-Message-State: AOJu0Yy85TmEGkgMGEmfaaOBaGsjEYOqIzqyrgVIUq0SjoGN2TZ4uR5B UnZpa+qlDmVDeyo6W0pi2Hujb/joKKyc+DqbOInsnslfrH6ryueS+G6uCQZTz9+wHHOXyZdsR4l i X-Received: by 2002:a17:90a:67c6:b0:2e0:f896:b806 with SMTP id 98e67ed59e1d1-2e2f0d7aa36mr12236464a91.27.1728857560094; Sun, 13 Oct 2024 15:12:40 -0700 (PDT) Received: from stoup.. (174-21-81-121.tukw.qwest.net. [174.21.81.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e2d5df1eebsm7271958a91.17.2024.10.13.15.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2024 15:12:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich Subject: [PULL 04/27] target/i386/gdbstub: Factor out gdb_get_reg() and gdb_write_reg() Date: Sun, 13 Oct 2024 15:12:12 -0700 Message-ID: <20241013221235.1585193-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241013221235.1585193-1-richard.henderson@linaro.org> References: <20241013221235.1585193-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Ilya Leoshkevich i386 gdbstub handles both i386 and x86_64. Factor out two functions for reading and writing registers without knowing their bitness. While at it, simplify the TARGET_LONG_BITS == 32 case. Reviewed-by: Richard Henderson Signed-off-by: Ilya Leoshkevich Message-ID: <20240912093012.402366-4-iii@linux.ibm.com> Signed-off-by: Richard Henderson --- target/i386/gdbstub.c | 51 +++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c index 4acf485879..cc5eceeb7e 100644 --- a/target/i386/gdbstub.c +++ b/target/i386/gdbstub.c @@ -96,6 +96,19 @@ static int gdb_write_reg_cs64(uint32_t hflags, uint8_t *buf, target_ulong *val) return 4; } +static int gdb_get_reg(CPUX86State *env, GByteArray *mem_buf, target_ulong val) +{ + if (TARGET_LONG_BITS == 64) { + if (env->hflags & HF_CS64_MASK) { + return gdb_get_reg64(mem_buf, val); + } else { + return gdb_get_reg64(mem_buf, val & 0xffffffffUL); + } + } else { + return gdb_get_reg32(mem_buf, val); + } +} + int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { X86CPU *cpu = X86_CPU(cs); @@ -137,15 +150,7 @@ int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) } else { switch (n) { case IDX_IP_REG: - if (TARGET_LONG_BITS == 64) { - if (env->hflags & HF_CS64_MASK) { - return gdb_get_reg64(mem_buf, env->eip); - } else { - return gdb_get_reg64(mem_buf, env->eip & 0xffffffffUL); - } - } else { - return gdb_get_reg32(mem_buf, env->eip); - } + return gdb_get_reg(env, mem_buf, env->eip); case IDX_FLAGS_REG: return gdb_get_reg32(mem_buf, env->eflags); @@ -248,6 +253,21 @@ static int x86_cpu_gdb_load_seg(X86CPU *cpu, X86Seg sreg, uint8_t *mem_buf) return 4; } +static int gdb_write_reg(CPUX86State *env, uint8_t *mem_buf, target_ulong *val) +{ + if (TARGET_LONG_BITS == 64) { + if (env->hflags & HF_CS64_MASK) { + *val = ldq_p(mem_buf); + } else { + *val = ldq_p(mem_buf) & 0xffffffffUL; + } + return 8; + } else { + *val = (uint32_t)ldl_p(mem_buf); + return 4; + } +} + int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) { X86CPU *cpu = X86_CPU(cs); @@ -288,18 +308,7 @@ int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) } else { switch (n) { case IDX_IP_REG: - if (TARGET_LONG_BITS == 64) { - if (env->hflags & HF_CS64_MASK) { - env->eip = ldq_p(mem_buf); - } else { - env->eip = ldq_p(mem_buf) & 0xffffffffUL; - } - return 8; - } else { - env->eip &= ~0xffffffffUL; - env->eip |= (uint32_t)ldl_p(mem_buf); - return 4; - } + return gdb_write_reg(env, mem_buf, &env->eip); case IDX_FLAGS_REG: env->eflags = ldl_p(mem_buf); return 4;