diff options
author | Lizzy Fleckenstein <eliasfleckenstein@web.de> | 2023-11-29 15:59:59 +0100 |
---|---|---|
committer | Lizzy Fleckenstein <eliasfleckenstein@web.de> | 2023-11-29 15:59:59 +0100 |
commit | e3976c3f58084ccdee5b24cf526dae41b57018cd (patch) | |
tree | 7daeccac1d00ad6e77246b7f6efb5cce88e2f6b3 | |
parent | fa439f4c94f20e7e4580a0436475efa4f2d24383 (diff) | |
download | cuddles-e3976c3f58084ccdee5b24cf526dae41b57018cd.tar.xz |
add more memory functions
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | stage3/memory.h | 11 | ||||
-rw-r--r-- | stage3/memory2.c | 22 |
3 files changed, 34 insertions, 0 deletions
@@ -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; +} |