virtual-machine 0.3.0 → 0.3.1
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/build/{chunk-7SVGV3JI.mjs → chunk-54RVUDUK.mjs} +100 -170
- package/build/cli.js +296 -219
- package/build/index.d.ts +93 -16
- package/build/index.js +181 -171
- package/build/index.mjs +83 -3
- package/build/node-worker.js +134 -179
- package/build/{riscv_vm-B72XE6VL.mjs → riscv_vm-34DGRA7W.mjs} +1 -1
- package/build/worker.js +41 -168
- package/native/index.d.ts +0 -3
- package/native/index.mjs +1 -0
- package/native/riscv-vm-native.darwin-arm64.node +0 -0
- package/native/riscv-vm-native.darwin-x64.node +0 -0
- package/native/riscv-vm-native.linux-arm64-gnu.node +0 -0
- package/native/riscv-vm-native.linux-arm64-musl.node +0 -0
- package/native/riscv-vm-native.linux-x64-gnu.node +0 -0
- package/native/riscv-vm-native.linux-x64-musl.node +0 -0
- package/native/riscv-vm-native.win32-x64-msvc.node +0 -0
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -15,17 +15,17 @@ declare class WasmVm {
|
|
|
15
15
|
free(): void;
|
|
16
16
|
[Symbol.dispose](): void;
|
|
17
17
|
/**
|
|
18
|
-
* Enable
|
|
18
|
+
* Enable D1 Display device for graphics rendering.
|
|
19
19
|
*
|
|
20
|
-
* The
|
|
20
|
+
* The display device allows the kernel to render to a framebuffer which can
|
|
21
21
|
* then be displayed in a Canvas element. Use `get_gpu_frame()` to retrieve
|
|
22
22
|
* the rendered frame pixels.
|
|
23
23
|
*
|
|
24
24
|
* # Arguments
|
|
25
|
-
* * `width` - Display width in pixels (
|
|
26
|
-
* * `height` - Display height in pixels (
|
|
25
|
+
* * `width` - Display width in pixels (ignored, uses 1024x768)
|
|
26
|
+
* * `height` - Display height in pixels (ignored, uses 1024x768)
|
|
27
27
|
*/
|
|
28
|
-
enable_gpu(
|
|
28
|
+
enable_gpu(_width: number, _height: number): void;
|
|
29
29
|
/**
|
|
30
30
|
* Get a byte from the UART output buffer, if available.
|
|
31
31
|
*
|
|
@@ -62,7 +62,7 @@ declare class WasmVm {
|
|
|
62
62
|
* Get GPU frame data as RGBA pixels.
|
|
63
63
|
* Returns a Uint8Array of pixel data, or null if no frame is available.
|
|
64
64
|
*
|
|
65
|
-
* The frame data is in RGBA format with 4 bytes per pixel (
|
|
65
|
+
* The frame data is in RGBA format with 4 bytes per pixel (1024×768 = 3,145,728 bytes).
|
|
66
66
|
*
|
|
67
67
|
* This reads from a fixed framebuffer address in guest memory (0x8100_0000).
|
|
68
68
|
* The kernel GPU driver writes pixels there, and we read them here.
|
|
@@ -101,7 +101,7 @@ declare class WasmVm {
|
|
|
101
101
|
get_heap_usage(): Array<any>;
|
|
102
102
|
/**
|
|
103
103
|
* Get the current network connection status.
|
|
104
|
-
* This checks the actual connection state by seeing if
|
|
104
|
+
* This checks the actual connection state by seeing if D1 EMAC is enabled.
|
|
105
105
|
*/
|
|
106
106
|
network_status(): NetworkStatus;
|
|
107
107
|
/**
|
|
@@ -138,6 +138,17 @@ declare class WasmVm {
|
|
|
138
138
|
* Returns true if the event was sent successfully.
|
|
139
139
|
*/
|
|
140
140
|
send_mouse_event(x: number, y: number, buttons: number): boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Send a touch event to the D1 GT911 touchscreen controller.
|
|
143
|
+
*
|
|
144
|
+
* # Arguments
|
|
145
|
+
* * `x` - X position (0 to display width)
|
|
146
|
+
* * `y` - Y position (0 to display height)
|
|
147
|
+
* * `pressed` - true for touch down/move, false for touch up
|
|
148
|
+
*
|
|
149
|
+
* Returns true if the event was sent successfully.
|
|
150
|
+
*/
|
|
151
|
+
send_touch_event(x: number, y: number, pressed: boolean): boolean;
|
|
141
152
|
/**
|
|
142
153
|
* Get the total disk capacity from attached VirtIO block devices.
|
|
143
154
|
* Returns total bytes across all block devices.
|
|
@@ -174,6 +185,22 @@ declare class WasmVm {
|
|
|
174
185
|
* Note: Connection is asynchronous. Check network_status() to monitor connection state.
|
|
175
186
|
*/
|
|
176
187
|
connect_webtransport(url: string, cert_hash?: string | null): void;
|
|
188
|
+
/**
|
|
189
|
+
* Get a direct zero-copy view into the framebuffer in SharedArrayBuffer.
|
|
190
|
+
*
|
|
191
|
+
* This eliminates all memory copies by creating a Uint8Array view directly
|
|
192
|
+
* into the SharedArrayBuffer at the framebuffer offset. The browser can
|
|
193
|
+
* pass this directly to WebGPU's writeTexture for zero-copy rendering.
|
|
194
|
+
*
|
|
195
|
+
* Returns None if SharedArrayBuffer is not available (single-threaded mode).
|
|
196
|
+
*/
|
|
197
|
+
get_framebuffer_view(): Uint8Array | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Get the current frame version from kernel memory.
|
|
200
|
+
* Returns a u32 that increments each time the kernel flushes dirty pixels.
|
|
201
|
+
* Browser can compare this to skip fetching unchanged frames.
|
|
202
|
+
*/
|
|
203
|
+
get_gpu_frame_version(): number;
|
|
177
204
|
/**
|
|
178
205
|
* Inject a network packet to be received by the guest.
|
|
179
206
|
* Called from JavaScript when the native WebTransport addon receives a packet.
|
|
@@ -270,7 +297,7 @@ declare class WasmVm {
|
|
|
270
297
|
*/
|
|
271
298
|
is_halted(): boolean;
|
|
272
299
|
/**
|
|
273
|
-
* Load a disk image and attach it as a
|
|
300
|
+
* Load a disk image and attach it as a D1 MMC device.
|
|
274
301
|
* This should be called before starting execution if the kernel needs a filesystem.
|
|
275
302
|
*/
|
|
276
303
|
load_disk(disk_image: Uint8Array): void;
|
|
@@ -302,10 +329,22 @@ declare class WorkerState {
|
|
|
302
329
|
* Get the total step count.
|
|
303
330
|
*/
|
|
304
331
|
step_count(): bigint;
|
|
332
|
+
/**
|
|
333
|
+
* Check if MSIP is pending for this hart (for debugging).
|
|
334
|
+
*/
|
|
335
|
+
is_msip_pending(): boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Check if timer is pending for this hart (for debugging).
|
|
338
|
+
*/
|
|
339
|
+
is_timer_pending(): boolean;
|
|
305
340
|
/**
|
|
306
341
|
* Create a new worker state for a secondary hart.
|
|
307
342
|
*/
|
|
308
343
|
constructor(hart_id: number, shared_mem: any, entry_pc: bigint);
|
|
344
|
+
/**
|
|
345
|
+
* Get the a0 register value (for debugging hart ID passing).
|
|
346
|
+
*/
|
|
347
|
+
get_a0(): bigint;
|
|
309
348
|
/**
|
|
310
349
|
* Get the hart ID.
|
|
311
350
|
*/
|
|
@@ -332,6 +371,11 @@ declare enum WorkerStepResult {
|
|
|
332
371
|
* Fatal error occurred
|
|
333
372
|
*/
|
|
334
373
|
Error = 3,
|
|
374
|
+
/**
|
|
375
|
+
* WFI executed - worker should yield to prevent busy loop
|
|
376
|
+
* TypeScript should add a small delay before calling step_batch again
|
|
377
|
+
*/
|
|
378
|
+
Wfi = 4,
|
|
335
379
|
}
|
|
336
380
|
|
|
337
381
|
/**
|
|
@@ -370,7 +414,9 @@ interface InitOutput {
|
|
|
370
414
|
readonly wasmvm_get_cpu_count: (a: number) => number;
|
|
371
415
|
readonly wasmvm_get_disk_capacity: (a: number) => bigint;
|
|
372
416
|
readonly wasmvm_get_disk_usage: (a: number) => any;
|
|
417
|
+
readonly wasmvm_get_framebuffer_view: (a: number) => any;
|
|
373
418
|
readonly wasmvm_get_gpu_frame: (a: number) => any;
|
|
419
|
+
readonly wasmvm_get_gpu_frame_version: (a: number) => number;
|
|
374
420
|
readonly wasmvm_get_gpu_size: (a: number) => any;
|
|
375
421
|
readonly wasmvm_get_heap_usage: (a: number) => any;
|
|
376
422
|
readonly wasmvm_get_memory_usage: (a: number) => bigint;
|
|
@@ -394,6 +440,7 @@ interface InitOutput {
|
|
|
394
440
|
readonly wasmvm_send_key_event: (a: number, b: number, c: number) => number;
|
|
395
441
|
readonly wasmvm_send_mouse_button: (a: number, b: number, c: number) => number;
|
|
396
442
|
readonly wasmvm_send_mouse_event: (a: number, b: number, c: number, d: number) => number;
|
|
443
|
+
readonly wasmvm_send_touch_event: (a: number, b: number, c: number, d: number) => number;
|
|
397
444
|
readonly wasmvm_set_external_network_ip: (a: number, b: any) => number;
|
|
398
445
|
readonly wasmvm_setup_external_network: (a: number, b: any) => [number, number];
|
|
399
446
|
readonly wasmvm_start_workers: (a: number, b: number, c: number) => [number, number];
|
|
@@ -402,17 +449,16 @@ interface InitOutput {
|
|
|
402
449
|
readonly wasmvm_terminate_workers: (a: number) => void;
|
|
403
450
|
readonly wasmvm_uart_output_pending: (a: number) => number;
|
|
404
451
|
readonly worker_check_interrupts: (a: number, b: any) => bigint;
|
|
405
|
-
readonly
|
|
452
|
+
readonly workerstate_get_a0: (a: number) => bigint;
|
|
406
453
|
readonly workerstate_hart_id: (a: number) => number;
|
|
454
|
+
readonly workerstate_is_msip_pending: (a: number) => number;
|
|
455
|
+
readonly workerstate_is_timer_pending: (a: number) => number;
|
|
407
456
|
readonly workerstate_new: (a: number, b: any, c: bigint) => number;
|
|
408
457
|
readonly workerstate_step_batch: (a: number, b: number) => number;
|
|
409
458
|
readonly workerstate_step_count: (a: number) => bigint;
|
|
410
|
-
readonly
|
|
411
|
-
readonly
|
|
412
|
-
readonly
|
|
413
|
-
readonly wasm_bindgen__closure__destroy__h612f8e24953b61d5: (a: number, b: number) => void;
|
|
414
|
-
readonly wasm_bindgen__convert__closures_____invoke__hd159192dfee36a06: (a: number, b: number) => void;
|
|
415
|
-
readonly wasm_bindgen__convert__closures_____invoke__hedae94b906f728f2: (a: number, b: number, c: any) => void;
|
|
459
|
+
readonly worker_entry: (a: number, b: any, c: bigint) => void;
|
|
460
|
+
readonly wasm_bindgen__convert__closures_____invoke__hfbd40044a7a1ae85: (a: number, b: number, c: any) => void;
|
|
461
|
+
readonly wasm_bindgen__closure__destroy__h4b145e497aa7828d: (a: number, b: number) => void;
|
|
416
462
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
417
463
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
418
464
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
@@ -535,6 +581,37 @@ interface VmOptions {
|
|
|
535
581
|
* @returns WasmVm instance
|
|
536
582
|
*/
|
|
537
583
|
declare function createVM(kernelData: Uint8Array, options?: VmOptions): Promise<WasmVm>;
|
|
584
|
+
interface SDBootInfo {
|
|
585
|
+
kernelData: Uint8Array;
|
|
586
|
+
sdcardData: Uint8Array;
|
|
587
|
+
fsPartitionStart: number;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Parse an SD card image to extract kernel from FAT32 boot partition.
|
|
591
|
+
*
|
|
592
|
+
* SD Card layout:
|
|
593
|
+
* - MBR with partition table
|
|
594
|
+
* - Partition 1 (FAT32): kernel.bin
|
|
595
|
+
* - Partition 2: SFS filesystem
|
|
596
|
+
*/
|
|
597
|
+
declare function parseSDCard(sdcard: Uint8Array): SDBootInfo;
|
|
598
|
+
/**
|
|
599
|
+
* Fetch an SD card image from a URL for browser use.
|
|
600
|
+
*
|
|
601
|
+
* @param url - URL to fetch SD card image from
|
|
602
|
+
* @returns Parsed boot info with kernel and disk data
|
|
603
|
+
*/
|
|
604
|
+
declare function loadSDCardFromUrl(url: string): Promise<SDBootInfo>;
|
|
605
|
+
/**
|
|
606
|
+
* Create a VM from an SD card image (fetched from URL).
|
|
607
|
+
*
|
|
608
|
+
* This is the recommended way to boot the VM in browser.
|
|
609
|
+
*
|
|
610
|
+
* @param sdcardUrl - URL to SD card image
|
|
611
|
+
* @param options - VM configuration options
|
|
612
|
+
* @returns WasmVm instance ready to run
|
|
613
|
+
*/
|
|
614
|
+
declare function createVMFromSDCard(sdcardUrl: string, options?: VmOptions): Promise<WasmVm>;
|
|
538
615
|
/**
|
|
539
616
|
* Run the VM with an output callback for UART data.
|
|
540
617
|
*
|
|
@@ -602,4 +679,4 @@ interface WorkerManager {
|
|
|
602
679
|
*/
|
|
603
680
|
declare function createWorkerManager(): WorkerManager;
|
|
604
681
|
|
|
605
|
-
export { NetworkStatus, REQUIRED_HEADERS, type SharedMemorySupport, type VmOptions, WasmInternal, WasmVm, type WorkerErrorMessage, type WorkerHaltedMessage, type WorkerInitMessage, type WorkerManager, type WorkerOutboundMessage, type WorkerReadyMessage, checkSharedMemorySupport, createVM, createWorkerManager, isCrossOriginIsolated, isHaltRequested, isHalted, requestHalt, runVM };
|
|
682
|
+
export { NetworkStatus, REQUIRED_HEADERS, type SharedMemorySupport, type VmOptions, WasmInternal, WasmVm, type WorkerErrorMessage, type WorkerHaltedMessage, type WorkerInitMessage, type WorkerManager, type WorkerOutboundMessage, type WorkerReadyMessage, checkSharedMemorySupport, createVM, createVMFromSDCard, createWorkerManager, isCrossOriginIsolated, isHaltRequested, isHalted, loadSDCardFromUrl, parseSDCard, requestHalt, runVM };
|