summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kernel/MiniStdLib.cpp25
-rw-r--r--Kernel/Prekernel/CMakeLists.txt2
2 files changed, 20 insertions, 7 deletions
diff --git a/Kernel/MiniStdLib.cpp b/Kernel/MiniStdLib.cpp
index 2fc5dfbe62..8995094f7e 100644
--- a/Kernel/MiniStdLib.cpp
+++ b/Kernel/MiniStdLib.cpp
@@ -10,24 +10,25 @@ extern "C" {
void* memcpy(void* dest_ptr, const void* src_ptr, size_t n)
{
+#if ARCH(I386) || ARCH(X86_64)
size_t dest = (size_t)dest_ptr;
size_t src = (size_t)src_ptr;
// FIXME: Support starting at an unaligned address.
if (!(dest & 0x3) && !(src & 0x3) && n >= 12) {
size_t size_ts = n / sizeof(size_t);
-#if ARCH(I386)
+# if ARCH(I386)
asm volatile(
"rep movsl\n"
: "=S"(src), "=D"(dest)
: "S"(src), "D"(dest), "c"(size_ts)
: "memory");
-#else
+# else
asm volatile(
"rep movsq\n"
: "=S"(src), "=D"(dest)
: "S"(src), "D"(dest), "c"(size_ts)
: "memory");
-#endif
+# endif
n -= size_ts * sizeof(size_t);
if (n == 0)
return dest_ptr;
@@ -35,6 +36,12 @@ void* memcpy(void* dest_ptr, const void* src_ptr, size_t n)
asm volatile(
"rep movsb\n" ::"S"(src), "D"(dest), "c"(n)
: "memory");
+#else
+ u8* pd = (u8*)dest_ptr;
+ u8 const* ps = (u8 const*)src_ptr;
+ for (; n--;)
+ *pd++ = *ps++;
+#endif
return dest_ptr;
}
@@ -52,24 +59,25 @@ void* memmove(void* dest, const void* src, size_t n)
void* memset(void* dest_ptr, int c, size_t n)
{
+#if ARCH(I386) || ARCH(X86_64)
size_t dest = (size_t)dest_ptr;
// FIXME: Support starting at an unaligned address.
if (!(dest & 0x3) && n >= 12) {
size_t size_ts = n / sizeof(size_t);
size_t expanded_c = explode_byte((u8)c);
-#if ARCH(I386)
+# if ARCH(I386)
asm volatile(
"rep stosl\n"
: "=D"(dest)
: "D"(dest), "c"(size_ts), "a"(expanded_c)
: "memory");
-#else
+# else
asm volatile(
"rep stosq\n"
: "=D"(dest)
: "D"(dest), "c"(size_ts), "a"(expanded_c)
: "memory");
-#endif
+# endif
n -= size_ts * sizeof(size_t);
if (n == 0)
return dest_ptr;
@@ -79,6 +87,11 @@ void* memset(void* dest_ptr, int c, size_t n)
: "=D"(dest), "=c"(n)
: "0"(dest), "1"(n), "a"(c)
: "memory");
+#else
+ u8* pd = (u8*)dest_ptr;
+ for (; n--;)
+ *pd++ = c;
+#endif
return dest_ptr;
}
diff --git a/Kernel/Prekernel/CMakeLists.txt b/Kernel/Prekernel/CMakeLists.txt
index 4c4f2a50e3..9aabfdfb56 100644
--- a/Kernel/Prekernel/CMakeLists.txt
+++ b/Kernel/Prekernel/CMakeLists.txt
@@ -1,5 +1,6 @@
set(SOURCES
UBSanitizer.cpp
+ ../MiniStdLib.cpp
)
if ("${SERENITY_ARCH}" STREQUAL "aarch64")
set(SOURCES
@@ -14,7 +15,6 @@ else()
Arch/x86/multiboot.S
# FIXME: Eventually, some of these should build on aarch64 too.
init.cpp
- ../MiniStdLib.cpp
../../Userland/Libraries/LibELF/Relocation.cpp
)
endif()