x86_64: Create a has_flag() helper function and remove redundant clearing of reserved bits

This commit is contained in:
apio 2022-12-26 12:10:47 +01:00
parent 59d69f684f
commit 08984e1673
Signed by: apio
GPG Key ID: B8A7D06E42258954

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 {};
}