![]() |
Max OS 0.3
|
Manages the CPU and its cores. More...
#include <cpu.h>
Public Member Functions | |
| CPU (GlobalDescriptorTable *gdt, Multiboot *multiboot) | |
| Constructor for the CPU class. | |
| void | find_cores () const |
| Search the madt for cores and store them. | |
| void | init_cores () |
| Wake up all the cores. | |
Static Public Member Functions | |
| static cpu_status_t * | prepare_for_panic (cpu_status_t *status=nullptr, const string &msg="") |
| Ensure the CPU must panic and prepare for it if so. | |
| static void | PANIC (const char *message, cpu_status_t *status=nullptr) |
| Puts the CPU into a panic state and halts it. Dumps the stack trace and registers. | |
| static void | halt () |
| Halts the CPU indefinitely. | |
| static Core * | executing_core () |
| Gets the core that is currently executing. | |
| static bool | check_nx () |
| Checks if the No Execute page flag is supported. | |
| static void | get_status (cpu_status_t *status) |
| Gets the current CPU status into the provided structure. | |
| static void | set_status (cpu_status_t *status) |
| Sets the CPU registers from the provided structure. | |
| static void | print_registers (cpu_status_t *status) |
| Prints the CPU registers from the provided structure. | |
| static uint64_t | read_msr (uint32_t msr) |
| Reads the value of the specified MSR. | |
| static void | write_msr (uint32_t msr, uint64_t value) |
| Writes the specified value to the specified MSR. | |
| static void | cpuid (uint32_t leaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) |
| Executes the CPUID instruction with the specified leaf and returns the results in the provided pointers. | |
| static bool | check_cpu_feature (CPU_FEATURE_ECX feature) |
| Checks if a CPU feature is supported (ECX Register) | |
| static bool | check_cpu_feature (CPU_FEATURE_EDX feature) |
| Checks if a CPU feature is supported (EDX Register) | |
| static void | stack_trace (size_t) |
| Prints a stack trace up to the specified level. | |
Public Attributes | |
| hardwarecommunication::AdvancedConfigurationAndPowerInterface | acpi |
| The ACPI interface for the CPU. | |
| hardwarecommunication::AdvancedProgrammableInterruptController | apic |
| The APIC interface for the CPU. | |
Static Public Attributes | |
| static Core * | panic_core = nullptr |
| The core that triggered the panic. | |
| static common::Spinlock | panic_lock |
| Lock to prevent multiple panics at once. | |
| static common::Vector< Core * > | cores |
| The list of CPU cores in the system (populated during initialization, includes the BSP and cores that failed to start) | |
| CPU::CPU | ( | GlobalDescriptorTable * | gdt, |
| Multiboot * | multiboot | ||
| ) |
Constructor for the CPU class.
| gdt | The global descriptor table |
| multiboot | The multiboot information struct |
Definition at line 252 of file cpu.cpp.
References apic, cores, find_cores(), MaxOS::Logger::INFO(), and MaxOS::hardwarecommunication::AdvancedProgrammableInterruptController::local_apic().
|
static |
Checks if a CPU feature is supported (ECX Register)
| feature | The feature to check |
Definition at line 575 of file cpu.cpp.
References cpuid().
Referenced by MaxOS::system::Core::init_sse().
|
static |
|
static |
Checks if the No Execute page flag is supported.
Definition at line 605 of file cpu.cpp.
References MaxOS::Logger::DEBUG(), and read_msr().
Referenced by MaxOS::memory::PhysicalMemoryManager::PhysicalMemoryManager().
|
static |
Executes the CPUID instruction with the specified leaf and returns the results in the provided pointers.
| leaf | The CPUID leaf to query |
| eax | The pointer to store the EAX result |
| ebx | The pointer to store the EBX result |
| ecx | The pointer to store the ECX result |
| edx | The pointer to store the EDX result |
Definition at line 403 of file cpu.cpp.
Referenced by check_cpu_feature(), check_cpu_feature(), executing_core(), and MaxOS::hardwarecommunication::LocalAPIC::LocalAPIC().
|
static |
Gets the core that is currently executing.
Definition at line 623 of file cpu.cpp.
References cores, and cpuid().
Referenced by core_main(), MaxOS::processes::GlobalScheduler::core_scheduler(), MaxOS::hardwarecommunication::InterruptManager::handle_interrupt_request(), prepare_for_panic(), MaxOS::processes::GlobalScheduler::print_running_header(), MaxOS::processes::Thread::restore_sse_state(), MaxOS::processes::Thread::save_sse_state(), and MaxOS::processes::Thread::Thread().
| void CPU::find_cores | ( | ) | const |
Search the madt for cores and store them.
Definition at line 527 of file cpu.cpp.
References apic, cores, MaxOS::hardwarecommunication::IOAPIC::get_madt_item(), and MaxOS::hardwarecommunication::AdvancedProgrammableInterruptController::io_apic().
Referenced by CPU().
|
static |
Gets the current CPU status into the provided structure.
| status | The structure to fill with the CPU status |
Definition at line 287 of file cpu.cpp.
Referenced by PANIC().
|
static |
| void CPU::init_cores | ( | ) |
Wake up all the cores.
Definition at line 551 of file cpu.cpp.
References ASSERT, core_boot_info, core_start(), cores, MaxOS::Logger::INFO(), p4_table, MaxOS::memory::PRESENT, MaxOS::memory::PhysicalMemoryManager::s_current_manager, MaxOS::memory::PhysicalMemoryManager::to_lower_region(), and MaxOS::memory::WRITE.
|
static |
Puts the CPU into a panic state and halts it. Dumps the stack trace and registers.
| message | The panic message |
| status | The CPU status at the time of the panic (if available, otherwise will be fetched) |
Definition at line 439 of file cpu.cpp.
References MaxOS::processes::GlobalScheduler::core_scheduler(), MaxOS::processes::GlobalScheduler::current_process(), MaxOS::Logger::ERROR(), get_status(), halt(), panic_core, panic_lock, prepare_for_panic(), print_registers(), and stack_trace().
Referenced by MaxOS::Logger::ASSERT(), and MaxOS::hardwarecommunication::InterruptManager::HandleInterrupt().
|
static |
Ensure the CPU must panic and prepare for it if so.
| status | The status of the CPU (if available) |
| msg | The message to print to diagnose the cause of the panic (prints when close program) |
Definition at line 495 of file cpu.cpp.
References MaxOS::processes::GlobalScheduler::current_process(), MaxOS::Logger::ERROR(), executing_core(), MaxOS::processes::GlobalScheduler::force_remove_process(), MaxOS::memory::PhysicalMemoryManager::in_higher_region(), panic_core, panic_lock, MaxOS::drivers::console::VESABootConsole::print_logo(), and MaxOS::processes::GlobalScheduler::system_scheduler().
Referenced by PANIC().
|
static |
Reads the value of the specified MSR.
| msr | The MSR to read |
Definition at line 372 of file cpu.cpp.
Referenced by check_nx(), MaxOS::hardwarecommunication::LocalAPIC::LocalAPIC(), and MaxOS::hardwarecommunication::LocalAPIC::read().
|
static |
Sets the CPU registers from the provided structure.
| status | The structure containing the CPU status |
Definition at line 312 of file cpu.cpp.
Prints a stack trace up to the specified level.
| level | The number of stack frames to print |
Definition at line 414 of file cpu.cpp.
References MaxOS::Logger::ERROR(), and MaxOS::common::resolve_symbol().
Referenced by PANIC().
Writes the specified value to the specified MSR.
| msr | The MSR to write to |
| value | The value to write |
Definition at line 388 of file cpu.cpp.
Referenced by MaxOS::hardwarecommunication::LocalAPIC::LocalAPIC(), MaxOS::hardwarecommunication::LocalAPIC::send_init(), MaxOS::hardwarecommunication::LocalAPIC::send_startup(), and MaxOS::hardwarecommunication::LocalAPIC::write().
| hardwarecommunication::AdvancedConfigurationAndPowerInterface MaxOS::system::CPU::acpi |
| hardwarecommunication::AdvancedProgrammableInterruptController MaxOS::system::CPU::apic |
The APIC interface for the CPU.
Definition at line 261 of file cpu.h.
Referenced by CPU(), and find_cores().
|
inlinestatic |
The list of CPU cores in the system (populated during initialization, includes the BSP and cores that failed to start)
Definition at line 270 of file cpu.h.
Referenced by MaxOS::processes::GlobalScheduler::activate(), MaxOS::processes::GlobalScheduler::add_process(), MaxOS::processes::GlobalScheduler::add_thread(), CPU(), MaxOS::processes::GlobalScheduler::deactivate(), executing_core(), find_cores(), MaxOS::processes::GlobalScheduler::force_remove_process(), MaxOS::processes::GlobalScheduler::get_process(), MaxOS::processes::GlobalScheduler::get_thread(), MaxOS::processes::GlobalScheduler::GlobalScheduler(), init_cores(), MaxOS::processes::GlobalScheduler::remove_process(), and MaxOS::processes::GlobalScheduler::~GlobalScheduler().
|
inlinestatic |
The core that triggered the panic.
Definition at line 263 of file cpu.h.
Referenced by PANIC(), and prepare_for_panic().
|
inlinestatic |
Lock to prevent multiple panics at once.
Definition at line 264 of file cpu.h.
Referenced by MaxOS::drivers::console::VESABootConsole::get_background_color(), MaxOS::drivers::console::VESABootConsole::get_foreground_color(), PANIC(), and prepare_for_panic().