mirror of
https://github.com/0Nera/BMOSP.git
synced 2025-01-05 12:24:27 +03:00
Небольшие оптимизации
This commit is contained in:
parent
e31c9db524
commit
933baa57f9
@ -24,6 +24,7 @@ typedef struct task {
|
|||||||
uint64_t cpu_time;
|
uint64_t cpu_time;
|
||||||
uint64_t cpu_time_expired;
|
uint64_t cpu_time_expired;
|
||||||
uint64_t id;
|
uint64_t id;
|
||||||
|
char *id_str;
|
||||||
void *stack;
|
void *stack;
|
||||||
|
|
||||||
struct task *last;
|
struct task *last;
|
||||||
@ -59,12 +60,15 @@ typedef void (*int_entry_t)(struct frame *state);
|
|||||||
|
|
||||||
extern lock_t task_lock;
|
extern lock_t task_lock;
|
||||||
extern uint64_t task_f_init;
|
extern uint64_t task_f_init;
|
||||||
|
extern task_t *current_task;
|
||||||
|
|
||||||
void arch_init( );
|
void arch_init( );
|
||||||
void task_init( );
|
void task_init( );
|
||||||
|
void task_after_init( );
|
||||||
void task_switch( );
|
void task_switch( );
|
||||||
uint64_t task_new_thread(void (*func)(void *));
|
uint64_t task_new_thread(void (*func)(void *), char *name);
|
||||||
void task_del_current( );
|
void task_del_current( );
|
||||||
|
void task_del(uint64_t id);
|
||||||
void cpu_init( );
|
void cpu_init( );
|
||||||
void pic_init( );
|
void pic_init( );
|
||||||
void pit_init( );
|
void pit_init( );
|
||||||
|
@ -76,7 +76,7 @@ typedef struct {
|
|||||||
sys_info_t *(*get_info)( );
|
sys_info_t *(*get_info)( );
|
||||||
module_info_t *(*get_module)(char *module_id);
|
module_info_t *(*get_module)(char *module_id);
|
||||||
module_info_t *(*mod_list_get)(uint64_t *count);
|
module_info_t *(*mod_list_get)(uint64_t *count);
|
||||||
uint64_t (*new_thread)(void (*func)(void *));
|
uint64_t (*new_thread)(void (*func)(void *), char *name);
|
||||||
void (*delete_thread)( );
|
void (*delete_thread)( );
|
||||||
time_t (*get_time)( );
|
time_t (*get_time)( );
|
||||||
} __attribute__((packed)) env_t;
|
} __attribute__((packed)) env_t;
|
||||||
|
55
kernel/mem.c
55
kernel/mem.c
@ -24,7 +24,8 @@ static volatile struct limine_hhdm_request hhdm_request = { .id = LIMINE_HHDM_RE
|
|||||||
struct mem_entry {
|
struct mem_entry {
|
||||||
struct mem_entry *next;
|
struct mem_entry *next;
|
||||||
bool free;
|
bool free;
|
||||||
size_t size;
|
uint64_t task_id;
|
||||||
|
uint64_t size;
|
||||||
uint8_t data[0];
|
uint8_t data[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -47,6 +48,9 @@ static uint64_t highest = 0;
|
|||||||
// Количество записей в карте памяти
|
// Количество записей в карте памяти
|
||||||
static uint64_t mmmap_count = 0;
|
static uint64_t mmmap_count = 0;
|
||||||
|
|
||||||
|
extern task_t *current_task;
|
||||||
|
extern uint64_t full_init;
|
||||||
|
|
||||||
static const char memory_types[8][82] = { "Доступно", "Зарезервировано", "ACPI, можно освободить",
|
static const char memory_types[8][82] = { "Доступно", "Зарезервировано", "ACPI, можно освободить",
|
||||||
"ACPI NVS", "Плохая память", "Загрузчик, можно освободить",
|
"ACPI NVS", "Плохая память", "Загрузчик, можно освободить",
|
||||||
"Ядро и модули", "Буфер кадра" };
|
"Ядро и модули", "Буфер кадра" };
|
||||||
@ -60,11 +64,11 @@ void mem_dump_memory( ) {
|
|||||||
|
|
||||||
while (curr) {
|
while (curr) {
|
||||||
if (curr->next) {
|
if (curr->next) {
|
||||||
LOG("->0x%x | %u мегабайт | %s | 0x%x\n", &curr->data, (curr->size) / 1024 / 1024,
|
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->free ? memory_types[0] : memory_types[1], curr->next, curr->task_id);
|
||||||
} else {
|
} else {
|
||||||
LOG("->0x%x | %u мегабайт | %s | Это последний блок\n", &curr->data, (curr->size) / 1024 / 1024,
|
LOG("->0x%x | %u мегабайт | %s | поток %u | Это последний блок\n", &curr->data, (curr->size) / 1024 / 1024,
|
||||||
curr->free ? memory_types[0] : memory_types[1]);
|
curr->free ? memory_types[0] : memory_types[1], curr->task_id);
|
||||||
}
|
}
|
||||||
curr = curr->next;
|
curr = curr->next;
|
||||||
}
|
}
|
||||||
@ -153,7 +157,12 @@ static void merge_blocks(mem_entry_t *start) {
|
|||||||
mem_entry_t *block = start;
|
mem_entry_t *block = start;
|
||||||
while (block->next && block->next->free) {
|
while (block->next && block->next->free) {
|
||||||
block->size += block->next->size + sizeof(mem_entry_t);
|
block->size += block->next->size + sizeof(mem_entry_t);
|
||||||
block->next = block->next->next;
|
|
||||||
|
if (block->next->next) {
|
||||||
|
block->next = block->next->next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
block->next = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,33 +205,37 @@ static void *alloc_align(size_t size, size_t alignment) {
|
|||||||
mem_entry_t *curr = first_node;
|
mem_entry_t *curr = first_node;
|
||||||
|
|
||||||
while (curr) {
|
while (curr) {
|
||||||
if (curr->free) {
|
if (curr->free && curr->size >= (alignment + sizeof(mem_entry_t) + size)) {
|
||||||
void *addr = curr->data + alignment - 1;
|
void *addr = curr->data + alignment - 1;
|
||||||
addr -= (uintptr_t)addr % alignment + sizeof(mem_entry_t);
|
addr -= (uintptr_t)addr % alignment + sizeof(mem_entry_t);
|
||||||
mem_entry_t *second = (mem_entry_t *)addr;
|
mem_entry_t *second = (mem_entry_t *)addr;
|
||||||
if (curr->size >= (second->data - curr->data + size)) {
|
|
||||||
mem_entry_t *third = (mem_entry_t *)(second->data + size);
|
|
||||||
|
|
||||||
third->size = curr->size - (third->data - curr->data);
|
mem_entry_t *third = (mem_entry_t *)(second->data + size);
|
||||||
third->next = curr->next;
|
tool_memset(third, 0, sizeof(mem_entry_t));
|
||||||
third->free = 1;
|
|
||||||
|
|
||||||
second->size = size;
|
third->size = curr->size - (third->data - curr->data);
|
||||||
second->next = third;
|
third->next = curr->next;
|
||||||
second->free = 0;
|
third->free = 1;
|
||||||
|
|
||||||
if (curr != second) {
|
second->size = size;
|
||||||
curr->next = second;
|
second->next = third;
|
||||||
curr->size = (uintptr_t)second - (uintptr_t)curr->data;
|
second->free = 0;
|
||||||
curr->free = 1;
|
second->task_id = 0;
|
||||||
}
|
|
||||||
|
|
||||||
return second->data;
|
if (full_init) { second->task_id = current_task->id; }
|
||||||
|
|
||||||
|
if (curr != second) {
|
||||||
|
curr->next = second;
|
||||||
|
curr->size = (uintptr_t)second - (uintptr_t)curr->data;
|
||||||
|
curr->free = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return second->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
curr = curr->next;
|
curr = curr->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,11 +16,16 @@
|
|||||||
#include <version.h>
|
#include <version.h>
|
||||||
|
|
||||||
uint64_t full_init = 0;
|
uint64_t full_init = 0;
|
||||||
|
uint64_t dum = 0;
|
||||||
|
|
||||||
void finally( ) {
|
void finally( ) {
|
||||||
LOG("Готово! Для выхода из симуляции удерживайте: ESCAPE\n");
|
LOG("Готово! Для выхода из симуляции удерживайте: ESCAPE\n");
|
||||||
mod_after_init( );
|
for (;;) { asm volatile("hlt"); }
|
||||||
for (;;) { task_switch( ); }
|
}
|
||||||
|
|
||||||
|
void dummy( ) {
|
||||||
|
LOG("Поток %u\n", dum++);
|
||||||
|
task_del(current_task->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Точка входа
|
// Точка входа
|
||||||
@ -32,6 +37,8 @@ void _start( ) {
|
|||||||
fb_init( );
|
fb_init( );
|
||||||
log_init_mem( );
|
log_init_mem( );
|
||||||
arch_init( );
|
arch_init( );
|
||||||
|
pit_init( );
|
||||||
|
task_init( );
|
||||||
mod_init( );
|
mod_init( );
|
||||||
|
|
||||||
LOG("\t\t\t\t *** Базовая Модульная Платформа Операционных Систем "
|
LOG("\t\t\t\t *** Базовая Модульная Платформа Операционных Систем "
|
||||||
@ -41,16 +48,22 @@ void _start( ) {
|
|||||||
LOG("\t\t\t\t *** Дата сборки: %s %s ***\n", __DATE__, __TIME__);
|
LOG("\t\t\t\t *** Дата сборки: %s %s ***\n", __DATE__, __TIME__);
|
||||||
|
|
||||||
time_t time = rtc_get_time( );
|
time_t time = rtc_get_time( );
|
||||||
LOG("Время: %2u:%2u.%2u, %2u.%2u.%2u\n", time.hours, time.minutes, time.second, time.day, time.month, time.year);
|
LOG("Время: %u:%u.%u, %u.%u.%u\n", time.hours, time.minutes, time.second, time.day, time.month, time.year);
|
||||||
|
|
||||||
pit_init( );
|
task_new_thread(finally, "fin");
|
||||||
task_init( );
|
|
||||||
|
|
||||||
task_new_thread(finally);
|
|
||||||
|
|
||||||
full_init = 1;
|
full_init = 1;
|
||||||
task_f_init = 1;
|
task_f_init = 1;
|
||||||
|
|
||||||
|
task_after_init( );
|
||||||
|
|
||||||
|
for (uint64_t i = 0; i < 6; i++) {
|
||||||
|
char *buf = mem_alloc(32);
|
||||||
|
tool_strcpy(buf, "dum");
|
||||||
|
tool_uint_to_str(i, 10, buf + 3);
|
||||||
|
task_new_thread(dummy, buf);
|
||||||
|
}
|
||||||
|
|
||||||
asm volatile("sti");
|
asm volatile("sti");
|
||||||
|
|
||||||
for (;;) { asm volatile("hlt"); }
|
for (;;) { asm volatile("hlt"); }
|
||||||
|
@ -189,9 +189,7 @@ char *trstr(char *str, char sym) {
|
|||||||
else
|
else
|
||||||
left = 0x00U;
|
left = 0x00U;
|
||||||
|
|
||||||
char *res = alloc(size);
|
return str + left;
|
||||||
memcpy(res, str + left, size);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strdup(char *str) {
|
char *strdup(char *str) {
|
||||||
|
@ -7,7 +7,7 @@ static int ru = 1;
|
|||||||
static char c_char = '\0';
|
static char c_char = '\0';
|
||||||
static key_event_t keyboard_buffer;
|
static key_event_t keyboard_buffer;
|
||||||
|
|
||||||
static void virt_exit( ) {
|
void virt_exit( ) {
|
||||||
fb_printf("Выход для Bochs\n");
|
fb_printf("Выход для Bochs\n");
|
||||||
outw(0xB004, 0x2000);
|
outw(0xB004, 0x2000);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user