Fabrice Bellard的Javascript中的Linux模拟器如何工作? [英] How does Linux emulator in Javascript by Fabrice Bellard work?

查看:117
本文介绍了Fabrice Bellard的Javascript中的Linux模拟器如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,当我在Javascript中看到Linux模拟器时,我有一个令人痛苦的时刻:
http://bellard.org/jslinux/

Today I had a jaw dropping moment, when I saw Linux emulator in Javascript: http://bellard.org/jslinux/

它编译C程序,它有vi和emacs,它支持所有shell命令等。

It compiles C programs, it has vi and emacs, it supports all shell commands, etc etc.

它是如何工作的?

推荐答案

起初,我还以为这只是一个终端模拟器,将你连接到一个VM但它不是。如果您观看网络连接,您可以看到,启动后,不再传输任何数据。

At first, I also thought this is just a terminal emulator connecting you to a VM but it isn't. If you watch the network connections, you can see that, after bootup, no data is transmitted anymore.

所以这是真的。

CPU不是神奇的东西;事实上它只是从内存读取字节并根据命令的含义修改RAM。

A CPU is not something magic; in fact all it does is read bytes from memory and modify the RAM in accordance to what the commands mean.

在这种情况下,CPU模拟器基于qemu代码。他所做的是创建一个函数数组,其中索引是PC(程序计数器)的下一个字节。

In this case, the CPU emulator is based on the qemu code. What he does is he creates an array of functions where the index is the next byte at the PC (program counter).

现在你所需要的只是一个简单的linux发行版,不需要任何奇特的CPU命令,如浮点运算或MMX代码和瞧。

Now all you need is a simple linux distribution that doesn't need any exotic CPU commands like floating point arithmetic or MMX code and voila.

有趣的是野兽的速度。整个事情有点迟钝但是,它是浏览器中的JavaScript。

What's interesting is the speed of the beast. The whole thing is a bit sluggish but then, it's JavaScript in a browser.

结论:令人印象深刻。迫不及待地想看到C64模拟器: - )

Conclusion: Impressive. Can't wait to see a C64 emulator :-)

这篇关于Fabrice Bellard的Javascript中的Linux模拟器如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆