在不同处理器上运行代码(x86 程序集)

发布于 2024-08-09 02:02:39 字数 123 浏览 4 评论 0原文

在 x86 上的实模式下,需要使用哪些指令在多处理器系统中的不同处理器上运行代码?

(我正在汇编器中编写一些预启动代码,需要设置某些 CPU 寄存器,并在实际操作系统启动之前在系统中的每个 CPU 上执行此操作。)

In real mode on x86, what instructions would need to be used to run the code on a different processor, in a multiprocessor system?

(I'm writing some pre-boot code in assembler that needs to set certain CPU registers, and do this on every CPU in the system, before the actual operating system boots.)

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

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

发布评论

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

评论(1

初心 2024-08-16 02:02:39

那么您有一个独立的(您说“预启动”)程序,例如引导加载程序,以实模式运行?这是在具有通常 BIOS 的 PeeCee 上吗?

在这种情况下,您只有一个 CPU 正在运行。为了启动其他 CPU 单元,操作系统通常会执行所谓的通用启动算法,如下所示:

BSP sends AP an INIT IPI
BSP DELAYs (10mSec)
If (APIC_VERSION is not an 82489DX) {
  BSP sends AP a STARTUP IPI
  BSP DELAYs (200μSEC)
  BSP sends AP a STARTUP IPI
  BSP DELAYs (200μSEC)
}
BSP verifies synchronization with executing AP

BSP 是引导处理器。 AP 是应用程序处理器。 IPI 是处理器间中断。为了执行 IPI,您需要启用 APIC,这是 PC 架构的中断控制器扩展,但在启动时不会启用。这就是为什么代码担心它正在运行什么样的 ICU 版本。所有这些都是相当深奥的内核魔法。您可以尝试查看 Linux、NetBSD 或其他 *BSD 源代码作为示例,但它并不容易阅读。如果你真的赢了,你可能会在某个地方找到一个小内核或独立的 SMP 测试程序。

如需了解更多信息,请参阅英特尔多处理器规范

So you have a stand-alone (you said "pre-boot") program, like a bootloader, running in real mode? And this is on a PeeCee with the usual BIOS?

In that case you have only one CPU running. In order to spin-up the other CPU units an operating system will typically execute what is called the universal startup algorithm which goes like this:

BSP sends AP an INIT IPI
BSP DELAYs (10mSec)
If (APIC_VERSION is not an 82489DX) {
  BSP sends AP a STARTUP IPI
  BSP DELAYs (200μSEC)
  BSP sends AP a STARTUP IPI
  BSP DELAYs (200μSEC)
}
BSP verifies synchronization with executing AP

The BSP is the Boot Processor. An AP is an Application Processor. An IPI is an inter-processor interrupt. In order to do an IPI, you need to enable the APIC, an interrupt controller extension to the PC architecture which is not enabled at bootup. That's why the code is worried about what kind of ICU version it is running. All of this is fairly deep kernel magic. You might try looking at Linux, NetBSD, or other *BSD source code for an example, but it won't be easy to read. If you really win, you might find a small kernel or standalone SMP test program out there somewhere.

For more information, see the Intel Multiprocessor Specification.

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