From: Matthias Kruk Date: Tue, 19 Nov 2019 06:55:01 +0000 (+0900) Subject: Use standard C functions from klibc within the kernel X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=d16e164c3c4454afbc5383aa8420fd1611ed81d5;p=corax Use standard C functions from klibc within the kernel --- diff --git a/include/string.h b/include/string.h new file mode 100644 index 0000000..9697603 --- /dev/null +++ b/include/string.h @@ -0,0 +1,10 @@ +#ifndef _STRING_H +#define _STRING_H + +#include + +void* memset(void *dst, int val, u32_t n); +void* memcpy(void *dst, const void *src, u32_t n); +size_t strlen(const char*); + +#endif /* _STRING_H */ diff --git a/kernel/Makefile b/kernel/Makefile index a5c7548..2d37c04 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,5 +1,5 @@ -OBJECTS = arch/arch.o core/core.o -DEPS = arch core +OBJECTS = arch/arch.o core/core.o klibc/klibc.a +DEPS = arch core klibc LDFLAGS = --oformat=elf32-i386 -b elf32-i386 -m elf_i386 CFLAGS = -m32 -Wall -nostdlib -nodefaultlibs -nostartfiles -ffreestanding PHONY = $(DEPS) clean diff --git a/kernel/arch/debug.c b/kernel/arch/debug.c index 3793a3c..5775006 100644 --- a/kernel/arch/debug.c +++ b/kernel/arch/debug.c @@ -18,6 +18,7 @@ #include #include +#include #define ABS(x) (((x) < 0) ? (-(x)) : (x)) @@ -140,30 +141,6 @@ u64_t _u64mod(u64_t dividend, u64_t divisor) return(dividend); } -void* memset(void *dst, int val, u32_t n) -{ - char *ptr; - - ptr = dst; - while(n--) { - *ptr++ = val; - } - return(dst); -} - -void* memcpy(void *dst, const void *src, u32_t n) -{ - char *d; - const char *s; - - d = dst; - s = src; - while(n--) { - *d++ = *s++; - } - return(dst); -} - static void _putchar(int c) { if(c == '\n') { diff --git a/kernel/arch/heap.c b/kernel/arch/heap.c index bc73405..0a85534 100644 --- a/kernel/arch/heap.c +++ b/kernel/arch/heap.c @@ -18,6 +18,7 @@ #include #include +#include #include "paging.h" #include "heap.h" diff --git a/kernel/arch/paging.c b/kernel/arch/paging.c index 038eb19..645ea68 100644 --- a/kernel/arch/paging.c +++ b/kernel/arch/paging.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "cpu.h" #include "paging.h" #include "heap.h" diff --git a/kernel/core/process.c b/kernel/core/process.c index 0d960a6..09b40d9 100644 --- a/kernel/core/process.c +++ b/kernel/core/process.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "fd.h" #include "sched.h" diff --git a/kernel/include/debug.h b/kernel/include/debug.h index af816c1..d642963 100644 --- a/kernel/include/debug.h +++ b/kernel/include/debug.h @@ -28,9 +28,6 @@ i64_t _i64mod(i64_t, i64_t); #define PANIC(msg) dbg_panic(__func__, __FILE__, __LINE__, msg) -void* memset(void *dst, int val, u32_t n); -void* memcpy(void *dst, const void *src, u32_t n); - int dbg_printf(const char*, ...); void dbg_panic(const char*, const char*, i32_t, const char*);