Electronic – How are cpus enumerated/identified/counted by BIOS and other low-level routines

assemblycpuprobe

By what mechanism is a BIOS or a kernel able to "see" (enumerate,identify,whatever term is right) other CPUs in an SMP system? How is the boot CPU able to initialise and then "launch" the second or third, fourth CPU?

This is not a question on how a user program has his thread scheduled on another cpu, thread affinity etc, but really down to the nitty-gritty lowest-level mechanism by which this works.

How I vaguely understand this might work is that an MMU temporarily keeps the second CPU on hold until the first one has initialised everything for itself, then for the second CPU, then receives a signal from the main CPU to start the other one. Still then it's not certain what the first thing is that the other cpu executes in an intel system; i.e. would it also start in 8086 mode first, requiring it to run the routine that enables A20 and jumps into PM?

I have coded in ASM in a previous life so I can understand well-explained theoretical answers but I have very little real-life coding experience so just being redirected to Linux kernel source (which I'm already going to try anyway) won't be an answer to my Q 🙂

Best Answer

The simple solution is that physical processors are identified using a wire connection. When you put your CPU into mainboard, there is a lot of pins on it. A pair of them can be simply short-connected inside CPU and used to say "I'm connected".

Additional CPU cores inside a single physical processor can be obtained by executing a special machine code instruction. CPU always know who it is and is ready to tell us when we use the "magic" machine code instruction.

The concrete solution depends on the particular computer system, BIOS, CPU family etc. The BIOS have to know exactly what different possible CPUs can it expect in the mainboard. (It is not possible to put 2-core CPU in an old mainboard which wasn't designed for 2-core CPUs.)

You can find very detailed information about x86/x64 CPUs on www.intel.com.