Skip to content

Commit

Permalink
Merge branch 'main' into lab/6
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Mar 18, 2024
2 parents 54d0421 + 2d743b4 commit eebbbf7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
8 changes: 4 additions & 4 deletions docs/labs/0x04/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,13 @@ pub fn write(fd: u8, buf: &[u8]) -> isize {
}
```

对于 `write` 系统调用,用户程序需要将数据写入到资源中,对此系统调用进行如下约定
对于 `write` 系统调用,用户程序需要将数据写入到资源中,`syscall::dispatcher` 中对此系统调用的相关参数进行如下约定

```
fd: arg0 as u8, buf: &[u8] (ptr: arg1 as *const u8, len: arg2)
```

为了便于理解,给出了用户侧进行调用时的示例代码,从 `print!` 的实现开始:
为了便于理解,给出了用户侧进行调用时的相关调用过程,从 `print!` 的实现开始:

```rust
#[macro_export]
Expand All @@ -644,7 +644,7 @@ impl Stdout {
}
```

传递给 `sys_write`,由此函数对传入的参数进行处理,并调用系统调用:
从而传递给 `sys_write`,由此函数对传入的参数进行处理,并调用系统调用:

```rust
pub fn sys_write(fd: u8, buf: &[u8]) -> Option<usize> {
Expand Down Expand Up @@ -763,7 +763,7 @@ pub fn exit(ret: isize, context: &mut ProcessContext) {

尝试修改用户态库中的 `entry!` 和 `panic` 函数,在用户程序中调用 `exit` 系统调用,并传递一个返回值,以验证用户程序的退出功能。

值此为止,你应当可以生成用户程序、输出 `Hello, world!!!`,并正确退出。
至此为止,你应当可以生成用户程序、输出 `Hello, world!!!`,并正确退出。

### 进程的创建与等待

Expand Down
9 changes: 6 additions & 3 deletions src/0x00/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ launch:
-net none \
$(QEMU_ARGS) \
$(QEMU_OUTPUT) \
-drive format=raw,file=fat:rw:${ESP}
-drive format=raw,file=fat:${ESP} \
-snapshot

intdbg:
@qemu-system-x86_64 \
-bios ${OVMF} \
-net none \
$(QEMU_ARGS) \
$(QEMU_OUTPUT) \
-drive format=raw,file=fat:rw:${ESP} \
-drive format=raw,file=fat:${ESP} \
-snapshot \
-no-reboot -d int,cpu_reset

debug:
Expand All @@ -39,7 +41,8 @@ debug:
-net none \
$(QEMU_ARGS) \
$(QEMU_OUTPUT) \
-drive format=raw,file=fat:rw:${ESP} \
-drive format=raw,file=fat:${ESP} \
-snapshot \
-s -S

clean:
Expand Down
2 changes: 1 addition & 1 deletion src/0x00/ysos.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def qemu(output: str = '-nographic', memory: str = '96M', debug: bool = False, i
raise Exception('qemu-system-x86_64 not found in PATH')

qemu_args = [qemu_exe, '-bios', args.bios, '-net', 'none', *output.split(),
'-m', memory, '-drive', 'format=raw,file=fat:rw:esp']
'-m', memory, '-drive', 'format=raw,file=fat:esp', '-snapshot']

if debug:
qemu_args += ['-s', '-S']
Expand Down
9 changes: 6 additions & 3 deletions src/0x01/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ launch:
-net none \
$(QEMU_ARGS) \
$(QEMU_OUTPUT) \
-drive format=raw,file=fat:rw:${ESP}
-drive format=raw,file=fat:${ESP} \
-snapshot

intdbg:
@qemu-system-x86_64 \
-bios ${OVMF} \
-net none \
$(QEMU_ARGS) \
$(QEMU_OUTPUT) \
-drive format=raw,file=fat:rw:${ESP} \
-drive format=raw,file=fat:${ESP} \
-snapshot \
-no-reboot -d int,cpu_reset

debug:
Expand All @@ -50,7 +52,8 @@ debug:
-net none \
$(QEMU_ARGS) \
$(QEMU_OUTPUT) \
-drive format=raw,file=fat:rw:${ESP} \
-drive format=raw,file=fat:${ESP} \
-snapshot \
-s -S

clean:
Expand Down
2 changes: 1 addition & 1 deletion src/0x01/ysos.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def qemu(output: str = '-nographic', memory: str = '96M', debug: bool = False, i
raise Exception('qemu-system-x86_64 not found in PATH')

qemu_args = [qemu_exe, '-bios', args.bios, '-net', 'none', *output.split(),
'-m', memory, '-drive', 'format=raw,file=fat:rw:esp']
'-m', memory, '-drive', 'format=raw,file=fat:esp', '-snapshot']

if debug:
qemu_args += ['-s', '-S']
Expand Down
3 changes: 3 additions & 0 deletions src/0x04/pkg/kernel/src/interrupt/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub fn dispatcher(context: &mut ProcessContext) {
context.regs.rdx,
);

// NOTE: you may want to trace syscall arguments
// trace!("{}", args);

match args.syscall {
// fd: arg0 as u8, buf: &[u8] (ptr: arg1 as *const u8, len: arg2)
Syscall::Read => { /* FIXME: read from fd & return length */},
Expand Down

0 comments on commit eebbbf7

Please sign in to comment.