[kernel] Start all other processors in the system
This very large commit is mainly focused on getting the APs started and to a state where they're waiting to have work scheduled. (Actually scheduling on them is for another commit.) To do this, a bunch of major changes were needed: - Moving a lot of the CPU initialization (including for the BSP) to init_cpu(). This includes setting up IST stacks, writing MSRs, and creating the cpu_data structure. For the APs, this also creates and installs the GDT and TSS, and installs the global IDT. - Creating the AP startup code, which tries to be as position independent as possible. It's copied from its location to 0x8000 for AP startup, and some of it is fixed at that address. The AP startup code jumps from real mode to long mode with paging in one swell foop. - Adding limited IPI capability to the lapic class. This will need to improve. - Renaming cpu/cpu.* to cpu/cpu_id.* because it was just annoying in GDB and really isn't anything but cpu_id anymore. - Moved all the GDT, TSS, and IDT code into their own files and made them classes instead of a mess of free functions. - Got rid of bsp_cpu_data everywhere. Now always call the new current_cpu() to get the current CPU's cpu_data. - Device manager keeps a list of APIC ids now. This should go somewhere else eventually, device_manager needs to be refactored away. - Moved some more things (notably the g_kernel_stacks vma) to the pre-constructor setup in memory_bootstrap. That whole file is in bad need of a refactor.
This commit is contained in:
@@ -2,9 +2,13 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "kutil/spinlock.h"
|
||||
|
||||
class GDT;
|
||||
class process;
|
||||
struct TCB;
|
||||
class thread;
|
||||
class process;
|
||||
class TSS;
|
||||
|
||||
struct cpu_state
|
||||
{
|
||||
@@ -18,15 +22,34 @@ struct cpu_state
|
||||
/// version in 'tasking.inc'
|
||||
struct cpu_data
|
||||
{
|
||||
cpu_data *self;
|
||||
uint64_t id;
|
||||
uintptr_t rsp0;
|
||||
uintptr_t rsp3;
|
||||
TCB *tcb;
|
||||
thread *t;
|
||||
process *p;
|
||||
thread *thread;
|
||||
process *process;
|
||||
TSS *tss;
|
||||
GDT *gdt;
|
||||
|
||||
// Values from here on don't need to be in the asm version
|
||||
kutil::spinlock::node spinner;
|
||||
};
|
||||
|
||||
extern cpu_data bsp_cpu_data;
|
||||
extern "C" cpu_data * _current_gsbase();
|
||||
|
||||
// We already validated the required options in the bootloader,
|
||||
// but iterate the options and log about them.
|
||||
/// Initialize a CPU and set up its cpu_data structure
|
||||
/// \arg bsp True if the current CPU is the BSP
|
||||
void init_cpu(bool bsp);
|
||||
|
||||
/// Get the cpu_data struct for the current executing CPU
|
||||
inline cpu_data & current_cpu() { return *_current_gsbase(); }
|
||||
|
||||
/// Validate the required CPU features are present. Really, the bootloader already
|
||||
/// validated the required features, but still iterate the options and log about them.
|
||||
void cpu_validate();
|
||||
|
||||
/// Set up the running CPU. This sets GDT, IDT, and necessary MSRs as well as creating
|
||||
/// the cpu_data structure for this processor.
|
||||
/// \arg bsp True if this CPU is the BSP
|
||||
void cpu_initialize(bool bsp);
|
||||
|
||||
Reference in New Issue
Block a user