Javascript PC emulator runs Linux

Fabrice Bellard, creator of the multiple architecture emulator QEMU and FFmpeg, amongst other open source projects, has unleashed his Javascript powered PC emulator. In its current state, it boots a stripped down, text mode Linux implementation and runs within a modern browser. Interesting curio or a potentially useful tool?

To say it's written in Javascript, an interpreted language that is usually used for client-side scripting on web pages, the emulator runs remarkably quickly. It boots to a command prompt in about a minute on this machine (Sempron 3000, FF 4.1). [Update: Considerably faster than that on my CoreDuo] By the way, the emulator requires a modern browser such as Firefox 4 or Chrome in order to operate.

Things are still at the proof of concept stage but there is already enough to play around with. Sitting on a command line prompt, the first thing I tried was typing ls. Doing this revealed the presence of a single file, a C source code file called hello.c. Attempting to compile with GCC wont work because GCC isn't installed. Examining the content of the file got the the bottom of things:

~ # cat hello.c
/* This C source can be compiled with:
tcc -o hello hello.c
*/
#include <tcclib.h>
int main(int argc, char **argv)
{
printf("Hello World\n");
return 0;
}
~ #

That the system includes the Tiny C Compiler (not to be confused with Small-C) makes sense as that is another project that was started by Bellard. You can get an idea of what other utilities are supported by the system by typing

ls /bin

So, what could this thing actually be used for, I hear you ask? As it stands, not all that much. For one thing, networking is not yet emulated. To perform any type of file transfer between the host and guest environments, one has to use the system cut and paste buffer and a virtual /dev/clipboard device. Other than that, there's no way to get data into or out of the system. This could be a point in the system's favor because, as it really is running locally, rather than on a server, it's fairly good in privacy terms. You can wipe the entire system by simply hitting refresh.

It could perhaps be used to provide some sort of training environment to teach people how to use the Linux command line. As it stands, the system could be used to compile simple snippets of C code if you were to find yourself stuck on a machine without a compiler installed.

[Update: Seems that a pal of mine, Chris Williams, is using it to demo his hobbyist microkernel project Diosix]

The implementation of a complete machine emulator is not the type of task that Javascript was created for. If you really needed a Linux command line that can be accessed without installing anything to the host machine, you'd be better off either SSHing into a remote box or running a virtual machine locally. If it must be browser based, a Java based PC emulator would be quite slow but it would still run faster than one written in Javascript. The JPC website even hosts some example Linux demos that you can try out, but of course, they require that you have Java installed.

Bellard's Javascript PC Emulator is an intriguing feat of programming, but it's likely that it wont see much practical use. It's still cool though.

The Javascript PC Emulator website.

Load Disqus comments