Новая система отладки

This commit is contained in:
Aren Elchinyan 2024-01-13 00:00:11 +03:00
parent 9c11be08c9
commit b6ad573dfa
27 changed files with 258 additions and 281 deletions

View File

@ -19,6 +19,9 @@
"stdbool.h": "c",
"stdint.h": "c",
"types.h": "c",
"random": "c"
"random": "c",
"6x8_slim_font.h": "c",
"log.h": "c",
"mem.h": "c"
}
}

View File

@ -65,6 +65,8 @@ 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_bytes(char *c, uint64_t n);
static inline void outb(uint16_t port, uint8_t val) {
asm volatile("outb %0, %1" : : "a"(val), "Nd"(port));
@ -92,7 +94,7 @@ static inline void io_wait( ) {
static inline void print_stack_trace( ) {
uint64_t *rsp;
asm volatile("movq %%rsp, %0;" : "=g"(rsp));
asm volatile("movq %%rsp, %0" : "=g"(rsp));
while (rsp) {
// fb_printf("%x\n", *rsp);
@ -100,4 +102,7 @@ static inline void print_stack_trace( ) {
}
}
#define GET_TICK_BIG arch_get_tick_b( )
#define GET_TICK_lOW arch_get_tick_l( )
#endif // arch.h

View File

@ -10,6 +10,7 @@
#ifndef FB_H
#define FB_H
#include <6x8_slim_font.h>
#include <arch.h>
#include <stdarg.h>
#include <stddef.h>
@ -26,26 +27,21 @@ enum colors {
DARK_GREEN = 0x013220,
};
#define GET_TICK_BIG arch_get_tick_b( )
#define GET_TICK_lOW arch_get_tick_l( )
extern int fb_init_status;
extern uint32_t *fb_addr;
extern uint64_t width;
extern uint64_t height;
#define SCREEN_WIDTH width
#define SCREEN_HEIGHT height
#define SCREEN_BUFFER fb_addr
#ifndef NO_DEBUG
#define LOG(...) \
fb_printf("[%4u]%s() (%s:%d) ", GET_TICK_BIG, __func__, __FILE__, __LINE__); \
fb_printf(__VA_ARGS__)
#else
#define LOG(...)
#endif
void fb_set_text_color(uint32_t color);
uint32_t fb_get_text_color( );
void fb_init( );
void fb_print_buf(size_t x, size_t y, size_t h, size_t w, uint32_t *buf);
void fb_printf(char *str, ...);
void fb_printf_at(size_t x, size_t y, char *str, ...);
void fb_print_bits(size_t x, size_t y, uint8_t num);
#endif // fb.h

33
include/log.h Normal file
View File

@ -0,0 +1,33 @@
/**
* log.h
* Заголовок с функциями отладки
*
* Данный заголовочный файл содержит определения которые используются для работы
* с системным отладчиком
*
*/
#ifndef LOG_H
#define LOG_H
#include <6x8_slim_font.h>
#include <arch.h>
#include <fb.h>
#include <lock.h>
#include <mem.h>
#include <stdint.h>
#include <tool.h>
void log_init( );
void log_init_mem( );
void log_printf(char *str, ...);
#ifndef NO_DEBUG
#define LOG(...) \
log_printf("[%4u]%s() (%s:%d) ", GET_TICK_BIG, __func__, __FILE__, __LINE__); \
log_printf(__VA_ARGS__)
#else
#define LOG(...)
#endif
#endif // log.h

View File

@ -18,7 +18,7 @@
#define assert(check) \
do { \
if (!(check)) { \
fb_printf("\nassert() failed in %s() (%s:%d)\n", __func__, __FILE__, __LINE__); \
LOG("\nassert() ошибка в %s() (%s:%d)\n", __func__, __FILE__, __LINE__); \
for (;;) asm volatile("hlt"); \
} \
} while (0)

View File

@ -1,3 +1,3 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 1
#define VERSION_BUILD 915
#define VERSION_BUILD 934

View File

@ -1,15 +0,0 @@
#include <arch.h>
static inline int serial_is_transmit_empty(uint16_t com) {
return inb(com + 5) & 0x20;
}
void serial_write_byte(uint8_t byte) {
while (!serial_is_transmit_empty(0x3F8)) {}
outb(0x3F8, byte);
}
void serial_write_bytes(char *c, uint64_t n) {
for (uint64_t i = 0; i < n; i++) { serial_write_byte(c[i]); }
}

15
kernel/cpu/com.c Normal file
View File

@ -0,0 +1,15 @@
#include <arch.h>
static inline int com_is_transmit_empty(uint16_t com) {
return inb(com + 5) & 0x20;
}
void com_write_byte(uint8_t byte) {
while (!com_is_transmit_empty(0x3F8)) {}
outb(0x3F8, byte);
}
void com_write_bytes(char *c, uint64_t n) {
for (uint64_t i = 0; i < n; i++) { com_write_byte(c[i]); }
}

View File

@ -8,6 +8,7 @@
*/
#include <fb.h>
#include <log.h>
#include <stdbool.h>
#include <stdint.h>
#include <tool.h>

View File

@ -8,6 +8,7 @@
#include <arch.h>
#include <fb.h>
#include <log.h>
#include <stdbool.h>
#include <stdint.h>
#include <tool.h>

View File

@ -9,6 +9,7 @@
#include "idt.h"
#include <arch.h>
#include <fb.h>
#include <log.h>
#include <stdbool.h>
#include <stdint.h>
#include <tool.h>
@ -30,22 +31,22 @@ static void encode_idt_entry(uint8_t vector, void *handler, uint8_t flags) {
}
static void exception_handler(struct frame state) {
fb_printf("\nПОЛУЧЕНО ИСКЛЮЧЕНИЕ: %s\n", exception_names[state.int_number]);
LOG("\nПОЛУЧЕНО ИСКЛЮЧЕНИЕ: %s\n", exception_names[state.int_number]);
fb_printf(" RAX=%x RBX=%x\n"
" RCX=%x RDX=%x\n"
" RSI=%x RDI=%x\n"
" RBP=%x RSP=%x\n"
" R08=%x R09=%x\n"
" R10=%x R11=%x\n"
" R12=%x R13=%x\n"
" R14=%x R15=%x\n"
" RIP=%x RFLAGS=%x\n"
" CS=%x SS=%x\n"
" ERR=%x INT=%u",
state.rax, state.rbx, state.rcx, state.rdx, state.rsi, state.rdi, state.rbp, state.rsp, state.r8,
state.r9, state.r10, state.r11, state.r12, state.r13, state.r14, state.r15, state.rip, state.rflags,
state.cs, state.ss, state.err, state.int_number);
LOG(" RAX=%x RBX=%x\n"
" RCX=%x RDX=%x\n"
" RSI=%x RDI=%x\n"
" RBP=%x RSP=%x\n"
" R08=%x R09=%x\n"
" R10=%x R11=%x\n"
" R12=%x R13=%x\n"
" R14=%x R15=%x\n"
" RIP=%x RFLAGS=%x\n"
" CS=%x SS=%x\n"
" ERR=%x INT=%u",
state.rax, state.rbx, state.rcx, state.rdx, state.rsi, state.rdi, state.rbp, state.rsp, state.r8, state.r9,
state.r10, state.r11, state.r12, state.r13, state.r14, state.r15, state.rip, state.rflags, state.cs, state.ss,
state.err, state.int_number);
asm volatile("cli; hlt");
}

View File

@ -7,7 +7,7 @@
*/
#include <arch.h>
#include <fb.h>
#include <log.h>
void pic_init( ) {
outb(0x20, 0x11);

View File

@ -12,8 +12,6 @@
#include <stdint.h>
#include <tool.h>
extern void task_switch(struct frame *state);
void pit_set_interval(int hz) {
int divisor = 1193180 / hz; // Вычисляем делитель
outb(0x43, 0x34); // Устанавливаем байт команды 0x34
@ -22,6 +20,5 @@ void pit_set_interval(int hz) {
}
void pit_init( ) {
idt_set_int(32, task_switch);
pit_set_interval(1);
}

View File

@ -7,7 +7,7 @@
*/
#include <arch.h>
#include <fb.h>
#include <log.h>
#include <mem.h>
static volatile uint64_t next_thread_id = 0;
@ -37,7 +37,7 @@ void task_switch(struct frame *state) {
current_task = kernel_task;
}
fb_printf("%u\n", current_task->id);
LOG("%u\n", current_task->id);
asm volatile("mov %0, %%rsp" ::"a"(current_task->rsp));
asm volatile("popf");
@ -96,7 +96,14 @@ task_t *task_new_thread(void (*func)(void *), void *arg) {
return new_task;
}
void notask_switch( ) {
asm volatile("nop");
}
void task_init( ) {
LOG("Потоки не инициализированы\n");
idt_set_int(32, notask_switch);
return;
uint64_t rsp;
uint64_t cr3;
@ -114,6 +121,5 @@ void task_init( ) {
current_task = kernel_task;
last_task = kernel_task;
idt_set_int(32, task_switch);
LOG("Потоки инициализированы\n");
}

View File

@ -1,83 +0,0 @@
/**
* debug.c
* Функции отладочных сообщений
*
* Функционал управления выводом отладочных сообщений
*
*/
#include <fb.h>
#include <mem.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <tool.h>
typedef struct msg {
uint64_t level;
char *message;
struct msg *next;
} msg_t;
msg_t *log = NULL;
msg_t *last_message = NULL;
uint32_t level_colors[] = {
0x0000FF00, // Зеленый
0x00FFFF00, // Желтый
0x00FF0000, // Красный
0x0000FFFF, // Голубой
0x000000FF, // Синий
0x00FF00FF // Пурпурный
};
// Функция для добавления сообщения в лог
void add_message(uint64_t level, char *message) {
msg_t *new_msg = (msg_t *)mem_alloc(sizeof(msg_t));
new_msg->level = level;
new_msg->message = mem_alloc(tool_strlen(message) + 1);
tool_strcpy(new_msg->message, message);
new_msg->next = NULL;
if (log == NULL) {
log = new_msg;
} else {
msg_t *current = log;
while (current->next != NULL) { current = current->next; }
current->next = new_msg;
}
last_message = new_msg;
}
// Функция для добавления символа в сообщение
void add_char_to_message(char c, msg_t *msg) {
uint64_t length = tool_strlen(msg->message);
msg->message = mem_realloc(msg->message, length + 1);
msg->message[length] = c;
msg->message[length + 1] = '\0';
}
void debug_putc(char c) {
add_char_to_message(c, last_message);
}
void debug_printf(uint8_t level, char *info, char *format, ...) {
va_list args;
va_start(args, format);
add_message(level, info);
tool_format(debug_putc, format, args);
va_end(args);
}
// Функция для вывода всего лога
void print_log( ) {
msg_t *current = log;
while (current != NULL) {
fb_set_text_color(level_colors[current->level]);
fb_printf("Message: %s\n", current->message);
fb_set_text_color(0x00D000);
current = current->next;
}
}

View File

@ -10,6 +10,7 @@
#include <6x8_slim_font.h>
#include <fb.h>
#include <limine.h>
#include <log.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
@ -22,6 +23,7 @@ static volatile struct limine_framebuffer_request framebuffer_request = {
static struct limine_framebuffer_response *framebuffer_response;
static struct limine_framebuffer *boot_framebuffer;
int fb_init_status = 0;
uint32_t *fb_addr;
uint32_t text_color = GREEN;
uint32_t background = DARK_GREEN;
@ -29,23 +31,18 @@ uint64_t width;
uint64_t height;
uint64_t pitch;
uint16_t bpp;
uint64_t pos_x = 4;
uint64_t pos_y = 4;
uint32_t fb_get_text_color( ) {
return text_color;
}
void fb_set_text_color(uint32_t color) {
text_color = color;
}
uint64_t pos_x = 0;
uint64_t pos_y = 0;
// Настройка прослойки графики ядра
void fb_init( ) {
framebuffer_response = framebuffer_request.response;
if (framebuffer_response == NULL) { asm volatile("hlt"); }
if (framebuffer_response == NULL) { return; }
if (framebuffer_response->framebuffer_count < 1) { return; }
fb_init_status = framebuffer_response->framebuffer_count;
boot_framebuffer = framebuffer_response->framebuffers[0];
fb_addr = (uint32_t *)boot_framebuffer->address;
@ -80,24 +77,12 @@ void fb_print_buf(uint64_t x, uint64_t y, uint64_t h, uint64_t w, uint32_t *buf)
}
}
static inline void print_bits(size_t x, size_t y, uint8_t num) {
void fb_print_bits(size_t x, size_t y, uint8_t num) {
for (size_t i = 0; i <= 7; i++) {
if ((num >> i) & 1) { SCREEN_BUFFER[x + i + y * SCREEN_WIDTH] = text_color; }
}
}
// Получение кода символа в таблице
static inline uint32_t analyze(char glyth) {
return ((uint8_t)glyth - 32) * 8;
}
// Вывод символа по координатам
static void print_char(int x, int y, char glyth) {
for (uint64_t i = 0; i < FONT_6X8_SLIM_CHAR_HEIGHT; i++) {
print_bits(x, y + i, font_6x8_slim[analyze(glyth) + i]);
}
}
void scroll_fb( ) {
size_t last_line_index = (SCREEN_HEIGHT - (FONT_6X8_SLIM_CHAR_HEIGHT)) * SCREEN_WIDTH;
@ -108,58 +93,4 @@ void scroll_fb( ) {
}
for (uint64_t i = last_line_index; i < SCREEN_HEIGHT * SCREEN_WIDTH; i++) { SCREEN_BUFFER[i] = background; }
}
// Вывод одного символа
static void fb_putchar(char c) {
if (c == '\0') { return; }
if (c == '\t') {
pos_x += FONT_6X8_SLIM_CHAR_WIDTH * 4;
} else if (c == '\n') {
// Новая строка
pos_x = 4;
pos_y += FONT_6X8_SLIM_CHAR_HEIGHT + 1;
} else {
if (pos_x >= SCREEN_WIDTH) {
pos_x = 4;
pos_y += FONT_6X8_SLIM_CHAR_HEIGHT + 1;
}
if (pos_y >= SCREEN_HEIGHT - FONT_6X8_SLIM_CHAR_HEIGHT) {
scroll_fb( );
pos_y -= FONT_6X8_SLIM_CHAR_HEIGHT;
}
print_char(pos_x, pos_y, c);
pos_x += FONT_6X8_SLIM_CHAR_WIDTH;
}
}
// Вывод текстового сообщения
void fb_printf(char *str, ...) {
va_list args;
va_start(args, str);
tool_format(&fb_putchar, str, args);
va_end(args);
}
// Вывод текстового сообщения по координатам
void fb_printf_at(uint64_t x, uint64_t y, char *str, ...) {
va_list args;
va_start(args, str);
// Сохраняем текущие значения pos_x и pos_y
uint64_t prev_x = pos_x;
uint64_t prev_y = pos_y;
// Устанавливаем новые значения координат вывода
pos_x = x;
pos_y = y;
// Выводим строку
tool_format(&fb_putchar, str, args);
// Восстанавливаем предыдущие значения pos_x и pos_y
pos_x = prev_x;
pos_y = prev_y;
va_end(args);
}

View File

@ -8,6 +8,7 @@
#include <fb.h>
#include <lock.h>
#include <log.h>
#include <stdint.h>
#include <tool.h>

107
kernel/log.c Normal file
View File

@ -0,0 +1,107 @@
/**
* log.c
* Функции отладки
*
* Функционал отладки
*
*/
#include <arch.h>
#include <fb.h>
#include <lock.h>
#include <log.h>
#include <mem.h>
#include <stdint.h>
#include <tool.h>
static char start_buffer[4096];
static char *log_buffer;
static uint64_t fb_pos_x = 4;
static uint64_t fb_pos_y = 0;
static uint64_t buf_pos = 0;
static uint64_t buf_max = 4096;
// Получение кода символа в таблице
static inline uint32_t analyze(char glyth) {
return ((uint8_t)glyth - 32) * 8;
}
// Вывод символа по координатам
static void print_char(uint64_t x, uint64_t y, char 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]);
}
}
static void fb_putchar(char c) {
if (c == '\0' || fb_init_status < 1) { return; }
if (c == '\t') {
fb_pos_x += FONT_6X8_SLIM_CHAR_WIDTH * 4;
} else if (c == '\n') {
// Новая строка
fb_pos_x = 4;
fb_pos_y += FONT_6X8_SLIM_CHAR_HEIGHT + 1;
} else {
if (fb_pos_x >= SCREEN_WIDTH) {
fb_pos_y = 4;
fb_pos_y += FONT_6X8_SLIM_CHAR_HEIGHT + 1;
}
if (fb_pos_y >= SCREEN_HEIGHT - FONT_6X8_SLIM_CHAR_HEIGHT) { fb_pos_y -= FONT_6X8_SLIM_CHAR_HEIGHT; }
print_char(fb_pos_x, fb_pos_y, c);
fb_pos_x += FONT_6X8_SLIM_CHAR_WIDTH;
}
}
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]; }
if (fb_init_status < 1) { return; }
// Перерисовка экрана
for (uint64_t i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++) { SCREEN_BUFFER[i] = DARK_GREEN; }
fb_pos_x = 4;
fb_pos_y = 0;
for (uint64_t i = 0; i < buf_pos; i++) { fb_putchar(log_buffer[i]); }
} else {
fb_putchar(c);
buf_pos++;
}
}
// Вывод текстового сообщения
void log_printf(char *str, ...) {
va_list args;
va_start(args, str);
tool_format(&log_putchar, str, args);
va_end(args);
}
#define FONT_WIDTH 6 + 1
#define FONT_HEIGHT 8 + 1
void log_init_mem( ) {
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, 4096);
buf_max = ((SCREEN_WIDTH - 4) / FONT_WIDTH) * (SCREEN_HEIGHT / FONT_HEIGHT);
}
void log_init( ) {
log_buffer = &start_buffer;
}

View File

@ -9,6 +9,7 @@
#include <fb.h>
#include <limine.h>
#include <lock.h>
#include <log.h>
#include <mem.h>
#include <stdbool.h>
#include <tool.h>
@ -59,11 +60,11 @@ void mem_dump_memory( ) {
while (curr) {
if (curr->next) {
fb_printf("->0x%x | %u килобайт | %s | 0x%x\n", &curr->data, (curr->size) / 1024,
curr->free ? memory_types[0] : memory_types[1], curr->next);
LOG("->0x%x | %u килобайт | %s | 0x%x\n", &curr->data, (curr->size) / 1024,
curr->free ? memory_types[0] : memory_types[1], curr->next);
} else {
fb_printf("->0x%x | %u килобайт | %s | Это последний блок\n", &curr->data, (curr->size) / 1024,
curr->free ? memory_types[0] : memory_types[1]);
LOG("->0x%x | %u килобайт | %s | Это последний блок\n", &curr->data, (curr->size) / 1024,
curr->free ? memory_types[0] : memory_types[1]);
}
curr = curr->next;
}
@ -295,10 +296,10 @@ void mem_init( ) {
for (uint64_t t = 0; t < mmaps[i]->length; t += BLOCK_SIZE) { mem_frame_free((void *)mmaps[i]->base + t, 1); }
}
LOG("%u / %u блоков доступно\n", bitmap_available, bitmap_limit);
// LOG("Размер битовой карты: %u\n", bitmap_size);
// LOG("%u / %u блоков доступно\n", bitmap_available, bitmap_limit);
// LOG("Размер битовой карты: %u\n", bitmap_size);
alloc_init(mem_frame_alloc(1), BLOCK_SIZE);
LOG("%u мегабайт выделено в динамичную память\n", (256 * 16 * BLOCK_SIZE + BLOCK_SIZE) / 1024 / 1024);
// LOG("%u мегабайт выделено в динамичную память\n", (256 * 16 * BLOCK_SIZE + BLOCK_SIZE) / 1024 / 1024);
// Выделяем по 4 мегабайта в аллокатор динамичной памяти
for (int64_t i = 0; i < 16; i += 4) {
@ -306,9 +307,10 @@ void mem_init( ) {
mem_add_block(mem_frame_alloc(1024), 1024 * BLOCK_SIZE);
}
mem_merge_all_blocks( );
mem_dump_memory( );
LOG("%u МБ объем доступной памяти, %u МБ объем виртуальной памяти\n", (bitmap_available * BLOCK_SIZE) / 1024 / 1024,
available / 1024 / 1024);
// mem_dump_memory( );
// LOG("%u МБ объем доступной памяти, %u МБ объем виртуальной памяти\n", (bitmap_available * BLOCK_SIZE) / 1024 /
// 1024,
// available / 1024 / 1024);
LOG("%u / %u блоков доступно\n", bitmap_available, bitmap_limit);
// LOG("%u / %u блоков доступно\n", bitmap_available, bitmap_limit);
}

View File

@ -9,6 +9,7 @@
#include <fb.h>
#include <limine.h>
#include <log.h>
#include <mod.h>
#include <sys.h>
#include <tool.h>
@ -35,7 +36,7 @@ static void *elf_entry(elf64_header_t *module_bin) {
// LOG("(uint64_t)elf_header->e_entry = 0x%x, type = %u\n", (uint64_t)elf_header->e_entry, elf_header->e_type);
if (elf_header->e_type != 2) {
fb_printf("\t\tОшибка! Модуль неправильно собран!\n");
LOG("\t\tОшибка! Модуль неправильно собран!\n");
for (;;) {}
}
@ -45,13 +46,13 @@ static void *elf_entry(elf64_header_t *module_bin) {
void mod_list_show( ) {
for (uint64_t i = 0; i < modules_count; i++) {
fb_printf("Имя: %s\n", module_list[i].name);
fb_printf("Описание модуля: %s\n", module_list[i].message);
fb_printf("Тип модуля: %u\n", module_list[i].type);
fb_printf("Код ошибки модуля: %u\n", module_list[i].err_code);
LOG("Имя: %s\n", module_list[i].name);
LOG("Описание модуля: %s\n", module_list[i].message);
LOG("Тип модуля: %u\n", module_list[i].type);
LOG("Код ошибки модуля: %u\n", module_list[i].err_code);
if (module_list[i].data_size) {
fb_printf("Размер данных: %u\n", module_list[i].data_size);
fb_printf("Адрес данных: 0x%x\n", module_list[i].data);
LOG("Размер данных: %u\n", module_list[i].data_size);
LOG("Адрес данных: 0x%x\n", module_list[i].data);
}
}
}
@ -101,7 +102,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);
// LOG("\t->Точка входа: 0x%x\n", module_init);

View File

@ -8,74 +8,36 @@
*/
#include <arch.h>
#include <fb.h>
#include <limine.h>
#include <log.h>
#include <mem.h>
#include <mod.h>
#include <tool.h>
#include <version.h>
char (*getc)( );
extern task_t* current_task;
// Пример функции, которую будем выполнять в разных потоках
static void test_task(void* arg) {
fb_printf("\n\t\t[%u]\n", current_task->id);
for (;;) {}
}
char* msg = "123!!!!";
// Точка входа
void _start( ) {
asm volatile("cli");
log_init( );
fb_init( );
arch_init( );
mem_init( );
log_init_mem( );
fb_set_text_color(0x00FF00);
fb_printf("\t\t\t\t *** Базовая Модульная Платформа Операционных Систем "
"версии %u.%u.%u %s***\n",
VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, KERNEL_GIT_TAG);
LOG("\t\t\t\t *** Базовая Модульная Платформа Операционных Систем "
"версии %u.%u.%u %s***\n",
VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, KERNEL_GIT_TAG);
fb_printf("\t\t\t\t *** Дата сборки: %s %s ***\n", __DATE__, __TIME__);
fb_set_text_color(0x00D000);
LOG("\t\t\t\t *** Дата сборки: %s %s ***\n", __DATE__, __TIME__);
task_init( );
pit_init( );
// mod_init( );
mod_init( );
fb_set_text_color(0x00FF00);
fb_printf("Готово! Для выхода из симуляции удерживайте: ESCAPE\n");
module_info_t* mod = mod_find("[KEYBOARD]");
if (mod == NULL) {
fb_set_text_color(0xFF0000);
fb_printf("\tТребуется модуль ps2.ko!\n");
getc = NULL;
} else {
fb_printf("\nОбнаружен модуль клавиатуры: %s\n", mod->name);
getc = mod->get_func(1);
}
fb_set_text_color(0x00D000);
// Создаем новый поток и передаем ему аргумент
fb_printf("\tСоздаем новый поток и передаем ему аргумент\n");
task_t* thread1 = task_new_thread(&test_task, &msg);
// Создаем новый поток и передаем ему аргумент
fb_printf("\tСоздаем новый поток и передаем ему аргумент\n");
task_t* thread2 = task_new_thread(test_task, &msg);
// Переключаем контекст на первый поток
// task_switch(thread1->state);
LOG("Готово! Для выхода из симуляции удерживайте: ESCAPE\n");
asm volatile("sti");
for (;;) {
asm volatile("hlt");
if (getc) { fb_printf("%c", getc( )); }
}
for (;;) { asm volatile("hlt"); }
}

View File

@ -6,6 +6,7 @@
*/
#include <fb.h>
#include <log.h>
#include <mem.h>
#include <mod.h>
#include <stdint.h>
@ -61,7 +62,7 @@ static time_t sys_get_time( ) {
}
env_t *sys_install(env_t *module) {
module->fb_printf = &fb_printf;
module->fb_printf = &log_printf;
module->alloc_framebuffer = &sys_alloc_framebuffer;
module->free_framebuffer = &sys_free_framebuffer;
module->alloc = &mem_alloc;

View File

@ -41,6 +41,18 @@ void tool_strcpy(char *dest, char *src) {
dest[i] = '\0';
}
void tool_strcat(char *str1, const char *str2) {
while (*str1 != '\0') { str1++; }
while (*str2 != '\0') {
*str1 = *str2;
str1++;
str2++;
}
*str1 = '\0';
}
uint64_t tool_starts_with(const char *str, const char *prefix) {
uint64_t str_len = tool_strlen(str);
uint64_t prefix_len = tool_strlen(prefix);