From 9ea1be96dbf9678f9fba27221ac267afa1d69ed3 Mon Sep 17 00:00:00 2001 From: belliash Date: Wed, 15 Feb 2023 20:48:48 +0100 Subject: [PATCH] Implement MmZeroPages() routine --- xtoskrnl/CMakeLists.txt | 1 + xtoskrnl/mm/amd64/pages.c | 42 +++++++++++++++++++++++++++++++++++++++ xtoskrnl/mm/i686/pages.c | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 xtoskrnl/mm/amd64/pages.c create mode 100644 xtoskrnl/mm/i686/pages.c diff --git a/xtoskrnl/CMakeLists.txt b/xtoskrnl/CMakeLists.txt index 4d7efbb..889feae 100644 --- a/xtoskrnl/CMakeLists.txt +++ b/xtoskrnl/CMakeLists.txt @@ -21,6 +21,7 @@ list(APPEND XTOSKRNL_SOURCE ${XTOSKRNL_SOURCE_DIR}/ke/${ARCH}/krnlinit.c ${XTOSKRNL_SOURCE_DIR}/ke/${ARCH}/proc.c ${XTOSKRNL_SOURCE_DIR}/mm/kpools.c + ${XTOSKRNL_SOURCE_DIR}/mm/${ARCH}/pages.c ${XTOSKRNL_SOURCE_DIR}/rtl/atomic.c ${XTOSKRNL_SOURCE_DIR}/rtl/byteswap.c ${XTOSKRNL_SOURCE_DIR}/rtl/memory.c diff --git a/xtoskrnl/mm/amd64/pages.c b/xtoskrnl/mm/amd64/pages.c new file mode 100644 index 0000000..48c1184 --- /dev/null +++ b/xtoskrnl/mm/amd64/pages.c @@ -0,0 +1,42 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/mm/amd64/pages.c + * DESCRIPTION: Architecture dependent paging support + * DEVELOPERS: Rafal Kupiec + */ + +#include + + +/** + * Fills a section of memory with zeroes like RtlZeroMemory(), but in more efficient way. + * + * @param Address + * Supplies an address of the page to be filled with zeroes. + * + * @param Size + * Number of bytes to be filled with zeros. This always should be a multiply of page size. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTFASTCALL +VOID +MmZeroPages(IN PVOID Address, + IN ULONG Size) +{ + asm volatile("xor %%rax, %%rax\n" + "mov %0, %%rdi\n" + "mov %1, %%ecx\n" + "shr $3, %%ecx\n" + "rep stosq\n" + : + : "m" (Address), + "m" (Size) + : "rax", + "rdi", + "ecx", + "memory"); +} diff --git a/xtoskrnl/mm/i686/pages.c b/xtoskrnl/mm/i686/pages.c new file mode 100644 index 0000000..073749a --- /dev/null +++ b/xtoskrnl/mm/i686/pages.c @@ -0,0 +1,38 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/mm/i686/pages.c + * DESCRIPTION: Architecture dependent paging support + * DEVELOPERS: Rafal Kupiec + */ + +#include + + +/** + * Fills a section of memory with zeroes like RtlZeroMemory(), but in more efficient way. + * + * @param Address + * Supplies an address of the page to be filled with zeroes. + * + * @param Size + * Number of bytes to be filled with zeros. This always should be a multiply of page size. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTFASTCALL +VOID +MmZeroPages(IN PVOID Address, + IN ULONG Size) +{ + asm volatile("xor %%eax, %%eax\n" + "rep stosb" + : "=D"(Address), + "=c"(Size) + : "0"(Address), + "1"(Size), + "a"(0) + : "memory"); +}