Let's do dword-at-a-time memcpy() and memset() in userspace as well.

Also fix a dumb bug that showed up when I was memsetting something other
than zeroes.
This commit is contained in:
Andreas Kling 2019-01-15 08:14:08 +01:00
parent a8e42bacf4
commit 14712ad9c5
Notes: sideshowbarker 2024-07-19 16:02:17 +09:00
3 changed files with 55 additions and 17 deletions

View File

@ -41,8 +41,8 @@ void* memset(void* dest_ptr, byte c, dword n)
if (!(dest & 0x3) && n >= 12) {
size_t dwords = n / sizeof(dword);
dword expanded_c = c;
expanded_c <<= 8;
expanded_c <<= 16;
expanded_c |= expanded_c << 8;
expanded_c |= expanded_c << 16;
asm volatile(
"rep stosl\n"
: "=D"(dest)

View File

@ -3,6 +3,7 @@
#include <stdio.h>
#include <signal.h>
#include <assert.h>
#include <AK/Types.h>
extern "C" {
@ -16,14 +17,6 @@ void bcopy(const void* src, void* dest, size_t n)
memmove(dest, src, n);
}
void* memset(void* dest, int c, size_t n)
{
uint8_t* bdest = (uint8_t*)dest;
for (; n; --n)
*(bdest++) = c;
return dest;
}
size_t strspn(const char* s, const char* accept)
{
const char* p = s;
@ -90,15 +83,60 @@ int memcmp(const void* v1, const void* v2, size_t n)
return 0;
}
void* memcpy(void* dest, const void* src, size_t n)
void* memcpy(void *dest_ptr, const void *src_ptr, dword n)
{
auto* bdest = (unsigned char*)dest;
auto* bsrc = (const unsigned char*)src;
for (; n; --n)
*(bdest++) = *(bsrc++);
return dest;
dword dest = (dword)dest_ptr;
dword src = (dword)src_ptr;
// FIXME: Support starting at an unaligned address.
if (!(dest & 0x3) && !(src & 0x3) && n >= 12) {
size_t dwords = n / sizeof(dword);
asm volatile(
"rep movsl\n"
: "=S"(src), "=D"(dest)
: "S"(src), "D"(dest), "c"(dwords)
: "memory"
);
n -= dwords * sizeof(dword);
if (n == 0)
return dest_ptr;
}
asm volatile(
"rep movsb\n"
:: "S"(src), "D"(dest), "c"(n)
: "memory"
);
return dest_ptr;
}
void* memset(void* dest_ptr, int c, dword n)
{
dword dest = (dword)dest_ptr;
// FIXME: Support starting at an unaligned address.
if (!(dest & 0x3) && n >= 12) {
size_t dwords = n / sizeof(dword);
dword expanded_c = (byte)c;
expanded_c |= expanded_c << 8;
expanded_c |= expanded_c << 16;
asm volatile(
"rep stosl\n"
: "=D"(dest)
: "D"(dest), "c"(dwords), "a"(expanded_c)
: "memory"
);
n -= dwords * sizeof(dword);
if (n == 0)
return dest_ptr;
}
asm volatile(
"rep stosb\n"
: "=D" (dest), "=c" (n)
: "0" (dest), "1" (n), "a" (c)
: "memory"
);
return dest_ptr;
}
void* memmove(void* dest, const void* src, size_t n)
{
if (dest < src)

View File

@ -97,7 +97,7 @@ void Painter::draw_glyph(const Point& point, char ch, Color color)
{
auto* bitmap = font().glyphBitmap(ch);
if (!bitmap) {
dbgprintf("Font doesn't have 0x%02x ('%c')\n", (byte)ch, ch);
dbgprintf("Font doesn't have 0x%b ('%c')\n", (byte)ch, ch);
ASSERT_NOT_REACHED();
}
int x = point.x();