Skip to content

Run Linux in your browser with an emulator written in Javascript

26 mayo, 2021

Fabrice Bellard has presented a program written in JavaScript that emulates a processor with x86 architecture, fast enough to run Linux in a web browser. Fabrice Bellard, in case you are not familiar with the name, is the founder of FFmpeg, the creator of the compiler Tiny C and the person in charge of the project QEMU.

JavaScript PC emulator does not work in all browsers, only in Google Chrome version 11 (in Beta 12 it does not work) and in Firefox 4. It is independent of the operating system, according to its creator, and runs without problems on Windows, GNU / Linux and Mac. I have done this article in Firefox 4 on Windows 7 Professional 64-bit. It starts up smoothly and is very fast.


JavaScript PC Emulator

JavaScript PC Emulator can simulate the operation of an Intel 486 chip from the 1990s, but it doesn’t have a floating point unit built into the numeric transformation, although fortunately, says Bellard, you can emulate that on Linux. The kernel version is 2.6.20.

I did it for fun, just because the new JavaScript engines are fast enough to do complicated things

The JavaScript PC emulator code is written in pure Javascript using the W3C Typed Arrays that are available in some modern browsers. The emulated hardware is as follows:

  • CPU compatible with 32-bit x86 architecture
  • 8259 Interrupt Controller
  • 8254 Interrupt Timer
  • UART 16450
  • Real time clock

CPU emulation

The CPU simulated is practically 486×86 compliant without the floating point unit (FPU). Lack of FPU It is not a problem when running Linux as the operating system as it contains an emulator of FPU.

Part of the code is inspired by my x86 dynamic translator present in QEMU, but there are important differences because here it is an interpreter

In order to be able to run Linux, a MMU (Memory Management Unit, memory management unit). The emulation is not complete, there are a number of restrictions.

In addition to the lack of FPU, no instructions available MMX, nor real mode, among other restrictions that are too technical for the scope of this article. However, if you are interested in knowing all the details, in the link that I leave at the end, you can consult these aspects.

Most of these restrictions are easy to remove, but I decided to apply the bare minimum to be able to use a recent Linux kernel and its front-end applications.


There is no synchronization between the frequency of PIT (Programmable Interval Timer) and the real time, so there is a bias between the time returned by Linux and the real time. To see this, try the “date” command and you will appreciate that difference.

The UART (serial port) does not support mode FIFO. Maybe it could help improve display speed. Network emulation is not available at this stage of development.

What it does have is a “clipboard” device to allow the exchange between the emulator and the outside world. You can see it in / dev / clipboard in the emulator. In the interface that appears in the screenshot, there is a button to clear the clipboard.

Javascript Terminal

Fabrice Bellard comments in the explanation about the technical details of the emulator, which has not used the Javascript library “termlib.js”, (it generates a terminal interface for Web services).

Even though I could have reused the excellent termlib (library), I decided to write my own because I was curious to see how it could be done.

Reading something like this, said with that simplicity, should not surprise us from the man who in 2009 set the record for calculating decimals of the number Pi (2.7 trillion digits), with a machine of similar power to the one I am using for this article.

After reading the phrase, another almost as devastating came to mind: “happy the times when men wrote their own controllers“, (Linus Torvalds). These gentlemen must have the DNA something different…

Kernel version

Bellard has used kernel version 2.6.20. The disk image is just an image RAM which is loaded at startup. The filesystem has been built with BuildRoot containing BusyBox (package that combines standard Unix utilities into a single executable).

The “distribution” integrates two tools written by Bellard: Tiny C and the Emacs clone, QEmacs, still unfinished, although functional.


Fabrice Bellard is currently very interested in the implementation of Javascript engines, to the point of considering writing one and has done this development as an exercise to learn to write optimized code for the latest Javascript engines, in particular Jaeger Monkey (Firefox 4) and V8 (Chrome).

JavaScript PC Emulator Utility

In general and for a user normal, JavaScript PC Emulator is still a curiosity that shows where the current limits of technology linked to the Web are.

For the student, the opportunity to dive into the code of one of the most relevant programmers in the environment Open Source and the capabilities of a language that not long ago some people gave up for dead: Javascript.

For Bellard, JavaScript PC Emulator is used to:

  • Evaluate and compare Javascript engines. How long does it take for the Javascript engine to boot Linux?
  • Learn to use Unix command line tools without leaving the browser.
  • Client-side processing using x86 libraries, for example, for cryptographic purposes.
  • Use A more advanced version that allows you to use old PC software TWO, like games.

Web | JavaScript PC Emulator
More information | Javascript PC Emulator – Technical Notes | Source code