From a118bbec5887a7c1cb77d31a7d4e9df16def0ebb Mon Sep 17 00:00:00 2001 From: xiaoyi1212 Date: Sat, 13 Apr 2024 22:22:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=9B=E7=A8=8B=E7=BB=88?= =?UTF-8?q?=E6=AD=A2=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/common.h | 3 +++ kernel/kernel.c | 10 ++++++++++ kernel/task.c | 11 ++++++++--- sysapp/shell.c | 4 +--- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/common.h b/include/common.h index 9f9fe35..50713a9 100644 --- a/include/common.h +++ b/include/common.h @@ -32,4 +32,7 @@ int vsprintf(char *buf, const char *fmt, va_list args); int sprintf(char *buf, const char *fmt, ...); long int strtol(const char *str,char **endptr,int base); +void reset_kernel(); +void shutdown_kernel(); + #endif //CRASHPOWEROS_COMMON_H diff --git a/kernel/kernel.c b/kernel/kernel.c index 72b9d07..e5144d4 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -15,6 +15,16 @@ extern uint32_t end; extern int status; uint32_t placement_address = (uint32_t) & end; +void reset_kernel(){ + printf("Restart %s for x86...",OS_NAME); + clock_sleep(10); + outb(0x64,0xfe); +} + +void shutdown_kernel(){ + //TODO ACPI Driver +} + void kernel_main(multiboot_t *multiboot) { io_cli(); vga_install(); diff --git a/kernel/task.c b/kernel/task.c index a7a091f..8c43975 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -62,7 +62,7 @@ void print_proc(){ printf("Name Pid Status [All Proc: %d]\n\n",index); } -static void found_task(int pid,struct task_struct *base,struct task_struct *argv){ +static void found_task(int pid,struct task_struct *head,struct task_struct *base,struct task_struct *argv,int first){ struct task_struct *t = base; if(t == NULL){ argv = NULL; @@ -72,13 +72,18 @@ static void found_task(int pid,struct task_struct *base,struct task_struct *argv *argv = *t; return; } else{ - found_task(pid,t->next,argv); + if(!first) + if(head->pid == t->pid){ + argv = NULL; + return; + } + found_task(pid,head,t->next,argv,0); } } void task_kill(int pid){ struct task_struct *argv; - found_task(pid,running_proc_head,argv); + found_task(pid,running_proc_head,running_proc_head,argv,1); if(argv == NULL){ printf("Cannot found task Pid:[%d].\n",pid); return; diff --git a/sysapp/shell.c b/sysapp/shell.c index a865b3c..a488b39 100644 --- a/sysapp/shell.c +++ b/sysapp/shell.c @@ -181,9 +181,7 @@ void cmd_del(int argc, char **argv) { } void cmd_reset(){ - printf("Restart %s for x86...",OS_NAME); - clock_sleep(10); - outb(0x64,0xfe); + reset_kernel(); } void setup_shell(){