diff --git a/.vscode/settings.json b/.vscode/settings.json index af8da87..528351b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,5 +14,6 @@ "fb.h": "c", "system.h": "c", "mod.h": "c", + "modstd.h": "c" } } \ No newline at end of file diff --git a/configs/limine.cfg b/configs/limine.cfg index 1e9cc50..fd619f1 100644 --- a/configs/limine.cfg +++ b/configs/limine.cfg @@ -22,6 +22,9 @@ TERM_WALLPAPER=boot:///boot.jpg MODULE_PATH=boot:///mod/simd.ko MODULE_CMDLINE=[MOD]simd.ko + MODULE_PATH=boot:///mod/pci_vendors.txt + MODULE_CMDLINE=[PCI][DATA][VENDORS] + MODULE_PATH=boot:///mod/pci_data.ko MODULE_CMDLINE=[MOD]pci_data.ko diff --git a/include/version.h b/include/version.h index ef16c31..1e245d6 100644 --- a/include/version.h +++ b/include/version.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 1 -#define VERSION_BUILD 583 +#define VERSION_BUILD 591 diff --git a/kernel/mod.c b/kernel/mod.c index 0280d7b..1ca5e4c 100644 --- a/kernel/mod.c +++ b/kernel/mod.c @@ -95,7 +95,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/modlib/modstd.h b/modlib/modstd.h index a795c4f..4d97703 100644 --- a/modlib/modstd.h +++ b/modlib/modstd.h @@ -6,17 +6,121 @@ * */ +#include + #ifndef MODSTD_H #define MODSTD_H -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long uint64_t; +static uint64_t strlen(const char *str) { + uint64_t length = 0; + while (*str) { + length++; + str++; + } + return length; +} -typedef char int8_t; -typedef short int16_t; -typedef int int32_t; -typedef long long int64_t; +static void memcpy(void *dest, void *src, uint64_t n) { + char *d = (char *)dest; + const char *s = (const char *)src; + + for (uint64_t i = 0; i < n; i++) { d[i] = s[i]; } +} + +static void *memset(void *ptr, uint8_t n, uint64_t size) { + uint8_t *p = (uint8_t *)ptr; + for (uint64_t i = 0; i < size; i++) { p[i] = n; } + return ptr; +} + +static size_t strspn(const char *str, const char *accept) { + size_t count = 0; + const char *ptr = str; + const char *acc; + + while (*ptr) { + acc = accept; + while (*acc) { + if (*ptr == *acc) { + count++; + break; + } + acc++; + } + if (*acc == '\0') break; + ptr++; + } + + return count; +} + +static size_t strcspn(const char *str, const char *reject) { + size_t count = 0; + const char *ptr = str; + const char *r; + + while (*ptr) { + r = reject; + while (*r) { + if (*ptr == *r) { return count; } + r++; + } + count++; + ptr++; + } + + return count; +} + +static char *strtok(char *str, const char *delim) { + static char *token = NULL; + static char *next_token = NULL; + + if (str != NULL) { + token = str; + } else { + token = next_token; + } + + if (token == NULL) { return NULL; } + + token += strspn(token, delim); + + if (*token == '\0') { + next_token = NULL; + return NULL; + } + + next_token = token + strcspn(token, delim); + + if (*next_token != '\0') { + *next_token = '\0'; + next_token++; + } else { + next_token = NULL; + } + + return token; +} + +static char *strdup(const char *str) { + size_t len = strlen(str) + 1; + char *dup = alloc(len); + + if (dup != NULL) { memcpy(dup, str, len); } + + return dup; +} + +static size_t count_chars(const char *str, char c) { + size_t count = 0; + + while (*str) { + if (*str == c) { count++; } + str++; + } + + return count; +} #endif // modstd.h diff --git a/modlib/system.h b/modlib/system.h index 07b114f..f719de3 100644 --- a/modlib/system.h +++ b/modlib/system.h @@ -6,72 +6,12 @@ * */ +#include +#include + #ifndef SYSTEM_H #define SYSTEM_H -#define NULL ((void *)0) - -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long uint64_t; -typedef long long int64_t; - -typedef struct { - int reserved; -} framebuffer_t; - -typedef struct { - int reserved; -} sys_info_t; - -typedef struct { - char *name; - void *addr; -} module_func_t; - -typedef struct { - int reserved; -} func_t; - -typedef struct { - uint8_t a[4]; - uint8_t b[4]; - uint8_t c[4]; - uint8_t d[4]; -} uid_t; - -typedef struct { - uint16_t year; - uint8_t month; - uint8_t day; - uint8_t second; -} time_t; - -typedef struct { - char *name; - char *message; - uint64_t type; - uint64_t data_size; - void *data; - int64_t err_code; - uint64_t module_id; -} __attribute__((packed)) module_info_t; - -typedef struct { - uint64_t offset; - void (*fb_printf)(char *str, ...); // Временная функция - framebuffer_t *(*alloc_framebuffer)( ); - void (*free_framebuffer)(framebuffer_t *frame); - void (*exit)(int code); - int (*get_error)( ); - sys_info_t *(*get_info)( ); - module_info_t *(*get_module)(char *module_id); - uint64_t (*new_thread)(uint64_t func); - int (*delete_thread)(uint64_t thread_id); - time_t (*get_time)( ); -} __attribute__((packed)) env_t; - static void (*fb_printf)(char *str, ...); static module_info_t *(*get_module)(char *module_id); static uint64_t offset; diff --git a/modlib/types.h b/modlib/types.h new file mode 100644 index 0000000..3e528a9 --- /dev/null +++ b/modlib/types.h @@ -0,0 +1,81 @@ +/** + * types.h + * Системные вызовы + * + * Заголовочный файл содержащий заготовку для работы с системными вызовами + * + */ + +#ifndef TYPES_H +#define TYPES_H + +#define NULL ((void *)0) + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +typedef char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef long long int64_t; + +typedef uint64_t size_t; + +typedef struct { + int reserved; +} framebuffer_t; + +typedef struct { + int reserved; +} sys_info_t; + +typedef struct { + char *name; + void *addr; +} module_func_t; + +typedef struct { + int reserved; +} func_t; + +typedef struct { + uint8_t a[4]; + uint8_t b[4]; + uint8_t c[4]; + uint8_t d[4]; +} uid_t; + +typedef struct { + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t second; +} time_t; + +typedef struct { + char *name; + char *message; + uint64_t type; + uint64_t data_size; + void *data; + int64_t err_code; + uint64_t module_id; +} __attribute__((packed)) module_info_t; + +typedef struct { + uint64_t offset; + void (*fb_printf)(char *str, ...); // Временная функция + framebuffer_t *(*alloc_framebuffer)( ); + void (*free_framebuffer)(framebuffer_t *frame); + void (*exit)(int code); + int (*get_error)( ); + sys_info_t *(*get_info)( ); + module_info_t *(*get_module)(char *module_id); + uint64_t (*new_thread)(uint64_t func); + int (*delete_thread)(uint64_t thread_id); + time_t (*get_time)( ); +} __attribute__((packed)) env_t; + +#endif // types.h diff --git a/modules/pci_data/build.sh b/modules/pci_data/build.sh index 585ffac..13019c6 100755 --- a/modules/pci_data/build.sh +++ b/modules/pci_data/build.sh @@ -4,4 +4,5 @@ echo "Лицензия: Публичное достояние" gcc -I../../modlib -O0 -finput-charset=UTF-8 -fexec-charset=cp1251 -c -fPIC -nostdlib main.c -o pci_data.o gcc -Wl,--entry=init -fPIC -shared -nostdlib pci_data.o -o pci_data.ko cp pci_data.ko ../bin/ +cp pci_vendors.txt ../bin/ echo "Сборка завершена, файл: pci_data.ko" diff --git a/modules/pci_data/main.c b/modules/pci_data/main.c index 1503e0b..09124b7 100644 --- a/modules/pci_data/main.c +++ b/modules/pci_data/main.c @@ -1,22 +1,48 @@ #include - typedef struct { char *name; uint16_t id; } vendor_t; +/* +vendor_t *parse_file(char *str, int *num_vendors) { + vendor_t *vendor_list = NULL; + int size = 0; -vendor_t vendor_list[] = { { "Intel", 0x8086 }, - { "AMD", 0x1002 }, - { "AMD", 0x1002 } }; + char *token; + char *line = strtok(str, "\n"); + + while (line != NULL) { + vendor_list = realloc(vendor_list, (size + 1) * sizeof(vendor_t)); + token = strtok(line, ";"); + vendor_list[size].id = (uint16_t)strtol(token, NULL, 16); + token = strtok(NULL, ";"); + vendor_list[size].name = strdup(token); + size++; + line = strtok(NULL, "\n"); + } + + *num_vendors = size; + return vendor_list; +}*/ module_info_t __attribute__((section(".minit"))) init(env_t *env) { init_env(env); + + module_info_t *pci_data = get_module("[PCI][DATA][VENDORS]"); + + if (pci_data == NULL) { fb_printf("Модуль PCI данных не найден!\n"); } + char *str = pci_data->data; + + int num_vendors = count_chars(str, ';'); + // vendor_t *vendor_list = parse_file(str, &num_vendors); + vendor_t *vendor_list; + fb_printf("Количество вендоров: %u\n", num_vendors); return (module_info_t){ .name = (char *)"[PCI][DATA]", .message = (char *)"PCI данные", .type = 0, - .data_size = 3, - .data = &vendor_list, + .data_size = num_vendors, + .data = vendor_list, .err_code = 0, .module_id = 0, }; diff --git a/modules/pci_data/pci_data.txt b/modules/pci_data/pci_vendors.txt similarity index 100% rename from modules/pci_data/pci_data.txt rename to modules/pci_data/pci_vendors.txt diff --git a/pbuild.py b/pbuild.py index ced66fa..9604604 100644 --- a/pbuild.py +++ b/pbuild.py @@ -142,7 +142,7 @@ def create_hdd(IMAGE_NAME): os.system(f"mformat -i {IMAGE_NAME}.hdd@@1M") os.system(f"mmd -i {IMAGE_NAME}.hdd@@1M ::/mod ::/EFI ::/EFI/BOOT") os.system(f"mcopy -i {IMAGE_NAME}.hdd@@1M kernel.elf configs/limine.cfg limine/limine-bios.sys ::/") - os.system(f"mcopy -i {IMAGE_NAME}.hdd@@1M modules/bin/*.ko ::/mod") + os.system(f"mcopy -i {IMAGE_NAME}.hdd@@1M modules/bin/* ::/mod") os.system(f"mcopy -i {IMAGE_NAME}.hdd@@1M limine/BOOTX64.EFI limine/BOOTIA32.EFI ::/EFI/BOOT") os.system(f"mcopy -i {IMAGE_NAME}.hdd@@1M boot.jpg boot.tga ::/") os.system(f"./limine/limine bios-install {IMAGE_NAME}.hdd")