How "modern" are we talking here? Core 2 Duo? Arrandale? Haswell? Skylake?
Re:Booting Modern Intel CPUs
by mananaysiempre on Monday April 17, 2023 @06:53AM
(#35599045)
Per the OSDev Wiki, Pentium Pro and later[1]:
> For newer CPUs (P6, Pentium 4) one SIPI is enough, but I'm not sure if older Intel CPUs (Pentium) or CPUs from other manufacturers need a second SIPI or not.
When (and if) that became officially sanctioned behaviour is another question.
[1] https://wiki.osdev.org/Symmetric_Multiprocessing#Initialisat...
> A few lines of memory-less stack-less assembly could get the CPU number and then change the stack...
Except for that TSC_AUX (CPU id number) is going to be 0 for all of the cores. Unless you know some other way to get CPU number?
Core ID in TSC_AUX is essentially an concession to userspace. As an OS and firmware you are supposed to identify CPU cores by means of their LAPIC ID (as read from APIC configurations MSR or from CPUID). Small issue there is that APIC IDs are structured according to HT/NUMA topology and thus not necessarily consecutive.
On the other hand, as an OS on PC-like platform you know how many cores there are supposed to be and what are their APIC IDs before-hand because they were already enumerated by firmware (which is the reason why you can do the one by one AP startup sequence in the first place).
Re:Booting Modern Intel CPUs
by JoshTriplett on Monday April 17, 2023 @09:07AM
(#35600065)
Exactly: either read the APIC ID and use that to look up the CPU number in a table you already have, or arrange a location in memory to use xadd to assign a sequential CPU number, whichever your OS prefers.
For the startup code, you shouldn't need to make a function call. A few lines of memory-less stack-less assembly could get the CPU number and then change the stack, assuming you have a global value that gives the base of a preallocated array of stacks.