[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 01/14] add skeleton
From: |
Paolo Bonzini |
Subject: |
[PATCH 01/14] add skeleton |
Date: |
Mon, 1 Jul 2024 16:58:33 +0200 |
qemu/ is where target-independent code goes. This code should
not use constructors and will be brought in as needed.
qemu-hw/ is where the target-dependent code goes, which is going
to be built depending on Kconfig symbols.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
.gitignore | 2 +
Cargo.toml | 3 +
qemu-hw/Cargo.toml | 6 ++
qemu-hw/src/lib.rs | 0
qemu-hw/src/main.rs | 3 +
qemu/Cargo.toml | 7 ++
qemu/src/bindings/mod.rs | 88 +++++++++++++++++++++++++
qemu/src/lib.rs | 4 ++
9 files changed, 249 insertions(+)
create mode 100644 .gitignore
create mode 100644 Cargo.toml
create mode 100644 qemu-hw/Cargo.toml
create mode 100644 qemu-hw/src/lib.rs
create mode 100644 qemu-hw/src/main.rs
create mode 100644 qemu/Cargo.toml
create mode 100644 qemu/src/bindings/mod.rs
create mode 100644 qemu/src/lib.rs
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3fbfc34
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/target
+/.git-old
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..f66a80e
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,3 @@
+[workspace]
+members = ["qemu"]
+resolver = "2"
diff --git a/qemu-hw/Cargo.toml b/qemu-hw/Cargo.toml
new file mode 100644
index 0000000..9bd6930
--- /dev/null
+++ b/qemu-hw/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "qemu-hw"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/qemu-hw/src/lib.rs b/qemu-hw/src/lib.rs
new file mode 100644
index 0000000..e69de29
diff --git a/qemu-hw/src/main.rs b/qemu-hw/src/main.rs
new file mode 100644
index 0000000..e7a11a9
--- /dev/null
+++ b/qemu-hw/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}
diff --git a/qemu/Cargo.toml b/qemu/Cargo.toml
new file mode 100644
index 0000000..18d0fa4
--- /dev/null
+++ b/qemu/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "qemu"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
+const-default = { version = "~1", features = ["derive"] }
diff --git a/qemu/src/bindings/mod.rs b/qemu/src/bindings/mod.rs
new file mode 100644
index 0000000..a49447b
--- /dev/null
+++ b/qemu/src/bindings/mod.rs
@@ -0,0 +1,88 @@
+use std::ffi::{c_char, c_void};
+
+#[repr(C)]
+pub struct Object {
+ pub klass: *mut c_void,
+ pub free: extern "C" fn(c: *mut c_void),
+ pub properties: *mut c_void,
+ pub r#ref: u32,
+ pub parent: *mut Object,
+}
+
+#[repr(C)]
+pub struct ObjectClass {
+ pub unparent: Option<unsafe extern "C" fn(*mut Object)>,
+}
+
+#[repr(C)]
+pub struct DeviceState {
+ pub base: Object,
+}
+
+#[repr(C)]
+#[allow(non_camel_case_types)]
+pub struct PropertyInfo {
+ pub name: *const c_char,
+ pub description: *const c_char,
+ // ...
+}
+#[repr(C)]
+pub struct Property {
+ pub name: *const c_char,
+ pub offset: usize,
+ pub default: u64,
+ pub info: *const PropertyInfo,
+}
+
+pub struct DeviceClass {
+ pub oc: ObjectClass,
+
+ pub realize: Option<unsafe extern "C" fn(*mut DeviceState, *mut *mut
Error)>,
+ pub unrealize: Option<unsafe extern "C" fn(*mut DeviceState)>,
+ pub cold_reset: Option<unsafe extern "C" fn(*mut DeviceState)>,
+ pub properties: *const Property,
+}
+
+#[repr(C)]
+pub struct TypeInfo {
+ pub name: *const c_char,
+ pub parent: *const c_char,
+ pub instance_mem_init: Option<unsafe extern "C" fn(*mut c_void)>,
+ pub instance_init: Option<unsafe extern "C" fn(*mut c_void)>,
+ pub instance_finalize: Option<unsafe extern "C" fn(*mut c_void)>,
+ pub class_init: Option<unsafe extern "C" fn(*mut c_void, *mut c_void)>,
+ pub instance_size: usize,
+}
+
+#[repr(C)]
+pub struct Error {
+ _unused: c_char,
+}
+
+extern "C" {
+ pub fn error_setg_internal(
+ errp: *mut *mut Error,
+ src: *mut c_char,
+ line: u32,
+ func: *mut c_char,
+ fmt: *const c_char,
+ ...
+ );
+ pub fn error_get_pretty(errp: *const Error) -> *mut c_char;
+ pub fn error_free(errp: *mut Error);
+
+ pub fn object_dynamic_cast(obj: *mut Object, typ: *const c_char) -> *mut
c_void;
+ pub fn object_property_add_child(obj: *mut Object, typ: *const c_char,
+ child: *mut Object);
+ pub fn object_get_typename(obj: *const Object) -> *const c_char;
+ pub fn object_ref(obj: *mut Object);
+ pub fn object_new(typ: *const c_char) -> *const Object;
+ pub fn object_unref(obj: *mut Object);
+ pub fn object_unparent(obj: *mut Object);
+
+ pub fn device_cold_reset(obj: *mut DeviceState);
+ pub fn device_realize(obj: *mut DeviceState, err: *mut *mut Error) -> bool;
+ pub fn type_register(obj: *const TypeInfo);
+
+ pub static qdev_prop_bool: PropertyInfo;
+}
diff --git a/qemu/src/lib.rs b/qemu/src/lib.rs
new file mode 100644
index 0000000..fce21d7
--- /dev/null
+++ b/qemu/src/lib.rs
@@ -0,0 +1,4 @@
+#![allow(unused_macros)]
+#![allow(dead_code)]
+
+pub mod bindings;
--
2.45.2
- [PATCH 00/14] rust: example of bindings code for Rust in QEMU, Paolo Bonzini, 2024/07/01
- [PATCH 01/14] add skeleton,
Paolo Bonzini <=
- [PATCH 02/14] set expectations, Paolo Bonzini, 2024/07/01
- [PATCH 04/14] rust: add tests for util::foreign, Paolo Bonzini, 2024/07/01
- [PATCH 05/14] rust: define wrappers for Error, Paolo Bonzini, 2024/07/01
- [PATCH 03/14] rust: define traits and pointer wrappers to convert from/to C representations, Paolo Bonzini, 2024/07/01
- [PATCH 07/14] rust: define wrappers for methods of the QOM Object class, Paolo Bonzini, 2024/07/01
- [PATCH 08/14] rust: define wrappers for methods of the QOM Device class, Paolo Bonzini, 2024/07/01
- [PATCH 06/14] rust: define wrappers for basic QOM concepts, Paolo Bonzini, 2024/07/01