diff --git a/src/Makefile.in b/src/Makefile.in index 12bdd68..b728749 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,11 +1,11 @@ -//----------------------------------------------------------------------------# -// GNU GPL OS/K # -// # -// Authors: spectral` # -// NeoX # -// # -// Desc: Project Makefile # -//----------------------------------------------------------------------------# +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: Project Makefile // +//----------------------------------------------------------------------------// // The madman's Makefile #include "preproc.h" diff --git a/src/kaleid/common/convert.c b/src/kaleid/common/itoa.c similarity index 96% rename from src/kaleid/common/convert.c rename to src/kaleid/common/itoa.c index c18765c..a184e16 100644 --- a/src/kaleid/common/convert.c +++ b/src/kaleid/common/itoa.c @@ -4,7 +4,7 @@ // Authors: spectral` // // NeoX // // // -// Desc: Conversion utilities // +// Desc: Conversion utilities - itoa family // //----------------------------------------------------------------------------// #include diff --git a/src/kaleid/common/memory.c b/src/kaleid/common/memory.c index c88bd43..59b6cb8 100644 --- a/src/kaleid/common/memory.c +++ b/src/kaleid/common/memory.c @@ -17,7 +17,7 @@ // // Set "bytes"-many bytes starting from ptr to val // -void *memsetb(void *ptr, int val, size_t bytes) +void *memset(void *ptr, int val, size_t bytes) { uchar *uptr = (uchar *)ptr; @@ -45,9 +45,7 @@ void *memsetb(void *ptr, int val, size_t bytes) } // deal with what's left - while (bytes--) { - *uptr++ = (uchar)val; - } + while (bytes--) *uptr++ = (uchar)val; return ptr; } @@ -61,12 +59,7 @@ void *memsetw(void *ptr, int val, size_t words) // can't we do this an aligned way? if unlikely (((ulong)uptr % WORD_ALIGN) > 0) { - // no, we can't align ourselves - while (words--) { - // do it the hard way - *uptr++ = (ushort)val; - } - // too bad '-' + while (words--) *uptr++ = (ushort)val; return uptr; } @@ -92,9 +85,7 @@ void *memsetw(void *ptr, int val, size_t words) } // deal with what's left - while (words--) { - *uptr++ = (ushort)val; - } + while (words--) *uptr++ = (ushort)val; return ptr; } @@ -135,7 +126,6 @@ void *memzero(void *ptr, size_t bytes) return memsetb(ptr, 0, bytes); } - // // Copy "bytes"-many bytes of src to dst // Does not deal with overlapping blocks (memmove's job) @@ -185,10 +175,45 @@ void *memcpy(void *dst, const void *src, size_t bytes) ushort *ubdst = (ushort *)udst; // deal with what's left - while (bytes--) { - *ubdst ++ = *ubsrc++; - } + while (bytes--) *ubdst ++ = *ubsrc++; return dst; } +// +// Move memory from src to dest +// To be made more efficient +// +void *memmove(void *dst, const void *src, size_t bytes) +{ + const uchar *usrc = src; + uchar *udst = dst; + + if (udst < usrc) { + while (bytes--) *udst++ = *usrc++; + return dst; + } + + uchar *usrc_end = (uchar *)usrc + bytes - 1; + uchar *udst_end = udst + bytes - 1; + while (bytes--) *udst_end-- = *usrc_end--; + + return dst; +} + +// +// Compare memory areas +// +int memcmp(const void *ptr1, const void *ptr2, size_t bytes) +{ + const uchar *uptr1 = ptr1; + const uchar *uptr2 = ptr2; + + while (bytes--) { + if (*uptr1++ != *uptr2++) { + return uptr1[-1] < uptr2[-1] ? -1 : 1; + } + } + + return 0; +} diff --git a/src/kaleid/include/kalcrt.h b/src/kaleid/include/kalcrt.h index bc46aa1..534533b 100644 --- a/src/kaleid/include/kalcrt.h +++ b/src/kaleid/include/kalcrt.h @@ -71,20 +71,20 @@ typedef struct { long quot, rem; } ldiv_t; // Memory management utilities // //------------------------------------------// -#ifndef memset -#define memset memsetb +#ifndef memsetb +#define memsetb memset #endif -#ifndef memchr -#define memchr memchrb +#ifndef memchrb +#define memchrb memchr #endif -void *memsetb(void *, int, size_t); +void *memset(void *, int, size_t); void *memsetw(void *, int, size_t); void *memsetd(void *, int, size_t); void *memsetq(void *, long, size_t); -void *memchrb(const void *, int, size_t); +void *memchr(const void *, int, size_t); void *memchrw(const void *, int, size_t); void *memchrd(const void *, int, size_t); void *memchrq(const void *, long, size_t); diff --git a/src/kaleid/include/kalmask.h b/src/kaleid/include/kalmask.h index 078163a..5c9870e 100644 --- a/src/kaleid/include/kalmask.h +++ b/src/kaleid/include/kalmask.h @@ -20,7 +20,7 @@ #define memsetd _osk_memsetd #define memsetq _osk_memsetq -#define memchrb _osk_memchrb +#define memchr _osk_memchrb #define memchrw _osk_memchrw #define memchrd _osk_memchrd #define memchrq _osk_memchrq diff --git a/src/preproc.h b/src/preproc.h index 265f9ee..b55004d 100644 --- a/src/preproc.h +++ b/src/preproc.h @@ -16,7 +16,7 @@ # define LINK_KERNEL(out) $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/out #endif -#define COMPILE_CONVRT(file) $(CCC) _CSPREF $(COMMDIR)/convert.c -o $(COBJDIR)/file._OUTFIX +#define COMPILE_CONVRT(file) $(CCC) _CSPREF $(COMMDIR)/itoa.c -o $(COBJDIR)/file._OUTFIX #define COMPILE_COMMON(file) $(CCC) _CSPREF $(COMMDIR)/file.c -o $(COBJDIR)/file._OUTFIX #define COMPILE_KERNEL(file) $(KCC) _CSPREF $(KERNDIR)/file.c -o $(KOBJDIR)/file._OUTFIX