This is demonstrative of the advantages of the new low-level APIs being added to JavaScript to work efficiently with binary data.<p>Fabrice uses this to implement an x86 interpreter -- it could not be done efficiently without typed arrays. However, it is still slow -- imagine what kind of advances could be made if a common bytecode was established that would be JIT'd by the JavaScript VM, and could be output directly by the emulator.<p><i>This</i> is why so many people want to see the browser execution environment offer more complete, low-level APIs instead of high-level APIs locked to HTML/CSS and legacy browser technology. Efficiently supporting high-performance, high-complexity systems such as an <i>x86 emulator</i> (or a video game, or custom font rendering, or even an application framework) absolutely require efficient low-level APIs.
After FFmpeg (used in all your TVs and gadgets, very likely), QEmu (used also by Xen and VBox and other), tcc and his IOCC entries, the DVB-T emission with an ATI card, Fabrice comes, once again with something crazy...<p>He is really impressive...
I'm utterly dumbfounded. Not only does it boot, it's got emacs, and a compiler.<p><pre><code> Welcome to JS/Linux
~ # emacs test.c
~ # cat test.c
void main(void) {
printf("Hello World!\n");
}
~ # tcc test.c -o hello
~ # ./hello
Hello World!
</code></pre>
[Edit: just realized that there is already a 'hello.c' in the directory that shows just this with better diction.]
Fabrice is one of my all time favorite software engineers. Reading his code, studying his methodologies and learning by copying has been a long time task for me.<p>My first encounter with his code was QEmu, when it was required to run the XO OLPC linux images. Society truly benefits when people like him are devoted in support of open source software.
Fabrice Bellard is truly impressive. There's a nice article about him, called "Fabrice Bellard: Portrait of a Superproductive programmer", here: <a href="http://www.softwarequalityconnection.com/2011/03/fabrice-bellard-portrait-of-a-superproductive-programmer/" rel="nofollow">http://www.softwarequalityconnection.com/2011/03/fabrice-bel...</a>
Unbelievable, this is like magic. I am totally impressed. It is a real linux instance. BTW. I see the hello.c file someone mentioned here. Have we all mounted the same disk image?<p>I see so many use cases for this, but I don't fully understand what is going on behind the scenes. Maybe someone can shed some light on it:<p><pre><code> 1) How is the disk emulated. Is it a local image, or is it running on the backend?
2) Is there a remote possibility to get the networking up and running?
3) Can the disk image be externally accessed to be customized?</code></pre>
This is completely awesome. When I saw <a href="http://cb.vu" rel="nofollow">http://cb.vu</a> a few years ago I thought hey, someone has finally done it, but that turned out to be a hack. Kudos to Bellard once again.<p>Nitpicking: the terminal emulation is messed up. It keeps resizing horizontally, and less gets confused. I'm sure the terminal emulator was fun to play with. A correct vt100 state machine implementation [1] would probably not be quite as fun [2]. There's a vt100.js library used by a couple projects that might improve things. [3]<p>[1] <a href="http://vt100.net/emu/dec_ansi_parser" rel="nofollow">http://vt100.net/emu/dec_ansi_parser</a><p>[2] <a href="http://vt100.net/emu/vt500_parser.png" rel="nofollow">http://vt100.net/emu/vt500_parser.png</a><p>[3] <a href="http://fzort.org/bi/o.php" rel="nofollow">http://fzort.org/bi/o.php</a>
I admire Fabrice a lot, he is a programming hero for me. However it is not true that he is not interested in money, for instance the QEMU module performing the run-time code translation to go fast was not released for free in order to earn from this. I don't know if he managed to earn or not from QEMU in the end, but IMHO that of selling the module to final user was not the right strategy, when QEMU was started and became famous, "virtualization" was an huge buzz and interest for many companies, so many ways to make money from this.<p>Also this new code is not released under a free license, so by default as far he is not sure what he's going to do with the code the "open source way" is not the default. This is not a critique. I think Fabrice Bellard is a genius, but as an observer he seems interested in making a profit from his work like many other programmers.<p>Instead subjectively I've to admit today I no longer consider the GPL a completely free license, but this is another matter and may be related not to earning but to the meaning "free software" has for you. For me it is as simple as letting people to do everything with your code. IMHO the BSD license turns out to be better both for users AND for you to earn from your product later.
The emulator code is <i>just</i> 86 kb, and it isn't even aggressively minified!<p><a href="http://bellard.org/jslinux/cpux86.js" rel="nofollow">http://bellard.org/jslinux/cpux86.js</a>
If it doesn't work for you on Chrome 12, this is probably the reason: "it does not work with Chrome 12 beta. As far as I know, it is a bug in the browser"<p>From <a href="http://bellard.org/jslinux/tech.html" rel="nofollow">http://bellard.org/jslinux/tech.html</a>
I just did 'rm -rf /' then ctrl+D on the terminal. Kernel Panic! Very nicely done! Technical notes here <a href="http://bellard.org/jslinux/tech.html" rel="nofollow">http://bellard.org/jslinux/tech.html</a>
Cloud VPS in the browser. ("Please standby while we create a browser tab for your new instance...")<p>"The browser as the operating."<p>Someone <i>must</i> buzzword the hell out of this and then create a new startup based on it.
My favorite bit:<p># cat /proc/cpuinfo<p>...<p>f00f bug: yes<p>#<p>Hah!<p>20 bogomips by the way, at least on Chrome on a MacBook Pro.<p>I sense a whole new era of browser performance testing..
I don't know why it's so amusing, but the network stack is fully functional for loopback.
Fire up telnetd, and telnet back to yourself.
telnetd -l /bin/sh -p 23
telnet 127.0.0.1 23
plenty of other services: httpd..
what a hoot.
He even ported his tcc compiler to it. Brilliant! I wonder if we could tap into the device file system. Given the increasing number of sensors in mobile phones and no standard way of reading from them, a linux like interface would be awesome.<p><pre><code> int main (int argc, char **argv)
{
int f = open("/dev/android_accelerometer");
double ax = f.read();
double ay = f.read();
double az = f.read();
printf ("Current 3d acceleration: %d %d %d", ax, ay, az);
return 0;
}</code></pre>
<p><pre><code> ~ # cat over.c
main () {
int i = 0x00ffffff;
while (i > 0) i--;
}
~ # tcc over.c -o out
~ # time ./out
real 0m 13.58s
user 0m 13.57s
sys 0m 0.01s
</code></pre>
I love this stuff.
Feel bad to miss out on this as I am on FF 3.6. But this remind reminded me of a service from a long time ago. Dont remember their name, this was some 10 years ago. But they used to provide a KDE desktop via the browser as a java applet. It was not terribly snappy, but quite surprisingly usable. Any one remembers this ?
Fabris should put donate button on the page!
I would happily donate to thank him for his great contribution to the Open Source and pushing boundaries of what possible to do with modern technology.
thank U Fabris :)
Didn't know about this guy! Unbelievable track record of consistently releasing groundbreaking software. Oh, and the x86 js emulator is cool too! made my day!
Anyone know why he used 2.6.20 ? I tried compiling a 2.6.38.6, but it doesn't boot. It's stopped at "Starting Linux" and CPU stays at 100% all the time.
<p><pre><code> ~ # httpd
~ # telnet 127.0.0.1 80
get / http/1.0
HTTP/1.0 404 Not Found
Content-type: text/html
Date: Tue, 17 May 2011 20:10:52 GMT
Connection: close
<HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD>
<BODY><H1>404 Not Found</H1>
The requested URL was not found
</BODY></HTML>
Connection closed by foreign host
~ #
</code></pre>
Coolness!
Neat. You can mount sysfs like so:<p><pre><code> # mkdir /sys; mount -t sysfs /sys /sys
</code></pre>
That would allow you to look at the emulated hardware that is present.
Looks like only virtual devices are present -- ram, loopback network etc.<p>Makes sense to me. The MVP here is cpu emulation.
How is this thing loads the kernel? I've read the <a href="http://bellard.org/jslinux/tech.html" rel="nofollow">http://bellard.org/jslinux/tech.html</a> but it doesn't say, Does it loads it over the net or what?
I'm sad the source has been compressed so there's no easy human-readable View Source, like there was on the VAX emulator that came up a few weeks ago. :( Still awe-inspiring, though. :)
If you have a programmers.stackexchange.com account, you might want to put a vote in here: <a href="http://programmers.stackexchange.com/questions/47197/are-there-any-famous-one-man-army-programmers/47240#47240" rel="nofollow">http://programmers.stackexchange.com/questions/47197/are-the...</a>
I tested the JS/Linux with google chrome 12 (beta and gnu/linux) with a new vmlinux26.bin and root.bin compiled using the 2.6.30 kernel with buildroot and work as expected (fine).<p>I don't know what is the problem of the original 2.6.20 linux kernel with JS/Linux but with this new compilation work perfectly.
This looks awesome! I'm just starting to learn ruby and was going to look today on whether there was a way to run it in a browser very easily. Wonder if this is the answer
wow, it is projects like this that get the imagination going and makes you feel bad for putting off a problem set that might have frustrated you at the time.
The page was near-unreadable for me because the CSS uses the font stack "courier,fixed,swiss,sans-serif", and courier is just too thin and wispy against a black background. I opened Firebug and changed the CSS declaration to be "monospace" and then all was right with the world.<p>That said, it's a phenomenal achievement, and should be a great way for websites to demonstrate command-line tools to people. :)<p>(also: browsers let you store more information with DOM Local Storage than you could in a cookie; If you could expose that to Linux as a block device...)
<p><pre><code> ERROR: your browser is too old to run JS/Linux.
You should use a recent browser such as Firefox 4.x or Google Chrome.
</code></pre>
No, it isn't. Stop using user-agent matching and start using JavaScript feature detection instead.