diff --git a/kernel/acpi/acpi.c b/kernel/acpi/acpi.c index 2bd7b4d..ffd8e4d 100644 --- a/kernel/acpi/acpi.c +++ b/kernel/acpi/acpi.c @@ -4,16 +4,16 @@ #include "acpi.h" #include "../common.h" -#include "../debug/assert.h" -#include "../debug/dump.h" -#include "../klib/sprintf.h" -#include "../klib/string.h" +#include "../lib/assert.h" +#include "../lib/dump.h" +#include "../lib/sprintf.h" +#include "../lib/string.h" #include "acpitables.h" #include "../int/apic.h" #include "../memory/vmap.h" #include "../memory/paging.h" #include "../drivers/pcie.h" -#include "../debug/logging.h" +#include "../lib/logging.h" static void* apic_config_base, *hpet_config_space; diff --git a/kernel/debug/assert.c b/kernel/debug/assert.c deleted file mode 100644 index e7f2af0..0000000 --- a/kernel/debug/assert.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "../klib/sprintf.h" -#include "assert.h" -#include "panic.h" - - -void __assert(const char* __restrict__ expression, - const char* __restrict__ file, - const int line) { - char buffer[1024]; - - sprintf(buffer, "%s:%d: assertion '%s' failed", file, line, expression); - - panic(buffer); -} \ No newline at end of file diff --git a/kernel/debug/assert.h b/kernel/debug/assert.h deleted file mode 100644 index 7d3ed6f..0000000 --- a/kernel/debug/assert.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - - -#ifndef NDEBUG -void __assert(const char* __restrict__ expression, - const char* __restrict__ file, - const int line); - -#define assert(EX) (void)((EX) || (__assert (#EX, __FILE__, __LINE__),0)) - -#define assert_aligned(ADDR, ALIGNMENT) assert(((uint64_t)ADDR & (ALIGNMENT-1)) == 0) -#else -#define assert(EX) -#endif - -#define static_assert(EX) _Static_assert(EX, #EX) - -#define static_assert_equals(EX1,EX2) _Static_assert(EX1==EX2, #EX1 " != " #EX2) - - diff --git a/kernel/debug/dump.c b/kernel/debug/dump.c deleted file mode 100644 index 84b914a..0000000 --- a/kernel/debug/dump.c +++ /dev/null @@ -1,100 +0,0 @@ -#include "dump.h" -#include "../klib/sprintf.h" - -void dump(const void* addr, size_t size, size_t line_size, uint8_t mode) { - - char row_fmt[16], last_row_fmt[16]; - - size_t pitch; // sizeof word - - int i = 0; - row_fmt [i] = '%'; - last_row_fmt[i] = '%'; - i++; - - - // create fmts for printf - -// word width - if((mode & DUMP_8) != 0) { - // byte mode - - row_fmt [i] = '2'; - last_row_fmt[i] = '2'; - i++; - - pitch = 1; - } - else if((mode & DUMP_64) == 0) { - // normal 32bit mode - - row_fmt [i] = '8'; - last_row_fmt[i] = '8'; - i++; - - pitch = 4; - } - else { - // long mode - row_fmt [i] = 'l'; - last_row_fmt[i] = 'l'; - i++; - row_fmt [i] = '1'; - last_row_fmt[i] = '1'; - i++; - row_fmt [i] = '6'; - last_row_fmt[i] = '6'; - i++; - - pitch = 8; - } - -// base - char base_id; - - - if((mode & DUMP_HEX) == 0) // hex - base_id = 'x'; - else // dec - base_id = 'u'; - - row_fmt [i] = base_id; - last_row_fmt[i] = base_id; - i++; - - row_fmt [i] = ' '; - last_row_fmt[i] = '\n'; - i++; - - row_fmt [i] = '\0'; - last_row_fmt[i] = '\0'; - i++; - - - - size /= pitch; - size_t lines = (size + line_size - 1) / line_size; - - // iterator ptr - const uint8_t* ptr = addr; - -// create mask : create the complementary with 0xff...ff << n -// then complement it - const uint64_t mask = ~(~0llu << 8*pitch); - - for(size_t i = 0; i < lines; i++) { - // the last line might not be full - // therefore we have to check each one - - for(size_t j = 0; j < line_size-1; j++) { - if(size-- <= 1) - break; - else { - kprintf(row_fmt, *(uint64_t *)ptr & mask); - ptr+=pitch; - } - } - kprintf(last_row_fmt, *(uint64_t *)ptr & mask); - ptr+=pitch; - } -} diff --git a/kernel/debug/dump.h b/kernel/debug/dump.h deleted file mode 100644 index 96b7de6..0000000 --- a/kernel/debug/dump.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include - - - -#define DUMP_HEX 0 -#define DUMP_DEC 16 - -#define DUMP_8 32 -#define DUMP_32 0 -#define DUMP_64 1 - -#define DUMP_HEX8 (DUMP_HEX | DUMP_8) -#define DUMP_HEX32 (DUMP_HEX | DUMP_32) -#define DUMP_HEX64 (DUMP_HEX | DUMP_64) -#define DUMP_DEC8 (DUMP_DEC | DUMP_8) -#define DUMP_DEC32 (DUMP_DEC | DUMP_32) -#define DUMP_DEC64 (DUMP_DEC | DUMP_64) - - -/** - * dump a memory chunk in kprintf - * addr: address of the beginning of the chunk - * size: number of bytes to dump - * line_size: number of words per line - * - * mode: either - * DUMP_HEX8 : hexadecimal integers of size 8 bits - * DUMP_HEX32 : hexadecimal integers of size 32 bits - * DUMP_HEX64 : hexadecimal integers of size 64 bits - * DUMP_DEC8 : decimal integers of size 8 bits - * DUMP_DEC32 : decimal integers of size 32 bits - * DUMP_DEC64 : decimal integers of size 64 bits - * - **/ -void dump(const void* addr, size_t size, size_t line_size, uint8_t mode); diff --git a/kernel/debug/logging.c b/kernel/debug/logging.c deleted file mode 100644 index 8978969..0000000 --- a/kernel/debug/logging.c +++ /dev/null @@ -1,99 +0,0 @@ -#include - -#include "../klib/sprintf.h" -#include "logging.h" -#include "../video/terminal.h" - -#include "../klib/string.h" - -#define TEXT_COLOR 0xfff0a0 - -#define BUFFER_SIZE 4096 - -static char logs_buffer[BUFFER_SIZE]; -static unsigned current_level; -// current position in the buffer -static int i = 0; - -// appends a string to the buffer -// if there is enough space remaining. -// else, leave it as is -static inline void append_string(const char* str) { - - unsigned len = strlen(str); - if(i+len >= BUFFER_SIZE) - klog_flush(); - memcpy(logs_buffer+i, str, len); - i += len; -} - -static const char* get_level_names_and_set_terminal_color(unsigned level) { - switch(level) { - case LOG_LEVEL_DEBUG: - set_terminal_fgcolor(LOG_DEBUG_COLOR); - return "[DEBUG] "; - case LOG_LEVEL_INFO: - set_terminal_fgcolor(LOG_INFO_COLOR); - return "[INFO] "; - - default:// level > warning -> warning. - case LOG_LEVEL_WARNING: - set_terminal_fgcolor(LOG_WARNIN_COLOR); - return "[WARNING] "; - } -} - -void klog(unsigned level, const char* string) { - if(level < current_level) - return; // avoid overflows - - const char* level_name = get_level_names_and_set_terminal_color(level); - - -// print on the screen -// with fancy colors - kputs(level_name); - set_terminal_fgcolor(TEXT_COLOR); - - kputs(string); - kputs("\n"); - -// append to the buffer - append_string(level_name); - append_string(string); - append_string("\n"); -} - - - -void klogf(unsigned level, const char* fmt, ...) { - if(level < current_level) - return; - - char string[1024]; - -// render string buffer - va_list ap; - va_start(ap, fmt); - vsprintf(string, fmt, ap); - va_end(ap); - - klog(level, string); - -} - -void set_logging_level(unsigned level) { - current_level = level; -} - - -const char* klog_get(void) { - logs_buffer[i] = 0; - return logs_buffer; -} - -void klog_flush(void) { - i = 0; -} - - diff --git a/kernel/debug/logging.h b/kernel/debug/logging.h deleted file mode 100644 index fedb2a8..0000000 --- a/kernel/debug/logging.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - - - -#define NUMARGS(...) (sizeof((int[]){__VA_ARGS__})/sizeof(int)) - - -#define LOG_LEVEL_DEBUG 1 -#define LOG_LEVEL_INFO 2 -#define LOG_LEVEL_WARNING 3 - -#define LOG_DEBUG_COLOR 0x909090 -#define LOG_INFO_COLOR 0xc0c0c0 -#define LOG_WARNIN_COLOR 0xffff00 - - -#ifndef NDEBUG -#define klog_debug(...) klogf(LOG_LEVEL_DEBUG, __VA_ARGS__) -#else -#define klog_debug(...) -#endif - -#define klog_info(...) klogf(LOG_LEVEL_INFO, __VA_ARGS__) -#define klog_warn(...) klogf(LOG_LEVEL_WARN, __VA_ARGS__) - -void klog(unsigned level, const char* string); - -// behaves like kprintf -void klogf(unsigned level, const char* fmt, ...); - -void set_logging_level(unsigned level); - -const char* klog_get(void); - -void klog_flush(void); diff --git a/kernel/debug/panic.c b/kernel/debug/panic.c deleted file mode 100644 index b74b07f..0000000 --- a/kernel/debug/panic.c +++ /dev/null @@ -1,55 +0,0 @@ -#include "panic.h" -#include "../klib/sprintf.h" -#include "../video/terminal.h" - - -int zero = 0; - -#define MAX_STACK_TRACE 15 - -extern uint64_t _rbp(void); - -// always inline: make sure -static inline __attribute__((always_inline)) void stack_trace(void) { - void** ptr = (void**)_rbp(); - kputs("backtrace:\n"); - - for(unsigned i = 0; i < MAX_STACK_TRACE; i++) { - - if(*ptr == 0) // reached the top - break; - kprintf("\t%llx \n", *(ptr+1)); - - ptr = *ptr; - } -} - -__attribute__((noreturn)) void panic(const char* panic_string) { - // checks if video is operationnal - if(get_terminal_handler() != NULL) { - terminal_set_colors(0xfff0a0, 0x400000); - - if(panic_string == NULL) - panic_string = "(null)"; - - kputs( - "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" - "!!!!!!!!!!!!! KERNL PANIC !!!!!!!!!!!!!\n" - "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); - - kputs(panic_string); - kputs("\n\n"); - - stack_trace(); - - kputs( - "\n\n" - "you may manually shutdown the machine.\n" - ); - } - - asm volatile("cli"); - asm volatile("hlt"); - - __builtin_unreachable(); -} \ No newline at end of file diff --git a/kernel/debug/panic.h b/kernel/debug/panic.h deleted file mode 100644 index fc938da..0000000 --- a/kernel/debug/panic.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - - -/** - * panic_string can be NULL - * - * doesn't return: freezes - * dumps the registers and print debug infos - */ -__attribute__((noreturn)) void panic(const char* panic_string); \ No newline at end of file diff --git a/kernel/drivers/hpet.c b/kernel/drivers/hpet.c index 9990a55..544ba10 100644 --- a/kernel/drivers/hpet.c +++ b/kernel/drivers/hpet.c @@ -2,8 +2,8 @@ #include #include "hpet.h" #include "../memory/vmap.h" -#include "../debug/assert.h" -#include "../debug/logging.h" +#include "../lib/assert.h" +#include "../lib/logging.h" /** 000-007h General Capabilities and ID Register Read Only 008-00Fh Reserved diff --git a/kernel/drivers/pcie.c b/kernel/drivers/pcie.c index ae92aae..71c51ea 100644 --- a/kernel/drivers/pcie.c +++ b/kernel/drivers/pcie.c @@ -1,10 +1,10 @@ #include "pcie.h" -#include "../debug/logging.h" -#include "../debug/dump.h" -#include "../debug/assert.h" +#include "../lib/logging.h" +#include "../lib/dump.h" +#include "../lib/assert.h" #include "../memory/kalloc.h" #include "../memory/paging.h" -#include "../klib/string.h" +#include "../lib/string.h" struct PCIE_configuration_space { diff --git a/kernel/entry.c b/kernel/entry.c index 9df0fe9..86fda20 100644 --- a/kernel/entry.c +++ b/kernel/entry.c @@ -5,8 +5,8 @@ #include "memory/gdt.h" #include "video/video.h" #include "video/terminal.h" -#include "klib/sprintf.h" -#include "klib/string.h" +#include "lib/sprintf.h" +#include "lib/string.h" #include "acpi/acpi.h" #include "common.h" #include "registers.h" @@ -19,7 +19,7 @@ #include "memory/paging.h" #include "memory/vmap.h" #include "memory/kalloc.h" -#include "debug/logging.h" +#include "lib/logging.h" #define KERNEL_STACK_SIZE 8192 diff --git a/kernel/int/apic.c b/kernel/int/apic.c index 50e8f00..c709a6a 100644 --- a/kernel/int/apic.c +++ b/kernel/int/apic.c @@ -3,9 +3,9 @@ #include "idt.h" #include "apic.h" -#include "../debug/assert.h" -#include "../debug/logging.h" -#include "../klib/sprintf.h" +#include "../lib/assert.h" +#include "../lib/logging.h" +#include "../lib/sprintf.h" #include "../memory/vmap.h" #include "../drivers/hpet.h" diff --git a/kernel/int/apic.h b/kernel/int/apic.h index e12fca6..0b18f01 100644 --- a/kernel/int/apic.h +++ b/kernel/int/apic.h @@ -2,7 +2,7 @@ #include #include -#include "../debug/assert.h" +#include "../lib/assert.h" #define LAPIC_SPURIOUS_IRQ 0xff diff --git a/kernel/int/idt.h b/kernel/int/idt.h index ea292ad..3164261 100644 --- a/kernel/int/idt.h +++ b/kernel/int/idt.h @@ -3,7 +3,7 @@ #include #include -#include "../debug/assert.h" +#include "../lib/assert.h" #include "../common.h" #define ATTR_64_GATE 0b1110 diff --git a/kernel/int/isr.c b/kernel/int/isr.c index 7b4080b..e246f99 100644 --- a/kernel/int/isr.c +++ b/kernel/int/isr.c @@ -1,6 +1,6 @@ -#include "../klib/sprintf.h" -#include "../debug/assert.h" -#include "../debug/panic.h" +#include "../lib/sprintf.h" +#include "../lib/assert.h" +#include "../lib/panic.h" #include "idt.h" // return the value of cr2 diff --git a/kernel/klib/Makefile b/kernel/klib/Makefile deleted file mode 100644 index 30a727b..0000000 --- a/kernel/klib/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -test: - del -f a.exe - gcc test.c sprintf.c string.c - a.exe \ No newline at end of file diff --git a/kernel/klib/math.h b/kernel/klib/math.h deleted file mode 100644 index a2148c6..0000000 --- a/kernel/klib/math.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#define MIN(X,Y) (X > Y ? Y : X) -#define MAX(X,Y) (X < Y ? Y : X) - -#define CEIL_DIV(X, Y) ((X + Y - 1) / Y) diff --git a/kernel/klib/sprintf.c b/kernel/klib/sprintf.c deleted file mode 100644 index e14b9c2..0000000 --- a/kernel/klib/sprintf.c +++ /dev/null @@ -1,227 +0,0 @@ -#include "sprintf.h" -#include "math.h" -#include "string.h" -#include "../video/terminal.h" - -#define SIGN(X) X > 0 ? 1 : -1 -#define ARG(TYPE) (TYPE)va_arg(ap, TYPE) - -static char* utohex(char* str, uint64_t x, int min_digits) { - size_t digits = 1; - - uint64_t _x = x; - - // _x < 0xf - while(_x & ~0xf) { - _x >>= 4; - digits++; - } - - if((int)digits < min_digits) - digits = min_digits; - - char* end = str+digits; - - char* ptr = end; - - for(int i = digits;i>0;i--) { - int d = x & 0x0f; - if(d < 0xa) - d += '0'; - else - d += 'a'-10; - *(--ptr) = d; - - x >>= 4; - } - - - *end = '\0'; - return end; -} - -// unsigned to string -// return a ptr to the end of the string -static char* utos(char* str, uint64_t x, int min_digits) { - size_t digits = 1; - - uint64_t _x = x; - while(_x > 9) { - _x /= 10; - digits++; - } - - if((int)digits < min_digits) - digits = min_digits; - - char* end = str+digits; - - char* ptr = end; - for(int i = digits;i>0;i--) { - *(--ptr) = '0' + x%10; - - x /= 10; - } - *end = '\0'; - - - return end; -} - -// signed to string -static char* itos(char* str, int64_t x, int min_digits) { - if(x < 0) { - *(str++) = '-'; - x *= -1; - } - - return utos(str, x, min_digits); -} - - -int vsprintf(char *str, const char *format, va_list ap) { - char cf; - int args_put = 0; - int persent = 0; - int digits = -1; - -// bool value: '%l..' - int _long = 0; - - while(1) { - cf = *(format++); - if(cf == '\0') - break; - - if(persent) { - if(cf == '.') - continue; - else if(cf == 'l') { - _long = 1; - continue; - } - - int i = cf - '0'; - if(i >= 0 && i <= 9) { - if(digits < 0) - digits = 0; - digits = 10 * digits + i; - } - else { - switch(cf) { - default: - // invalid - break; - case 'u': - if(!_long) - str = utos(str, ARG(uint32_t), digits); - else - str = utos(str, ARG(uint64_t), digits); - break; - case 'd': - case 'i': - if(!_long) - str = itos(str, ARG(int32_t), digits); - else - str = itos(str, ARG(int64_t), digits); - break; - case 'h': - case 'x': - if(!_long) - str = utohex(str, ARG(uint32_t), digits); - else - str = utohex(str, ARG(uint64_t), digits); - break; - case 's': - { - const char* arg = ARG(const char*); - if(digits >= 0) { - strncpy(str, arg, digits); - if((int) strlen(arg) < digits) - str += strlen(arg); - else - str += digits; - } - else { - strcpy(str, arg); - str += strlen(arg); - } - } - break; - case 'c': - *(str++) = (char)ARG(int); - break; - } - digits = -1; - persent = 0; - _long = 0; - args_put++; - } - } - - else if(cf == '%') { - if(persent) { - // allow %% in fmt to print '%' - persent = 0; - *(str++) = '%'; - } - persent = 1; - } - else { - *(str++) = cf; - } - } - - *str = '\0'; - return args_put; -} - - -int sprintf(char* str, const char* format, ...) { - va_list ap; - int res; - - va_start(ap, format); - res = vsprintf(str,format,ap); - va_end(ap); - - return res; -} -// -//int vsnprintf(char *str, size_t size, const char *format, va_list ap) { -// -// -//} - -void kputs(const char* s) { - terminal_handler_t print_fun = get_terminal_handler(); - - if(print_fun) - print_fun(s, strlen(s)); -} - -int kprintf(const char* format, ...) { - va_list ap; - int ret; - - va_start(ap, format); - - ret = vkprintf(format, ap); - - - va_end(ap); - - return ret; -} - -int vkprintf(const char* format, va_list ap) { - terminal_handler_t print_fun = get_terminal_handler(); - - char buf[1024]; - - int ret = vsprintf(buf, format, ap); - - print_fun(buf, strlen(buf)); - - return ret; -} diff --git a/kernel/klib/sprintf.h b/kernel/klib/sprintf.h deleted file mode 100644 index a16ec08..0000000 --- a/kernel/klib/sprintf.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef SPRINTF_H -#define SPRINTF_H - - -#include -#include -#include - - -int sprintf(char *str, const char *format, ...); -int snprintf(char *str, size_t size, const char *format, ...); -int vsprintf(char *str, const char *format, va_list ap); -int vsnprintf(char *str, size_t size, const char *format, va_list ap); - -int vkprintf(const char* format, va_list ap); -int kprintf(const char* format, ...); - -void kputs(const char* s); - -#endif diff --git a/kernel/klib/string.c b/kernel/klib/string.c deleted file mode 100644 index bb8745f..0000000 --- a/kernel/klib/string.c +++ /dev/null @@ -1,273 +0,0 @@ -#include "string.h" - - -size_t strlen(const char* str) { - const char* ptr = str; - - int len = 0; - - while(*(ptr++) != '\0') - len++; - - return len; -} - - -size_t strnlen(const char* str, size_t n) { - int len = 0; - - while(*(str++) != '\0' && n--) - len++; - - return len; -} - -char* strcpy(char* dst, const char* src) { - char c; - char* pdst = dst; - - do { - c = *(src++); - - *(pdst++) = c; - } - while(c != '\0'); - - return dst; -} - -char* strncpy(char* dst, const char* src, size_t n) { - char c; - char* pdst = dst; - - do { - c = *(src++); - - *(pdst++) = c; - - n--; - } - while(c != '\0' && n > 0); - - if(c != '\0') - *pdst = '\0'; - dst = '\0'; - return dst; -} - - -int strcmp(const char* str1, const char* str2) { - int d; - - while(1) { - char c1 = *(str1++); - char c2 = *(str2++); - - d = c1-c2; - - if(!c1 || !c2 || d) - break; - } - - return d; -} - -int strncmp(const char* str1, const char* str2, size_t n) { - int d; - - while(n-- > 0) { - char c1 = *(str1++); - char c2 = *(str2++); - - d = c1-c2; - - if(!c1 || !c2 || d) - break; - } - - return d; -} - - -const char* strchr (const char *_s, int c) { - const char* s=_s; - char curr; - - while(1) { - curr = *s; - - if(curr == c) - return s; - else if(curr == '\0') - break; - - s++; - } - - return NULL; -} - - -const char* strrchr(const char *s, int c) { - char curr; - - const char* found = NULL; - - while(1) { - curr = *s; - - if(curr == c) - found = s; - else if(curr == '\0') - break; - - s++; - } - - return found; -} - - -const char *strstr(const char *haystack, const char *needle) { - - int i = 0; - char c, ci; - - while(1) { - - ci = needle[i]; - - if(ci == '\0') - return haystack - i - 1; - - - c = *(haystack++); - - if(c == ci) - i++; - else if(c == '\0') - return NULL; - else - i = 0; - } -} - - -char* strcat(char *dest, const char *src) { - while(*(dest++)) ; - - return strcpy(dest, src); -} - -char *strncat(char *dest, const char *src, size_t n) { - char* ret = dest; - - while(*(dest++)) ; - strncpy(--dest, src, n); - - return ret; -} - - -void * memccpy (void* dst, const void *src, int c, size_t n) { - - - for(; n > 0; n--) { - char d = *(char*)(src++) = *(char*)(dst++); - - if(d == c) - return dst; - } - - return NULL; -} - -const void* memchr (const void *_buf, int _ch, size_t n) { - uint8_t ch = *(uint8_t*)(&_ch); - const uint8_t* buf=_buf; - - for(;n > 0; n--) { - if(*buf == ch) - return buf; - buf++; - } - return NULL; -} - -int memcmp (const void* _buf1, const void* _buf2, size_t n) { - const uint8_t* buf1=_buf1; - const uint8_t* buf2=_buf2; - - for(; n > 0; n--) { - int d = *(buf1++) - *(buf2++); - - if(d != 0) - return d; - } - - return 0; -} - - -void * memcpy (void* restrict _dest, - const void* restrict _src, size_t n) { - const uint8_t* src=_src; - uint8_t* dest=_dest; - - for(;n > 0; --n) - *(dest++) = *(src++); - - return dest; -} - -void * memset (void * _buf, int _ch, size_t n) { - uint8_t ch = *(uint8_t*)(&_ch); - uint8_t* buf = _buf; - - // first unaligned bytes - for(;n > 0 && (uint64_t)buf % 8 != 0; --n) - *(buf++) = ch; - - - if(!n) return buf; - - if(n >= 8) { - uint64_t ch64 = ch | (ch << 8); - ch64 = ch64 | (ch64 << 16); - ch64 = ch64 | (ch64 << 32); - - for(;n > 0; n -= 8) { - *(uint64_t*)buf = ch64; - buf += 8; - } - } - - // last unaligned bytes - for(;n > 0 && (uint64_t)buf % 8 != 0; --n) - *(buf++) = ch; - - return buf; -} - - -void * memmove (void* _dest, const void* _src, size_t n) { - uint8_t* dest=_dest; - const uint8_t* src=_src; - - // check for overlapping - if(src < dest && src + n > dest) { - dest += n; - src += n; - - - // backward copy - for(;n > 0; --n) - *(--dest) = *(--src); - - return _dest; - } - // not overlapping: just call memcpy - else { - return memcpy(dest, src, n); - } -} diff --git a/kernel/klib/string.h b/kernel/klib/string.h deleted file mode 100644 index 6965050..0000000 --- a/kernel/klib/string.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef KSTRING_H -#define KSTRING_H - -#include -#include - - -#ifndef __ATTR_PURE__ -#define __ATTR_PURE__ __attribute__((__pure__)) -#endif - - -void * memccpy (void * __restrict__, const void * __restrict__, int, size_t); -const void * memchr (const void *, int, size_t) __ATTR_PURE__; -int memcmp (const void *, const void *, size_t) __ATTR_PURE__; -void * memcpy (void * __restrict__, const void * __restrict__, size_t); -void * memset (void *, int, size_t); -//void * memmem (const void *, size_t, const void *, size_t) __ATTR_PURE__; -void * memmove (void *, const void *, size_t); -//void * memrchr (const void *, int, size_t) __ATTR_PURE__; - - - -size_t strlen (const char* str) __ATTR_PURE__; -size_t strnlen(const char* str, size_t n) __ATTR_PURE__; -int strcmp (const char* str1, const char* str2) __ATTR_PURE__; -int strncmp(const char* str1, const char* str2, size_t n) __ATTR_PURE__; -const char* strchr (const char *s, int c) __ATTR_PURE__; -const char* strrchr(const char *s, int c) __ATTR_PURE__; -const char* strstr(const char *haystack, const char *needle) __ATTR_PURE__; - - -char* strcpy (char* __restrict__ dst, const char* __restrict__ src); -char* strncpy(char* __restrict__ dst, const char* __restrict__ src, size_t n); -char* strcat(char * __restrict__ dest, const char * __restrict__ src); -char* strncat(char * __restrict__ dest, const char * __restrict__ src, size_t n); - - - - -#endif//KSTRING_H \ No newline at end of file diff --git a/kernel/memory/gdt.c b/kernel/memory/gdt.c index 1161f1f..a187258 100644 --- a/kernel/memory/gdt.c +++ b/kernel/memory/gdt.c @@ -1,7 +1,7 @@ #include "gdt.h" #include "../common.h" -#include "../klib/sprintf.h" -#include "../debug/assert.h" +#include "../lib/sprintf.h" +#include "../lib/assert.h" extern void _ltr(uint16_t tss_selector); diff --git a/kernel/memory/kalloc.c b/kernel/memory/kalloc.c index 6d036a1..1a3ab69 100644 --- a/kernel/memory/kalloc.c +++ b/kernel/memory/kalloc.c @@ -2,11 +2,11 @@ #include #include "kalloc.h" -#include "../klib/sprintf.h" +#include "../lib/sprintf.h" #include "../memory/vmap.h" #include "../memory/paging.h" -#include "../debug/logging.h" -#include "../debug/assert.h" +#include "../lib/logging.h" +#include "../lib/assert.h" #define MIN_EXPAND_SIZE 1024 diff --git a/kernel/memory/paging.c b/kernel/memory/paging.c index 72485de..48d9760 100644 --- a/kernel/memory/paging.c +++ b/kernel/memory/paging.c @@ -1,13 +1,13 @@ #include -#include "../debug/assert.h" -#include "../klib/string.h" +#include "../lib/assert.h" +#include "../lib/string.h" #include "physical_allocator.h" #include "paging.h" #include "vmap.h" -#include "../klib/sprintf.h" -#include "../debug/panic.h" -#include "../debug/logging.h" +#include "../lib/sprintf.h" +#include "../lib/panic.h" +#include "../lib/logging.h" #include "../registers.h" diff --git a/kernel/memory/physical_allocator.c b/kernel/memory/physical_allocator.c index 2bc707d..252fd62 100644 --- a/kernel/memory/physical_allocator.c +++ b/kernel/memory/physical_allocator.c @@ -3,12 +3,12 @@ #include #include -#include "../klib/string.h" -#include "../klib/sprintf.h" -#include "../debug/assert.h" -#include "../debug/panic.h" +#include "../lib/string.h" +#include "../lib/sprintf.h" +#include "../lib/assert.h" +#include "../lib/panic.h" #include "physical_allocator.h" -#include "../debug/logging.h" +#include "../lib/logging.h" #include "vmap.h" /** diff --git a/kernel/video/terminal.c b/kernel/video/terminal.c index 2b3bdf8..7e38b4c 100644 --- a/kernel/video/terminal.c +++ b/kernel/video/terminal.c @@ -2,9 +2,9 @@ #include #include "terminal.h" #include "video.h" -#include "../klib/string.h" -#include "../debug/assert.h" -#include "../debug/logging.h" +#include "../lib/string.h" +#include "../lib/assert.h" +#include "../lib/logging.h" #include "../memory/kalloc.h" #define TAB_SPACE 6 diff --git a/kernel/video/terminal.h b/kernel/video/terminal.h index 16595d9..5ac573f 100644 --- a/kernel/video/terminal.h +++ b/kernel/video/terminal.h @@ -2,7 +2,7 @@ #include #include -#include "../debug/assert.h" +#include "../lib/assert.h" #define TERMINAL_CHARMAP_W 6 diff --git a/kernel/video/video.c b/kernel/video/video.c index 2550e01..4585737 100644 --- a/kernel/video/video.c +++ b/kernel/video/video.c @@ -3,11 +3,11 @@ // for initialization #include -#include "../klib/string.h" -#include "../debug/logging.h" +#include "../lib/string.h" +#include "../lib/logging.h" //#include "../memory/kalloc.h" #include "../common.h" -#include "../debug/assert.h" +#include "../lib/assert.h" #include "video.h" #include "terminal.h"