summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--stage3/memory.h11
-rw-r--r--stage3/memory2.c22
3 files changed, 34 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index b9e677b..ae3b7fb 100644
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,7 @@ STAGE3 = \
stage3/halt.o \
stage3/framebuffer.o \
stage3/memory.o \
+ stage3/memory2.o \
stage3/paging.o \
stage3/heap.o \
stage3/font.o \
diff --git a/stage3/memory.h b/stage3/memory.h
new file mode 100644
index 0000000..774d596
--- /dev/null
+++ b/stage3/memory.h
@@ -0,0 +1,11 @@
+#ifndef _MEMORY_H_
+#define _MEMORY_H_
+
+#include "def.h"
+
+void memcpy(void *dst, const void *src, usize bytes); // memory.asm
+void memmove(void *dst, const void *src, usize bytes); // memory.asm
+int memcmp(const void *s1, const void *s2, usize n); // memory2.c
+u8 memsum(const void *ptr, usize size); // memory2.c
+
+#endif
diff --git a/stage3/memory2.c b/stage3/memory2.c
new file mode 100644
index 0000000..cca3cb1
--- /dev/null
+++ b/stage3/memory2.c
@@ -0,0 +1,22 @@
+#include "memory.h"
+
+int memcmp(const void *s1, const void *s2, usize n)
+{
+ for (usize i = 0; i < n; i++) {
+ unsigned char c1 = ((const unsigned char *) s1)[i];
+ unsigned char c2 = ((const unsigned char *) s2)[i];
+
+ if (c1 != c2)
+ return (int) c1 - (int) c2;
+ }
+
+ return 0;
+}
+
+u8 memsum(const void *ptr, usize size)
+{
+ u8 sum = 0;
+ for (usize i = 0; i < size; i++)
+ sum += ((const u8 *) ptr)[i];
+ return sum;
+}