spz3/Kernel.cpp

30 lines
760 B
C++
Raw Normal View History

2025-03-31 17:19:43 +03:00
#include "Kernel.h"
Kernel::Kernel(const List<PhysicalPage> &free_pages, const List<PhysicalPage> &busy_pages)
: free_pages(free_pages), busy_pages(busy_pages) {
}
void Kernel::page_fault(PageTable page_table, const int idx) {
PhysicalPage *page;
if (!this->free_pages.is_empty()) {
page = free_pages.last();
free_pages.remove(page);
busy_pages.insert_tail(page);
} else {
page = nullptr; // TODO: page replacement algorithm
}
if (page) {
page_table[idx].PPN = page->PPN;
page_table[idx].P = true;
page_table[idx].R = false;
page_table[idx].M = false;
}
}
void Kernel::stat_update() {
for (int i = 0; i < 10; ++i) {
// TODO: update busy page stats
}
}