Compare commits
2 Commits
0ff365c7f0
...
a4698f0bde
Author | SHA1 | Date |
---|---|---|
|
a4698f0bde | |
|
9a6eae69ba |
|
@ -64,8 +64,8 @@ namespace Kernel
|
|||
static void toggle_should_print_cpu_load() { s_should_print_cpu_load = !s_should_print_cpu_load; }
|
||||
static bool get_should_print_cpu_load() { return s_should_print_cpu_load; }
|
||||
|
||||
static ProcessorID bsb_id() { return s_bsb_id; }
|
||||
static bool current_is_bsb() { return current_id() == bsb_id(); }
|
||||
static ProcessorID bsp_id() { return s_bsp_id; }
|
||||
static bool current_is_bsp() { return current_id() == bsp_id(); }
|
||||
|
||||
static void set_interrupt_state(InterruptState state)
|
||||
{
|
||||
|
@ -153,7 +153,7 @@ namespace Kernel
|
|||
}
|
||||
|
||||
private:
|
||||
static ProcessorID s_bsb_id;
|
||||
static ProcessorID s_bsp_id;
|
||||
static BAN::Atomic<uint8_t> s_processor_count;
|
||||
static BAN::Atomic<bool> s_is_smp_enabled;
|
||||
static BAN::Atomic<bool> s_should_print_cpu_load;
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
#define LAPIC_TIMER_CURRENT_REG 0x390
|
||||
#define LAPIC_TIMER_DIVIDE_REG 0x3E0
|
||||
|
||||
#define IOAPIC_MAX_REDIRS 0x01
|
||||
#define IOAPIC_REDIRS 0x10
|
||||
#define IOAPIC_APICVER 0x01
|
||||
#define IOAPIC_REDIRS 0x10
|
||||
|
||||
// https://uefi.org/specs/ACPI/6.5/05_ACPI_Software_Programming_Model.html#multiple-apic-description-table-madt-format
|
||||
|
||||
|
@ -238,7 +238,7 @@ namespace Kernel
|
|||
io_apic.vaddr & PAGE_ADDR_MASK,
|
||||
PageTable::Flags::ReadWrite | PageTable::Flags::Present
|
||||
);
|
||||
io_apic.max_redirs = io_apic.read(IOAPIC_MAX_REDIRS);
|
||||
io_apic.max_redirs = (io_apic.read(IOAPIC_APICVER) >> 16) & 0xFF;
|
||||
}
|
||||
|
||||
// Enable local apic
|
||||
|
@ -470,7 +470,7 @@ namespace Kernel
|
|||
IOAPIC* ioapic = nullptr;
|
||||
for (IOAPIC& io : m_io_apics)
|
||||
{
|
||||
if (io.gsi_base <= gsi && gsi < io.gsi_base + io.max_redirs)
|
||||
if (io.gsi_base <= gsi && gsi <= io.gsi_base + io.max_redirs)
|
||||
{
|
||||
ioapic = &io;
|
||||
break;
|
||||
|
@ -488,7 +488,7 @@ namespace Kernel
|
|||
redir.vector = IRQ_VECTOR_BASE + irq;
|
||||
redir.mask = 0;
|
||||
// FIXME: distribute IRQs more evenly?
|
||||
redir.destination = Kernel::Processor::bsb_id().as_u32();
|
||||
redir.destination = Kernel::Processor::bsp_id().as_u32();
|
||||
|
||||
ioapic->write(IOAPIC_REDIRS + pin * 2, redir.lo_dword);
|
||||
ioapic->write(IOAPIC_REDIRS + pin * 2 + 1, redir.hi_dword);
|
||||
|
@ -512,7 +512,7 @@ namespace Kernel
|
|||
bool found_ioapic = false;
|
||||
for (const auto& io : m_io_apics)
|
||||
{
|
||||
if (io.gsi_base <= gsi && gsi < io.gsi_base + io.max_redirs)
|
||||
if (io.gsi_base <= gsi && gsi <= io.gsi_base + io.max_redirs)
|
||||
{
|
||||
found_ioapic = true;
|
||||
break;
|
||||
|
@ -566,7 +566,7 @@ namespace Kernel
|
|||
IOAPIC* ioapic = nullptr;
|
||||
for (IOAPIC& io : m_io_apics)
|
||||
{
|
||||
if (io.gsi_base <= gsi && gsi < io.gsi_base + io.max_redirs)
|
||||
if (io.gsi_base <= gsi && gsi <= io.gsi_base + io.max_redirs)
|
||||
{
|
||||
ioapic = &io;
|
||||
break;
|
||||
|
|
|
@ -336,7 +336,7 @@ namespace Kernel
|
|||
ASSERT(InterruptController::get().is_in_service(IRQ_TIMER - IRQ_VECTOR_BASE));
|
||||
InterruptController::get().eoi(IRQ_TIMER - IRQ_VECTOR_BASE);
|
||||
|
||||
if (Processor::current_is_bsb())
|
||||
if (Processor::current_is_bsp())
|
||||
Process::update_alarm_queue();
|
||||
|
||||
Processor::scheduler().timer_interrupt();
|
||||
|
|
|
@ -954,7 +954,7 @@ namespace Kernel
|
|||
|
||||
void Process::update_alarm_queue()
|
||||
{
|
||||
ASSERT(Processor::current_is_bsb());
|
||||
ASSERT(Processor::current_is_bsp());
|
||||
|
||||
SpinLockGuard _(s_process_lock);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Kernel
|
|||
static constexpr uint32_t MSR_IA32_GS_BASE = 0xC0000101;
|
||||
#endif
|
||||
|
||||
ProcessorID Processor::s_bsb_id { PROCESSOR_NONE };
|
||||
ProcessorID Processor::s_bsp_id { PROCESSOR_NONE };
|
||||
BAN::Atomic<uint8_t> Processor::s_processor_count { 0 };
|
||||
BAN::Atomic<bool> Processor::s_is_smp_enabled { false };
|
||||
BAN::Atomic<bool> Processor::s_should_print_cpu_load { false };
|
||||
|
@ -41,10 +41,10 @@ namespace Kernel
|
|||
|
||||
Processor& Processor::create(ProcessorID id)
|
||||
{
|
||||
// bsb is the first processor
|
||||
if (s_bsb_id == PROCESSOR_NONE && id == PROCESSOR_NONE)
|
||||
s_bsb_id = id = read_processor_id();
|
||||
if (s_bsb_id == PROCESSOR_NONE || id == PROCESSOR_NONE || id.m_id >= s_processors.size())
|
||||
// bsp is the first processor
|
||||
if (s_bsp_id == PROCESSOR_NONE && id == PROCESSOR_NONE)
|
||||
s_bsp_id = id = read_processor_id();
|
||||
if (s_bsp_id == PROCESSOR_NONE || id == PROCESSOR_NONE || id.m_id >= s_processors.size())
|
||||
Kernel::panic("Trying to initialize invalid processor {}", id.m_id);
|
||||
|
||||
auto& processor = s_processors[id.m_id];
|
||||
|
@ -114,13 +114,13 @@ namespace Kernel
|
|||
{
|
||||
if (s_processors_created == 1)
|
||||
{
|
||||
ASSERT(current_is_bsb());
|
||||
ASSERT(current_is_bsp());
|
||||
s_processor_count++;
|
||||
s_processor_ids[0] = current_id();
|
||||
}
|
||||
|
||||
// wait until bsb is ready
|
||||
if (current_is_bsb())
|
||||
// wait until bsp is ready
|
||||
if (current_is_bsp())
|
||||
{
|
||||
s_processor_count = 1;
|
||||
s_processor_ids[0] = current_id();
|
||||
|
@ -143,7 +143,7 @@ namespace Kernel
|
|||
}
|
||||
else
|
||||
{
|
||||
// wait until bsb is ready, it shall get index 0
|
||||
// wait until bsp is ready, it shall get index 0
|
||||
while (s_processor_count == 0)
|
||||
__builtin_ia32_pause();
|
||||
|
||||
|
@ -162,7 +162,7 @@ namespace Kernel
|
|||
{
|
||||
if (SystemTimer::get().ms_since_boot() >= timeout_ms)
|
||||
{
|
||||
if (current_is_bsb())
|
||||
if (current_is_bsp())
|
||||
dprintln("Could not initialize {} processors :(", s_processors_created - s_processor_count);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue