From nobody Tue Feb 10 10:03:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.53 as permitted sender) client-ip=209.85.221.53; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f53.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.53 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1621252601; cv=none; d=zohomail.com; s=zohoarc; b=OiM0mjroQS3TSbWELLpM2TprvPjT1m0vlj9QNR3Q4qjVPkq/FEmdFNa8Vny63qBR2vK8Ae208FAIjKRHmIiBEFOx5htQPKYr+Wjm7aEj6jMtdQaVbGVgICCr4GUVJ2bBK1reTArbMY1XOe235V22oLtYJP0f43g8gI/fAfhkvCc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621252601; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sd+8rlQTZ1aQWmKwzm10sDs8kTu4DF8a2ZaQBsZHL+s=; b=QfStSRW2frxl9anAs3JZaPXK5WInQdD5i1vWaYdWDlN2tOe6S7QLqe8ZdcJKhfLcPX7Y7+joheiHtG+TS7jB2ug2w7HJUeSLrGPB0LuOZwcR2E9DiUeMlNR3DlXF1tc0QShwgdDSfAqdZ7+xloO6i4m/PYnnRIbDgV+OqB6Nts0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.53 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by mx.zohomail.com with SMTPS id 1621252601368351.1868439538964; Mon, 17 May 2021 04:56:41 -0700 (PDT) Received: by mail-wr1-f53.google.com with SMTP id a4so6112862wrr.2 for ; Mon, 17 May 2021 04:56:40 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id z66sm22158561wmc.4.2021.05.17.04.56.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 04:56:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sd+8rlQTZ1aQWmKwzm10sDs8kTu4DF8a2ZaQBsZHL+s=; b=Ef65eCcW+UYXksgChEGOj7hbYMyBJyAD0mcVItG0bhbFrVCDWE6FJxqYPn9NQBtfQB aDvaN3AFxquafO9h5zyoFm7F9H3i4AhJ4HVZrz9ypjLPcPKnA6dfXPiRuZrVLuifeFZ8 cvpS83M38CKWHzipB7ns7t1svqI3jbMbifJjA3Du77akusC3lR2WUXQ6XOAB8+O2TUHK auFqH8huq0gFksLNTHrJaVS9POX/ZRoaa9EnicNBuqgaAu8cnrEwDiu3eLFeu8zd5fmC /0Rcak/mkpWlq7frlfqatsSLxdhHmsSyQr51p/YpkLqRgX4F7VPPxvPcIUDqf0bWyTr8 +l3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=sd+8rlQTZ1aQWmKwzm10sDs8kTu4DF8a2ZaQBsZHL+s=; b=Nsip0Q2ucwgbQKsdfTcnbLMCN/CVRbVMyRTNH9Kn9c/Hq0sdq/44NZSP4bW023JwdZ SfjzLX2Qr0LSY+UjauVIHmRzW+Er+kPgCRyXPR+wpvv2fwlQ1hybjU/ib1zRtK4ZWPqv FsdXqTA1X5fLTsom4OFw2WNU6pkFw8GGByXVn/dBrkd2AoV6P3wrWWAZwmU8uOic+Fw1 4LPZINfVdQ1VfYVT9g5nb+H9pZLnVh2LK45F2GuTi2JqKWO7iSz5DfFjQvOzUBX7j58k 9Y6eKA7cw3itgn9RXvoet+Zabzy5TX53E44ERH3kxzvEsRhuPLdrvjX2j3JNkp9govDI 4uUg== X-Gm-Message-State: AOAM533s2kfVE8OJzmTtG7ZE71cfRm+kWex3/4yltDjMcZOefAYNzdom HJvnGHRZ4exXUs0LqeKrvkA= X-Google-Smtp-Source: ABdhPJwQyaKdsUaWI3uJSHGdeYnG2iypDW3Iu9cqX48JnACSPkGTMnx1Fsl7uu4Qr6wgpAOXL3RE4w== X-Received: by 2002:adf:df8d:: with SMTP id z13mr30592907wrl.267.1621252599559; Mon, 17 May 2021 04:56:39 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Richard Henderson , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [RFC PATCH 14/15] softmmu/cpus: Extract QMP command handlers to cpus-qmp.c Date: Mon, 17 May 2021 13:55:24 +0200 Message-Id: <20210517115525.1088693-15-f4bug@amsat.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210517115525.1088693-1-f4bug@amsat.org> References: <20210517115525.1088693-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) qmp_memsave() and qmp_pmemsave() call cpu_memory_rw_debug() and cpu_physical_memory_read(), which are target specific prototypes. To be able to build softmmu/cpus.c once for all targets, extract the QMP commands handlers to a new file which will be built per target. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- softmmu/cpus-qmp.c | 115 ++++++++++++++++++++++++++++++++++++++++++++ softmmu/cpus.c | 89 ---------------------------------- softmmu/meson.build | 1 + 3 files changed, 116 insertions(+), 89 deletions(-) create mode 100644 softmmu/cpus-qmp.c diff --git a/softmmu/cpus-qmp.c b/softmmu/cpus-qmp.c new file mode 100644 index 00000000000..7b613028225 --- /dev/null +++ b/softmmu/cpus-qmp.c @@ -0,0 +1,115 @@ +/* + * QEMU System Emulator + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "exec/exec-all.h" +#include "qapi/error.h" +#include "qapi/qmp/qerror.h" +#include "qapi/qapi-commands-machine.h" +#include "monitor/monitor.h" +#include "hw/nmi.h" + +void qmp_memsave(int64_t addr, int64_t size, const char *filename, + bool has_cpu, int64_t cpu_index, Error **errp) +{ + FILE *f; + uint32_t l; + CPUState *cpu; + uint8_t buf[1024]; + int64_t orig_addr =3D addr, orig_size =3D size; + + if (!has_cpu) { + cpu_index =3D 0; + } + + cpu =3D qemu_get_cpu(cpu_index); + if (cpu =3D=3D NULL) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", + "a CPU number"); + return; + } + + f =3D fopen(filename, "wb"); + if (!f) { + error_setg_file_open(errp, errno, filename); + return; + } + + while (size !=3D 0) { + l =3D sizeof(buf); + if (l > size) { + l =3D size; + } + if (cpu_memory_rw_debug(cpu, addr, buf, l, 0) !=3D 0) { + error_setg(errp, "Invalid addr 0x%016" PRIx64 "/size %" PRId64 + " specified", orig_addr, orig_size); + goto exit; + } + if (fwrite(buf, 1, l, f) !=3D l) { + error_setg(errp, QERR_IO_ERROR); + goto exit; + } + addr +=3D l; + size -=3D l; + } + +exit: + fclose(f); +} + +void qmp_pmemsave(int64_t addr, int64_t size, const char *filename, + Error **errp) +{ + FILE *f; + uint32_t l; + uint8_t buf[1024]; + + f =3D fopen(filename, "wb"); + if (!f) { + error_setg_file_open(errp, errno, filename); + return; + } + + while (size !=3D 0) { + l =3D sizeof(buf); + if (l > size) { + l =3D size; + } + cpu_physical_memory_read(addr, buf, l); + if (fwrite(buf, 1, l, f) !=3D l) { + error_setg(errp, QERR_IO_ERROR); + goto exit; + } + addr +=3D l; + size -=3D l; + } + +exit: + fclose(f); +} + +void qmp_inject_nmi(Error **errp) +{ + nmi_monitor_handle(monitor_get_cpu_index(monitor_cur()), errp); +} diff --git a/softmmu/cpus.c b/softmmu/cpus.c index a7ee431187a..e3810135166 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -24,20 +24,14 @@ =20 #include "qemu/osdep.h" #include "qemu-common.h" -#include "monitor/monitor.h" #include "qapi/error.h" -#include "qapi/qapi-commands-machine.h" -#include "qapi/qapi-commands-misc.h" #include "qapi/qapi-events-run-state.h" -#include "qapi/qmp/qerror.h" #include "exec/gdbstub.h" #include "sysemu/hw_accel.h" -#include "exec/exec-all.h" #include "qemu/thread.h" #include "qemu/plugin.h" #include "sysemu/cpus.h" #include "qemu/guest-random.h" -#include "hw/nmi.h" #include "sysemu/replay.h" #include "sysemu/runstate.h" #include "sysemu/cpu-timers.h" @@ -720,86 +714,3 @@ void list_cpus(const char *optarg) cpu_list(); #endif } - -void qmp_memsave(int64_t addr, int64_t size, const char *filename, - bool has_cpu, int64_t cpu_index, Error **errp) -{ - FILE *f; - uint32_t l; - CPUState *cpu; - uint8_t buf[1024]; - int64_t orig_addr =3D addr, orig_size =3D size; - - if (!has_cpu) { - cpu_index =3D 0; - } - - cpu =3D qemu_get_cpu(cpu_index); - if (cpu =3D=3D NULL) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", - "a CPU number"); - return; - } - - f =3D fopen(filename, "wb"); - if (!f) { - error_setg_file_open(errp, errno, filename); - return; - } - - while (size !=3D 0) { - l =3D sizeof(buf); - if (l > size) - l =3D size; - if (cpu_memory_rw_debug(cpu, addr, buf, l, 0) !=3D 0) { - error_setg(errp, "Invalid addr 0x%016" PRIx64 "/size %" PRId64 - " specified", orig_addr, orig_size); - goto exit; - } - if (fwrite(buf, 1, l, f) !=3D l) { - error_setg(errp, QERR_IO_ERROR); - goto exit; - } - addr +=3D l; - size -=3D l; - } - -exit: - fclose(f); -} - -void qmp_pmemsave(int64_t addr, int64_t size, const char *filename, - Error **errp) -{ - FILE *f; - uint32_t l; - uint8_t buf[1024]; - - f =3D fopen(filename, "wb"); - if (!f) { - error_setg_file_open(errp, errno, filename); - return; - } - - while (size !=3D 0) { - l =3D sizeof(buf); - if (l > size) - l =3D size; - cpu_physical_memory_read(addr, buf, l); - if (fwrite(buf, 1, l, f) !=3D l) { - error_setg(errp, QERR_IO_ERROR); - goto exit; - } - addr +=3D l; - size -=3D l; - } - -exit: - fclose(f); -} - -void qmp_inject_nmi(Error **errp) -{ - nmi_monitor_handle(monitor_get_cpu_index(monitor_cur()), errp); -} - diff --git a/softmmu/meson.build b/softmmu/meson.build index d8e03018abf..5e578b20e6c 100644 --- a/softmmu/meson.build +++ b/softmmu/meson.build @@ -2,6 +2,7 @@ 'arch_init.c', 'balloon.c', 'cpus.c', + 'cpus-qmp.c', 'cpu-throttle.c', 'datadir.c', 'globals.c', --=20 2.26.3