Compare commits

...

3 Commits

Author SHA1 Message Date
73c58bd902
Init: Move platform_init() before MemoryManager::init()
All checks were successful
continuous-integration/drone/push Build is passing
This enables NX before we actually use it.
Wasn't causing problems with KVM on, but crashed with KVM off with a 'reserved bit set' page fault.
2022-12-26 12:12:55 +01:00
0054777e7d
x86_64: Warn if NX is not supported 2022-12-26 12:11:10 +01:00
08984e1673
x86_64: Create a has_flag() helper function and remove redundant clearing of reserved bits 2022-12-26 12:10:47 +01:00
3 changed files with 20 additions and 16 deletions

View File

@ -143,6 +143,8 @@ namespace CPU
enable_sse();
enable_write_protect();
if (test_nx()) enable_nx();
else
kwarnln("not setting the NX bit as it is unsupported");
setup_gdt();
setup_idt();
}

View File

@ -24,6 +24,11 @@ void PageTableEntry::clear()
raw = 0;
}
static bool has_flag(int flags, MMU::Flags flag)
{
return flags & flag;
}
namespace MMU
{
@ -172,7 +177,6 @@ namespace MMU
l4.present = true;
l4.set_address(addr);
memset(l3_table(virt), 0, ARCH_PAGE_SIZE);
l4.ignore0 = l4.ignore1 = 0;
}
if (flags & Flags::ReadWrite) l4.read_write = true;
if (flags & Flags::User) l4.user = true;
@ -184,7 +188,6 @@ namespace MMU
l3.present = true;
l3.set_address(addr);
memset(l2_table(virt), 0, ARCH_PAGE_SIZE);
l3.ignore0 = l3.ignore1 = 0;
}
if (flags & Flags::ReadWrite) l3.read_write = true;
if (flags & Flags::User) l3.user = true;
@ -198,7 +201,6 @@ namespace MMU
l2.present = true;
l2.set_address(addr);
memset(l1_table(virt), 0, ARCH_PAGE_SIZE);
l2.ignore0 = l2.ignore1 = 0;
}
if (flags & Flags::ReadWrite) l2.read_write = true;
if (flags & Flags::User) l2.user = true;
@ -207,13 +209,12 @@ namespace MMU
auto& l1 = l1_entry(virt);
if (l1.present) return err(EEXIST); // Please explicitly unmap the page before mapping it again.
l1.ignore0 = l1.ignore1 = false;
l1.present = true;
l1.read_write = (flags & Flags::ReadWrite);
l1.user = (flags & Flags::User);
l1.write_through = (flags & Flags::WriteThrough);
l1.cache_disabled = (flags & Flags::CacheDisable);
l1.no_execute = (flags & Flags::NoExecute);
l1.read_write = has_flag(flags, Flags::ReadWrite);
l1.user = has_flag(flags, Flags::User);
l1.write_through = has_flag(flags, Flags::WriteThrough);
l1.cache_disabled = has_flag(flags, Flags::CacheDisable);
l1.no_execute = has_flag(flags, Flags::NoExecute);
l1.set_address(phys);
return {};
}
@ -222,11 +223,12 @@ namespace MMU
{
auto& l1 = *TRY(apply_cascading_flags(virt, flags));
if (!l1.present) return err(EFAULT);
l1.read_write = (flags & Flags::ReadWrite);
l1.user = (flags & Flags::User);
l1.write_through = (flags & Flags::WriteThrough);
l1.cache_disabled = (flags & Flags::CacheDisable);
l1.no_execute = (flags & Flags::NoExecute);
l1.read_write = has_flag(flags, Flags::ReadWrite);
l1.user = has_flag(flags, Flags::User);
l1.write_through = has_flag(flags, Flags::WriteThrough);
l1.cache_disabled = has_flag(flags, Flags::CacheDisable);
l1.no_execute = has_flag(flags, Flags::NoExecute);
flush_page(virt);
return {};
}

View File

@ -28,10 +28,10 @@ void Init::early_init()
setup_log(log_debug_enabled(), log_serial_enabled(), true);
CPU::platform_init();
MemoryManager::init();
InitRD::initialize();
CPU::platform_init();
MemoryManager::protect_kernel_sections().expect_release_value("We should succeed to protect sections");
}