Hi,
doxrobot wrote:This is very helpful Brendan thank you. I was a little unsure how to handle the 8259 PIC. Also, when I am initializing the local APIC on my AP's do you know if an AP can receive a SIPI after it executes a CLI then a HLT?
I don't know what effect a SIPI would have on a normally running CPU - I'd assume "undefined behaviour" (likely that the CPU simply ignores the SIPI but different CPUs might do different things).
"STI; HLT" puts a CPU into a wait state where any interrupt can wake it up. I don't know what effect a SIPI would have on the CPU in this state either; but I'd assume it'd have the same effect as it would on a normally running CPU. There's also a "MWAIT" state (which is similar to the "HLT" wait state except a write to the specified cache line can wake it up too).
"CLI; HLT" puts the CPU into a halted state where it can only respond to INIT, SMI and NMI. In this state the CPU will ignore a SIPI. Note that because of the possibility of SMI and NMI I'd want a loop (e.g. "CLI; HLT; jmp do_it_forever") and I'd want to make sure nothing moved these instructions (e.g. you don't want an SMI to occur when the "CLI; HLT" code has been paged to disk or something).
Note: If your OS is taking a CPU offline, it's wise to disable caches and then clear the caches before doing the "CLI;HLT").
The INIT is like a CPU reset. It's capable of taking the CPU out of any state, and puts the CPU into a special "wait for SIPI" state. This is the only state where a SIPI makes sense. If a CPU is in the "wait for SIPI" state (and possible only if it's in the "wait for SIPI" state) the SIPI will tell it where to start executing.
Note: All of the above only applies to CPUs with a built-in local APIC (e.g. Pentium or later).
doxrobot wrote:From my interpretation after a hard reset this is how the AP's wait. I've also read in the MP specification that it's also possible to use the warm reset vector (assuming BIOS obviously, not EFI/UEFI) and just issue an INIT?
For CPUs with an external local APIC (e.g. 80486) there's an "INIT_assert" and an "INIT_deassert" that make the CPU reset, but there isn't any SIPI - the CPU just starts running at "0xFFFF000:0xFFF0" instead. In this case the firmware's code (at 0xFFFFFFF0) has to check if it's the BSP during power on/reset or if it's an AP being started (either by the BIOS or by an OS). For this reason there's a warm reset vector that tells the firmware's code what the recently started CPU should do. Of course this isn't worth caring about anymore - SMP was rare 20+ years ago when 80486 was new and almost all of those few rare machines have died and/or been replaced and thrown away now.
Cheers,
Brendan