diff options
| author | iximeow <me@iximeow.net> | 2026-05-24 01:07:51 +0000 |
|---|---|---|
| committer | iximeow <me@iximeow.net> | 2026-05-24 22:20:18 +0000 |
| commit | 4532dbcfe444a05dea7022d86a502308eedd367f (patch) | |
| tree | fb7c883c38b10ed99e5474c7c283635133549a06 | |
| parent | 347d8f4b677d6879856241a1c2b39783a61df026 (diff) | |
2.1.0HEAD2.1.0no-gods-no-
| -rw-r--r-- | Cargo.lock | 2 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | README.md | 28 |
3 files changed, 28 insertions, 4 deletions
@@ -4,7 +4,7 @@ version = 4 [[package]] name = "asmlinator" -version = "2.0.0" +version = "2.1.0" dependencies = [ "kvm-bindings", "kvm-ioctls", @@ -1,7 +1,7 @@ [package] name = "asmlinator" -version = "2.0.0" +version = "2.1.0" authors = [ "iximeow <me@iximeow.net>" ] license = "0BSD" repository = "https://git.iximeow.net/asmlinator/" @@ -28,6 +28,30 @@ eprintln!("ending rip: {:016x}", regs.rip); eprintln!("ending rax: {:016x}", regs.rax); ``` +for non-x86-64 modes, the path is slightly longer: +``` +use asmlinator::x86_64::{IsaMode, VcpuExit, VmSettings, Vm}; + +let settings = VmSettings::new(1024 * 1024, IsaMode::Real); +let mut vm = Vm::create_by_settings(settings) + .expect("can create the VM"); + +let mut regs = vm.get_regs().unwrap(); +regs.rax = 0x11223344_55667788; + +// program VM with "xor al, al; hlt" +vm.program(&[0x33, 0xc0, 0xf4], &mut regs); +vm.set_regs(®s).unwrap(); + +let res = vm.run().expect("can run cpu"); +assert_eq!(res, VcpuExit::Hlt); + +let regs = vm.get_regs().unwrap(); +eprintln!("ending rip: {:016x}", regs.rip); +eprintln!("ending rax: {:016x}", regs.rax); +assert_eq!(regs.rax, 0x1122334455660000); +``` + ### design it's just a glorified virtual CPU wrapper. there is no device emulation, there @@ -46,8 +70,8 @@ require setting up an IDT, GDT, paging, ... ### future -it'd be nice to set up aarch64 processors for code execution too. and -32-bit/16-bit x86. and to do all this on other OSes with other VM APIs. +it'd be nice to set up aarch64 processors for code execution too. and to do all +this on other OSes with other VM APIs. it would probably nice to expose a C ffi to embed this into other programs! such an ffi interface should be straightforward. i haven't needed one yet. |
