Browse Source

feat(gblibc): separate libc from kernel code

greatbridf 2 years ago
parent
commit
d44046d21c

+ 5 - 6
CMakeLists.txt

@@ -5,8 +5,6 @@ set(CMAKE_ASM_FLAGS "-m32")
 
 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
 
-include_directories(${PROJECT_SOURCE_DIR}/include)
-
 set(EXTRACT_DIR ${PROJECT_BINARY_DIR}/extract)
 file(MAKE_DIRECTORY ${EXTRACT_DIR})
 
@@ -54,7 +52,6 @@ set(KERNEL_MAIN_SOURCES src/fs/fat.cpp
                         src/kernel/interrupt.cpp
                         src/kernel/process.cpp
                         src/kernel/tty.cpp
-                        src/kernel/stdio.cpp
                         src/kernel/syscall.cpp
                         src/kernel/mem.cpp
                         src/kernel/vfs.cpp
@@ -77,7 +74,6 @@ set(KERNEL_MAIN_SOURCES src/fs/fat.cpp
                         include/kernel/tty.hpp
                         include/kernel/interrupt.h
                         include/kernel/process.hpp
-                        include/kernel/stdio.hpp
                         include/kernel/syscall.hpp
                         include/kernel/mem.h
                         include/kernel/mm.hpp
@@ -100,7 +96,6 @@ set(KERNEL_MAIN_SOURCES src/fs/fat.cpp
                         include/types/types.h
                         include/types/size.h
                         include/types/status.h
-                        include/types/stdint.h
                         include/types/allocator.hpp
                         include/types/cplusplus.hpp
                         include/types/list.hpp
@@ -108,9 +103,13 @@ set(KERNEL_MAIN_SOURCES src/fs/fat.cpp
                         include/types/string.hpp
                         include/types/vector.hpp
                         include/types/function.hpp
+                        include/kernel/log.hpp
                         include/kernel_main.hpp
                         )
 add_library(kernel_main STATIC ${KERNEL_MAIN_SOURCES})
+target_link_libraries(kernel_main gblibc)
+target_include_directories(kernel_main PRIVATE ${PROJECT_SOURCE_DIR}/include)
+add_subdirectory(gblibc)
 
 add_custom_command(OUTPUT extracted_kernel_main
     DEPENDS kernel_main
@@ -128,7 +127,7 @@ add_custom_target(kernel.out
     DEPENDS user_space_programs
     DEPENDS ${CMAKE_SOURCE_DIR}/src/kernel.ld
     COMMAND ${CMAKE_LINKER} -T ${CMAKE_SOURCE_DIR}/src/kernel.ld ${EXTRACT_DIR}/*.o
-    -melf_i386 -o ${CMAKE_BINARY_DIR}/kernel.out
+    -melf_i386 -o ${CMAKE_BINARY_DIR}/kernel.out -lgblibc -L${CMAKE_BINARY_DIR}/gblibc
 )
 
 add_custom_target(mbr_hole.bin

+ 16 - 0
gblibc/CMakeLists.txt

@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.15)
+project(gblibc)
+
+add_library(gblibc STATIC
+    src/stdio.c
+    src/arithmetic.c
+    src/string.c
+)
+
+target_include_directories(gblibc PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
+                                  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include)
+
+set_target_properties(gblibc PROPERTIES PRIVATE_HEADER
+    "private-include/devutil.h")
+set_target_properties(gblibc PROPERTIES PUBLIC_HEADER
+    "include/stdio.h,include/stdint.h,include/stdarg.h,include/string.h")

+ 11 - 0
gblibc/include/stdarg.h

@@ -0,0 +1,11 @@
+#ifndef __GBLIBC_STDARG_H_
+#define __GBLIBC_STDARG_H_
+
+typedef __builtin_va_list va_list;
+
+#define va_start(v, l) __builtin_va_start(v, l)
+#define va_arg(v, l) __builtin_va_arg(v, l)
+#define va_end(v) __builtin_va_end(v)
+#define va_copy(v, l) __builtin_va_copy(v, l)
+
+#endif

+ 7 - 3
include/types/stdint.h → gblibc/include/stdint.h

@@ -1,5 +1,7 @@
-#pragma once
+#ifndef __GBLIBC_STDINT_H_
+#define __GBLIBC_STDINT_H_
 
+#undef NULL
 #ifdef __cplusplus
 #define NULL (nullptr)
 #else
@@ -19,5 +21,7 @@ typedef __UINT64_TYPE__ uint64_t;
 typedef __SIZE_TYPE__ size_t;
 typedef int32_t ssize_t;
 
-typedef uint32_t time_t;
-typedef int32_t time_diff_t;
+typedef size_t time_t;
+typedef ssize_t time_diff_t;
+
+#endif

+ 19 - 0
gblibc/include/stdio.h

@@ -0,0 +1,19 @@
+#ifndef __GBLIBC_STDIO_H_
+#define __GBLIBC_STDIO_H_
+
+#include <stdint.h>
+
+#undef EOF
+#define EOF (-1)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int snprintf(char* buf, size_t bufsize, const char* fmt, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 10 - 23
include/kernel/stdio.hpp → gblibc/include/string.h

@@ -1,14 +1,12 @@
-#pragma once
+#ifndef __GBLIBC_STRING_H_
+#define __GBLIBC_STRING_H_
 
-#include <types/stdint.h>
+#include <stdint.h>
 
-#ifndef CR
+#undef CR
+#undef LF
 #define CR ('\r')
-#endif
-
-#ifndef LF
 #define LF ('\n')
-#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -16,25 +14,14 @@ extern "C" {
 
 void* memcpy(void* dst, const void* src, size_t n);
 void* memset(void* dst, int c, size_t n);
-size_t strlen(const char* str);
-char* strncpy(char* dst, const char* src, size_t n);
-int strcmp(const char* s1, const char* s2);
 
-ssize_t
-snprint_decimal(
-    char* buf,
-    size_t buf_size,
-    int32_t num);
-
-ssize_t
-snprintf(
-    char* buf,
-    size_t buf_size,
-    const char* fmt,
-    ...);
+int strcmp(const char* s1, const char* s2);
+size_t strlen(const char* str);
 
-void kmsg(const char* msg);
+char* strncpy(char* dst, const char* src, size_t n);
 
 #ifdef __cplusplus
 }
 #endif
+
+#endif

+ 11 - 0
gblibc/private-include/devutil.h

@@ -0,0 +1,11 @@
+#ifndef __GBLIBC_DEVUTIL_H_
+#define __GBLIBC_DEVUTIL_H_
+
+#ifdef __i386__
+
+#define __GBLIBC__X86_SYSTEM_
+#define __32bit_system
+
+#endif
+
+#endif

+ 53 - 0
gblibc/src/arithmetic.c

@@ -0,0 +1,53 @@
+#include <devutil.h>
+#include <stdint.h>
+
+static inline uint64_t do_div(uint64_t a, uint64_t b, uint64_t* remainder)
+{
+    uint64_t r = 0, q = 0;
+    for (int32_t i = 0; i < 64; i++) {
+        r = (r << 1) + (a >> 63);
+        a <<= 1;
+        q <<= 1;
+        if (r >= b) {
+            r -= b;
+            q += 1;
+        }
+    }
+    if (remainder)
+        *remainder = r;
+    return q;
+}
+
+static inline int64_t do_div_s(int64_t a, int64_t b, uint64_t* remainder)
+{
+    int32_t qf = 0, rf = 0;
+    if (a < 0) {
+        qf = rf = 1;
+        a = -a;
+    }
+    if (b < 0) {
+        qf ^= 1;
+        b = -b;
+    }
+
+    int64_t quotient = do_div(a, b, (uint64_t*)remainder);
+
+    if (qf)
+        quotient = -quotient;
+    if (remainder && rf)
+        *remainder = -*remainder;
+
+    return quotient;
+}
+
+int64_t __divdi3(int64_t a, int64_t b)
+{
+    return do_div_s(a, b, (uint64_t*)0);
+}
+
+int64_t __moddi3(int64_t a, int64_t b)
+{
+    uint64_t remainder = 0;
+    do_div_s(a, b, &remainder);
+    return remainder;
+}

+ 27 - 165
src/kernel/stdio.cpp → gblibc/src/stdio.c

@@ -1,64 +1,6 @@
-#include <kernel/stdio.hpp>
-#include <kernel/tty.hpp>
-
-#include <types/size.h>
-#include <types/stdint.h>
-
-#define __32bit_system
-
-#ifdef __32bit_system
-uint64_t do_div(uint64_t a, uint64_t b, uint64_t* remainder)
-{
-    uint64_t r = 0, q = 0;
-    int32_t i;
-    for (i = 0; i < 64; i++) {
-        r = (r << 1) + (a >> 63);
-        a <<= 1;
-        q <<= 1;
-        if (r >= b) {
-            r -= b;
-            q += 1;
-        }
-    }
-    if (remainder)
-        *remainder = r;
-    return q;
-}
-
-int64_t do_div_s(int64_t a, int64_t b, uint64_t* remainder)
-{
-    int32_t qf = 0, rf = 0;
-    if (a < 0) {
-        qf = rf = 1;
-        a = -a;
-    }
-    if (b < 0) {
-        qf ^= 1;
-        b = -b;
-    }
-
-    int64_t quotient = do_div(a, b, (uint64_t*)remainder);
-
-    if (qf)
-        quotient = -quotient;
-    if (remainder && rf)
-        *remainder = -*remainder;
-
-    return quotient;
-}
-
-extern "C" int64_t __divdi3(int64_t a, int64_t b)
-{
-    return do_div_s(a, b, (uint64_t*)0);
-}
-
-extern "C" int64_t __moddi3(int64_t a, int64_t b)
-{
-    uint64_t remainder = 0;
-    do_div_s(a, b, &remainder);
-    return remainder;
-}
-#endif
+#include <devutil.h>
+#include <stdint.h>
+#include <stdarg.h>
 
 // where n is in the range of [0, 9]
 static inline char d_to_c(int32_t n)
@@ -105,7 +47,7 @@ static inline char X_to_c(int32_t n)
         --(y);                    \
     }
 
-ssize_t
+static inline ssize_t
 snprint_decimal32(
     char* buf,
     size_t buf_size,
@@ -146,7 +88,7 @@ snprint_decimal32(
     return n_write;
 }
 
-ssize_t
+static inline ssize_t
 snprint_decimal64(
     char* buf,
     size_t buf_size,
@@ -187,7 +129,7 @@ snprint_decimal64(
     return n_write;
 }
 
-ssize_t
+static inline ssize_t
 snprint_hex32(
     char* buf,
     size_t buf_size,
@@ -235,7 +177,7 @@ snprint_hex32(
     return n_write;
 }
 
-ssize_t
+static inline ssize_t
 snprint_hex64(
     char* buf,
     size_t buf_size,
@@ -294,15 +236,12 @@ snprint_char(
     return sizeof(c);
 }
 
-ssize_t
-snprintf(
-    char* buf,
-    size_t buf_size,
-    const char* fmt,
-    ...)
+int snprintf(char* buf, size_t buf_size, const char* fmt, ...)
 {
     ssize_t n_write = 0;
-    uint8_t* arg_ptr = ((uint8_t*)&buf) + sizeof(char*) + sizeof(size_t) + sizeof(const char*);
+
+    va_list arg;
+    va_start(arg, fmt);
 
     for (char c; (c = *fmt) != 0x00; ++fmt) {
         if (c == '%') {
@@ -310,20 +249,17 @@ snprintf(
 
             switch (*(++fmt)) {
 
-            // int32 decimal
+            // int
             case 'd':
-                n_tmp_write = snprint_decimal32(buf, buf_size, *(int32_t*)arg_ptr);
-                arg_ptr += sizeof(int32_t);
+                n_tmp_write = snprint_decimal32(buf, buf_size, va_arg(arg, int));
                 break;
 
             case 'x':
-                n_tmp_write = snprint_hex32(buf, buf_size, *(uint32_t*)arg_ptr, 0);
-                arg_ptr += sizeof(uint32_t);
+                n_tmp_write = snprint_hex32(buf, buf_size, va_arg(arg, unsigned int), 0);
                 break;
 
             case 'X':
-                n_tmp_write = snprint_hex32(buf, buf_size, *(uint32_t*)arg_ptr, 1);
-                arg_ptr += sizeof(uint32_t);
+                n_tmp_write = snprint_hex32(buf, buf_size, va_arg(arg, unsigned int), 1);
                 break;
 
             // long decimal
@@ -333,54 +269,47 @@ snprintf(
                 case 'l':
                     switch (*(++fmt)) {
                     case 'd':
-                        n_tmp_write = snprint_decimal64(buf, buf_size, *(int64_t*)arg_ptr);
+                        n_tmp_write = snprint_decimal64(buf, buf_size, va_arg(arg, long long));
                         break;
                     case 'x':
-                        n_tmp_write = snprint_hex64(buf, buf_size, *(int64_t*)arg_ptr, 0);
+                        n_tmp_write = snprint_hex64(buf, buf_size, va_arg(arg, unsigned long long), 0);
                         break;
                     case 'X':
-                        n_tmp_write = snprint_hex64(buf, buf_size, *(int64_t*)arg_ptr, 1);
+                        n_tmp_write = snprint_hex64(buf, buf_size, va_arg(arg, unsigned long long), 1);
                         break;
                     }
-                    arg_ptr += sizeof(int64_t);
                     break;
                 // long int aka int32
                 case 'd':
-                    n_tmp_write = snprint_decimal32(buf, buf_size, *(int32_t*)arg_ptr);
-                    arg_ptr += sizeof(int32_t);
+                    n_tmp_write = snprint_decimal32(buf, buf_size, va_arg(arg, long));
                     break;
                 case 'x':
-                    n_tmp_write = snprint_hex32(buf, buf_size, *(uint32_t*)arg_ptr, 0);
-                    arg_ptr += sizeof(uint32_t);
+                    n_tmp_write = snprint_hex32(buf, buf_size, va_arg(arg, unsigned long), 0);
                     break;
 
                 case 'X':
-                    n_tmp_write = snprint_hex32(buf, buf_size, *(uint32_t*)arg_ptr, 1);
-                    arg_ptr += sizeof(uint32_t);
+                    n_tmp_write = snprint_hex32(buf, buf_size, va_arg(arg, unsigned long), 1);
                     break;
                 }
                 break;
 
             // c string
             case 's':
-                n_tmp_write = snprintf(buf, buf_size, *(const char**)arg_ptr);
-                arg_ptr += sizeof(const char*);
+                n_tmp_write = snprintf(buf, buf_size, va_arg(arg, const char*));
                 break;
 
             // int8 char
             case 'c':
-                n_tmp_write = snprint_char(buf, buf_size, *(char*)arg_ptr);
-                arg_ptr += sizeof(char);
+                n_tmp_write = snprint_char(buf, buf_size, va_arg(arg, int));
                 break;
 
             // pointer
             case 'p':
 #ifdef __32bit_system
-                n_tmp_write = snprint_hex32(buf, buf_size, *(ptr_t*)arg_ptr, 0);
+                n_tmp_write = snprint_hex32(buf, buf_size, va_arg(arg, size_t), 0);
 #else
-                n_tmp_write = snprint_hex64(buf, buf_size, *(ptr_t*)arg_ptr, 0);
+                n_tmp_write = snprint_hex64(buf, buf_size, va_arg(arg, size_t), 0);
 #endif
-                arg_ptr += sizeof(ptr_t);
                 break;
 
             default:
@@ -410,74 +339,7 @@ snprintf(
     if (buf_size > 0)
         *buf = 0x00;
 
-    return n_write;
-}
-
-#define BYTES_PER_MAX_COPY_UNIT (sizeof(uint32_t) / sizeof(uint8_t))
-void* memcpy(void* _dst, const void* _src, size_t n)
-{
-    void* orig_dst = _dst;
-    uint8_t* dst = (uint8_t*)_dst;
-    const uint8_t* src = (const uint8_t*)_src;
-    for (size_t i = 0; i < n / BYTES_PER_MAX_COPY_UNIT; ++i) {
-        *(uint32_t*)dst = *(uint32_t*)src;
-        dst += BYTES_PER_MAX_COPY_UNIT;
-        src += BYTES_PER_MAX_COPY_UNIT;
-    }
-    for (size_t i = 0; i < (n % BYTES_PER_MAX_COPY_UNIT); ++i) {
-        *((char*)dst++) = *((char*)src++);
-    }
-    return orig_dst;
-}
+    va_end(arg);
 
-void* memset(void* _dst, int c, size_t n)
-{
-    uint8_t* dst = (uint8_t*)_dst;
-    c &= 0xff;
-    int cc = (c + (c << 8) + (c << 16) + (c << 24));
-    for (size_t i = 0; i < n / BYTES_PER_MAX_COPY_UNIT; ++i) {
-        *(uint32_t*)dst = cc;
-        dst += BYTES_PER_MAX_COPY_UNIT;
-    }
-    for (size_t i = 0; i < (n % BYTES_PER_MAX_COPY_UNIT); ++i) {
-        *((char*)dst++) = c;
-    }
-    return dst;
-}
-
-size_t strlen(const char* str)
-{
-    size_t n = 0;
-    while (*(str++) != '\0')
-        ++n;
-    return n;
-}
-
-char* strncpy(char* dst, const char* src, size_t n)
-{
-    size_t len = strlen(src);
-
-    if (len < n) {
-        memset(dst + len, 0x00, n - len);
-        memcpy(dst, src, len);
-    } else {
-        memcpy(dst, src, n);
-    }
-
-    return dst;
-}
-
-int strcmp(const char* s1, const char* s2)
-{
-    int c;
-    while ((c = *s1 - *s2) == 0 && *s1 != 0) {
-        ++s1;
-        ++s2;
-    }
-    return c;
-}
-
-void kmsg(const char* msg)
-{
-    console->print(msg);
+    return n_write;
 }

+ 66 - 0
gblibc/src/string.c

@@ -0,0 +1,66 @@
+#include <stdint.h>
+
+#define BYTES_PER_MAX_COPY_UNIT (sizeof(uint32_t) / sizeof(uint8_t))
+
+void* memcpy(void* _dst, const void* _src, size_t n)
+{
+    void* orig_dst = _dst;
+    uint8_t* dst = (uint8_t*)_dst;
+    const uint8_t* src = (const uint8_t*)_src;
+    for (size_t i = 0; i < n / BYTES_PER_MAX_COPY_UNIT; ++i) {
+        *(uint32_t*)dst = *(uint32_t*)src;
+        dst += BYTES_PER_MAX_COPY_UNIT;
+        src += BYTES_PER_MAX_COPY_UNIT;
+    }
+    for (size_t i = 0; i < (n % BYTES_PER_MAX_COPY_UNIT); ++i) {
+        *((char*)dst++) = *((char*)src++);
+    }
+    return orig_dst;
+}
+
+void* memset(void* _dst, int c, size_t n)
+{
+    uint8_t* dst = (uint8_t*)_dst;
+    c &= 0xff;
+    int cc = (c + (c << 8) + (c << 16) + (c << 24));
+    for (size_t i = 0; i < n / BYTES_PER_MAX_COPY_UNIT; ++i) {
+        *(uint32_t*)dst = cc;
+        dst += BYTES_PER_MAX_COPY_UNIT;
+    }
+    for (size_t i = 0; i < (n % BYTES_PER_MAX_COPY_UNIT); ++i) {
+        *((char*)dst++) = c;
+    }
+    return dst;
+}
+
+size_t strlen(const char* str)
+{
+    size_t n = 0;
+    while (*(str++) != '\0')
+        ++n;
+    return n;
+}
+
+char* strncpy(char* dst, const char* src, size_t n)
+{
+    size_t len = strlen(src);
+
+    if (len < n) {
+        memset(dst + len, 0x00, n - len);
+        memcpy(dst, src, len);
+    } else {
+        memcpy(dst, src, n);
+    }
+
+    return dst;
+}
+
+int strcmp(const char* s1, const char* s2)
+{
+    int c;
+    while ((c = *s1 - *s2) == 0 && *s1 != 0) {
+        ++s1;
+        ++s2;
+    }
+    return c;
+}

+ 1 - 1
include/asm/boot.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#include <types/stdint.h>
+#include <stdint.h>
 
 #define KERNEL_EARLY_STACK_ADDR ((phys_ptr_t)0x01000000)
 #define KERNEL_EARLY_STACK_SIZE ((size_t)0x100000)

+ 2 - 1
include/fs/fat.hpp

@@ -2,8 +2,9 @@
 
 #include <kernel/mem.h>
 #include <kernel/vfs.hpp>
+#include <stdint.h>
+#include <string.h>
 #include <types/size.h>
-#include <types/stdint.h>
 
 namespace fs::fat {
 using cluster_t = uint32_t;

+ 1 - 1
include/kernel/hw/port.hpp

@@ -1,7 +1,7 @@
 #pragma once
 
+#include <stdint.h>
 #include <types/cplusplus.hpp>
-#include <types/stdint.h>
 
 namespace hw {
 template <typename port_size_t, bool r = true, bool w = true>

+ 1 - 1
include/kernel/hw/timer.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#include <types/stdint.h>
+#include <stdint.h>
 
 #ifdef __cplusplus
 extern "C" {

+ 8 - 0
include/kernel/log.hpp

@@ -0,0 +1,8 @@
+#pragma once
+
+#include <kernel/tty.hpp>
+
+inline void kmsg(const char* msg)
+{
+    console->print(msg);
+}

+ 1 - 1
include/kernel/mem.h

@@ -1,7 +1,7 @@
 #pragma once
 
+#include <stdint.h>
 #include <types/size.h>
-#include <types/stdint.h>
 
 #define PAGE_SIZE (4096)
 #define KERNEL_IDENTICALLY_MAPPED_AREA_LIMIT ((void*)0x30000000)

+ 1 - 1
include/kernel/process.hpp

@@ -6,6 +6,7 @@
 #include <kernel/mm.hpp>
 #include <kernel/task.h>
 #include <kernel/vfs.hpp>
+#include <stdint.h>
 #include <types/allocator.hpp>
 #include <types/cplusplus.hpp>
 #include <types/hash_map.hpp>
@@ -13,7 +14,6 @@
 #include <types/map.hpp>
 #include <types/pair.hpp>
 #include <types/status.h>
-#include <types/stdint.h>
 #include <types/types.h>
 
 typedef size_t pid_t;

+ 1 - 1
include/kernel/tty.hpp

@@ -1,9 +1,9 @@
 #pragma once
 #include <kernel/event/evtqueue.hpp>
+#include <stdint.h>
 #include <types/allocator.hpp>
 #include <types/buffer.hpp>
 #include <types/cplusplus.hpp>
-#include <types/stdint.h>
 
 class tty : public types::non_copyable {
 public:

+ 1 - 1
include/kernel/vfs.hpp

@@ -1,11 +1,11 @@
 #pragma once
 
+#include <stdint.h>
 #include <types/allocator.hpp>
 #include <types/function.hpp>
 #include <types/hash_map.hpp>
 #include <types/list.hpp>
 #include <types/map.hpp>
-#include <types/stdint.h>
 #include <types/types.h>
 #include <types/vector.hpp>
 

+ 1 - 1
include/kernel/vga.hpp

@@ -2,7 +2,7 @@
 #ifndef _KERNEL_VGA_H_
 #define _KERNEL_VGA_H_
 
-#include <types/stdint.h>
+#include <stdint.h>
 
 #define VGA_CHAR_COLOR_WHITE (0x0fU)
 

+ 1 - 1
include/types/allocator.hpp

@@ -1,7 +1,7 @@
 #pragma once
 #include <kernel/mem.h>
+#include <stdint.h>
 #include <types/cplusplus.hpp>
-#include <types/stdint.h>
 #include <types/types.h>
 
 constexpr void* operator new(size_t, void* ptr)

+ 1 - 1
include/types/bitmap.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#include <types/stdint.h>
+#include <stdint.h>
 
 #ifdef __cplusplus
 extern "C" {

+ 1 - 1
include/types/buffer.hpp

@@ -1,7 +1,7 @@
 #pragma once
 
+#include <stdint.h>
 #include <types/allocator.hpp>
-#include <types/stdint.h>
 
 namespace types {
 

+ 1 - 1
include/types/cplusplus.hpp

@@ -1,6 +1,6 @@
 #pragma once
 
-#include <types/stdint.h>
+#include <stdint.h>
 
 #ifdef __cplusplus
 

+ 1 - 1
include/types/elf.hpp

@@ -3,9 +3,9 @@
 #include <kernel/interrupt.h>
 #include <kernel/process.hpp>
 #include <kernel/vfs.hpp>
+#include <stdint.h>
 #include <types/size.h>
 #include <types/status.h>
-#include <types/stdint.h>
 
 namespace types::elf {
 using elf32_addr_t = uint32_t;

+ 1 - 1
include/types/hash_map.hpp

@@ -1,10 +1,10 @@
 #pragma once
 
+#include <stdint.h>
 #include <types/allocator.hpp>
 #include <types/cplusplus.hpp>
 #include <types/list.hpp>
 #include <types/pair.hpp>
-#include <types/stdint.h>
 #include <types/string.hpp>
 #include <types/types.h>
 #include <types/vector.hpp>

+ 1 - 1
include/types/lock.hpp

@@ -1,6 +1,6 @@
 #pragma once
 
-#include <types/stdint.h>
+#include <stdint.h>
 
 inline void spin_lock(uint32_t volatile* lock_addr)
 {

+ 1 - 1
include/types/string.hpp

@@ -1,6 +1,6 @@
 #pragma once
 
-#include <kernel/stdio.hpp>
+#include <string.h>
 #include <types/allocator.hpp>
 #include <types/types.h>
 #include <types/vector.hpp>

+ 2 - 2
src/fs/fat.cpp

@@ -1,13 +1,13 @@
 #include <fs/fat.hpp>
 #include <kernel/mem.h>
 #include <kernel/mm.hpp>
-#include <kernel/stdio.hpp>
 #include <kernel/vfs.hpp>
+#include <stdint.h>
+#include <stdio.h>
 #include <types/allocator.hpp>
 #include <types/assert.h>
 #include <types/hash_map.hpp>
 #include <types/status.h>
-#include <types/stdint.h>
 
 namespace fs::fat {
 // buf MUST be larger than 512 bytes

+ 2 - 1
src/kernel/event/event.cpp

@@ -2,8 +2,9 @@
 #include <kernel/event/event.h>
 #include <kernel/event/evtqueue.hpp>
 #include <kernel/input/input_event.h>
+#include <kernel/log.hpp>
 #include <kernel/process.hpp>
-#include <kernel/stdio.hpp>
+#include <stdio.h>
 #include <types/allocator.hpp>
 #include <types/assert.h>
 #include <types/cplusplus.hpp>

+ 2 - 2
src/kernel/hw/ata.cpp

@@ -1,13 +1,13 @@
 #include <asm/port_io.h>
 #include <fs/fat.hpp>
 #include <kernel/hw/ata.hpp>
-#include <kernel/stdio.hpp>
 #include <kernel/syscall.hpp>
 #include <kernel/vfs.hpp>
+#include <stdint.h>
+#include <stdio.h>
 #include <types/allocator.hpp>
 #include <types/assert.h>
 #include <types/status.h>
-#include <types/stdint.h>
 
 hw::ata::ata(port_id_t p)
     : data(p)

+ 1 - 1
src/kernel/hw/serial.cpp

@@ -1,7 +1,7 @@
 #include <asm/port_io.h>
 #include <kernel/hw/serial.h>
-#include <kernel/stdio.hpp>
 #include <kernel/tty.hpp>
+#include <stdio.h>
 #include <types/status.h>
 
 int32_t init_serial_port(port_id_t port)

+ 3 - 2
src/kernel/interrupt.cpp

@@ -5,17 +5,18 @@
 #include <kernel/hw/serial.h>
 #include <kernel/hw/timer.h>
 #include <kernel/interrupt.h>
+#include <kernel/log.hpp>
 #include <kernel/mem.h>
 #include <kernel/mm.hpp>
 #include <kernel/process.hpp>
-#include <kernel/stdio.hpp>
 #include <kernel/syscall.hpp>
 #include <kernel/vfs.hpp>
 #include <kernel/vga.hpp>
 #include <kernel_main.hpp>
+#include <stdint.h>
+#include <stdio.h>
 #include <types/assert.h>
 #include <types/size.h>
-#include <types/stdint.h>
 #include <types/types.h>
 
 static struct IDT_entry IDT[256];

+ 1 - 1
src/kernel/mem.cpp

@@ -5,10 +5,10 @@
 #include <kernel/mem.h>
 #include <kernel/mm.hpp>
 #include <kernel/process.hpp>
-#include <kernel/stdio.hpp>
 #include <kernel/task.h>
 #include <kernel/vga.hpp>
 #include <kernel_main.hpp>
+#include <stdio.h>
 #include <types/allocator.hpp>
 #include <types/assert.h>
 #include <types/bitmap.h>

+ 3 - 2
src/kernel/process.cpp

@@ -3,12 +3,14 @@
 #include <fs/fat.hpp>
 #include <kernel/hw/ata.hpp>
 #include <kernel/interrupt.h>
+#include <kernel/log.hpp>
 #include <kernel/mem.h>
 #include <kernel/mm.hpp>
 #include <kernel/process.hpp>
-#include <kernel/stdio.hpp>
 #include <kernel/vfs.hpp>
 #include <kernel_main.hpp>
+#include <stdint.h>
+#include <stdio.h>
 #include <types/allocator.hpp>
 #include <types/assert.h>
 #include <types/cplusplus.hpp>
@@ -18,7 +20,6 @@
 #include <types/lock.hpp>
 #include <types/size.h>
 #include <types/status.h>
-#include <types/stdint.h>
 #include <types/types.h>
 
 static void (*volatile kthreadd_new_thd_func)(void*);

+ 3 - 2
src/kernel/syscall.cpp

@@ -2,18 +2,19 @@
 #include <asm/sys.h>
 #include <kernel/errno.h>
 #include <kernel/interrupt.h>
+#include <kernel/log.hpp>
 #include <kernel/mem.h>
 #include <kernel/mm.hpp>
 #include <kernel/process.hpp>
-#include <kernel/stdio.hpp>
 #include <kernel/syscall.hpp>
 #include <kernel/vfs.hpp>
 #include <kernel_main.hpp>
+#include <stdint.h>
+#include <stdio.h>
 #include <types/allocator.hpp>
 #include <types/assert.h>
 #include <types/elf.hpp>
 #include <types/status.h>
-#include <types/stdint.h>
 
 #define SYSCALL_SET_RETURN_VAL_EAX(_eax) \
     data->s_regs.eax = ((decltype(data->s_regs.eax))(_eax))

+ 2 - 2
src/kernel/tty.cpp

@@ -1,9 +1,9 @@
 #include <kernel/hw/serial.h>
 #include <kernel/process.hpp>
-#include <kernel/stdio.hpp>
 #include <kernel/tty.hpp>
 #include <kernel/vga.hpp>
-#include <types/stdint.h>
+#include <stdint.h>
+#include <stdio.h>
 
 tty::tty()
     : buf(BUFFER_SIZE)

+ 2 - 2
src/kernel/vfs.cpp

@@ -1,15 +1,15 @@
 #include <kernel/errno.h>
 #include <kernel/mem.h>
-#include <kernel/stdio.hpp>
 #include <kernel/tty.hpp>
 #include <kernel/vfs.hpp>
+#include <stdint.h>
+#include <stdio.h>
 #include <types/allocator.hpp>
 #include <types/assert.h>
 #include <types/list.hpp>
 #include <types/map.hpp>
 #include <types/pair.hpp>
 #include <types/status.h>
-#include <types/stdint.h>
 #include <types/string.hpp>
 #include <types/vector.hpp>
 

+ 2 - 2
src/kernel/vga.cpp

@@ -1,8 +1,8 @@
 #define _KERNEL_VGA_C_
-#include <types/stdint.h>
 
-#include <kernel/stdio.hpp>
 #include <kernel/vga.hpp>
+#include <stdint.h>
+#include <string.h>
 
 static struct vga_char* p_vga_head = VGA_MEM;
 

+ 3 - 2
src/kernel_main.cpp

@@ -8,16 +8,17 @@
 #include <kernel/hw/serial.h>
 #include <kernel/hw/timer.h>
 #include <kernel/interrupt.h>
+#include <kernel/log.hpp>
 #include <kernel/mem.h>
 #include <kernel/process.hpp>
-#include <kernel/stdio.hpp>
 #include <kernel/task.h>
 #include <kernel/tty.hpp>
 #include <kernel/vga.hpp>
+#include <stdint.h>
+#include <stdio.h>
 #include <types/assert.h>
 #include <types/bitmap.h>
 #include <types/status.h>
-#include <types/stdint.h>
 #include <types/types.h>
 
 #define KERNEL_MAIN_BUF_SIZE (128)

+ 2 - 2
src/types/elf.cpp

@@ -1,8 +1,8 @@
 #include <kernel/errno.h>
-#include <kernel/stdio.hpp>
+#include <stdint.h>
+#include <stdio.h>
 #include <types/assert.h>
 #include <types/elf.hpp>
-#include <types/stdint.h>
 
 template <typename T>
 constexpr void _user_push(uint32_t** sp, T d)