@aptre/v86 0.5.0
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/LICENSE +22 -0
- package/LICENSE.MIT +22 -0
- package/Readme.md +237 -0
- package/dist/v86.browser.js +26666 -0
- package/dist/v86.browser.js.map +7 -0
- package/dist/v86.js +26632 -0
- package/dist/v86.js.map +7 -0
- package/gen/generate_analyzer.ts +512 -0
- package/gen/generate_interpreter.ts +522 -0
- package/gen/generate_jit.ts +624 -0
- package/gen/rust_ast.ts +107 -0
- package/gen/util.ts +35 -0
- package/gen/x86_table.ts +1836 -0
- package/lib/9p.ts +1547 -0
- package/lib/filesystem.ts +1879 -0
- package/lib/marshall.ts +168 -0
- package/lib/softfloat/softfloat.c +32501 -0
- package/lib/zstd/zstddeclib.c +13520 -0
- package/package.json +75 -0
- package/src/acpi.ts +267 -0
- package/src/browser/dummy_screen.ts +106 -0
- package/src/browser/fake_network.ts +1771 -0
- package/src/browser/fetch_network.ts +361 -0
- package/src/browser/filestorage.ts +124 -0
- package/src/browser/inbrowser_network.ts +57 -0
- package/src/browser/keyboard.ts +564 -0
- package/src/browser/main.ts +3415 -0
- package/src/browser/mouse.ts +255 -0
- package/src/browser/network.ts +142 -0
- package/src/browser/print_stats.ts +336 -0
- package/src/browser/screen.ts +978 -0
- package/src/browser/serial.ts +316 -0
- package/src/browser/speaker.ts +1223 -0
- package/src/browser/starter.ts +1688 -0
- package/src/browser/wisp_network.ts +332 -0
- package/src/browser/worker_bus.ts +64 -0
- package/src/buffer.ts +652 -0
- package/src/bus.ts +78 -0
- package/src/const.ts +128 -0
- package/src/cpu.ts +2891 -0
- package/src/dma.ts +474 -0
- package/src/elf.ts +251 -0
- package/src/floppy.ts +1778 -0
- package/src/ide.ts +3455 -0
- package/src/io.ts +504 -0
- package/src/iso9660.ts +317 -0
- package/src/kernel.ts +250 -0
- package/src/lib.ts +645 -0
- package/src/log.ts +149 -0
- package/src/main.ts +199 -0
- package/src/ne2k.ts +1589 -0
- package/src/pci.ts +815 -0
- package/src/pit.ts +406 -0
- package/src/ps2.ts +820 -0
- package/src/rtc.ts +537 -0
- package/src/rust/analysis.rs +101 -0
- package/src/rust/codegen.rs +2660 -0
- package/src/rust/config.rs +3 -0
- package/src/rust/control_flow.rs +425 -0
- package/src/rust/cpu/apic.rs +658 -0
- package/src/rust/cpu/arith.rs +1207 -0
- package/src/rust/cpu/call_indirect.rs +2 -0
- package/src/rust/cpu/cpu.rs +4501 -0
- package/src/rust/cpu/fpu.rs +923 -0
- package/src/rust/cpu/global_pointers.rs +112 -0
- package/src/rust/cpu/instructions.rs +2486 -0
- package/src/rust/cpu/instructions_0f.rs +5261 -0
- package/src/rust/cpu/ioapic.rs +316 -0
- package/src/rust/cpu/memory.rs +351 -0
- package/src/rust/cpu/misc_instr.rs +613 -0
- package/src/rust/cpu/mod.rs +16 -0
- package/src/rust/cpu/modrm.rs +133 -0
- package/src/rust/cpu/pic.rs +402 -0
- package/src/rust/cpu/sse_instr.rs +361 -0
- package/src/rust/cpu/string.rs +701 -0
- package/src/rust/cpu/vga.rs +175 -0
- package/src/rust/cpu_context.rs +69 -0
- package/src/rust/dbg.rs +98 -0
- package/src/rust/gen/analyzer.rs +3807 -0
- package/src/rust/gen/analyzer0f.rs +3992 -0
- package/src/rust/gen/interpreter.rs +4447 -0
- package/src/rust/gen/interpreter0f.rs +5404 -0
- package/src/rust/gen/jit.rs +5080 -0
- package/src/rust/gen/jit0f.rs +5547 -0
- package/src/rust/gen/mod.rs +14 -0
- package/src/rust/jit.rs +2443 -0
- package/src/rust/jit_instructions.rs +7881 -0
- package/src/rust/js_api.rs +6 -0
- package/src/rust/leb.rs +46 -0
- package/src/rust/lib.rs +29 -0
- package/src/rust/modrm.rs +330 -0
- package/src/rust/opstats.rs +249 -0
- package/src/rust/page.rs +15 -0
- package/src/rust/paging.rs +25 -0
- package/src/rust/prefix.rs +15 -0
- package/src/rust/profiler.rs +155 -0
- package/src/rust/regs.rs +38 -0
- package/src/rust/softfloat.rs +286 -0
- package/src/rust/state_flags.rs +27 -0
- package/src/rust/wasmgen/mod.rs +2 -0
- package/src/rust/wasmgen/wasm_builder.rs +1047 -0
- package/src/rust/wasmgen/wasm_opcodes.rs +221 -0
- package/src/rust/zstd.rs +105 -0
- package/src/sb16.ts +1928 -0
- package/src/state.ts +359 -0
- package/src/uart.ts +472 -0
- package/src/vga.ts +2791 -0
- package/src/virtio.ts +1756 -0
- package/src/virtio_balloon.ts +273 -0
- package/src/virtio_console.ts +372 -0
- package/src/virtio_net.ts +326 -0
package/src/bus.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { dbg_assert } from './log.js'
|
|
2
|
+
|
|
3
|
+
interface BusListener {
|
|
4
|
+
fn: (...args: any[]) => any
|
|
5
|
+
this_value: unknown
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class BusConnector {
|
|
9
|
+
listeners: Record<string, BusListener[]> = {}
|
|
10
|
+
pair: BusConnector | undefined = undefined
|
|
11
|
+
|
|
12
|
+
register(
|
|
13
|
+
name: string,
|
|
14
|
+
fn: (...args: any[]) => any,
|
|
15
|
+
this_value: unknown,
|
|
16
|
+
): void {
|
|
17
|
+
let listeners = this.listeners[name]
|
|
18
|
+
|
|
19
|
+
if (listeners === undefined) {
|
|
20
|
+
listeners = this.listeners[name] = []
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
listeners.push({
|
|
24
|
+
fn: fn,
|
|
25
|
+
this_value: this_value,
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
unregister(name: string, fn: (...args: any[]) => any): void {
|
|
30
|
+
const listeners = this.listeners[name]
|
|
31
|
+
|
|
32
|
+
if (listeners === undefined) {
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this.listeners[name] = listeners.filter(function (l) {
|
|
37
|
+
return l.fn !== fn
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
send(name: string, value?: unknown, _unused_transfer?: unknown): void {
|
|
42
|
+
if (!this.pair) {
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const listeners = this.pair.listeners[name]
|
|
47
|
+
|
|
48
|
+
if (listeners === undefined) {
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (let i = 0; i < listeners.length; i++) {
|
|
53
|
+
const listener = listeners[i]
|
|
54
|
+
listener.fn.call(listener.this_value, value)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
send_async(name: string, value?: unknown): void {
|
|
59
|
+
dbg_assert(arguments.length === 1 || arguments.length === 2)
|
|
60
|
+
|
|
61
|
+
setTimeout(this.send.bind(this, name, value), 0)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function create_bus(): [BusConnector, BusConnector] {
|
|
66
|
+
const c0 = new BusConnector()
|
|
67
|
+
const c1 = new BusConnector()
|
|
68
|
+
|
|
69
|
+
c0.pair = c1
|
|
70
|
+
c1.pair = c0
|
|
71
|
+
|
|
72
|
+
return [c0, c1]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Backwards compatibility: Bus namespace
|
|
76
|
+
export const Bus = {
|
|
77
|
+
create: create_bus,
|
|
78
|
+
}
|
package/src/const.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
export const LOG_ALL = -1,
|
|
2
|
+
LOG_NONE = 0,
|
|
3
|
+
LOG_OTHER = 0x0000001,
|
|
4
|
+
LOG_CPU = 0x0000002,
|
|
5
|
+
LOG_FPU = 0x0000004,
|
|
6
|
+
LOG_MEM = 0x0000008,
|
|
7
|
+
LOG_DMA = 0x0000010,
|
|
8
|
+
LOG_IO = 0x0000020,
|
|
9
|
+
LOG_PS2 = 0x0000040,
|
|
10
|
+
LOG_PIC = 0x0000080,
|
|
11
|
+
LOG_VGA = 0x0000100,
|
|
12
|
+
LOG_PIT = 0x0000200,
|
|
13
|
+
LOG_MOUSE = 0x0000400,
|
|
14
|
+
LOG_PCI = 0x0000800,
|
|
15
|
+
LOG_BIOS = 0x0001000,
|
|
16
|
+
LOG_FLOPPY = 0x0002000,
|
|
17
|
+
LOG_SERIAL = 0x0004000,
|
|
18
|
+
LOG_DISK = 0x0008000,
|
|
19
|
+
LOG_RTC = 0x0010000,
|
|
20
|
+
// unused 0x0020000,
|
|
21
|
+
LOG_ACPI = 0x0040000,
|
|
22
|
+
LOG_APIC = 0x0080000,
|
|
23
|
+
LOG_NET = 0x0100000,
|
|
24
|
+
LOG_VIRTIO = 0x0200000,
|
|
25
|
+
LOG_9P = 0x0400000,
|
|
26
|
+
LOG_SB16 = 0x0800000,
|
|
27
|
+
LOG_FETCH = 0x1000000
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @type {Array<Array<string|number>>}
|
|
31
|
+
*/
|
|
32
|
+
export const LOG_NAMES: ReadonlyArray<readonly [number, string]> = [
|
|
33
|
+
[1, ''],
|
|
34
|
+
[LOG_CPU, 'CPU'],
|
|
35
|
+
[LOG_DISK, 'DISK'],
|
|
36
|
+
[LOG_FPU, 'FPU'],
|
|
37
|
+
[LOG_MEM, 'MEM'],
|
|
38
|
+
[LOG_DMA, 'DMA'],
|
|
39
|
+
[LOG_IO, 'IO'],
|
|
40
|
+
[LOG_PS2, 'PS2'],
|
|
41
|
+
[LOG_PIC, 'PIC'],
|
|
42
|
+
[LOG_VGA, 'VGA'],
|
|
43
|
+
[LOG_PIT, 'PIT'],
|
|
44
|
+
[LOG_MOUSE, 'MOUS'],
|
|
45
|
+
[LOG_PCI, 'PCI'],
|
|
46
|
+
[LOG_BIOS, 'BIOS'],
|
|
47
|
+
[LOG_FLOPPY, 'FLOP'],
|
|
48
|
+
[LOG_SERIAL, 'SERI'],
|
|
49
|
+
[LOG_RTC, 'RTC'],
|
|
50
|
+
[LOG_ACPI, 'ACPI'],
|
|
51
|
+
[LOG_APIC, 'APIC'],
|
|
52
|
+
[LOG_NET, 'NET'],
|
|
53
|
+
[LOG_VIRTIO, 'VIO'],
|
|
54
|
+
[LOG_9P, '9P'],
|
|
55
|
+
[LOG_SB16, 'SB16'],
|
|
56
|
+
[LOG_FETCH, 'FETC'],
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
export const // flags register bitflags
|
|
60
|
+
FLAG_CARRY = 1,
|
|
61
|
+
FLAG_PARITY = 4,
|
|
62
|
+
FLAG_ADJUST = 16,
|
|
63
|
+
FLAG_ZERO = 64,
|
|
64
|
+
FLAG_SIGN = 128,
|
|
65
|
+
FLAG_TRAP = 256,
|
|
66
|
+
FLAG_INTERRUPT = 512,
|
|
67
|
+
FLAG_DIRECTION = 1024,
|
|
68
|
+
FLAG_OVERFLOW = 2048,
|
|
69
|
+
FLAG_IOPL = (1 << 12) | (1 << 13),
|
|
70
|
+
FLAG_NT = 1 << 14,
|
|
71
|
+
FLAG_RF = 1 << 16,
|
|
72
|
+
FLAG_VM = 1 << 17,
|
|
73
|
+
FLAG_AC = 1 << 18,
|
|
74
|
+
FLAG_VIF = 1 << 19,
|
|
75
|
+
FLAG_VIP = 1 << 20,
|
|
76
|
+
FLAG_ID = 1 << 21,
|
|
77
|
+
// default values of reserved flags bits
|
|
78
|
+
FLAGS_DEFAULT = 1 << 1,
|
|
79
|
+
REG_EAX = 0,
|
|
80
|
+
REG_ECX = 1,
|
|
81
|
+
REG_EDX = 2,
|
|
82
|
+
REG_EBX = 3,
|
|
83
|
+
REG_ESP = 4,
|
|
84
|
+
REG_EBP = 5,
|
|
85
|
+
REG_ESI = 6,
|
|
86
|
+
REG_EDI = 7,
|
|
87
|
+
REG_ES = 0,
|
|
88
|
+
REG_CS = 1,
|
|
89
|
+
REG_SS = 2,
|
|
90
|
+
REG_DS = 3,
|
|
91
|
+
REG_FS = 4,
|
|
92
|
+
REG_GS = 5,
|
|
93
|
+
REG_LDTR = 7 // local descriptor table register
|
|
94
|
+
|
|
95
|
+
export const // The minimum number of bytes that can be memory-mapped by one device.
|
|
96
|
+
MMAP_BLOCK_BITS = 17,
|
|
97
|
+
MMAP_BLOCK_SIZE = 1 << MMAP_BLOCK_BITS,
|
|
98
|
+
MMAP_MAX = 0x100000000
|
|
99
|
+
|
|
100
|
+
export const CR0_PG = 1 << 31
|
|
101
|
+
export const CR4_PAE = 1 << 5
|
|
102
|
+
|
|
103
|
+
// https://github.com/qemu/seabios/blob/14221cd86eadba82255fdc55ed174d401c7a0a04/src/fw/paravirt.c#L205-L219
|
|
104
|
+
|
|
105
|
+
export const FW_CFG_SIGNATURE = 0x00
|
|
106
|
+
export const FW_CFG_ID = 0x01
|
|
107
|
+
export const FW_CFG_RAM_SIZE = 0x03
|
|
108
|
+
export const FW_CFG_NB_CPUS = 0x05
|
|
109
|
+
export const FW_CFG_MAX_CPUS = 0x0f
|
|
110
|
+
export const FW_CFG_NUMA = 0x0d
|
|
111
|
+
export const FW_CFG_FILE_DIR = 0x19
|
|
112
|
+
|
|
113
|
+
export const FW_CFG_CUSTOM_START = 0x8000
|
|
114
|
+
// This value is specific to v86, choosen to hopefully not collide with other indexes
|
|
115
|
+
export const FW_CFG_FILE_START = 0xc000
|
|
116
|
+
export const FW_CFG_SIGNATURE_QEMU = 0x554d4551
|
|
117
|
+
|
|
118
|
+
// See same constant in jit.rs
|
|
119
|
+
export const WASM_TABLE_SIZE = 900
|
|
120
|
+
|
|
121
|
+
export const WASM_TABLE_OFFSET = 1024
|
|
122
|
+
|
|
123
|
+
export const MIXER_CHANNEL_LEFT = 0
|
|
124
|
+
export const MIXER_CHANNEL_RIGHT = 1
|
|
125
|
+
export const MIXER_CHANNEL_BOTH = 2
|
|
126
|
+
export const MIXER_SRC_MASTER = 0
|
|
127
|
+
export const MIXER_SRC_PCSPEAKER = 1
|
|
128
|
+
export const MIXER_SRC_DAC = 2
|