mirror of
https://github.com/0Nera/BMOSP.git
synced 2024-11-25 18:09:38 +03:00
Добавлены модули-приложения
This commit is contained in:
parent
7e9cbe5e07
commit
384d04b89b
@ -3,6 +3,11 @@
|
||||
static const char name[] = "[APP]Привет мир!";
|
||||
static const char message[] = "Привет из модуля!";
|
||||
|
||||
static int app_main( ) {
|
||||
fb_printf("[%s]\n", message);
|
||||
return 2 + 2;
|
||||
}
|
||||
|
||||
module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
init_env(env);
|
||||
fb_printf("[%s]\n", message);
|
||||
@ -10,7 +15,7 @@ module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
.message = (char *)&message,
|
||||
.type = 0,
|
||||
.data_size = 0,
|
||||
.data = (void *)0,
|
||||
.data = (void *)&app_main,
|
||||
.err_code = 0,
|
||||
.module_id = 0,
|
||||
.irq = 0,
|
||||
|
@ -4,6 +4,61 @@ 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 char (*getc)( ) = NULL;
|
||||
|
||||
static inline int is_digit(char c) {
|
||||
if (c >= '0' && c <= '9') { return 1; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int64_t char_to_digit(char c) {
|
||||
if (is_digit(c)) { return (int64_t)(c - '0'); }
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ios_main( ) {
|
||||
module_info_t *kbd_mod = get_module("[KEYBOARD]");
|
||||
|
||||
if (kbd_mod == NULL) {
|
||||
fb_printf("Клавиатура не найдена!\n");
|
||||
delete_thread( );
|
||||
for (;;) { asm volatile("hlt"); }
|
||||
}
|
||||
|
||||
getc = kbd_mod->get_func(2);
|
||||
|
||||
while (1) {
|
||||
fb_printf("Доступные программы:\n");
|
||||
for (uint64_t i = 0; i < app_count; i++) { fb_printf(" %2u. %s\n", i, app_list[i].name); }
|
||||
fb_printf(" %2u. Выход\n", app_count + 1);
|
||||
|
||||
fb_printf("[IOS]>");
|
||||
|
||||
char c = '\0';
|
||||
|
||||
do { c = getc( ); } while (!is_digit(c));
|
||||
|
||||
fb_printf(" %c\n", c);
|
||||
|
||||
int select = char_to_digit(c);
|
||||
|
||||
if (select == app_count + 1) {
|
||||
fb_printf("Выход\n");
|
||||
delete_thread( );
|
||||
for (;;) { asm volatile("hlt"); }
|
||||
}
|
||||
|
||||
if (select > app_count - 1) {
|
||||
fb_printf("Ошибка! %u не входит в список\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
fb_printf("Запуск %s...\n", app_list[select].name);
|
||||
int (*app)( ) = (int (*)( ))app_list[select].data;
|
||||
int ret = (*app)( );
|
||||
fb_printf("Приложение %s завершилось с кодом: %d\n", app_list[select].name, ret);
|
||||
}
|
||||
}
|
||||
|
||||
static void main( ) {
|
||||
fb_printf("IOS (input-output shell) - оболочка ввода-вывода\n");
|
||||
@ -36,7 +91,7 @@ static void main( ) {
|
||||
delete_thread( );
|
||||
} else {
|
||||
app_list = realloc(app_list, app_count * sizeof(module_info_t));
|
||||
for (uint64_t i = 0; i < app_count; i++) { fb_printf("%2u.\t%s\n", i, app_list[i].name); }
|
||||
ios_main( );
|
||||
for (;;) { asm volatile("hlt"); }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user