Today I had a jaw dropping moment, when I saw Linux emulator in Javascript: http://bellard.org/jslinux/
It compiles C programs, it has vi and emacs, it supports all shell commands, etc etc.
How does it work?
jslinux is essentially a complete computer implemented in software, specifically JavaScript. This is of course known as an emulator. This particular version is setup to run Linux, but in theory it could run other operating systems instead.
In Linux operating system, we are having different types of emulator like a terminal emulator, gaming emulator, android emulator, etc. In Linux, the terminal emulator is providing the graphical frame to its end-user. In the same frame, the user will enter shell job, Linux commands, application-level job, etc.
Fabrice Bellard (French pronunciation: [fa. bʁis bɛ. laʁ]; born 1972) is a French computer programmer known for writing FFmpeg, QEMU, and the Tiny C Compiler.
At first, I also thought this is just a terminal emulator connecting you to a VM but it isn't. If you watch the network connections, you can see that, after bootup, no data is transmitted anymore.
So it's real.
A CPU is not something magic; in fact all it does is read bytes from memory and modify the RAM in accordance to what the commands mean.
In this case, the CPU emulator is based on the qemu code. What he does is he creates an array of functions where the index is the next byte at the PC (program counter).
Now all you need is a simple linux distribution that doesn't need any exotic CPU commands like floating point arithmetic or MMX code and voila.
What's interesting is the speed of the beast. The whole thing is a bit sluggish but then, it's JavaScript in a browser.
Conclusion: Impressive. Can't wait to see a C64 emulator :-)
See http://www.quora.com/CPU-Emulation/How-does-bellard-org-jslinux-work
Simplified Explanation
jslinux is essentially a complete computer implemented in software, specifically JavaScript. This is of course known as an emulator. This particular version is setup to run Linux, but in theory it could run other operating systems instead.
The emulator (JavaScript, ~90KB minified, ~7000 lines formatted) is loaded into the browser. A version of Linux was previously compiled into machine code for an x86 processor is loaded and copied into a big array of integers that acts as the emulated computer's RAM. The emulator CPU is then pointed to the first instruction of the machine code and told to start interpreting the instructions (such as reading/writing RAM, doing arithmetic and logic operations, jumping around to different instructions, etc). Sometimes it will write data (like the system log, or a shell command prompt) to the "terminal" via another piece of JavaScript code that simulates a serial port and a terminal using the browser DOM. Your key presses are also sent back to Linux via this simulated serial port...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With