Skip to content

Commit

Permalink
更新shell切换机制
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyi1212 committed Sep 1, 2024
1 parent 07e44df commit 3767787
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
18 changes: 3 additions & 15 deletions apps/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,20 @@ int main(){

argc = cmd_parse(com, argv, ' ');



if (argc == -1) {
printf("[Shell]: Error: out of arguments buffer\n");
continue;
}

if (!strcmp("version", argv[0])){
print_info();
}if (!strcmp("system", argv[0])){
exit(0);
}else if (!strcmp("help", argv[0]) || !strcmp("?", argv[0]) || !strcmp("h", argv[0])) {
printf("-=[CoolPotShell Helper]=-\n");
printf("help ? h Print shell help info.\n");
printf("version Print os version.\n");
printf("type <name> Read a file.\n");
printf("ls List all files.\n");
printf("mkdir <name> Make a directory.\n");
printf("del rm <name> Delete a file.\n");
printf("sysinfo Print system info.\n");
printf("proc [kill<pid>|list] List all running processes.\n");
printf("reset Reset OS.\n");
printf("shutdown exit Shutdown OS.\n");
printf("debug Print os debug info.\n");
printf("disk[list|<ID>|cg<ID>]List or view disks.\n");
printf("cd <path> Change shell top directory.\n");
printf("sb3 <name> Player a wav sound file.\n");
printf("exec <path> Execute a application.\n");
printf("system Launch system shell.\n");
} else printf("\033ff3030;[Shell]: Unknown command '%s'.\033c6c6c6;\n", argv[0]);
}
}
40 changes: 37 additions & 3 deletions src/kernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ void shutdown_kernel(){
kill_all_task();
clock_sleep(10);
power_off();


}

uint32_t memory_all(){
Expand All @@ -53,6 +51,15 @@ uint32_t memory_all(){

int check_task(int *pid){
struct task_struct *shell = found_task_pid(*pid);

if(shell == NULL){
printf("\n[Task-Check]: Task was throw exception.\n");
printf("Enter any key to restart kernel.> ");
getc();
printf("\n");
reset_kernel();
}

while (1){
if(shell->state == TASK_DEATH){
printf("\n[Task-Check]: Task was throw exception.\n");
Expand All @@ -65,6 +72,18 @@ int check_task(int *pid){
return 0;
}

int check_task_usershell(int *pid){
struct task_struct *shell = found_task_pid(*pid);
while (1){
if(shell->state == TASK_DEATH){
screen_clear();
int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell");
kernel_thread(check_task,&pid,"CPOS-CK");
}
}
return 0;
}

void kernel_main(multiboot_t *multiboot) {

io_cli();
Expand Down Expand Up @@ -141,7 +160,22 @@ void kernel_main(multiboot_t *multiboot) {
clock_sleep(25);

vfs_change_path("apps");
klogf(user_process("shell.bin","Shell") != -1,"Shell process init.\n");
int pid = user_process("shell.bin","Shell");
klogf(pid != -1,"Shell process init.\n");
if(pid == -1){
printf("UserShell launch fault.\n");
printf("Launching system shell...\n");

int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell");
klogf(pid != -1,"Launch kernel shell.\n");
kernel_thread(check_task,&pid,"CPOS-CK");
goto ker;
}

kernel_thread(check_task_usershell,&pid,"CPOS-UCK");

ker:

//klogf(user_process("init.bin","Init") != -1,"Init base process init.\n");

//int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell");
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static char syscall_getch(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,ui

static void syscall_exit(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){
task_kill(get_current()->pid);
printf("PID[%d] exit code: %d",get_current()->pid,ebx);
//printf("PID[%d] exit code: %d",get_current()->pid,ebx);
}

static void* syscall_malloc(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){
Expand Down

0 comments on commit 3767787

Please sign in to comment.