在虚拟机中实现 I/O 的更好方法?

发布于 2024-10-03 08:18:12 字数 454 浏览 5 评论 0原文

我正在编写一个虚拟机 - 不是像 Virtualbox 这样的现有架构模拟器,而是像 JVM 或 BEAM 这样的东西 - 具有自己的指令集、内存模型等。最终我计划实现一个非常小且简单的(但图灵完备)高级语言可以编译成字节码,只是为了好玩。

当然,机器必须有一些 I/O 支持,但我不想将其仅限于使用 stdin/stdout 进行操作。我想象类似模块化“虚拟设备”的东西,它可以实现为共享库,以便虚拟机可以在运行时加载它们并通过标准接口与它们通信。例如,通过这种方式,我们可以拥有用于标准输入/输出、图形的“虚拟设备”(想象一个虚拟设备,让您的 VM 程序在 SDL 窗口内绘制内容)甚至网络。

问题是:为VM编写的程序应该如何与虚拟设备通信?我决定模仿实际硬件所采用的技术,并了解基于端口的 I/O 和内存映射 I/O。但是,我不确定其中哪一个更适合我的目标。您能否建议哪一个更好,或者甚至指出一种完全不同的处理输入/输出的技术?

提前致谢。

I'm writing a virtual machine - not an existing architecture emulator like Virtualbox, but rather something like the JVM or BEAM - with its own instruction set, memory model, etc. Eventually I'm planning to implement a very small and simple (but turing-complete) high-level language that would compile into its bytecode, just for fun.

Of course, the machine must have some support of I/O, but I do not want to limit it only to manipulations with stdin/stdout. I imagine something like modular "virtual devices", which can be implemented as shared libraries so that the VM can load them at runtime and communicate with them through a standard interface. This way, for example, we can have "virtual devices" for standard input/output, graphics (imagine a virtual device that lets your VM program draw stuff inside an SDL window) or maybe even network.

The question is: how should the programs written for the VM communicate with the virtual devices? I decided to mimic techniques which are employed with actual hardware and learned about port-based I/O and memory-mapped I/O. However, I'm not sure which one of them is more suitable for my goals. Can you suggest which one is better or maybe even point out a totally different technique for dealing with input/output?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪异←思 2024-10-10 08:18:12

内存映射和基于端口都不适合大多数 I/O。

带有块复制的 DMA 请求通常就是您想要的。

Both memory-mapped and port based are inappropriate for most I/O.

DMA request with block-copy is usually what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文