views:

340

answers:

1

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.)

+4  A: 

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.

DigitalRoss
Thanks, that's just the information I need! This should be a challenge ...
Rhys Bradshaw