virtual-machine 0.0.28 → 0.0.30

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.
@@ -0,0 +1,828 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // worker.ts
17
+ var worker_exports = {};
18
+ module.exports = __toCommonJS(worker_exports);
19
+
20
+ // pkg/riscv_vm.js
21
+ var wasm;
22
+ function addToExternrefTable0(obj) {
23
+ const idx = wasm.__externref_table_alloc();
24
+ wasm.__wbindgen_externrefs.set(idx, obj);
25
+ return idx;
26
+ }
27
+ var CLOSURE_DTORS = typeof FinalizationRegistry === "undefined" ? { register: () => {
28
+ }, unregister: () => {
29
+ } } : new FinalizationRegistry((state) => state.dtor(state.a, state.b));
30
+ function debugString(val) {
31
+ const type = typeof val;
32
+ if (type == "number" || type == "boolean" || val == null) {
33
+ return `${val}`;
34
+ }
35
+ if (type == "string") {
36
+ return `"${val}"`;
37
+ }
38
+ if (type == "symbol") {
39
+ const description = val.description;
40
+ if (description == null) {
41
+ return "Symbol";
42
+ } else {
43
+ return `Symbol(${description})`;
44
+ }
45
+ }
46
+ if (type == "function") {
47
+ const name = val.name;
48
+ if (typeof name == "string" && name.length > 0) {
49
+ return `Function(${name})`;
50
+ } else {
51
+ return "Function";
52
+ }
53
+ }
54
+ if (Array.isArray(val)) {
55
+ const length = val.length;
56
+ let debug = "[";
57
+ if (length > 0) {
58
+ debug += debugString(val[0]);
59
+ }
60
+ for (let i = 1; i < length; i++) {
61
+ debug += ", " + debugString(val[i]);
62
+ }
63
+ debug += "]";
64
+ return debug;
65
+ }
66
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
67
+ let className;
68
+ if (builtInMatches && builtInMatches.length > 1) {
69
+ className = builtInMatches[1];
70
+ } else {
71
+ return toString.call(val);
72
+ }
73
+ if (className == "Object") {
74
+ try {
75
+ return "Object(" + JSON.stringify(val) + ")";
76
+ } catch (_) {
77
+ return "Object";
78
+ }
79
+ }
80
+ if (val instanceof Error) {
81
+ return `${val.name}: ${val.message}
82
+ ${val.stack}`;
83
+ }
84
+ return className;
85
+ }
86
+ function getArrayU8FromWasm0(ptr, len) {
87
+ ptr = ptr >>> 0;
88
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
89
+ }
90
+ var cachedDataViewMemory0 = null;
91
+ function getDataViewMemory0() {
92
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
93
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
94
+ }
95
+ return cachedDataViewMemory0;
96
+ }
97
+ function getStringFromWasm0(ptr, len) {
98
+ ptr = ptr >>> 0;
99
+ return decodeText(ptr, len);
100
+ }
101
+ var cachedUint8ArrayMemory0 = null;
102
+ function getUint8ArrayMemory0() {
103
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
104
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
105
+ }
106
+ return cachedUint8ArrayMemory0;
107
+ }
108
+ function handleError(f, args) {
109
+ try {
110
+ return f.apply(this, args);
111
+ } catch (e) {
112
+ const idx = addToExternrefTable0(e);
113
+ wasm.__wbindgen_exn_store(idx);
114
+ }
115
+ }
116
+ function isLikeNone(x) {
117
+ return x === void 0 || x === null;
118
+ }
119
+ function makeClosure(arg0, arg1, dtor, f) {
120
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
121
+ const real = (...args) => {
122
+ state.cnt++;
123
+ try {
124
+ return f(state.a, state.b, ...args);
125
+ } finally {
126
+ real._wbg_cb_unref();
127
+ }
128
+ };
129
+ real._wbg_cb_unref = () => {
130
+ if (--state.cnt === 0) {
131
+ state.dtor(state.a, state.b);
132
+ state.a = 0;
133
+ CLOSURE_DTORS.unregister(state);
134
+ }
135
+ };
136
+ CLOSURE_DTORS.register(real, state, state);
137
+ return real;
138
+ }
139
+ function makeMutClosure(arg0, arg1, dtor, f) {
140
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
141
+ const real = (...args) => {
142
+ state.cnt++;
143
+ const a = state.a;
144
+ state.a = 0;
145
+ try {
146
+ return f(a, state.b, ...args);
147
+ } finally {
148
+ state.a = a;
149
+ real._wbg_cb_unref();
150
+ }
151
+ };
152
+ real._wbg_cb_unref = () => {
153
+ if (--state.cnt === 0) {
154
+ state.dtor(state.a, state.b);
155
+ state.a = 0;
156
+ CLOSURE_DTORS.unregister(state);
157
+ }
158
+ };
159
+ CLOSURE_DTORS.register(real, state, state);
160
+ return real;
161
+ }
162
+ function passArray8ToWasm0(arg, malloc) {
163
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
164
+ getUint8ArrayMemory0().set(arg, ptr / 1);
165
+ WASM_VECTOR_LEN = arg.length;
166
+ return ptr;
167
+ }
168
+ function passStringToWasm0(arg, malloc, realloc) {
169
+ if (realloc === void 0) {
170
+ const buf = cachedTextEncoder.encode(arg);
171
+ const ptr2 = malloc(buf.length, 1) >>> 0;
172
+ getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
173
+ WASM_VECTOR_LEN = buf.length;
174
+ return ptr2;
175
+ }
176
+ let len = arg.length;
177
+ let ptr = malloc(len, 1) >>> 0;
178
+ const mem = getUint8ArrayMemory0();
179
+ let offset = 0;
180
+ for (; offset < len; offset++) {
181
+ const code = arg.charCodeAt(offset);
182
+ if (code > 127) break;
183
+ mem[ptr + offset] = code;
184
+ }
185
+ if (offset !== len) {
186
+ if (offset !== 0) {
187
+ arg = arg.slice(offset);
188
+ }
189
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
190
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
191
+ const ret = cachedTextEncoder.encodeInto(arg, view);
192
+ offset += ret.written;
193
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
194
+ }
195
+ WASM_VECTOR_LEN = offset;
196
+ return ptr;
197
+ }
198
+ function takeFromExternrefTable0(idx) {
199
+ const value = wasm.__wbindgen_externrefs.get(idx);
200
+ wasm.__externref_table_dealloc(idx);
201
+ return value;
202
+ }
203
+ var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
204
+ cachedTextDecoder.decode();
205
+ var MAX_SAFARI_DECODE_BYTES = 2146435072;
206
+ var numBytesDecoded = 0;
207
+ function decodeText(ptr, len) {
208
+ numBytesDecoded += len;
209
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
210
+ cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
211
+ cachedTextDecoder.decode();
212
+ numBytesDecoded = len;
213
+ }
214
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
215
+ }
216
+ var cachedTextEncoder = new TextEncoder();
217
+ if (!("encodeInto" in cachedTextEncoder)) {
218
+ cachedTextEncoder.encodeInto = function(arg, view) {
219
+ const buf = cachedTextEncoder.encode(arg);
220
+ view.set(buf);
221
+ return {
222
+ read: arg.length,
223
+ written: buf.length
224
+ };
225
+ };
226
+ }
227
+ var WASM_VECTOR_LEN = 0;
228
+ function wasm_bindgen__convert__closures_____invoke__hb4c5b5d7ccdc8795(arg0, arg1) {
229
+ wasm.wasm_bindgen__convert__closures_____invoke__hb4c5b5d7ccdc8795(arg0, arg1);
230
+ }
231
+ function wasm_bindgen__convert__closures_____invoke__hca46242f02098063(arg0, arg1) {
232
+ wasm.wasm_bindgen__convert__closures_____invoke__hca46242f02098063(arg0, arg1);
233
+ }
234
+ function wasm_bindgen__convert__closures_____invoke__h39d3e89751b07765(arg0, arg1, arg2) {
235
+ wasm.wasm_bindgen__convert__closures_____invoke__h39d3e89751b07765(arg0, arg1, arg2);
236
+ }
237
+ var WasmVmFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
238
+ }, unregister: () => {
239
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_wasmvm_free(ptr >>> 0, 1));
240
+ var NetworkStatus = Object.freeze({
241
+ Disconnected: 0,
242
+ "0": "Disconnected",
243
+ Connecting: 1,
244
+ "1": "Connecting",
245
+ Connected: 2,
246
+ "2": "Connected",
247
+ Error: 3,
248
+ "3": "Error"
249
+ });
250
+ var WasmVm = class {
251
+ __destroy_into_raw() {
252
+ const ptr = this.__wbg_ptr;
253
+ this.__wbg_ptr = 0;
254
+ WasmVmFinalization.unregister(this);
255
+ return ptr;
256
+ }
257
+ free() {
258
+ const ptr = this.__destroy_into_raw();
259
+ wasm.__wbg_wasmvm_free(ptr, 0);
260
+ }
261
+ /**
262
+ * Get a byte from the UART output buffer, if available.
263
+ * @returns {number | undefined}
264
+ */
265
+ get_output() {
266
+ const ret = wasm.wasmvm_get_output(this.__wbg_ptr);
267
+ return ret === 16777215 ? void 0 : ret;
268
+ }
269
+ /**
270
+ * Print the VM banner to UART output (visible in browser).
271
+ * Call this after creating the VM to show a boot banner.
272
+ */
273
+ print_banner() {
274
+ wasm.wasmvm_print_banner(this.__wbg_ptr);
275
+ }
276
+ /**
277
+ * Print a status message to UART output (visible in browser).
278
+ * @param {string} message
279
+ */
280
+ print_status(message) {
281
+ const ptr0 = passStringToWasm0(message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
282
+ const len0 = WASM_VECTOR_LEN;
283
+ wasm.wasmvm_print_status(this.__wbg_ptr, ptr0, len0);
284
+ }
285
+ /**
286
+ * Get the current network connection status.
287
+ * This checks the actual connection state by seeing if an IP was assigned.
288
+ * @returns {NetworkStatus}
289
+ */
290
+ network_status() {
291
+ const ret = wasm.wasmvm_network_status(this.__wbg_ptr);
292
+ return ret;
293
+ }
294
+ /**
295
+ * Get current memory usage (DRAM size) in bytes.
296
+ * @returns {bigint}
297
+ */
298
+ get_memory_usage() {
299
+ const ret = wasm.wasmvm_get_memory_usage(this.__wbg_ptr);
300
+ return BigInt.asUintN(64, ret);
301
+ }
302
+ /**
303
+ * Disconnect from the network.
304
+ */
305
+ disconnect_network() {
306
+ wasm.wasmvm_disconnect_network(this.__wbg_ptr);
307
+ }
308
+ /**
309
+ * Check how many bytes are pending in the UART output buffer.
310
+ * Useful for debugging output issues.
311
+ * @returns {number}
312
+ */
313
+ uart_output_pending() {
314
+ const ret = wasm.wasmvm_uart_output_pending(this.__wbg_ptr);
315
+ return ret >>> 0;
316
+ }
317
+ /**
318
+ * Connect to a WebTransport relay server.
319
+ * Note: Connection is asynchronous. Check network_status() to monitor connection state.
320
+ * @param {string} url
321
+ * @param {string | null} [cert_hash]
322
+ */
323
+ connect_webtransport(url, cert_hash) {
324
+ const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
325
+ const len0 = WASM_VECTOR_LEN;
326
+ var ptr1 = isLikeNone(cert_hash) ? 0 : passStringToWasm0(cert_hash, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
327
+ var len1 = WASM_VECTOR_LEN;
328
+ const ret = wasm.wasmvm_connect_webtransport(this.__wbg_ptr, ptr0, len0, ptr1, len1);
329
+ if (ret[1]) {
330
+ throw takeFromExternrefTable0(ret[0]);
331
+ }
332
+ }
333
+ /**
334
+ * Create a new VM instance and load a kernel (ELF or raw binary).
335
+ * @param {Uint8Array} kernel
336
+ */
337
+ constructor(kernel) {
338
+ const ptr0 = passArray8ToWasm0(kernel, wasm.__wbindgen_malloc);
339
+ const len0 = WASM_VECTOR_LEN;
340
+ const ret = wasm.wasmvm_new(ptr0, len0);
341
+ if (ret[2]) {
342
+ throw takeFromExternrefTable0(ret[1]);
343
+ }
344
+ this.__wbg_ptr = ret[0] >>> 0;
345
+ WasmVmFinalization.register(this, this.__wbg_ptr, this);
346
+ return this;
347
+ }
348
+ /**
349
+ * Execute one instruction on each CPU (round-robin).
350
+ * Returns true if the VM is still running, false if halted.
351
+ * @returns {boolean}
352
+ */
353
+ step() {
354
+ const ret = wasm.wasmvm_step(this.__wbg_ptr);
355
+ return ret !== 0;
356
+ }
357
+ /**
358
+ * Push an input byte to the UART.
359
+ * @param {number} byte
360
+ */
361
+ input(byte) {
362
+ wasm.wasmvm_input(this.__wbg_ptr, byte);
363
+ }
364
+ /**
365
+ * Execute up to N instructions in a batch.
366
+ * Returns the number of instructions actually executed.
367
+ * This is more efficient than calling step() N times due to reduced
368
+ * JS-WASM boundary crossings.
369
+ * @param {number} count
370
+ * @returns {number}
371
+ */
372
+ step_n(count) {
373
+ const ret = wasm.wasmvm_step_n(this.__wbg_ptr, count);
374
+ return ret >>> 0;
375
+ }
376
+ /**
377
+ * Get the halt code if the VM has halted.
378
+ * Code 0x5555 typically means successful shutdown (PASS).
379
+ * @returns {bigint}
380
+ */
381
+ halt_code() {
382
+ const ret = wasm.wasmvm_halt_code(this.__wbg_ptr);
383
+ return BigInt.asUintN(64, ret);
384
+ }
385
+ /**
386
+ * Check if the VM has halted (e.g., due to shutdown command).
387
+ * @returns {boolean}
388
+ */
389
+ is_halted() {
390
+ const ret = wasm.wasmvm_is_halted(this.__wbg_ptr);
391
+ return ret !== 0;
392
+ }
393
+ /**
394
+ * Load a disk image and attach it as a VirtIO block device.
395
+ * This should be called before starting execution if the kernel needs a filesystem.
396
+ * @param {Uint8Array} disk_image
397
+ */
398
+ load_disk(disk_image) {
399
+ const ptr0 = passArray8ToWasm0(disk_image, wasm.__wbindgen_malloc);
400
+ const len0 = WASM_VECTOR_LEN;
401
+ wasm.wasmvm_load_disk(this.__wbg_ptr, ptr0, len0);
402
+ }
403
+ };
404
+ if (Symbol.dispose) WasmVm.prototype[Symbol.dispose] = WasmVm.prototype.free;
405
+ function worker_entry(hart_id, shared_mem, entry_pc) {
406
+ wasm.worker_entry(hart_id, shared_mem, entry_pc);
407
+ }
408
+ var EXPECTED_RESPONSE_TYPES = /* @__PURE__ */ new Set(["basic", "cors", "default"]);
409
+ async function __wbg_load(module2, imports) {
410
+ if (typeof Response === "function" && module2 instanceof Response) {
411
+ if (typeof WebAssembly.instantiateStreaming === "function") {
412
+ try {
413
+ return await WebAssembly.instantiateStreaming(module2, imports);
414
+ } catch (e) {
415
+ const validResponse = module2.ok && EXPECTED_RESPONSE_TYPES.has(module2.type);
416
+ if (validResponse && module2.headers.get("Content-Type") !== "application/wasm") {
417
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
418
+ } else {
419
+ throw e;
420
+ }
421
+ }
422
+ }
423
+ const bytes = await module2.arrayBuffer();
424
+ return await WebAssembly.instantiate(bytes, imports);
425
+ } else {
426
+ const instance = await WebAssembly.instantiate(module2, imports);
427
+ if (instance instanceof WebAssembly.Instance) {
428
+ return { instance, module: module2 };
429
+ } else {
430
+ return instance;
431
+ }
432
+ }
433
+ }
434
+ function __wbg_get_imports() {
435
+ const imports = {};
436
+ imports.wbg = {};
437
+ imports.wbg.__wbg___wbindgen_boolean_get_dea25b33882b895b = function(arg0) {
438
+ const v = arg0;
439
+ const ret = typeof v === "boolean" ? v : void 0;
440
+ return isLikeNone(ret) ? 16777215 : ret ? 1 : 0;
441
+ };
442
+ imports.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6 = function(arg0, arg1) {
443
+ const ret = debugString(arg1);
444
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
445
+ const len1 = WASM_VECTOR_LEN;
446
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
447
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
448
+ };
449
+ imports.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd = function(arg0) {
450
+ const ret = typeof arg0 === "function";
451
+ return ret;
452
+ };
453
+ imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
454
+ const ret = arg0 === void 0;
455
+ return ret;
456
+ };
457
+ imports.wbg.__wbg___wbindgen_number_get_9619185a74197f95 = function(arg0, arg1) {
458
+ const obj = arg1;
459
+ const ret = typeof obj === "number" ? obj : void 0;
460
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
461
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
462
+ };
463
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
464
+ throw new Error(getStringFromWasm0(arg0, arg1));
465
+ };
466
+ imports.wbg.__wbg__wbg_cb_unref_87dfb5aaa0cbcea7 = function(arg0) {
467
+ arg0._wbg_cb_unref();
468
+ };
469
+ imports.wbg.__wbg_byteLength_05cd8538d8f5f592 = function(arg0) {
470
+ const ret = arg0.byteLength;
471
+ return ret;
472
+ };
473
+ imports.wbg.__wbg_call_3020136f7a2d6e44 = function() {
474
+ return handleError(function(arg0, arg1, arg2) {
475
+ const ret = arg0.call(arg1, arg2);
476
+ return ret;
477
+ }, arguments);
478
+ };
479
+ imports.wbg.__wbg_call_abb4ff46ce38be40 = function() {
480
+ return handleError(function(arg0, arg1) {
481
+ const ret = arg0.call(arg1);
482
+ return ret;
483
+ }, arguments);
484
+ };
485
+ imports.wbg.__wbg_call_c8baa5c5e72d274e = function() {
486
+ return handleError(function(arg0, arg1, arg2, arg3) {
487
+ const ret = arg0.call(arg1, arg2, arg3);
488
+ return ret;
489
+ }, arguments);
490
+ };
491
+ imports.wbg.__wbg_datagrams_05d12f8029dbc662 = function(arg0) {
492
+ const ret = arg0.datagrams;
493
+ return ret;
494
+ };
495
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
496
+ let deferred0_0;
497
+ let deferred0_1;
498
+ try {
499
+ deferred0_0 = arg0;
500
+ deferred0_1 = arg1;
501
+ console.error(getStringFromWasm0(arg0, arg1));
502
+ } finally {
503
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
504
+ }
505
+ };
506
+ imports.wbg.__wbg_error_7bc7d576a6aaf855 = function(arg0) {
507
+ console.error(arg0);
508
+ };
509
+ imports.wbg.__wbg_fill_508dd108a821ee20 = function(arg0, arg1, arg2, arg3) {
510
+ const ret = arg0.fill(arg1, arg2 >>> 0, arg3 >>> 0);
511
+ return ret;
512
+ };
513
+ imports.wbg.__wbg_getReader_b6676f6d8b326942 = function(arg0) {
514
+ const ret = arg0.getReader();
515
+ return ret;
516
+ };
517
+ imports.wbg.__wbg_getUint16_cb7a6e659d68e5a6 = function(arg0, arg1, arg2) {
518
+ const ret = arg0.getUint16(arg1 >>> 0, arg2 !== 0);
519
+ return ret;
520
+ };
521
+ imports.wbg.__wbg_getUint32_d3b8478c9340d38b = function(arg0, arg1, arg2) {
522
+ const ret = arg0.getUint32(arg1 >>> 0, arg2 !== 0);
523
+ return ret;
524
+ };
525
+ imports.wbg.__wbg_getUint8_f42915a9262518eb = function(arg0, arg1) {
526
+ const ret = arg0.getUint8(arg1 >>> 0);
527
+ return ret;
528
+ };
529
+ imports.wbg.__wbg_getWriter_bbffb7cf601bec61 = function() {
530
+ return handleError(function(arg0) {
531
+ const ret = arg0.getWriter();
532
+ return ret;
533
+ }, arguments);
534
+ };
535
+ imports.wbg.__wbg_get_af9dab7e9603ea93 = function() {
536
+ return handleError(function(arg0, arg1) {
537
+ const ret = Reflect.get(arg0, arg1);
538
+ return ret;
539
+ }, arguments);
540
+ };
541
+ imports.wbg.__wbg_hardwareConcurrency_11023a850a093b20 = function(arg0) {
542
+ const ret = arg0.hardwareConcurrency;
543
+ return ret;
544
+ };
545
+ imports.wbg.__wbg_instanceof_Window_b5cf7783caa68180 = function(arg0) {
546
+ let result;
547
+ try {
548
+ result = arg0 instanceof Window;
549
+ } catch (_) {
550
+ result = false;
551
+ }
552
+ const ret = result;
553
+ return ret;
554
+ };
555
+ imports.wbg.__wbg_length_22ac23eaec9d8053 = function(arg0) {
556
+ const ret = arg0.length;
557
+ return ret;
558
+ };
559
+ imports.wbg.__wbg_load_f1dd26e734971d92 = function() {
560
+ return handleError(function(arg0, arg1) {
561
+ const ret = Atomics.load(arg0, arg1 >>> 0);
562
+ return ret;
563
+ }, arguments);
564
+ };
565
+ imports.wbg.__wbg_log_1d990106d99dacb7 = function(arg0) {
566
+ console.log(arg0);
567
+ };
568
+ imports.wbg.__wbg_navigator_b49edef831236138 = function(arg0) {
569
+ const ret = arg0.navigator;
570
+ return ret;
571
+ };
572
+ imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
573
+ const ret = new Object();
574
+ return ret;
575
+ };
576
+ imports.wbg.__wbg_new_25f239778d6112b9 = function() {
577
+ const ret = new Array();
578
+ return ret;
579
+ };
580
+ imports.wbg.__wbg_new_6421f6084cc5bc5a = function(arg0) {
581
+ const ret = new Uint8Array(arg0);
582
+ return ret;
583
+ };
584
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
585
+ const ret = new Error();
586
+ return ret;
587
+ };
588
+ imports.wbg.__wbg_new_ab1fe2437c86d873 = function(arg0) {
589
+ const ret = new SharedArrayBuffer(arg0 >>> 0);
590
+ return ret;
591
+ };
592
+ imports.wbg.__wbg_new_de1e660b88fc921f = function(arg0) {
593
+ const ret = new Int32Array(arg0);
594
+ return ret;
595
+ };
596
+ imports.wbg.__wbg_new_from_slice_f9c22b9153b26992 = function(arg0, arg1) {
597
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
598
+ return ret;
599
+ };
600
+ imports.wbg.__wbg_new_no_args_cb138f77cf6151ee = function(arg0, arg1) {
601
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
602
+ return ret;
603
+ };
604
+ imports.wbg.__wbg_new_with_options_661ae023a99756d4 = function() {
605
+ return handleError(function(arg0, arg1, arg2) {
606
+ const ret = new WebTransport(getStringFromWasm0(arg0, arg1), arg2);
607
+ return ret;
608
+ }, arguments);
609
+ };
610
+ imports.wbg.__wbg_new_with_shared_array_buffer_f801846979192910 = function(arg0, arg1, arg2) {
611
+ const ret = new DataView(arg0, arg1 >>> 0, arg2 >>> 0);
612
+ return ret;
613
+ };
614
+ imports.wbg.__wbg_notify_f7e901980222d3e0 = function() {
615
+ return handleError(function(arg0, arg1) {
616
+ const ret = Atomics.notify(arg0, arg1 >>> 0);
617
+ return ret;
618
+ }, arguments);
619
+ };
620
+ imports.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd = function(arg0, arg1, arg2) {
621
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
622
+ };
623
+ imports.wbg.__wbg_push_7d9be8f38fc13975 = function(arg0, arg1) {
624
+ const ret = arg0.push(arg1);
625
+ return ret;
626
+ };
627
+ imports.wbg.__wbg_queueMicrotask_9b549dfce8865860 = function(arg0) {
628
+ const ret = arg0.queueMicrotask;
629
+ return ret;
630
+ };
631
+ imports.wbg.__wbg_queueMicrotask_fca69f5bfad613a5 = function(arg0) {
632
+ queueMicrotask(arg0);
633
+ };
634
+ imports.wbg.__wbg_random_cc1f9237d866d212 = function() {
635
+ const ret = Math.random();
636
+ return ret;
637
+ };
638
+ imports.wbg.__wbg_read_39c4b35efcd03c25 = function(arg0) {
639
+ const ret = arg0.read();
640
+ return ret;
641
+ };
642
+ imports.wbg.__wbg_readable_91b7193a7ae57e51 = function(arg0) {
643
+ const ret = arg0.readable;
644
+ return ret;
645
+ };
646
+ imports.wbg.__wbg_ready_a3e887a4174c582b = function(arg0) {
647
+ const ret = arg0.ready;
648
+ return ret;
649
+ };
650
+ imports.wbg.__wbg_resolve_fd5bfbaa4ce36e1e = function(arg0) {
651
+ const ret = Promise.resolve(arg0);
652
+ return ret;
653
+ };
654
+ imports.wbg.__wbg_setUint16_ff3205ca61800a91 = function(arg0, arg1, arg2, arg3) {
655
+ arg0.setUint16(arg1 >>> 0, arg2, arg3 !== 0);
656
+ };
657
+ imports.wbg.__wbg_setUint32_3590d6adecfd0c9a = function(arg0, arg1, arg2, arg3) {
658
+ arg0.setUint32(arg1 >>> 0, arg2 >>> 0, arg3 !== 0);
659
+ };
660
+ imports.wbg.__wbg_setUint8_71dd48d3e18e4e40 = function(arg0, arg1, arg2) {
661
+ arg0.setUint8(arg1 >>> 0, arg2);
662
+ };
663
+ imports.wbg.__wbg_set_algorithm_f5b9d6dae15e63e3 = function(arg0, arg1, arg2) {
664
+ arg0.algorithm = getStringFromWasm0(arg1, arg2);
665
+ };
666
+ imports.wbg.__wbg_set_bc3a432bdcd60886 = function(arg0, arg1, arg2) {
667
+ arg0.set(arg1, arg2 >>> 0);
668
+ };
669
+ imports.wbg.__wbg_set_server_certificate_hashes_d12c95e03a45bcd5 = function(arg0, arg1) {
670
+ arg0.serverCertificateHashes = arg1;
671
+ };
672
+ imports.wbg.__wbg_set_value_3371f9dc48a34104 = function(arg0, arg1) {
673
+ arg0.value = arg1;
674
+ };
675
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
676
+ const ret = arg1.stack;
677
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
678
+ const len1 = WASM_VECTOR_LEN;
679
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
680
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
681
+ };
682
+ imports.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335 = function() {
683
+ const ret = typeof global === "undefined" ? null : global;
684
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
685
+ };
686
+ imports.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1 = function() {
687
+ const ret = typeof globalThis === "undefined" ? null : globalThis;
688
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
689
+ };
690
+ imports.wbg.__wbg_static_accessor_SELF_08f5a74c69739274 = function() {
691
+ const ret = typeof self === "undefined" ? null : self;
692
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
693
+ };
694
+ imports.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024 = function() {
695
+ const ret = typeof window === "undefined" ? null : window;
696
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
697
+ };
698
+ imports.wbg.__wbg_store_9f60a65541866026 = function() {
699
+ return handleError(function(arg0, arg1, arg2) {
700
+ const ret = Atomics.store(arg0, arg1 >>> 0, arg2);
701
+ return ret;
702
+ }, arguments);
703
+ };
704
+ imports.wbg.__wbg_then_429f7caf1026411d = function(arg0, arg1, arg2) {
705
+ const ret = arg0.then(arg1, arg2);
706
+ return ret;
707
+ };
708
+ imports.wbg.__wbg_then_4f95312d68691235 = function(arg0, arg1) {
709
+ const ret = arg0.then(arg1);
710
+ return ret;
711
+ };
712
+ imports.wbg.__wbg_warn_6e567d0d926ff881 = function(arg0) {
713
+ console.warn(arg0);
714
+ };
715
+ imports.wbg.__wbg_writable_523e68bd72433329 = function(arg0) {
716
+ const ret = arg0.writable;
717
+ return ret;
718
+ };
719
+ imports.wbg.__wbg_write_0823b42435137c02 = function(arg0, arg1) {
720
+ const ret = arg0.write(arg1);
721
+ return ret;
722
+ };
723
+ imports.wbg.__wbindgen_cast_0268c24e8eb79d38 = function(arg0, arg1) {
724
+ const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h3128a8e596085273, wasm_bindgen__convert__closures_____invoke__hb4c5b5d7ccdc8795);
725
+ return ret;
726
+ };
727
+ imports.wbg.__wbindgen_cast_0de0c044529fd48a = function(arg0, arg1) {
728
+ const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__hf225e18fc5ab9bc1, wasm_bindgen__convert__closures_____invoke__h39d3e89751b07765);
729
+ return ret;
730
+ };
731
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
732
+ const ret = getStringFromWasm0(arg0, arg1);
733
+ return ret;
734
+ };
735
+ imports.wbg.__wbindgen_cast_4ee4ae87c307a33c = function(arg0, arg1) {
736
+ const ret = makeClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h3128a8e596085273, wasm_bindgen__convert__closures_____invoke__hca46242f02098063);
737
+ return ret;
738
+ };
739
+ imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
740
+ const ret = arg0;
741
+ return ret;
742
+ };
743
+ imports.wbg.__wbindgen_init_externref_table = function() {
744
+ const table = wasm.__wbindgen_externrefs;
745
+ const offset = table.grow(4);
746
+ table.set(0, void 0);
747
+ table.set(offset + 0, void 0);
748
+ table.set(offset + 1, null);
749
+ table.set(offset + 2, true);
750
+ table.set(offset + 3, false);
751
+ };
752
+ return imports;
753
+ }
754
+ function __wbg_finalize_init(instance, module2) {
755
+ wasm = instance.exports;
756
+ __wbg_init.__wbindgen_wasm_module = module2;
757
+ cachedDataViewMemory0 = null;
758
+ cachedUint8ArrayMemory0 = null;
759
+ wasm.__wbindgen_start();
760
+ return wasm;
761
+ }
762
+ async function __wbg_init(module_or_path) {
763
+ if (wasm !== void 0) return wasm;
764
+ if (typeof module_or_path !== "undefined") {
765
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
766
+ ({ module_or_path } = module_or_path);
767
+ } else {
768
+ console.warn("using deprecated parameters for the initialization function; pass a single object instead");
769
+ }
770
+ }
771
+ const imports = __wbg_get_imports();
772
+ if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
773
+ module_or_path = fetch(module_or_path);
774
+ }
775
+ const { instance, module: module2 } = await __wbg_load(await module_or_path, imports);
776
+ return __wbg_finalize_init(instance, module2);
777
+ }
778
+ var riscv_vm_default = __wbg_init;
779
+
780
+ // worker.ts
781
+ var initialized = false;
782
+ self.onmessage = async (event) => {
783
+ const { hartId, sharedMem, entryPc } = event.data;
784
+ console.log(`[Worker ${hartId}] Received init message`);
785
+ if (!initialized) {
786
+ try {
787
+ await riscv_vm_default();
788
+ initialized = true;
789
+ console.log(`[Worker ${hartId}] WASM initialized`);
790
+ } catch (e) {
791
+ console.error(`[Worker ${hartId}] WASM init failed:`, e);
792
+ const msg = {
793
+ type: "error",
794
+ hartId,
795
+ error: String(e)
796
+ };
797
+ self.postMessage(msg);
798
+ return;
799
+ }
800
+ }
801
+ const readyMsg = { type: "ready", hartId };
802
+ self.postMessage(readyMsg);
803
+ try {
804
+ const pc = BigInt(Math.floor(entryPc));
805
+ console.log(`[Worker ${hartId}] Starting execution at PC=0x${pc.toString(16)}`);
806
+ worker_entry(hartId, sharedMem, pc);
807
+ } catch (e) {
808
+ console.error(`[Worker ${hartId}] Execution error:`, e);
809
+ const msg = {
810
+ type: "error",
811
+ hartId,
812
+ error: String(e)
813
+ };
814
+ self.postMessage(msg);
815
+ return;
816
+ }
817
+ console.log(`[Worker ${hartId}] Halted`);
818
+ const haltedMsg = { type: "halted", hartId };
819
+ self.postMessage(haltedMsg);
820
+ };
821
+ self.onerror = (e) => {
822
+ console.error("[Worker] Uncaught error:", e);
823
+ const msg = {
824
+ type: "error",
825
+ error: e.message || String(e)
826
+ };
827
+ self.postMessage(msg);
828
+ };