mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[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:
@@ -8,6 +8,7 @@
|
||||
#include "debug.h"
|
||||
#include "device_manager.h"
|
||||
#include "gdt.h"
|
||||
#include "idt.h"
|
||||
#include "interrupts.h"
|
||||
#include "io.h"
|
||||
#include "kernel_memory.h"
|
||||
@@ -15,6 +16,7 @@
|
||||
#include "objects/process.h"
|
||||
#include "scheduler.h"
|
||||
#include "syscall.h"
|
||||
#include "tss.h"
|
||||
#include "vm_space.h"
|
||||
|
||||
static const uint16_t PIC1 = 0x20;
|
||||
@@ -22,19 +24,14 @@ static const uint16_t PIC2 = 0xa0;
|
||||
|
||||
constexpr uintptr_t apic_eoi_addr = 0xfee000b0 + ::memory::page_offset;
|
||||
|
||||
constexpr size_t increment_offset = 0x1000;
|
||||
|
||||
extern "C" {
|
||||
void _halt();
|
||||
|
||||
void isr_handler(cpu_state*);
|
||||
void irq_handler(cpu_state*);
|
||||
|
||||
#define ISR(i, s, name) extern void name ();
|
||||
#define EISR(i, s, name) extern void name ();
|
||||
#define IRQ(i, q, name) extern void name ();
|
||||
#include "interrupt_isrs.inc"
|
||||
#undef IRQ
|
||||
#undef EISR
|
||||
#undef ISR
|
||||
}
|
||||
|
||||
isr
|
||||
@@ -60,7 +57,7 @@ get_irq(unsigned vector)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
disable_legacy_pic()
|
||||
{
|
||||
// Mask all interrupts
|
||||
@@ -80,28 +77,16 @@ disable_legacy_pic()
|
||||
outb(PIC2+1, 0x02); io_wait();
|
||||
}
|
||||
|
||||
void
|
||||
interrupts_init()
|
||||
{
|
||||
#define ISR(i, s, name) idt_set_entry(i, reinterpret_cast<uint64_t>(& name), 0x08, 0x8e);
|
||||
#define EISR(i, s, name) idt_set_entry(i, reinterpret_cast<uint64_t>(& name), 0x08, 0x8e);
|
||||
#define IRQ(i, q, name) idt_set_entry(i, reinterpret_cast<uint64_t>(& name), 0x08, 0x8e);
|
||||
#include "interrupt_isrs.inc"
|
||||
#undef IRQ
|
||||
#undef EISR
|
||||
#undef ISR
|
||||
|
||||
disable_legacy_pic();
|
||||
|
||||
log::info(logs::boot, "Interrupts enabled.");
|
||||
}
|
||||
|
||||
void
|
||||
isr_handler(cpu_state *regs)
|
||||
{
|
||||
console *cons = console::get();
|
||||
uint8_t vector = regs->interrupt & 0xff;
|
||||
ist_decrement(vector);
|
||||
|
||||
TSS &tss = TSS::current();
|
||||
uint8_t ist = g_idt.get_ist(vector);
|
||||
if (ist)
|
||||
tss.ist_stack(ist) -= increment_offset;
|
||||
|
||||
switch (static_cast<isr>(vector)) {
|
||||
|
||||
@@ -150,13 +135,13 @@ isr_handler(cpu_state *regs)
|
||||
switch ((regs->errorcode & 0x07) >> 1) {
|
||||
case 0:
|
||||
cons->printf(" GDT[%x]\n", index);
|
||||
gdt_dump(index);
|
||||
GDT::current().dump(index);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
case 3:
|
||||
cons->printf(" IDT[%x]\n", index);
|
||||
idt_dump(index);
|
||||
g_idt.dump(index);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -275,7 +260,9 @@ isr_handler(cpu_state *regs)
|
||||
print_stacktrace(2);
|
||||
_halt();
|
||||
}
|
||||
ist_increment(vector);
|
||||
|
||||
if (ist)
|
||||
tss.ist_stack(ist) += increment_offset;
|
||||
*reinterpret_cast<uint32_t *>(apic_eoi_addr) = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user