@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.browser.js
CHANGED
|
@@ -18822,6 +18822,7 @@ var V86Starter = (() => {
|
|
|
18822
18822
|
wasm_memory;
|
|
18823
18823
|
memory_size;
|
|
18824
18824
|
mem8;
|
|
18825
|
+
mem8_offset = 0;
|
|
18825
18826
|
mem32s;
|
|
18826
18827
|
segment_is_null;
|
|
18827
18828
|
segment_offsets;
|
|
@@ -18951,10 +18952,46 @@ var V86Starter = (() => {
|
|
|
18951
18952
|
this.wasm_memory = wm.wasm_memory;
|
|
18952
18953
|
this.wasm_patch();
|
|
18953
18954
|
this.create_jit_imports();
|
|
18954
|
-
const memory = this.wasm_memory;
|
|
18955
|
-
this.memory_size = view(Uint32Array, memory, 812, 1);
|
|
18956
18955
|
this.mem8 = new Uint8Array(0);
|
|
18957
18956
|
this.mem32s = new Int32Array(this.mem8.buffer);
|
|
18957
|
+
this.rebuild_wasm_views();
|
|
18958
|
+
this.devices = {};
|
|
18959
|
+
this.memory_map_read8 = [];
|
|
18960
|
+
this.memory_map_write8 = [];
|
|
18961
|
+
this.memory_map_read32 = [];
|
|
18962
|
+
this.memory_map_write32 = [];
|
|
18963
|
+
this.bios = {
|
|
18964
|
+
main: null,
|
|
18965
|
+
vga: null
|
|
18966
|
+
};
|
|
18967
|
+
this.fpu_stack_empty[0] = 255;
|
|
18968
|
+
this.fpu_stack_ptr[0] = 0;
|
|
18969
|
+
this.fpu_control_word[0] = 895;
|
|
18970
|
+
this.fpu_status_word[0] = 0;
|
|
18971
|
+
this.fpu_ip[0] = 0;
|
|
18972
|
+
this.fpu_ip_selector[0] = 0;
|
|
18973
|
+
this.fpu_opcode[0] = 0;
|
|
18974
|
+
this.fpu_dp[0] = 0;
|
|
18975
|
+
this.fpu_dp_selector[0] = 0;
|
|
18976
|
+
this.fw_value = [];
|
|
18977
|
+
this.fw_pointer = 0;
|
|
18978
|
+
this.option_roms = [];
|
|
18979
|
+
this.io = void 0;
|
|
18980
|
+
this.bus = bus;
|
|
18981
|
+
this.set_tsc(0, 0);
|
|
18982
|
+
if (false) {
|
|
18983
|
+
this.seen_code = {};
|
|
18984
|
+
this.seen_code_uncompiled = {};
|
|
18985
|
+
}
|
|
18986
|
+
}
|
|
18987
|
+
/**
|
|
18988
|
+
* Rebuild all TypedArray views into WASM linear memory.
|
|
18989
|
+
* Must be called after any wasm_memory.grow() since growth
|
|
18990
|
+
* detaches the old ArrayBuffer, invalidating all views.
|
|
18991
|
+
*/
|
|
18992
|
+
rebuild_wasm_views() {
|
|
18993
|
+
const memory = this.wasm_memory;
|
|
18994
|
+
this.memory_size = view(Uint32Array, memory, 812, 1);
|
|
18958
18995
|
this.segment_is_null = view(Uint8Array, memory, 724, 8);
|
|
18959
18996
|
this.segment_offsets = view(Int32Array, memory, 736, 8);
|
|
18960
18997
|
this.segment_limits = view(Uint32Array, memory, 768, 8);
|
|
@@ -18983,40 +19020,22 @@ var V86Starter = (() => {
|
|
|
18983
19020
|
this.last_op1 = view(Int32Array, memory, 104, 1);
|
|
18984
19021
|
this.last_result = view(Int32Array, memory, 112, 1);
|
|
18985
19022
|
this.current_tsc = view(Uint32Array, memory, 960, 2);
|
|
18986
|
-
this.devices = {};
|
|
18987
19023
|
this.instruction_pointer = view(Int32Array, memory, 556, 1);
|
|
18988
19024
|
this.previous_ip = view(Int32Array, memory, 560, 1);
|
|
18989
19025
|
this.apic_enabled = view(Uint8Array, memory, 548, 1);
|
|
18990
19026
|
this.acpi_enabled = view(Uint8Array, memory, 552, 1);
|
|
18991
|
-
this.memory_map_read8 = [];
|
|
18992
|
-
this.memory_map_write8 = [];
|
|
18993
|
-
this.memory_map_read32 = [];
|
|
18994
|
-
this.memory_map_write32 = [];
|
|
18995
|
-
this.bios = {
|
|
18996
|
-
main: null,
|
|
18997
|
-
vga: null
|
|
18998
|
-
};
|
|
18999
19027
|
this.instruction_counter = view(Uint32Array, memory, 664, 1);
|
|
19000
19028
|
this.reg32 = view(Int32Array, memory, 64, 8);
|
|
19001
19029
|
this.fpu_st = view(Int32Array, memory, 1152, 4 * 8);
|
|
19002
19030
|
this.fpu_stack_empty = view(Uint8Array, memory, 816, 1);
|
|
19003
|
-
this.fpu_stack_empty[0] = 255;
|
|
19004
19031
|
this.fpu_stack_ptr = view(Uint8Array, memory, 1032, 1);
|
|
19005
|
-
this.fpu_stack_ptr[0] = 0;
|
|
19006
19032
|
this.fpu_control_word = view(Uint16Array, memory, 1036, 1);
|
|
19007
|
-
this.fpu_control_word[0] = 895;
|
|
19008
19033
|
this.fpu_status_word = view(Uint16Array, memory, 1040, 1);
|
|
19009
|
-
this.fpu_status_word[0] = 0;
|
|
19010
19034
|
this.fpu_ip = view(Int32Array, memory, 1048, 1);
|
|
19011
|
-
this.fpu_ip[0] = 0;
|
|
19012
19035
|
this.fpu_ip_selector = view(Int32Array, memory, 1052, 1);
|
|
19013
|
-
this.fpu_ip_selector[0] = 0;
|
|
19014
19036
|
this.fpu_opcode = view(Int32Array, memory, 1044, 1);
|
|
19015
|
-
this.fpu_opcode[0] = 0;
|
|
19016
19037
|
this.fpu_dp = view(Int32Array, memory, 1056, 1);
|
|
19017
|
-
this.fpu_dp[0] = 0;
|
|
19018
19038
|
this.fpu_dp_selector = view(Int32Array, memory, 1060, 1);
|
|
19019
|
-
this.fpu_dp_selector[0] = 0;
|
|
19020
19039
|
this.reg_xmm32s = view(Int32Array, memory, 832, 8 * 4);
|
|
19021
19040
|
this.mxcsr = view(Int32Array, memory, 824, 1);
|
|
19022
19041
|
this.sreg = view(Uint16Array, memory, 668, 8);
|
|
@@ -19024,16 +19043,6 @@ var V86Starter = (() => {
|
|
|
19024
19043
|
this.reg_pdpte = view(Int32Array, memory, 968, 8);
|
|
19025
19044
|
this.svga_dirty_bitmap_min_offset = view(Uint32Array, memory, 716, 1);
|
|
19026
19045
|
this.svga_dirty_bitmap_max_offset = view(Uint32Array, memory, 720, 1);
|
|
19027
|
-
this.fw_value = [];
|
|
19028
|
-
this.fw_pointer = 0;
|
|
19029
|
-
this.option_roms = [];
|
|
19030
|
-
this.io = void 0;
|
|
19031
|
-
this.bus = bus;
|
|
19032
|
-
this.set_tsc(0, 0);
|
|
19033
|
-
if (false) {
|
|
19034
|
-
this.seen_code = {};
|
|
19035
|
-
this.seen_code_uncompiled = {};
|
|
19036
|
-
}
|
|
19037
19046
|
}
|
|
19038
19047
|
mmap_read8(addr) {
|
|
19039
19048
|
const value = this.memory_map_read8[addr >>> MMAP_BLOCK_BITS](addr);
|
|
@@ -19336,7 +19345,7 @@ var V86Starter = (() => {
|
|
|
19336
19345
|
);
|
|
19337
19346
|
}
|
|
19338
19347
|
resize_memory(new_size) {
|
|
19339
|
-
const mem8_offset = this.
|
|
19348
|
+
const mem8_offset = this.mem8_offset;
|
|
19340
19349
|
const needed_total = mem8_offset + new_size;
|
|
19341
19350
|
const current_buffer = this.wasm_memory.buffer.byteLength;
|
|
19342
19351
|
if (needed_total > current_buffer) {
|
|
@@ -19344,6 +19353,7 @@ var V86Starter = (() => {
|
|
|
19344
19353
|
(needed_total - current_buffer) / WASM_PAGE_SIZE
|
|
19345
19354
|
);
|
|
19346
19355
|
this.wasm_memory.grow(grow_pages);
|
|
19356
|
+
this.rebuild_wasm_views();
|
|
19347
19357
|
}
|
|
19348
19358
|
this.mem8 = view(Uint8Array, this.wasm_memory, mem8_offset, new_size);
|
|
19349
19359
|
this.mem32s = view(
|
|
@@ -19355,7 +19365,12 @@ var V86Starter = (() => {
|
|
|
19355
19365
|
this.memory_size[0] = new_size;
|
|
19356
19366
|
}
|
|
19357
19367
|
set_state(state) {
|
|
19358
|
-
|
|
19368
|
+
const saved_memory_size = state[0];
|
|
19369
|
+
if (saved_memory_size > this.memory_size[0]) {
|
|
19370
|
+
this.resize_memory(saved_memory_size);
|
|
19371
|
+
} else {
|
|
19372
|
+
this.memory_size[0] = saved_memory_size;
|
|
19373
|
+
}
|
|
19359
19374
|
if (this.mem8.length !== this.memory_size[0]) {
|
|
19360
19375
|
console.warn(
|
|
19361
19376
|
"Note: Memory size mismatch. we=" + this.mem8.length + " state=" + this.memory_size[0]
|
|
@@ -19655,8 +19670,10 @@ var V86Starter = (() => {
|
|
|
19655
19670
|
this.memory_size[0] === 0,
|
|
19656
19671
|
"Expected uninitialised memory"
|
|
19657
19672
|
);
|
|
19658
|
-
this.memory_size[0] = size;
|
|
19659
19673
|
const memory_offset = this.allocate_memory(size);
|
|
19674
|
+
this.rebuild_wasm_views();
|
|
19675
|
+
this.memory_size[0] = size;
|
|
19676
|
+
this.mem8_offset = memory_offset;
|
|
19660
19677
|
this.mem8 = view(Uint8Array, this.wasm_memory, memory_offset, size);
|
|
19661
19678
|
this.mem32s = view(
|
|
19662
19679
|
Uint32Array,
|
|
@@ -19900,6 +19917,21 @@ var V86Starter = (() => {
|
|
|
19900
19917
|
}
|
|
19901
19918
|
}
|
|
19902
19919
|
this.debug_init();
|
|
19920
|
+
this.rebuild_wasm_views();
|
|
19921
|
+
if (this.mem8_offset > 0) {
|
|
19922
|
+
this.mem8 = view(
|
|
19923
|
+
Uint8Array,
|
|
19924
|
+
this.wasm_memory,
|
|
19925
|
+
this.mem8_offset,
|
|
19926
|
+
this.memory_size[0]
|
|
19927
|
+
);
|
|
19928
|
+
this.mem32s = view(
|
|
19929
|
+
Uint32Array,
|
|
19930
|
+
this.wasm_memory,
|
|
19931
|
+
this.mem8_offset,
|
|
19932
|
+
this.memory_size[0] >> 2
|
|
19933
|
+
);
|
|
19934
|
+
}
|
|
19903
19935
|
}
|
|
19904
19936
|
load_multiboot(buffer) {
|
|
19905
19937
|
if (this.bios.main) {
|
|
@@ -26211,12 +26243,25 @@ ${e.stack || e.message}`
|
|
|
26211
26243
|
this.bus = bus[0];
|
|
26212
26244
|
this.emulator_bus = bus[1];
|
|
26213
26245
|
let cpu;
|
|
26214
|
-
|
|
26246
|
+
const memory_size = options.memory_size || 64 * 1024 * 1024;
|
|
26247
|
+
const vga_memory_size = options.vga_memory_size || 8 * 1024 * 1024;
|
|
26248
|
+
const memory_max = options.memory_max || (memory_size + vga_memory_size) * 4;
|
|
26249
|
+
const WASM_PAGE_SIZE2 = 65536;
|
|
26250
|
+
const wasm_initial_pages = 256;
|
|
26251
|
+
const wasm_max_pages = Math.max(
|
|
26252
|
+
wasm_initial_pages,
|
|
26253
|
+
Math.min(Math.ceil(memory_max / WASM_PAGE_SIZE2), 65536)
|
|
26254
|
+
);
|
|
26255
|
+
const wasm_memory = new WebAssembly.Memory({
|
|
26256
|
+
initial: wasm_initial_pages,
|
|
26257
|
+
maximum: wasm_max_pages
|
|
26258
|
+
});
|
|
26215
26259
|
const wasm_table = new WebAssembly.Table({
|
|
26216
26260
|
element: "anyfunc",
|
|
26217
26261
|
initial: WASM_TABLE_SIZE + WASM_TABLE_OFFSET
|
|
26218
26262
|
});
|
|
26219
26263
|
const wasm_shared_funcs = {
|
|
26264
|
+
memory: wasm_memory,
|
|
26220
26265
|
cpu_exception_hook: (n) => this.cpu_exception_hook(n),
|
|
26221
26266
|
run_hardware_timers: function(a, t) {
|
|
26222
26267
|
return cpu.run_hardware_timers(a, t);
|
|
@@ -26351,7 +26396,6 @@ ${e.stack || e.message}`
|
|
|
26351
26396
|
};
|
|
26352
26397
|
}
|
|
26353
26398
|
wasm_fn({ env: wasm_shared_funcs }).then((exports) => {
|
|
26354
|
-
wasm_memory = exports.memory;
|
|
26355
26399
|
exports["rust_init"]();
|
|
26356
26400
|
const emulator = this.v86 = new v86(this.emulator_bus, {
|
|
26357
26401
|
exports,
|
|
@@ -26878,6 +26922,26 @@ ${e.stack || e.message}`
|
|
|
26878
26922
|
async run() {
|
|
26879
26923
|
this.v86.run();
|
|
26880
26924
|
}
|
|
26925
|
+
/**
|
|
26926
|
+
* Grow guest memory to the specified size in bytes. Stops the VM,
|
|
26927
|
+
* grows WASM linear memory, updates memory_size, clears the TLB,
|
|
26928
|
+
* and resumes execution.
|
|
26929
|
+
*/
|
|
26930
|
+
async growMemory(newSizeBytes) {
|
|
26931
|
+
const cpu = this.v86.cpu;
|
|
26932
|
+
if (newSizeBytes <= cpu.memory_size[0]) {
|
|
26933
|
+
return;
|
|
26934
|
+
}
|
|
26935
|
+
const wasRunning = this.cpu_is_running;
|
|
26936
|
+
if (wasRunning) {
|
|
26937
|
+
await this.stop();
|
|
26938
|
+
}
|
|
26939
|
+
cpu.resize_memory(newSizeBytes);
|
|
26940
|
+
cpu.full_clear_tlb();
|
|
26941
|
+
if (wasRunning) {
|
|
26942
|
+
await this.run();
|
|
26943
|
+
}
|
|
26944
|
+
}
|
|
26881
26945
|
/**
|
|
26882
26946
|
* Stop emulation. Do nothing if emulator is not running. Can be asynchronous.
|
|
26883
26947
|
*/
|