mirror of
https://github.com/0Nera/BMOSP.git
synced 2024-11-22 00:21:22 +03:00
Compare commits
6 Commits
89652e9819
...
03742e31bb
Author | SHA1 | Date | |
---|---|---|---|
|
03742e31bb | ||
|
5175bba935 | ||
|
9a56ff681a | ||
|
cce42f26e6 | ||
|
c41fe4a8a5 | ||
|
6d414307dc |
1
.github/workflows/release.yml
vendored
1
.github/workflows/release.yml
vendored
@ -64,7 +64,6 @@ jobs:
|
||||
draft: true
|
||||
files: |
|
||||
${{ github.workspace }}/rel/kernel.elf
|
||||
${{ github.workspace }}/rel/bmosp.hdd
|
||||
${{ github.workspace }}/rel/bmosp.iso
|
||||
${{ github.workspace }}/rel/LICENSE
|
||||
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,8 +5,7 @@ limine/
|
||||
ovmf/
|
||||
iso_root/
|
||||
output/
|
||||
sdk/
|
||||
_sdk/
|
||||
sdk*/
|
||||
*.so
|
||||
*.o
|
||||
*.ko
|
||||
|
4
build.sh
4
build.sh
@ -2,6 +2,8 @@
|
||||
|
||||
dos2unix *.sh
|
||||
|
||||
python3 scripts/pbuild.py
|
||||
|
||||
cd modlib/lib/
|
||||
dos2unix build.sh
|
||||
chmod +x build.sh
|
||||
@ -22,5 +24,3 @@ for dir in */; do
|
||||
done
|
||||
|
||||
cd ..
|
||||
|
||||
python3 scripts/pbuild.py
|
@ -19,9 +19,6 @@ TERM_WALLPAPER=boot:///mod/boot.jpg
|
||||
MODULE_PATH=boot:///mod/pci_vendors.txt
|
||||
MODULE_CMDLINE=[PCI][DATA][VENDORS]
|
||||
|
||||
MODULE_PATH=boot:///mod/simd.ko
|
||||
MODULE_CMDLINE=[MOD]simd.ko
|
||||
|
||||
MODULE_PATH=boot:///mod/pci_data.ko
|
||||
MODULE_CMDLINE=[MOD]pci_data.ko
|
||||
|
||||
|
@ -77,7 +77,7 @@ void idt_set_int(uint8_t vector, int_entry_t handler);
|
||||
uint64_t arch_get_tick_b( );
|
||||
uint64_t arch_get_tick_l( );
|
||||
uint64_t arch_get_tick( );
|
||||
void com_write_byte(uint8_t byte);
|
||||
void com_write_byte(char byte);
|
||||
void com_write_bytes(char *c, uint64_t n);
|
||||
time_t rtc_get_time( );
|
||||
|
||||
@ -105,6 +105,26 @@ static inline void io_wait( ) {
|
||||
outb(0x80, 0);
|
||||
}
|
||||
|
||||
static inline void *hal_memset(void *s, char c, int64_t count) {
|
||||
int64_t d0, d1;
|
||||
asm volatile("rep\n\t"
|
||||
"stosb"
|
||||
: "=&c"(d0), "=&D"(d1)
|
||||
: "a"(c), "1"(s), "0"(count)
|
||||
: "memory");
|
||||
return s;
|
||||
}
|
||||
|
||||
static inline void *hal_memset_32(void *s, uint32_t c, int64_t count) {
|
||||
int64_t d0, d1;
|
||||
asm volatile("rep\n\t"
|
||||
"stosl"
|
||||
: "=&c"(d0), "=&D"(d1)
|
||||
: "a"(c), "1"(s), "0"(count)
|
||||
: "memory");
|
||||
return s;
|
||||
}
|
||||
|
||||
#define GET_TICK_BIG arch_get_tick_b( )
|
||||
#define GET_TICK_lOW arch_get_tick_l( )
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
void log_init( );
|
||||
void log_init_mem( );
|
||||
void log_printf(char *str, ...);
|
||||
char *utf8cp(char *str);
|
||||
|
||||
#ifndef NO_DEBUG
|
||||
#define LOG(...) \
|
||||
|
@ -62,6 +62,7 @@ typedef struct {
|
||||
void *irq_handler; // Адрес обработчика прерываний
|
||||
void *(*get_func)(uint64_t id);
|
||||
void (*after_init)( );
|
||||
void *env; // env_t
|
||||
} __attribute__((packed)) module_info_t;
|
||||
|
||||
typedef struct {
|
||||
@ -76,9 +77,10 @@ typedef struct {
|
||||
sys_info_t *(*get_info)( );
|
||||
module_info_t *(*get_module)(char *module_id);
|
||||
module_info_t *(*mod_list_get)(uint64_t *count);
|
||||
uint64_t (*new_thread)(void (*func)(void *), char *name);
|
||||
uint64_t (*new_thread)(void (*func)(void *), char *name, void *arg);
|
||||
void (*delete_thread)( );
|
||||
time_t (*get_time)( );
|
||||
module_info_t *ret;
|
||||
} __attribute__((packed)) env_t;
|
||||
|
||||
env_t *sys_install(env_t *module);
|
||||
|
@ -41,6 +41,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);
|
||||
void tool_memmove(void *dest, void *src, uint64_t n);
|
||||
uint64_t tool_strlen(const char *str);
|
||||
void tool_strcpy(char *dest, char *src);
|
||||
int tool_strcmp(const char *s1, const char *s2);
|
||||
|
@ -1,3 +1,3 @@
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_BUILD 107
|
||||
#define VERSION_BUILD 162
|
||||
|
@ -12,7 +12,7 @@ static inline int com_is_transmit_empty(uint16_t com) {
|
||||
return inb(com + 5) & 0x20;
|
||||
}
|
||||
|
||||
void com_write_byte(uint8_t byte) {
|
||||
void com_write_byte(char byte) {
|
||||
while (!com_is_transmit_empty(0x3F8)) {}
|
||||
|
||||
outb(0x3F8, byte);
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <tool.h>
|
||||
|
||||
static bool acpi_msrs_support = false;
|
||||
static char fxsave_region[512] __attribute__((aligned(16)));
|
||||
|
||||
static void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) {
|
||||
asm volatile("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "a"(leaf));
|
||||
@ -142,4 +143,21 @@ void cpu_init( ) {
|
||||
if ((edx >> 5) & 1) { LOG("Программный терморегулятор (STC) поддерживается!\n"); }
|
||||
|
||||
brandname( );
|
||||
|
||||
cpuid(1, &eax, &ebx, &ecx, &edx);
|
||||
|
||||
if ((edx >> 0) & 1) {
|
||||
asm volatile("finit");
|
||||
LOG("FPU(x87) поддерживается!\n");
|
||||
}
|
||||
|
||||
if ((edx >> 25) & 1) {
|
||||
LOG("SSE2 поддерживается!\n");
|
||||
LOG("Адрес региона fxsave 0x%x\n", &fxsave_region);
|
||||
asm volatile(" fxsave %0 " ::"m"(fxsave_region));
|
||||
uint32_t sse_version = (ecx >> 25) & 0x7;
|
||||
LOG("SSE%u включен\n", sse_version);
|
||||
}
|
||||
|
||||
if ((ecx >> 28) & 1) { LOG("AVX поддерживается!\n"); }
|
||||
}
|
@ -121,9 +121,11 @@ void task_del_current( ) {
|
||||
prev->next = next;
|
||||
next->last = prev;
|
||||
|
||||
LOG("Очистка потока ID: %u, %s\n", current_task->id, current_task->id_str);
|
||||
mem_free(current_task->stack);
|
||||
mem_free(current_task);
|
||||
|
||||
LOG("Смена ID: %u, %s\n", next->id, next->id_str);
|
||||
current_task = next;
|
||||
if (full_init) { task_switch( ); }
|
||||
}
|
||||
|
23
kernel/elf.c
23
kernel/elf.c
@ -107,26 +107,40 @@ void *elf_parse(elf64_header_t *head) {
|
||||
}
|
||||
|
||||
if (symtab_section && string_table) {
|
||||
#ifdef DEBUG_ELF
|
||||
LOG("\nТаблица символов:\n");
|
||||
LOG("%s %s %s %s\n", "Индекс", "Значение", "Размер", "Наименование");
|
||||
#endif
|
||||
|
||||
int num_symbols = symtab_section->sh_size / symtab_section->sh_entsize;
|
||||
for (int i = 0; i < num_symbols; i++) {
|
||||
elf64_sym_t *sym = elf64_get_symval(head, symtab_section - elf64_sheader(head), i);
|
||||
if (sym) {
|
||||
#ifdef DEBUG_ELF
|
||||
LOG("%6u %8x %6x %18s ", i, sym->st_value, sym->st_size, string_table + sym->st_name);
|
||||
#endif
|
||||
switch (ELF64_ST_TYPE(sym->st_info)) {
|
||||
case STT_NOTYPE: log_printf("без типа\n"); break;
|
||||
case STT_NOTYPE:
|
||||
|
||||
#ifdef DEBUG_ELF
|
||||
log_printf("без типа\n");
|
||||
#endif
|
||||
break;
|
||||
case STT_OBJECT:
|
||||
#ifdef DEBUG_ELF
|
||||
log_printf("объект данных\n");
|
||||
#endif
|
||||
if (!(string_table + sym->st_name)) { break; }
|
||||
// log_printf("%u\n", tool_strcmp(string_table + sym->st_name, "import_test"));
|
||||
if (tool_strcmp(string_table + sym->st_name, "import_test") == 0) {
|
||||
#ifdef DEBUG_ELF
|
||||
log_printf("0x%x\n", head + sym->st_value);
|
||||
#endif
|
||||
// void (*imp)( ) = (void *)head + sym->st_value;
|
||||
// imp = &import_test;
|
||||
}
|
||||
break;
|
||||
#ifdef DEBUG_ELF
|
||||
case STT_FUNC: log_printf("объект кода\n"); break;
|
||||
case STT_SECTION: log_printf("символ раздела\n"); break;
|
||||
case STT_FILE: log_printf("имя файла\n"); break;
|
||||
@ -134,7 +148,12 @@ void *elf_parse(elf64_header_t *head) {
|
||||
case STT_TLS: log_printf("объект данных локального потока\n"); break;
|
||||
case STT_NUM: log_printf("количество определенных типов\n"); break;
|
||||
case STT_GNU_IFUNC: log_printf("объект непрямого кода\n"); break;
|
||||
default: log_printf("???\n"); break;
|
||||
#endif
|
||||
default:
|
||||
#ifdef DEBUG_ELF
|
||||
log_printf("???\n");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,16 +53,17 @@ void fb_init( ) {
|
||||
|
||||
for (uint64_t i = 0; i < width * height; i++) { fb_addr[i] = background; }
|
||||
|
||||
LOG("0x%x %ux%u\n", fb_addr, width, height);
|
||||
|
||||
if (framebuffer_response->framebuffer_count == 1) { return; }
|
||||
|
||||
#ifdef DEBUG_FB
|
||||
LOG("Инициализация дополнительных: %u мониторов\n", framebuffer_response->framebuffer_count);
|
||||
|
||||
#endif
|
||||
for (uint64_t i = 1; i < framebuffer_response->framebuffer_count; i++) {
|
||||
struct limine_framebuffer *framebuffer = framebuffer_response->framebuffers[i];
|
||||
uint32_t *framebuffer_addr = (uint32_t *)framebuffer->address;
|
||||
#ifdef DEBUG_FB
|
||||
LOG("[%u]->0x%x %ux%u\n", i, framebuffer->address, framebuffer->width, framebuffer->height);
|
||||
#endif
|
||||
for (uint64_t ij = 0; ij < width * height; ij++) { framebuffer_addr[ij] = background; }
|
||||
}
|
||||
}
|
||||
|
30
kernel/log.c
30
kernel/log.c
@ -34,8 +34,9 @@ static inline uint32_t analyze(char glyth) {
|
||||
|
||||
// Вывод символа по координатам
|
||||
static void print_char(uint64_t x, uint64_t y, char glyth) {
|
||||
uint32_t glyth_index = analyze(glyth);
|
||||
for (uint64_t i = 0; i < FONT_6X8_SLIM_CHAR_HEIGHT; i++) {
|
||||
fb_print_bits(x, y + i, font_6x8_slim[analyze(glyth) + i]);
|
||||
fb_print_bits(x, y + i, font_6x8_slim[glyth_index + i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +46,10 @@ void log_dump_buffer( ) {
|
||||
|
||||
static void log_fb_putchar(char c) {
|
||||
if (c == '\0' || fb_init_status < 1) { return; }
|
||||
if (c == '\t') {
|
||||
|
||||
if (c == '\r') {
|
||||
log_buffer[--buf_pos] = 0;
|
||||
} else if (c == '\t') {
|
||||
fb_pos_x += FONT_6X8_SLIM_CHAR_WIDTH * 4;
|
||||
} else if (c == '\n') {
|
||||
fb_pos_x = 4;
|
||||
@ -58,12 +62,8 @@ static void log_fb_putchar(char c) {
|
||||
|
||||
if (fb_pos_y + FONT_6X8_SLIM_CHAR_HEIGHT >= SCREEN_HEIGHT) {
|
||||
// Дошли до нижнего края экрана
|
||||
while (log_buffer[0] != '\n') {
|
||||
for (uint64_t i = 0; i < buf_max - 1; i++) { log_buffer[i] = log_buffer[i + 1]; }
|
||||
buf_pos--;
|
||||
}
|
||||
for (uint64_t i = 0; i < buf_max - 1; i++) { log_buffer[i] = log_buffer[i + 1]; }
|
||||
buf_pos--;
|
||||
while (log_buffer[0] != '\n') { tool_memmove(log_buffer, log_buffer + 1, --buf_pos); }
|
||||
tool_memmove(log_buffer, log_buffer + 1, --buf_pos);
|
||||
redraw_screen( );
|
||||
return;
|
||||
}
|
||||
@ -75,7 +75,7 @@ static void log_fb_putchar(char c) {
|
||||
|
||||
void redraw_screen( ) {
|
||||
// Перерисовка экрана
|
||||
for (uint64_t i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++) { SCREEN_BUFFER[i] = DARK_GREEN; }
|
||||
hal_memset_32(SCREEN_BUFFER, DARK_GREEN, SCREEN_WIDTH * SCREEN_HEIGHT);
|
||||
|
||||
fb_pos_x = 4;
|
||||
fb_pos_y = 0;
|
||||
@ -87,8 +87,6 @@ void log_putchar(char c) {
|
||||
log_buffer[buf_pos] = c;
|
||||
com_write_byte(c);
|
||||
|
||||
log_buffer[buf_pos] = c;
|
||||
|
||||
if (buf_pos + 1 == buf_max) {
|
||||
// Смещение буфера на 1 символ влево
|
||||
for (uint64_t i = 0; i < buf_max - 1; i++) { log_buffer[i] = log_buffer[i + 1]; }
|
||||
@ -109,24 +107,18 @@ void log_printf(char *str, ...) {
|
||||
va_list args;
|
||||
va_start(args, str);
|
||||
tool_format(&log_putchar, str, args);
|
||||
|
||||
lock_release(log_lock);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void log_init_mem( ) {
|
||||
LOCK(log_lock);
|
||||
if (fb_init_status < 1) {
|
||||
LOG("Нет доступных фреймбуфферов для вывода\n");
|
||||
return;
|
||||
}
|
||||
|
||||
LOG("Полная инициализация отладчика занимает %u килобайт озу\n",
|
||||
(((SCREEN_WIDTH - 4) / FONT_WIDTH) * (SCREEN_HEIGHT / FONT_HEIGHT)) / 1024);
|
||||
|
||||
log_buffer = mem_alloc(((SCREEN_WIDTH - 4) / FONT_WIDTH) * (SCREEN_HEIGHT / FONT_HEIGHT));
|
||||
tool_memcpy(log_buffer, start_buffer, buf_max);
|
||||
buf_max = ((SCREEN_WIDTH - 4) / FONT_WIDTH) * (SCREEN_HEIGHT / FONT_HEIGHT);
|
||||
LOG("Размер буффера: %u символов\n", buf_max);
|
||||
LOG("%ux%u\n", width, height);
|
||||
redraw_screen( );
|
||||
lock_release(log_lock);
|
||||
}
|
||||
|
15
kernel/mem.c
15
kernel/mem.c
@ -51,9 +51,11 @@ static uint64_t mmmap_count = 0;
|
||||
extern task_t *current_task;
|
||||
extern uint64_t full_init;
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
static const char memory_types[8][82] = { "Доступно", "Зарезервировано", "ACPI, можно освободить",
|
||||
"ACPI NVS", "Плохая память", "Загрузчик, можно освободить",
|
||||
"Ядро и модули", "Буфер кадра" };
|
||||
#endif
|
||||
|
||||
static struct limine_memmap_response *memmap_response;
|
||||
|
||||
@ -63,6 +65,7 @@ void mem_dump_memory( ) {
|
||||
mem_entry_t *curr = first_node;
|
||||
|
||||
while (curr) {
|
||||
#ifdef DEBUG_MEM
|
||||
if (curr->next) {
|
||||
LOG("->0x%x | %u мегабайт | %s | 0x%x | поток %u\n", &curr->data, (curr->size) / 1024 / 1024,
|
||||
curr->free ? memory_types[0] : memory_types[1], curr->next, curr->task_id);
|
||||
@ -70,6 +73,7 @@ void mem_dump_memory( ) {
|
||||
LOG("->0x%x | %u мегабайт | %s | поток %u | Это последний блок\n", &curr->data, (curr->size) / 1024 / 1024,
|
||||
curr->free ? memory_types[0] : memory_types[1], curr->task_id);
|
||||
}
|
||||
#endif
|
||||
curr = curr->next;
|
||||
}
|
||||
}
|
||||
@ -284,8 +288,9 @@ void mem_init( ) {
|
||||
mmmap_count = memmap_response->entry_count;
|
||||
struct limine_memmap_entry **mmaps = memmap_response->entries;
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
LOG("Записей в карте памяти: %u\n", memmap_response->entry_count);
|
||||
|
||||
#endif
|
||||
// Обработка каждой записи в карте памяти
|
||||
for (uint64_t i = 0; i < mmmap_count; i++) {
|
||||
available += mmaps[i]->length;
|
||||
@ -293,9 +298,11 @@ void mem_init( ) {
|
||||
// LOG("\t%d: 0x%x\tдлина: 0x%x\tтип: %s\n", i + 1, mmaps[i]->base, mmaps[i]->length,
|
||||
// memory_types[mmaps[i]->type]);
|
||||
if (mmaps[i]->type == LIMINE_MEMMAP_FRAMEBUFFER) {
|
||||
#ifdef DEBUG_MEM
|
||||
LOG("На видеопамять BIOS/UEFI выделено: %u мегабайт + %u "
|
||||
"килобайт\n",
|
||||
mmaps[i]->length / 1024 / 1024, (mmaps[i]->length / 1024) % 1024);
|
||||
#endif
|
||||
}
|
||||
if (!(mmaps[i]->type == LIMINE_MEMMAP_USABLE)) { continue; }
|
||||
|
||||
@ -330,20 +337,26 @@ void mem_init( ) {
|
||||
for (uint64_t t = 0; t < mmaps[i]->length; t += BLOCK_SIZE) { mem_frame_free((void *)mmaps[i]->base + t, 1); }
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
LOG("%u / %u блоков доступно\n", bitmap_available, bitmap_limit);
|
||||
LOG("Размер битовой карты: %u\n", bitmap_size);
|
||||
#endif
|
||||
|
||||
alloc_init(mem_frame_alloc(1024), 1024 * BLOCK_SIZE);
|
||||
#ifdef DEBUG_MEM
|
||||
LOG("%u мегабайт выделено в динамичную память\n", (256 * 16 * BLOCK_SIZE + BLOCK_SIZE) / 1024 / 1024);
|
||||
#endif
|
||||
|
||||
// Выделяем по 4 мегабайта в аллокатор динамичной памяти
|
||||
for (uint64_t i = 0; i < 32; i += 8) { mem_add_block(mem_frame_alloc(1024), 1024 * BLOCK_SIZE); }
|
||||
|
||||
mem_merge_all_blocks( );
|
||||
mem_dump_memory( );
|
||||
#ifdef DEBUG_MEM
|
||||
|
||||
LOG("%u МБ объем доступной памяти, %u МБ объем виртуальной памяти\n", (bitmap_available * BLOCK_SIZE) / 1024 / 1024,
|
||||
available / 1024 / 1024);
|
||||
|
||||
LOG("%u / %u блоков доступно\n", bitmap_available, bitmap_limit);
|
||||
#endif
|
||||
}
|
45
kernel/mod.c
45
kernel/mod.c
@ -24,7 +24,7 @@ module_info_t *module_list = NULL;
|
||||
static char *graphics_module_message = "Графический модуль-объект";
|
||||
static char *other_module_message = "Неизвестный тип модуля";
|
||||
|
||||
static env_t main_env;
|
||||
static env_t *main_env = NULL;
|
||||
|
||||
void *bootpng_ptr;
|
||||
uint64_t bootpng_size;
|
||||
@ -49,7 +49,7 @@ void mod_after_init( ) {
|
||||
for (uint64_t i = 0; i < modules_count; i++) {
|
||||
if (module_list[i].after_init != 0) {
|
||||
LOG("%s.after_init( );\n", module_list[i].name);
|
||||
task_new_thread(module_list[i].after_init, module_list[i].name);
|
||||
task_new_thread(module_list[i].after_init, module_list[i].name, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -125,37 +125,20 @@ void mod_init( ) {
|
||||
}
|
||||
|
||||
// LOG("\t->Точка входа: 0x%x\n", module_init);
|
||||
main_env = (env_t *)mem_alloc(sizeof(env_t));
|
||||
tool_memset(main_env, 0, sizeof(env_t));
|
||||
main_env->offset = (uint64_t)module_ptr->address;
|
||||
|
||||
main_env.offset = (uint64_t)module_ptr->address;
|
||||
|
||||
sys_install(&main_env);
|
||||
|
||||
uint64_t id = task_new_thread((void *)1, module_list[i].name);
|
||||
|
||||
module_info_t ret = module_init(&main_env);
|
||||
LOG("\t->%s\n", ret.message);
|
||||
|
||||
task_del(id);
|
||||
|
||||
module_list[modules_count].name = ret.name;
|
||||
module_list[modules_count].message = ret.message;
|
||||
module_list[modules_count].data_size = ret.data_size;
|
||||
module_list[modules_count].data = ret.data;
|
||||
module_list[modules_count].get_func = ret.get_func;
|
||||
module_list[modules_count].after_init = ret.after_init;
|
||||
|
||||
if (module_list[modules_count].after_init) {
|
||||
task_new_thread(module_list[modules_count].after_init, module_list[modules_count].name);
|
||||
}
|
||||
|
||||
if (ret.irq != 0) {
|
||||
if (ret.irq_handler != 0) {
|
||||
LOG("Установлен обработчик прерывания [%u] по адресу 0x%x в модуле %s\n", ret.irq, ret.irq_handler,
|
||||
ret.name);
|
||||
idt_set_int(ret.irq, ret.irq_handler);
|
||||
}
|
||||
}
|
||||
sys_install(main_env);
|
||||
|
||||
uint64_t id = task_new_thread((void (*)(void *))module_init, module_list[i].name, main_env);
|
||||
module_list[modules_count].env = (void *)main_env;
|
||||
module_list[modules_count].name = 0;
|
||||
module_list[modules_count].message = 0;
|
||||
module_list[modules_count].data_size = 0;
|
||||
module_list[modules_count].data = 0;
|
||||
module_list[modules_count].get_func = 0;
|
||||
module_list[modules_count].after_init = 0;
|
||||
modules_count++;
|
||||
}
|
||||
LOG("Модулей обработано: %u\n", modules_count);
|
||||
|
@ -60,9 +60,10 @@ env_t *sys_install(env_t *module) {
|
||||
module->get_info = &sys_get_info;
|
||||
module->get_module = &sys_get_module;
|
||||
module->mod_list_get = &mod_list_get;
|
||||
module->new_thread = &task_new_thread;
|
||||
module->new_thread = task_new_thread;
|
||||
module->delete_thread = &task_del_current;
|
||||
module->get_time = &rtc_get_time;
|
||||
module->ret = NULL;
|
||||
|
||||
return module;
|
||||
}
|
||||
|
@ -23,6 +23,17 @@ void *tool_memset(void *ptr, uint8_t n, uint64_t size) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void tool_memmove(void *dest, void *src, uint64_t n) {
|
||||
unsigned char *cdest = (unsigned char *)dest;
|
||||
unsigned char *csrc = (unsigned char *)src;
|
||||
|
||||
if (cdest < csrc) {
|
||||
for (uint64_t i = 0; i < n; i++) { cdest[i] = csrc[i]; }
|
||||
} else {
|
||||
for (uint64_t i = n; i > 0; i--) { cdest[i - 1] = csrc[i - 1]; }
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t tool_strlen(const char *str) {
|
||||
uint64_t length = 0;
|
||||
while (*str) {
|
||||
|
65
kernel/utf8cp.c
Normal file
65
kernel/utf8cp.c
Normal file
@ -0,0 +1,65 @@
|
||||
#include <mem.h>
|
||||
#include <tool.h>
|
||||
|
||||
#define NONS (0x98)
|
||||
#define SKIP_OR_NOT (dest != NONS)
|
||||
#define M(W40, W45, W201) ((((W40)-0x80) << 10) | (((W45) - (W40)) << 5) | ((W201)-0x80))
|
||||
|
||||
unsigned int utf8_2_win1251(const char *utf8, char *win) {
|
||||
unsigned int dest, p, l1, l2, l3, inc, i, j, b1, b2, b3;
|
||||
const unsigned short AR[16] = {
|
||||
M(NONS, NONS, 0x86), M(0xA8, 0xB8, 0x87), M(0x80, 0x90, 0x95), M(0x81, 0x83, 0x96),
|
||||
M(0xAA, 0xBA, 0x97), M(0xBD, 0xBE, NONS), M(0xB2, 0xB3, NONS), M(0xAF, 0xBF, NONS),
|
||||
M(0xA3, 0xBC, 0x91), M(0x8A, 0x9A, 0x92), M(0x8C, 0x9C, 0x82), M(0x8E, 0x9E, NONS),
|
||||
M(0x8D, 0x9D, 0x93), M(NONS, NONS, 0x94), M(0xA1, 0xA2, 0x84), M(0x8F, 0x9F, NONS)
|
||||
};
|
||||
|
||||
for (i = 0, j = 0; utf8[i] != 0; i += inc) {
|
||||
b1 = utf8[i];
|
||||
b2 = utf8[i + 1];
|
||||
b3 = utf8[i + 2];
|
||||
|
||||
// Utf8 переводим в Unicode.
|
||||
inc = (0xE5000000u >> (((b1) >> 4) << 1)) & 0x3;
|
||||
p = ((((b1) << 12) + (((b2)&0x3F) << 6) + ((b3)&0x3F)) & (0x7FFFF >> inc)) >>
|
||||
(((0xC5FFAAAAu >> (((b1) >> 4) << 1)) & 0x3) * 6);
|
||||
|
||||
// Добавляем все остающиеся на месте.
|
||||
dest = (((inc != 0) & (((p >> 5) != 0x5) | (0xF71C852E >> b2))) - 1) & p;
|
||||
inc++;
|
||||
|
||||
// Добавляем русские буквы кроме ё и Ё.
|
||||
dest += ((((p - 0x10) >> 6) != 0x10) - 1) & (p - 0x350);
|
||||
|
||||
// Добавляем символы из диапазонов: 0x401-0x40F, 0x451-0x45F, 0x2013-0x2022.
|
||||
l1 = ((p >> 4) != 0x40) - 1;
|
||||
l2 = ((p >> 4) != 0x45) - 1;
|
||||
l3 = (((p - 3) >> 4) != 0x201) - 1;
|
||||
dest += ((((l2 & (AR[p & 0xF] >> 5)) | (l3 & AR[p & 0xF])) & 0x1F) + ((l1 | l2) & (AR[p & 0xF] >> 10))) +
|
||||
((l1 | l2 | l3) & 0x80);
|
||||
|
||||
// Добавляем оставшиеся.
|
||||
dest += (((p != 0x490) - 1) & 0xA5) | (((p != 0x491) - 1) & 0xB4) | (((p != 0x2026) - 1) & 0x85) |
|
||||
(((p != 0x2030) - 1) & 0x89) | (((p != 0x2039) - 1) & 0x8B) | (((p != 0x203A) - 1) & 0x9B) |
|
||||
(((p != 0x20AC) - 1) & 0x88) | (((p != 0x2116) - 1) & 0xB9) | (((p != 0x2122) - 1) & 0x99);
|
||||
|
||||
// Отличаем настоящий 0 от просто отсутствующих в win 1251 символов.
|
||||
dest += (((b1 == 0) | (dest != 0)) - 1) & NONS;
|
||||
|
||||
win[j] = dest;
|
||||
j += SKIP_OR_NOT;
|
||||
}
|
||||
win[j] = 0;
|
||||
return j;
|
||||
}
|
||||
|
||||
#undef M
|
||||
#undef NONS
|
||||
#undef SKIP_OR_NOT
|
||||
|
||||
char *utf8cp(char *str) {
|
||||
size_t len = tool_strlen(str);
|
||||
char *result = (char *)mem_alloc(len + 1);
|
||||
if (result) { utf8_2_win1251(str, result); }
|
||||
return result;
|
||||
}
|
@ -25,6 +25,9 @@ time_t (*get_time)( );
|
||||
uint64_t offset;
|
||||
|
||||
void init_env(env_t *loader_env) {
|
||||
if (loader_env == NULL) {
|
||||
for (;;) {}
|
||||
}
|
||||
offset = loader_env->offset;
|
||||
log_printf = loader_env->log_printf;
|
||||
alloc = loader_env->alloc;
|
||||
|
@ -57,7 +57,7 @@ static void cpu_info( ) {
|
||||
log_printf(" Узлы на процессор: %u\n", nodes_per_processor);
|
||||
}
|
||||
|
||||
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
void __attribute__((section(".minit"))) init(env_t *env) {
|
||||
uint32_t eax, ebx, ecx, edx;
|
||||
|
||||
init_env(env);
|
||||
@ -77,15 +77,16 @@ module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
|
||||
if (eax >= 0x8000001E) { cpu_info( ); }
|
||||
|
||||
return (module_info_t){ .name = (char *)"CPUBENCH",
|
||||
.message = (char *)"Дополнительная информация о процессоре",
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)0,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
.irq_handler = 0,
|
||||
.get_func = 0,
|
||||
.after_init = 0 };
|
||||
env->ret = &((module_info_t){ .name = (char *)"CPUBENCH",
|
||||
.message = (char *)"Дополнительная информация о процессоре",
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)0,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
.irq_handler = 0,
|
||||
.get_func = 0,
|
||||
.after_init = 0 });
|
||||
delete_thread( );
|
||||
}
|
@ -61,20 +61,21 @@ static int app_main( ) {
|
||||
return 2 + 2;
|
||||
}
|
||||
|
||||
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
void __attribute__((section(".minit"))) init(env_t *env) {
|
||||
init_env(env);
|
||||
log_printf("[%s]\n", message);
|
||||
log_printf("%s\n", logo);
|
||||
log_printf("%s\n", logo_synapseos);
|
||||
return (module_info_t){ .name = (char *)&name,
|
||||
.message = (char *)&message,
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)&app_main,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
.irq_handler = 0,
|
||||
.get_func = 0,
|
||||
.after_init = 0 };
|
||||
env->ret = &((module_info_t){ .name = (char *)&name,
|
||||
.message = (char *)&message,
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)&app_main,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
.irq_handler = 0,
|
||||
.get_func = 0,
|
||||
.after_init = 0 });
|
||||
delete_thread( );
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ void print_folder_contents(folder_t *folder, size_t depth) {
|
||||
}
|
||||
}
|
||||
|
||||
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
void __attribute__((section(".minit"))) init(env_t *env) {
|
||||
init_env(env);
|
||||
create_folder("", NULL);
|
||||
|
||||
@ -154,17 +154,17 @@ module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
file_t *readme = create_file("readme", "txt", root_folder);
|
||||
write_file(readme, "БМПОС 2023-2024", 21);
|
||||
|
||||
return (module_info_t){
|
||||
.name = (char *)"[FS][IMFS]",
|
||||
.message = (char *)"IMFS (in memory filesystem) - файловая система работающая исключительно в ОЗУ.",
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)0,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
.irq_handler = 0,
|
||||
.get_func = 0,
|
||||
.after_init = 0
|
||||
};
|
||||
env->ret = &((module_info_t){
|
||||
.name = (char *)"[FS][IMFS]",
|
||||
.message = (char *)"IMFS (in memory filesystem) - файловая система работающая исключительно в ОЗУ.",
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)0,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
.irq_handler = 0,
|
||||
.get_func = 0,
|
||||
.after_init = 0 });
|
||||
delete_thread( );
|
||||
}
|
||||
|
@ -98,18 +98,19 @@ static void main( ) {
|
||||
for (;;) { asm volatile("hlt"); }
|
||||
}
|
||||
|
||||
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
void __attribute__((section(".minit"))) init(env_t *env) {
|
||||
init_env(env);
|
||||
|
||||
return (module_info_t){ .name = (char *)"[IOS]",
|
||||
.message = (char *)"IOS (input-output shell) - оболочка ввода-вывода.",
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)0,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
.irq_handler = 0,
|
||||
.get_func = 0,
|
||||
.after_init = main };
|
||||
env->ret = &((module_info_t){ .name = (char *)"[IOS]",
|
||||
.message = (char *)"IOS (input-output shell) - оболочка ввода-вывода.",
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)0,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
.irq_handler = 0,
|
||||
.get_func = 0,
|
||||
.after_init = main });
|
||||
delete_thread( );
|
||||
}
|
||||
|
@ -114,10 +114,24 @@ static inline void scan( ) {
|
||||
}
|
||||
}
|
||||
|
||||
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
module_info_t mod = { .name = (char *)"[PCI]",
|
||||
.message = (char *)"PCI драйвер",
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)0,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
.irq_handler = 0,
|
||||
.get_func = 0,
|
||||
.after_init = 0 };
|
||||
|
||||
void __attribute__((section(".minit"))) init(env_t *env) {
|
||||
init_env(env);
|
||||
|
||||
log_printf("pci_data %x\n", 1);
|
||||
module_info_t *pci_data = get_module("[PCI][ADAPTER]");
|
||||
log_printf("pci_data %x\n", pci_data);
|
||||
|
||||
if (pci_data == NULL) {
|
||||
log_printf("Адаптер PCI данных не найден!\n");
|
||||
@ -129,15 +143,6 @@ module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
}
|
||||
|
||||
scan( );
|
||||
return (module_info_t){ .name = (char *)"[PCI]",
|
||||
.message = (char *)"PCI драйвер",
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)0,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
.irq_handler = 0,
|
||||
.get_func = 0,
|
||||
.after_init = 0 };
|
||||
env->ret = &mod;
|
||||
delete_thread( );
|
||||
}
|
@ -59,7 +59,19 @@ static void print_vendors(uint64_t num_vendors, vendor_t **vendor_list) {
|
||||
}
|
||||
}
|
||||
|
||||
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
module_info_t mod = { .name = (char *)"[PCI][ADAPTER]",
|
||||
.message = (char *)"PCI данные",
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = 0,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
.irq_handler = 0,
|
||||
.get_func = 0,
|
||||
.after_init = 0 };
|
||||
|
||||
void __attribute__((section(".minit"))) init(env_t *env) {
|
||||
init_env(env);
|
||||
|
||||
module_info_t *pci_data = get_module("[PCI][DATA][VENDORS]");
|
||||
@ -71,15 +83,9 @@ module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
|
||||
vendor_t **vendor_list = parse_file(pci_data->data, num_vendors, pci_data->data_size);
|
||||
// print_vendors(num_vendors, vendor_list);
|
||||
return (module_info_t){ .name = (char *)"[PCI][ADAPTER]",
|
||||
.message = (char *)"PCI данные",
|
||||
.type = 0,
|
||||
.data_size = num_vendors,
|
||||
.data = vendor_list,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
.irq_handler = 0,
|
||||
.get_func = 0,
|
||||
.after_init = 0 };
|
||||
mod.data_size = num_vendors;
|
||||
mod.data = vendor_list;
|
||||
env->ret = &mod;
|
||||
log_printf("Готово22\n");
|
||||
delete_thread( );
|
||||
}
|
@ -145,20 +145,21 @@ static void handler( ) {
|
||||
after_interrupt( );
|
||||
}
|
||||
|
||||
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
void __attribute__((section(".minit"))) init(env_t *env) {
|
||||
init_env(env);
|
||||
current_state = NORMAL_STATE;
|
||||
keyboard_buffer.ctrl_pressed = 0;
|
||||
keyboard_buffer.shift_pressed = 0;
|
||||
|
||||
return (module_info_t){ .name = (char *)"[KEYBOARD]",
|
||||
.message = (char *)"PS/2 драйвер",
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)0,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 33,
|
||||
.irq_handler = &handler,
|
||||
.get_func = __get_func };
|
||||
env->ret = &((module_info_t){ .name = (char *)"[KEYBOARD]",
|
||||
.message = (char *)"PS/2 драйвер",
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)0,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 33,
|
||||
.irq_handler = &handler,
|
||||
.get_func = __get_func });
|
||||
delete_thread( );
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#/bin/sh
|
||||
echo "Название: SIMD"
|
||||
echo "Лицензия: Публичное достояние"
|
||||
|
||||
CC=${CC:-gcc}
|
||||
ARCH_FLAGS="-fno-stack-protector -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 simd.o
|
||||
$CC $ARCH_FLAGS -Wl,--entry=init,--build-id=none -T ../link.ld simd.o -L../../modlib/lib/ -lmod -o simd.ko
|
||||
|
||||
cp simd.ko ../bin/
|
||||
echo "Сборка завершена, файл: simd.ko"
|
@ -1,43 +0,0 @@
|
||||
#include <system.h>
|
||||
|
||||
static char fxsave_region[512] __attribute__((aligned(16)));
|
||||
|
||||
static inline void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) {
|
||||
asm volatile("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "a"(leaf));
|
||||
}
|
||||
|
||||
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
init_env(env);
|
||||
|
||||
uint32_t eax, ebx, ecx, edx;
|
||||
cpuid(1, &eax, &ebx, &ecx, &edx);
|
||||
|
||||
if ((edx >> 0) & 1) {
|
||||
asm volatile("finit");
|
||||
log_printf("FPU(x87) поддерживается!\n");
|
||||
}
|
||||
|
||||
if ((edx >> 23) & 1) { log_printf("MMX поддерживается!\n"); }
|
||||
|
||||
if ((edx >> 25) & 1) {
|
||||
log_printf("SSE2 поддерживается!\n");
|
||||
log_printf("Адрес региона fxsave 0x%x\n", &fxsave_region);
|
||||
asm volatile(" fxsave %0 " ::"m"(fxsave_region));
|
||||
uint32_t sse_version = (ecx >> 25) & 0x7;
|
||||
log_printf("SSE%u включен\n", sse_version);
|
||||
}
|
||||
|
||||
if ((ecx >> 28) & 1) { log_printf("AVX поддерживается!\n"); }
|
||||
|
||||
return (module_info_t){ .name = (char *)"SIMD",
|
||||
.message = (char *)"SIMD инструкции",
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)0,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
.irq_handler = 0,
|
||||
.get_func = 0,
|
||||
.after_init = 0 };
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 47 KiB |
Binary file not shown.
@ -1,19 +0,0 @@
|
||||
#/bin/sh
|
||||
echo "Название: TGA"
|
||||
echo "Лицензия: Публичное достояние"
|
||||
|
||||
CC=${CC:-gcc}
|
||||
ARCH_FLAGS="-fno-stack-protector -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 -Wl,--entry=init,--build-id=none -T ../link.ld tga.o -L../../modlib/lib/ -lmod -o tga.ko
|
||||
|
||||
cp boot.jpg ../bin/
|
||||
cp boot.tga ../bin/
|
||||
cp tga.ko ../bin/
|
||||
echo "Сборка завершена, файл: tga.ko"
|
@ -1,189 +0,0 @@
|
||||
#include <system.h>
|
||||
|
||||
#define TGA_ERR( ) log_printf("Ошибка декодирования TGA на строчке: %u\n", __LINE__);
|
||||
|
||||
typedef struct {
|
||||
unsigned char magic1; // должно быть нулевым
|
||||
unsigned char colormap; // должно быть нулевым
|
||||
unsigned char encoding; // должно быть 2
|
||||
unsigned short cmaporig, cmaplen; // должны быть нулевыми
|
||||
unsigned char cmapent; // должно быть нулевым
|
||||
unsigned short x; // должно быть нулевым
|
||||
unsigned short y; // высота изображения
|
||||
unsigned short h; // высота изображения
|
||||
unsigned short w; // ширина изображения
|
||||
unsigned char bpp; // должно быть 32
|
||||
unsigned char pixeltype; // должно быть 40
|
||||
} __attribute__((packed)) tga_header_t;
|
||||
|
||||
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 *)alloc((w * h + 2) * sizeof(unsigned int));
|
||||
if (!data) { return NULL; }
|
||||
memset(data, 0, (w * h + 2) * sizeof(unsigned int));
|
||||
|
||||
switch (ptr[2]) {
|
||||
case 1:
|
||||
if (ptr[6] != 0 || ptr[4] != 0 || ptr[3] != 0 || (ptr[7] != 24 && ptr[7] != 32)) {
|
||||
TGA_ERR( );
|
||||
free(data);
|
||||
return NULL;
|
||||
}
|
||||
for (y = i = 0; y < h; y++) {
|
||||
k = ((!o ? h - y - 1 : y) * w);
|
||||
for (x = 0; x < w; x++) {
|
||||
j = ptr[m + k++] * (ptr[7] >> 3) + 18;
|
||||
data[2 + i++] =
|
||||
((ptr[7] == 32 ? ptr[j + 3] : 0xFF) << 24) | (ptr[j + 2] << 16) | (ptr[j + 1] << 8) | ptr[j];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (ptr[5] != 0 || ptr[6] != 0 || ptr[1] != 0 || (ptr[16] != 24 && ptr[16] != 32)) {
|
||||
TGA_ERR( );
|
||||
free(data);
|
||||
return NULL;
|
||||
}
|
||||
for (y = i = 0; y < h; y++) {
|
||||
j = ((!o ? h - y - 1 : y) * w * (ptr[16] >> 3));
|
||||
for (x = 0; x < w; x++) {
|
||||
data[2 + i++] =
|
||||
((ptr[16] == 32 ? ptr[j + 3] : 0xFF) << 24) | (ptr[j + 2] << 16) | (ptr[j + 1] << 8) | ptr[j];
|
||||
j += ptr[16] >> 3;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
if (ptr[6] != 0 || ptr[4] != 0 || ptr[3] != 0 || (ptr[7] != 24 && ptr[7] != 32)) {
|
||||
TGA_ERR( );
|
||||
free(data);
|
||||
return NULL;
|
||||
}
|
||||
y = i = 0;
|
||||
for (x = 0; x < w * h && m < size;) {
|
||||
k = ptr[m++];
|
||||
if (k > 127) {
|
||||
k -= 127;
|
||||
x += k;
|
||||
j = ptr[m++] * (ptr[7] >> 3) + 18;
|
||||
while (k--) {
|
||||
if (!(i % w)) {
|
||||
i = ((!o ? h - y - 1 : y) * w);
|
||||
y++;
|
||||
}
|
||||
data[2 + i++] = ((ptr[7] == 32 ? ptr[j + 3] : 0xFF) << 24) | (ptr[j + 2] << 16) |
|
||||
(ptr[j + 1] << 8) | ptr[j];
|
||||
}
|
||||
} else {
|
||||
k++;
|
||||
x += k;
|
||||
while (k--) {
|
||||
j = ptr[m++] * (ptr[7] >> 3) + 18;
|
||||
if (!(i % w)) {
|
||||
i = ((!o ? h - y - 1 : y) * w);
|
||||
y++;
|
||||
}
|
||||
data[2 + i++] = ((ptr[7] == 32 ? ptr[j + 3] : 0xFF) << 24) | (ptr[j + 2] << 16) |
|
||||
(ptr[j + 1] << 8) | ptr[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
if (ptr[5] != 0 || ptr[6] != 0 || ptr[1] != 0 || (ptr[16] != 24 && ptr[16] != 32)) {
|
||||
TGA_ERR( );
|
||||
free(data);
|
||||
return NULL;
|
||||
}
|
||||
y = i = 0;
|
||||
for (x = 0; x < w * h && m < size;) {
|
||||
k = ptr[m++];
|
||||
if (k > 127) {
|
||||
k -= 127;
|
||||
x += k;
|
||||
while (k--) {
|
||||
if (!(i % w)) {
|
||||
i = ((!o ? h - y - 1 : y) * w);
|
||||
y++;
|
||||
}
|
||||
data[2 + i++] = ((ptr[16] == 32 ? ptr[m + 3] : 0xFF) << 24) | (ptr[m + 2] << 16) |
|
||||
(ptr[m + 1] << 8) | ptr[m];
|
||||
}
|
||||
m += ptr[16] >> 3;
|
||||
} else {
|
||||
k++;
|
||||
x += k;
|
||||
while (k--) {
|
||||
if (!(i % w)) {
|
||||
i = ((!o ? h - y - 1 : y) * w);
|
||||
y++;
|
||||
}
|
||||
data[2 + i++] = ((ptr[16] == 32 ? ptr[m + 3] : 0xFF) << 24) | (ptr[m + 2] << 16) |
|
||||
(ptr[m + 1] << 8) | ptr[m];
|
||||
m += ptr[16] >> 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
TGA_ERR( );
|
||||
free(data);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
data[0] = w;
|
||||
data[1] = h;
|
||||
return data;
|
||||
}
|
||||
|
||||
static void *handler(uint64_t func) {
|
||||
switch (func) {
|
||||
case 0: return tga_parse;
|
||||
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
init_env(env);
|
||||
|
||||
module_info_t *boot_tga = get_module("[BOOTIMG]");
|
||||
|
||||
if (boot_tga != NULL) {
|
||||
#if 0
|
||||
framebuffer_t screen = alloc_framebuffer( );
|
||||
uint32_t *screen_buf = screen.address;
|
||||
|
||||
uint32_t *img = tga_parse(boot_tga->data, boot_tga->data_size);
|
||||
uint32_t width = img[0];
|
||||
uint32_t height = img[1];
|
||||
uint32_t *img_data = (uint32_t *)img + 2;
|
||||
|
||||
for (uint32_t w = 0; w < width; w++) {
|
||||
for (uint32_t h = 0; h < height; h++) {
|
||||
if (*img_data == 0x013220) {
|
||||
*img_data++;
|
||||
continue;
|
||||
}
|
||||
screen_buf[w * height + h] = *img_data++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
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 };
|
||||
}
|
4
run.sh
4
run.sh
@ -1,10 +1,10 @@
|
||||
#!/bin/sh
|
||||
qemu-system-x86_64 -name "БМПОС" -cpu max -m 64M -smp 1 \
|
||||
-serial file:serial.log \
|
||||
-drive file=bmosp.hdd,if=none,id=sata_drive -device ahci \
|
||||
-drive file=bmosp.iso,if=none,id=sata_drive -device ahci \
|
||||
-device virtio-blk-pci,drive=sata_drive \
|
||||
-rtc base=localtime,clock=host \
|
||||
--no-reboot -no-shutdown \
|
||||
--no-reboot -no-shutdown -boot d \
|
||||
-net nic,model=pcnet # AMD PCnet Am79C970
|
||||
#qemu-system-x86_64 -name "БМПОС" -cpu max -m 1G -smp 1 -hda bmosp.hdd --no-reboot
|
||||
#qemu-system-x86_64 -name "БМПОС" -cpu max -m 1G -smp 1 -cdrom bmosp.iso -boot d --no-reboot
|
||||
|
@ -14,9 +14,9 @@ if "^.M" in output:
|
||||
ARCH_FLAGS = "-m64 -march=x86-64 -mabi=sysv -mno-red-zone -mcmodel=kernel -MMD -MP"
|
||||
WARN_FLAGS = "-Wall -Wextra -nostdlib"
|
||||
STANDART_FLAGS = f"-std=gnu11 -DKERNEL_GIT_TAG=\\\"{__VERSION}\\\"" # -DNO_DEBUG=1
|
||||
PROTECT_FLAGS = "-O0 -g -pipe -ffreestanding -fno-stack-protector -fno-lto -fno-stack-check -fno-PIC -fno-PIE"
|
||||
PROTECT_FLAGS += " -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx"
|
||||
CHARSET_FLAGS = "-finput-charset=UTF-8 -fexec-charset=cp1251"
|
||||
PROTECT_FLAGS = "-O0 -pipe -ffreestanding -fno-stack-protector -fno-lto -fno-stack-check -fno-PIC -fno-PIE"
|
||||
PROTECT_FLAGS += " -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -ffunction-sections -fdata-sections"
|
||||
CHARSET_FLAGS = "-finput-charset=UTF-8 -fexec-charset=cp1251" #""
|
||||
LIBS_FLAGS = "-Ilimine -Iinclude"
|
||||
FORMAT_CMD = """find . \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) -print0 | xargs -0 clang-format -i -style=file"""
|
||||
|
||||
@ -91,7 +91,7 @@ def compile_all():
|
||||
|
||||
def check_limine():
|
||||
if not os.path.isdir("limine"):
|
||||
subprocess.run(["git", "clone", "https://git.synapseos.ru/Aren/limine.git", "--branch=v5.x-branch-binary", "--depth=1"])
|
||||
subprocess.run(["git", "clone", "https://git.synapseos.ru/mirrors/limine.git", "--branch=v5.x-branch-binary", "--depth=1"])
|
||||
else:
|
||||
os.chdir("limine")
|
||||
subprocess.run(["git", "pull"])
|
||||
@ -100,19 +100,6 @@ def check_limine():
|
||||
subprocess.run(["make"])
|
||||
os.chdir("..")
|
||||
|
||||
def create_hdd(IMAGE_NAME):
|
||||
os.system(f"rm -f {IMAGE_NAME}.hdd".format())
|
||||
os.system(f"dd if=/dev/zero bs=1M count=0 seek=4 of={IMAGE_NAME}.hdd")
|
||||
os.system(f"sgdisk {IMAGE_NAME}.hdd -n 1:2048 -t 1:ef00")
|
||||
os.system(f"./limine/limine bios-install {IMAGE_NAME}.hdd")
|
||||
os.system(f"mformat -i {IMAGE_NAME}.hdd@@1M")
|
||||
os.system(f"mmd -i {IMAGE_NAME}.hdd@@1M ::/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 iso_root/mod/ ::/")
|
||||
os.system(f"mcopy -i {IMAGE_NAME}.hdd@@1M limine/BOOTX64.EFI limine/BOOTIA32.EFI ::/EFI/BOOT")
|
||||
os.system(f"./limine/limine bios-install {IMAGE_NAME}.hdd")
|
||||
|
||||
|
||||
def create_iso(IMAGE_NAME):
|
||||
os.system(f"rm -f {IMAGE_NAME}.iso")
|
||||
os.system(f"rm -rf iso_root")
|
||||
@ -165,7 +152,4 @@ if __name__ == "__main__":
|
||||
print("Создание ISO образа")
|
||||
create_iso("bmosp")
|
||||
|
||||
print("Создание HDD образа")
|
||||
create_hdd("bmosp")
|
||||
|
||||
print(f"Не забудьте сохранить изменения! Номер сборки: {major}.{minor}.{build}")
|
||||
|
Loading…
Reference in New Issue
Block a user