From e3976c3f58084ccdee5b24cf526dae41b57018cd Mon Sep 17 00:00:00 2001 From: Lizzy Fleckenstein Date: Wed, 29 Nov 2023 15:59:59 +0100 Subject: add more memory functions --- Makefile | 1 + stage3/memory.h | 11 +++++++++++ stage3/memory2.c | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 stage3/memory.h create mode 100644 stage3/memory2.c 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; +} -- cgit v1.2.3