From 0d5299a94fc115c3cc68fd4f1397b38e22d70f08 Mon Sep 17 00:00:00 2001 From: xiaoyi1212 Date: Sun, 8 Sep 2024 10:03:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E9=A1=B5=E8=A1=A8=E8=BF=98=E5=8E=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/init/init.c | 6 +++++- src/driver/keyboard.c | 2 ++ src/include/common.h | 4 ++-- src/kernel/kernel.c | 9 ++++++--- src/kernel/syscall.c | 9 +++++++-- src/kernel/task.c | 7 +++++-- src/sysapp/shell.c | 1 + src/util/printf.c | 2 ++ 8 files changed, 30 insertions(+), 10 deletions(-) diff --git a/apps/init/init.c b/apps/init/init.c index c643d1b..9a4f37a 100644 --- a/apps/init/init.c +++ b/apps/init/init.c @@ -3,6 +3,10 @@ int main(){ printf("Init service launched.\n"); - exec_elf("shell.bin"); + + int pid = exec_elf("shell.bin"); + if(pid != 0){ + printf("Shell process launched [PID: %d]\n",pid); + } else printf("Cannot launch shell\n"); return 0; } diff --git a/src/driver/keyboard.c b/src/driver/keyboard.c index 437ba45..deda32f 100644 --- a/src/driver/keyboard.c +++ b/src/driver/keyboard.c @@ -79,11 +79,13 @@ int input_char_inSM() { int i; struct task_struct *task = get_current(); if (task->tty->is_using == false) { + } else { do{ i = fifo8_get(task->tty->fifo); } while (i == -1); } + return i; } diff --git a/src/include/common.h b/src/include/common.h index 5f5bcf8..9fa3ebc 100644 --- a/src/include/common.h +++ b/src/include/common.h @@ -2,8 +2,8 @@ #define CRASHPOWEROS_COMMON_H #define OS_NAME "CoolPotOS" -#define OS_VERSION "v0.3.1" -#define KERNEL_NAME "CP_Kernel-i386-0.3.1" +#define OS_VERSION "v0.3.2" +#define KERNEL_NAME "CP_Kernel-i386-0.3.2" // b 0x211972 // b 0x20d0a6 diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 953b6e3..a67d401 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -74,13 +74,18 @@ int check_task(int *pid){ int check_task_usershell(int *pid){ struct task_struct *shell = found_task_pid(*pid); + while (1){ if(shell->state == TASK_DEATH){ + io_sti(); screen_clear(); int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell"); kernel_thread(check_task,&pid,"CPOS-CK"); + break; } } + + while (1); return 0; } @@ -113,7 +118,6 @@ void kernel_main(multiboot_t *multiboot) { init_page(multiboot); init_sched(); - //proc_install(); init_keyboard(); init_pit(); @@ -160,8 +164,7 @@ void kernel_main(multiboot_t *multiboot) { vfs_change_path("apps"); klogf(user_process("init.bin","InitService") != -1,"Init service process init.\n"); - - //int pid = user_process("shell.bin","UserShell"); + // int pid = user_process("shell.bin","UserShell"); //kernel_thread(check_task_usershell,&pid,"CTU"); // int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell"); diff --git a/src/kernel/syscall.c b/src/kernel/syscall.c index cf9c629..0f2664a 100644 --- a/src/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -52,6 +52,7 @@ static void syscall_get_cd(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,u } static int syscall_vfs_filesize(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){ + io_sti(); return vfs_filesize(ebx); } @@ -119,8 +120,8 @@ static void* syscall_sysinfo(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi return info; } -static int syscall_exec(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){ - int pid = user_process(ebx,ebx); +static uint32_t syscall_exec(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){ + uint32_t pid = user_process(ebx,ebx); return pid; } @@ -142,9 +143,11 @@ void *sycall_handlers[MAX_SYSCALLS] = { }; typedef size_t (*syscall_t)(size_t, size_t, size_t, size_t, size_t); +extern int can_sche; //进程调度器 0 禁用 | 1 启用 size_t syscall() { io_cli(); + // can_sche = 0; volatile size_t eax, ebx, ecx, edx, esi, edi; asm("mov %%eax, %0\n\t" : "=r"(eax)); asm("mov %%ebx, %0\n\t" : "=r"(ebx)); @@ -157,6 +160,8 @@ size_t syscall() { } else { eax = -1; } + can_sche = 1; + io_sti(); return eax; } diff --git a/src/kernel/task.c b/src/kernel/task.c index fe4d926..20741bd 100644 --- a/src/kernel/task.c +++ b/src/kernel/task.c @@ -200,6 +200,7 @@ int32_t user_process(char *path, char *name){ // 用户进程创建 uint32_t size = vfs_filesize(path); if(size == -1){ + can_sche = 1; return NULL; } @@ -232,7 +233,7 @@ int32_t user_process(char *path, char *name){ // 用户进程创建 char* ker_path = kmalloc(strlen(path) + 1); strcpy(ker_path,path); - + page_directory_t *cur_page_dir = get_current()->pgd_dir; page_switch(page); @@ -256,6 +257,7 @@ int32_t user_process(char *path, char *name){ // 用户进程创建 if(!elf32Validate(ehdr)){ printf("Unknown exec file format.\n"); kfree(ker_path); + can_sche = 1; return NULL; } uint32_t main = ehdr->e_entry; @@ -276,7 +278,8 @@ int32_t user_process(char *path, char *name){ // 用户进程创建 new_task->next = running_proc_head; kfree(ker_path); - page_switch(kernel_directory); + page_switch(cur_page_dir); + can_sche = 1; // 找到当前进任务队列,插入到末尾 struct task_struct *tailt = running_proc_head; diff --git a/src/sysapp/shell.c b/src/sysapp/shell.c index 1f55eeb..a2567f1 100644 --- a/src/sysapp/shell.c +++ b/src/sysapp/shell.c @@ -354,6 +354,7 @@ char *user() { } void setup_shell() { + asm("sti"); printf("Welcome to %s %s (CPOS Kernel i386)\n" "\n" " * SourceCode: https://github.com/xiaoyi1212/CoolPotOS\n" diff --git a/src/util/printf.c b/src/util/printf.c index 67dbc83..f759db0 100644 --- a/src/util/printf.c +++ b/src/util/printf.c @@ -318,11 +318,13 @@ void screen_clear(){ } void putchar(char c){ + /* struct task_struct *task = get_current(); if(task != NULL){ task->tty->putchar(task->tty,c); return; } + */ if(vbe_status){ vbe_putchar(c);