V86: x86 virtualization in the browser, recompiling x86 to WASM on the fly
github.com
github.com
Compilation in tcc with a file of ~300 lines of code, linking to a library, takes roughly 50 ms. Compiling the entire libharu library takes 23 s. It's ~120.000 SLOC but where most is long arrays of encoding data.
I have used musl as toolchain, but will look into uclibc because of a weird problem: printf without \n in the end doesn't display the text before something creates a newline. And that could be readline, in which case you'd get:
Pizza
What's your favourite food?
At least I think this is because of musl where there's a problem with the syscall writev: https://www.openwall.com/lists/musl/2013/05/05/9.Really looking forward to get the tutorial out and I hope it'll be with the strace based console!
For my emulator jor1k [1] I tried something similar years ago [2]. However I haven't continued on this topic because of priority shifts. But the potential speed advantages are astonishing. My proof of context reached more than 1 billion emulated machine instructions per second.
[1] https://github.com/s-macke/jor1k
[2] https://github.com/s-macke/jor1k/wiki/Breaking-the-1-billion...
Fundamentally it's "just" a JIT that compiles to WASM. It's a ton of effort to build something like that, but I think fundamentally it's not an impossible undertaking.
The JIT seems to be living there, so you can probably explore from there: https://github.com/copy/v86/blob/master/src/rust/jit.rs
WRT speed advantage: compared to what?
One plausible guess I have is that they might be running out of memory since the browser runtimes are expecting the WASM code to be long lived whilst a emulator JIT by nature should be able to adapt to rapidly changing code and blows out of memory before things are cleaned up.
The Chromium team is pretty receptive to patches though, so for a big project like this it doesn't seem unreasonable to just patch the browser to perform well enough for your use case, and then upstream the patch so everyone has it within a few months when you're ready to launch your product.
I will definitely look at your code :-)
> WRT speed advantage: compared to what?
The speed advantage between interpreted and JIT compiled execution.
It's literally the source. It looks like gen/generate_jit.js is what you want.
Which are the calculations about the billion instructions per second? Emulating instructions, even on a relatively simple system, requires a lot of support: decoding, cpu state, memory access/mapping, buses - and this doesn't even include the instructions themselves.
For the proof of concept, that was the compiled code in [1]. Just look for code snipplets such as "cycles = cyles - xxxx|0", that does the calculation during runtime.
So, my calculation does not include decoding, but CPU state, memory access/mapping, buses.
[1] https://gist.github.com/s-macke/0d79d2ba78a022269cb7859a4417...
It's interesting to see that the window sizes are automatic. There are no real windows. Also, it's kind of fun to see that there's no "Maximize", but "Zoom", just like macOS.. And double-clicking the titlebar actually minimizes the application to an icon, just like macOS.
The write.exe program is pretty cool
At that time, it was nowhere close to being called an OS. It was a collection of GUI-ish tools for DOS. This started to change with Windows 3. That one still required DOS to function, but by that time it was clear DOS was the past on the PC and Windows (in some form) was the way forward.
My last version was MS-DOS 6.22, but I can't remember that. Personally I used volkov commander.
Edit: I see it was discontinued in 6.22, I wonder why.
I guess it was discontinued probably because by that time MS was focusing on Windows as the operating system "shell".
With Norton commander you could only spawn one process from NC. NC itself had quite a lot for built in tools (viewer, editor, comparison, 2 file panes).
So I’d call windows 1.0 more an OS in terms of process “management”, UI, etc. No hardware layer of course.
I am happy to answer questions.
SCNR