[Zion] Access the KernelStackManager through the VMM.
This commit is contained in:
parent
c5b9d20c7e
commit
07e6e3028d
11 changed files with 46 additions and 38 deletions
|
|
@ -2,30 +2,28 @@
|
|||
|
||||
#include "common/gdt.h"
|
||||
#include "debug/debug.h"
|
||||
#include "interrupt/interrupt.h"
|
||||
#include "memory/paging_util.h"
|
||||
|
||||
#define KERNEL_STACK_START 0xFFFFFFFF'90000000
|
||||
#define KERNEL_STACK_LIMIT 0xFFFFFFFF'9FFFFFFF
|
||||
#define KERNEL_STACK_OFFSET 0x4000
|
||||
|
||||
KernelStackManager* gKernelStackManager;
|
||||
|
||||
void KernelStackManager::Init() {
|
||||
gKernelStackManager = new KernelStackManager();
|
||||
|
||||
SetIst1(gKernelStackManager->AllocateKernelStack());
|
||||
}
|
||||
|
||||
KernelStackManager::KernelStackManager()
|
||||
: next_stack_addr_(KERNEL_STACK_START) {}
|
||||
|
||||
uint64_t* KernelStackManager::AllocateKernelStack() {
|
||||
void KernelStackManager::SetupInterruptStack() {
|
||||
SetIst1(AllocateKernelStack());
|
||||
UpdateFaultHandlersToIst1();
|
||||
}
|
||||
|
||||
uint64_t KernelStackManager::AllocateKernelStack() {
|
||||
next_stack_addr_ += KERNEL_STACK_OFFSET;
|
||||
if (next_stack_addr_ >= KERNEL_STACK_LIMIT) {
|
||||
panic("No more kernelstack space");
|
||||
}
|
||||
EnsureResident(next_stack_addr_ - 0x3000, 0x3000);
|
||||
return reinterpret_cast<uint64_t*>(next_stack_addr_) - 1;
|
||||
return next_stack_addr_ - 8;
|
||||
}
|
||||
|
||||
void KernelStackManager::FreeKernelStack(uint64_t stack_base) {
|
||||
|
|
|
|||
|
|
@ -14,14 +14,15 @@
|
|||
// class.
|
||||
class KernelStackManager {
|
||||
public:
|
||||
static void Init();
|
||||
KernelStackManager();
|
||||
|
||||
uint64_t* AllocateKernelStack();
|
||||
void SetupInterruptStack();
|
||||
|
||||
uint64_t AllocateKernelStack();
|
||||
|
||||
void FreeKernelStack(uint64_t stack_base);
|
||||
|
||||
private:
|
||||
KernelStackManager();
|
||||
uint64_t next_stack_addr_;
|
||||
uint64_t freed_stack_cnt_ = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,12 +13,18 @@ KernelVmm::KernelVmm() {
|
|||
panic("KernelVmm double init.");
|
||||
}
|
||||
gKernelVmm = this;
|
||||
stack_manager_ = glcr::MakeUnique<KernelStackManager>();
|
||||
stack_manager_->SetupInterruptStack();
|
||||
}
|
||||
|
||||
uint64_t KernelVmm::AcquireSlabHeapRegion(uint64_t slab_size_bytes) {
|
||||
return gKernelVmm->AcquireSlabHeapRegionInternal(slab_size_bytes);
|
||||
}
|
||||
|
||||
uint64_t KernelVmm::AcquireKernelStack() {
|
||||
return gKernelVmm->stack_manager_->AllocateKernelStack();
|
||||
}
|
||||
|
||||
uint64_t KernelVmm::AcquireSlabHeapRegionInternal(uint64_t slab_size_bytes) {
|
||||
uint64_t next_slab = next_slab_heap_page_;
|
||||
if (next_slab >= kKernelBuddyHeapEnd) {
|
||||
|
|
|
|||
|
|
@ -3,15 +3,25 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "memory/constants.h"
|
||||
#include "memory/kernel_heap.h"
|
||||
#include "memory/kernel_stack_manager.h"
|
||||
|
||||
class KernelVmm {
|
||||
public:
|
||||
KernelVmm();
|
||||
|
||||
// TODO: Create a "MemoryRegion" style class to hold the return
|
||||
// types from this object.
|
||||
static uint64_t AcquireSlabHeapRegion(uint64_t slab_size_bytes);
|
||||
|
||||
static uint64_t AcquireKernelStack();
|
||||
|
||||
static void FreeKernelStack(uint64_t);
|
||||
|
||||
private:
|
||||
uint64_t next_slab_heap_page_ = kKernelSlabHeapStart;
|
||||
KernelHeap heap_;
|
||||
glcr::UniquePtr<KernelStackManager> stack_manager_;
|
||||
|
||||
uint64_t AcquireSlabHeapRegionInternal(uint64_t slab_size_bytes);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -153,10 +153,10 @@ void InitBootstrapPageAllocation() {
|
|||
// if we limit the number of pages this should be fine.
|
||||
// Currently set to the minimum of 3 for one kernel heap allocation:
|
||||
// PageDirectory + PageTable + Page
|
||||
if (entry.type == 0 && entry.length >= 0x5000) {
|
||||
if (entry.type == 0 && entry.length >= 0x9000) {
|
||||
gBootstrap.init_page = entry.base;
|
||||
gBootstrap.next_page = entry.base;
|
||||
gBootstrap.max_page = entry.base + 0x4000;
|
||||
gBootstrap.max_page = entry.base + 0x9000;
|
||||
gBootstrapEnabled = true;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue