Skip to content

Commit 350d08f

Browse files
committed
Add example to README
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
1 parent 86e6b16 commit 350d08f

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,31 @@ Use the following command to self sign your binary for local development:
2727
```bash
2828
$ codesign --sign - --force --entitlements=example.entitlements ./binary
2929
```
30+
31+
## Example
32+
33+
Here is basic "Hello world" example on Apple Silicon:
34+
```rust
35+
// Init VM
36+
hv::Vm::create_vm(ptr::null_mut())?;
37+
38+
// Initialize guest memory
39+
hv::Vm::map(load_addr, GUEST_ADDR as _, MEM_SIZE as _, hv::Memory::READ)?;
40+
41+
// Create VCPU
42+
let cpu = hv::Vm::create_cpu()?;
43+
44+
// Register regs
45+
cpu.set_reg(Reg::PC, GUEST_ADDR)?;
46+
cpu.set_reg(Reg::X1, GUEST_RESULT_ADDR)?;
47+
48+
// Run CPU
49+
loop {
50+
cpu.run()?;
51+
52+
let info = cpu.exit_info();
53+
println!("{:?}", info);
54+
55+
break;
56+
}
57+
```

0 commit comments

Comments
 (0)