2

我对虚拟机的 CPU 虚拟化有疑问。我无法理解即时到本机代码翻译和陷阱和模拟翻译之间的区别。

据我了解,在第一种情况下,假设我从不同平台模拟二进制代码,如果我有 x86 CPU,代码将转换为等效的 x86 指令。现在在 trap-and-emulate 方法中,虚拟机接收来自客户操作系统的 ISA 调用,并将其转换为主机操作系统的等效 ISA 调用。

为什么我们需要从 ISA 翻译到 ISA?假设我在 Windows 主机上运行 Ubuntu 来宾。Ubuntu ISA 调用与 Windows ISA 调用不同?我知道来宾无法访问主机上的系统 ISA,只有监视器可以这样做。但是为什么需要转换为 Host ISA?ISA还取决于操作系统?

4

1 回答 1

4

"On-the-fly to native" translation (often called JIT compilation/translation) is used when running code from one ISA on another ISA, such as running M68K code on an x86 CPU. It's in no way virtualization, but emulation.

Trap-and-emulate is a way to run "privileged" code in an unprivileged environment (example: running a kernel as an application). The way it works is that you start executing the privileged code, and once it tries to execute a privileged instruction (lidt in x86 for example), the host OS will issue a trap. In the handler for that trap, you could emulate that specific privileged instruction, and then let the guest kernel continue executing. The advantage of this is that you will reach close to native speeds for CPU emulation.

However, just emulating the ISA is only a "small" part of emulating a complete system. Emulating/virtualization of the MMU is much more complex to get right, and to get running fast.

于 2013-05-02T11:50:38.463 回答