Browser-based Linux

Source: Internet
Author: User
Document directory
  • Javascript PC emulator-news
  • Javascript PC emulator-news
  • Javascript PC emulator-FAQ
  • Javascript PC emulator-technical notes

Fabrice bellard, founder of qemu simulator ProjectA simulator is developed for running in Javascript, allowing users to start Linux on a browser (Firefox 4 and Google Chrome 11 are supported.Now another developer has modified the JS/Linux version of Fabrice bellard, allowing the simulator to start a newer kernel version of Linux kernel 3.0.4.Support permanent storage.

Figure 1 latest version (kernel version 3.0.4)

The developer creates a virtual block device that can store data locally in HTML5. The block device can be partitioned and formatted.Part of the source code (http://stud.hro.nl/0814604/jslinuxdemo/ repository address, Runtime is click emulator.html (http://stud.hro.nl/0814604/jslinuxdemo/emulator.html), login name is root.

Figure 2 latest version (local storage is supported, and file system images can be saved locally or uploaded)

The address of another version is the http://bellard.org/jslinux.

Figure 2 another version (information can be transmitted through the clipboard device in Linux between users and virtual machines)

This is a virtual machine that uses JavaScript to simulate the x86 instruction set using qemu and runs on a browser (my Firefox runs normally. This machine runs a Linux kernel of 2.6.20, the related information of this virtual machine can be seen on the tech page published by the author. You can also log on to the VM and check it.

It is found that the file system is made of busybox. Most Linux commands can be used, and the commands for Automatic completion can be used with tabs.

Figure 3 all supported commands

How to implement:

  1. The author Fabrice bellard compiled a simple PC simulator using JavaScript, including 32-bit x86 compatible CPU, 8259 programmable interrupt controller, 8254 Programmable Interrupt Timer
  2. Implement 16450 UART serial port device
  3. Implement a terminal using JavaScript
  4. Compile a Linux kernel image that contains FPU simulation.
  5. Use buildroot to create a file system and load Ram at startup.
  6. Add basic toolkit busybox, Mini C compiler tinycc, and mini editor qemacs

Jslinux simple analysis

Jslinux: Write a PC simulator in JavaScript and run Linux (the code is written in pure JavaScript using typed arrays which are available in recent browsers .)
1, the home page (http://bellard.org/jslinux/) is very simple, mainly called the following two JS files.

Http://bellard.org/jslinux/term.js

Http://bellard.org/jslinux/cpux86.js

2. Nothing special was found in term. js;
3. cpux86.js uses a load_binary function. After checking the implementation, the following three bin files are obtained through XMLHttpRequest (using typed arrays to operate binary files ):

Http://bellard.org/jslinux/vmlinux26.bin

Http://bellard.org/jslinux/root.bin

Http://bellard.org/jslinux/linuxstart.bin

According to the author's description, the original intention of this simulator is to understand the current work of the JavaScript engine, especially the Jaeger monkey of Firefox 4 and the V8 of chrome. The results of this exploration can be used:

  • The Linux Startup time reflects the Javascript performance of the browser. (The author said that Firefox 4 is twice faster than chrome 11, and chrome 12 has bugs that cannot be run ).
  • Experiment the possibility of loading the x86 Runtime Library when using JavaScript for client operations.
  • Further development to support the operation of DOS games.

Figure 4 tiny C compiler tinycc

The home directory contains a hello. c file, which is the result after compilation and running. With the C compiler and text compilers such as qemacs and VI, we can compile C Programs on this platform.

Figure 5 CPU Information

Figure 6 memory information

The following describes virtual block devices and local storage:

This project allows the virtual machine to access a persistent block device. This means
A user can format and partition this device inside it's Virtual Machine. Because this disk
Is then stored in the HTML5 local storage (stored in the HTML5 local storage), a return to the emulator's web page allows
User to reopen the block device. All data stored on the disk can therefore be read again.

Schematically, the process works in the following way:
A block device driver is added to the Linux kernel. This allows a user to operate
A 'device' written in Javascript. This device is bound to the virtual machine using
Same I/O ports as a floppy disk. the device driver itself uses a temporary testing major
Device node, Id 250. Theoretically, it allows dynamic device node allocation, but I have
Not tested this.
On the Javascript side, a lot of caching occurs because the local storage interface is
Quite slow. I therefore decided to cache the total 'disk' in memory, because it's about
1 m anyway. writes are cached as well, and are 'flushed' once the driver has transferred
A complete sector.
For more details, see the source code.

========================================================== ==========================================

Javascript PC emulator-news
  • Aug 20,201 1:
  • May 26,201 1:
  • May 20,201 1:
  • May 18,201 1:
  • May 17,201 1:
  • May 16,201 1:

Javascript PC emulator-FAQ

Which browser shocould I use to try the PC emulator?

What is the expected boot time of Linux with the emulator?

How can I scroll back in the terminal?

How Can I copy data to the virtual machine?

How Can I copy data from the virtual machine?

When will there be network support?

Is it possible to emulate a VGA Card and all the missing devices to launch say freedos or windows?

Is there some source code available?

Is my privacy respected?

Technical connotation of JavaScript PC emulator-technical notes

This PC emulator is written in Javascript. The emulated hardware consists in the following devices:

CPU emulation

Devices

Javascript Terminal

Linux distribution

Javascript

What's the use?

========================================================== ==========================================

Javascript PC emulator-news
  • Aug 20,201 1:
    • Faster emulation
    • Added 16 bit & segmentation support
    • Added scroll back in Terminal
  • May 26,201 1:
    • Display boot time
    • Faster emulation
    • Added some missing instructions (BCD support, xlat, bound)
    • Easier customization possible (seeJslinux. jsFile ).
  • May 20,201 1:
    • Added support for more browsers including opera 11.11 and Internet Explorer 9
    • Reduced VM Ram size from 32 MB to 16 MB
    • Source code release of the Linux starter utility.
  • May 18,201 1:
    • Added a clipboard to exchange data between the VM and the host
    • Added FAQ and news pages
    • Fixed monospace font for Some browsers.
  • May 17,201 1:
    • Fixed binary xhr for Firefox nightly builds
    • Fixed terminal height forLessCommand
    • Fixed ampersand output in the terminal.
  • May 16,201 1:
    • Initial realnames.
Javascript PC emulator-faqwhich browser shocould I use to try the PC emulator?

The following browsers are officially supported:

  • Firefox> = 4
  • Chrome 11
  • Opera 11.11
  • Internet Explorer 9

For optimal performance, your browser shocould support the W3C typed arrays. Firefox 4.x and chrome 11 have such support.

The current version of chrome 12 beta is reported to have a bug preventing to run the emulator.

What is the expected boot time of Linux with the emulator?

Here are some figures:

Browser
Host
Boot time (s)

Firefox 5.0.1
Core2 quad 2.3 GHz
4.0

Firefox 6 beta
Samsung Galaxy S2
32.5

How can I scroll back in the terminal?

Use ctrl-up, Ctrl-down, Ctrl-Pageup and Ctrl-Pagedown.
How Can I copy data to the virtual machine?

  1. Copy your file content to the OS clipboard using your favorite text editor.
  2. Paste the data to the JS/Linux clipboard using the mouse (it is the text area on the right of the VM terminal ).
  3. In the VM Linux Shell do:
    cat < /dev/clipboard > /tmp/myfile

    Your text file is now copied/Tmp/myfile.

To copy binary data, you canUUEncodeIt on the PC using (assuming you use Linux ):

uuencode myfile myfile > myfile.txt

Then you copyMyfile.txtTo the Linux Vm and uudecode it by doing:

uudecode < /dev/clipboard
How Can I copy data from the virtual machine?

The procedure is the reverse of the previous one:

  1. Copy your file to the clipboard:

    cat myfile > /dev/clipboard
  2. Select all the Clipboard data and copy it to the Host OS clipboard using the mouse over the text area on the right of the VM terminal.
  3. Paste the data in your favorite text editor

For binary files, you canUUEncodeIn the VM andUudecodeOn the host.

When will there be network support?

It is relatively easy to add a virtual network interface. the problem is to make it communicate with other hosts, so at this point it is not my priority. for example, due to security restrictions, it is only possible to communicate with the Web site hosting the VM or with cooperating servers. moreover, only specific types of network protocols can be handled because no raw TCP connection nor raw UDP packets can be sent due to API restrictions and security reasons.

Is it possible to emulate a VGA Card and all the missing devices to launch say freedos or windows?

Yes, it is possible but since the current VM is quite slow, only old OSes (such as Windows 3 or msdos) wocould be really usable.

Is there some source code available?

In the technical notes, an archive is given which explains how to build the varous binary images.

The readable source code of the js pc emulator itself is not yet available. At this point, any allocation ing or redistribution of the Code needs my explicit permission.

Is my privacy respected?

Yes. What you type in the virtual machine stays in your browser. No data is sent back to the server.

Javascript PC emulator-technical notes

By Fabrice bellard-May 23,201 1

This PC emulator is written in Javascript. The emulated hardware consists in the following devices:

  • 32 bit x86 compatible CPU
  • 8259 programmble Interrupt Controller
  • 8254 programmble interrupt Timer
  • 16450 UART
  • Real time clock.

The code is written in pure JavaScript using the W3C typed arrays. A slightly slower Fallback mode is implemented for browsers missing this support. for the exact list of supported browsers, see the FAQ. in any case, a fast JavaScript Engine is needed to have good performance.

CPU emulation

Some of the Code is too red from my x86 dynamic translator present in qemu, but there are important differences because here it is an interpreter. the CPU is close to a 486 compatible x86 without FPU. the lack of FPU is not a problem when running Linux as operating system because it contains a FPU emulator. in order to be able to run Linux, a complete MMU is implemented. the exact restrictions of the emulated CPU are:

  1. No FPU/MMX/SSE
  2. No segment limit and right checks when accessing memory (Linux does not rely on them for memory protection, so it is not an issue. The x86 emulator of qemu has the same restriction ).
  3. No single-stepping

I added some tricks which are not present in qemu to be more precise when emulating unaligned load/stores at page boundaries. The condition code emulation is also more efficient than the one in qemu.

Devices

Currently there is no synchronization between the pit frequency and the real time, so there is a variable drift between the time returned by Linux (try the "date" command) and the real time.

The UART (Serial Port) does not support FIFO mode. Perhaps it cocould help to improve the display speed.

There is no network emulation at this point.

A clipboard device (seen/Dev/clipboardIn the emulator) was added to allow exchange of data between the emulator and the outside world.

Javascript Terminal

Although I cocould have reused the excellent termlib, I decided to write my own because I was curious to see how it cocould be done. the main problem is the key handling which is different among browsers and OSES, as described here.

Linux distribution

I compiled a 2.6.20 Linux kernel (I guess any other version wocould work provided there is still an FPU emulator ). the Linux Kernel configuration, patch and the source code of the Linux starter (kind of BIOS) are available: linuxstart-20110820.tar.gz.

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 tinyccand my unfinished but usable Emacs clone qemacs. there is also a small MS-DOS. com launcher I use to test the 16 bit emulation with a tiny. com program to compute PI and a small self-processing ing runner for MS-DOS.

Javascript

I happen to be interested by the implementation of Javascript Engines these days-but I don't know yet if I will write my own any time soon! Anyway, this emulator was a way to learn how to write optimized code for recent Javascript Engines, in particle Jaeger monkey (for Firefox 4) and V8 (for chrome ).

A troubling thing is that the PC emulator is slower using V8 than Jaeger monkey (I used the 32 bit version for both ). I have no precise explanation yet because I only looked at the jeager monkey code so far.

What's the use?

I did it for fun, just because newer Javascript Engines are fast enough to do complicated things. Real use cocould be:

  • Benchmarking of Javascript Engines (How much time takes your JavaScript Engine to boot Linux ?). For this special application, efficient handling of 32 bit signed and unsigned integers and of typed arrays is important.
  • Learning to use command line UNIX tools without leaving the browser.
  • 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 wocould allow to use old dos PC software such as games.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.