Hi,
mariuszp wrote:
At boot-time, you are guaranteed to be working in mono-core mode. You must explicitly turn on the other cores if you want to use them.
That depends a little on how much you care about security.
I've always thought it'd be fun to have a "boot manager"/MBR that hooks "int 0x15" and steals some memory, then starts an AP CPU and modifies ACPI tables to remove any mention of that AP CPU, then chain-loads/boots the unsuspecting OS's boot loader. This way my code would have full access to the victim OS's physical memory and could do whatever it pleased with it; and most operating systems wouldn't detect my presence.
Tweety wrote:
-> Is there a way to know if an AP core of a multi-core CPU has been enabled ?
No, not unless you started it or you know something specific about the code that did start it.
Tweety wrote:
-> Is there a way to switch from multi-core to mono-core processing at OS startup? (shutdown/disable AP cores ?)
Yes, but I'm not too sure how "failure proof" it is. The basic idea is to send an INIT IPI to the CPU (causing it to return to a "wait for SIPI state"); but (due to various CPU errata, etc) I'd want take various precautions, like disabling paging, returning to real mode, disabling and flushing caches, etc.
Note that it may be possible for the BSP to send an INIT IPI to "all excluding self" and cause any/all AP CPUs that were started to be stopped (to enter that "wait for SIPI state"), without knowing if any AP CPUs were started or not. However I'm not sure how many different corner-cases might exist that could make this idea unsafe or unwise.
mariuszp wrote:
For the sake of starting easy again, I'm using a BIOS to focus on the OS part at the moment.
The only reason to allow yourself to be constrained by the restrictions of BIOS is to make sure that you are unable to learn anything that you need to learn to achieve anything useful. It's like an athlete who decides the best way to start training to win a marathon is have the lower half of their body encased in solid concrete.
mariuszp wrote:
Nevertheless, I decided to proceed to shutdown every AP core according to Intel MP specifications: send the APs an INIT IPI with HALT instruction at warm reset vector.
But these specifications are quite old, and I remember reading on this forum this method was not done anymore. Is this still valid ?
Once upon a time (a long time ago) the local APIC was an separate chip (not built into the CPU at all) and had some differences. One of those differences is AP initialisation; where you'd send "INIT IPI (assert)" then "INIT IPI (deassert)" to reset it, and it'd begin executing at firmware's rest vector.
None of that applies to Pentium or later CPUs (which have the local APIC built into the same chip as the CPU). For these you send an "INIT IPI" and then one or 2 "Startup IPIs"; where the CPU begins executing at the address determined by the "Startup IPI" (and doesn't use the firmware's reset vector).
Cheers,
Brendan