F: rust/qemu-api-macros
F: rust/qom/
F: rust/rustfmt.toml
+F: rust/system/
F: rust/util/
F: scripts/get-wraps-from-cargo-registry.py
"qemu_api",
"qemu_api_macros",
"qom",
+ "system",
"util",
]
"qemu_api",
"qemu_api_macros",
"qom",
+ "system",
"util",
]
"migration",
"qemu_api_macros",
"qom",
+ "system",
"util",
]
"unicode-ident",
]
+[[package]]
+name = "system"
+version = "0.1.0"
+dependencies = [
+ "common",
+ "qemu_api_macros",
+ "qom",
+ "util",
+]
+
[[package]]
name = "unicode-ident"
version = "1.0.12"
"qemu-api-macros",
"qemu-api",
"qom",
+ "system",
"hw/char/pl011",
"hw/timer/hpet",
"util",
//!
//! ```ignore
//! # use bql::BqlRefCell;
-//! # use qemu_api::prelude::*;
-//! # use qemu_api::{irq::InterruptSource, irq::IRQState};
-//! # use qemu_api::{sysbus::SysBusDevice, qom::Owned, qom::ParentField};
+//! # use qom::{Owned, ParentField};
+//! # use system::{InterruptSource, IRQState, SysBusDevice};
//! # const N_GPIOS: usize = 8;
//! # struct PL061Registers { /* ... */ }
//! # unsafe impl ObjectType for PL061State {
migration = { path = "../../../migration" }
qom = { path = "../../../qom" }
chardev = { path = "../../../chardev" }
+system = { path = "../../../system" }
qemu_api = { path = "../../../qemu-api" }
qemu_api_macros = { path = "../../../qemu-api-macros" }
qemu_api_macros,
qom_rs,
chardev_rs,
+ system_rs,
],
)
};
use qemu_api::{
irq::{IRQState, InterruptSource},
- memory::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder},
prelude::*,
qdev::{Clock, ClockEvent, DeviceImpl, DeviceState, ResetType, ResettablePhasesImpl},
sysbus::{SysBusDevice, SysBusDeviceImpl},
};
use qom::{prelude::*, ObjectImpl, Owned, ParentField, ParentInit};
+use system::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder};
use util::{log::Log, log_mask_ln};
use crate::registers::{self, Interrupt, RegisterOffset};
migration = { path = "../../../migration" }
bql = { path = "../../../bql" }
qom = { path = "../../../qom" }
+system = { path = "../../../system" }
qemu_api = { path = "../../../qemu-api" }
qemu_api_macros = { path = "../../../qemu-api-macros" }
bql_rs,
qemu_api_macros,
qom_rs,
+ system_rs,
],
)
VMStateDescription, VMStateDescriptionBuilder,
};
use qemu_api::{
- bindings::{
- address_space_memory, address_space_stl_le, qdev_prop_bit, qdev_prop_bool,
- qdev_prop_uint32, qdev_prop_usize,
- },
+ bindings::{qdev_prop_bit, qdev_prop_bool, qdev_prop_uint32, qdev_prop_usize},
irq::InterruptSource,
- memory::{
- hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder, MEMTXATTRS_UNSPECIFIED,
- },
prelude::*,
qdev::{DeviceImpl, DeviceState, Property, ResetType, ResettablePhasesImpl},
sysbus::{SysBusDevice, SysBusDeviceImpl},
};
use qom::{prelude::*, ObjectImpl, ParentField, ParentInit};
+use system::{
+ bindings::{address_space_memory, address_space_stl_le, hwaddr},
+ MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder, MEMTXATTRS_UNSPECIFIED,
+};
use util::timer::{Timer, CLOCK_VIRTUAL, NANOSECONDS_PER_SECOND};
use crate::fw_cfg::HPETFwConfig;
subdir('migration')
subdir('bql')
subdir('qom')
+subdir('system')
subdir('chardev')
subdir('qemu-api')
util = { path = "../util" }
bql = { path = "../bql" }
qom = { path = "../qom" }
+system = { path = "../system" }
qemu_api_macros = { path = "../qemu-api-macros" }
[lints]
'MachineInitPhase',
'MemoryDeviceInfoKind',
'ResetType',
- 'device_endian',
]
_qemu_api_bindgen_args = []
foreach enum : c_enums
blocked_type = [
'Chardev',
'Error',
+ 'MemTxAttrs',
+ 'MemoryRegion',
'ObjectClass',
'VMStateDescription',
+ 'device_endian',
]
foreach type: blocked_type
_qemu_api_bindgen_args += ['--blocklist-type', type]
'src/lib.rs',
'src/bindings.rs',
'src/irq.rs',
- 'src/memory.rs',
'src/prelude.rs',
'src/qdev.rs',
'src/sysbus.rs',
rust_abi: 'rust',
rust_args: _qemu_api_cfg,
dependencies: [anyhow_rs, bql_rs, chardev_rs, common_rs, foreign_rs, libc_rs, migration_rs, qemu_api_macros,
- qom_rs, util_rs, hwcore],
+ qom_rs, system_rs, util_rs, hwcore],
)
qemu_api_rs = declare_dependency(link_with: [_qemu_api_rs],
use common::Zeroable;
use migration::bindings::VMStateDescription;
use qom::bindings::ObjectClass;
+use system::bindings::{device_endian, MemTxAttrs, MemoryRegion};
use util::bindings::Error;
#[cfg(MESON)]
#[cfg(not(MESON))]
include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs"));
-// SAFETY: this is a pure data struct
-unsafe impl Send for CoalescedMemoryRange {}
-unsafe impl Sync for CoalescedMemoryRange {}
-
-// SAFETY: these are constants and vtables; the Send and Sync requirements
-// are deferred to the unsafe callbacks that they contain
-unsafe impl Send for MemoryRegionOps {}
-unsafe impl Sync for MemoryRegionOps {}
-
unsafe impl Send for Property {}
unsafe impl Sync for Property {}
unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 {}
unsafe impl Zeroable for crate::bindings::Property {}
-unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_1 {}
-unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 {}
-unsafe impl Zeroable for crate::bindings::MemoryRegionOps {}
-unsafe impl Zeroable for crate::bindings::MemTxAttrs {}
pub mod prelude;
pub mod irq;
-pub mod memory;
pub mod qdev;
pub mod sysbus;
pub use bindings::SysBusDeviceClass;
use common::Opaque;
use qom::{prelude::*, Owned};
+use system::MemoryRegion;
use crate::{
bindings,
irq::{IRQState, InterruptSource},
- memory::MemoryRegion,
qdev::{DeviceImpl, DeviceState},
};
#include "qemu/osdep.h"
#include "qemu-io.h"
-#include "system/system.h"
#include "hw/sysbus.h"
-#include "system/memory.h"
#include "hw/clock.h"
#include "hw/qdev-clock.h"
#include "hw/qdev-properties.h"
#include "hw/qdev-properties-system.h"
#include "hw/irq.h"
#include "exec/memattrs.h"
-#include "system/address-spaces.h"
#include "hw/char/pl011.h"
--- /dev/null
+[package]
+name = "system"
+version = "0.1.0"
+description = "Rust bindings for QEMU/system"
+resolver = "2"
+publish = false
+
+authors.workspace = true
+edition.workspace = true
+homepage.workspace = true
+license.workspace = true
+repository.workspace = true
+rust-version.workspace = true
+
+[dependencies]
+common = { path = "../common" }
+qom = { path = "../qom" }
+util = { path = "../util" }
+qemu_api_macros = { path = "../qemu-api-macros" }
+
+[lints]
+workspace = true
--- /dev/null
+../util/build.rs
\ No newline at end of file
--- /dev/null
+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,
+)
+
+_system_rs = static_library(
+ 'system',
+ structured_sources(
+ [
+ 'src/lib.rs',
+ 'src/bindings.rs',
+ 'src/memory.rs',
+ ],
+ {'.': _system_bindings_inc_rs}
+ ),
+ override_options: ['rust_std=2021', 'build.rust_std=2021'],
+ rust_abi: 'rust',
+ link_with: [_bql_rs, _migration_rs, _qom_rs, _util_rs],
+ dependencies: [common_rs, qemu_api_macros],
+)
+
+system_rs = declare_dependency(link_with: [_system_rs],
+ dependencies: [qemu_api_macros, hwcore])
--- /dev/null
+// 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 common::Zeroable;
+
+#[cfg(MESON)]
+include!("bindings.inc.rs");
+
+#[cfg(not(MESON))]
+include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs"));
+
+// SAFETY: these are constants and vtables; the Send and Sync requirements
+// are deferred to the unsafe callbacks that they contain
+unsafe impl Send for MemoryRegionOps {}
+unsafe impl Sync for MemoryRegionOps {}
+
+// SAFETY: this is a pure data struct
+unsafe impl Send for CoalescedMemoryRange {}
+unsafe impl Sync for CoalescedMemoryRange {}
+
+unsafe impl Zeroable for MemoryRegionOps__bindgen_ty_1 {}
+unsafe impl Zeroable for MemoryRegionOps__bindgen_ty_2 {}
+unsafe impl Zeroable for MemoryRegionOps {}
+unsafe impl Zeroable for MemTxAttrs {}
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+pub mod bindings;
+
+mod memory;
+pub use memory::*;
marker::PhantomData,
};
-pub use bindings::{hwaddr, MemTxAttrs};
use common::{callbacks::FnCall, uninit::MaybeUninitField, zeroable::Zeroable, Opaque};
use qom::prelude::*;
use crate::bindings::{self, device_endian, memory_region_init_io};
+pub use crate::bindings::{hwaddr, MemTxAttrs};
pub struct MemoryRegionOps<T>(
bindings::MemoryRegionOps,
--- /dev/null
+/* 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"