From f4d515879921d36e4612c9812fa6c47913517b3d Mon Sep 17 00:00:00 2001 From: Aren Elchinyan Date: Sat, 16 Dec 2023 00:12:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20TGA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/limine.cfg | 9 ++-- modules/tga/build.sh | 17 ++++++++ {kernel/main => modules/tga}/main.c | 67 +++++++++++++---------------- 3 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 modules/tga/build.sh rename {kernel/main => modules/tga}/main.c (73%) diff --git a/configs/limine.cfg b/configs/limine.cfg index 6c6cda5..8f40147 100644 --- a/configs/limine.cfg +++ b/configs/limine.cfg @@ -15,9 +15,6 @@ TERM_WALLPAPER=boot:///boot.jpg KASLR=no KERNEL_PATH=boot:///kernel.elf - MODULE_PATH=boot:///mod/cpubench.ko - MODULE_CMDLINE=[MOD]cpubench.ko - MODULE_PATH=boot:///mod/simd.ko MODULE_CMDLINE=[MOD]simd.ko @@ -33,5 +30,11 @@ TERM_WALLPAPER=boot:///boot.jpg MODULE_PATH=boot:///mod/ps2.ko MODULE_CMDLINE=[MOD]ps2.ko + MODULE_PATH=boot:///mod/cpubench.ko + MODULE_CMDLINE=[MOD]cpubench.ko + + MODULE_PATH=boot:///mod/tga.ko + MODULE_CMDLINE=[MOD]tga.ko + MODULE_PATH=boot:///boot.tga MODULE_CMDLINE=[BOOTIMG] \ No newline at end of file diff --git a/modules/tga/build.sh b/modules/tga/build.sh new file mode 100644 index 0000000..be9e77f --- /dev/null +++ b/modules/tga/build.sh @@ -0,0 +1,17 @@ +#/bin/sh +echo "Название: TGA" +echo "Лицензия: Публичное достояние" + +CC="gcc" +ARCH_FLAGS="-ffreestanding -O0 -g -fPIC -static -nostdlib " + +if [ -d "../../sdk" ]; then + CC="../../sdk/bin/x86_64-elf-gcc" +fi + + +$CC $ARCH_FLAGS -I../../modlib -finput-charset=UTF-8 -fexec-charset=cp1251 -c main.c -o tga.o +$CC $ARCH_FLAGS -T ../link.ld -Wl,--entry=init,--build-id=none tga.o -o tga.ko + +cp tga.ko ../bin/ +echo "Сборка завершена, файл: tga.ko" diff --git a/kernel/main/main.c b/modules/tga/main.c similarity index 73% rename from kernel/main/main.c rename to modules/tga/main.c index 03a7092..7f9bb6c 100644 --- a/kernel/main/main.c +++ b/modules/tga/main.c @@ -1,19 +1,6 @@ -/** - * main.c - * Точка входа окончания загрузки - * - * Функции эффектов после полной инициализации ядра - * - */ +#include -#include -#include -#include - -#define TGA_ERR( ) LOG("Ошибка декодирования TGA на строчке: %u\n", __LINE__); - -extern void *bootpng_ptr; -extern uint64_t bootpng_size; +#define TGA_ERR( ) fb_printf("Ошибка декодирования TGA на строчке: %u\n", __LINE__); typedef struct { unsigned char magic1; // должно быть нулевым @@ -29,25 +16,21 @@ typedef struct { unsigned char pixeltype; // должно быть 40 } __attribute__((packed)) tga_header_t; -unsigned int *tga_parse(unsigned char *ptr, int size) { +static unsigned int *tga_parse(unsigned char *ptr, int size) { unsigned int *data; int i, j, k, x, y, w = (ptr[13] << 8) + ptr[12], h = (ptr[15] << 8) + ptr[14], o = (ptr[11] << 8) + ptr[10]; int m = ((ptr[1] ? (ptr[7] >> 3) * ptr[5] : 0) + 18); if (w < 1 || h < 1) return NULL; - data = (unsigned int *)mem_alloc((w * h + 2) * sizeof(unsigned int)); - if (!data) { - LOG("Ошибка декодирования TGA на строчке: %u, %x, %u kb\n", __LINE__, data, - ((w * h + 2) * sizeof(unsigned int)) / 1024); - return NULL; - } + data = (unsigned int *)alloc((w * h + 2) * sizeof(unsigned int)); + if (!data) { return NULL; } switch (ptr[2]) { case 1: if (ptr[6] != 0 || ptr[4] != 0 || ptr[3] != 0 || (ptr[7] != 24 && ptr[7] != 32)) { TGA_ERR( ); - mem_free(data); + free(data); return NULL; } for (y = i = 0; y < h; y++) { @@ -62,7 +45,7 @@ unsigned int *tga_parse(unsigned char *ptr, int size) { case 2: if (ptr[5] != 0 || ptr[6] != 0 || ptr[1] != 0 || (ptr[16] != 24 && ptr[16] != 32)) { TGA_ERR( ); - mem_free(data); + free(data); return NULL; } for (y = i = 0; y < h; y++) { @@ -77,7 +60,7 @@ unsigned int *tga_parse(unsigned char *ptr, int size) { case 9: if (ptr[6] != 0 || ptr[4] != 0 || ptr[3] != 0 || (ptr[7] != 24 && ptr[7] != 32)) { TGA_ERR( ); - mem_free(data); + free(data); return NULL; } y = i = 0; @@ -113,7 +96,7 @@ unsigned int *tga_parse(unsigned char *ptr, int size) { case 10: if (ptr[5] != 0 || ptr[6] != 0 || ptr[1] != 0 || (ptr[16] != 24 && ptr[16] != 32)) { TGA_ERR( ); - mem_free(data); + free(data); return NULL; } y = i = 0; @@ -148,7 +131,7 @@ unsigned int *tga_parse(unsigned char *ptr, int size) { break; default: { TGA_ERR( ); - mem_free(data); + free(data); return NULL; } } @@ -156,17 +139,25 @@ unsigned int *tga_parse(unsigned char *ptr, int size) { data[1] = h; return data; } -void main( ) { - for (uint64_t i = 512; i > 1; i--) { pause( ); } - LOG("Загрузка завершена! 1\n"); - unsigned int *res = tga_parse((uint8_t *)bootpng_ptr, bootpng_size); - LOG("Загрузка завершена! 2 %x\n", res); - tga_header_t *head = (tga_header_t *)bootpng_ptr; +static void *handler(uint64_t func) { + switch (func) { + case 0: return &tga_parse; - if (res != NULL) { LOG("Размер экрана загрузки: %ux%u \n", res[0], res[1]); } - LOG("Размер экрана загрузки: %ux%u \n", head->h, head->w); - mem_dump_memory( ); + default: return NULL; + } +} - fb_print_buf(0, 0, head->w, head->h, (uint32_t *)(res + 2)); -} \ No newline at end of file +module_info_t __attribute__((section(".minit"))) init(env_t *env) { + init_env(env); + return (module_info_t){ .name = (char *)"[MEDIA][TGA]", + .message = (char *)"Отрисовка TGA изображений", + .type = 0, + .data_size = 0, + .data = (void *)0, + .err_code = 0, + .module_id = 0, + .irq = 0, + .irq_handler = 0, + .get_func = handler }; +}