diff --git a/README.md b/README.md index fd02e14bfc4dfde46a2fd2f13cd08aa847beb998..07479e55dc983cf8fac9a4a16e8f93d391ebdff0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # XV6-RISCV On K210 Run xv6-riscv on k210 board -[English](./README.md) [䏿–‡](./README_cn.md) +[English](./README.md) | [䏿–‡](./README_cn.md) ``` (`-') (`-') <-.(`-') @@ -40,7 +40,8 @@ make build ## Run on k210 board Instead of the original file system, xv6-k210 runs with FAT32. You might need an SD card with FAT32 format. To start `shell`, you need to rename the "_init" and "_sh" in the "/xv6-user" to "init" and "sh" after building, -then copy them to the root of your SD card. +then copy them to the root of your SD card. +Also, you can copy other programs start with "\_". Or you can directly run the command as below with your SD card connected to your PC (SD card reader required). Warning: this will format your SD card and clean your original data! @@ -88,6 +89,25 @@ In addition, `shell` supports some shortcut keys as below: - Ctrl-D -- end of file (EOF) - Ctrl-P -- print process list +## Add my programs on xv6-k210 +1. Make a new C source file in `xv6-user/` like `myprog.c`, and put your codes; +2. You can include `user.h` to use the functions declared in it, such as `open`, `gets` and `printf`; +3. Add a line "`$U/_myprog\`" in `Makefile` as below: + ```Makefile + UPROGS=\ + $U/_init\ + $U/_sh\ + $U/_cat\ + ... + $U/_myprog\ # Don't ignore the leading '_' + ``` +4. Then make: + ```bash + make userprogs + ``` + Now you might see `_myprog` in `xv6-user/` if no error detected. Finally you need to copy it into your SD (see [here](#run-on-k210-board)) + or FS image (see [here](#run-on-qemu-system-riscv64)). + ## Progress - [x] Multicore boot - [x] Bare-metal printf @@ -100,8 +120,8 @@ In addition, `shell` supports some shortcut keys as below: - [x] Process management - [x] File system - [x] User program -- [ ] Steady keyboard input(k210) +- [X] Steady keyboard input(k210) ## TODO -Keyboard input on k210 platform. +Fix the bugs of U-mode exception caught by RUSTSBI. diff --git a/README_cn.md b/README_cn.md index 6b003ebb5f3d406f88ff19485c56059b71313a42..1f5c2ce96fdc126a6bddaa1bfdfb1cff86508a38 100644 --- a/README_cn.md +++ b/README_cn.md @@ -1,5 +1,5 @@ # XV6-RISCV On K210 -[English](./README.md) [䏿–‡](./README_cn.md) +[English](./README.md) | [䏿–‡](./README_cn.md) 在 `K210` 开呿¿ä¸Šè¿è¡Œ `xv6-riscv` æ“作系统 ``` @@ -37,9 +37,9 @@ cd xv6-k210 make build ``` -## 在 k210 开呿¿ä¸Šè¿è¡Œ +## <a id="title_k210">在 k210 开呿¿ä¸Šè¿è¡Œ</a> Xv6-k210 采用 FAT32 æ–‡ä»¶ç³»ç»Ÿï¼Œè€Œä¸æ˜¯å…¶åŽŸæœ¬çš„æ–‡ä»¶ç³»ç»Ÿã€‚æ‚¨éœ€è¦ä¸€å¼ FAT32 æ ¼å¼çš„ SD 塿‰èƒ½è¿è¡Œã€‚ -在编译项目åŽï¼Œæ‚¨éœ€è¦å°† “/xv6-user†目录下的 “_init†和 “_sh†é‡å‘½å为 “init†和 “shâ€ï¼Œå¹¶æ‹·è´è‡³ SD å¡çš„æ ¹ç›®å½•下。 +在编译项目åŽï¼Œæ‚¨éœ€è¦å°† “/xv6-user†目录下的 “_init†和 “_sh†é‡å‘½å为 “init†和 “shâ€ï¼Œå¹¶æ‹·è´è‡³ SD å¡çš„æ ¹ç›®å½•下。您还å¯ä»¥æ‹·è´å…¶ä»–编译好的程åº(以“\_â€å¼€å¤´çš„æ–‡ä»¶)。 或者,您å¯ä»¥å°† SD å¡è¿žè‡³ä¸»æœºï¼ˆéœ€è¦è¯»å¡å™¨ï¼‰ï¼Œå†ç›´æŽ¥è¿è¡Œä»¥ä¸‹å‘½ä»¤ã€‚ è¦å‘Šï¼šè¿™ä¼šæ ¼å¼åŒ–您的 SD å¡å¹¶æ¸…除å¡ä¸Šçš„原有数æ®ï¼ @@ -58,7 +58,7 @@ make run k210-serialport=`USB 端å£`(默认是 ttyUSB0) ``` Ps: 在 `Linux` 上这个端å£å¤§éƒ¨åˆ†æƒ…况是 `ttyUSB0`, 如果您使用 `Windows` 或者 `MacOS`,这个文档å¯ä»¥å¸®åŠ©åˆ°æ‚¨ï¼š[maixpy-doc](https://maixpy.sipeed.com/zh/get_started/env_install_driver.html#) -## 在 qemu-system-riscv64 模拟器上è¿è¡Œ +## <a id="title_qemu">在 qemu-system-riscv64 模拟器上è¿è¡Œ</a> é¦–å…ˆï¼Œç¡®ä¿ `qemu-system-riscv64` å·²ç»ä¸‹è½½åˆ°æ‚¨çš„æœºå™¨ä¸Šå¹¶ä¸”åŠ åˆ°äº†çŽ¯å¢ƒå˜é‡ä¸ï¼› 其次,需è¦ä¸€ä¸ª FAT32 ç£ç›˜é•œåƒæ–‡ä»¶ï¼› ```bash @@ -83,6 +83,25 @@ Shell 命令其实也是用户程åºã€‚这些程åºåº”当放置在 SD 塿ˆ– `fs - Ctrl-D -- 文件尾(EOF) - Ctrl-P -- 打å°è¿›ç¨‹åˆ—表 +## æ·»åŠ ç”¨æˆ·ç¨‹åº +1. 在 `xv6-user/` 目录下新建一个 C 文件,如 `myprog.c`,然åŽå†™å…¥æ‚¨çš„代ç ï¼› +2. 您å¯ä»¥å¼•å…¥ `user.h` å¤´æ–‡ä»¶ï¼Œä»¥ä½¿ç”¨å…¶ä¸æä¾›çš„å‡½æ•°ï¼Œå¦‚ `open`ã€`gets` å’Œ `printf`ç‰ï¼› +3. 在 `Makefile` 䏿·»åŠ ä¸€è¡Œ “`$U/_myprog\`â€ï¼Œå…·ä½“如下: + ```Makefile + UPROGS=\ + $U/_init\ + $U/_sh\ + $U/_cat\ + ... + $U/_myprog\ # 请ä¸è¦å¿½ç•¥å¼€å¤´çš„ '_' + ``` +4. ç„¶åŽæ‰§è¡Œï¼š + ```bash + make userprogs + ``` + 如果没有出错,您应该å¯ä»¥åœ¨ `xv6-user/` ä¸çœ‹åˆ° `_myprog` 文件。最åŽï¼Œæ‚¨éœ€è¦å°†å®ƒæ‹·è´åˆ°SDå¡(å‚考<a href="#title_k210">æ¤å¤„</a>) + 或ç£ç›˜é•œåƒ(å‚考<a href="#title_qemu">æ¤å¤„</a>)ä¸ã€‚ + ## 进度 - [x] å¤šæ ¸å¯åЍ - [x] 裸机 printf @@ -95,8 +114,8 @@ Shell 命令其实也是用户程åºã€‚这些程åºåº”当放置在 SD 塿ˆ– `fs - [x] è¿›ç¨‹ç®¡ç† - [x] 文件系统 - [x] ç”¨æˆ·ç¨‹åº -- [ ] 稳定的键盘输入(k210) +- [X] 稳定的键盘输入(k210) ## TODO -完善 k210 å¹³å°ä¸Šçš„键盘输入。 +解决用户æ€å¯¼è‡´ RUSTSBI 报 panic çš„ bug diff --git a/xv6-user/user.h b/xv6-user/user.h index 1b35cc8c82ac855ee6ebf5d0cd550fa26cb38b59..7f1b5a5df9576eb1d5227629339ee8e923df70c0 100644 --- a/xv6-user/user.h +++ b/xv6-user/user.h @@ -1,3 +1,7 @@ +#include "kernel/include/types.h" +#include "kernel/include/stat.h" +#include "kernel/include/fcntl.h" + struct stat; struct rtcdate; struct sysinfo;