Home Run Linux on… JavaScript?!

Run Linux on… JavaScript?!

Fabrice Bellard built an x86 PC emulator using JavaScript. He’s even gone so far as to install Linux kernel 2.6.20 on top of it. “The code is written in pure Javascript using Typed Arrays which are available in recent browsers,” Bellard wrote. It works in Firefox and Chrome 11, but not not Chrome 12.

As for the Linux instance, Bellard wrote: “The disk image is just a ram disk image loaded at boot time. It contains a filesystem generated with Buildroot containing BusyBox. I added my toy C compiler TinyCC and my unfinished but usable emacs clone QEmacs.” You can see Linux running JavaScript here.

Bellard did it just for fun, but he speculates that it could be useful for the following purposes:

  • Benchmarking of Javascript engines (how much time takes your Javascript engine to boot Linux ?). For this particular application, efficient handling of 32 bit signed and unsigned integers and of typed arrays is important.
  • Client side processing using an x86 library, for example for cryptographic purposes. For such application, the x86 emulator can be modified to provide an API to load x86 dynamic libraries and to provide a js-ctypes like API to call the C/C++ functions from javascript.
  • A more advanced version would allow to use old DOS PC software such as games.

Oddly enough, he found that Linux ran twice as fast on Jaeger Monkey as it did on V8. He’s not sure why.

About ReadWrite’s Editorial Process

The ReadWrite Editorial policy involves closely monitoring the gambling and blockchain industries for major developments, new product and brand launches, game releases and other newsworthy events. Editors assign relevant stories to in-house staff writers with expertise in each particular topic area. Before publication, articles go through a rigorous round of editing for accuracy, clarity, and to ensure adherence to ReadWrite's style guidelines.