virtual-machine 0.0.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +2 -1
- package/README.md +76 -0
- package/build/{riscv_vm-FIEDMHCY.mjs → chunk-GZ343GYI.mjs} +20 -22
- package/build/chunk-Q7TFYQ5G.mjs +670 -0
- package/build/cli.js +707 -688
- package/build/index.d.ts +4 -4
- package/build/index.js +23 -24
- package/build/index.mjs +10 -3
- package/build/riscv_vm-3CIEJ5K7.mjs +12 -0
- package/build/riscv_vm-VNML57ES.mjs +12 -0
- package/build.sh +5 -6
- package/index.ts +1 -0
- package/package.json +1 -1
- package/src/main.rs +15 -5
- package/tsup/index.ts +0 -1
package/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "riscv-vm"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.0.2"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
@@ -21,6 +21,7 @@ wasm-bindgen = "0.2"
|
|
|
21
21
|
|
|
22
22
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
|
23
23
|
tun-tap = "0.1"
|
|
24
|
+
reqwest = { version = "0.12", features = ["blocking", "rustls-tls"] }
|
|
24
25
|
tungstenite = "0.21"
|
|
25
26
|
# WebTransport for connecting to the relay
|
|
26
27
|
wtransport = { version = "0.6", features = ["dangerous-configuration"] }
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# RISC-V Virtual Machine
|
|
2
|
+
|
|
3
|
+
A complete RISC-V 64-bit (RV64GC) virtual machine implementation in Rust, capable of running modern operating systems like Linux (xv6) and custom bare-metal kernels. It is designed to run both natively and in the browser via WebAssembly.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Core**: Full RV64GC instruction set implementation (IMAFDC + Zicsr + Zifencei).
|
|
8
|
+
- **Memory**: Sv39 Virtual Memory Management Unit (MMU) with TLB.
|
|
9
|
+
- **Peripherals**:
|
|
10
|
+
- **UART**: 16550-compatible serial console.
|
|
11
|
+
- **PLIC**: Platform-Level Interrupt Controller.
|
|
12
|
+
- **CLINT**: Core Local Interruptor (Timer).
|
|
13
|
+
- **VirtIO**: Block Device (Disk) and Network Device (Net).
|
|
14
|
+
- **Networking**:
|
|
15
|
+
- Native TAP interface support (Linux).
|
|
16
|
+
- WebSocket backend for browser/cross-platform networking.
|
|
17
|
+
- WebTransport backend for P2P connectivity.
|
|
18
|
+
- **Platform**:
|
|
19
|
+
- **WASM**: Compiles to WebAssembly for browser execution.
|
|
20
|
+
- **Native**: Runs as a CLI application on Host OS.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### CLI (Native)
|
|
25
|
+
|
|
26
|
+
Run the emulator from the command line:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Run a kernel image
|
|
30
|
+
cargo run --release -- --kernel path/to/kernel
|
|
31
|
+
|
|
32
|
+
# Run with networking (WebSocket backend)
|
|
33
|
+
cargo run --release -- --kernel path/to/kernel --net-ws ws://localhost:8765
|
|
34
|
+
|
|
35
|
+
# Run with block device
|
|
36
|
+
cargo run --release -- --kernel path/to/kernel --disk path/to/fs.img
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### WebAssembly
|
|
40
|
+
|
|
41
|
+
The VM exposes a simple API for JavaScript integration:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { WasmVm } from "virtual-machine";
|
|
45
|
+
|
|
46
|
+
// Initialize VM with kernel binary
|
|
47
|
+
const vm = new WasmVm(kernelBytes);
|
|
48
|
+
|
|
49
|
+
// Connect networking
|
|
50
|
+
vm.connect_network("ws://localhost:8765");
|
|
51
|
+
|
|
52
|
+
// Step execution
|
|
53
|
+
while (running) {
|
|
54
|
+
vm.step();
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Architecture
|
|
59
|
+
|
|
60
|
+
The VM follows a modular design:
|
|
61
|
+
- `cpu.rs`: Instruction decoder and execution pipeline.
|
|
62
|
+
- `mmu.rs`: Virtual address translation.
|
|
63
|
+
- `bus.rs`: Memory mapping and device routing.
|
|
64
|
+
- `virtio.rs`: VirtIO device implementations.
|
|
65
|
+
- `net.rs`: Network backend abstraction.
|
|
66
|
+
|
|
67
|
+
## Build
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Build native CLI
|
|
71
|
+
cargo build --release
|
|
72
|
+
|
|
73
|
+
# Build WASM package
|
|
74
|
+
wasm-pack build --target web
|
|
75
|
+
```
|
|
76
|
+
|
|
@@ -186,15 +186,15 @@ function passArray8ToWasm0(arg, malloc) {
|
|
|
186
186
|
WASM_VECTOR_LEN = arg.length;
|
|
187
187
|
return ptr;
|
|
188
188
|
}
|
|
189
|
-
function
|
|
190
|
-
wasm.
|
|
189
|
+
function wasm_bindgen__convert__closures_____invoke__h74b0833075704714(arg0, arg1, arg2) {
|
|
190
|
+
wasm.wasm_bindgen__convert__closures_____invoke__h74b0833075704714(arg0, arg1, arg2);
|
|
191
|
+
}
|
|
192
|
+
function wasm_bindgen__convert__closures_____invoke__hb59cd9fe41fe42e5(arg0, arg1) {
|
|
193
|
+
wasm.wasm_bindgen__convert__closures_____invoke__hb59cd9fe41fe42e5(arg0, arg1);
|
|
191
194
|
}
|
|
192
195
|
function wasm_bindgen__convert__closures_____invoke__h6fd3101b14d9814b(arg0, arg1, arg2) {
|
|
193
196
|
wasm.wasm_bindgen__convert__closures_____invoke__h6fd3101b14d9814b(arg0, arg1, arg2);
|
|
194
197
|
}
|
|
195
|
-
function wasm_bindgen__convert__closures_____invoke__hcf26143a2d2b8df4(arg0, arg1) {
|
|
196
|
-
wasm.wasm_bindgen__convert__closures_____invoke__hcf26143a2d2b8df4(arg0, arg1);
|
|
197
|
-
}
|
|
198
198
|
var NetworkStatus = Object.freeze({
|
|
199
199
|
Disconnected: 0,
|
|
200
200
|
"0": "Disconnected",
|
|
@@ -584,28 +584,28 @@ function __wbg_get_imports() {
|
|
|
584
584
|
const ret = arg0.write(arg1);
|
|
585
585
|
return ret;
|
|
586
586
|
};
|
|
587
|
-
imports.wbg.__wbindgen_cast_188ff5bafa3120b4 = function(arg0, arg1) {
|
|
588
|
-
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h158587509e69fed9, wasm_bindgen__convert__closures_____invoke__hcf26143a2d2b8df4);
|
|
589
|
-
return ret;
|
|
590
|
-
};
|
|
591
587
|
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
592
588
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
593
589
|
return ret;
|
|
594
590
|
};
|
|
595
|
-
imports.wbg.
|
|
596
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
591
|
+
imports.wbg.__wbindgen_cast_3aa963a08b1e1d3f = function(arg0, arg1) {
|
|
592
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h0c7e8767edb7b811, wasm_bindgen__convert__closures_____invoke__h74b0833075704714);
|
|
597
593
|
return ret;
|
|
598
594
|
};
|
|
599
|
-
imports.wbg.
|
|
600
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
595
|
+
imports.wbg.__wbindgen_cast_3fd26d226c2b9642 = function(arg0, arg1) {
|
|
596
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h0c7e8767edb7b811, wasm_bindgen__convert__closures_____invoke__h74b0833075704714);
|
|
601
597
|
return ret;
|
|
602
598
|
};
|
|
603
|
-
imports.wbg.
|
|
604
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
599
|
+
imports.wbg.__wbindgen_cast_5b09fbeec74be75e = function(arg0, arg1) {
|
|
600
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__hb2f3fe1158f30bc9, wasm_bindgen__convert__closures_____invoke__h6fd3101b14d9814b);
|
|
605
601
|
return ret;
|
|
606
602
|
};
|
|
607
|
-
imports.wbg.
|
|
608
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
603
|
+
imports.wbg.__wbindgen_cast_77a91827c917be15 = function(arg0, arg1) {
|
|
604
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h0c7e8767edb7b811, wasm_bindgen__convert__closures_____invoke__hb59cd9fe41fe42e5);
|
|
605
|
+
return ret;
|
|
606
|
+
};
|
|
607
|
+
imports.wbg.__wbindgen_cast_e6666d41823ad376 = function(arg0, arg1) {
|
|
608
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h0c7e8767edb7b811, wasm_bindgen__convert__closures_____invoke__h74b0833075704714);
|
|
609
609
|
return ret;
|
|
610
610
|
};
|
|
611
611
|
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
@@ -653,9 +653,6 @@ async function __wbg_init(module_or_path) {
|
|
|
653
653
|
console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
654
654
|
}
|
|
655
655
|
}
|
|
656
|
-
if (typeof module_or_path === "undefined") {
|
|
657
|
-
module_or_path = new URL("riscv_vm_bg.wasm", import.meta.url);
|
|
658
|
-
}
|
|
659
656
|
const imports = __wbg_get_imports();
|
|
660
657
|
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
|
|
661
658
|
module_or_path = fetch(module_or_path);
|
|
@@ -664,9 +661,10 @@ async function __wbg_init(module_or_path) {
|
|
|
664
661
|
return __wbg_finalize_init(instance, module);
|
|
665
662
|
}
|
|
666
663
|
var riscv_vm_default = __wbg_init;
|
|
664
|
+
|
|
667
665
|
export {
|
|
668
666
|
NetworkStatus,
|
|
669
667
|
WasmVm,
|
|
670
|
-
|
|
671
|
-
|
|
668
|
+
initSync,
|
|
669
|
+
riscv_vm_default
|
|
672
670
|
};
|