Kernel: Per processor information is now stored in class Processor
This allows us to allocate processor stacks, and other per processor structures dynamically in runtime. Giving processor stack to ap_trampoline feels super hacky, but it works for now.
This commit is contained in:
34
kernel/kernel/Processor.cpp
Normal file
34
kernel/kernel/Processor.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <BAN/Vector.h>
|
||||
#include <kernel/Processor.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
static BAN::Vector<Processor> s_processors;
|
||||
|
||||
Processor& Processor::create(ProcessorID id)
|
||||
{
|
||||
while (s_processors.size() <= id)
|
||||
MUST(s_processors.emplace_back());
|
||||
auto& processor = s_processors[id];
|
||||
if (processor.m_stack == nullptr)
|
||||
{
|
||||
processor.m_stack = kmalloc(m_stack_size, 4096, true);
|
||||
ASSERT(processor.m_stack);
|
||||
}
|
||||
return processor;
|
||||
}
|
||||
|
||||
Processor::~Processor()
|
||||
{
|
||||
if (m_stack)
|
||||
kfree(m_stack);
|
||||
m_stack = nullptr;
|
||||
}
|
||||
|
||||
Processor& Processor::get(ProcessorID id)
|
||||
{
|
||||
return s_processors[id];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user