@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.
Files changed (111) hide show
  1. package/LICENSE +22 -0
  2. package/LICENSE.MIT +22 -0
  3. package/Readme.md +237 -0
  4. package/dist/v86.browser.js +26666 -0
  5. package/dist/v86.browser.js.map +7 -0
  6. package/dist/v86.js +26632 -0
  7. package/dist/v86.js.map +7 -0
  8. package/gen/generate_analyzer.ts +512 -0
  9. package/gen/generate_interpreter.ts +522 -0
  10. package/gen/generate_jit.ts +624 -0
  11. package/gen/rust_ast.ts +107 -0
  12. package/gen/util.ts +35 -0
  13. package/gen/x86_table.ts +1836 -0
  14. package/lib/9p.ts +1547 -0
  15. package/lib/filesystem.ts +1879 -0
  16. package/lib/marshall.ts +168 -0
  17. package/lib/softfloat/softfloat.c +32501 -0
  18. package/lib/zstd/zstddeclib.c +13520 -0
  19. package/package.json +75 -0
  20. package/src/acpi.ts +267 -0
  21. package/src/browser/dummy_screen.ts +106 -0
  22. package/src/browser/fake_network.ts +1771 -0
  23. package/src/browser/fetch_network.ts +361 -0
  24. package/src/browser/filestorage.ts +124 -0
  25. package/src/browser/inbrowser_network.ts +57 -0
  26. package/src/browser/keyboard.ts +564 -0
  27. package/src/browser/main.ts +3415 -0
  28. package/src/browser/mouse.ts +255 -0
  29. package/src/browser/network.ts +142 -0
  30. package/src/browser/print_stats.ts +336 -0
  31. package/src/browser/screen.ts +978 -0
  32. package/src/browser/serial.ts +316 -0
  33. package/src/browser/speaker.ts +1223 -0
  34. package/src/browser/starter.ts +1688 -0
  35. package/src/browser/wisp_network.ts +332 -0
  36. package/src/browser/worker_bus.ts +64 -0
  37. package/src/buffer.ts +652 -0
  38. package/src/bus.ts +78 -0
  39. package/src/const.ts +128 -0
  40. package/src/cpu.ts +2891 -0
  41. package/src/dma.ts +474 -0
  42. package/src/elf.ts +251 -0
  43. package/src/floppy.ts +1778 -0
  44. package/src/ide.ts +3455 -0
  45. package/src/io.ts +504 -0
  46. package/src/iso9660.ts +317 -0
  47. package/src/kernel.ts +250 -0
  48. package/src/lib.ts +645 -0
  49. package/src/log.ts +149 -0
  50. package/src/main.ts +199 -0
  51. package/src/ne2k.ts +1589 -0
  52. package/src/pci.ts +815 -0
  53. package/src/pit.ts +406 -0
  54. package/src/ps2.ts +820 -0
  55. package/src/rtc.ts +537 -0
  56. package/src/rust/analysis.rs +101 -0
  57. package/src/rust/codegen.rs +2660 -0
  58. package/src/rust/config.rs +3 -0
  59. package/src/rust/control_flow.rs +425 -0
  60. package/src/rust/cpu/apic.rs +658 -0
  61. package/src/rust/cpu/arith.rs +1207 -0
  62. package/src/rust/cpu/call_indirect.rs +2 -0
  63. package/src/rust/cpu/cpu.rs +4501 -0
  64. package/src/rust/cpu/fpu.rs +923 -0
  65. package/src/rust/cpu/global_pointers.rs +112 -0
  66. package/src/rust/cpu/instructions.rs +2486 -0
  67. package/src/rust/cpu/instructions_0f.rs +5261 -0
  68. package/src/rust/cpu/ioapic.rs +316 -0
  69. package/src/rust/cpu/memory.rs +351 -0
  70. package/src/rust/cpu/misc_instr.rs +613 -0
  71. package/src/rust/cpu/mod.rs +16 -0
  72. package/src/rust/cpu/modrm.rs +133 -0
  73. package/src/rust/cpu/pic.rs +402 -0
  74. package/src/rust/cpu/sse_instr.rs +361 -0
  75. package/src/rust/cpu/string.rs +701 -0
  76. package/src/rust/cpu/vga.rs +175 -0
  77. package/src/rust/cpu_context.rs +69 -0
  78. package/src/rust/dbg.rs +98 -0
  79. package/src/rust/gen/analyzer.rs +3807 -0
  80. package/src/rust/gen/analyzer0f.rs +3992 -0
  81. package/src/rust/gen/interpreter.rs +4447 -0
  82. package/src/rust/gen/interpreter0f.rs +5404 -0
  83. package/src/rust/gen/jit.rs +5080 -0
  84. package/src/rust/gen/jit0f.rs +5547 -0
  85. package/src/rust/gen/mod.rs +14 -0
  86. package/src/rust/jit.rs +2443 -0
  87. package/src/rust/jit_instructions.rs +7881 -0
  88. package/src/rust/js_api.rs +6 -0
  89. package/src/rust/leb.rs +46 -0
  90. package/src/rust/lib.rs +29 -0
  91. package/src/rust/modrm.rs +330 -0
  92. package/src/rust/opstats.rs +249 -0
  93. package/src/rust/page.rs +15 -0
  94. package/src/rust/paging.rs +25 -0
  95. package/src/rust/prefix.rs +15 -0
  96. package/src/rust/profiler.rs +155 -0
  97. package/src/rust/regs.rs +38 -0
  98. package/src/rust/softfloat.rs +286 -0
  99. package/src/rust/state_flags.rs +27 -0
  100. package/src/rust/wasmgen/mod.rs +2 -0
  101. package/src/rust/wasmgen/wasm_builder.rs +1047 -0
  102. package/src/rust/wasmgen/wasm_opcodes.rs +221 -0
  103. package/src/rust/zstd.rs +105 -0
  104. package/src/sb16.ts +1928 -0
  105. package/src/state.ts +359 -0
  106. package/src/uart.ts +472 -0
  107. package/src/vga.ts +2791 -0
  108. package/src/virtio.ts +1756 -0
  109. package/src/virtio_balloon.ts +273 -0
  110. package/src/virtio_console.ts +372 -0
  111. package/src/virtio_net.ts +326 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012, The v86 contributors
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/LICENSE.MIT ADDED
@@ -0,0 +1,22 @@
1
+ QEMU Floppy disk emulator (Intel 82078)
2
+
3
+ Copyright (c) 2003, 2007 Jocelyn Mayer
4
+ Copyright (c) 2008 Hervé Poussineau
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
package/Readme.md ADDED
@@ -0,0 +1,237 @@
1
+ This is a fork of [copy/v86][upstream]. This fork migrates the JavaScript
2
+ frontend to TypeScript, replaces Closure Compiler with esbuild + tsgo, and
3
+ publishes as [`@aptre/v86`](https://www.npmjs.com/package/@aptre/v86) on npm
4
+ with ESM and TypeScript declarations. The Rust/WASM backend is unchanged.
5
+
6
+ [upstream]: https://github.com/copy/v86
7
+
8
+ ---
9
+
10
+ [![Join the chat at https://gitter.im/copy/v86](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/copy/v86) or #v86 on [irc.libera.chat](https://libera.chat/)
11
+
12
+ v86 emulates an x86-compatible CPU and hardware. Machine code is translated to
13
+ WebAssembly modules at runtime in order to achieve decent performance. Here's a
14
+ list of emulated hardware:
15
+
16
+ - An x86-compatible CPU. The instruction set is around Pentium 4 level,
17
+ including full SSE3 support. Some features are missing, in particular:
18
+ - Task gates, far calls in protected mode
19
+ - Some 16 bit protected mode features
20
+ - Single stepping (trap flag, debug registers)
21
+ - Some exceptions, especially floating point and SSE
22
+ - Multicore
23
+ - 64-bit extensions
24
+ - A floating point unit (FPU). Calculations are done using the Berkeley
25
+ SoftFloat library and therefore should be precise (but slow). Trigonometric
26
+ and log functions are emulated using 64-bit floats and may be less precise.
27
+ Not all FPU exceptions are supported.
28
+ - A floppy disk controller (8272A).
29
+ - An 8042 Keyboard Controller, PS2. With mouse support.
30
+ - An 8254 Programmable Interval Timer (PIT).
31
+ - An 8259 Programmable Interrupt Controller (PIC).
32
+ - Partial APIC support.
33
+ - A CMOS Real Time Clock (RTC).
34
+ - A generic VGA card with SVGA support and Bochs VBE Extensions.
35
+ - A PCI bus. This one is partly incomplete and not used by every device.
36
+ - An IDE disk controller.
37
+ - A built-in ISO 9660 CD-ROM generator.
38
+ - An NE2000 (RTL8390) PCI network card.
39
+ - Various virtio devices: Filesystem, network and balloon.
40
+ - A SoundBlaster 16 sound card.
41
+
42
+ ## Demos
43
+
44
+ [9front](https://copy.sh/v86/?profile=9front) —
45
+ [Arch Linux](https://copy.sh/v86/?profile=archlinux) —
46
+ [Android-x86 1.6-r2](https://copy.sh/v86?profile=android) —
47
+ [Android-x86 4.4-r2](https://copy.sh/v86?profile=android4) —
48
+ [BasicLinux](https://copy.sh/v86/?profile=basiclinux) —
49
+ [Buildroot Linux](https://copy.sh/v86/?profile=buildroot) —
50
+ [Damn Small Linux](https://copy.sh/v86/?profile=dsl) —
51
+ [ELKS](https://copy.sh/v86/?profile=elks) —
52
+ [FreeDOS](https://copy.sh/v86/?profile=freedos) —
53
+ [FreeBSD](https://copy.sh/v86/?profile=freebsd) —
54
+ [FiwixOS](https://copy.sh/v86/?profile=fiwix) —
55
+ [Haiku](https://copy.sh/v86/?profile=haiku) —
56
+ [SkiffOS](https://copy.sh/v86/?profile=copy/skiffos) —
57
+ [ReactOS](https://copy.sh/v86/?profile=reactos) —
58
+ [Windows 2000](https://copy.sh/v86/?profile=windows2000) —
59
+ [Windows 98](https://copy.sh/v86/?profile=windows98) —
60
+ [Windows 95](https://copy.sh/v86/?profile=windows95) —
61
+ [Windows 1.01](https://copy.sh/v86/?profile=windows1) —
62
+ [MS-DOS 6.22](https://copy.sh/v86/?profile=msdos) —
63
+ [OpenBSD](https://copy.sh/v86/?profile=openbsd) —
64
+ [Oberon](https://copy.sh/v86/?profile=oberon) —
65
+ [KolibriOS](https://copy.sh/v86/?profile=kolibrios) —
66
+ [SkiftOS](https://copy.sh/v86?profile=skift) —
67
+ [QNX](https://copy.sh/v86/?profile=qnx)
68
+
69
+ ## Documentation
70
+
71
+ [How it works](docs/how-it-works.md) —
72
+ [Networking](docs/networking.md) —
73
+ [Alpine Linux guest setup](tools/docker/alpine/) —
74
+ [Arch Linux guest setup](docs/archlinux.md) —
75
+ [Windows NT guest setup](docs/windows-nt.md) —
76
+ [Windows 9x guest setup](docs/windows-9x.md) —
77
+ [9p filesystem](docs/filesystem.md) —
78
+ [Linux rootfs on 9p](docs/linux-9p-image.md) —
79
+ [Profiling](docs/profiling.md) —
80
+ [CPU Idling](docs/cpu-idling.md)
81
+
82
+ ## Compatibility
83
+
84
+ Here's an overview of the operating systems supported in v86:
85
+
86
+ - Linux works pretty well. 64-bit kernels are not supported.
87
+ - [Buildroot](https://buildroot.org/) can be used to build a minimal image.
88
+ [humphd/browser-vm](https://github.com/humphd/browser-vm) and
89
+ [darin755/browser-buildroot](https://github.com/Darin755/browser-buildroot) have some useful scripts for building one.
90
+ - [SkiffOS](https://github.com/skiffos/SkiffOS/tree/master/configs/browser/v86) (based on Buildroot) can cross-compile a custom image.
91
+ - Ubuntu and other Debian derivatives works up to the latest version that supported i386 (16.04 LTS or 18.04 LTS for some variants).
92
+ - Alpine Linux works. An image can be built from a Dockerfile, see [tools/docker/alpine/](tools/docker/alpine/).
93
+ - Arch Linux 32 works. See [archlinux.md](docs/archlinux.md) for building an image.
94
+ - ReactOS works.
95
+ - FreeDOS, Windows 1.01 and MS-DOS run very well.
96
+ - KolibriOS works.
97
+ - Haiku works.
98
+ - Android-x86 has been tested up to 4.4-r2.
99
+ - Windows 1, 3.x, 95, 98, ME, NT and 2000 work reasonably well.
100
+ - In Windows 2000 and higher the PC type has to be changed from ACPI PC to Standard PC
101
+ - There are some known boot issues ([#250](https://github.com/copy/v86/issues/250), [#433](https://github.com/copy/v86/issues/433), [#507](https://github.com/copy/v86/issues/507), [#555](https://github.com/copy/v86/issues/555), [#620](https://github.com/copy/v86/issues/620), [#645](https://github.com/copy/v86/issues/645))
102
+ - See [Windows 9x guest setup](docs/windows-9x.md)
103
+ - Windows XP, Vista and 8 work under certain conditions (see [#86](https://github.com/copy/v86/issues/86), [#208](https://github.com/copy/v86/issues/208))
104
+ - See [Windows NT guest setup](docs/windows-nt.md)
105
+ - Many hobby operating systems work.
106
+ - 9front works.
107
+ - Plan 9 doesn't work.
108
+ - QNX works.
109
+ - OS/2 doesn't work.
110
+ - FreeBSD works.
111
+ - OpenBSD works with a specific boot configuration. At the `boot>` prompt type
112
+ `boot -c`, then at the `UKC>` prompt `disable mpbios` and `exit`.
113
+ - NetBSD works only with a custom kernel, see [#350](https://github.com/copy/v86/issues/350).
114
+ - SerenityOS works (only 32-bit versions).
115
+ - [SkiftOS](https://skiftos.org/) works.
116
+
117
+ You can get some information on the disk images here: https://github.com/copy/images.
118
+
119
+ ## How to build, run and embed?
120
+
121
+ You need:
122
+
123
+ - [bun](https://bun.sh/) (runtime and package manager)
124
+ - Rust with the wasm32-unknown-unknown target (for the WASM backend)
125
+ - A version of clang compatible with Rust
126
+ - To run tests: nasm, gdb, qemu-system, gcc, libc-i386 and rustfmt
127
+
128
+ ```bash
129
+ bun install # install dependencies
130
+ bun run build # production build (ESM + browser bundle in dist/)
131
+ bun run build:debug # debug build (with DEBUG=true)
132
+ bun run typecheck # type-check with tsgo
133
+ bun run lint # lint with eslint
134
+ bun run format # format with prettier
135
+ bun run test # run tests with vitest
136
+ ```
137
+
138
+ See [tools/docker/test-image/Dockerfile](tools/docker/test-image/Dockerfile)
139
+ for a full setup on Debian or
140
+ [WSL](https://docs.microsoft.com/en-us/windows/wsl/install).
141
+
142
+ The WASM backend is still built with `make` (Rust toolchain required).
143
+ Run `make` for the debug build (`debug.html`) or `make all` for the optimized
144
+ build (`index.html`). The TypeScript/JavaScript frontend is built with the bun
145
+ commands above.
146
+
147
+ ROM and disk images are loaded via XHR, so if you want to try out the HTML
148
+ files locally, make sure to serve them from a local webserver. You can use
149
+ `make run` to serve the files using Python's http module.
150
+
151
+ If you only want to embed v86 in a webpage, check out the
152
+ [examples](examples/). For bundler-based setups, install from npm:
153
+ `bun add @aptre/v86`
154
+
155
+ ### Alternatively, to build using Docker
156
+
157
+ - If you have Docker installed, you can run the whole system inside a container.
158
+ - See `tools/docker/exec` to find the Dockerfile required for this.
159
+ - You can run `docker build -f tools/docker/exec/Dockerfile -t v86:alpine-3.19 .` from the root directory to generate docker image.
160
+ - Then you can simply run `docker run -it -p 8000:8000 v86:alpine-3.19` to start the server.
161
+ - Check `localhost:8000` for hosted server.
162
+
163
+ ### Running via Dev Container
164
+
165
+ - If you are using an IDE that supports Dev Containers, such as GitHub Codespaces, the Visual Studio Code Remote Container extension, or possibly others such as Jetbrains' IntelliJ IDEA, you can setup the development environment in a Dev Container.
166
+ - Follow the instructions from your development environment to setup the container.
167
+ - Run the Task "Fetch images" in order to download images for testing.
168
+
169
+ ## Testing
170
+
171
+ The disk images for testing are not included in this repository. You can
172
+ download them directly from the website using:
173
+
174
+ `curl --compressed --output-dir images/ --remote-name-all https://i.copy.sh/{linux.iso,linux3.iso,linux4.iso,buildroot-bzimage68.bin,TinyCore-11.0.iso,oberon.img,msdos.img,openbsd-floppy.img,kolibri.img,windows101.img,os8.img,freedos722.img,mobius-fd-release5.img,msdos622.img}`
175
+
176
+ Run integration tests: `make tests`
177
+
178
+ Run all tests: `make jshint rustfmt kvm-unit-test nasmtests nasmtests-force-jit expect-tests jitpagingtests qemutests rust-test tests`
179
+
180
+ See [tests/Readme.md](tests/Readme.md) for more information.
181
+
182
+ ## API examples
183
+
184
+ - [Basic](examples/basic.html)
185
+ - [Programatically using the serial terminal](examples/serial.html)
186
+ - [A Lua interpreter](examples/lua.html)
187
+ - [Two instances in one window](examples/two_instances.html)
188
+ - [Networking between browser windows/tabs using the Broadcast Channel API](examples/broadcast-network.html)
189
+ - [TCP Terminal (fetch-based networking)](examples/tcp_terminal.html)
190
+ - [Saving and restoring emulator state](examples/save_restore.html)
191
+
192
+ Using v86 for your own purposes is as easy as:
193
+
194
+ ```javascript
195
+ var emulator = new V86({
196
+ screen_container: document.getElementById("screen_container"),
197
+ bios: {
198
+ url: "../../bios/seabios.bin",
199
+ },
200
+ vga_bios: {
201
+ url: "../../bios/vgabios.bin",
202
+ },
203
+ cdrom: {
204
+ url: "../../images/linux.iso",
205
+ },
206
+ autostart: true,
207
+ });
208
+ ```
209
+
210
+ See [starter.js](src/browser/starter.js) for the full API.
211
+
212
+ ## License
213
+
214
+ v86 is distributed under the terms of the Simplified BSD License, see
215
+ [LICENSE](LICENSE). The following third-party dependencies are included in the
216
+ repository under their own licenses:
217
+
218
+ - [`lib/softfloat/softfloat.c`](lib/softfloat/softfloat.c)
219
+ - [`lib/zstd/zstddeclib.c`](lib/zstd/zstddeclib.c)
220
+ - [`tests/kvm-unit-tests/`](tests/kvm-unit-tests)
221
+ - [`tests/qemutests/`](tests/qemutests)
222
+ - [`src/floppy.js/`](src/floppy.js) contains parts ported from qemu under the MIT license, see LICENSE.MIT.
223
+
224
+ ## Credits
225
+
226
+ - CPU test cases via [QEMU](https://wiki.qemu.org/Main_Page)
227
+ - More tests via [kvm-unit-tests](https://www.linux-kvm.org/page/KVM-unit-tests)
228
+ - [zstd](https://github.com/facebook/zstd) support is included for better compression of state images
229
+ - [Berkeley SoftFloat](http://www.jhauser.us/arithmetic/SoftFloat.html) is included to precisely emulate 80-bit floating point numbers
230
+ - [The jor1k project](https://github.com/s-macke/jor1k) for 9p, filesystem and uart drivers
231
+ - [WinWorld](https://winworldpc.com/) sources of some old operating systems
232
+ - [OS/2 Museum](https://www.os2museum.com/) sources of some old operating systems
233
+ - [ArchiveOS](https://archiveos.org/) sources of several operating systems
234
+
235
+ ## More questions?
236
+
237
+ Shoot me an email to `copy@copy.sh`. Please report bugs on GitHub.