First Hello world syscall
All checks were successful
Build documentation / build-and-deploy (push) Successful in 26s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 26s
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/debug.h>
|
||||
#include <sys/smp.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
/// Cpu ID counter
|
||||
static uint32_t cpu_counter = 0;
|
||||
@@ -18,6 +19,10 @@ static spin_lock_t cpu_counter_lock = SPIN_LOCK_INIT;
|
||||
/// The CPUs
|
||||
static struct cpu cpus[CPUS_MAX];
|
||||
|
||||
static bool thiscpu_init = false;
|
||||
|
||||
void amd64_thiscpu_set_init (void) { thiscpu_init = true; }
|
||||
|
||||
/// Allocate a CPU structure
|
||||
struct cpu* cpu_make (void) {
|
||||
spin_lock (&cpu_counter_lock);
|
||||
@@ -30,30 +35,26 @@ struct cpu* cpu_make (void) {
|
||||
cpu->lock = SPIN_LOCK_INIT;
|
||||
cpu->id = id;
|
||||
|
||||
return cpu_get (id);
|
||||
amd64_wrmsr (MSR_SHADOW_GS_BASE, (uint64_t)cpu);
|
||||
|
||||
return cpu;
|
||||
}
|
||||
|
||||
struct cpu* cpu_get (uint32_t id) {
|
||||
if (id >= CPUS_MAX)
|
||||
struct cpu* cpu_get (void) {
|
||||
if (!thiscpu_init)
|
||||
return NULL;
|
||||
|
||||
return &cpus[id];
|
||||
return (struct cpu*)amd64_rdmsr (MSR_SHADOW_GS_BASE);
|
||||
}
|
||||
|
||||
/// Get ID of current running CPU
|
||||
uint32_t cpu_id (void) { return (uint32_t)amd64_rdmsr (MSR_SHADOW_GS_BASE); }
|
||||
|
||||
/// Assign an ID to the current running CPU
|
||||
void cpu_assign (uint32_t id) { amd64_wrmsr (MSR_SHADOW_GS_BASE, (uint64_t)id); }
|
||||
|
||||
/// Bootstrap code for non-BSP CPUs
|
||||
static void amd64_smp_bootstrap (struct limine_mp_info* mp_info) {
|
||||
amd64_load_kernel_cr3 ();
|
||||
|
||||
struct cpu* cpu = cpu_make ();
|
||||
cpu_assign (cpu->id);
|
||||
|
||||
amd64_init (cpu, true); /* gdt + idt */
|
||||
syscall_init ();
|
||||
|
||||
thiscpu->lapic_ticks = amd64_lapic_init (2500);
|
||||
amd64_lapic_tick (thiscpu->lapic_ticks);
|
||||
|
||||
Reference in New Issue
Block a user