[kernel] Add index to cpu_data

Because the firmware can set the APIC ids to whatever it wants, add a
sequential index to each cpu_data structure that jsix will use for its
main identifier, or for indexing into arrays, etc.
This commit is contained in:
Justin C. Miller
2021-02-11 00:00:34 -08:00
parent 214ff3eff0
commit 36da65e15b
4 changed files with 15 additions and 7 deletions

View File

@@ -57,9 +57,6 @@ cpu_init(cpu_data *cpu, bool bsp)
cpu_early_init(cpu); cpu_early_init(cpu);
} }
lapic &apic = device_manager::get().get_lapic();
cpu->id = apic.get_id();
// Set up the syscall MSRs // Set up the syscall MSRs
syscall_enable(); syscall_enable();

View File

@@ -23,7 +23,9 @@ struct cpu_state
struct cpu_data struct cpu_data
{ {
cpu_data *self; cpu_data *self;
uint64_t id; uint16_t id;
uint16_t index;
uint32_t reserved;
uintptr_t rsp0; uintptr_t rsp0;
uintptr_t rsp3; uintptr_t rsp3;
TCB *tcb; TCB *tcb;

View File

@@ -159,7 +159,10 @@ kernel_main(args::header *header)
device_manager &devices = device_manager::get(); device_manager &devices = device_manager::get();
devices.parse_acpi(header->acpi_table); devices.parse_acpi(header->acpi_table);
// cpu_init relies on the APIC being set up // Need the local APIC to get the BSP's id
lapic &apic = device_manager::get().get_lapic();
cpu->id = apic.get_id();
cpu_init(cpu, true); cpu_init(cpu, true);
devices.init_drivers(); devices.init_drivers();
@@ -228,6 +231,8 @@ start_aps(void *kpml4)
cpu_data &bsp = current_cpu(); cpu_data &bsp = current_cpu();
bsp.process = &g_kernel_process; bsp.process = &g_kernel_process;
uint16_t index = bsp.index;
// Copy the startup code somwhere the real mode trampoline can run // Copy the startup code somwhere the real mode trampoline can run
uintptr_t addr = 0x8000; // TODO: find a valid address, rewrite addresses uintptr_t addr = 0x8000; // TODO: find a valid address, rewrite addresses
uint8_t vector = addr >> 12; uint8_t vector = addr >> 12;
@@ -258,6 +263,8 @@ start_aps(void *kpml4)
cpu_data *cpu = new cpu_data; cpu_data *cpu = new cpu_data;
kutil::memset(cpu, 0, sizeof(cpu_data)); kutil::memset(cpu, 0, sizeof(cpu_data));
cpu->self = cpu; cpu->self = cpu;
cpu->id = id;
cpu->index = ++index;
cpu->gdt = gdt; cpu->gdt = gdt;
cpu->tss = tss; cpu->tss = tss;
@@ -279,7 +286,7 @@ start_aps(void *kpml4)
// Kick it off! // Kick it off!
size_t current_count = ap_startup_count; size_t current_count = ap_startup_count;
log::debug(logs::boot, "Starting AP %d: stack %llx", id, stack_end); log::debug(logs::boot, "Starting AP %d: stack %llx", cpu->index, stack_end);
apic.send_ipi(lapic::ipi_mode::init, 0, id); apic.send_ipi(lapic::ipi_mode::init, 0, id);
clk.spinwait(1000); clk.spinwait(1000);

View File

@@ -7,7 +7,9 @@ endstruc
struc CPU_DATA struc CPU_DATA
.self: resq 1 .self: resq 1
.id: resq 1 .id: resw 1
.index: resw 1
.reserved resd 1
.rsp0: resq 1 .rsp0: resq 1
.rsp3: resq 1 .rsp3: resq 1
.tcb: resq 1 .tcb: resq 1