diff --git a/kernel/syscall/syscall.c b/kernel/syscall/syscall.c index 9b03828e..eda0ac11 100644 --- a/kernel/syscall/syscall.c +++ b/kernel/syscall/syscall.c @@ -634,7 +634,8 @@ uint64_t sys_wait4(struct pt_regs *regs) wait_queue_sleep_on_interriptible(¤t_pcb->wait_child_proc_exit); // 拷贝子进程的返回码 - copy_to_user(status, (void*)child_proc->exit_code, sizeof(int)); + *status = child_proc->exit_code; + // copy_to_user(status, (void*)child_proc->exit_code, sizeof(int)); proc->next_pcb = child_proc->next_pcb; // 释放子进程的页表 diff --git a/user/apps/about/about.c b/user/apps/about/about.c index f8d0ed9d..737a032c 100644 --- a/user/apps/about/about.c +++ b/user/apps/about/about.c @@ -1,8 +1,31 @@ #include +void print_ascii_logo() +{ + printf(" ____ ___ ____ \n"); + printf("| _ \\ _ __ __ _ __ _ ___ _ __ / _ \\ / ___| \n"); + printf("| | | || '__| / _` | / _` | / _ \\ | '_ \\ | | | |\\___ \\ \n"); + printf("| |_| || | | (_| || (_| || (_) || | | || |_| | ___) |\n"); + printf("|____/ |_| \\__,_| \\__, | \\___/ |_| |_| \\___/ |____/ \n"); + printf(" |___/ \n"); +} +void print_copyright() +{ + printf(" DragonOS - An opensource operating system.\n"); + printf(" Copyright: fslongjin. 2022, All rights reserved.\n"); + printf(" You can visit the project via:\n"); + printf("\n"); + put_string(" https://github.com/fslongjin/DragonOS\n", COLOR_ORANGE, COLOR_BLACK); + printf("\n"); + printf(" Email: longjin@RinGoTek.cn\n"); + printf("\n"); +} int main() { - printf("Hello World!\n"); - exit(0); - while(1); + // printf("Hello World!\n"); + print_ascii_logo(); + print_copyright(); + exit(1); + while (1) + ; } \ No newline at end of file diff --git a/user/apps/shell/cmd.c b/user/apps/shell/cmd.c index de83cbec..c0d86f53 100644 --- a/user/apps/shell/cmd.c +++ b/user/apps/shell/cmd.c @@ -31,6 +31,7 @@ struct built_in_cmd_t shell_cmds[] = {"rmdir", shell_cmd_rmdir}, {"reboot", shell_cmd_reboot}, {"touch", shell_cmd_touch}, + {"about", shell_cmd_about}, {"help", shell_help}, }; @@ -62,7 +63,10 @@ static char *get_target_filepath(const char *filename, int *result_path_len) file_path[cwd_len] = '/'; // 拼接完整路径 - strcat(file_path, filename); + if (filename[0] == '/') + strcat(file_path, filename + 1); + else + strcat(file_path, filename); return file_path; } @@ -377,21 +381,37 @@ int shell_cmd_exec(int argc, char **argv) // 子进程 int path_len = 0; char *file_path = get_target_filepath(argv[1], &path_len); - // printf("before execv, path=%s, argc=%d\n", file_path, argc); + printf("before execv, path=%s, argc=%d\n", file_path, argc); execv(file_path, argv); free(argv); - while(1); + while (1) + ; exit(0); } else { printf("parent process wait for pid:[ %d ]\n", pid); - + waitpid(pid, &retval, 0); printf("parent process wait pid [ %d ], exit code=%d\n", pid, retval); free(argv); } +} +int shell_cmd_about(int argc, char **argv) +{ + if (argv != NULL) + free(argv); + int aac = 0; + char **aav; + + unsigned char input_buffer[INPUT_BUFFER_SIZE] = {0}; + + strcpy(input_buffer, "exec /about.elf\0"); + + parse_command(input_buffer, &aac, &aav); + + shell_cmd_exec(aac, aav); } @@ -406,4 +426,54 @@ int shell_cmd_exec(int argc, char **argv) int shell_cmd_reboot(int argc, char **argv) { return syscall_invoke(SYS_REBOOT, 0, 0, 0, 0, 0, 0, 0, 0); +} + +/** + * @brief 解析shell命令 + * + * @param buf 输入缓冲区 + * @param argc 返回值:参数数量 + * @param argv 返回值:参数列表 + * @return int 主命令的编号 + */ +int parse_command(char *buf, int *argc, char ***argv) +{ + // printf("parse command\n"); + int index = 0; // 当前访问的是buf的第几位 + // 去除命令前导的空格 + while (index < INPUT_BUFFER_SIZE && buf[index] == ' ') + ++index; + + // 计算参数数量 + for (int i = index; i < (INPUT_BUFFER_SIZE - 1); ++i) + { + // 到达了字符串末尾 + if (!buf[i]) + break; + if (buf[i] != ' ' && (buf[i + 1] == ' ' || buf[i + 1] == '\0')) + ++(*argc); + } + + // printf("\nargc=%d\n", *argc); + + // 为指向每个指令的指针分配空间 + *argv = (char **)malloc(sizeof(char **) * (*argc)); + memset(*argv, 0, sizeof(char **) * (*argc)); + // 将每个命令都单独提取出来 + for (int i = 0; i < *argc && index < INPUT_BUFFER_SIZE; ++i) + { + // 提取出命令,以空格作为分割 + *((*argv) + i) = &buf[index]; + while (index < (INPUT_BUFFER_SIZE - 1) && buf[index] && buf[index] != ' ') + ++index; + buf[index++] = '\0'; + + // 删除命令间多余的空格 + while (index < INPUT_BUFFER_SIZE && buf[index] == ' ') + ++index; + + // printf("%s\n", (*argv)[i]); + } + // 以第一个命令作为主命令,查找其在命令表中的编号 + return shell_find_cmd(**argv); } \ No newline at end of file diff --git a/user/apps/shell/cmd.h b/user/apps/shell/cmd.h index 507b143a..a74f11f7 100644 --- a/user/apps/shell/cmd.h +++ b/user/apps/shell/cmd.h @@ -2,6 +2,7 @@ // cwd字符串的最大大小 #define SHELL_CWD_MAX_SIZE 256 +#define INPUT_BUFFER_SIZE 512 /** * @brief shell内建命令结构体 @@ -121,3 +122,22 @@ int shell_cmd_exec(int argc, char **argv); * @return int */ int shell_cmd_reboot(int argc, char **argv); + +/** + * @brief 关于软件 + * + * @param argc + * @param argv + * @return int + */ +int shell_cmd_about(int argc, char **argv); + +/** + * @brief 解析shell命令 + * + * @param buf 输入缓冲区 + * @param argc 返回值:参数数量 + * @param argv 返回值:参数列表 + * @return int + */ +int parse_command(char *buf, int *argc, char ***argv); \ No newline at end of file diff --git a/user/apps/shell/shell.c b/user/apps/shell/shell.c index 64fdb9e5..008ea6dd 100644 --- a/user/apps/shell/shell.c +++ b/user/apps/shell/shell.c @@ -17,20 +17,12 @@ * @param buf 输入缓冲区 * @return 读取的字符数 */ -#define INPUT_BUFFER_SIZE 512 + int shell_readline(int fd, char *buf); extern char *shell_current_path; -/** - * @brief 解析shell命令 - * - * @param buf 输入缓冲区 - * @param argc 返回值:参数数量 - * @param argv 返回值:参数列表 - * @return int - */ -int parse_command(char *buf, int *argc, char ***argv); + /** * @brief shell主循环 @@ -130,52 +122,3 @@ int shell_readline(int fd, char *buf) } } -/** - * @brief 解析shell命令 - * - * @param buf 输入缓冲区 - * @param argc 返回值:参数数量 - * @param argv 返回值:参数列表 - * @return int 主命令的编号 - */ -int parse_command(char *buf, int *argc, char ***argv) -{ - // printf("parse command\n"); - int index = 0; // 当前访问的是buf的第几位 - // 去除命令前导的空格 - while (index < INPUT_BUFFER_SIZE && buf[index] == ' ') - ++index; - - // 计算参数数量 - for (int i = index; i < (INPUT_BUFFER_SIZE - 1); ++i) - { - // 到达了字符串末尾 - if (!buf[i]) - break; - if (buf[i] != ' ' && (buf[i + 1] == ' ' || buf[i + 1] == '\0')) - ++(*argc); - } - - // printf("\nargc=%d\n", *argc); - - // 为指向每个指令的指针分配空间 - *argv = (char **)malloc(sizeof(char **) * (*argc)); - memset(*argv, 0, sizeof(char **) * (*argc)); - // 将每个命令都单独提取出来 - for (int i = 0; i < *argc && index < INPUT_BUFFER_SIZE; ++i) - { - // 提取出命令,以空格作为分割 - *((*argv) + i) = &buf[index]; - while (index < (INPUT_BUFFER_SIZE - 1) && buf[index] && buf[index] != ' ') - ++index; - buf[index++] = '\0'; - - // 删除命令间多余的空格 - while (index < INPUT_BUFFER_SIZE && buf[index] == ' ') - ++index; - - // printf("%s\n", (*argv)[i]); - } - // 以第一个命令作为主命令,查找其在命令表中的编号 - return shell_find_cmd(**argv); -} \ No newline at end of file