Skip to content

Commit

Permalink
Исправлена работа модулей, повышена стабильность системы
Browse files Browse the repository at this point in the history
  • Loading branch information
0Nera committed Sep 17, 2024
1 parent f214c92 commit fb2effa
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 100 deletions.
21 changes: 0 additions & 21 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,3 @@
dos2unix *.sh

python3 scripts/pbuild.py

cd modlib/lib/
dos2unix build.sh
chmod +x build.sh
./build.sh
cd ../..

cd modules/
mkdir -p bin
dos2unix */*.sh
chmod +x */build.sh

for dir in */; do
if [ $dir != "bin/" ]; then
cd $dir
./build.sh
cd ..
fi
done

cd ..
24 changes: 24 additions & 0 deletions build_mods.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

dos2unix *.sh

cd modlib/lib/
dos2unix build.sh
chmod +x build.sh
./build.sh
cd ../..

cd modules/
mkdir -p bin
dos2unix */*.sh
chmod +x */build.sh

for dir in */; do
if [ $dir != "bin/" ]; then
cd $dir
./build.sh
cd ..
fi
done

cd ..
5 changes: 4 additions & 1 deletion configs/limine.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TERM_WALLPAPER=boot:///mod/boot.jpg
:BMOSP (KASLR off)
#RESOLUTION=640x480
#RESOLUTION=1024x768
RESOLUTION=1280x720
RESOLUTION=1280x720x32
PROTOCOL=limine
KASLR=no
KERNEL_PATH=boot:///kernel.elf
Expand All @@ -34,5 +34,8 @@ TERM_WALLPAPER=boot:///mod/boot.jpg
MODULE_PATH=boot:///mod/hello.ko
MODULE_CMDLINE=[MOD]hello.ko

MODULE_PATH=boot:///mod/doom.ko
MODULE_CMDLINE=[MOD]doom.ko

MODULE_PATH=boot:///mod/ios.ko
MODULE_CMDLINE=[MOD][IO]ios.ko
20 changes: 20 additions & 0 deletions include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ static inline void *hal_memset_32(void *s, uint32_t c, int64_t count) {
return s;
}

static inline void *hal_memcpy(void *dest, const void *src, int64_t count) {
int64_t d0, d1;
asm volatile("rep\n\t"
"movsb"
: "=&c"(d0), "=&D"(d1)
: "S"(src), "0"(count), "1"(dest)
: "memory");
return dest;
}

static inline void *hal_memcpy32(void *dest, const void *src, int64_t count) {
int64_t d0, d1;
asm volatile("rep\n\t"
"movsl"
: "=&c"(d0), "=&D"(d1)
: "S"(src), "0"(count), "1"(dest)
: "memory");
return dest;
}

#define GET_TICK_BIG arch_get_tick_b( )
#define GET_TICK_lOW arch_get_tick_l( )

Expand Down
1 change: 1 addition & 0 deletions include/fb.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern int fb_init_status;
extern uint32_t *fb_addr;
extern uint64_t width;
extern uint64_t height;
extern uint16_t bpp;

#define SCREEN_WIDTH width
#define SCREEN_HEIGHT height
Expand Down
1 change: 0 additions & 1 deletion include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
void log_init( );
void log_init_mem( );
void log_printf(char *str, ...);
char *utf8cp(char *str);

#ifndef NO_DEBUG
#define LOG(...) \
Expand Down
1 change: 1 addition & 0 deletions include/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ typedef struct env_t_s {
module_info_t *(*mod_list_get)(uint64_t *count);
uint64_t (*new_thread)(void (*func)(void *), char *name, void *arg);
void (*delete_thread)( );
void (*task_switch)( );
time_t (*get_time)( );
void (*set_int)(uint8_t vector, void (*handler)(void *));
void (*mod_update_info)(struct env_t_s *ret);
Expand Down
2 changes: 1 addition & 1 deletion include/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_BUILD 202
#define VERSION_BUILD 257
8 changes: 1 addition & 7 deletions kernel/cpu/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,9 @@ void cpu_init( ) {

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));
fpu_initialize( );
uint32_t sse_version = (ecx >> 25) & 0x7;
LOG("SSE%u включен\n", sse_version);
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/cpu/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ uint64_t task_new_thread(void (*func)(void *), char *name, void *arg) {
current_task->next->last = new_task;
current_task->next = new_task;

LOG("Создан новый поток с ID: %u\n", new_task->id);
LOG("Создан новый поток с ID: %u (%s)\n", new_task->id, name);

if (full_init == 0) { current_task = new_task; }

Expand Down
20 changes: 20 additions & 0 deletions kernel/cpu/task_switch.s
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,23 @@ task_switch_asm:
popfq
sti
retq

.global fpu_initialize
fpu_initialize:
clts
mov %cr0, %rax
and $0xFFFD, %ax
or $0x10, %ax
mov %rax, %cr0
fninit
mov %cr0, %rax
and $0xfffb, %ax
or $0x0002, %ax
mov %rax, %cr0
mov %cr4, %rax
or $0x600, %rax
mov %rax, %cr4
pushq $0x1F80
ldmxcsr (%rsp)
addq $8, %rsp
ret
2 changes: 1 addition & 1 deletion kernel/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void log_init_mem( ) {
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);
LOG("%ux%u %u\n", width, height, bpp);
redraw_screen( );
lock_release(log_lock);
}
Expand Down
15 changes: 3 additions & 12 deletions kernel/mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ uint64_t bootpng_size;

// Вывод списка модулей в отладчик
void mod_list_show( ) {
LOG("Список модулей:\n");
for (uint64_t i = 0; i < modules_count; i++) {
LOG("Имя: %s\n", module_list[i].name ? module_list[i].name : "(NULL)");
LOG("Имя: %s | ID: %u \n", module_list[i].name ? module_list[i].name : "(NULL)", i);
LOG("Описание модуля: %s\n", module_list[i].message ? module_list[i].message : "(NULL)");
LOG("Тип модуля: %u\n", module_list[i].type);
LOG("Код ошибки модуля: %u\n", module_list[i].err_code);
Expand All @@ -44,16 +45,6 @@ void mod_list_show( ) {
}
}

// Запуск модулей имеющих дополнительную точку входа
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, NULL);
}
}
}

// Запуск модулей имеющих дополнительную точку входа
module_info_t *mod_list_get(uint64_t *count) {
*count = modules_count;
Expand Down Expand Up @@ -133,7 +124,7 @@ void mod_init( ) {
main_env->id = modules_count;
sys_install(main_env);

uint64_t id = task_new_thread((void (*)(void *))module_init, module_list[i].name, main_env);
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;
Expand Down
12 changes: 5 additions & 7 deletions kernel/start.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,27 @@ void _start( ) {
full_init = 1;

task_after_init( );
mem_get_stat( );

LOG("Готово! Для выхода из симуляции удерживайте: ESCAPE\n");
asm volatile("sti");

for (;;) {
task_t *task = current_task;

// Поиск задачи по ID
do {
task = task->next;
if (task->status == 0) {
LOG("УДАЛЕНИЕ %u(%s)\n", task->id, task->id_str);
// LOG("УДАЛЕНИЕ %u(%s)\n", task->id, task->id_str);
task_t *prev = task->last;
task_t *next = task->next;

// Обновляем связи в двусвязном списке
prev->next = next;
next->last = prev;

// Освобождаем память, выделенную под стек и структуру текущего потока
mem_free(task->stack);
mem_free(task);
}
} while (task->id != 0);

task_switch( );
}
}
}
1 change: 1 addition & 0 deletions kernel/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ env_t *sys_install(env_t *module) {
module->mod_list_get = &mod_list_get;
module->new_thread = &task_new_thread;
module->delete_thread = &task_del_current;
module->task_switch = &task_switch;
module->get_time = &rtc_get_time;
module->set_int = &idt_set_int;
module->mod_update_info = &mod_update_info;
Expand Down
2 changes: 2 additions & 0 deletions modlib/lib/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ int (*get_error)( );
sys_info_t *(*get_info)( );
uint64_t (*new_thread)(void (*func)(void *), char *name, void *arg);
void (*delete_thread)( );
void (*task_switch)( );
time_t (*get_time)( );
void (*mod_update_info)(env_t *ret);
void (*set_int)(uint8_t vector, void (*func)(void *));
Expand All @@ -43,6 +44,7 @@ void init_env(env_t *loader_env) {
get_info = loader_env->get_info;
new_thread = loader_env->new_thread;
delete_thread = loader_env->delete_thread;
task_switch = loader_env->task_switch;
get_time = loader_env->get_time;
mod_update_info = loader_env->mod_update_info;
set_int = loader_env->set_int;
Expand Down
1 change: 1 addition & 0 deletions modlib/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern int (*get_error)( );
extern sys_info_t *(*get_info)( );
extern uint64_t (*new_thread)(void (*func)(void *), char *name, void *arg);
extern void (*delete_thread)( );
extern void (*task_switch)( );
extern time_t (*get_time)( );
extern void (*mod_update_info)(env_t *ret);
extern void (*set_int)(uint8_t vector, void (*func)(void *));
Expand Down
1 change: 1 addition & 0 deletions modlib/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ typedef struct env_t_s {
module_info_t *(*mod_list_get)(uint64_t *count);
uint64_t (*new_thread)(void (*func)(void *), char *name, void *arg);
void (*delete_thread)( );
void (*task_switch)( );
time_t (*get_time)( );
void (*set_int)(uint8_t vector, int_entry_t handler);
void (*mod_update_info)(struct env_t_s *ret);
Expand Down
30 changes: 15 additions & 15 deletions modules/ios/main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <system.h>

static module_info_t *mod_list = NULL;
static uint64_t *mod_count = NULL;
static uint64_t mod_count = 0;
static uint64_t app_count = 0;
static module_info_t *app_list = NULL;
static char (*getc)( ) = NULL;
Expand Down Expand Up @@ -64,39 +64,37 @@ void ios_main( ) {

static void main( ) {
log_printf("IOS (input-output shell) - оболочка ввода-вывода\n");
mod_count = alloc(sizeof(uint64_t));
mod_list = mod_list_get(mod_count);
mod_list = mod_list_get(&mod_count);

app_list = alloc((*mod_count) * sizeof(module_info_t));
app_list = alloc((mod_count) * sizeof(module_info_t));

if (app_list == NULL) {
log_printf("Ошибка выделения памяти для app_list!\n");
delete_thread( );
mod_update_info(env);
for (;;) { asm volatile("hlt"); }
}

app_count = 0;

for (uint64_t i = 0; i < *mod_count; i++) {
if (str_contains(mod_list[i].name, "[APP]")) {
// log_printf("%u. %s\n", app_count, mod_list[i].name);
app_list[app_count] = mod_list[i];
app_count++;
log_printf("%u модулей\n", mod_count);
for (uint64_t i = 0; i < mod_count; i++) {
if (mod_list[i].name) {
if (str_contains(mod_list[i].name, "[APP]")) {
// log_printf("%u. %s\n", app_count, mod_list[i].name);
app_list[app_count] = mod_list[i];
app_count++;
}
}
}

free(mod_count);

if (app_count < 1) {
log_printf("Модулей-программ не обнаружено!\n");
free(app_list);
delete_thread( );
mod_update_info(env);
} else {
app_list = realloc(app_list, app_count * sizeof(module_info_t));
ios_main( );
for (;;) { asm volatile("hlt"); }
for (;;) { delete_thread( ); }
}

for (;;) { asm volatile("hlt"); }
Expand All @@ -118,5 +116,7 @@ void __attribute__((section(".minit"))) init(env_t *envm) {
.get_func = 0,
.after_init = main });
mod_update_info(env);
delete_thread( );
task_switch( );
main( );
for (;;) { delete_thread( ); }
}
2 changes: 1 addition & 1 deletion modules/pci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ echo "Лицензия: Публичное достояние"


CC=${CC:-gcc}
ARCH_FLAGS="-fno-stack-protector -ffreestanding -O0 -g -fPIC -static -nostdlib "
ARCH_FLAGS="-fno-stack-protector -fdata-sections -fno-stack-check -ffreestanding -O0 -g -fPIC -static -nostdlib "

if [ -d "../../sdk" ]; then
CC="../../sdk/bin/x86_64-elf-gcc"
Expand Down
Loading

0 comments on commit fb2effa

Please sign in to comment.