Skip to content

Commit

Permalink
finish sh.c and update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ejunjsh committed Jun 30, 2021
1 parent 0cf2f39 commit 571fc6b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# myxv6

看代码并加上中文注释
看代码并加上中文注释,还有就是做lab

## 环境

Expand All @@ -21,12 +21,17 @@

所以不知道后面更新的qemu是否还能启动,

所以记下现在运行的qemu版本
所以记下现在运行的版本

$ brew info qemu
qemu: stable 6.0.0 (bottled), HEAD
Emulator for x86 and PowerPC
...
$ riscv64-unknown-elf-gcc --version
riscv64-unknown-elf-gcc (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ qemu-system-riscv64 --version
QEMU emulator version 6.0.0
Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers

退出qemu:

Expand Down
20 changes: 10 additions & 10 deletions user/sh.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "user/user.h"
#include "kernel/fcntl.h"

// Parsed command representation
// 解析的命令表示
#define EXEC 1
#define REDIR 2
#define PIPE 3
Expand Down Expand Up @@ -49,11 +49,11 @@ struct backcmd {
struct cmd *cmd;
};

int fork1(void); // Fork but panics on failure.
int fork1(void); // Fork 但如果错误则,恐慌(panic)
void panic(char*);
struct cmd *parsecmd(char*);

// Execute cmd. Never returns.
// 执行命令,不会返回
void
runcmd(struct cmd *cmd)
{
Expand Down Expand Up @@ -147,19 +147,19 @@ main(void)
static char buf[100];
int fd;

// Ensure that three file descriptors are open.
// 保证这三个文件描述符是打开的
while((fd = open("console", O_RDWR)) >= 0){
if(fd >= 3){
close(fd);
break;
}
}

// Read and run input commands.
// 读取和运行输入命令
while(getcmd(buf, sizeof(buf)) >= 0){
if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
// Chdir must be called by the parent, not the child.
buf[strlen(buf)-1] = 0; // chop \n
// Chdir 必须被父调用,不能被子调用
buf[strlen(buf)-1] = 0; // 去掉 \n
if(chdir(buf+3) < 0)
fprintf(2, "cannot cd %s\n", buf+3);
continue;
Expand Down Expand Up @@ -190,7 +190,7 @@ fork1(void)
}

//PAGEBREAK!
// Constructors
// 构造cmd

struct cmd*
execcmd(void)
Expand Down Expand Up @@ -257,7 +257,7 @@ backcmd(struct cmd *subcmd)
return (struct cmd*)cmd;
}
//PAGEBREAK!
// Parsing
// 解析

char whitespace[] = " \t\r\n\v";
char symbols[] = "<|>&;()";
Expand Down Expand Up @@ -445,7 +445,7 @@ parseexec(char **ps, char *es)
return ret;
}

// NUL-terminate all the counted strings.
// NUL终结所有字符串
struct cmd*
nulterminate(struct cmd *cmd)
{
Expand Down

0 comments on commit 571fc6b

Please sign in to comment.