How are cpus enumerated/identified/counted by BIOS and other low-level routines?
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.