From 95031d592a25d3016780f35ab302b33c342d0f65 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 16 Apr 2026 22:19:20 -0400 Subject: [PATCH] lib: Add libstr library Signed-off-by: Ian Moffett --- usr/src/Makefile | 6 +++++- usr/src/lib/Makefile | 19 +++++++++++++++++++ usr/src/lib/libstr/Makefile | 22 ++++++++++++++++++++++ usr/src/lib/libstr/memcmp.c | 27 +++++++++++++++++++++++++++ usr/src/lib/libstr/memcpy.c | 26 ++++++++++++++++++++++++++ usr/src/lib/libstr/memset.c | 26 ++++++++++++++++++++++++++ usr/src/sp1/amd64/Makefile | 6 ++++-- 7 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 usr/src/lib/Makefile create mode 100644 usr/src/lib/libstr/Makefile create mode 100644 usr/src/lib/libstr/memcmp.c create mode 100644 usr/src/lib/libstr/memcpy.c create mode 100644 usr/src/lib/libstr/memset.c diff --git a/usr/src/Makefile b/usr/src/Makefile index 2698de2..8d0243c 100644 --- a/usr/src/Makefile +++ b/usr/src/Makefile @@ -12,7 +12,11 @@ include mk/sys.mk .PHONY: all -all: sp1 boot +all: lib sp1 boot + +.PHONY: lib +lib: + cd lib/; $(MAKE) .PHONY: boot boot: diff --git a/usr/src/lib/Makefile b/usr/src/lib/Makefile new file mode 100644 index 0000000..ff6aecb --- /dev/null +++ b/usr/src/lib/Makefile @@ -0,0 +1,19 @@ +# +# Copyright (c) 2026, Mirocom Laboratories +# All rights reserved. +# +# The following sources are CONFIDENTIAL and PROPRIETARY +# property of Mirocom Laboratories. Unauthorized copying, +# use, distrubution or modification of this file, in whole +# and in part, is strictly prohibited without the prior written +# consent from Mirocom Laboratories. +# + +include ../mk/sys.mk + +.PHONY: all +all: libstr + +.PHONY: libstr +libstr: + cd libstr/; $(MAKE) $(PASSDOWN_ARGS) diff --git a/usr/src/lib/libstr/Makefile b/usr/src/lib/libstr/Makefile new file mode 100644 index 0000000..35c0e41 --- /dev/null +++ b/usr/src/lib/libstr/Makefile @@ -0,0 +1,22 @@ +# +# Copyright (c) 2026, Mirocom Laboratories +# All rights reserved. +# +# The following sources are CONFIDENTIAL and PROPRIETARY +# property of Mirocom Laboratories. Unauthorized copying, +# use, distrubution or modification of this file, in whole +# and in part, is strictly prohibited without the prior written +# consent from Mirocom Laboratories. +# + +CFILES = $(shell find . -name "*.c") +OFILES = $(CFILES:.c=.o) + +CC = ../../../../$(SYS_CC) +CFLAGS = $(SYS_CFLAGS) -I../../head -D_SP1_SOURCE + +.PHONY: all +all: $(OFILES) + +%.o: %.c + $(CC) -c $< $(CFLAGS) -o $@ diff --git a/usr/src/lib/libstr/memcmp.c b/usr/src/lib/libstr/memcmp.c new file mode 100644 index 0000000..2ce4144 --- /dev/null +++ b/usr/src/lib/libstr/memcmp.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2026, Mirocom Laboratories + * All rights reserved. + * + * The following sources are CONFIDENTIAL and PROPRIETARY + * property of Mirocom Laboratories. Unauthorized copying, + * use, distribution or modification of this file, in whole + * and in part, is strictly prohibited without the prior written + * consent from Mirocom Laboratories. + */ + +#include + +int +memcmp(const void *s1, const void *s2, __size_t n) +{ + if (n != 0) { + const unsigned char *p1 = s1, *p2 = s2; + + do { + if (*p1++ != *p2++) { + return (*--p1 - *--p2); + } + } while (--n != 0); + } + return 0; +} diff --git a/usr/src/lib/libstr/memcpy.c b/usr/src/lib/libstr/memcpy.c new file mode 100644 index 0000000..4f0fa18 --- /dev/null +++ b/usr/src/lib/libstr/memcpy.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2026, Mirocom Laboratories + * All rights reserved. + * + * The following sources are CONFIDENTIAL and PROPRIETARY + * property of Mirocom Laboratories. Unauthorized copying, + * use, distribution or modification of this file, in whole + * and in part, is strictly prohibited without the prior written + * consent from Mirocom Laboratories. + */ + +#include + +void * +memcpy(void *dest, const void *src, size_t count) +{ + if (dest == NULL || src == NULL) { + return NULL; + } + + for (size_t i = 0; i < count; ++i) { + ((char *)dest)[i] = ((char *)src)[i]; + } + + return dest; +} diff --git a/usr/src/lib/libstr/memset.c b/usr/src/lib/libstr/memset.c new file mode 100644 index 0000000..61d18c0 --- /dev/null +++ b/usr/src/lib/libstr/memset.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2026, Mirocom Laboratories + * All rights reserved. + * + * The following sources are CONFIDENTIAL and PROPRIETARY + * property of Mirocom Laboratories. Unauthorized copying, + * use, distribution or modification of this file, in whole + * and in part, is strictly prohibited without the prior written + * consent from Mirocom Laboratories. + */ + +#include + +void * +memset(void *s, int c, size_t n) +{ + if (s == NULL) { + return NULL; + } + + for (size_t i = 0; i < n; ++i) { + ((uint8_t *)s)[i] = c; + } + + return s; +} diff --git a/usr/src/sp1/amd64/Makefile b/usr/src/sp1/amd64/Makefile index b6103a4..9aaf090 100644 --- a/usr/src/sp1/amd64/Makefile +++ b/usr/src/sp1/amd64/Makefile @@ -11,7 +11,9 @@ ASMFILES = $(shell find . -name "*.S") ASMOFILES = $(ASMFILES:.S=.S.o) -MISC_OFILES = $(shell find ../common -name "*.o") + +MISC_OFILES = $(shell find ../ -name "*.o") +LIB_OFILES = $(shell find ../../lib/ -name "*.o") CC = \ ../../../../$(SYS_CC) @@ -27,7 +29,7 @@ all: $(ASMOFILES) $(LD) \ -Tconf/link.ld \ $(MISC_OFILES) \ - $(ASMOFILES) \ + $(LIB_OFILES) \ -o ../../../../sp1.sys %.S.o: %.S