Skip to contentSkip to conversation

Rust, i386 changes for 2026-01-27

GIT PULL Applied Paolo Bonzini 2 participants 15 messages Jan 27 – Jan 28

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

The following changes since commit f26976b9d30496d28bd4fd045f4300706e567a29:

Merge tag 'pull-vfio-20260126' of https://github.com/legoater/qemu into staging (2026-01-27 07:14:11 +1100)

are available in the Git repository at:

https://gitlab.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to df8dfc3b6080713c2dbd7ef37c2c85a78e502cd6:

rust/hpet: remove stale TODO comment (2026-01-27 10:37:11 +0100)

----------------------------------------------------------------
* rust: move binding generation to bindings/
* rust: fixes for Windows
* target/i386/tcg: fix a few instructions that do not support VEX.L=1
* target/i386/tcg: various cleanups

----------------------------------------------------------------
Marc-André Lureau (1):
rust: move binding generation to bindings/

Mohd Kashif Khan (1):
rust/hpet: remove stale TODO comment

Paolo Bonzini (11):
rust: trace: libc does not have syslog on windows
rust: hwcore: add chardev symbols to integration tests
rust: move class_init to an extension trait
rust: move hwcore::sysbus to system crate
qdev: add hw/core/gpio.c to libhwcore
target/i386/tcg: fix a few instructions that do not support VEX.L=1 target/i386/tcg: fix typo in dpps/dppd instructions target/i386/tcg: remove dead constants
target/i386/tcg: merge decode_modrm and decode_modrm_address split target/i386/tcg: replace havesib variable with the SIB byte itself target/i386/tcg: cleanup #ifdef TARGET_X86_64

 docs/devel/rust.rst                                |  57 +++++++
 meson.build                                        |   3 +-
 rust/bindings/chardev-sys/wrapper.h                |  12 ++
 rust/bindings/hwcore-sys/wrapper.h                 |  30 ++++
 rust/bindings/migration-sys/wrapper.h              |  10 ++
 rust/bindings/qom-sys/wrapper.h                    |  17 +++
 rust/bindings/system-sys/wrapper.h                 |  21 +++
 rust/bindings/util-sys/wrapper.h                   |  39 +++++
 rust/bql/wrapper.h                                 |  27 ----
 rust/chardev/wrapper.h                             |  28 ----
 rust/hw/core/wrapper.h                             |  32 ----
 rust/migration/wrapper.h                           |  51 -------
 rust/qom/wrapper.h                                 |  27 ----
 rust/system/wrapper.h                              |  29 ----
 rust/util/wrapper.h                                |  32 ----
 target/i386/tcg/translate.c                        |  35 +----
 target/i386/tcg/decode-new.c.inc                   |  85 +++++------
 target/i386/tcg/emit.c.inc                         |  22 ++-
 hw/core/meson.build                                |   2 +-
 rust/Cargo.lock                                    |  68 +++++++++
 rust/{util => bindings}/build.rs                   |  30 ++--
 rust/bindings/chardev-sys/Cargo.toml               |  28 ++++
 rust/bindings/chardev-sys/build.rs                 |   1 +
 .../bindings.rs => bindings/chardev-sys/lib.rs}    |   7 +-
 rust/bindings/chardev-sys/meson.build              |  12 ++
 rust/bindings/generate_bindgen_args.py             | 164 +++++++++++++++++++++
 rust/bindings/hwcore-sys/Cargo.toml                |  32 ++++
 rust/bindings/hwcore-sys/build.rs                  |   1 +
 .../src/bindings.rs => bindings/hwcore-sys/lib.rs} |  17 +--
 rust/bindings/hwcore-sys/meson.build               |  12 ++
 rust/bindings/meson.build                          |  37 +++++
 rust/bindings/migration-sys/Cargo.toml             |  28 ++++
 rust/bindings/migration-sys/build.rs               |   1 +
 rust/bindings/migration-sys/lib.rs                 | 125 ++++++++++++++++
 rust/bindings/migration-sys/meson.build            |  12 ++
 rust/bindings/qom-sys/Cargo.toml                   |  25 ++++
 rust/bindings/qom-sys/build.rs                     |   1 +
 .../src/bindings.rs => bindings/qom-sys/lib.rs}    |   4 +
 rust/bindings/qom-sys/meson.build                  |  12 ++
 rust/bindings/system-sys/Cargo.toml                |  30 ++++
 rust/bindings/system-sys/build.rs                  |   1 +
 .../src/bindings.rs => bindings/system-sys/lib.rs} |   4 +-
 rust/bindings/system-sys/meson.build               |  12 ++
 rust/bindings/util-sys/Cargo.toml                  |  25 ++++
 rust/bindings/util-sys/build.rs                    |   1 +
 .../src/bindings.rs => bindings/util-sys/lib.rs}   |   2 +-
 rust/bindings/util-sys/meson.build                 |  12 ++
 rust/bql/Cargo.toml                                |   1 +
 rust/bql/build.rs                                  |   1 -
 rust/bql/meson.build                               |  30 +---
 rust/bql/src/bindings.rs                           |  27 ----
 rust/bql/src/lib.rs                                |   3 +-
 rust/chardev/Cargo.toml                            |   1 +
 rust/chardev/build.rs                              |   1 -
 rust/chardev/meson.build                           |  37 +----
 rust/chardev/src/lib.rs                            |   2 +-
 rust/hw/char/pl011/build.rs                        |   2 +-
 rust/hw/char/pl011/meson.build                     |  21 +--
 rust/hw/char/pl011/src/bindings.rs                 |   7 +-
 rust/hw/core/Cargo.toml                            |   2 +-
 rust/hw/core/build.rs                              |   1 -
 rust/hw/core/meson.build                           |  64 +-------
 rust/hw/core/src/irq.rs                            |   8 +-
 rust/hw/core/src/lib.rs                            |   6 +-
 rust/hw/core/src/prelude.rs                        |   6 +-
 rust/hw/core/src/qdev.rs                           |  31 ++--
 rust/hw/core/tests/tests.rs                        |   4 +-
 rust/hw/timer/hpet/src/device.rs                   |   1 -
 rust/meson.build                                   |   3 +-
 rust/migration/Cargo.toml                          |   1 +
 rust/migration/build.rs                            |   1 -
 rust/migration/meson.build                         |  40 +----
 rust/migration/src/bindings.rs                     |  49 ------
 rust/migration/src/lib.rs                          |   3 +-
 rust/migration/src/vmstate.rs                      |  73 ---------
 rust/qom/Cargo.toml                                |   1 +
 rust/qom/build.rs                                  |   1 -
 rust/qom/meson.build                               |  29 +---
 rust/qom/src/lib.rs                                |   3 +-
 rust/qom/src/prelude.rs                            |   1 +
 rust/qom/src/qom.rs                                |   8 +-
 rust/system/Cargo.toml                             |   4 +
 rust/system/build.rs                               |   1 -
 rust/system/meson.build                            |  39 +----
 rust/system/src/lib.rs                             |   5 +-
 rust/system/src/memory.rs                          |   2 +-
 rust/system/src/prelude.rs                         |   5 +
 rust/{hw/core => system}/src/sysbus.rs             |  36 ++---
 rust/trace/src/lib.rs                              |   1 +
 rust/util/Cargo.toml                               |   1 +
 rust/util/meson.build                              |  42 +-----
 rust/util/src/lib.rs                               |   3 +-
 92 files changed, 1025 insertions(+), 846 deletions(-)
 create mode 100644 rust/bindings/chardev-sys/wrapper.h
 create mode 100644 rust/bindings/hwcore-sys/wrapper.h
 create mode 100644 rust/bindings/migration-sys/wrapper.h
 create mode 100644 rust/bindings/qom-sys/wrapper.h
 create mode 100644 rust/bindings/system-sys/wrapper.h
 create mode 100644 rust/bindings/util-sys/wrapper.h
 delete mode 100644 rust/bql/wrapper.h
 delete mode 100644 rust/chardev/wrapper.h
 delete mode 100644 rust/hw/core/wrapper.h
 delete mode 100644 rust/migration/wrapper.h
 delete mode 100644 rust/qom/wrapper.h
 delete mode 100644 rust/system/wrapper.h
 delete mode 100644 rust/util/wrapper.h
 rename rust/{util => bindings}/build.rs (55%)
 create mode 100644 rust/bindings/chardev-sys/Cargo.toml
 create mode 120000 rust/bindings/chardev-sys/build.rs
 rename rust/{chardev/src/bindings.rs => bindings/chardev-sys/lib.rs} (84%)
 create mode 100644 rust/bindings/chardev-sys/meson.build
 create mode 100644 rust/bindings/generate_bindgen_args.py
 create mode 100644 rust/bindings/hwcore-sys/Cargo.toml
 create mode 120000 rust/bindings/hwcore-sys/build.rs
 rename rust/{hw/core/src/bindings.rs => bindings/hwcore-sys/lib.rs} (71%)
 create mode 100644 rust/bindings/hwcore-sys/meson.build
 create mode 100644 rust/bindings/meson.build
 create mode 100644 rust/bindings/migration-sys/Cargo.toml
 create mode 120000 rust/bindings/migration-sys/build.rs
 create mode 100644 rust/bindings/migration-sys/lib.rs
 create mode 100644 rust/bindings/migration-sys/meson.build
 create mode 100644 rust/bindings/qom-sys/Cargo.toml
 create mode 120000 rust/bindings/qom-sys/build.rs
 rename rust/{qom/src/bindings.rs => bindings/qom-sys/lib.rs} (85%)
 create mode 100644 rust/bindings/qom-sys/meson.build
 create mode 100644 rust/bindings/system-sys/Cargo.toml
 create mode 120000 rust/bindings/system-sys/build.rs
 rename rust/{system/src/bindings.rs => bindings/system-sys/lib.rs} (88%)
 create mode 100644 rust/bindings/system-sys/meson.build
 create mode 100644 rust/bindings/util-sys/Cargo.toml
 create mode 120000 rust/bindings/util-sys/build.rs
 rename rust/{util/src/bindings.rs => bindings/util-sys/lib.rs} (88%)
 create mode 100644 rust/bindings/util-sys/meson.build
 delete mode 120000 rust/bql/build.rs
 delete mode 100644 rust/bql/src/bindings.rs
 delete mode 120000 rust/chardev/build.rs
 delete mode 120000 rust/hw/core/build.rs
 delete mode 120000 rust/migration/build.rs
 delete mode 100644 rust/migration/src/bindings.rs
 delete mode 120000 rust/qom/build.rs
 delete mode 120000 rust/system/build.rs
 rename rust/{hw/core => system}/src/sysbus.rs (76%)
Signature · 1 line
2.52.0
#1 lore raw

[PULL 02/13] rust: hwcore: add chardev symbols to integration tests

Even though they are not used, rustc does not elide its symbols on msys2. This causes a linker error.

---
 rust/hw/core/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/hw/core/meson.build +1 -1
index fa1765a2302..942ee9cdacf 100644
@@ -73,7 +73,7 @@ test('rust-hwcore-rs-integration',
         override_options: ['rust_std=2021', 'build.rust_std=2021'],
         rust_args: ['--test'],
         install: false,
-        dependencies: [common_rs, hwcore_rs, bql_rs, migration_rs, util_rs]),
+        dependencies: [chardev_rs, common_rs, hwcore_rs, bql_rs, migration_rs, util_rs]),
     args: [
         '--test', '--test-threads', '1',
         '--format', 'pretty',
Signature · 1 line
2.52.0
#2 lore raw

[PULL 11/13] target/i386/tcg: replace havesib variable with the SIB byte itself

In reply to Paolo Bonzini
---
 target/i386/tcg/decode-new.c.inc | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
target/i386/tcg/decode-new.c.inc +6 -7
index 662d1d707d0..086a3bcec18 100644
@@ -2015,7 +2015,7 @@ static void decode_modrm(DisasContext *s, CPUX86State *env,
     int mod = (modrm >> 6) & 3;
     int rm = modrm & 7;
     bool is_vsib = decode->e.vex_class == 12;
-    bool havesib = false;
+    int sib = -1;
 
     if (mod == 3) {
         op->n = rm;
@@ -2036,14 +2036,13 @@ static void decode_modrm(DisasContext *s, CPUX86State *env,
     case MO_64:
     case MO_32:
         if (rm == 4) {
-            int code = x86_ldub_code(env, s);
-            scale = (code >> 6) & 3;
-            index = ((code >> 3) & 7) | REX_X(s);
+            sib = x86_ldub_code(env, s);
+            scale = (sib >> 6) & 3;
+            index = ((sib >> 3) & 7) | REX_X(s);
             if (index == 4 && !is_vsib) {
                 index = -1;  /* no index */
             }
-            base = (code & 7) | REX_B(s);
-            havesib = true;
+            base = (sib & 7) | REX_B(s);
         }
 
         switch (mod) {
@@ -2051,7 +2050,7 @@ static void decode_modrm(DisasContext *s, CPUX86State *env,
             if ((base & 7) == 5) {
                 base = -1;
                 disp = (int32_t)x86_ldl_code(env, s);
-                if (CODE64(s) && !havesib) {
+                if (CODE64(s) && sib == -1) {
                     base = -2;
                     disp += s->pc + s->rip_offset;
                 }
Signature · 1 line
2.52.0
#3 lore raw

[PULL 04/13] rust: move binding generation to bindings/

In reply to Paolo Bonzini

From: Marc-André Lureau <[email protected]>

Move raw FFI bindings generation to separate crates. This makes it possible to reuse bindgen declarations for a header file in its dependencies (this was not the case before this change), while keeping multiple -sys crates to avoid rebuilding all the code whenever something changes.

Because the -sys crates are generated in dependency order, this also enforces that the crates are organized in something that resembles the dependencies between C headers.

The meson.build for rust-safe crates becomes simpler, and it should be possible in the future to let Meson's cargo support handle most of it.

[General cleanup and Python script. - Paolo]
---
 docs/devel/rust.rst                           |  57 ++++++
 meson.build                                   |   3 +-
 rust/bindings/chardev-sys/wrapper.h           |  12 ++
 rust/bindings/hwcore-sys/wrapper.h            |  30 ++++
 rust/bindings/migration-sys/wrapper.h         |  10 ++
 rust/bindings/qom-sys/wrapper.h               |  17 ++
 rust/bindings/system-sys/wrapper.h            |  21 +++
 rust/bindings/util-sys/wrapper.h              |  39 +++++
 rust/bql/wrapper.h                            |  27 ---
 rust/chardev/wrapper.h                        |  28 ---
 rust/hw/core/wrapper.h                        |  32 ----
 rust/migration/wrapper.h                      |  51 ------
 rust/qom/wrapper.h                            |  27 ---
 rust/system/wrapper.h                         |  29 ----
 rust/util/wrapper.h                           |  32 ----
 rust/Cargo.lock                               |  68 ++++++++
 rust/{util => bindings}/build.rs              |  30 ++--
 rust/bindings/chardev-sys/Cargo.toml          |  28 +++
 rust/bindings/chardev-sys/build.rs            |   1 +
 .../chardev-sys/lib.rs}                       |   7 +-
 rust/bindings/chardev-sys/meson.build         |  12 ++
 rust/bindings/generate_bindgen_args.py        | 164 ++++++++++++++++++
 rust/bindings/hwcore-sys/Cargo.toml           |  32 ++++
 rust/bindings/hwcore-sys/build.rs             |   1 +
 .../hwcore-sys/lib.rs}                        |  17 +-
 rust/bindings/hwcore-sys/meson.build          |  12 ++
 rust/bindings/meson.build                     |  37 ++++
 rust/bindings/migration-sys/Cargo.toml        |  28 +++
 rust/bindings/migration-sys/build.rs          |   1 +
 rust/bindings/migration-sys/lib.rs            | 125 +++++++++++++
 rust/bindings/migration-sys/meson.build       |  12 ++
 rust/bindings/qom-sys/Cargo.toml              |  25 +++
 rust/bindings/qom-sys/build.rs                |   1 +
 .../bindings.rs => bindings/qom-sys/lib.rs}   |   4 +
 rust/bindings/qom-sys/meson.build             |  12 ++
 rust/bindings/system-sys/Cargo.toml           |  30 ++++
 rust/bindings/system-sys/build.rs             |   1 +
 .../system-sys/lib.rs}                        |   4 +-
 rust/bindings/system-sys/meson.build          |  12 ++
 rust/bindings/util-sys/Cargo.toml             |  25 +++
 rust/bindings/util-sys/build.rs               |   1 +
 .../bindings.rs => bindings/util-sys/lib.rs}  |   2 +-
 rust/bindings/util-sys/meson.build            |  12 ++
 rust/bql/Cargo.toml                           |   1 +
 rust/bql/build.rs                             |   1 -
 rust/bql/meson.build                          |  30 +---
 rust/bql/src/bindings.rs                      |  27 ---
 rust/bql/src/lib.rs                           |   3 +-
 rust/chardev/Cargo.toml                       |   1 +
 rust/chardev/build.rs                         |   1 -
 rust/chardev/meson.build                      |  37 +---
 rust/chardev/src/lib.rs                       |   2 +-
 rust/hw/char/pl011/build.rs                   |   2 +-
 rust/hw/char/pl011/meson.build                |  21 +--
 rust/hw/char/pl011/src/bindings.rs            |   7 +-
 rust/hw/core/Cargo.toml                       |   1 +
 rust/hw/core/build.rs                         |   1 -
 rust/hw/core/meson.build                      |  60 +------
 rust/hw/core/src/lib.rs                       |   3 +-
 rust/hw/core/src/qdev.rs                      |   6 +-
 rust/hw/core/src/sysbus.rs                    |  21 ++-
 rust/meson.build                              |   1 +
 rust/migration/Cargo.toml                     |   1 +
 rust/migration/build.rs                       |   1 -
 rust/migration/meson.build                    |  40 +----
 rust/migration/src/bindings.rs                |  49 ------
 rust/migration/src/lib.rs                     |   3 +-
 rust/migration/src/vmstate.rs                 |  73 --------
 rust/qom/Cargo.toml                           |   1 +
 rust/qom/build.rs                             |   1 -
 rust/qom/meson.build                          |  29 +---
 rust/qom/src/lib.rs                           |   3 +-
 rust/system/Cargo.toml                        |   3 +
 rust/system/build.rs                          |   1 -
 rust/system/meson.build                       |  37 +---
 rust/system/src/lib.rs                        |   2 +-
 rust/system/src/memory.rs                     |   2 +-
 rust/util/Cargo.toml                          |   1 +
 rust/util/meson.build                         |  42 +----
 rust/util/src/lib.rs                          |   3 +-
 80 files changed, 918 insertions(+), 719 deletions(-)
 create mode 100644 rust/bindings/chardev-sys/wrapper.h
 create mode 100644 rust/bindings/hwcore-sys/wrapper.h
 create mode 100644 rust/bindings/migration-sys/wrapper.h
 create mode 100644 rust/bindings/qom-sys/wrapper.h
 create mode 100644 rust/bindings/system-sys/wrapper.h
 create mode 100644 rust/bindings/util-sys/wrapper.h
 delete mode 100644 rust/bql/wrapper.h
 delete mode 100644 rust/chardev/wrapper.h
 delete mode 100644 rust/hw/core/wrapper.h
 delete mode 100644 rust/migration/wrapper.h
 delete mode 100644 rust/qom/wrapper.h
 delete mode 100644 rust/system/wrapper.h
 delete mode 100644 rust/util/wrapper.h
 rename rust/{util => bindings}/build.rs (55%)
 create mode 100644 rust/bindings/chardev-sys/Cargo.toml
 create mode 120000 rust/bindings/chardev-sys/build.rs
 rename rust/{chardev/src/bindings.rs => bindings/chardev-sys/lib.rs} (84%)
 create mode 100644 rust/bindings/chardev-sys/meson.build
 create mode 100644 rust/bindings/generate_bindgen_args.py
 create mode 100644 rust/bindings/hwcore-sys/Cargo.toml
 create mode 120000 rust/bindings/hwcore-sys/build.rs
 rename rust/{hw/core/src/bindings.rs => bindings/hwcore-sys/lib.rs} (71%)
 create mode 100644 rust/bindings/hwcore-sys/meson.build
 create mode 100644 rust/bindings/meson.build
 create mode 100644 rust/bindings/migration-sys/Cargo.toml
 create mode 120000 rust/bindings/migration-sys/build.rs
 create mode 100644 rust/bindings/migration-sys/lib.rs
 create mode 100644 rust/bindings/migration-sys/meson.build
 create mode 100644 rust/bindings/qom-sys/Cargo.toml
 create mode 120000 rust/bindings/qom-sys/build.rs
 rename rust/{qom/src/bindings.rs => bindings/qom-sys/lib.rs} (85%)
 create mode 100644 rust/bindings/qom-sys/meson.build
 create mode 100644 rust/bindings/system-sys/Cargo.toml
 create mode 120000 rust/bindings/system-sys/build.rs
 rename rust/{system/src/bindings.rs => bindings/system-sys/lib.rs} (88%)
 create mode 100644 rust/bindings/system-sys/meson.build
 create mode 100644 rust/bindings/util-sys/Cargo.toml
 create mode 120000 rust/bindings/util-sys/build.rs
 rename rust/{util/src/bindings.rs => bindings/util-sys/lib.rs} (88%)
 create mode 100644 rust/bindings/util-sys/meson.build
 delete mode 120000 rust/bql/build.rs
 delete mode 100644 rust/bql/src/bindings.rs
 delete mode 120000 rust/chardev/build.rs
 delete mode 120000 rust/hw/core/build.rs
 delete mode 120000 rust/migration/build.rs
 delete mode 100644 rust/migration/src/bindings.rs
 delete mode 120000 rust/qom/build.rs
 delete mode 120000 rust/system/build.rs
docs/devel/rust.rst +57 -0
index 79c26d9d165..67ea84539a2 100644
@@ -339,6 +339,63 @@ Here are some things to keep in mind when working on the QEMU Rust crate.
   or a macro) where it can be documented and tested.  If needed, include
   toy versions of the code in the documentation.
 
+FFI Binding Generation
+''''''''''''''''''''''
+
+QEMU's Rust integration uses multiple ``*-sys`` crates that contain raw FFI
+bindings to different QEMU subsystems. These crates mirror the dependency
+structure that meson.build uses for C code, and which is reflected in
+``static_library()`` declarations. For example:
+
+* util-sys: Basic utilities (no dependencies)
+* qom-sys: QEMU Object Model (depends on util-sys)
+* chardev-sys: Character devices (depends on qom-sys, util-sys)
+* hwcore-sys: Hardware core (depends on qom-sys, util-sys)
+* migration-sys: Migration (depends on util-sys)
+* system-sys: System-level APIs (depends on all others)
+
+Having multiple crates avoids massive rebuilds of all Rust code when C headers
+are changed. On the other hand, bindgen is not aware of how headers are split
+across crates, and therefore it would generate declarations for dependencies
+again. These duplicate declarations are not only large, they create distinct
+types and therefore they are incompatible with each other.
+
+Bindgen Configuration
+~~~~~~~~~~~~~~~~~~~~~
+
+Bindgen options such as symbol blocklists or how to configure enums can be
+defined in each crate's ``Cargo.toml`` via a ``[package.metadata.bindgen]`` section.
+For example::
+
+    [package.metadata.bindgen]
+    header = "wrapper.h"                    # Main header file for this crate
+    rustified-enum = ["QEMUClockType"]      # Enums to generate as Rust enums
+    bitfield-enum = ["VMStateFlags"]        # Enums to treat as bitfields
+    blocklist-function = [                  # Functions to exclude
+        "vmstate_register_ram",
+        "vmstate_unregister_ram"
+    ]
+    additional-files = [                    # Extra files to allowlist
+        "include/system/memory_ldst.*"
+    ]
+
+All bindgen options are supported in the metadata section. The complete list
+can be found in ``rust/bindings/generate_bindgen_args.py``.
+
+Dependency Management
+~~~~~~~~~~~~~~~~~~~~~
+
+By examining the dependency chain before bindgen creates the code for
+the ``*-sys`` crates, the build system ensures that header files included in
+one crate are blocked from appearing in dependent crates, thus avoiding
+duplicate definitions. Dependent crates can import the definition via
+"use" statements.
+
+This dependency-aware binding generation is handled automatically by
+``rust/bindings/generate_bindgen_args.py``, which processes the Cargo.toml
+files in dependency order and generates appropriate ``--allowlist-file`` and
+``--blocklist-file`` arguments for bindgen.
+
 Writing procedural macros
 '''''''''''''''''''''''''
 
meson.build +1 -2
index a84f14258b0..668f1aa919c 100644
@@ -4169,9 +4169,8 @@ if have_rust
     '--with-derive-default',
     '--no-layout-tests',
     '--no-prepend-enum-name',
-    '--allowlist-file', meson.project_source_root() + '/include/.*',
-    '--allowlist-file', meson.project_build_root() + '/.*',
     '--blocklist-file', glib_pc.get_variable('includedir') + '/glib-2.0/.*',
+    '--blocklist-file', meson.project_source_root() + '/include/qemu/typedefs.h',
     '--blocklist-type', '.*_([a-z]*autoptr)$',
     ]
   if not rustfmt.found()
rust/bindings/chardev-sys/wrapper.h new file +12 -0
new file mode 100644
index 00000000000..b8ddc361f76
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/*
+ * This header file is meant to be used as input to the `bindgen` application
+ * in order to generate C FFI compatible Rust bindings.
+ */
+
+#include "qemu/osdep.h"
+
+#include "chardev/char.h"
+#include "chardev/char-fe.h"
+#include "chardev/char-serial.h"
rust/bindings/hwcore-sys/wrapper.h new file +30 -0
new file mode 100644
index 00000000000..7c7c3c35f6d
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/*
+ * This header file is meant to be used as input to the `bindgen` application
+ * in order to generate C FFI compatible Rust bindings.
+ */
+
+/*
+ * We block include/qemu/typedefs.h from bindgen, add here symbols
+ * that are needed as opaque types by other functions.
+ */
+typedef struct Clock Clock;
+typedef struct DeviceState DeviceState;
+typedef struct IRQState *qemu_irq;
+typedef void (*qemu_irq_handler)(void *opaque, int n, int level);
+
+/* Once bindings exist, these could move to a different *-sys crate.  */
+typedef struct BlockBackend BlockBackend;
+typedef struct Monitor Monitor;
+typedef struct NetClientState NetClientState;
+
+#include "qemu/osdep.h"
+
+#include "hw/core/clock.h"
+#include "hw/core/irq.h"
+#include "hw/core/qdev-clock.h"
+#include "hw/core/qdev.h"
+#include "hw/core/qdev-properties-system.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/resettable.h"
rust/bindings/migration-sys/wrapper.h new file +10 -0
new file mode 100644
index 00000000000..076ad79a21f
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/*
+ * This header file is meant to be used as input to the `bindgen` application
+ * in order to generate C FFI compatible Rust bindings.
+ */
+
+#include "qemu/osdep.h"
+
+#include "migration/vmstate.h"
rust/bindings/qom-sys/wrapper.h new file +17 -0
new file mode 100644
index 00000000000..18a5ea6d25f
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/*
+ * This header file is meant to be used as input to the `bindgen` application
+ * in order to generate C FFI compatible Rust bindings.
+ */
+
+/*
+ * We block include/qemu/typedefs.h from bindgen, add here symbols
+ * that are needed as opaque types by other functions.
+ */
+typedef struct Object Object;
+typedef struct ObjectClass ObjectClass;
+
+#include "qemu/osdep.h"
+
+#include "qom/object.h"
rust/bindings/system-sys/wrapper.h new file +21 -0
new file mode 100644
index 00000000000..0a8bf06a1f3
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/*
+ * This header file is meant to be used as input to the `bindgen` application
+ * in order to generate C FFI compatible Rust bindings.
+ */
+
+/*
+ * We block include/qemu/typedefs.h from bindgen, add here symbols
+ * that are needed as opaque types by other functions.
+ */
+typedef struct DirtyBitmapSnapshot DirtyBitmapSnapshot;
+typedef struct MemoryRegion MemoryRegion;
+typedef struct RAMBlock RAMBlock;
+
+#include "qemu/osdep.h"
+
+#include "exec/hwaddr.h"
+#include "system/address-spaces.h"
+#include "system/memory.h"
+#include "hw/core/sysbus.h"
rust/bindings/util-sys/wrapper.h new file +39 -0
new file mode 100644
index 00000000000..e9c433e7dc1
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/*
+ * This header file is meant to be used as input to the `bindgen` application
+ * in order to generate C FFI compatible Rust bindings.
+ */
+
+/*
+ * We block include/qemu/typedefs.h from bindgen, add here symbols
+ * that are needed as opaque types by other functions.
+ */
+typedef struct QEMUBH QEMUBH;
+typedef struct QEMUFile QEMUFile;
+typedef struct QemuOpts QemuOpts;
+typedef struct JSONWriter JSONWriter;
+typedef struct Visitor Visitor;
+
+#include "qemu/osdep.h"
+
+#include "qapi/error.h"
+#include "qapi/error-internal.h"
+#include "qemu/event_notifier.h"
+#include "qemu/main-loop.h"
+#include "qemu/aio.h"
+#include "qemu/log-for-trace.h"
+#include "qemu/log.h"
+#include "qemu/module.h"
+#include "qemu/option.h"
+#include "qemu/timer.h"
+#include "qapi/visitor.h"
+#include "qobject/qbool.h"
+#include "qobject/qdict.h"
+#include "qobject/qjson.h"
+#include "qobject/qlist.h"
+#include "qobject/qnull.h"
+#include "qobject/qnum.h"
+#include "qobject/qobject.h"
+#include "qobject/qstring.h"
+#include "qobject/json-writer.h"
rust/bql/wrapper.h deleted +0 -27
deleted file mode 100644
index 2ef9a96e1d3..00000000000
@@ -1,27 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-/*
- * This header file is meant to be used as input to the `bindgen` application
- * in order to generate C FFI compatible Rust bindings.
- */
-
-#ifndef __CLANG_STDATOMIC_H
-#define __CLANG_STDATOMIC_H
-/*
- * Fix potential missing stdatomic.h error in case bindgen does not insert the
- * correct libclang header paths on its own. We do not use stdatomic.h symbols
- * in QEMU code, so it's fine to declare dummy types instead.
- */
-typedef enum memory_order {
-  memory_order_relaxed,
-  memory_order_consume,
-  memory_order_acquire,
-  memory_order_release,
-  memory_order_acq_rel,
-  memory_order_seq_cst,
-} memory_order;
-#endif /* __CLANG_STDATOMIC_H */
-
-#include "qemu/osdep.h"
-
-#include "qemu/main-loop.h"
rust/chardev/wrapper.h deleted +0 -28
deleted file mode 100644
index 65ede6ea6d7..00000000000
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-/*
- * This header file is meant to be used as input to the `bindgen` application
- * in order to generate C FFI compatible Rust bindings.
- */
-
-#ifndef __CLANG_STDATOMIC_H
-#define __CLANG_STDATOMIC_H
-/*
- * Fix potential missing stdatomic.h error in case bindgen does not insert the
- * correct libclang header paths on its own. We do not use stdatomic.h symbols
- * in QEMU code, so it's fine to declare dummy types instead.
- */
-typedef enum memory_order {
-  memory_order_relaxed,
-  memory_order_consume,
-  memory_order_acquire,
-  memory_order_release,
-  memory_order_acq_rel,
-  memory_order_seq_cst,
-} memory_order;
-#endif /* __CLANG_STDATOMIC_H */
-
-#include "qemu/osdep.h"
-
-#include "chardev/char-fe.h"
-#include "chardev/char-serial.h"
rust/hw/core/wrapper.h deleted +0 -32
deleted file mode 100644
index 8278738f3d8..00000000000
@@ -1,32 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-/*
- * This header file is meant to be used as input to the `bindgen` application
- * in order to generate C FFI compatible Rust bindings.
- */
-
-#ifndef __CLANG_STDATOMIC_H
-#define __CLANG_STDATOMIC_H
-/*
- * Fix potential missing stdatomic.h error in case bindgen does not insert the
- * correct libclang header paths on its own. We do not use stdatomic.h symbols
- * in QEMU code, so it's fine to declare dummy types instead.
- */
-typedef enum memory_order {
-  memory_order_relaxed,
-  memory_order_consume,
-  memory_order_acquire,
-  memory_order_release,
-  memory_order_acq_rel,
-  memory_order_seq_cst,
-} memory_order;
-#endif /* __CLANG_STDATOMIC_H */
-
-#include "qemu/osdep.h"
-
-#include "hw/core/sysbus.h"
-#include "hw/core/clock.h"
-#include "hw/core/qdev-clock.h"
-#include "hw/core/qdev-properties.h"
-#include "hw/core/qdev-properties-system.h"
-#include "hw/core/irq.h"
rust/migration/wrapper.h deleted +0 -51

51 lines not on this page · raw message

rust/qom/wrapper.h deleted +0 -27
deleted file mode 100644
index 3b71bcd3f5b..00000000000
@@ -1,27 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-/*
- * This header file is meant to be used as input to the `bindgen` application
- * in order to generate C FFI compatible Rust bindings.
- */
-
-#ifndef __CLANG_STDATOMIC_H
-#define __CLANG_STDATOMIC_H
-/*
- * Fix potential missing stdatomic.h error in case bindgen does not insert the
- * correct libclang header paths on its own. We do not use stdatomic.h symbols
- * in QEMU code, so it's fine to declare dummy types instead.
- */
-typedef enum memory_order {
-  memory_order_relaxed,
-  memory_order_consume,
-  memory_order_acquire,
-  memory_order_release,
-  memory_order_acq_rel,
-  memory_order_seq_cst,
-} memory_order;
-#endif /* __CLANG_STDATOMIC_H */
-
-#include "qemu/osdep.h"
-
-#include "qom/object.h"
rust/system/wrapper.h deleted +0 -29
deleted file mode 100644
index 48abde85052..00000000000
@@ -1,29 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-/*
- * This header file is meant to be used as input to the `bindgen` application
- * in order to generate C FFI compatible Rust bindings.
- */
-
-#ifndef __CLANG_STDATOMIC_H
-#define __CLANG_STDATOMIC_H
-/*
- * Fix potential missing stdatomic.h error in case bindgen does not insert the
- * correct libclang header paths on its own. We do not use stdatomic.h symbols
- * in QEMU code, so it's fine to declare dummy types instead.
- */
-typedef enum memory_order {
-  memory_order_relaxed,
-  memory_order_consume,
-  memory_order_acquire,
-  memory_order_release,
-  memory_order_acq_rel,
-  memory_order_seq_cst,
-} memory_order;
-#endif /* __CLANG_STDATOMIC_H */
-
-#include "qemu/osdep.h"
-
-#include "system/system.h"
-#include "system/memory.h"
-#include "system/address-spaces.h"
rust/util/wrapper.h deleted +0 -32
deleted file mode 100644
index b9ed68a01d8..00000000000
@@ -1,32 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-/*
- * This header file is meant to be used as input to the `bindgen` application
- * in order to generate C FFI compatible Rust bindings.
- */
-
-#ifndef __CLANG_STDATOMIC_H
-#define __CLANG_STDATOMIC_H
-/*
- * Fix potential missing stdatomic.h error in case bindgen does not insert the
- * correct libclang header paths on its own. We do not use stdatomic.h symbols
- * in QEMU code, so it's fine to declare dummy types instead.
- */
-typedef enum memory_order {
-  memory_order_relaxed,
-  memory_order_consume,
-  memory_order_acquire,
-  memory_order_release,
-  memory_order_acq_rel,
-  memory_order_seq_cst,
-} memory_order;
-#endif /* __CLANG_STDATOMIC_H */
-
-#include "qemu/osdep.h"
-
-#include "qapi/error.h"
-#include "qapi/error-internal.h"
-#include "qemu/log-for-trace.h"
-#include "qemu/log.h"
-#include "qemu/module.h"
-#include "qemu/timer.h"
rust/Cargo.lock +68 -0

144 lines not on this page · raw message

rust/bindings/build.rs renamed from rust/util/build.rs +15 -15
similarity index 55%
rename from rust/util/build.rs
rename to rust/bindings/build.rs
index 5654d1d5624..a466958d713 100644
@@ -10,25 +10,25 @@
 
 fn main() -> Result<()> {
     let manifest_dir = env!("CARGO_MANIFEST_DIR");
-    let file = if let Ok(root) = env::var("MESON_BUILD_ROOT") {
-        let sub = get_rust_subdir(manifest_dir).unwrap();
-        format!("{root}/{sub}/bindings.inc.rs")
-    } else {
-        // Placing bindings.inc.rs in the source directory is supported
-        // but not documented or encouraged.
-        format!("{manifest_dir}/src/bindings.inc.rs")
-    };
+    let root = env::var("MESON_BUILD_ROOT").expect(concat!(
+        "\n",
+        "    MESON_BUILD_ROOT not found.  Maybe you wanted one of\n",
+        "    `make clippy`, `make rustfmt`, `make rustdoc`?\n",
+        "\n",
+        "    For other uses of `cargo`, start a subshell with\n",
+        "    `pyvenv/bin/meson devenv`, or point MESON_BUILD_ROOT to\n",
+        "    the top of the build tree."
+    ));
 
+    let sub = get_rust_subdir(manifest_dir).unwrap();
+    let file = format!("{root}/{sub}/bindings.inc.rs");
     let file = Path::new(&file);
-    if !Path::new(&file).exists() {
+
+    if !file.exists() {
         panic!(concat!(
             "\n",
-            "    No generated C bindings found! Maybe you wanted one of\n",
-            "    `make clippy`, `make rustfmt`, `make rustdoc`?\n",
-            "\n",
-            "    For other uses of `cargo`, start a subshell with\n",
-            "    `pyvenv/bin/meson devenv`, or point MESON_BUILD_ROOT to\n",
-            "    the top of the build tree."
+            "    No generated C bindings found! Run `make` first; or maybe you\n",
+            "    wanted one of `make clippy`, `make rustfmt`, `make rustdoc`?\n",
         ));
     }
 
rust/bindings/chardev-sys/Cargo.toml new file +28 -0
new file mode 100644
index 00000000000..6aa0025ca6f
@@ -0,0 +1,28 @@
+[package]
+name = "chardev-sys"
+version = "0.1.0"
+description = "Rust sys bindings for QEMU/chardev"
+publish = false
+
+authors.workspace = true
+edition.workspace = true
+homepage.workspace = true
+license.workspace = true
+repository.workspace = true
+rust-version.workspace = true
+
+[lib]
+path = "lib.rs"
+
+[dependencies]
+glib-sys = { workspace = true }
+common = { path = "../../common" }
+qom-sys = { path = "../qom-sys" }
+util-sys = { path = "../util-sys" }
+
+[lints]
+workspace = true
+
+[package.metadata.bindgen]
+header = "wrapper.h"
+rustified-enum = ["QEMUChrEvent"]
rust/bindings/chardev-sys/build.rs new file +1 -0
new file mode 120000
index 00000000000..10238032f5f
@@ -0,0 +1 @@
+../build.rs
\ No newline at end of file
rust/bindings/chardev-sys/lib.rs renamed from rust/chardev/src/bindings.rs +3 -4
similarity index 84%
rename from rust/chardev/src/bindings.rs
rename to rust/bindings/chardev-sys/lib.rs
index 360b30d6a34..903f6fc492a 100644
@@ -19,10 +19,9 @@
 )]
 
 use common::Zeroable;
-use glib_sys::{
-    gboolean, guint, GArray, GHashTable, GHashTableIter, GIOCondition, GMainContext, GPollFD,
-    GPtrArray, GSList, GSource, GSourceFunc,
-};
+use glib_sys::{gboolean, guint, GIOCondition, GMainContext, GSource, GSourceFunc};
+use qom_sys::{Object, ObjectClass};
+use util_sys::{Error, IOCanReadHandler, IOReadHandler, QemuOpts};
 
 #[cfg(MESON)]
 include!("bindings.inc.rs");
rust/bindings/chardev-sys/meson.build new file +12 -0
new file mode 100644
index 00000000000..458075b8060
@@ -0,0 +1,12 @@
+_bindgen_chardev_rs = rust.bindgen(
+  args: bindgen_args_common + bindgen_args_data['chardev-sys'].split(),
+  kwargs: bindgen_kwargs)
+_chardev_sys_rs = static_library(
+  'chardev_sys',
+  structured_sources(['lib.rs', _bindgen_chardev_rs]),
+  override_options: ['rust_std=2021', 'build.rust_std=2021'],
+  rust_abi: 'rust',
+  dependencies: [glib_sys_rs, common_rs, qom_sys_rs, util_sys_rs],
+)
+
+chardev_sys_rs = declare_dependency(link_with: [_chardev_sys_rs])
rust/bindings/generate_bindgen_args.py new file +164 -0

164 lines not on this page · raw message

rust/bindings/hwcore-sys/Cargo.toml new file +32 -0
new file mode 100644
index 00000000000..c20024e921a
@@ -0,0 +1,32 @@
+[package]
+name = "hwcore-sys"
+version = "0.1.0"
+description = "Rust sys bindings for QEMU/hwcore"
+publish = false
+
+authors.workspace = true
+edition.workspace = true
+homepage.workspace = true
+license.workspace = true
+repository.workspace = true
+rust-version.workspace = true
+
+[lib]
+path = "lib.rs"
+
+[dependencies]
+glib-sys = { workspace = true }
+common = { path = "../../common" }
+chardev-sys = { path = "../chardev-sys" }
+qom-sys = { path = "../qom-sys" }
+migration-sys = { path = "../migration-sys" }
+util-sys = { path = "../util-sys" }
+system-sys = { path = "../system-sys" }
+
+[lints]
+workspace = true
+
+[package.metadata.bindgen]
+header = "wrapper.h"
+rustified-enum = ["DeviceCategory", "GpioPolarity", "MachineInitPhase", "ResetType"]
+bitfield-enum = ["ClockEvent"]
rust/bindings/hwcore-sys/build.rs new file +1 -0
new file mode 120000
index 00000000000..10238032f5f
@@ -0,0 +1 @@
+../build.rs
\ No newline at end of file
rust/bindings/hwcore-sys/lib.rs renamed from rust/hw/core/src/bindings.rs +8 -9
similarity index 71%
rename from rust/hw/core/src/bindings.rs
rename to rust/bindings/hwcore-sys/lib.rs
index db872d38bc7..8cef4a79619 100644
@@ -18,13 +18,15 @@
     clippy::too_many_arguments
 )]
 
-use chardev::bindings::Chardev;
+use chardev_sys::Chardev;
 use common::Zeroable;
-use glib_sys::{GHashTable, GHashTableIter, GList, GPtrArray, GSList};
-use migration::bindings::VMStateDescription;
-use qom::bindings::ObjectClass;
-use system::bindings::MemoryRegion;
-use util::bindings::Error;
+use glib_sys::GSList;
+use migration_sys::VMStateDescription;
+use qom_sys::{
+    InterfaceClass, Object, ObjectClass, ObjectProperty, ObjectPropertyAccessor,
+    ObjectPropertyRelease,
+};
+use util_sys::{Error, QDict, QList};
 
 #[cfg(MESON)]
 include!("bindings.inc.rs");
@@ -35,8 +37,5 @@
 unsafe impl Send for Property {}
 unsafe impl Sync for Property {}
 
-unsafe impl Send for TypeInfo {}
-unsafe impl Sync for TypeInfo {}
-
 unsafe impl Zeroable for Property__bindgen_ty_1 {}
 unsafe impl Zeroable for Property {}
rust/bindings/hwcore-sys/meson.build new file +12 -0
new file mode 100644
index 00000000000..3d51947b4a4
@@ -0,0 +1,12 @@
+_bindgen_hwcore_rs = rust.bindgen(
+  args: bindgen_args_common + bindgen_args_data['hwcore-sys'].split(),
+  kwargs: bindgen_kwargs)
+_hwcore_sys_rs = static_library(
+  'hwcore_sys',
+  structured_sources(['lib.rs', _bindgen_hwcore_rs]),
+  override_options: ['rust_std=2021', 'build.rust_std=2021'],
+  rust_abi: 'rust',
+  dependencies: [common_rs, glib_sys_rs, qom_sys_rs, util_sys_rs, migration_sys_rs, chardev_sys_rs],
+)
+
+hwcore_sys_rs = declare_dependency(link_with: [_hwcore_sys_rs])
rust/bindings/meson.build new file +37 -0
new file mode 100644
index 00000000000..c2798731a14
@@ -0,0 +1,37 @@
+# Generate bindgen arguments from Cargo.toml metadata
+# Sort these in dependency order, same as the subdir()
+# invocations below.
+bindgen_dirs = [
+  'util-sys',
+  'migration-sys',
+  'qom-sys',
+  'chardev-sys',
+  'hwcore-sys',
+  'system-sys',
+]
+bindgen_args_file = configure_file(
+  command: [files('generate_bindgen_args.py'),
+            '-I', meson.project_source_root() / 'include',
+            '--source-dir', meson.current_source_dir(),
+            '-o', '@OUTPUT@', '--dep-file', '@DEPFILE@'] + bindgen_dirs,
+  output: 'bindgen_args.mak',
+  depfile: 'bindgen_args.d'
+)
+
+# now generate all bindgen files
+bindgen_args_data = keyval.load(bindgen_args_file)
+bindgen_kwargs = {
+  'input': 'wrapper.h',
+  'dependencies': common_ss.all_dependencies(),
+  'output': 'bindings.inc.rs',
+  'include_directories': bindings_incdir,
+  'bindgen_version': ['>=0.60.0'],
+  'c_args': bindgen_c_args,
+}
+
+subdir('util-sys')
+subdir('migration-sys')
+subdir('qom-sys')
+subdir('chardev-sys')
+subdir('hwcore-sys')
+subdir('system-sys')
rust/bindings/migration-sys/Cargo.toml new file +28 -0
new file mode 100644
index 00000000000..88d7742e6ac
@@ -0,0 +1,28 @@
+[package]
+name = "migration-sys"
+version = "0.1.0"
+description = "Rust sys bindings for QEMU/migration"
+publish = false
+
+authors.workspace = true
+edition.workspace = true
+homepage.workspace = true
+license.workspace = true
+repository.workspace = true
+rust-version.workspace = true
+
+[lib]
+path = "lib.rs"
+
+[dependencies]
+glib-sys = { workspace = true }
+common = { path = "../../common" }
+util-sys = { path = "../util-sys" }
+
+[lints]
+workspace = true
+
+[package.metadata.bindgen]
+header = "wrapper.h"
+bitfield-enum = ["MigrationPolicy", "MigrationPriority", "VMStateFlags"]
+blocklist-function = ["vmstate_register_ram", "vmstate_register_ram_global", "vmstate_unregister_ram"]
rust/bindings/migration-sys/build.rs new file +1 -0
new file mode 120000
index 00000000000..10238032f5f
@@ -0,0 +1 @@
+../build.rs
\ No newline at end of file
rust/bindings/migration-sys/lib.rs new file +125 -0

125 lines not on this page · raw message

rust/bindings/migration-sys/meson.build new file +12 -0
new file mode 100644
index 00000000000..9243acba300
@@ -0,0 +1,12 @@
+_bindgen_migration_rs = rust.bindgen(
+  args: bindgen_args_common + bindgen_args_data['migration-sys'].split(),
+  kwargs: bindgen_kwargs)
+_migration_sys_rs = static_library(
+  'migration_sys',
+  structured_sources(['lib.rs', _bindgen_migration_rs]),
+  override_options: ['rust_std=2021', 'build.rust_std=2021'],
+  rust_abi: 'rust',
+  dependencies: [glib_sys_rs, common_rs, util_sys_rs],
+)
+
+migration_sys_rs = declare_dependency(link_with: [_migration_sys_rs])
rust/bindings/qom-sys/Cargo.toml new file +25 -0
new file mode 100644
index 00000000000..621bd468e69
@@ -0,0 +1,25 @@
+[package]
+name = "qom-sys"
+version = "0.1.0"
+description = "Rust sys bindings for QEMU/qom"
+publish = false
+
+authors.workspace = true
+edition.workspace = true
+homepage.workspace = true
+license.workspace = true
+repository.workspace = true
+rust-version.workspace = true
+
+[lib]
+path = "lib.rs"
+
+[dependencies]
+glib-sys = { workspace = true }
+util-sys = { path = "../util-sys" }
+
+[lints]
+workspace = true
+
+[package.metadata.bindgen]
+header = "wrapper.h"
rust/bindings/qom-sys/build.rs new file +1 -0
new file mode 120000
index 00000000000..10238032f5f
@@ -0,0 +1 @@
+../build.rs
\ No newline at end of file
rust/bindings/qom-sys/lib.rs renamed from rust/qom/src/bindings.rs +4 -0
similarity index 85%
rename from rust/qom/src/bindings.rs
rename to rust/bindings/qom-sys/lib.rs
index e61259ec2ef..464b9290344 100644
@@ -19,9 +19,13 @@
 )]
 
 use glib_sys::{GHashTable, GHashTableIter, GPtrArray, GSList};
+use util_sys::{Error, QDict, QObject, Visitor};
 
 #[cfg(MESON)]
 include!("bindings.inc.rs");
 
 #[cfg(not(MESON))]
 include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs"));
+
+unsafe impl Send for TypeInfo {}
+unsafe impl Sync for TypeInfo {}
rust/bindings/qom-sys/meson.build new file +12 -0
new file mode 100644
index 00000000000..8f8ae7d1bc8
@@ -0,0 +1,12 @@
+_bindgen_qom_rs = rust.bindgen(
+  args: bindgen_args_common + bindgen_args_data['qom-sys'].split(),
+  kwargs: bindgen_kwargs)
+_qom_sys_rs = static_library(
+  'qom_sys',
+  structured_sources(['lib.rs', _bindgen_qom_rs]),
+  override_options: ['rust_std=2021', 'build.rust_std=2021'],
+  rust_abi: 'rust',
+  dependencies: [glib_sys_rs, util_sys_rs],
+)
+
+qom_sys_rs = declare_dependency(link_with: [_qom_sys_rs])
rust/bindings/system-sys/Cargo.toml new file +30 -0
new file mode 100644
index 00000000000..7e527130ff5
@@ -0,0 +1,30 @@
+[package]
+name = "system-sys"
+version = "0.1.0"
+description = "Rust sys bindings for QEMU/system"
+publish = false
+
+authors.workspace = true
+edition.workspace = true
+homepage.workspace = true
+license.workspace = true
+repository.workspace = true
+rust-version.workspace = true
+
+[lib]
+path = "lib.rs"
+
+[dependencies]
+glib-sys = { workspace = true }
+common = { path = "../../common" }
+migration-sys = { path = "../migration-sys" }
+util-sys = { path = "../util-sys" }
+qom-sys = { path = "../qom-sys" }
+
+[lints]
+workspace = true
+
+[package.metadata.bindgen]
+header = "wrapper.h"
+rustified-enum = ["device_endian"]
+additional-files = ["system/memory.*"]
rust/bindings/system-sys/build.rs new file +1 -0
new file mode 120000
index 00000000000..10238032f5f
@@ -0,0 +1 @@
+../build.rs
\ No newline at end of file
rust/bindings/system-sys/lib.rs renamed from rust/system/src/bindings.rs +3 -1
similarity index 88%
rename from rust/system/src/bindings.rs
rename to rust/bindings/system-sys/lib.rs
index 7164c5219a5..022fe65dd83 100644
@@ -19,7 +19,9 @@
 )]
 
 use common::Zeroable;
-use glib_sys::{guint, GHashTable, GHashTableIter, GList, GPollFD, GPtrArray, GSList};
+use hwcore_sys::{qemu_irq, DeviceClass, DeviceState};
+use qom_sys::{InterfaceClass, Object, ObjectClass};
+use util_sys::{Error, EventNotifier, QEMUBH};
 
 #[cfg(MESON)]
 include!("bindings.inc.rs");
rust/bindings/system-sys/meson.build new file +12 -0
new file mode 100644
index 00000000000..aa5e8801149
@@ -0,0 +1,12 @@
+_bindgen_system_rs = rust.bindgen(
+  args: bindgen_args_common + bindgen_args_data['system-sys'].split(),
+  kwargs: bindgen_kwargs)
+_system_sys_rs = static_library(
+  'system_sys',
+  structured_sources(['lib.rs', _bindgen_system_rs]),
+  override_options: ['rust_std=2021', 'build.rust_std=2021'],
+  rust_abi: 'rust',
+  dependencies: [common_rs, glib_sys_rs, hwcore_sys_rs, migration_sys_rs, qom_sys_rs, util_sys_rs],
+)
+
+system_sys_rs = declare_dependency(link_with: [_system_sys_rs])
rust/bindings/util-sys/Cargo.toml new file +25 -0
new file mode 100644
index 00000000000..929a08ac4ea
@@ -0,0 +1,25 @@
+[package]
+name = "util-sys"
+version = "0.1.0"
+description = "Rust sys bindings for QEMU/util"
+publish = false
+
+authors.workspace = true
+edition.workspace = true
+homepage.workspace = true
+license.workspace = true
+repository.workspace = true
+rust-version.workspace = true
+
+[lib]
+path = "lib.rs"
+
+[dependencies]
+glib-sys = { workspace = true }
+
+[lints]
+workspace = true
+
+[package.metadata.bindgen]
+header = "wrapper.h"
+rustified-enum = ["module_init_type", "QEMUClockType"]
rust/bindings/util-sys/build.rs new file +1 -0
new file mode 120000
index 00000000000..10238032f5f
@@ -0,0 +1 @@
+../build.rs
\ No newline at end of file
rust/bindings/util-sys/lib.rs renamed from rust/util/src/bindings.rs +1 -1
similarity index 88%
rename from rust/util/src/bindings.rs
rename to rust/bindings/util-sys/lib.rs
index 3514a66f5fa..0212e941843 100644
@@ -18,7 +18,7 @@
     clippy::too_many_arguments
 )]
 
-use glib_sys::{guint, GPollFD, GString};
+use glib_sys::{guint, GArray, GHashTable, GPollFD, GSList, GSource, GString};
 
 #[cfg(MESON)]
 include!("bindings.inc.rs");
rust/bindings/util-sys/meson.build new file +12 -0
new file mode 100644
index 00000000000..c37f50a94bd
@@ -0,0 +1,12 @@
+_bindgen_util_rs = rust.bindgen(
+  args: bindgen_args_common + bindgen_args_data['util-sys'].split(),
+  kwargs: bindgen_kwargs)
+_util_sys_rs = static_library(
+  'util_sys',
+  structured_sources(['lib.rs', _bindgen_util_rs]),
+  override_options: ['rust_std=2021', 'build.rust_std=2021'],
+  rust_abi: 'rust',
+  dependencies: [glib_sys_rs],
+)
+
+util_sys_rs = declare_dependency(link_with: [_util_sys_rs])
rust/bql/Cargo.toml +1 -0
index 8fd81311028..a27099e0587 100644
@@ -14,6 +14,7 @@ rust-version.workspace = true
 
 [dependencies]
 glib-sys.workspace = true
+util-sys = { path = "../bindings/util-sys" }
 
 [features]
 default = ["debug_cell"]
rust/bql/build.rs deleted +0 -1
deleted file mode 120000
index 71a3167885c..00000000000
@@ -1 +0,0 @@
-../util/build.rs
\ No newline at end of file
rust/bql/meson.build +2 -28
index 728c9e4dacf..de295d2983e 100644
@@ -6,37 +6,11 @@ if get_option('debug_mutex')
   _bql_cfg += ['--cfg', 'feature="debug_cell"']
 endif
 
-#
-# TODO: Remove this comment when the clang/libclang mismatch issue is solved.
-#
-# Rust bindings generation with `bindgen` might fail in some cases where the
-# detected `libclang` does not match the expected `clang` version/target. In
-# this case you must pass the path to `clang` and `libclang` to your build
-# command invocation using the environment variables CLANG_PATH and
-# LIBCLANG_PATH
-_bql_bindings_inc_rs = rust.bindgen(
-  input: 'wrapper.h',
-  dependencies: common_ss.all_dependencies(),
-  output: 'bindings.inc.rs',
-  include_directories: bindings_incdir,
-  bindgen_version: ['>=0.60.0'],
-  args: bindgen_args_common,
-  c_args: bindgen_c_args,
-)
-
 _bql_rs = static_library(
   'bql',
-  structured_sources(
-    [
-      'src/lib.rs',
-      'src/bindings.rs',
-      'src/cell.rs',
-      'src/prelude.rs',
-    ],
-    {'.': _bql_bindings_inc_rs}
-  ),
+  'src/lib.rs',
   rust_args: _bql_cfg,
-  dependencies: [glib_sys_rs],
+  dependencies: [glib_sys_rs, util_sys_rs],
 )
 
 bql_rs = declare_dependency(link_with: [_bql_rs],
rust/bql/src/bindings.rs deleted +0 -27
deleted file mode 100644
index c656cf18845..00000000000
@@ -1,27 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-#![allow(
-    dead_code,
-    improper_ctypes_definitions,
-    improper_ctypes,
-    non_camel_case_types,
-    non_snake_case,
-    non_upper_case_globals,
-    unnecessary_transmutes,
-    unsafe_op_in_unsafe_fn,
-    clippy::pedantic,
-    clippy::restriction,
-    clippy::style,
-    clippy::missing_const_for_fn,
-    clippy::ptr_offset_with_cast,
-    clippy::useless_transmute,
-    clippy::missing_safety_doc,
-    clippy::too_many_arguments
-)]
-
-use glib_sys::{guint, GArray, GHashTable, GHashTableIter, GPollFD, GPtrArray, GSList, GSource};
-
-#[cfg(MESON)]
-include!("bindings.inc.rs");
-
-#[cfg(not(MESON))]
-include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs"));
rust/bql/src/lib.rs +1 -2
index d2fea5db1ac..3aa3d46d76c 100644
@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
-mod bindings;
-use bindings::{bql_block_unlock, bql_locked, rust_bql_mock_lock};
+use util_sys::{bql_block_unlock, bql_locked, rust_bql_mock_lock};
 
 mod cell;
 pub use cell::*;
rust/chardev/Cargo.toml +1 -0
index f105189dccb..208d44d0cdf 100644
@@ -14,6 +14,7 @@ rust-version.workspace = true
 
 [dependencies]
 glib-sys = { workspace = true }
+chardev-sys = { path = "../bindings/chardev-sys" }
 common = { path = "../common" }
 bql = { path = "../bql" }
 migration = { path = "../migration" }
rust/chardev/build.rs deleted +0 -1
deleted file mode 120000
index 71a3167885c..00000000000
@@ -1 +0,0 @@
-../util/build.rs
\ No newline at end of file
rust/chardev/meson.build +2 -35
index 2e4f4670bd8..7b267fd23ae 100644
@@ -1,41 +1,8 @@
-c_enums = [
-  'QEMUChrEvent',
-]
-_chardev_bindgen_args = []
-foreach enum : c_enums
-  _chardev_bindgen_args += ['--rustified-enum', enum]
-endforeach
-
-# TODO: Remove this comment when the clang/libclang mismatch issue is solved.
-#
-# Rust bindings generation with `bindgen` might fail in some cases where the
-# detected `libclang` does not match the expected `clang` version/target. In
-# this case you must pass the path to `clang` and `libclang` to your build
-# command invocation using the environment variables CLANG_PATH and
-# LIBCLANG_PATH
-_chardev_bindings_inc_rs = rust.bindgen(
-  input: 'wrapper.h',
-  dependencies: common_ss.all_dependencies(),
-  output: 'bindings.inc.rs',
-  include_directories: bindings_incdir,
-  bindgen_version: ['>=0.60.0'],
-  args: bindgen_args_common + _chardev_bindgen_args,
-  c_args: bindgen_c_args,
-)
-
 _chardev_rs = static_library(
   'chardev',
-  structured_sources(
-    [
-      'src/lib.rs',
-      'src/bindings.rs',
-      'src/chardev.rs',
-      'src/prelude.rs',
-    ],
-    {'.': _chardev_bindings_inc_rs}
-  ),
+  'src/lib.rs',
   link_with: [_bql_rs, _migration_rs, _qom_rs, _util_rs],
-  dependencies: [glib_sys_rs, common_rs, qemu_macros],
+  dependencies: [glib_sys_rs, common_rs, qemu_macros, chardev_sys_rs],
 )
 
 chardev_rs = declare_dependency(link_with: [_chardev_rs], dependencies: [chardev, qemuutil])
rust/chardev/src/lib.rs +1 -1
index 93a28725932..9f1a3a9c1c5 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
-pub mod bindings;
+pub use chardev_sys as bindings;
 
 mod chardev;
 pub use chardev::*;
rust/hw/char/pl011/build.rs +1 -1
index 5f5060db356..e3262426852 120000
@@ -1 +1 @@
-../../../util/build.rs
\ No newline at end of file
+../../../bindings/build.rs
\ No newline at end of file
rust/hw/char/pl011/meson.build +7 -14
index 9c0e8290e9a..1a1a09e5083 100644
@@ -1,18 +1,11 @@
-# TODO: Remove this comment when the clang/libclang mismatch issue is solved.
-#
-# Rust bindings generation with `bindgen` might fail in some cases where the
-# detected `libclang` does not match the expected `clang` version/target. In
-# this case you must pass the path to `clang` and `libclang` to your build
-# command invocation using the environment variables CLANG_PATH and
-# LIBCLANG_PATH
 _libpl011_bindings_inc_rs = rust.bindgen(
-  input: 'wrapper.h',
-  dependencies: common_ss.all_dependencies(),
-  output: 'bindings.inc.rs',
-  include_directories: bindings_incdir,
-  bindgen_version: ['>=0.60.0'],
-  args: bindgen_args_common,
-  c_args: bindgen_c_args,
+  args: bindgen_args_common + [
+    '--allowlist-file', meson.project_source_root() / 'include/hw/char/pl011.h',
+    '--blocklist-file',
+      meson.project_source_root() /
+      'include/(block\|chardev/|exec/|hw/core/|qemu/|qom/|system/).*',
+  ],
+  kwargs: bindgen_kwargs,
 )
 
 _libpl011_rs = static_library(
rust/hw/char/pl011/src/bindings.rs +3 -4
index 68b9b22bbc3..8e2f8863b18 100644
@@ -20,10 +20,9 @@
 
 //! `bindgen`-generated declarations.
 
-use glib_sys::{
-    gboolean, guint, GArray, GHashTable, GHashTableIter, GIOCondition, GList, GMainContext,
-    GPollFD, GPtrArray, GSList, GSource, GSourceFunc,
-};
+use chardev::bindings::{CharFrontend, Chardev};
+use hwcore::bindings::{qemu_irq, Clock, DeviceState};
+use system::bindings::{hwaddr, MemoryRegion, SysBusDevice};
 
 #[cfg(MESON)]
 include!("bindings.inc.rs");
rust/hw/core/Cargo.toml +1 -0
index ecfb5647184..8cc514da202 100644
@@ -14,6 +14,7 @@ rust-version.workspace = true
 
 [dependencies]
 glib-sys.workspace = true
+hwcore-sys = { path = "../../bindings/hwcore-sys" }
 qemu_macros = { path = "../../qemu-macros" }
 common = { path = "../../common" }
 bql = { path = "../../bql" }
rust/hw/core/build.rs deleted +0 -1
deleted file mode 120000
index 2a79ee31b8c..00000000000
@@ -1 +0,0 @@
-../../util/build.rs
\ No newline at end of file
rust/hw/core/meson.build +2 -58

68 lines not on this page · raw message

rust/hw/core/src/lib.rs +1 -2
index 491743d2b9d..76689fe7db1 100644
@@ -1,10 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
+pub use hwcore_sys as bindings;
 pub use qemu_macros::Device;
 pub use qom;
 
-pub mod bindings;
-
 mod irq;
 pub use irq::*;
 
rust/hw/core/src/qdev.rs +3 -3
index f6037fbdcae..145e20a984f 100644
@@ -66,7 +66,7 @@ pub trait ResettablePhasesImpl {
 /// can be downcasted to type `T`. We also expect the device is
 /// readable/writeable from one thread at any time.
 unsafe extern "C" fn rust_resettable_enter_fn<T: ResettablePhasesImpl>(
-    obj: *mut bindings::Object,
+    obj: *mut qom::bindings::Object,
     typ: ResetType,
 ) {
     let state = NonNull::new(obj).unwrap().cast::<T>();
@@ -79,7 +79,7 @@ pub trait ResettablePhasesImpl {
 /// can be downcasted to type `T`. We also expect the device is
 /// readable/writeable from one thread at any time.
 unsafe extern "C" fn rust_resettable_hold_fn<T: ResettablePhasesImpl>(
-    obj: *mut bindings::Object,
+    obj: *mut qom::bindings::Object,
     typ: ResetType,
 ) {
     let state = NonNull::new(obj).unwrap().cast::<T>();
@@ -92,7 +92,7 @@ pub trait ResettablePhasesImpl {
 /// can be downcasted to type `T`. We also expect the device is
 /// readable/writeable from one thread at any time.
 unsafe extern "C" fn rust_resettable_exit_fn<T: ResettablePhasesImpl>(
-    obj: *mut bindings::Object,
+    obj: *mut qom::bindings::Object,
     typ: ResetType,
 ) {
     let state = NonNull::new(obj).unwrap().cast::<T>();
rust/hw/core/src/sysbus.rs +10 -11
index 81fab3f1910..7db09a82c63 100644
@@ -6,22 +6,21 @@
 
 use std::ffi::CStr;
 
-pub use bindings::SysBusDeviceClass;
 use common::Opaque;
 use qom::prelude::*;
 use system::MemoryRegion;
+pub use system_sys::SysBusDeviceClass;
 use util::{Error, Result};
 
 use crate::{
-    bindings,
     irq::{IRQState, InterruptSource},
     qdev::{DeviceClassExt, DeviceImpl, DeviceState},
 };
 
-/// A safe wrapper around [`bindings::SysBusDevice`].
+/// A safe wrapper around [`system_sys::SysBusDevice`].
 #[repr(transparent)]
 #[derive(Debug, common::Wrapper)]
-pub struct SysBusDevice(Opaque<bindings::SysBusDevice>);
+pub struct SysBusDevice(Opaque<system_sys::SysBusDevice>);
 
 unsafe impl Send for SysBusDevice {}
 unsafe impl Sync for SysBusDevice {}
@@ -29,7 +28,7 @@ unsafe impl Sync for SysBusDevice {}
 unsafe impl ObjectType for SysBusDevice {
     type Class = SysBusDeviceClass;
     const TYPE_NAME: &'static CStr =
-        unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_SYS_BUS_DEVICE) };
+        unsafe { CStr::from_bytes_with_nul_unchecked(system_sys::TYPE_SYS_BUS_DEVICE) };
 }
 
 qom_isa!(SysBusDevice: DeviceState, Object);
@@ -62,7 +61,7 @@ pub trait SysBusDeviceMethods: ObjectDeref
     fn init_mmio(&self, iomem: &MemoryRegion) {
         assert!(bql::is_locked());
         unsafe {
-            bindings::sysbus_init_mmio(self.upcast().as_mut_ptr(), iomem.as_mut_ptr());
+            system_sys::sysbus_init_mmio(self.upcast().as_mut_ptr(), iomem.as_mut_ptr());
         }
     }
 
@@ -73,7 +72,7 @@ fn init_mmio(&self, iomem: &MemoryRegion) {
     fn init_irq(&self, irq: &InterruptSource) {
         assert!(bql::is_locked());
         unsafe {
-            bindings::sysbus_init_irq(self.upcast().as_mut_ptr(), irq.as_ptr());
+            system_sys::sysbus_init_irq(self.upcast().as_mut_ptr(), irq.as_ptr());
         }
     }
 
@@ -82,7 +81,7 @@ fn mmio_addr(&self, id: u32) -> Option<u64> {
         assert!(bql::is_locked());
         // SAFETY: the BQL ensures that no one else writes to sbd.mmio[], and
         // the SysBusDevice must be initialized to get an IsA<SysBusDevice>.
-        let sbd = unsafe { &*self.upcast().as_ptr() };
+        let sbd = unsafe { &*self.upcast().as_mut_ptr() };
         let id: usize = id.try_into().unwrap();
         if sbd.mmio[id].memory.is_null() {
             None
@@ -96,7 +95,7 @@ fn mmio_map(&self, id: u32, addr: u64) {
         assert!(bql::is_locked());
         let id: i32 = id.try_into().unwrap();
         unsafe {
-            bindings::sysbus_mmio_map(self.upcast().as_mut_ptr(), id, addr);
+            system_sys::sysbus_mmio_map(self.upcast().as_mut_ptr(), id, addr);
         }
     }
 
@@ -108,7 +107,7 @@ fn connect_irq(&self, id: u32, irq: &Owned<IRQState>) {
         let id: i32 = id.try_into().unwrap();
         let irq: &IRQState = irq;
         unsafe {
-            bindings::sysbus_connect_irq(self.upcast().as_mut_ptr(), id, irq.as_mut_ptr());
+            system_sys::sysbus_connect_irq(self.upcast().as_mut_ptr(), id, irq.as_mut_ptr());
         }
     }
 
@@ -116,7 +115,7 @@ fn sysbus_realize(&self) -> Result<()> {
         assert!(bql::is_locked());
         unsafe {
             Error::with_errp(|errp| {
-                bindings::sysbus_realize(self.upcast().as_mut_ptr(), errp);
+                system_sys::sysbus_realize(self.upcast().as_mut_ptr(), errp);
             })
         }
     }
rust/meson.build +1 -0
index bacb7879102..3a3e10d7b97 100644
@@ -35,6 +35,7 @@ genrs = []
 subdir('qemu-macros')
 
 subdir('common')
+subdir('bindings')
 subdir('bits')
 
 subdir('util')
rust/migration/Cargo.toml +1 -0
index 415457496d6..cf10601b44a 100644
@@ -17,6 +17,7 @@ bql = { path = "../bql" }
 common = { path = "../common" }
 qemu_macros = { path = "../qemu-macros" }
 util = { path = "../util" }
+migration-sys = { path = "../bindings/migration-sys" }
 glib-sys.workspace = true
 
 [lints]
rust/migration/build.rs deleted +0 -1
deleted file mode 120000
index 71a3167885c..00000000000
@@ -1 +0,0 @@
-../util/build.rs
\ No newline at end of file
rust/migration/meson.build +2 -38
index 76d86b0ac0f..96266897770 100644
@@ -1,44 +1,8 @@
-_migration_bindgen_args = []
-c_bitfields = [
-  'MigrationPolicy',
-  'MigrationPriority',
-  'VMStateFlags',
-]
-foreach enum : c_bitfields
-  _migration_bindgen_args += ['--bitfield-enum', enum]
-endforeach
-#
-# TODO: Remove this comment when the clang/libclang mismatch issue is solved.
-#
-# Rust bindings generation with `bindgen` might fail in some cases where the
-# detected `libclang` does not match the expected `clang` version/target. In
-# this case you must pass the path to `clang` and `libclang` to your build
-# command invocation using the environment variables CLANG_PATH and
-# LIBCLANG_PATH
-_migration_bindings_inc_rs = rust.bindgen(
-  input: 'wrapper.h',
-  dependencies: common_ss.all_dependencies(),
-  output: 'bindings.inc.rs',
-  include_directories: bindings_incdir,
-  bindgen_version: ['>=0.60.0'],
-  args: bindgen_args_common + _migration_bindgen_args,
-  c_args: bindgen_c_args,
-)
-
 _migration_rs = static_library(
   'migration',
-  structured_sources(
-    [
-      'src/lib.rs',
-      'src/bindings.rs',
-      'src/migratable.rs',
-      'src/prelude.rs',
-      'src/vmstate.rs',
-    ],
-    {'.' : _migration_bindings_inc_rs},
-  ),
+  'src/lib.rs',
   link_with: [_util_rs, _bql_rs],
-  dependencies: [common_rs, glib_sys_rs, qemu_macros],
+  dependencies: [common_rs, glib_sys_rs, qemu_macros, migration_sys_rs],
 )
 
 migration_rs = declare_dependency(link_with: [_migration_rs],
rust/migration/src/bindings.rs deleted +0 -49

49 lines not on this page · raw message

rust/migration/src/lib.rs +1 -2
index 32e182e716a..6d819cc1554 100644
@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
-pub mod bindings;
-
+pub use migration_sys as bindings;
 pub use qemu_macros::ToMigrationState;
 
 pub mod migratable;
rust/migration/src/vmstate.rs +0 -73

79 lines not on this page · raw message

rust/qom/Cargo.toml +1 -0
index 4be3c2541b6..aed8af5474a 100644
@@ -18,6 +18,7 @@ bql = { path = "../bql" }
 migration = { path = "../migration" }
 qemu_macros = { path = "../qemu-macros" }
 util = { path = "../util" }
+qom-sys = { path = "../bindings/qom-sys" }
 glib-sys.workspace = true
 
 [lints]
rust/qom/build.rs deleted +0 -1
deleted file mode 120000
index 71a3167885c..00000000000
@@ -1 +0,0 @@
-../util/build.rs
\ No newline at end of file
rust/qom/meson.build +2 -27
index dda26c3f981..9865da280cf 100644
@@ -1,33 +1,8 @@
-# TODO: Remove this comment when the clang/libclang mismatch issue is solved.
-#
-# Rust bindings generation with `bindgen` might fail in some cases where the
-# detected `libclang` does not match the expected `clang` version/target. In
-# this case you must pass the path to `clang` and `libclang` to your build
-# command invocation using the environment variables CLANG_PATH and
-# LIBCLANG_PATH
-_qom_bindings_inc_rs = rust.bindgen(
-  input: 'wrapper.h',
-  dependencies: common_ss.all_dependencies(),
-  output: 'bindings.inc.rs',
-  include_directories: bindings_incdir,
-  bindgen_version: ['>=0.60.0'],
-  args: bindgen_args_common,
-  c_args: bindgen_c_args,
-)
-
 _qom_rs = static_library(
   'qom',
-  structured_sources(
-    [
-      'src/lib.rs',
-      'src/bindings.rs',
-      'src/prelude.rs',
-      'src/qom.rs',
-    ],
-    {'.': _qom_bindings_inc_rs}
-  ),
+  'src/lib.rs',
   link_with: [_bql_rs, _migration_rs],
-  dependencies: [common_rs, glib_sys_rs, qemu_macros],
+  dependencies: [common_rs, glib_sys_rs, qemu_macros, qom_sys_rs],
 )
 
 qom_rs = declare_dependency(link_with: [_qom_rs], dependencies: [qemu_macros, qom, qemuutil])
rust/qom/src/lib.rs +1 -2
index 24c44fc2afb..1bed1cfe233 100644
@@ -1,8 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
 pub use qemu_macros::Object;
-
-pub mod bindings;
+pub use qom_sys as bindings;
 
 // preserve one-item-per-"use" syntax, it is clearer
 // for prelude-like modules
rust/system/Cargo.toml +3 -0
index 186ea00bfff..f7fde9782ea 100644
@@ -14,6 +14,9 @@ rust-version.workspace = true
 
 [dependencies]
 common = { path = "../common" }
+system-sys = { path = "../bindings/system-sys" }
+bql = { path = "../bql" }
+migration = { path = "../migration" }
 qom = { path = "../qom" }
 util = { path = "../util" }
 glib-sys.workspace = true
rust/system/build.rs deleted +0 -1
deleted file mode 120000
index 71a3167885c..00000000000
@@ -1 +0,0 @@
-../util/build.rs
\ No newline at end of file
rust/system/meson.build +2 -35
index e9f36ed8554..4cbd63cbbd7 100644
@@ -1,41 +1,8 @@
-c_enums = [
-  'device_endian',
-]
-_system_bindgen_args = []
-foreach enum : c_enums
-  _system_bindgen_args += ['--rustified-enum', enum]
-endforeach
-
-# TODO: Remove this comment when the clang/libclang mismatch issue is solved.
-#
-# Rust bindings generation with `bindgen` might fail in some cases where the
-# detected `libclang` does not match the expected `clang` version/target. In
-# this case you must pass the path to `clang` and `libclang` to your build
-# command invocation using the environment variables CLANG_PATH and
-# LIBCLANG_PATH
-_system_bindings_inc_rs = rust.bindgen(
-  input: 'wrapper.h',
-  dependencies: common_ss.all_dependencies(),
-  output: 'bindings.inc.rs',
-  include_directories: bindings_incdir,
-  bindgen_version: ['>=0.60.0'],
-  args: bindgen_args_common + _system_bindgen_args,
-  c_args: bindgen_c_args,
-)
-
 _system_rs = static_library(
   'system',
-  structured_sources(
-    [
-      'src/lib.rs',
-      'src/bindings.rs',
-      'src/memory.rs',
-      'src/prelude.rs',
-    ],
-    {'.': _system_bindings_inc_rs}
-  ),
+  'src/lib.rs',
   link_with: [_bql_rs, _migration_rs, _qom_rs, _util_rs],
-  dependencies: [glib_sys_rs, common_rs, qemu_macros],
+  dependencies: [glib_sys_rs, common_rs, qemu_macros, system_sys_rs],
 )
 
 system_rs = declare_dependency(link_with: [_system_rs],
rust/system/src/lib.rs +1 -1
index 5fb83b65d8d..10741e0ee0a 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
-pub mod bindings;
+pub use system_sys as bindings;
 
 mod memory;
 pub use memory::*;
rust/system/src/memory.rs +1 -1
index 4e06c16a0b5..4c258201bad 100644
@@ -132,7 +132,7 @@ unsafe impl Sync for MemoryRegion {}
 impl MemoryRegion {
     unsafe fn do_init_io(
         slot: *mut bindings::MemoryRegion,
-        owner: *mut bindings::Object,
+        owner: *mut qom::bindings::Object,
         ops: &'static bindings::MemoryRegionOps,
         name: &'static str,
         size: u64,
rust/util/Cargo.toml +1 -0
index 85f91436545..2ad5940daca 100644
@@ -18,6 +18,7 @@ foreign = { workspace = true }
 glib-sys = { workspace = true }
 libc = { workspace = true }
 common = { path = "../common" }
+util-sys = { path = "../bindings/util-sys" }
 
 [lints]
 workspace = true
rust/util/meson.build +2 -40

47 lines not on this page · raw message

rust/util/src/lib.rs +2 -1
index 7d2de3ed811..436c67e139e 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
-pub mod bindings;
+pub use util_sys as bindings;
+
 pub mod error;
 pub mod log;
 pub mod module;
Signature · 1 line
2.52.0
#4 lore raw

[PULL 13/13] rust/hpet: remove stale TODO comment

In reply to Paolo Bonzini

From: Mohd Kashif Khan <[email protected]>

The irq binding is already implemented in the following line, so the TODO comment is obsolete.

---
 rust/hw/timer/hpet/src/device.rs | 1 -
 1 file changed, 1 deletion(-)
rust/hw/timer/hpet/src/device.rs +0 -1
index 4757bf5fd55..ebf715d3995 100644
@@ -725,7 +725,6 @@ fn set_cfg_reg(&self, regs: &mut HPETRegisters, shift: u32, len: u32, val: u64)
             self.irqs[0].lower();
             self.irqs[RTC_ISA_IRQ].lower();
         } else if deactivating_bit(old_val, new_val, HPET_CFG_LEG_RT_SHIFT) {
-            // TODO: Add irq binding: qemu_irq_lower(s->irqs[0])
             self.irqs[0].lower();
             self.pit_enabled.set(true);
             self.irqs[RTC_ISA_IRQ].set(self.rtc_irq_level.get() != 0);
Signature · 1 line
2.52.0
#5 lore raw

[PULL 03/13] rust: move class_init to an extension trait

In reply to Paolo Bonzini

Prepare for having ObjectClass, DeviceClass and SysbusDeviceClass defined outside the hwcore and qom crates. It then becomes impossible to add a method to them.

Extracted from a patch by Marc-André Lureau.

---
 rust/hw/core/src/prelude.rs |  3 +++
 rust/hw/core/src/qdev.rs    | 25 +++++++++++++++----------
 rust/hw/core/src/sysbus.rs  | 10 +++++++---
 rust/qom/src/prelude.rs     |  1 +
 rust/qom/src/qom.rs         |  8 ++++++--
 5 files changed, 32 insertions(+), 15 deletions(-)
rust/hw/core/src/prelude.rs +3 -0
index c544c317b39..13f7dfc6809 100644
@@ -1,6 +1,8 @@
 //! Essential types and traits intended for blanket imports.
 
 pub use crate::qdev::Clock;
+
+pub use crate::qdev::DeviceClassExt;
 pub use crate::qdev::DeviceState;
 pub use crate::qdev::DeviceImpl;
 pub use crate::qdev::DeviceMethods;
@@ -8,6 +10,7 @@
 pub use crate::qdev::ResetType;
 
 pub use crate::sysbus::SysBusDevice;
+pub use crate::sysbus::SysBusDeviceClassExt;
 pub use crate::sysbus::SysBusDeviceImpl;
 pub use crate::sysbus::SysBusDeviceMethods;
 
rust/hw/core/src/qdev.rs +15 -10
index 87232becbad..f6037fbdcae 100644
@@ -15,9 +15,9 @@
 use qom::{prelude::*, ObjectClass};
 use util::{Error, Result};
 
-pub use crate::bindings::{ClockEvent, DeviceClass, Property, ResetType};
+pub use crate::bindings::{ClockEvent, ResetType};
 use crate::{
-    bindings::{self, qdev_init_gpio_in, qdev_init_gpio_out, ResettableClass},
+    bindings::{self, qdev_init_gpio_in, qdev_init_gpio_out, DeviceClass, Property},
     irq::InterruptSource,
 };
 
@@ -206,6 +206,9 @@ pub trait DeviceImpl:
     }
 }
 
+#[repr(transparent)]
+pub struct ResettableClass(bindings::ResettableClass);
+
 unsafe impl InterfaceType for ResettableClass {
     const TYPE_NAME: &'static CStr =
         unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_RESETTABLE_INTERFACE) };
@@ -214,23 +217,25 @@ unsafe impl InterfaceType for ResettableClass {
 impl ResettableClass {
     /// Fill in the virtual methods of `ResettableClass` based on the
     /// definitions in the `ResettablePhasesImpl` trait.
-    pub fn class_init<T: ResettablePhasesImpl>(&mut self) {
+    fn class_init<T: ResettablePhasesImpl>(&mut self) {
         if <T as ResettablePhasesImpl>::ENTER.is_some() {
-            self.phases.enter = Some(rust_resettable_enter_fn::<T>);
+            self.0.phases.enter = Some(rust_resettable_enter_fn::<T>);
         }
         if <T as ResettablePhasesImpl>::HOLD.is_some() {
-            self.phases.hold = Some(rust_resettable_hold_fn::<T>);
+            self.0.phases.hold = Some(rust_resettable_hold_fn::<T>);
         }
         if <T as ResettablePhasesImpl>::EXIT.is_some() {
-            self.phases.exit = Some(rust_resettable_exit_fn::<T>);
+            self.0.phases.exit = Some(rust_resettable_exit_fn::<T>);
         }
     }
 }
 
-impl DeviceClass {
-    /// Fill in the virtual methods of `DeviceClass` based on the definitions in
-    /// the `DeviceImpl` trait.
-    pub fn class_init<T: DeviceImpl>(&mut self) {
+pub trait DeviceClassExt {
+    fn class_init<T: DeviceImpl>(&mut self);
+}
+
+impl DeviceClassExt for DeviceClass {
+    fn class_init<T: DeviceImpl>(&mut self) {
         if <T as DeviceImpl>::REALIZE.is_some() {
             self.realize = Some(rust_realize_fn::<T>);
         }
rust/hw/core/src/sysbus.rs +7 -3
index 071fccff1e6..81fab3f1910 100644
@@ -15,7 +15,7 @@
 use crate::{
     bindings,
     irq::{IRQState, InterruptSource},
-    qdev::{DeviceImpl, DeviceState},
+    qdev::{DeviceClassExt, DeviceImpl, DeviceState},
 };
 
 /// A safe wrapper around [`bindings::SysBusDevice`].
@@ -37,10 +37,14 @@ unsafe impl ObjectType for SysBusDevice {
 // TODO: add virtual methods
 pub trait SysBusDeviceImpl: DeviceImpl + IsA<SysBusDevice> {}
 
-impl SysBusDeviceClass {
+pub trait SysBusDeviceClassExt {
+    fn class_init<T: SysBusDeviceImpl>(&mut self);
+}
+
+impl SysBusDeviceClassExt for SysBusDeviceClass {
     /// Fill in the virtual methods of `SysBusDeviceClass` based on the
     /// definitions in the `SysBusDeviceImpl` trait.
-    pub fn class_init<T: SysBusDeviceImpl>(self: &mut SysBusDeviceClass) {
+    fn class_init<T: SysBusDeviceImpl>(&mut self) {
         self.parent_class.class_init::<T>();
     }
 }
rust/qom/src/prelude.rs +1 -0
index 6a1ecaef2a7..1d1177f1e0d 100644
@@ -4,6 +4,7 @@
 pub use crate::qom::IsA;
 pub use crate::qom::Object;
 pub use crate::qom::ObjectCast;
+pub use crate::qom::ObjectClassExt;
 pub use crate::qom::ObjectClassMethods;
 pub use crate::qom::ObjectDeref;
 pub use crate::qom::ObjectImpl;
rust/qom/src/qom.rs +6 -2
index 84455cea79b..cc00ddcfc98 100644
@@ -729,10 +729,14 @@ pub trait ObjectImpl: ObjectType + IsA<Object> {
     T::UNPARENT.unwrap()(unsafe { state.as_ref() });
 }
 
-impl ObjectClass {
+pub trait ObjectClassExt {
+    fn class_init<T: ObjectImpl>(&mut self);
+}
+
+impl ObjectClassExt for ObjectClass {
     /// Fill in the virtual methods of `ObjectClass` based on the definitions in
     /// the `ObjectImpl` trait.
-    pub fn class_init<T: ObjectImpl>(&mut self) {
+    fn class_init<T: ObjectImpl>(&mut self) {
         if <T as ObjectImpl>::UNPARENT.is_some() {
             self.unparent = Some(rust_unparent_fn::<T>);
         }
Signature · 1 line
2.52.0
#6 lore raw

[PULL 07/13] target/i386/tcg: fix a few instructions that do not support VEX.L=1

In reply to Paolo Bonzini

Match the contents of table 2-17 ("#UD Exception and VEX.L Field Encoding") in the SDM, for instruction in exception class 5. They were incorrectly accepting 256-bit versions that do not exist.

---
 target/i386/tcg/decode-new.c.inc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
target/i386/tcg/decode-new.c.inc +4 -4
index 09e3d8884cf..e44b92710cf 100644
@@ -628,7 +628,7 @@ static void decode_0F7E(DisasContext *s, CPUX86State *env, X86OpEntry *entry, ui
     static const X86OpEntry opcodes_0F7E[4] = {
         X86_OP_ENTRY3(MOVD_from,  E,y, None,None, P,y, vex5 mmx),
         X86_OP_ENTRY3(MOVD_from,  E,y, None,None, V,y, vex5),
-        X86_OP_ENTRY3(MOVQ,       V,x, None,None, W,q, vex5),  /* wrong dest Vy on SDM! */
+        X86_OP_ENTRY3(MOVQ,       V,dq,None,None, W,q, vex5),  /* wrong dest Vq on SDM! */
         {},
     };
     *entry = *decode_by_prefix(s, opcodes_0F7E);
@@ -693,7 +693,7 @@ static void decode_0FD6(DisasContext *s, CPUX86State *env, X86OpEntry *entry, ui
 {
     static const X86OpEntry movq[4] = {
         {},
-        X86_OP_ENTRY3(MOVQ,    W,x,  None, None, V,q, vex5),
+        X86_OP_ENTRY3(MOVQ,    W,dq, None, None, V,q, vex5),
         X86_OP_ENTRY3(MOVq_dq, V,dq, None, None, N,q),
         X86_OP_ENTRY3(MOVq_dq, P,q,  None, None, U,q),
     };
@@ -1102,7 +1102,7 @@ static void decode_0F12(DisasContext *s, CPUX86State *env, X86OpEntry *entry, ui
     };
     static const X86OpEntry opcodes_0F12_reg[4] = {
         X86_OP_ENTRY3(VMOVHLPS,  V,dq, H,dq,       U,dq, vex7),
-        X86_OP_ENTRY3(VMOVLPx,   W,x,  H,x,        U,q,  vex5), /* MOVLPD */
+        X86_OP_ENTRY3(VMOVLPx,   W,dq, H,dq,       U,q,  vex5), /* MOVLPD */
         X86_OP_ENTRY3(VMOVSLDUP, V,x,  None,None,  U,x,  vex4 cpuid(SSE3)),
         X86_OP_ENTRY3(VMOVDDUP,  V,x,  None,None,  U,x,  vex5 cpuid(SSE3)),
     };
@@ -1465,7 +1465,7 @@ static const X86OpEntry opcodes_0F[256] = {
     [0x6b] = X86_OP_ENTRY3(PACKSSDW,   V,x, H,x, W,x,  vex4 mmx avx2_256 p_00_66),
     [0x6c] = X86_OP_ENTRY3(PUNPCKLQDQ, V,x, H,x, W,x,  vex4 p_66 avx2_256),
     [0x6d] = X86_OP_ENTRY3(PUNPCKHQDQ, V,x, H,x, W,x,  vex4 p_66 avx2_256),
-    [0x6e] = X86_OP_ENTRY3(MOVD_to,    V,x, None,None, E,y, vex5 mmx p_00_66),  /* wrong dest Vy on SDM! */
+    [0x6e] = X86_OP_ENTRY3(MOVD_to,    V,dq,None,None, E,y, vex5 mmx p_00_66),  /* wrong dest Vy on SDM! */
     [0x6f] = X86_OP_GROUP0(0F6F),
 
     [0x78] = X86_OP_GROUP0(0F78),
Signature · 1 line
2.52.0
#7 lore raw

[PULL 12/13] target/i386/tcg: cleanup #ifdef TARGET_X86_64

In reply to Paolo Bonzini

32-bit TCG opcodes produced for the i386 target usually looks the same as 64-bit TCG opcodes produced for the x86_64. The special one that needs extensions is 32-bit TCG opcodes produced for the x86_64 target. Make all #ifdefs look the same, like this:

    case MO_32:
  #ifdef TARGET_X86_64
      /* code using 32-bit opcodes */

    case MO_64:
  #endif
      /* code using target_long opcodes */
  default:
    g_assert_not_reached();
---
 target/i386/tcg/translate.c | 11 ++++++-----
 target/i386/tcg/emit.c.inc  | 18 ++++++++++++------
 2 files changed, 18 insertions(+), 11 deletions(-)
target/i386/tcg/translate.c +6 -5
index 20aa94347b0..7186517239c 100644
@@ -430,17 +430,15 @@ static TCGv gen_op_deposit_reg_v(DisasContext *s, MemOp ot, int reg, TCGv dest,
         tcg_gen_deposit_tl(dest, cpu_regs[reg], t0, 0, 16);
         break;
     case MO_32:
-        /* For x86_64, this sets the higher half of register to zero.
-           For i386, this is equivalent to a mov. */
+#ifdef TARGET_X86_64
         dest = dest ? dest : cpu_regs[reg];
         tcg_gen_ext32u_tl(dest, t0);
         break;
-#ifdef TARGET_X86_64
     case MO_64:
+#endif
         dest = dest ? dest : cpu_regs[reg];
         tcg_gen_mov_tl(dest, t0);
         break;
-#endif
     default:
         g_assert_not_reached();
     }
@@ -1585,8 +1583,8 @@ static TCGv gen_shiftd_rm_T1(DisasContext *s, MemOp ot,
             tcg_gen_shri_i64(s->T0, s->T0, 32);
         }
         break;
+    case MO_64:
 #endif
-    default:
         hishift = tcg_temp_new();
         tcg_gen_subi_tl(tmp, count, 1);
         if (is_right) {
@@ -1615,6 +1613,9 @@ static TCGv gen_shiftd_rm_T1(DisasContext *s, MemOp ot,
                            tcg_constant_tl(0), s->T1);
         tcg_gen_or_tl(s->T0, s->T0, s->T1);
         break;
+
+    default:
+	g_assert_not_reached();
     }
 
     return cc_src;
target/i386/tcg/emit.c.inc +12 -6
index f23c401189b..ce636b6c56c 100644
@@ -1236,8 +1236,8 @@ static void gen_ADCOX(DisasContext *s, X86DecodedInsn *decode, int cc_op)
     }
 
     switch (ot) {
-#ifdef TARGET_X86_64
     case MO_32:
+#ifdef TARGET_X86_64
         /* If TL is 64-bit just do everything in 64-bit arithmetic.  */
         tcg_gen_ext32u_tl(s->T0, s->T0);
         tcg_gen_ext32u_tl(s->T1, s->T1);
@@ -1245,12 +1245,16 @@ static void gen_ADCOX(DisasContext *s, X86DecodedInsn *decode, int cc_op)
         tcg_gen_add_i64(s->T0, s->T0, carry_in);
         tcg_gen_shri_i64(*carry_out, s->T0, 32);
         break;
+
+    case MO_64:
 #endif
-    default:
         zero = tcg_constant_tl(0);
         tcg_gen_add2_tl(s->T0, *carry_out, s->T0, zero, carry_in, zero);
         tcg_gen_add2_tl(s->T0, *carry_out, s->T0, *carry_out, s->T1, zero);
         break;
+
+    default:
+        g_assert_not_reached();
     }
 }
 
@@ -1991,7 +1995,6 @@ static void gen_DIV(DisasContext *s, X86DecodedInsn *decode)
     case MO_16:
         gen_helper_divw_AX(tcg_env, s->T0);
         break;
-    default:
     case MO_32:
         gen_helper_divl_EAX(tcg_env, s->T0);
         break;
@@ -2000,6 +2003,8 @@ static void gen_DIV(DisasContext *s, X86DecodedInsn *decode)
         gen_helper_divq_EAX(tcg_env, s->T0);
         break;
 #endif
+    default:
+        g_assert_not_reached();
     }
 }
 
@@ -2065,7 +2070,6 @@ static void gen_IDIV(DisasContext *s, X86DecodedInsn *decode)
     case MO_16:
         gen_helper_idivw_AX(tcg_env, s->T0);
         break;
-    default:
     case MO_32:
         gen_helper_idivl_EAX(tcg_env, s->T0);
         break;
@@ -2074,6 +2078,8 @@ static void gen_IDIV(DisasContext *s, X86DecodedInsn *decode)
         gen_helper_idivq_EAX(tcg_env, s->T0);
         break;
 #endif
+    default:
+        g_assert_not_reached();
     }
 }
 
@@ -2876,7 +2882,7 @@ static inline void gen_pextr(DisasContext *s, X86DecodedInsn *decode, MemOp ot)
         tcg_gen_ld_tl(s->T0, tcg_env, vector_elem_offset(&decode->op[1], ot, val));
         break;
     default:
-        abort();
+        g_assert_not_reached();
     }
 }
 
@@ -2923,7 +2929,7 @@ static inline void gen_pinsr(DisasContext *s, X86DecodedInsn *decode, MemOp ot)
         tcg_gen_st_tl(s->T1, tcg_env, vector_elem_offset(&decode->op[0], ot, val));
         break;
     default:
-        abort();
+        g_assert_not_reached();
     }
 }
 
Signature · 1 line
2.52.0
#8 lore raw

[PULL 08/13] target/i386/tcg: fix typo in dpps/dppd instructions

In reply to Paolo Bonzini

Their gen_* functions were incorrectly named gen_VDDPS and gen_VDDPD.

---
 target/i386/tcg/decode-new.c.inc | 4 ++--
 target/i386/tcg/emit.c.inc       | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
target/i386/tcg/decode-new.c.inc +2 -2
index e44b92710cf..b00ea3e86e8 100644
@@ -977,8 +977,8 @@ static const X86OpEntry opcodes_0F3A[256] = {
     [0x21] = X86_OP_GROUP0(VINSERTPS),
     [0x22] = X86_OP_ENTRY4(PINSR,      V,dq, H,dq, E,y,  vex5 cpuid(SSE41) p_66),
 
-    [0x40] = X86_OP_ENTRY4(VDDPS,      V,x,  H,x,  W,x,  vex2 cpuid(SSE41) p_66),
-    [0x41] = X86_OP_ENTRY4(VDDPD,      V,dq, H,dq, W,dq, vex2 cpuid(SSE41) p_66),
+    [0x40] = X86_OP_ENTRY4(VDPPS,      V,x,  H,x,  W,x,  vex2 cpuid(SSE41) p_66),
+    [0x41] = X86_OP_ENTRY4(VDPPD,      V,dq, H,dq, W,dq, vex2 cpuid(SSE41) p_66),
     [0x42] = X86_OP_ENTRY4(VMPSADBW,   V,x,  H,x,  W,x,  vex2 cpuid(SSE41) avx2_256 p_66),
     [0x44] = X86_OP_ENTRY4(PCLMULQDQ,  V,dq, H,dq, W,dq, vex4 cpuid(PCLMULQDQ) p_66),
     [0x46] = X86_OP_ENTRY4(VPERM2x128, V,qq, H,qq, W,qq, vex6 chk(W0) cpuid(AVX2) p_66),
target/i386/tcg/emit.c.inc +2 -2
index 639a1eb638f..f23c401189b 100644
@@ -788,9 +788,9 @@ static void gen_##uname(DisasContext *s, X86DecodedInsn *decode)
 BINARY_IMM_SSE(VBLENDPD,   blendpd)
 BINARY_IMM_SSE(VBLENDPS,   blendps)
 BINARY_IMM_SSE(VPBLENDW,   pblendw)
-BINARY_IMM_SSE(VDDPS,      dpps)
+BINARY_IMM_SSE(VDPPS,      dpps)
 #define gen_helper_dppd_ymm NULL
-BINARY_IMM_SSE(VDDPD,      dppd)
+BINARY_IMM_SSE(VDPPD,      dppd)
 BINARY_IMM_SSE(VMPSADBW,   mpsadbw)
 BINARY_IMM_SSE(PCLMULQDQ,  pclmulqdq)
 
Signature · 1 line
2.52.0
#9 lore raw

[PULL 05/13] rust: move hwcore::sysbus to system crate

In reply to Paolo Bonzini

This inverts the dependency from hwcore to system, replacing it with a dependency from system to hwcore. It also matches how hw/core/sysbus.h is part of the system-sys crate, and hw/core/sysbus.c is part of system_ss on the C side.

This fixes a linker error in hwcore integration tests on msys2.

---
 rust/hw/core/Cargo.toml                | 1 -
 rust/hw/core/meson.build               | 2 +-
 rust/hw/core/src/irq.rs                | 8 ++++----
 rust/hw/core/src/lib.rs                | 3 ---
 rust/hw/core/src/prelude.rs            | 5 -----
 rust/hw/core/tests/tests.rs            | 4 ++--
 rust/meson.build                       | 2 +-
 rust/system/Cargo.toml                 | 1 +
 rust/system/meson.build                | 2 +-
 rust/system/src/lib.rs                 | 3 +++
 rust/system/src/prelude.rs             | 5 +++++
 rust/{hw/core => system}/src/sysbus.rs | 7 ++-----
 12 files changed, 20 insertions(+), 23 deletions(-)
 rename rust/{hw/core => system}/src/sysbus.rs (96%)
rust/hw/core/Cargo.toml +0 -1
index 8cc514da202..d1ff71d5c37 100644
@@ -21,7 +21,6 @@ bql = { path = "../../bql" }
 qom = { path = "../../qom" }
 chardev = { path = "../../chardev" }
 migration = { path = "../../migration" }
-system = { path = "../../system" }
 util = { path = "../../util" }
 
 [lints]
rust/hw/core/meson.build +1 -1
index 28ea00cdb4f..6d1bfd4d204 100644
@@ -3,7 +3,7 @@ _hwcore_rs = static_library(
   'src/lib.rs',
   override_options: ['rust_std=2021', 'build.rust_std=2021'],
   rust_abi: 'rust',
-  link_with: [_bql_rs, _chardev_rs, _migration_rs, _qom_rs, _system_rs, _util_rs],
+  link_with: [_bql_rs, _chardev_rs, _migration_rs, _qom_rs, _util_rs],
   dependencies: [glib_sys_rs, qemu_macros, common_rs, hwcore_sys_rs],
 )
 
rust/hw/core/src/irq.rs +4 -4
index e0d7784d97b..13ace921824 100644
@@ -33,10 +33,10 @@
 ///
 /// Interrupts are implemented as a pointer to the interrupt "sink", which has
 /// type [`IRQState`].  A device exposes its source as a QOM link property using
-/// a function such as [`crate::sysbus::SysBusDeviceMethods::init_irq`], and
+/// a function such as [`crate::DeviceMethods::init_gpio_out`], and
 /// initially leaves the pointer to a NULL value, representing an unconnected
 /// interrupt. To connect it, whoever creates the device fills the pointer with
-/// the sink's `IRQState *`, for example using `sysbus_connect_irq`.  Because
+/// the sink's `IRQState *`, for example using `qdev_connect_gpio_out`.  Because
 /// devices are generally shared objects, interrupt sources are an example of
 /// the interior mutability pattern.
 ///
@@ -87,11 +87,11 @@ pub fn set(&self, level: T) {
         }
     }
 
-    pub(crate) const fn as_ptr(&self) -> *mut *mut bindings::IRQState {
+    pub const fn as_ptr(&self) -> *mut *mut bindings::IRQState {
         self.cell.as_ptr()
     }
 
-    pub(crate) const fn slice_as_ptr(slice: &[Self]) -> *mut *mut bindings::IRQState {
+    pub const fn slice_as_ptr(slice: &[Self]) -> *mut *mut bindings::IRQState {
         assert!(!slice.is_empty());
         slice[0].as_ptr()
     }
rust/hw/core/src/lib.rs +0 -3
index 76689fe7db1..6701dc52b65 100644
@@ -14,6 +14,3 @@
 
 mod qdev;
 pub use qdev::*;
-
-mod sysbus;
-pub use sysbus::*;
rust/hw/core/src/prelude.rs +0 -5
index 13f7dfc6809..45e86e178b1 100644
@@ -9,9 +9,4 @@
 pub use crate::qdev::ResettablePhasesImpl;
 pub use crate::qdev::ResetType;
 
-pub use crate::sysbus::SysBusDevice;
-pub use crate::sysbus::SysBusDeviceClassExt;
-pub use crate::sysbus::SysBusDeviceImpl;
-pub use crate::sysbus::SysBusDeviceMethods;
-
 pub use crate::irq::InterruptSource;
rust/hw/core/tests/tests.rs +2 -2
index 115dd7a860d..05aa5d4a377 100644
@@ -142,7 +142,7 @@ fn test_cast() {
     let obj_ref: &Object = p_ref.upcast();
     assert_eq!(addr_of!(*obj_ref), p_ptr.cast());
 
-    let sbd_ref: Option<&SysBusDevice> = obj_ref.dynamic_cast();
+    let sbd_ref: Option<&DummyChildState> = obj_ref.dynamic_cast();
     assert!(sbd_ref.is_none());
 
     let dev_ref: Option<&DeviceState> = obj_ref.downcast();
@@ -150,7 +150,7 @@ fn test_cast() {
 
     // SAFETY: the cast is wrong, but the value is only used for comparison
     unsafe {
-        let sbd_ref: &SysBusDevice = obj_ref.unsafe_cast();
+        let sbd_ref: &DummyChildState = obj_ref.unsafe_cast();
         assert_eq!(addr_of!(*sbd_ref), p_ptr.cast());
     }
 }
rust/meson.build +1 -1
index 3a3e10d7b97..b6711fe77dd 100644
@@ -42,9 +42,9 @@ subdir('util')
 subdir('bql')
 subdir('migration')
 subdir('qom')
-subdir('system')
 subdir('chardev')
 subdir('hw/core')
+subdir('system')
 subdir('tests')
 subdir('trace')
 subdir('hw')
rust/system/Cargo.toml +1 -0
index f7fde9782ea..d6217370317 100644
@@ -16,6 +16,7 @@ rust-version.workspace = true
 common = { path = "../common" }
 system-sys = { path = "../bindings/system-sys" }
 bql = { path = "../bql" }
+hwcore = { path = "../hw/core" }
 migration = { path = "../migration" }
 qom = { path = "../qom" }
 util = { path = "../util" }
rust/system/meson.build +1 -1
index 4cbd63cbbd7..89c1f2b84d1 100644
@@ -1,7 +1,7 @@
 _system_rs = static_library(
   'system',
   'src/lib.rs',
-  link_with: [_bql_rs, _migration_rs, _qom_rs, _util_rs],
+  link_with: [_bql_rs, _hwcore_rs, _migration_rs, _qom_rs, _util_rs],
   dependencies: [glib_sys_rs, common_rs, qemu_macros, system_sys_rs],
 )
 
rust/system/src/lib.rs +3 -0
index 10741e0ee0a..3b1666e62ce 100644
@@ -9,3 +9,6 @@
 // for prelude-like modules
 #[rustfmt::skip]
 pub mod prelude;
+
+mod sysbus;
+pub use sysbus::*;
rust/system/src/prelude.rs +5 -0
index 2d98524c36e..5a8688ca343 100644
@@ -6,3 +6,8 @@
 pub use crate::memory::MemoryRegionOps;
 pub use crate::memory::MemoryRegionOpsBuilder;
 pub use crate::memory::MemTxAttrs;
+
+pub use crate::sysbus::SysBusDevice;
+pub use crate::sysbus::SysBusDeviceClassExt;
+pub use crate::sysbus::SysBusDeviceImpl;
+pub use crate::sysbus::SysBusDeviceMethods;
rust/system/src/sysbus.rs renamed from rust/hw/core/src/sysbus.rs +2 -5
similarity index 96%
rename from rust/hw/core/src/sysbus.rs
rename to rust/system/src/sysbus.rs
index 7db09a82c63..3c9aff51be0 100644
@@ -7,15 +7,12 @@
 use std::ffi::CStr;
 
 use common::Opaque;
+use hwcore::{prelude::*, IRQState};
 use qom::prelude::*;
-use system::MemoryRegion;
 pub use system_sys::SysBusDeviceClass;
 use util::{Error, Result};
 
-use crate::{
-    irq::{IRQState, InterruptSource},
-    qdev::{DeviceClassExt, DeviceImpl, DeviceState},
-};
+use crate::MemoryRegion;
 
 /// A safe wrapper around [`system_sys::SysBusDevice`].
 #[repr(transparent)]
Signature · 1 line
2.52.0
#10 lore raw

[PULL 10/13] target/i386/tcg: merge decode_modrm and decode_modrm_address split

In reply to Paolo Bonzini

Unlike the older code in translate.c, mod=11b *is* filtered out earlier by decode_modrm, and it would have returned bogus code. Since the register case is so simple, just inline decode_modrm_address into its caller instead of removing the "if".

---
 target/i386/tcg/decode-new.c.inc | 64 ++++++++++++--------------------
 1 file changed, 24 insertions(+), 40 deletions(-)
target/i386/tcg/decode-new.c.inc +24 -40
index b00ea3e86e8..662d1d707d0 100644
@@ -2007,33 +2007,34 @@ static void decode_root(DisasContext *s, CPUX86State *env, X86OpEntry *entry, ui
     *entry = opcodes_root[*b];
 }
 
-/* Decompose an address.  */
-static AddressParts decode_modrm_address(CPUX86State *env, DisasContext *s,
-                                         int modrm, bool is_vsib)
+/* Decode the MODRM and SIB bytes into a register or memory operand.  */
+static void decode_modrm(DisasContext *s, CPUX86State *env,
+                         X86DecodedInsn *decode, X86DecodedOp *op)
 {
-    int def_seg, base, index, scale, mod, rm;
-    target_long disp;
-    bool havesib;
-
-    def_seg = R_DS;
-    index = -1;
-    scale = 0;
-    disp = 0;
-
-    mod = (modrm >> 6) & 3;
-    rm = modrm & 7;
-    base = rm | REX_B(s);
+    int modrm = get_modrm(s, env);
+    int mod = (modrm >> 6) & 3;
+    int rm = modrm & 7;
+    bool is_vsib = decode->e.vex_class == 12;
+    bool havesib = false;
 
     if (mod == 3) {
-        /* Normally filtered out earlier, but including this path
-           simplifies multi-byte nop, as well as bndcl, bndcu, bndcn.  */
-        goto done;
+        op->n = rm;
+        if (op->unit != X86_OP_MMX) {
+            op->n |= REX_B(s);
+        }
+	return;
     }
 
+    /* Decompose an address.  */
+    int def_seg = R_DS;
+    int base = rm | REX_B(s);
+    int index = -1;
+    int scale = 0;
+    target_ulong disp = 0;
+
     switch (s->aflag) {
     case MO_64:
     case MO_32:
-        havesib = 0;
         if (rm == 4) {
             int code = x86_ldub_code(env, s);
             scale = (code >> 6) & 3;
@@ -2042,7 +2043,7 @@ static AddressParts decode_modrm_address(CPUX86State *env, DisasContext *s,
                 index = -1;  /* no index */
             }
             base = (code & 7) | REX_B(s);
-            havesib = 1;
+            havesib = true;
         }
 
         switch (mod) {
@@ -2127,26 +2128,9 @@ static AddressParts decode_modrm_address(CPUX86State *env, DisasContext *s,
         g_assert_not_reached();
     }
 
- done:
-    return (AddressParts){ def_seg, base, index, scale, disp };
-}
-
-static int decode_modrm(DisasContext *s, CPUX86State *env,
-                        X86DecodedInsn *decode, X86DecodedOp *op)
-{
-    int modrm = get_modrm(s, env);
-    if ((modrm >> 6) == 3) {
-        op->n = (modrm & 7);
-        if (op->unit != X86_OP_MMX) {
-            op->n |= REX_B(s);
-        }
-    } else {
-        op->has_ea = true;
-        op->n = -1;
-        decode->mem = decode_modrm_address(env, s, get_modrm(s, env),
-                                           decode->e.vex_class == 12);
-    }
-    return modrm;
+    op->has_ea = true;
+    op->n = -1;
+    decode->mem = (AddressParts){ def_seg, base, index, scale, disp };
 }
 
 static bool decode_op_size(DisasContext *s, X86OpEntry *e, X86OpSize size, MemOp *ot)
Signature · 1 line
2.52.0
#11 lore raw

[PULL 06/13] qdev: add hw/core/gpio.c to libhwcore

In reply to Paolo Bonzini

While GPIO functionality is not used by user-mode emulation, it is conceptually part of qdev - GPIO pins are included in DeviceState independent of whether this is system or user-mode emulation.

For the Rust bindings, having GPIO functionality in system_ss causes a problem because, for simplicity, all methods of DeviceState are included in the Rust hwcore crate. On Windows, rustc is not able to do dead code elimination as well as on other OSes and this causes an undefined symbol error, because gpio.c is not linked into the rust/hw/core/rust-hwcore-rs-integration test binary.

To fix it, move gpio.c out of system_ss and into libhwcore. Alternatively, it would be possible to define some DeviceState methods also in the system crate, using for example a separate trace SystemDeviceMethods. For now, keep all the methods in one crate and link 200 unused lines of code into user-mode emulators.

---
 hw/core/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/meson.build +1 -1
index b5a545a0edd..8a96567de8f 100644
@@ -1,6 +1,7 @@
 # core qdev-related obj files, also used by *-user and unit tests
 hwcore_ss.add(files(
   'bus.c',
+  'gpio.c',
   'qdev-properties.c',
   'qdev.c',
   'resetcontainer.c',
@@ -29,7 +30,6 @@ system_ss.add(when: 'CONFIG_EIF', if_true: [files('eif.c'), zlib, libcbor, gnutl
 system_ss.add(files(
   'cpu-system.c',
   'fw-path-provider.c',
-  'gpio.c',
   'hotplug.c',
   'loader.c',
   'machine-hmp-cmds.c',
Signature · 1 line
2.52.0
#12 lore raw

[PULL 09/13] target/i386/tcg: remove dead constants

In reply to Paolo Bonzini

NB_OP_SIZES has been dead since the conversion to TCG, REG_L_OFFSET since 2015, the others somewhere in the middle.

---
 target/i386/tcg/translate.c | 24 ------------------------
 1 file changed, 24 deletions(-)
target/i386/tcg/translate.c +0 -24
index 460848e4223..20aa94347b0 100644
@@ -374,30 +374,6 @@ static void gen_update_cc_op(DisasContext *s)
     }
 }
 
-#ifdef TARGET_X86_64
-
-#define NB_OP_SIZES 4
-
-#else /* !TARGET_X86_64 */
-
-#define NB_OP_SIZES 3
-
-#endif /* !TARGET_X86_64 */
-
-#if HOST_BIG_ENDIAN
-#define REG_B_OFFSET (sizeof(target_ulong) - 1)
-#define REG_H_OFFSET (sizeof(target_ulong) - 2)
-#define REG_W_OFFSET (sizeof(target_ulong) - 2)
-#define REG_L_OFFSET (sizeof(target_ulong) - 4)
-#define REG_LH_OFFSET (sizeof(target_ulong) - 8)
-#else
-#define REG_B_OFFSET 0
-#define REG_H_OFFSET 1
-#define REG_W_OFFSET 0
-#define REG_L_OFFSET 0
-#define REG_LH_OFFSET 4
-#endif
-
 /* In instruction encodings for byte register accesses the
  * register number usually indicates "low 8 bits of register N";
  * however there are some special cases where N 4..7 indicates
Signature · 1 line
2.52.0
#13 lore raw

[PULL 01/13] rust: trace: libc does not have syslog on windows

In reply to Paolo Bonzini
---
 rust/trace/src/lib.rs | 1 +
 1 file changed, 1 insertion(+)
rust/trace/src/lib.rs +1 -0
index c2abe430a52..859d8d1b94f 100644
@@ -3,6 +3,7 @@
 //! This crate provides macros that aid in using QEMU's tracepoint
 //! functionality.
 
+#[cfg(not(windows))]
 #[doc(hidden)]
 /// Re-exported item to avoid adding libc as a dependency everywhere.
 pub use libc::{syslog, LOG_INFO};
Signature · 1 line
2.52.0
#14 lore raw
In reply to Paolo Bonzini
Quoted 10 lines · Paolo Bonzini

The following changes since commit f26976b9d30496d28bd4fd045f4300706e567a29:

   Merge tag 'pull-vfio-20260126' ofhttps://github.com/legoater/qemu into staging (2026-01-27 07:14:11 +1100)

are available in the Git repository at:

https://gitlab.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to df8dfc3b6080713c2dbd7ef37c2c85a78e502cd6:

Quoted 7 lines
   rust/hpet: remove stale TODO comment (2026-01-27 10:37:11 +0100)

----------------------------------------------------------------
* rust: move binding generation to bindings/
* rust: fixes for Windows
* target/i386/tcg: fix a few instructions that do not support VEX.L=1
* target/i386/tcg: various cleanups

Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/11.0 as appropriate.

r~