mirror of
https://github.com/0Nera/BMOSP.git
synced 2025-02-09 05:34:44 +03:00
Добавлена функция удаления потока
This commit is contained in:
parent
fc43b6746a
commit
adf6d4a8b9
@ -44,4 +44,7 @@ TERM_WALLPAPER=boot:///mod/boot.jpg
|
||||
MODULE_CMDLINE=[MOD]imfs.ko
|
||||
|
||||
MODULE_PATH=boot:///mod/hello.ko
|
||||
MODULE_CMDLINE=[MOD]hello.ko
|
||||
MODULE_CMDLINE=[MOD]hello.ko
|
||||
|
||||
MODULE_PATH=boot:///mod/ios.ko
|
||||
MODULE_CMDLINE=[MOD][IO]ios.ko
|
@ -64,6 +64,7 @@ void arch_init( );
|
||||
void task_init( );
|
||||
void task_switch( );
|
||||
uint64_t task_new_thread(void (*func)(void *));
|
||||
void task_del_current( );
|
||||
void cpu_init( );
|
||||
void gdt_init( );
|
||||
void pic_init( );
|
||||
|
@ -77,7 +77,7 @@ typedef struct {
|
||||
module_info_t *(*get_module)(char *module_id);
|
||||
module_info_t *(*mod_list_get)(uint64_t *count);
|
||||
uint64_t (*new_thread)(uint64_t func);
|
||||
int (*delete_thread)(uint64_t thread_id);
|
||||
void (*delete_thread)( );
|
||||
time_t (*get_time)( );
|
||||
} __attribute__((packed)) env_t;
|
||||
|
||||
|
@ -79,9 +79,19 @@ uint64_t task_new_thread(void (*func)(void *)) {
|
||||
return new_task->id;
|
||||
}
|
||||
|
||||
void dummy( ) {
|
||||
LOG("\t\tПривет! Я поток: %u\n", current_task->id);
|
||||
for (;;) { task_switch( ); }
|
||||
void task_del_current( ) {
|
||||
LOG("Удаление потока ID: %u\n", current_task->id);
|
||||
task_t *prev = current_task->last;
|
||||
task_t *next = current_task->next;
|
||||
|
||||
prev->next = next;
|
||||
next->last = prev;
|
||||
|
||||
mem_free(current_task->stack);
|
||||
mem_free(current_task);
|
||||
|
||||
current_task = next;
|
||||
task_switch( );
|
||||
}
|
||||
|
||||
void task_init( ) {
|
||||
@ -116,10 +126,5 @@ void task_init( ) {
|
||||
|
||||
last_task = kernel_task;
|
||||
|
||||
LOG("Создание потока dummy\n");
|
||||
task_new_thread(dummy);
|
||||
|
||||
test_buf = mem_alloc(8 * 8 * sizeof(uint32_t));
|
||||
|
||||
LOG("Потоки инициализированы\n");
|
||||
}
|
||||
|
@ -62,8 +62,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);
|
||||
module_list[i].after_init( );
|
||||
LOG("%s.after_init( );\n", module_list[i].name);
|
||||
task_new_thread(module_list[i].after_init);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -75,7 +74,7 @@ module_info_t *mod_list_get(uint64_t *count) {
|
||||
|
||||
module_info_t *mod_find(char *tag) {
|
||||
for (uint64_t i = 0; i < modules_count; i++) {
|
||||
if (tool_starts_with(module_list[i].name, tag)) { return &module_list[i]; }
|
||||
if (tool_str_contains(module_list[i].name, tag)) { return &module_list[i]; }
|
||||
}
|
||||
|
||||
return (module_info_t *)NULL;
|
||||
@ -128,7 +127,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);
|
||||
|
@ -19,6 +19,7 @@ uint64_t full_init = 0;
|
||||
|
||||
void finally( ) {
|
||||
LOG("Готово! Для выхода из симуляции удерживайте: ESCAPE\n");
|
||||
mod_after_init( );
|
||||
for (;;) {
|
||||
task_switch( );
|
||||
asm volatile("hlt");
|
||||
@ -35,7 +36,6 @@ void _start( ) {
|
||||
log_init_mem( );
|
||||
arch_init( );
|
||||
mod_init( );
|
||||
mod_after_init( );
|
||||
|
||||
LOG("\t\t\t\t *** Базовая Модульная Платформа Операционных Систем "
|
||||
"версии %u.%u.%u %s***\n",
|
||||
|
12
kernel/sys.c
12
kernel/sys.c
@ -49,14 +49,6 @@ static module_info_t *sys_get_module(char *module_id) {
|
||||
return (module_info_t *)mod_find(module_id);
|
||||
}
|
||||
|
||||
static uint64_t sys_new_thread(uint64_t func) {
|
||||
return func;
|
||||
}
|
||||
|
||||
static int sys_delete_thread(uint64_t thread_id) {
|
||||
return thread_id;
|
||||
}
|
||||
|
||||
env_t *sys_install(env_t *module) {
|
||||
module->fb_printf = &log_printf;
|
||||
module->alloc_framebuffer = &sys_alloc_framebuffer;
|
||||
@ -68,8 +60,8 @@ 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 = &sys_new_thread;
|
||||
module->delete_thread = &sys_delete_thread;
|
||||
module->new_thread = &task_new_thread;
|
||||
module->delete_thread = &task_del_current;
|
||||
module->get_time = &rtc_get_time;
|
||||
|
||||
return module;
|
||||
|
@ -20,7 +20,7 @@ void (*exit)(int code);
|
||||
int (*get_error)( );
|
||||
sys_info_t *(*get_info)( );
|
||||
uint64_t (*new_thread)(uint64_t func);
|
||||
int (*delete_thread)(uint64_t thread_id);
|
||||
void (*delete_thread)( );
|
||||
time_t (*get_time)( );
|
||||
uint64_t offset;
|
||||
|
||||
|
@ -22,6 +22,7 @@ int strcmp(const char *s1, const char *s2);
|
||||
char *trstr(char *str, char sym);
|
||||
char *strdup(char *str);
|
||||
size_t count_chars(char *str, char c);
|
||||
uint64_t str_contains(const char *str, const char *substr);
|
||||
void memcpy(void *dest, void *src, size_t n);
|
||||
void *memset(void *ptr, uint8_t n, size_t size);
|
||||
void *memmove(void *dest, void *src, size_t n);
|
||||
|
@ -23,7 +23,7 @@ extern void (*exit)(int code);
|
||||
extern int (*get_error)( );
|
||||
extern sys_info_t *(*get_info)( );
|
||||
extern uint64_t (*new_thread)(uint64_t func);
|
||||
extern int (*delete_thread)(uint64_t thread_id);
|
||||
extern void (*delete_thread)( );
|
||||
extern time_t (*get_time)( );
|
||||
extern uint64_t offset;
|
||||
|
||||
|
@ -118,7 +118,7 @@ typedef struct {
|
||||
module_info_t *(*get_module)(char *module_id);
|
||||
module_info_t *(*mod_list_get)(uint64_t *count);
|
||||
uint64_t (*new_thread)(uint64_t func);
|
||||
int (*delete_thread)(uint64_t thread_id);
|
||||
void (*delete_thread)( );
|
||||
time_t (*get_time)( );
|
||||
} __attribute__((packed)) env_t;
|
||||
|
||||
|
@ -146,16 +146,8 @@ static void main( ) {
|
||||
uint64_t *mod_count = alloc(sizeof(uint64_t));
|
||||
module_info_t *mod_list = mod_list_get(mod_count);
|
||||
fb_printf("Модулей: %u\n", *mod_count);
|
||||
for (uint64_t i = 0; i < *mod_count; i++) {
|
||||
if (mod_list[i].data_size > 0) {
|
||||
fb_printf("Модуль: %s\n", mod_list[i].name);
|
||||
add_file(mod_list[i].name, "datafile", mod_f, mod_list[i].data, mod_list[i].data_size);
|
||||
}
|
||||
}
|
||||
fb_printf("Модулей: %u\n", *mod_count);
|
||||
print_folder_contents(root_folder, 0);
|
||||
free(mod_count);
|
||||
fb_printf("Модулей: %u\n", *mod_count);
|
||||
delete_thread( );
|
||||
}
|
||||
|
||||
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
|
17
modules/ios/build.sh
Normal file
17
modules/ios/build.sh
Normal file
@ -0,0 +1,17 @@
|
||||
#/bin/sh
|
||||
echo "Название: IOS"
|
||||
echo "Лицензия: CC BY-NC 4.0"
|
||||
|
||||
CC="gcc"
|
||||
ARCH_FLAGS="-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 ios.o
|
||||
$CC $ARCH_FLAGS -Wl,--entry=init,--build-id=none -T ../link.ld ios.o -L../../modlib/lib/ -lmod -o ios.ko
|
||||
|
||||
cp ios.ko ../bin/
|
||||
echo "Сборка завершена, файл: ios.ko"
|
58
modules/ios/main.c
Normal file
58
modules/ios/main.c
Normal file
@ -0,0 +1,58 @@
|
||||
#include <system.h>
|
||||
|
||||
static module_info_t *mod_list = NULL;
|
||||
static uint64_t *mod_count = NULL;
|
||||
static uint64_t app_count = 0;
|
||||
static module_info_t *app_list = NULL;
|
||||
|
||||
static void main( ) {
|
||||
fb_printf("IOS (input-output shell) - оболочка ввода-вывода\n");
|
||||
mod_count = alloc(sizeof(uint64_t));
|
||||
mod_list = mod_list_get(mod_count);
|
||||
|
||||
app_list = alloc((*mod_count) * sizeof(module_info_t));
|
||||
|
||||
if (app_list == NULL) {
|
||||
fb_printf("Ошибка выделения памяти для app_list!\n");
|
||||
delete_thread( );
|
||||
}
|
||||
|
||||
app_count = 0;
|
||||
|
||||
for (uint64_t i = 0; i < *mod_count; i++) {
|
||||
if (str_contains(mod_list[i].name, "[APP]")) {
|
||||
fb_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) {
|
||||
fb_printf("Модулей-программ не обнаружено!\n");
|
||||
free(app_list);
|
||||
delete_thread( );
|
||||
} else {
|
||||
app_list = realloc(app_list, app_count * sizeof(module_info_t));
|
||||
for (;;) { asm volatile("hlt"); }
|
||||
}
|
||||
|
||||
for (;;) { asm volatile("hlt"); }
|
||||
}
|
||||
|
||||
module_info_t __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 };
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user