Compare commits
5
Commits
811ce51c2c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79d7667a9f
|
||
|
|
0692b9d618
|
||
|
|
cc360c5939
|
||
|
|
d9a0b3652c
|
||
|
|
3aa3538489
|
@@ -26,8 +26,6 @@ void arch::init() {
|
|||||||
|
|
||||||
static constexpr hwirq_t PIT_HWIRQ = 0x00;
|
static constexpr hwirq_t PIT_HWIRQ = 0x00;
|
||||||
|
|
||||||
m_picController.enable(PIT_HWIRQ);
|
|
||||||
|
|
||||||
irq_t pitIrq = m_irqManager.allocate();
|
irq_t pitIrq = m_irqManager.allocate();
|
||||||
m_irqManager.bind(pitIrq, m_picController, PIT_HWIRQ, 0x20);
|
m_irqManager.bind(pitIrq, m_picController, PIT_HWIRQ, 0x20);
|
||||||
m_irqManager.register_handler(pitIrq, pit::handler, &m_pit);
|
m_irqManager.register_handler(pitIrq, pit::handler, &m_pit);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ irq_manager::irq_manager(vm& vm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
irq_t irq_manager::allocate() {
|
irq_t irq_manager::allocate() {
|
||||||
auto* entry = at(m_count + 1);
|
auto* entry = at(m_count);
|
||||||
if (entry == nullptr) {
|
if (entry == nullptr) {
|
||||||
page* newPage = m_vm->allocate<page>();
|
page* newPage = m_vm->allocate<page>();
|
||||||
if (newPage == nullptr) return INVALID_IRQ;
|
if (newPage == nullptr) return INVALID_IRQ;
|
||||||
@@ -64,6 +64,7 @@ bool irq_manager::enable(irq_t irq) {
|
|||||||
auto* entry = at(irq);
|
auto* entry = at(irq);
|
||||||
if (entry == nullptr) return false;
|
if (entry == nullptr) return false;
|
||||||
entry->enabled = true;
|
entry->enabled = true;
|
||||||
|
entry->controller->enable(entry->hwirq);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +72,7 @@ bool irq_manager::disable(irq_t irq) {
|
|||||||
auto* entry = at(irq);
|
auto* entry = at(irq);
|
||||||
if (entry == nullptr) return false;
|
if (entry == nullptr) return false;
|
||||||
entry->enabled = false;
|
entry->enabled = false;
|
||||||
|
entry->controller->disable(entry->hwirq);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,14 @@ common_isr_stub:
|
|||||||
|
|
||||||
cld
|
cld
|
||||||
mov %rsp, %rdi
|
mov %rsp, %rdi
|
||||||
|
|
||||||
|
mov %rsp, %r12
|
||||||
|
and $-16, %rsp
|
||||||
|
|
||||||
call interrupt_handler
|
call interrupt_handler
|
||||||
|
|
||||||
|
mov %r12, %rsp
|
||||||
|
|
||||||
pop %r15
|
pop %r15
|
||||||
pop %r14
|
pop %r14
|
||||||
pop %r13
|
pop %r13
|
||||||
|
|||||||
@@ -131,6 +131,11 @@ private:
|
|||||||
static constexpr u64 INIT_END = 0xFFFFA00000000000ULL;
|
static constexpr u64 INIT_END = 0xFFFFA00000000000ULL;
|
||||||
private:
|
private:
|
||||||
struct node {
|
struct node {
|
||||||
|
enum color_e {
|
||||||
|
RED = 0,
|
||||||
|
BLACK = 1,
|
||||||
|
};
|
||||||
|
|
||||||
// NOTE: The parent node is used for the last free node for first free node.
|
// NOTE: The parent node is used for the last free node for first free node.
|
||||||
node* parent = nullptr;
|
node* parent = nullptr;
|
||||||
node* left = nullptr;
|
node* left = nullptr;
|
||||||
@@ -141,10 +146,12 @@ private:
|
|||||||
u64 size = 0;
|
u64 size = 0;
|
||||||
u64 maxSize = 0;
|
u64 maxSize = 0;
|
||||||
|
|
||||||
bool is_red() const { return (base & (1ULL << 63)) != 0; }
|
color_e color = BLACK;
|
||||||
|
|
||||||
void make_red() { base |= (1ULL << 63); }
|
bool is_red() const { return color == RED; }
|
||||||
void make_black() { base &= ~(1ULL << 63); }
|
|
||||||
|
void make_red() { color = RED; }
|
||||||
|
void make_black() { color = BLACK; }
|
||||||
|
|
||||||
static u64 max_size(node* node) { return (node != nullptr) ? node->maxSize : 0; }
|
static u64 max_size(node* node) { return (node != nullptr) ? node->maxSize : 0; }
|
||||||
|
|
||||||
@@ -171,7 +178,7 @@ private:
|
|||||||
|
|
||||||
node* max() {
|
node* max() {
|
||||||
node* node = this;
|
node* node = this;
|
||||||
while (node != nullptr && node->left != nullptr)
|
while (node != nullptr && node->right != nullptr)
|
||||||
node = node->right;
|
node = node->right;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,14 @@ paging::paging(pmm& pmm)
|
|||||||
m_pml4 = reinterpret_cast<u64*>(m_pml4Phys + HHDM_BASE);
|
m_pml4 = reinterpret_cast<u64*>(m_pml4Phys + HHDM_BASE);
|
||||||
pmm.relocate_bitmap(HHDM_BASE);
|
pmm.relocate_bitmap(HHDM_BASE);
|
||||||
|
|
||||||
// TODO: Map the rest of RAM
|
for (auto *entry = pmm.get_mmap().entries, *end = entry + pmm.get_mmap().entryCount; entry != end; ++entry) {
|
||||||
|
if (entry->type != mmap::entry::AVAILABLE) continue;
|
||||||
|
const physaddr_t begin = entry->base;
|
||||||
|
const physaddr_t entryEnd = entry->base + entry->size;
|
||||||
|
if (entryEnd < BOOTSTRAP_HHDM_LIMIT) continue;
|
||||||
|
|
||||||
|
map_hhdm(begin >= BOOTSTRAP_HHDM_LIMIT ? begin : BOOTSTRAP_HHDM_LIMIT, entryEnd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
physaddr_t paging::get(virtaddr_t virtualAddr) {
|
physaddr_t paging::get(virtaddr_t virtualAddr) {
|
||||||
@@ -106,14 +113,26 @@ physaddr_t paging::get(virtaddr_t virtualAddr) {
|
|||||||
u64 pdIdx = (addrInt >> 21) & ENTRY_INDEX_MASK;
|
u64 pdIdx = (addrInt >> 21) & ENTRY_INDEX_MASK;
|
||||||
u64 ptIdx = (addrInt >> 12) & ENTRY_INDEX_MASK;
|
u64 ptIdx = (addrInt >> 12) & ENTRY_INDEX_MASK;
|
||||||
|
|
||||||
|
const bool bootstrap = reinterpret_cast<virtaddr_t>(m_pml4) < HHDM_BASE;
|
||||||
|
|
||||||
|
auto tableFromPhys = [bootstrap](physaddr_t physical) -> u64* {
|
||||||
|
return bootstrap ? reinterpret_cast<u64*>(physical) : reinterpret_cast<u64*>(HHDM_BASE + physical);
|
||||||
|
};
|
||||||
|
|
||||||
u64 pml4e = m_pml4[pml4Idx];
|
u64 pml4e = m_pml4[pml4Idx];
|
||||||
if ((pml4e & 0x01) == 0) return INVALID_PHYSADDR;
|
if ((pml4e & PAGE_PRESENT) == 0) return INVALID_PHYSADDR;
|
||||||
u64 pdpte = reinterpret_cast<u64*>(pml4e & PHYS_MASK)[pdptIdx];
|
|
||||||
if ((pdpte & 0x01) == 0) return INVALID_PHYSADDR;
|
u64* pdpt = tableFromPhys(pml4e & PHYS_MASK);
|
||||||
u64 pde = reinterpret_cast<u64*>(pdpte & PHYS_MASK)[pdIdx];
|
u64 pdpte = pdpt[pdptIdx];
|
||||||
if ((pde & 0x01) == 0) return INVALID_PHYSADDR;
|
if ((pdpte & PAGE_PRESENT) == 0) return INVALID_PHYSADDR;
|
||||||
u64 pte = reinterpret_cast<u64*>(pde & PHYS_MASK)[ptIdx];
|
|
||||||
if ((pte & 0x01) == 0) return INVALID_PHYSADDR;
|
u64* pd = tableFromPhys(pdpte & PHYS_MASK);
|
||||||
|
u64 pde = pd[pdIdx];
|
||||||
|
if ((pde & PAGE_PRESENT) == 0) return INVALID_PHYSADDR;
|
||||||
|
if ((pde & PAGE_LARGE) == PAGE_LARGE) panic();
|
||||||
|
|
||||||
|
u64* pt = tableFromPhys(pde & PHYS_MASK);
|
||||||
|
u64 pte = pt[ptIdx];
|
||||||
|
|
||||||
return (pte & PHYS_MASK) | (addrInt & ((1 << 12) - 1));
|
return (pte & PHYS_MASK) | (addrInt & ((1 << 12) - 1));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include "arch/x86_64/int.hpp"
|
#include "arch/x86_64/int.hpp"
|
||||||
#include "arch/x86_64/io.hpp"
|
#include "arch/x86_64/io.hpp"
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
#include "vga.hpp"
|
|
||||||
|
|
||||||
namespace x86_64 {
|
namespace x86_64 {
|
||||||
|
|
||||||
@@ -25,8 +24,6 @@ struct pit {
|
|||||||
|
|
||||||
pit* pit = reinterpret_cast<decltype(pit)>(data);
|
pit* pit = reinterpret_cast<decltype(pit)>(data);
|
||||||
++pit->ticks;
|
++pit->ticks;
|
||||||
|
|
||||||
vga::puts("PIT called!", 0, 5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
volatile u64 ticks = 0;
|
volatile u64 ticks = 0;
|
||||||
|
|||||||
@@ -351,7 +351,7 @@ void vm::remove_fixup(node* first, node* second) {
|
|||||||
|
|
||||||
node* sibling = second->left;
|
node* sibling = second->left;
|
||||||
|
|
||||||
if (sibling->is_red()) {
|
if (sibling != nullptr && sibling->is_red()) {
|
||||||
sibling->make_black();
|
sibling->make_black();
|
||||||
second->make_red();
|
second->make_red();
|
||||||
|
|
||||||
@@ -491,6 +491,7 @@ vm::node* vm::allocate_node() {
|
|||||||
if (m_firstFree != nullptr) {
|
if (m_firstFree != nullptr) {
|
||||||
node* node = m_firstFree;
|
node* node = m_firstFree;
|
||||||
m_firstFree = m_firstFree->right;
|
m_firstFree = m_firstFree->right;
|
||||||
|
m_firstFree->parent = node->parent;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user