aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
Diffstat (limited to 'libc')
-rw-r--r--libc/inc/mem.h4
-rw-r--r--libc/inc/sys.h2
-rw-r--r--libc/mem.c44
3 files changed, 36 insertions, 14 deletions
diff --git a/libc/inc/mem.h b/libc/inc/mem.h
index 0030b3d..cb64ce8 100644
--- a/libc/inc/mem.h
+++ b/libc/inc/mem.h
@@ -20,8 +20,8 @@
u32 HEAP;
u32 HEAP_START;
-void *memcpy(void *dst, const void *src, u32 n);
-void *memset(void *dst, int c, u32 n);
+void *memcpy(void *dest, const void *src, u32 n);
+void *memset(void *dest, int c, u32 n);
int memcmp(const void *s1, const void *s2, u32 n);
#endif
diff --git a/libc/inc/sys.h b/libc/inc/sys.h
index ebb3836..7c3e6fb 100644
--- a/libc/inc/sys.h
+++ b/libc/inc/sys.h
@@ -22,7 +22,7 @@ enum sys {
SYS_SEND, // Send message to process
SYS_RECEIVE // Receive message (non-blocking/sync)
};
-enum message_type { MSG_NEW_WINDOW, EVENT_KEYBOARD, EVENT_MOUSE };
+enum message_type { MSG_NEW_WINDOW, MSG_REDRAW, EVENT_KEYBOARD, EVENT_MOUSE };
struct message {
int src;
diff --git a/libc/mem.c b/libc/mem.c
index 58c337b..4b7981f 100644
--- a/libc/mem.c
+++ b/libc/mem.c
@@ -4,21 +4,43 @@
#include <print.h>
#include <sys.h>
-void *memcpy(void *dst, const void *src, u32 n)
+// Taken from jgraef at osdev
+void *memcpy(void *dest, const void *src, u32 n)
{
- const char *sp = (const char *)src;
- char *dp = (char *)dst;
- for (; n != 0; n--)
- *dp++ = *sp++;
- return dst;
+ u32 num_dwords = n / 4;
+ u32 num_bytes = n % 4;
+ u32 *dest32 = (u32 *)dest;
+ u32 *src32 = (u32 *)src;
+ u8 *dest8 = ((u8 *)dest) + num_dwords * 4;
+ u8 *src8 = ((u8 *)src) + num_dwords * 4;
+ u32 i;
+
+ for (i = 0; i < num_dwords; i++) {
+ dest32[i] = src32[i];
+ }
+ for (i = 0; i < num_bytes; i++) {
+ dest8[i] = src8[i];
+ }
+ return dest;
}
-void *memset(void *dst, char val, u32 n)
+void *memset(void *dest, char val, u32 n)
{
- char *temp = (char *)dst;
- for (; n != 0; n--)
- *temp++ = val;
- return dst;
+ u32 num_dwords = n / 4;
+ u32 num_bytes = n % 4;
+ u32 *dest32 = (u32 *)dest;
+ u8 *dest8 = ((u8 *)dest) + num_dwords * 4;
+ u8 val8 = (u8)val;
+ u32 val32 = val | (val << 8) | (val << 16) | (val << 24);
+ u32 i;
+
+ for (i = 0; i < num_dwords; i++) {
+ dest32[i] = val32;
+ }
+ for (i = 0; i < num_bytes; i++) {
+ dest8[i] = val8;
+ }
+ return dest;
}
int memcmp(const void *s1, const void *s2, u32 n)