aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/util.c b/src/util.c
index 2c22dfc3..8e02d1e0 100644
--- a/src/util.c
+++ b/src/util.c
@@ -202,24 +202,27 @@ memcpy(void *d1, const void *s1, size_t len)
return d1;
}
-// Copy from memory mapped IO. IO mem is very slow, so yield
-// periodically. 'len' must be 4 byte aligned.
+// Copy to/from memory mapped IO. IO mem is very slow, so yield
+// periodically.
void
iomemcpy(void *d, const void *s, u32 len)
{
yield();
- while (len) {
+ while (len > 3) {
u32 copylen = len;
if (copylen > 2048)
copylen = 2048;
- len -= copylen;
copylen /= 4;
+ len -= copylen * 4;
asm volatile(
"rep movsl (%%esi),%%es:(%%edi)"
: "+c"(copylen), "+S"(s), "+D"(d)
: : "cc", "memory");
yield();
}
+ if (len)
+ // Copy any remaining bytes.
+ memcpy(d, s, len);
}
void *