From 053f93edecf6aa02ec29366621adf2de6522cdf3 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 26 Nov 2024 22:38:35 +0100 Subject: Move string.S to the lib directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was weird enough to have it in the 'kernel' directory, as it's way more fitting to have it on 'lib'. Signed-off-by: Miquel Sabaté Solà --- Makefile | 2 +- kernel/string.S | 97 --------------------------------------------------------- lib/string.S | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 98 deletions(-) delete mode 100644 kernel/string.S create mode 100644 lib/string.S diff --git a/Makefile b/Makefile index a408630..60feb98 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ endif ## # Paths -SRC = $(filter-out kernel/fbos.ld.S, $(wildcard kernel/*.S kernel/*.c lib/*.c)) +SRC = $(filter-out kernel/fbos.ld.S, $(wildcard kernel/*.S kernel/*.c lib/*.c lib/*.S)) OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(SRC))) LINKER = kernel/fbos.ld KRNL = fbos diff --git a/kernel/string.S b/kernel/string.S deleted file mode 100644 index 271e8f3..0000000 --- a/kernel/string.S +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Defined in include/fbos/string.h - * - * size_t strlen(const char *str) - * - * Returns (a0): string length. - * Parameter (a0): string to measure. - * Clobbers: t0, t1. - */ -.globl strlen -.type strlen, @function -strlen: - mv t1, a0 -1: - lbu t0, 0(t1) - beqz t0, 2f - addi t1, t1, 1 - j 1b -2: - sub a0, t1, a0 - ret - -/* - * Defined in include/fbos/string.h - * - * int strcmp(const char *s1, const char *s2) - * - * Returns (a0): comparison result as in stdlib. - * Parameter (a0, a1): strings to compare. - * Clobbers: t0, t1. - */ -.globl strcmp -.type strcmp, @function -strcmp: -1: - lbu t0, 0(a0) - lbu t1, 0(a1) - addi a0, a0, 1 - addi a1, a1, 1 - bne t0, t1, 2f - bnez t0, 1b - li a0, 0 - ret -2: - sub a0, t0, t1 - ret - -/* - * Defined in include/fbos/string.h - * - * int memcmp(const void *ptr1, const void *ptr2, size_t n) - * - * Returns (a0): comparison result as in stdlib. - * Parameters (a0, a1): strings to compare. - * Clobbers: t0, t1. - */ -.global memcmp -.type memcmp, @function -memcmp: -1: - lbu t0, 0(a0) - lbu t1, 0(a1) - bne t0, t1, 2f - addi a0, a0, 1 - addi a1, a1, 1 - addi a2, a2, -1 - bnez a2, 1b - li a0, 0 - ret -2: - sub a0, t0, t1 - ret - -/* - * Defined in include/fbos/string.h - * - * void memcpy(const void *dest, const void *src, size_t count) - * - * Parameter a0: destination string. - * Parameter a1: source string. - * Parameter a2: number of bytes to copy. - * Clobbers: t0. - */ -.global memcpy -.type memcpy, @function -memcpy: -1: - beqz a2, 3f -2: - lbu t0, 0(a1) - sb t0, 0(a0) - addi a0, a0, 1 - addi a1, a1, 1 - addi a2, a2, -1 - bnez a2, 2b -3: - ret diff --git a/lib/string.S b/lib/string.S new file mode 100644 index 0000000..271e8f3 --- /dev/null +++ b/lib/string.S @@ -0,0 +1,97 @@ +/* + * Defined in include/fbos/string.h + * + * size_t strlen(const char *str) + * + * Returns (a0): string length. + * Parameter (a0): string to measure. + * Clobbers: t0, t1. + */ +.globl strlen +.type strlen, @function +strlen: + mv t1, a0 +1: + lbu t0, 0(t1) + beqz t0, 2f + addi t1, t1, 1 + j 1b +2: + sub a0, t1, a0 + ret + +/* + * Defined in include/fbos/string.h + * + * int strcmp(const char *s1, const char *s2) + * + * Returns (a0): comparison result as in stdlib. + * Parameter (a0, a1): strings to compare. + * Clobbers: t0, t1. + */ +.globl strcmp +.type strcmp, @function +strcmp: +1: + lbu t0, 0(a0) + lbu t1, 0(a1) + addi a0, a0, 1 + addi a1, a1, 1 + bne t0, t1, 2f + bnez t0, 1b + li a0, 0 + ret +2: + sub a0, t0, t1 + ret + +/* + * Defined in include/fbos/string.h + * + * int memcmp(const void *ptr1, const void *ptr2, size_t n) + * + * Returns (a0): comparison result as in stdlib. + * Parameters (a0, a1): strings to compare. + * Clobbers: t0, t1. + */ +.global memcmp +.type memcmp, @function +memcmp: +1: + lbu t0, 0(a0) + lbu t1, 0(a1) + bne t0, t1, 2f + addi a0, a0, 1 + addi a1, a1, 1 + addi a2, a2, -1 + bnez a2, 1b + li a0, 0 + ret +2: + sub a0, t0, t1 + ret + +/* + * Defined in include/fbos/string.h + * + * void memcpy(const void *dest, const void *src, size_t count) + * + * Parameter a0: destination string. + * Parameter a1: source string. + * Parameter a2: number of bytes to copy. + * Clobbers: t0. + */ +.global memcpy +.type memcpy, @function +memcpy: +1: + beqz a2, 3f +2: + lbu t0, 0(a1) + sb t0, 0(a0) + addi a0, a0, 1 + addi a1, a1, 1 + addi a2, a2, -1 + bnez a2, 2b +3: + ret -- cgit v1.2.3