diff --git a/ci-user/Makefile b/ci-user/Makefile index bd3777f..3741230 100644 --- a/ci-user/Makefile +++ b/ci-user/Makefile @@ -20,10 +20,10 @@ else ifeq ($(CHAPTER), 8) endif randomize: - find user/src/bin -name "*.rs" | xargs sed -i 's/OK/OK$(RAND)/g' - find user/src/bin -name "*.rs" | xargs sed -i 's/passed/passed$(RAND)/g' - find check -name "*.py" | xargs sed -i 's/OK/OK$(RAND)/g' - find check -name "*.py" | xargs sed -i 's/passed/passed$(RAND)/g' + find user/src/bin -name "*.rs" | xargs perl -pi -e s,OK,OK$(RAND),g + find user/src/bin -name "*.rs" | xargs perl -pi -e s,passed,passed$(RAND),g + find check -name "*.py" | xargs perl -pi -e s,OK,OK$(RAND),g + find check -name "*.py" | xargs perl -pi -e s,passed,passed$(RAND),g test: randomize python3 overwrite.py $(CHAPTER) diff --git a/guide/source/0setup-devel-env.rst b/guide/source/0setup-devel-env.rst index a8b3b72..43cf3ba 100644 --- a/guide/source/0setup-devel-env.rst +++ b/guide/source/0setup-devel-env.rst @@ -18,7 +18,7 @@ 目前,实验主要支持 Ubuntu18.04/20.04 操作系统。使用 Windows10 和 macOS 的读者,可以安装一台 Ubuntu18.04 虚拟机或 Docker -进行实验。也可基于 **gihub classroom with codespaces** 进行开发。 +进行实验。也可基于 **github classroom with codespaces** 进行开发。 Github Classroom方式进行在线OS 环境配置 diff --git a/guide/source/chapter1/0intro.rst b/guide/source/chapter1/0intro.rst index dd767ae..244cf9a 100644 --- a/guide/source/chapter1/0intro.rst +++ b/guide/source/chapter1/0intro.rst @@ -59,10 +59,6 @@ 获取本章代码: -.. code-block:: console - -获取本章代码: - .. code-block:: console $ git clone ``gitaddr of github-classroom-build-lab0-0`` diff --git a/guide/source/chapter1/2remove-std.rst b/guide/source/chapter1/2remove-std.rst index f70f4d8..2a8c693 100644 --- a/guide/source/chapter1/2remove-std.rst +++ b/guide/source/chapter1/2remove-std.rst @@ -118,6 +118,12 @@ println! 宏是由标准库 std 提供的,且会使用到一个名为 write 分析被移除标准库的程序 ----------------------------- +首先安装 cargo-binutils 工具集: + +.. code-block:: console + $ cargo install cargo-binutils + $ rustup component add llvm-tools-preview + 我们可以通过一些工具来分析目前的程序: .. code-block:: console diff --git a/guide/source/chapter1/3mini-rt-usrland.rst b/guide/source/chapter1/3mini-rt-usrland.rst index b466f9d..4710198 100644 --- a/guide/source/chapter1/3mini-rt-usrland.rst +++ b/guide/source/chapter1/3mini-rt-usrland.rst @@ -162,11 +162,15 @@ Rust 的 core 库内建了以一系列帮助实现显示字符的基本 Trait 如果你觉得理解 Rust 宏有困难,把它当成黑盒就好! + 学习rust宏的参考链接: `The Little Book of Rust Macros `_ + 首先封装一下对 ``SYSCALL_WRITE`` 系统调用。 .. code-block:: rust + // os/src/main.rs + const SYSCALL_WRITE: usize = 64; pub fn sys_write(fd: usize, buffer: &[u8]) -> isize { @@ -178,6 +182,8 @@ Rust 的 core 库内建了以一系列帮助实现显示字符的基本 Trait .. code-block:: rust + // os/src/console.rs + struct Stdout; impl Write for Stdout { @@ -196,20 +202,31 @@ Rust 的 core 库内建了以一系列帮助实现显示字符的基本 Trait .. code-block:: rust - #[macro_export] + // os/src/console.rs + macro_rules! print { ($fmt: literal $(, $($arg: tt)+)?) => { $crate::console::print(format_args!($fmt $(, $($arg)+)?)); } } - #[macro_export] macro_rules! println { ($fmt: literal $(, $($arg: tt)+)?) => { - print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?)); + $crate::console::print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?)); } } + // os/src/main.rs + + #![no_std] + #![no_main] + + #[macro_use] + mod console; + mod lang_items; + + ... + 接下来,我们调整一下应用程序,让它发出显示字符串和退出的请求: .. code-block:: rust diff --git a/os7-ref/src/link_app.S b/os7-ref/src/link_app.S new file mode 100644 index 0000000..e69de29 diff --git a/os8-ref/src/link_app.S b/os8-ref/src/link_app.S new file mode 100644 index 0000000..e69de29 diff --git a/scheduling.md b/scheduling.md index 7d3565a..6204a5a 100644 --- a/scheduling.md +++ b/scheduling.md @@ -71,7 +71,7 @@ 3.) 完成第二步后,你的rustings实验练习 的 github repository 会被自动建立好,点击此github repository的链接,就可看到你要完成的实验了。 - 4.) 在你的第一个实验练习的网页的中上部可以看到一个醒目的 `code` 绿色按钮,点击后,可以进一步看到 `codespace` 标签和醒目的 `create codesapce on main` 绿色按钮。请点击这个绿色按钮,就可以进入到在线的ubuntu +vscode环境中 + 4.) 在你的第一个实验练习的网页的中上部可以看到一个醒目的 `code` 绿色按钮,点击后,可以进一步看到 `codespace` 标签和醒目的 `create codesapce on edu` 绿色按钮。请点击这个绿色按钮,就可以进入到在线的ubuntu +vscode环境中 5.) 再按照下面的环境安装提示在vscode的 `console` 中安装配置开发环境:rustc等工具。注:也可在vscode的 `console` 中执行 ``make codespaces_setenv`` 来自动安装配置开发环境(执行``sudo``需要root权限,仅需要执行一次)。