Rewrite init app in C, introduce MSL (MOP3 System Library)
All checks were successful
Build documentation / build-and-deploy (push) Successful in 35s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 35s
This commit is contained in:
@@ -13,38 +13,31 @@
|
||||
#include <sys/syscall.h>
|
||||
|
||||
/// Cpu ID counter
|
||||
static uint32_t cpu_counter = 0;
|
||||
/// Lock for \ref cpu_counter
|
||||
static spin_lock_t cpu_counter_lock = SPIN_LOCK_INIT;
|
||||
static atomic_uint cpu_counter = 0;
|
||||
/// The CPUs
|
||||
static struct cpu cpus[CPUS_MAX];
|
||||
|
||||
static bool thiscpu_init = false;
|
||||
|
||||
void amd64_thiscpu_set_init (void) { thiscpu_init = true; }
|
||||
static atomic_int cpu_init_count;
|
||||
|
||||
/// Allocate a CPU structure
|
||||
struct cpu* cpu_make (void) {
|
||||
spin_lock (&cpu_counter_lock);
|
||||
int id = cpu_counter++;
|
||||
spin_unlock (&cpu_counter_lock);
|
||||
int id = atomic_fetch_add (&cpu_counter, 1);
|
||||
|
||||
struct cpu* cpu = &cpus[id];
|
||||
|
||||
memset (cpu, 0, sizeof (*cpu));
|
||||
cpu->lock = SPIN_LOCK_INIT;
|
||||
cpu->id = id;
|
||||
cpu->self = cpu;
|
||||
|
||||
amd64_wrmsr (MSR_SHADOW_GS_BASE, (uint64_t)cpu);
|
||||
amd64_wrmsr (MSR_GS_BASE, (uint64_t)cpu);
|
||||
|
||||
return cpu;
|
||||
}
|
||||
|
||||
struct cpu* cpu_get (void) {
|
||||
if (!thiscpu_init)
|
||||
return NULL;
|
||||
|
||||
return (struct cpu*)amd64_rdmsr (MSR_SHADOW_GS_BASE);
|
||||
struct cpu* ptr = (struct cpu*)amd64_rdmsr (MSR_GS_BASE);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/// Bootstrap code for non-BSP CPUs
|
||||
@@ -56,27 +49,36 @@ static void amd64_smp_bootstrap (struct limine_mp_info* mp_info) {
|
||||
amd64_init (cpu, true); /* gdt + idt */
|
||||
syscall_init ();
|
||||
|
||||
thiscpu->lapic_ticks = amd64_lapic_init (2500);
|
||||
thiscpu->lapic_ticks = amd64_lapic_init (10000);
|
||||
amd64_lapic_tick (thiscpu->lapic_ticks);
|
||||
|
||||
DEBUG ("CPU %u is online!\n", thiscpu->id);
|
||||
|
||||
__asm__ volatile ("sti");
|
||||
|
||||
atomic_fetch_sub (&cpu_init_count, 1);
|
||||
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
|
||||
/// Initialize SMP subsystem for AMD64. Start AP CPUs
|
||||
void smp_init (void) {
|
||||
thiscpu->lapic_ticks = amd64_lapic_init (2500);
|
||||
thiscpu->lapic_ticks = amd64_lapic_init (10000);
|
||||
|
||||
struct limine_mp_response* mp = limine_mp_request.response;
|
||||
|
||||
cpu_init_count = mp->cpu_count - 1; /* Don't include BSP */
|
||||
|
||||
for (size_t i = 0; i < mp->cpu_count; i++) {
|
||||
if (mp->cpus[i]->lapic_id != thiscpu->id) {
|
||||
DEBUG ("Trying CPU %u\n", mp->cpus[i]->lapic_id);
|
||||
mp->cpus[i]->goto_address = &amd64_smp_bootstrap;
|
||||
}
|
||||
}
|
||||
|
||||
while (atomic_load (&cpu_init_count) > 0)
|
||||
;
|
||||
|
||||
DEBUG ("All CPUs are online\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user