diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6215fca..34f2978 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,10 +13,10 @@ jobs: steps: - uses: actions/checkout@v3 - + - name: install depends run: sudo apt install clang-format python3 git gdisk gcc g++ xorriso make mtools curl dos2unix - + - name: install limine run: | git clone https://git.synapseos.ru/Aren/limine.git --branch=v5.x-branch-binary --depth=1 diff --git a/.gitignore b/.gitignore index 56e43bd..c63fd25 100644 --- a/.gitignore +++ b/.gitignore @@ -6,10 +6,11 @@ ovmf/ iso_root/ output/ sdk/ +_sdk/ *.so *.o *.ko *.elf -*.zip -*.log -*.lck +*.zip +*.log +*.lck diff --git a/build.sh b/build.sh index 79a1b95..d3cabb7 100755 --- a/build.sh +++ b/build.sh @@ -7,7 +7,9 @@ chmod +x */build.sh for dir in */; do if [ $dir != "bin/" ]; then - cd $dir && ./build.sh && cd .. + cd $dir + ./build.sh + cd .. fi done diff --git a/include/tool.h b/include/tool.h index b7e0a55..9ebb455 100644 --- a/include/tool.h +++ b/include/tool.h @@ -42,6 +42,7 @@ static inline void pause( ) { void tool_memcpy(void *dest, void *src, uint64_t n); void *tool_memset(void *ptr, uint8_t n, uint64_t size); uint64_t tool_strlen(const char *str); +void tool_strcpy(char *dest, char *src); uint64_t tool_starts_with(const char *str, const char *prefix); void tool_format(void (*putc)(char c), const char *format_string, va_list args); diff --git a/kernel/debug.c b/kernel/debug.c new file mode 100644 index 0000000..8b4e3e4 --- /dev/null +++ b/kernel/debug.c @@ -0,0 +1,83 @@ +/** + * debug.c + * Функции отладочных сообщений + * + * Функционал управления выводом отладочных сообщений + * + */ + +#include +#include +#include +#include +#include +#include + +typedef struct msg { + uint64_t level; + char *message; + struct msg *next; +} msg_t; + +msg_t *log = NULL; +msg_t *last_message = NULL; + +uint32_t level_colors[] = { + 0x0000FF00, // Зеленый + 0x00FFFF00, // Желтый + 0x00FF0000, // Красный + 0x0000FFFF, // Голубой + 0x000000FF, // Синий + 0x00FF00FF // Пурпурный +}; + +// Функция для добавления сообщения в лог +void add_message(uint64_t level, char *message) { + msg_t *new_msg = (msg_t *)mem_alloc(sizeof(msg_t)); + + new_msg->level = level; + new_msg->message = mem_alloc(tool_strlen(message) + 1); + tool_strcpy(new_msg->message, message); + + new_msg->next = NULL; + + if (log == NULL) { + log = new_msg; + } else { + msg_t *current = log; + while (current->next != NULL) { current = current->next; } + current->next = new_msg; + } + last_message = new_msg; +} + +// Функция для добавления символа в сообщение +void add_char_to_message(char c, msg_t *msg) { + uint64_t length = tool_strlen(msg->message); + msg->message = mem_realloc(msg->message, length + 1); + msg->message[length] = c; + msg->message[length + 1] = '\0'; +} + +void debug_putc(char c) { + add_char_to_message(c, last_message); +} + +void debug_printf(uint8_t level, char *info, char *format, ...) { + va_list args; + va_start(args, format); + add_message(level, info); + tool_format(debug_putc, format, args); + va_end(args); +} + +// Функция для вывода всего лога +void print_log( ) { + msg_t *current = log; + while (current != NULL) { + fb_set_text_color(level_colors[current->level]); + fb_printf("Message: %s\n", current->message); + fb_set_text_color(0x00D000); + current = current->next; + } +} \ No newline at end of file diff --git a/kernel/mod.c b/kernel/mod.c index 0bc33b5..23d2f80 100644 --- a/kernel/mod.c +++ b/kernel/mod.c @@ -33,8 +33,12 @@ uint64_t bootpng_size; static void *elf_entry(elf64_header_t *module_bin) { // Приводим заголовок ELF файла к типу elf64_header_t elf64_header_t *elf_header = (elf64_header_t *)module_bin; - LOG("(uint64_t)elf_header->e_entry = 0x%x\n", - (uint64_t)elf_header->e_entry); + LOG("(uint64_t)elf_header->e_entry = 0x%x, type = %u\n", + (uint64_t)elf_header->e_entry, elf_header->e_type); + if (elf_header->e_type != 2) { + fb_printf("\t\tОшибка! Модуль неправильно собран!\n"); + for (;;) {} + } // Возвращаем указатель на точку входа return (void *)((uint64_t)elf_header->e_entry + (uint64_t)module_bin); } @@ -99,7 +103,7 @@ void mod_init( ) { continue; } - module_info_t (*module_init)(env_t *env) = + module_info_t (*module_init)(env_t * env) = (module_info_t(*)(env_t * env)) elf_entry((elf64_header_t *)module_ptr->address); diff --git a/kernel/tool.c b/kernel/tool.c index 0279de5..c0933a2 100644 --- a/kernel/tool.c +++ b/kernel/tool.c @@ -32,6 +32,15 @@ uint64_t tool_strlen(const char *str) { return length; } +void tool_strcpy(char *dest, char *src) { + uint64_t i = 0; + while (src[i] != '\0') { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; +} + uint64_t tool_starts_with(const char *str, const char *prefix) { uint64_t str_len = tool_strlen(str); uint64_t prefix_len = tool_strlen(prefix); diff --git a/modules/cpubench/build.sh b/modules/cpubench/build.sh index cb462b2..7a38324 100755 --- a/modules/cpubench/build.sh +++ b/modules/cpubench/build.sh @@ -3,7 +3,7 @@ echo "Название: CPUBENCH" echo "Лицензия: Публичное достояние" CC="gcc" -ARCH_FLAGS="-ffreestanding -O0 -g -fPIC -shared -nostdlib " +ARCH_FLAGS="-ffreestanding -O0 -g -fPIC -static -nostdlib " if [ -d "../../sdk" ]; then CC="../../sdk/bin/x86_64-elf-gcc" diff --git a/modules/helloworld/build.sh b/modules/helloworld/build.sh index 8510403..3bc1afa 100755 --- a/modules/helloworld/build.sh +++ b/modules/helloworld/build.sh @@ -3,7 +3,7 @@ echo "Название: Hello world" echo "Лицензия: Публичное достояние" CC="gcc" -ARCH_FLAGS="-ffreestanding -O0 -g -fPIC -shared -nostdlib " +ARCH_FLAGS="-ffreestanding -O0 -g -fPIC -static -nostdlib " if [ -d "../../sdk" ]; then CC="../../sdk/bin/x86_64-elf-gcc" diff --git a/modules/music/build.sh b/modules/music/build.sh index b07817d..c1a415c 100755 --- a/modules/music/build.sh +++ b/modules/music/build.sh @@ -3,7 +3,7 @@ echo "Название: Мелодия из тетриса" echo "Лицензия: Публичное достояние" CC="gcc" -ARCH_FLAGS="-ffreestanding -O0 -g -fPIC -shared -nostdlib " +ARCH_FLAGS="-ffreestanding -O0 -g -fPIC -static -nostdlib " if [ -d "../../sdk" ]; then CC="../../sdk/bin/x86_64-elf-gcc" diff --git a/modules/pci/build.sh b/modules/pci/build.sh index 6b2939f..4092c16 100755 --- a/modules/pci/build.sh +++ b/modules/pci/build.sh @@ -4,7 +4,7 @@ echo "Лицензия: Публичное достояние" CC="gcc" -ARCH_FLAGS="-ffreestanding -O0 -g -fPIC -shared -nostdlib " +ARCH_FLAGS="-ffreestanding -O0 -g -fPIC -static -nostdlib " if [ -d "../../sdk" ]; then CC="../../sdk/bin/x86_64-elf-gcc" diff --git a/modules/simd/build.sh b/modules/simd/build.sh index 9721e95..30ef716 100755 --- a/modules/simd/build.sh +++ b/modules/simd/build.sh @@ -3,7 +3,7 @@ echo "Название: SIMD" echo "Лицензия: Публичное достояние" CC="gcc" -ARCH_FLAGS="-ffreestanding -O0 -g -fPIC -shared -nostdlib " +ARCH_FLAGS="-ffreestanding -O0 -g -fPIC -static -nostdlib " if [ -d "../../sdk" ]; then CC="../../sdk/bin/x86_64-elf-gcc"