@aptre/v86 0.6.0 → 0.6.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/dist/v86.browser.js +99 -35
- package/dist/v86.browser.js.map +3 -3
- package/dist/v86.js +99 -35
- package/dist/v86.js.map +3 -3
- package/package.json +1 -1
- package/src/browser/starter.ts +42 -2
- package/src/cpu.ts +83 -93
package/dist/v86.js
CHANGED
|
@@ -18786,6 +18786,7 @@ var CPU = class {
|
|
|
18786
18786
|
wasm_memory;
|
|
18787
18787
|
memory_size;
|
|
18788
18788
|
mem8;
|
|
18789
|
+
mem8_offset = 0;
|
|
18789
18790
|
mem32s;
|
|
18790
18791
|
segment_is_null;
|
|
18791
18792
|
segment_offsets;
|
|
@@ -18915,10 +18916,46 @@ var CPU = class {
|
|
|
18915
18916
|
this.wasm_memory = wm.wasm_memory;
|
|
18916
18917
|
this.wasm_patch();
|
|
18917
18918
|
this.create_jit_imports();
|
|
18918
|
-
const memory = this.wasm_memory;
|
|
18919
|
-
this.memory_size = view(Uint32Array, memory, 812, 1);
|
|
18920
18919
|
this.mem8 = new Uint8Array(0);
|
|
18921
18920
|
this.mem32s = new Int32Array(this.mem8.buffer);
|
|
18921
|
+
this.rebuild_wasm_views();
|
|
18922
|
+
this.devices = {};
|
|
18923
|
+
this.memory_map_read8 = [];
|
|
18924
|
+
this.memory_map_write8 = [];
|
|
18925
|
+
this.memory_map_read32 = [];
|
|
18926
|
+
this.memory_map_write32 = [];
|
|
18927
|
+
this.bios = {
|
|
18928
|
+
main: null,
|
|
18929
|
+
vga: null
|
|
18930
|
+
};
|
|
18931
|
+
this.fpu_stack_empty[0] = 255;
|
|
18932
|
+
this.fpu_stack_ptr[0] = 0;
|
|
18933
|
+
this.fpu_control_word[0] = 895;
|
|
18934
|
+
this.fpu_status_word[0] = 0;
|
|
18935
|
+
this.fpu_ip[0] = 0;
|
|
18936
|
+
this.fpu_ip_selector[0] = 0;
|
|
18937
|
+
this.fpu_opcode[0] = 0;
|
|
18938
|
+
this.fpu_dp[0] = 0;
|
|
18939
|
+
this.fpu_dp_selector[0] = 0;
|
|
18940
|
+
this.fw_value = [];
|
|
18941
|
+
this.fw_pointer = 0;
|
|
18942
|
+
this.option_roms = [];
|
|
18943
|
+
this.io = void 0;
|
|
18944
|
+
this.bus = bus;
|
|
18945
|
+
this.set_tsc(0, 0);
|
|
18946
|
+
if (false) {
|
|
18947
|
+
this.seen_code = {};
|
|
18948
|
+
this.seen_code_uncompiled = {};
|
|
18949
|
+
}
|
|
18950
|
+
}
|
|
18951
|
+
/**
|
|
18952
|
+
* Rebuild all TypedArray views into WASM linear memory.
|
|
18953
|
+
* Must be called after any wasm_memory.grow() since growth
|
|
18954
|
+
* detaches the old ArrayBuffer, invalidating all views.
|
|
18955
|
+
*/
|
|
18956
|
+
rebuild_wasm_views() {
|
|
18957
|
+
const memory = this.wasm_memory;
|
|
18958
|
+
this.memory_size = view(Uint32Array, memory, 812, 1);
|
|
18922
18959
|
this.segment_is_null = view(Uint8Array, memory, 724, 8);
|
|
18923
18960
|
this.segment_offsets = view(Int32Array, memory, 736, 8);
|
|
18924
18961
|
this.segment_limits = view(Uint32Array, memory, 768, 8);
|
|
@@ -18947,40 +18984,22 @@ var CPU = class {
|
|
|
18947
18984
|
this.last_op1 = view(Int32Array, memory, 104, 1);
|
|
18948
18985
|
this.last_result = view(Int32Array, memory, 112, 1);
|
|
18949
18986
|
this.current_tsc = view(Uint32Array, memory, 960, 2);
|
|
18950
|
-
this.devices = {};
|
|
18951
18987
|
this.instruction_pointer = view(Int32Array, memory, 556, 1);
|
|
18952
18988
|
this.previous_ip = view(Int32Array, memory, 560, 1);
|
|
18953
18989
|
this.apic_enabled = view(Uint8Array, memory, 548, 1);
|
|
18954
18990
|
this.acpi_enabled = view(Uint8Array, memory, 552, 1);
|
|
18955
|
-
this.memory_map_read8 = [];
|
|
18956
|
-
this.memory_map_write8 = [];
|
|
18957
|
-
this.memory_map_read32 = [];
|
|
18958
|
-
this.memory_map_write32 = [];
|
|
18959
|
-
this.bios = {
|
|
18960
|
-
main: null,
|
|
18961
|
-
vga: null
|
|
18962
|
-
};
|
|
18963
18991
|
this.instruction_counter = view(Uint32Array, memory, 664, 1);
|
|
18964
18992
|
this.reg32 = view(Int32Array, memory, 64, 8);
|
|
18965
18993
|
this.fpu_st = view(Int32Array, memory, 1152, 4 * 8);
|
|
18966
18994
|
this.fpu_stack_empty = view(Uint8Array, memory, 816, 1);
|
|
18967
|
-
this.fpu_stack_empty[0] = 255;
|
|
18968
18995
|
this.fpu_stack_ptr = view(Uint8Array, memory, 1032, 1);
|
|
18969
|
-
this.fpu_stack_ptr[0] = 0;
|
|
18970
18996
|
this.fpu_control_word = view(Uint16Array, memory, 1036, 1);
|
|
18971
|
-
this.fpu_control_word[0] = 895;
|
|
18972
18997
|
this.fpu_status_word = view(Uint16Array, memory, 1040, 1);
|
|
18973
|
-
this.fpu_status_word[0] = 0;
|
|
18974
18998
|
this.fpu_ip = view(Int32Array, memory, 1048, 1);
|
|
18975
|
-
this.fpu_ip[0] = 0;
|
|
18976
18999
|
this.fpu_ip_selector = view(Int32Array, memory, 1052, 1);
|
|
18977
|
-
this.fpu_ip_selector[0] = 0;
|
|
18978
19000
|
this.fpu_opcode = view(Int32Array, memory, 1044, 1);
|
|
18979
|
-
this.fpu_opcode[0] = 0;
|
|
18980
19001
|
this.fpu_dp = view(Int32Array, memory, 1056, 1);
|
|
18981
|
-
this.fpu_dp[0] = 0;
|
|
18982
19002
|
this.fpu_dp_selector = view(Int32Array, memory, 1060, 1);
|
|
18983
|
-
this.fpu_dp_selector[0] = 0;
|
|
18984
19003
|
this.reg_xmm32s = view(Int32Array, memory, 832, 8 * 4);
|
|
18985
19004
|
this.mxcsr = view(Int32Array, memory, 824, 1);
|
|
18986
19005
|
this.sreg = view(Uint16Array, memory, 668, 8);
|
|
@@ -18988,16 +19007,6 @@ var CPU = class {
|
|
|
18988
19007
|
this.reg_pdpte = view(Int32Array, memory, 968, 8);
|
|
18989
19008
|
this.svga_dirty_bitmap_min_offset = view(Uint32Array, memory, 716, 1);
|
|
18990
19009
|
this.svga_dirty_bitmap_max_offset = view(Uint32Array, memory, 720, 1);
|
|
18991
|
-
this.fw_value = [];
|
|
18992
|
-
this.fw_pointer = 0;
|
|
18993
|
-
this.option_roms = [];
|
|
18994
|
-
this.io = void 0;
|
|
18995
|
-
this.bus = bus;
|
|
18996
|
-
this.set_tsc(0, 0);
|
|
18997
|
-
if (false) {
|
|
18998
|
-
this.seen_code = {};
|
|
18999
|
-
this.seen_code_uncompiled = {};
|
|
19000
|
-
}
|
|
19001
19010
|
}
|
|
19002
19011
|
mmap_read8(addr) {
|
|
19003
19012
|
const value = this.memory_map_read8[addr >>> MMAP_BLOCK_BITS](addr);
|
|
@@ -19300,7 +19309,7 @@ var CPU = class {
|
|
|
19300
19309
|
);
|
|
19301
19310
|
}
|
|
19302
19311
|
resize_memory(new_size) {
|
|
19303
|
-
const mem8_offset = this.
|
|
19312
|
+
const mem8_offset = this.mem8_offset;
|
|
19304
19313
|
const needed_total = mem8_offset + new_size;
|
|
19305
19314
|
const current_buffer = this.wasm_memory.buffer.byteLength;
|
|
19306
19315
|
if (needed_total > current_buffer) {
|
|
@@ -19308,6 +19317,7 @@ var CPU = class {
|
|
|
19308
19317
|
(needed_total - current_buffer) / WASM_PAGE_SIZE
|
|
19309
19318
|
);
|
|
19310
19319
|
this.wasm_memory.grow(grow_pages);
|
|
19320
|
+
this.rebuild_wasm_views();
|
|
19311
19321
|
}
|
|
19312
19322
|
this.mem8 = view(Uint8Array, this.wasm_memory, mem8_offset, new_size);
|
|
19313
19323
|
this.mem32s = view(
|
|
@@ -19319,7 +19329,12 @@ var CPU = class {
|
|
|
19319
19329
|
this.memory_size[0] = new_size;
|
|
19320
19330
|
}
|
|
19321
19331
|
set_state(state) {
|
|
19322
|
-
|
|
19332
|
+
const saved_memory_size = state[0];
|
|
19333
|
+
if (saved_memory_size > this.memory_size[0]) {
|
|
19334
|
+
this.resize_memory(saved_memory_size);
|
|
19335
|
+
} else {
|
|
19336
|
+
this.memory_size[0] = saved_memory_size;
|
|
19337
|
+
}
|
|
19323
19338
|
if (this.mem8.length !== this.memory_size[0]) {
|
|
19324
19339
|
console.warn(
|
|
19325
19340
|
"Note: Memory size mismatch. we=" + this.mem8.length + " state=" + this.memory_size[0]
|
|
@@ -19619,8 +19634,10 @@ var CPU = class {
|
|
|
19619
19634
|
this.memory_size[0] === 0,
|
|
19620
19635
|
"Expected uninitialised memory"
|
|
19621
19636
|
);
|
|
19622
|
-
this.memory_size[0] = size;
|
|
19623
19637
|
const memory_offset = this.allocate_memory(size);
|
|
19638
|
+
this.rebuild_wasm_views();
|
|
19639
|
+
this.memory_size[0] = size;
|
|
19640
|
+
this.mem8_offset = memory_offset;
|
|
19624
19641
|
this.mem8 = view(Uint8Array, this.wasm_memory, memory_offset, size);
|
|
19625
19642
|
this.mem32s = view(
|
|
19626
19643
|
Uint32Array,
|
|
@@ -19864,6 +19881,21 @@ var CPU = class {
|
|
|
19864
19881
|
}
|
|
19865
19882
|
}
|
|
19866
19883
|
this.debug_init();
|
|
19884
|
+
this.rebuild_wasm_views();
|
|
19885
|
+
if (this.mem8_offset > 0) {
|
|
19886
|
+
this.mem8 = view(
|
|
19887
|
+
Uint8Array,
|
|
19888
|
+
this.wasm_memory,
|
|
19889
|
+
this.mem8_offset,
|
|
19890
|
+
this.memory_size[0]
|
|
19891
|
+
);
|
|
19892
|
+
this.mem32s = view(
|
|
19893
|
+
Uint32Array,
|
|
19894
|
+
this.wasm_memory,
|
|
19895
|
+
this.mem8_offset,
|
|
19896
|
+
this.memory_size[0] >> 2
|
|
19897
|
+
);
|
|
19898
|
+
}
|
|
19867
19899
|
}
|
|
19868
19900
|
load_multiboot(buffer) {
|
|
19869
19901
|
if (this.bios.main) {
|
|
@@ -26174,12 +26206,25 @@ var V86 = class {
|
|
|
26174
26206
|
this.bus = bus[0];
|
|
26175
26207
|
this.emulator_bus = bus[1];
|
|
26176
26208
|
let cpu;
|
|
26177
|
-
|
|
26209
|
+
const memory_size = options.memory_size || 64 * 1024 * 1024;
|
|
26210
|
+
const vga_memory_size = options.vga_memory_size || 8 * 1024 * 1024;
|
|
26211
|
+
const memory_max = options.memory_max || (memory_size + vga_memory_size) * 4;
|
|
26212
|
+
const WASM_PAGE_SIZE2 = 65536;
|
|
26213
|
+
const wasm_initial_pages = 256;
|
|
26214
|
+
const wasm_max_pages = Math.max(
|
|
26215
|
+
wasm_initial_pages,
|
|
26216
|
+
Math.min(Math.ceil(memory_max / WASM_PAGE_SIZE2), 65536)
|
|
26217
|
+
);
|
|
26218
|
+
const wasm_memory = new WebAssembly.Memory({
|
|
26219
|
+
initial: wasm_initial_pages,
|
|
26220
|
+
maximum: wasm_max_pages
|
|
26221
|
+
});
|
|
26178
26222
|
const wasm_table = new WebAssembly.Table({
|
|
26179
26223
|
element: "anyfunc",
|
|
26180
26224
|
initial: WASM_TABLE_SIZE + WASM_TABLE_OFFSET
|
|
26181
26225
|
});
|
|
26182
26226
|
const wasm_shared_funcs = {
|
|
26227
|
+
memory: wasm_memory,
|
|
26183
26228
|
cpu_exception_hook: (n) => this.cpu_exception_hook(n),
|
|
26184
26229
|
run_hardware_timers: function(a, t) {
|
|
26185
26230
|
return cpu.run_hardware_timers(a, t);
|
|
@@ -26314,7 +26359,6 @@ var V86 = class {
|
|
|
26314
26359
|
};
|
|
26315
26360
|
}
|
|
26316
26361
|
wasm_fn({ env: wasm_shared_funcs }).then((exports) => {
|
|
26317
|
-
wasm_memory = exports.memory;
|
|
26318
26362
|
exports["rust_init"]();
|
|
26319
26363
|
const emulator = this.v86 = new v86(this.emulator_bus, {
|
|
26320
26364
|
exports,
|
|
@@ -26841,6 +26885,26 @@ var V86 = class {
|
|
|
26841
26885
|
async run() {
|
|
26842
26886
|
this.v86.run();
|
|
26843
26887
|
}
|
|
26888
|
+
/**
|
|
26889
|
+
* Grow guest memory to the specified size in bytes. Stops the VM,
|
|
26890
|
+
* grows WASM linear memory, updates memory_size, clears the TLB,
|
|
26891
|
+
* and resumes execution.
|
|
26892
|
+
*/
|
|
26893
|
+
async growMemory(newSizeBytes) {
|
|
26894
|
+
const cpu = this.v86.cpu;
|
|
26895
|
+
if (newSizeBytes <= cpu.memory_size[0]) {
|
|
26896
|
+
return;
|
|
26897
|
+
}
|
|
26898
|
+
const wasRunning = this.cpu_is_running;
|
|
26899
|
+
if (wasRunning) {
|
|
26900
|
+
await this.stop();
|
|
26901
|
+
}
|
|
26902
|
+
cpu.resize_memory(newSizeBytes);
|
|
26903
|
+
cpu.full_clear_tlb();
|
|
26904
|
+
if (wasRunning) {
|
|
26905
|
+
await this.run();
|
|
26906
|
+
}
|
|
26907
|
+
}
|
|
26844
26908
|
/**
|
|
26845
26909
|
* Stop emulation. Do nothing if emulator is not running. Can be asynchronous.
|
|
26846
26910
|
*/
|