sdk: Add sdk string functions
Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
@@ -3,8 +3,14 @@
|
|||||||
# Provided under the BSD-3 clause
|
# Provided under the BSD-3 clause
|
||||||
#
|
#
|
||||||
|
|
||||||
|
include mk/default.mk
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: m1x
|
all: sdk m1x
|
||||||
|
|
||||||
|
.PHONY: sdk
|
||||||
|
sdk:
|
||||||
|
cd sdk/; make $(PASSDOWN_ARGS)
|
||||||
|
|
||||||
.PHONY: m1x
|
.PHONY: m1x
|
||||||
m1x:
|
m1x:
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
MISC_OFILES = $(shell find ../../ -name "*.o")
|
MISC_OFILES = $(shell find ../../ -name "*.o")
|
||||||
|
SDK_OFILES = $(shell find ../../../sdk/ -name "*.o")
|
||||||
|
|
||||||
ASMFILES = $(shell find . -name "*.S" | grep -v "boot")
|
ASMFILES = $(shell find . -name "*.S" | grep -v "boot")
|
||||||
ASMOFILES = $(ASMFILES:.S=.S.o)
|
ASMOFILES = $(ASMFILES:.S=.S.o)
|
||||||
@@ -24,7 +25,7 @@ CFLAGS = \
|
|||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: $(OFILES) $(ASMOFILES)
|
all: $(OFILES) $(ASMOFILES)
|
||||||
$(LD) $(MISC_OFILES) -Tconf/link.ld -o $(KERN_BIN) $(LDFLAGS)
|
$(LD) $(MISC_OFILES) $(SDK_OFILES) -Tconf/link.ld -o $(KERN_BIN) $(LDFLAGS)
|
||||||
|
|
||||||
%.S.o: %.S
|
%.S.o: %.S
|
||||||
$(CC) -c $< $(CFLAGS) -o $@
|
$(CC) -c $< $(CFLAGS) -o $@
|
||||||
|
|||||||
18
src/sdk/Makefile
Normal file
18
src/sdk/Makefile
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#
|
||||||
|
# Copyright (c) 2026, Mirocom Laboratories
|
||||||
|
# Provided under the BSD-3 clause
|
||||||
|
#
|
||||||
|
|
||||||
|
CFILES = $(shell find . -name "*.c")
|
||||||
|
OFILES = $(CFILES:.c=.o)
|
||||||
|
CC = ../$(SYS_CC)
|
||||||
|
|
||||||
|
CFLAGS = \
|
||||||
|
$(SYS_CFLAGS) \
|
||||||
|
-Iinclude/
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: $(OFILES)
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
43
src/sdk/include/string.h
Normal file
43
src/sdk/include/string.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026, Mirocom Laboratories
|
||||||
|
* Provided under the BSD-3 clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SDK_STRING_H_
|
||||||
|
#define _SDK_STRING_H_ 1
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Obtain the length of a string in bytes excluding the NULL
|
||||||
|
* terminating character.
|
||||||
|
*
|
||||||
|
* @s: String to obtain length from
|
||||||
|
*
|
||||||
|
* Return values of zero indicate error
|
||||||
|
*/
|
||||||
|
size_t strlen(const char *s);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copy memory from `src` to `dest`
|
||||||
|
*
|
||||||
|
* @dest: Destination buffer
|
||||||
|
* @src: Source buffer
|
||||||
|
* @count: Number of bytes to copy
|
||||||
|
*
|
||||||
|
* Returns `dest' on success
|
||||||
|
*/
|
||||||
|
void *memcpy(void *dest, const void *src, size_t count);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fill a buffer `s` with `n` bytes of `c`
|
||||||
|
*
|
||||||
|
* @s: Buffer to fill
|
||||||
|
* @c: Data to fill with
|
||||||
|
* @n: Number of bytes to fill
|
||||||
|
*
|
||||||
|
* Returns `s` on success
|
||||||
|
*/
|
||||||
|
void *memset(void *s, int c, size_t n);
|
||||||
|
|
||||||
|
#endif /* !_SDK_STRING_H_ */
|
||||||
21
src/sdk/string/memcpy.c
Normal file
21
src/sdk/string/memcpy.c
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026, Mirocom Laboratories
|
||||||
|
* Provided under the BSD-3 clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _M1X_SOURCE
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
21
src/sdk/string/memset.c
Normal file
21
src/sdk/string/memset.c
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026, Mirocom Laboratories
|
||||||
|
* Provided under the BSD-3 clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _M1X_SOURCE
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
20
src/sdk/string/strlen.c
Normal file
20
src/sdk/string/strlen.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026, Mirocom Laboratories
|
||||||
|
* Provided under the BSD-3 clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _M1X_SOURCE
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
size_t
|
||||||
|
strlen(const char *s)
|
||||||
|
{
|
||||||
|
size_t length = 0;
|
||||||
|
const char *p = s;
|
||||||
|
|
||||||
|
while ((*p++) != '\0') {
|
||||||
|
++length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return length;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user