virtual-machine 0.0.28 → 0.0.29

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/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { WorkerErrorMessage, WorkerHaltedMessage, WorkerInitMessage, WorkerOutboundMessage, WorkerReadyMessage } from './worker.js';
2
+
1
3
  /* tslint:disable */
2
4
  /* eslint-disable */
3
5
 
@@ -55,7 +57,7 @@ declare class WasmVm {
55
57
  */
56
58
  constructor(kernel: Uint8Array);
57
59
  /**
58
- * Execute a single instruction.
60
+ * Execute one instruction on each CPU (round-robin).
59
61
  * Returns true if the VM is still running, false if halted.
60
62
  */
61
63
  step(): boolean;
@@ -86,6 +88,16 @@ declare class WasmVm {
86
88
  load_disk(disk_image: Uint8Array): void;
87
89
  }
88
90
 
91
+ /**
92
+ * Worker entry point, called from JavaScript.
93
+ *
94
+ * # Arguments
95
+ * * `hart_id` - This worker's hart ID (1, 2, 3, ...)
96
+ * * `shared_mem` - SharedArrayBuffer containing DRAM
97
+ * * `entry_pc` - Kernel entry point address
98
+ */
99
+ declare function worker_entry(hart_id: number, shared_mem: any, entry_pc: bigint): void;
100
+
89
101
  type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
90
102
 
91
103
  interface InitOutput {
@@ -106,11 +118,12 @@ interface InitOutput {
106
118
  readonly wasmvm_step: (a: number) => number;
107
119
  readonly wasmvm_step_n: (a: number, b: number) => number;
108
120
  readonly wasmvm_uart_output_pending: (a: number) => number;
109
- readonly wasm_bindgen__convert__closures_____invoke__haab0aa5fef68b647: (a: number, b: number) => void;
110
- readonly wasm_bindgen__closure__destroy__hcbebb3eac6bc054d: (a: number, b: number) => void;
111
- readonly wasm_bindgen__convert__closures_____invoke__hd4872e8b3188af0e: (a: number, b: number) => void;
112
- readonly wasm_bindgen__convert__closures_____invoke__h6709295d3f31b919: (a: number, b: number, c: any) => void;
113
- readonly wasm_bindgen__closure__destroy__hb099e2ae98169675: (a: number, b: number) => void;
121
+ readonly worker_entry: (a: number, b: any, c: bigint) => void;
122
+ readonly wasm_bindgen__convert__closures_____invoke__hd26ce43761bab283: (a: number, b: number) => void;
123
+ readonly wasm_bindgen__closure__destroy__h04a8b4d76d4f17bc: (a: number, b: number) => void;
124
+ readonly wasm_bindgen__convert__closures_____invoke__h05c4944ac285ac35: (a: number, b: number) => void;
125
+ readonly wasm_bindgen__convert__closures_____invoke__h39d3e89751b07765: (a: number, b: number, c: any) => void;
126
+ readonly wasm_bindgen__closure__destroy__hf225e18fc5ab9bc1: (a: number, b: number) => void;
114
127
  readonly __wbindgen_malloc: (a: number, b: number) => number;
115
128
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
116
129
  readonly __wbindgen_exn_store: (a: number) => void;
@@ -151,10 +164,52 @@ type __pkg_riscv_vm_SyncInitInput = SyncInitInput;
151
164
  type __pkg_riscv_vm_WasmVm = WasmVm;
152
165
  declare const __pkg_riscv_vm_WasmVm: typeof WasmVm;
153
166
  declare const __pkg_riscv_vm_initSync: typeof initSync;
167
+ declare const __pkg_riscv_vm_worker_entry: typeof worker_entry;
154
168
  declare namespace __pkg_riscv_vm {
155
- export { type __pkg_riscv_vm_InitInput as InitInput, type __pkg_riscv_vm_InitOutput as InitOutput, __pkg_riscv_vm_NetworkStatus as NetworkStatus, type __pkg_riscv_vm_SyncInitInput as SyncInitInput, __pkg_riscv_vm_WasmVm as WasmVm, __wbg_init as default, __pkg_riscv_vm_initSync as initSync };
169
+ export { type __pkg_riscv_vm_InitInput as InitInput, type __pkg_riscv_vm_InitOutput as InitOutput, __pkg_riscv_vm_NetworkStatus as NetworkStatus, type __pkg_riscv_vm_SyncInitInput as SyncInitInput, __pkg_riscv_vm_WasmVm as WasmVm, __wbg_init as default, __pkg_riscv_vm_initSync as initSync, __pkg_riscv_vm_worker_entry as worker_entry };
156
170
  }
157
171
 
158
172
  declare function WasmInternal(): Promise<typeof __pkg_riscv_vm>;
159
173
 
160
- export { NetworkStatus, WasmInternal, WasmVm };
174
+ interface VmOptions {
175
+ /** Number of harts (auto-detected if not specified) */
176
+ harts?: number;
177
+ /** Path to worker script (default: '/worker.js') */
178
+ workerScript?: string;
179
+ }
180
+ /**
181
+ * Create a VM instance and optionally start workers for multi-hart execution.
182
+ *
183
+ * @param kernelData - ELF kernel binary
184
+ * @param options - VM configuration options
185
+ * @returns WasmVm instance
186
+ */
187
+ declare function createVM(kernelData: Uint8Array, options?: VmOptions): Promise<WasmVm>;
188
+ /**
189
+ * Run the VM with an output callback for UART data.
190
+ *
191
+ * @param vm - WasmVm instance
192
+ * @param onOutput - Callback for each character output
193
+ * @param options - Run options
194
+ * @returns Stop function to halt execution
195
+ */
196
+ declare function runVM(vm: WasmVm, onOutput: (char: string) => void, options?: {
197
+ stepsPerFrame?: number;
198
+ }): () => void;
199
+ interface SharedMemorySupport {
200
+ supported: boolean;
201
+ message: string;
202
+ }
203
+ /**
204
+ * Check if SharedArrayBuffer is available for multi-threaded execution.
205
+ *
206
+ * SharedArrayBuffer requires Cross-Origin Isolation (COOP/COEP headers).
207
+ * If not available, the VM will run in single-threaded mode.
208
+ */
209
+ declare function checkSharedMemorySupport(): SharedMemorySupport;
210
+ /**
211
+ * Check if the page is cross-origin isolated (required for SharedArrayBuffer).
212
+ */
213
+ declare function isCrossOriginIsolated(): boolean;
214
+
215
+ export { NetworkStatus, type SharedMemorySupport, type VmOptions, WasmInternal, WasmVm, checkSharedMemorySupport, createVM, isCrossOriginIsolated, runVM };