result.r15 = 0;
// Copy kernel mappings to the new virtual address space.
- memset(result.PML4T->contents, 0, 256 * amy::byte_size<os::paging::PML4E>());
- memcpy(result.PML4T->contents + 256, original_PML4T.contents + 256, 256 * amy::byte_size<os::paging::PML4E>());
+ amy::memset(result.PML4T->contents, 0, 256 * amy::byte_size<os::paging::PML4E>());
+ amy::memcpy(result.PML4T->contents + 256, original_PML4T.contents + 256, 256 * amy::byte_size<os::paging::PML4E>());
for (amy::size i = 0; i < elf_header.entry_count_program_header_table; i++) {
const os::elf::program_header program_header = *(os::elf::program_header*)(
.US = true, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = false, .AVL = 0,
.NX = (program_header.flags & 1) == 0,
});
- memcpy((void*)alloc.ptr, start + program_header.p_offset, clamp(0ul, program_header.p_filesz - i * 0x1000, 0x1000ul));
+ amy::memcpy((void*)alloc.ptr, start + program_header.p_offset, clamp(0ul, program_header.p_filesz - i * 0x1000, 0x1000ul));
}
}
}
amy::size const index = (amy::size(&os::processes) >> (12 + 9 * 3)) & 0x1FF;
os::paging::global_PML4T.contents[index].paging_table_info({.RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .AVL = 0, .NX = false});
const auto PDPT_alloc = os::paging::page_allocator.allocate(1);
- os::memset((void*)PDPT_alloc.ptr, 0, 0x1000);
+ amy::memset((void*)PDPT_alloc.ptr, 0, 0x1000);
os::paging::global_PML4T.contents[index].paging_table_ptr(os::phys_ptr<os::paging::PDPT>(PDPT_alloc.ptr.get_phys_addr()));
}
} else {
auto const alloc = page_allocator.allocate(1);
assert(alloc.ptr != nullptr, "Not enough RAM to create the paging structures.");
- memset((void*)alloc.ptr, 0, 0x1000);
+ amy::memset((void*)alloc.ptr, 0, 0x1000);
paging_table.contents[index].paging_table_info(
{.RW = true, .US = page_info.US, .PWT = false, .PCD = false, .A = false, .AVL = 0, .NX = false});
paging_table.contents[index].paging_table_ptr(os::phys_ptr<os::paging::paging_table<paging_depth - 1>>{alloc.ptr.get_phys_addr()});
void os::set_msr(amy::u32 msr, amy::u64 v) {
asm volatile ("wrmsr" : : "a"(v & 0xFFFF'FFFF), "d"((v >> 32) & 0xFFFF'FFFF), "c"(msr));
}
-extern "C" void* os::memset(void* dest, int c, amy::size n) {
- os::assert(n >= 0, "Memset expects a positive size.");
- while (n-- > 0) {
- reinterpret_cast<amy::byte*>(dest)[n] = amy::byte(c);
- }
- return dest;
-}
-extern "C" void* os::memcpy(void* dest, const void* src, amy::size n) {
- os::assert(n >= 0, "Memcpy expects a positive size.");
- while (n-- > 0) {
- reinterpret_cast<amy::byte*>(dest)[n] = reinterpret_cast<const amy::byte*>(src)[n];
- }
- return dest;
-}
template <typename T> T clamp(T min, T v, T max) {
return v < min ? min : max < v ? max : v;
}
-extern "C" void* memset(void* dest, int c, amy::size n);
-extern "C" void* memcpy(void* dest, const void* src, amy::size n);
template <typename T>
struct incrementing_int64_map {
static_assert(false, "amy::declval cannot be used in an evaluated context.");
}
+
+extern "C" inline void* memset(void* dest, int c, amy::size n) {
+ while (n-- > 0) {
+ reinterpret_cast<amy::byte*>(dest)[n] = amy::byte(c);
+ }
+ return dest;
+}
+extern "C" inline void* memcpy(void* dest, const void* src, amy::size n) {
+ while (n-- > 0) {
+ reinterpret_cast<amy::byte*>(dest)[n] = reinterpret_cast<const amy::byte*>(src)[n];
+ }
+ return dest;
+}
+
} // namespace amy