diff --git a/include/version.h b/include/version.h index f47701f..ed89816 100644 --- a/include/version.h +++ b/include/version.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 1 -#define VERSION_BUILD 24 +#define VERSION_BUILD 40 diff --git a/kernel/mod.cpp b/kernel/mod.cpp index aea4e0f..9d6a4ed 100644 --- a/kernel/mod.cpp +++ b/kernel/mod.cpp @@ -20,39 +20,42 @@ typedef struct { uint16_t e_shstrndx; } elf64_header_t; -void *elf_entry(void *module, uint64_t size) { - // Приводим заголовок ELF файла к типу elf64_header_t - elf64_header_t *elf_header = (elf64_header_t *)module; +typedef struct { + void (*fb_printf)(char *str, ...); +} env_t; - // Выводим данные о заголовке ELF файла - fb::printf("ELF Header:\n"); - fb::printf(" Magic number: "); - for (int i = 0; i < 16; i++) { - fb::printf("0x%x ", elf_header->e_ident[i]); - } - fb::printf("\n"); - fb::printf(" Class: ELF64\n"); - fb::printf(" Version: %u\n", elf_header->e_ident[6]); - fb::printf(" OS/ABI: %u\n", elf_header->e_ident[7]); - fb::printf(" Type: %u\n", elf_header->e_type); - fb::printf(" Machine: %u\n", elf_header->e_machine); - fb::printf(" Version: %u\n", elf_header->e_version); - fb::printf(" Entry point: 0x%x\n", elf_header->e_entry); - fb::printf(" Program header offset: %u\n", elf_header->e_phoff); - fb::printf(" Section header offset: %u\n", elf_header->e_shoff); - fb::printf(" Flags: %u\n", elf_header->e_flags); - fb::printf(" ELF header size: %u (bytes)\n", +env_t main_env; + +void *elf_entry(void *module_bin, uint64_t size) { + // Приводим заголовок ELF файла к типу elf64_header_t + elf64_header_t *elf_header = (elf64_header_t *)module_bin; + + fb::printf(" Класс: ELF64\n"); + fb::printf(" Версия: %u\n", elf_header->e_ident[6]); + fb::printf(" ОС/ABI: %u\n", elf_header->e_ident[7]); + fb::printf(" Тип: %u\n", elf_header->e_type); + fb::printf(" Машина: %u\n", elf_header->e_machine); + fb::printf(" Версия: %u\n", elf_header->e_version); + fb::printf(" Точка входа: 0x%x\n", elf_header->e_entry); +#if 0 + fb::printf(" Смещение таблицы программ: %u\n", elf_header->e_phoff); + fb::printf(" Смещение таблицы секций: %u\n", elf_header->e_shoff); + fb::printf(" Флаги: %u\n", elf_header->e_flags); + fb::printf(" Размер заголовка ELF файла: %u (байт)\n", elf_header->e_ehsize); - fb::printf(" Program header entry size: %u (bytes)\n", + fb::printf(" Размер записи таблицы программ: %u (байт)\n", elf_header->e_phentsize); - fb::printf(" Program header count: %u\n", elf_header->e_phnum); - fb::printf(" Section header entry size: %u (bytes)\n", + fb::printf(" Количество записей таблицы программ: %u\n", + elf_header->e_phnum); + fb::printf(" Размер записи таблицы секций: %u (байт)\n", elf_header->e_shentsize); - fb::printf(" Section header count: %u\n", elf_header->e_shnum); - fb::printf(" Section header string index: %u\n", elf_header->e_shstrndx); + fb::printf(" Количество записей таблицы секций: %u\n", + elf_header->e_shnum); + fb::printf(" Индекс строки таблицы секций: %u\n", elf_header->e_shstrndx); +#endif // Возвращаем указатель на точку входа - return (void *)elf_header->e_entry; + return (void *)((uint64_t)elf_header->e_entry + (uint64_t)module_bin); } namespace mod { @@ -66,6 +69,7 @@ struct limine_module_response *module_response; static uint64_t module_count = 0; void init( ) { + main_env.fb_printf = &fb::printf; module_response = module_request.response; module_count = module_response->module_count; struct limine_file *module_ptr = (struct limine_file *)0; @@ -74,15 +78,23 @@ void init( ) { module_ptr = module_response->modules[i]; fb::printf("[%d] %s [%s] 0x%x\n", i, module_ptr->path, module_ptr->cmdline, module_ptr->address); - fb::printf("->Size: %u, media_type: %u, partition_index: %u\n", + fb::printf("->Размер: %u, тип носителя: %u, индекс раздела: %u\n", module_ptr->size, module_ptr->media_type, module_ptr->partition_index); - fb::printf("->mbr_disk_id: %u, tftp_ip: %u, tftp_port: %u\n", - module_ptr->mbr_disk_id, module_ptr->tftp_ip, - module_ptr->tftp_port); + fb::printf( + "->Идентификатор диска MBR: %u, TFTP IP: %u, TFTP порт: %u\n", + module_ptr->mbr_disk_id, module_ptr->tftp_ip, + module_ptr->tftp_port); - fb::printf("\t->Entry point: 0x%x\n\n", - elf_entry(module_ptr->address, module_ptr->size)); + long long (*module_init)(env_t * env) = (long long (*)(env_t * env)) + elf_entry(module_ptr->address, module_ptr->size); + + fb::printf("\t->Точка входа: 0x%x\n", module_init); + + int ret = module_init(&main_env); + + fb::printf("Инициализированно с кодом: %x\n", ret); + fb::printf("Сообщение из модуля: %s\n\n", (char *)ret); } } } // namespace mod \ No newline at end of file diff --git a/kernel/start.cpp b/kernel/start.cpp index 452e53a..3ae8b5b 100644 --- a/kernel/start.cpp +++ b/kernel/start.cpp @@ -31,7 +31,5 @@ extern "C" void _start( ) { fb::printf("\t\t\t\t *** Дата сборки: %s %s ***\n", __DATE__, __TIME__); mod::init( ); - asm volatile("int $0"); - for (;;) { asm volatile("hlt"); } } \ No newline at end of file diff --git a/modules/helloworld/build.sh b/modules/helloworld/build.sh index 97bbafd..d282b5a 100755 --- a/modules/helloworld/build.sh +++ b/modules/helloworld/build.sh @@ -1,6 +1,6 @@ #/bin/sh echo "Название: Hello world" echo "Лицензия: Публичное достояние" -g++ -c -fPIC -nostdlib main.cpp -o hello.o +g++ -O0 -finput-charset=UTF-8 -fexec-charset=cp1251 -c -fPIC -nostdlib main.cpp -o hello.o gcc -shared -nostdlib hello.o -o hello.so -Wl,--entry=_start echo "Сборка завершена, файл: hello.so" diff --git a/modules/helloworld/main.cpp b/modules/helloworld/main.cpp index 010d457..b2429be 100644 --- a/modules/helloworld/main.cpp +++ b/modules/helloworld/main.cpp @@ -1,5 +1,10 @@ +typedef struct { + void (*fb_printf)(char *str, ...); +} env_t; +const char message[] = "Привет из модуля!"; -extern "C" int _start( ) { - return 80; +extern "C" long long _start(env_t *env) { + env->fb_printf("[hello]message=[%s]\n", message); + return (long long)&message; } \ No newline at end of file diff --git a/pbuild.py b/pbuild.py index c9c82c2..720ac9b 100644 --- a/pbuild.py +++ b/pbuild.py @@ -159,9 +159,9 @@ if __name__ == "__main__": check_limine() check_tools() major, minor, build = version_build() + os.system("cd modules/helloworld/ && ./build.sh") compile_all() create_iso("bmosp") create_hdd("bmosp") - os.system("cd modules/helloworld/ && ./build.sh") print(f"Не забудьте сохранить изменения! Номер сборки: {major}.{minor}, {build}") \ No newline at end of file diff --git a/run.sh b/run.sh index f9e1eff..69d4fce 100755 --- a/run.sh +++ b/run.sh @@ -1,2 +1,2 @@ #!/bin/sh -qemu-system-x86_64 -cpu max -m 2G -smp 1 -bios ovmf/OVMF.fd -hda bmosp.hdd \ No newline at end of file +qemu-system-x86_64 -cpu max -m 256M -smp 1 -bios ovmf/OVMF.fd -hda bmosp.hdd \ No newline at end of file