From patchwork Thu Apr 3 23:49:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 877982 Delivered-To: patch@linaro.org Received: by 2002:a5d:6dae:0:b0:38f:210b:807b with SMTP id u14csp3527468wrs; Thu, 3 Apr 2025 16:51:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUY2Ft0wMhPqvTAcWrFE2EQzJOeRDI2AZIi33oiYiNpfI37xMRk25dq288zHp+ZNGbbX2jFLg==@linaro.org X-Google-Smtp-Source: AGHT+IEE0d4yEYHHLa1eiciYDsiXcarojghnVmXPyJcLchePp/MGEM+sRWm3BHSUG5lUxqfHfi57 X-Received: by 2002:a05:620a:4151:b0:7c5:46e4:47f5 with SMTP id af79cd13be357-7c774d520a1mr151387285a.20.1743724274472; Thu, 03 Apr 2025 16:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1743724274; cv=none; d=google.com; s=arc-20240605; b=d+3p4KKfRmGK58ICs2/+2OgXkP/wWWOiujI6sNN4jWpD6ZUhBKGUkeovoLkIDmtIVA crvd1+iAF0PjFuFui0iuGbdDzKJYVme702hMHDITz0a4+GGgv6hriG/QVIUXmjkD80gm 84MFHRPvQFr7lyR0szV93M5ib3O/uQy16PzcsUflxq5xcPz/YzWTfbHkZJXmlAYNYThj lTDPHXO7R8Si/o/A5K8227RYX9aBin3ye4KJzQJqkH3bYhtC7R69heVw7G1K6NYXZegK PUP0AmV8jJn/2vOTolgIP1l6md1bqP+FnPDrg6LKg/8qhihKConYaJmFA33hlk+z7U+I np7A== 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=PjLhp4LZOvkpDq4jQIYUOR+57wmLdvndO6f3N6bUc2k=; fh=ISslU+6AOAPvfm3mmMuq/p0l7xeUGlnJLjUVX+iCVao=; b=HSd+41chfr501aYwQiGgUq6MPNGYWlRfG4Pz4QW248tzv0tfDbNgJswf/+VVSUdfiC OF/BWDqz3WQ+I8s0orw4QbIQ8zGlK7e2dHc3C7Bn5dUeYLSEnT3FojpjXIiBnoKh9ViC xA0FyE8c6vNu8SUgZV5MMszjH17blI3HwstYNqkFP0HGZFL+gOBd/3EW05hlj+bw8KKY ndzQ0nq4voRpUx+80h/cPlT//7ZH9ivVXx5s2VEIiEpLwYGfHtVODEwugdD/FetPhTmN 43RZthAPQKZ7GHNDj49gi0SDnhVW2QFzzduZqUEfvC/AOBaPbwrD/wOi5Z8As8ufXntn qp2w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T3N3FYBC; 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 af79cd13be357-7c76e95ba83si221567985a.175.2025.04.03.16.51.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Apr 2025 16:51:14 -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=T3N3FYBC; 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 1u0UKq-0002Fx-4Y; Thu, 03 Apr 2025 19:51:00 -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 1u0UKS-0001lA-1q for qemu-devel@nongnu.org; Thu, 03 Apr 2025 19:50:40 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u0UKP-0000k0-Tt for qemu-devel@nongnu.org; Thu, 03 Apr 2025 19:50:35 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3913958ebf2so1047868f8f.3 for ; Thu, 03 Apr 2025 16:50:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1743724232; x=1744329032; 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=PjLhp4LZOvkpDq4jQIYUOR+57wmLdvndO6f3N6bUc2k=; b=T3N3FYBC8v8lz0bcjwSeKUBsDHTwoLHz27f4XLXoVdRrowUPEx45fyU2pYn/zyAzF9 5HyHm/Oz3xWxQE2ANMeV8fUFT3TmnZVlHUkO2EgKPT07ymJqf2EHlCcRY/T9nzgS1q9M yN2Qibn2svcG6a2SqPlmUu4mkOspU4exwQ3kvd08Pk0pxW8OAc5ESafdElU0XHwgFdWy zdVvKfDuKnsLU2WThD/5Os7Ns0qUrTVhLclbUCz923jLIR9uvg2kFzqkrKbk4XWoJG5X feiTIqk3IE1ESX3IEw/jQYhtYP34KnDLxSVkXqcSYjdluTgtN0KCkgvyrtAAaJV5gH/x GVmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743724232; x=1744329032; 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=PjLhp4LZOvkpDq4jQIYUOR+57wmLdvndO6f3N6bUc2k=; b=o21CVDmZOr928ro9xrxyOl1Khlhfe1qJTuXB5ZxAkzwSKKgxgxSDUIkjymsDGJPhMQ omcGuDuIIF6reQnIbhm3LOz/8M30V6P/nLrzL3Psy2mkCS9XOCZetyyiYX+IayObIvlk 6ql1wYEQA8geB5nBL+4l5MKuiSmtNVY+ybJjTX9IpCAwTy52n7JeVWSLZnk7eorXYpyz XAU2kXat/CjgwYKYFIsKDGJnSbLJaCjSowUiMTuFyVVZq2y4fMoiG1OeCNzBtQvcPHYz Oj33albN8MWC8zlFpgyN/7YEUa2nsXNnjUBMxk8/i9mCSmeOA+wNqgl4qDyUcXKzgvCL Dhkw== X-Gm-Message-State: AOJu0YwZH/Vm44K/tFVs+fSYI+v1iRx3s/m0DiHRQX9+a9scsGDdVpGk iUdrax0tqjSTEJHJ2pUs9akVLE+KnJyhQSmazLFqltspUzTqofM6bcRAk0G+CmtsoPCDXXKsqle a X-Gm-Gg: ASbGncui4UqnoH+eb6aHzQbtSHvvGLBU+of4o7Gf7BILOftWW2PglVukyVJ7B1gLzLE SzdnFGfjTeffxcdItm1DWZ+zlzRk4ee6RFgmMl0ly/j8p30p4kiNoD8gvHVpzyS4Fy2ShWbeQNZ 5p+Xl6LyTF+hyaInOBSqYu6hBkTkeisb+is9Zp5a7RV5gQiv2ahcxvcOx3e0d5CR/6uHkQYAmWH BO2uGXT6kiUvbUuI3aTw/1sqCg4GHTPFH4TVhACvM2CQ34BpjNJYsB02xpR53sziktfmeR23L4N XnolPrBJAjAClIMo9ZPkFwaG7z7poQLeTOQ6Y4PWkDvnhGvtZKOszSXu7JQqhqJF9it9P3dCahl o3a4hru2wlCatRWoiphM= X-Received: by 2002:a05:6000:2481:b0:39c:f0d:9146 with SMTP id ffacd0b85a97d-39cba9368b5mr855120f8f.45.1743724231967; Thu, 03 Apr 2025 16:50:31 -0700 (PDT) Received: from localhost.localdomain (184.170.88.92.rev.sfr.net. [92.88.170.184]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39c301a7225sm2963060f8f.26.2025.04.03.16.50.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 03 Apr 2025 16:50:31 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Markus Armbruster , Richard Henderson , Pierrick Bouvier Subject: [RFC PATCH-for-10.1 12/19] cpus: Move target-agnostic methods out of cpu-target.c Date: Fri, 4 Apr 2025 01:49:07 +0200 Message-ID: <20250403234914.9154-13-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250403234914.9154-1-philmd@linaro.org> References: <20250403234914.9154-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=philmd@linaro.org; helo=mail-wr1-x432.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 Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Pierrick Bouvier --- cpu-target.c | 78 +------------------------------------------- hw/core/cpu-common.c | 74 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 77 deletions(-) diff --git a/cpu-target.c b/cpu-target.c index 01b0064b91f..20db5ff3108 100644 --- a/cpu-target.c +++ b/cpu-target.c @@ -19,94 +19,18 @@ #include "qemu/osdep.h" #include "cpu.h" -#include "qapi/error.h" -#include "qemu/error-report.h" -#include "qemu/qemu-print.h" -#include "qemu/target_info.h" #include "system/accel-ops.h" #include "system/cpus.h" #include "exec/cpu-common.h" -#include "exec/tswap.h" #include "exec/replay-core.h" #include "exec/log.h" -#include "accel/accel-cpu-target.h" +#include "hw/core/cpu.h" #include "trace/trace-root.h" /* Validate correct placement of CPUArchState. */ QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0); QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState)); -char *cpu_model_from_type(const char *typename) -{ - g_autofree char *suffix = g_strdup_printf("-%s", target_cpu_type()); - - if (!object_class_by_name(typename)) { - return NULL; - } - - if (g_str_has_suffix(typename, suffix)) { - return g_strndup(typename, strlen(typename) - strlen(suffix)); - } - - return g_strdup(typename); -} - -const char *parse_cpu_option(const char *cpu_option) -{ - ObjectClass *oc; - CPUClass *cc; - gchar **model_pieces; - const char *cpu_type; - - model_pieces = g_strsplit(cpu_option, ",", 2); - if (!model_pieces[0]) { - error_report("-cpu option cannot be empty"); - exit(1); - } - - oc = cpu_class_by_name(target_cpu_type(), model_pieces[0]); - if (oc == NULL) { - error_report("unable to find CPU model '%s'", model_pieces[0]); - g_strfreev(model_pieces); - exit(EXIT_FAILURE); - } - - cpu_type = object_class_get_name(oc); - cc = CPU_CLASS(oc); - cc->parse_features(cpu_type, model_pieces[1], &error_fatal); - g_strfreev(model_pieces); - return cpu_type; -} - -static void cpu_list_entry(gpointer data, gpointer user_data) -{ - CPUClass *cc = CPU_CLASS(OBJECT_CLASS(data)); - const char *typename = object_class_get_name(OBJECT_CLASS(data)); - g_autofree char *model = cpu_model_from_type(typename); - - if (cc->deprecation_note) { - qemu_printf(" %s (deprecated)\n", model); - } else { - qemu_printf(" %s\n", model); - } -} - -void list_cpus(void) -{ - CPUClass *cc = CPU_CLASS(object_class_by_name(target_cpu_type())); - - if (cc->list_cpus) { - cc->list_cpus(); - } else { - GSList *list; - - list = object_class_get_list_sorted(TYPE_CPU, false); - qemu_printf("Available CPUs:\n"); - g_slist_foreach(list, cpu_list_entry, NULL); - g_slist_free(list); - } -} - /* enable or disable single step mode. EXCP_DEBUG is returned by the CPU loop after each instruction */ void cpu_single_step(CPUState *cpu, int enabled) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 9064dd24f82..6d0788331c7 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -25,6 +25,9 @@ #include "qemu/log.h" #include "qemu/main-loop.h" #include "qemu/lockcnt.h" +#include "qemu/error-report.h" +#include "qemu/qemu-print.h" +#include "qemu/target_info.h" #include "exec/log.h" #include "exec/gdbstub.h" #include "system/tcg.h" @@ -152,6 +155,21 @@ ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model) return NULL; } +char *cpu_model_from_type(const char *typename) +{ + g_autofree char *suffix = g_strdup_printf("-%s", target_cpu_type()); + + if (!object_class_by_name(typename)) { + return NULL; + } + + if (g_str_has_suffix(typename, suffix)) { + return g_strndup(typename, strlen(typename) - strlen(suffix)); + } + + return g_strdup(typename); +} + static void cpu_common_parse_features(const char *typename, char *features, Error **errp) { @@ -183,6 +201,33 @@ static void cpu_common_parse_features(const char *typename, char *features, } } +const char *parse_cpu_option(const char *cpu_option) +{ + ObjectClass *oc; + CPUClass *cc; + gchar **model_pieces; + const char *cpu_type; + + model_pieces = g_strsplit(cpu_option, ",", 2); + if (!model_pieces[0]) { + error_report("-cpu option cannot be empty"); + exit(1); + } + + oc = cpu_class_by_name(target_cpu_type(), model_pieces[0]); + if (oc == NULL) { + error_report("unable to find CPU model '%s'", model_pieces[0]); + g_strfreev(model_pieces); + exit(EXIT_FAILURE); + } + + cpu_type = object_class_get_name(oc); + cc = CPU_CLASS(oc); + cc->parse_features(cpu_type, model_pieces[1], &error_fatal); + g_strfreev(model_pieces); + return cpu_type; +} + bool cpu_exec_realizefn(CPUState *cpu, Error **errp) { if (!accel_cpu_common_realize(cpu, errp)) { @@ -359,3 +404,32 @@ static void cpu_register_types(void) } type_init(cpu_register_types) + +static void cpu_list_entry(gpointer data, gpointer user_data) +{ + CPUClass *cc = CPU_CLASS(OBJECT_CLASS(data)); + const char *typename = object_class_get_name(OBJECT_CLASS(data)); + g_autofree char *model = cpu_model_from_type(typename); + + if (cc->deprecation_note) { + qemu_printf(" %s (deprecated)\n", model); + } else { + qemu_printf(" %s\n", model); + } +} + +void list_cpus(void) +{ + CPUClass *cc = CPU_CLASS(object_class_by_name(target_cpu_type())); + + if (cc->list_cpus) { + cc->list_cpus(); + } else { + GSList *list; + + list = object_class_get_list_sorted(TYPE_CPU, false); + qemu_printf("Available CPUs:\n"); + g_slist_foreach(list, cpu_list_entry, NULL); + g_slist_free(list); + } +}