Kernel: Save BSB id

This commit is contained in:
Bananymous 2024-03-06 00:36:09 +02:00
parent 58aca68726
commit f84df175ce
2 changed files with 11 additions and 2 deletions

View File

@ -31,11 +31,12 @@ namespace Kernel
asm volatile("movw %%gs, %0" : "=rm"(id)); asm volatile("movw %%gs, %0" : "=rm"(id));
return id; return id;
} }
static Processor& get(ProcessorID); static Processor& get(ProcessorID);
static Processor& current() { return get(current_id()); } static Processor& current() { return get(current_id()); }
static ProcessorID bsb_id() { return s_bsb_id; }
static bool current_is_bsb() { return current_id() == bsb_id(); }
static void set_interrupt_state(InterruptState state) static void set_interrupt_state(InterruptState state)
{ {
if (state == InterruptState::Enabled) if (state == InterruptState::Enabled)
@ -73,6 +74,8 @@ namespace Kernel
~Processor(); ~Processor();
private: private:
static ProcessorID s_bsb_id;
void* m_stack { nullptr }; void* m_stack { nullptr };
static constexpr size_t m_stack_size { 4096 }; static constexpr size_t m_stack_size { 4096 };

View File

@ -4,10 +4,16 @@
namespace Kernel namespace Kernel
{ {
ProcessorID Processor::s_bsb_id { PROCESSOR_NONE };
static BAN::Vector<Processor> s_processors; static BAN::Vector<Processor> s_processors;
Processor& Processor::create(ProcessorID id) Processor& Processor::create(ProcessorID id)
{ {
// bsb is the first processor
if (s_bsb_id == PROCESSOR_NONE)
s_bsb_id = id;
while (s_processors.size() <= id) while (s_processors.size() <= id)
MUST(s_processors.emplace_back()); MUST(s_processors.emplace_back());
auto& processor = s_processors[id]; auto& processor = s_processors[id];