# 2019q1 Homework4 (riscv) contributed by < `njjack` > ### riscv-emu 原始程式碼中多次出現 virtio,這樣的機制對於 host 和 guest 兩端有何作用?在閱讀 Virtio: An I/O virtualization framework for Linux 一文後,對照原始程式碼,你發現什麼? 首先粗略地比較 full virtualization 和 paravirtualization 相較於 full virtualization 中 guest 不須修改即可運行但 emulation 較複雜且沒效率,paravirtualization 提供較有效率的方法,但須修改 guest 使 guest 能在 hypervisor 上運行且合作 virtio 在 paravirtualization 中扮演的角色是提供 guset 中 front-end driver 統一的介面,以和 hypervisor 中 back-end driver 溝通 ### 編譯 [kilo](https://github.com/sysprog21/kilo) 編輯器,允許在 RISC-V/Linux 模擬環境中運作 用 cross-compiler 編譯 kilo.c ``` $ /tmp/buildroot-riscv-2018-10-20/output/host/usr/bin/riscv64-buildroot-linux-gnu-gcc -o kilo kilo.c -static ``` 掛載 Host 端檔案系統到 Guest 端 `~# mount -t 9p /dev/root /mnt` 執行 `/mnt/kilo # ./kilo README.md` ![](https://i.imgur.com/GEUJ1Kc.png) ### 客製化 buildroot,將 kilo 編輯器加入到 build image,建立 Git repository 來追蹤你對 buildroot 做的變更,並依據 Buildroot Manual 更新套件描述和建構方式 參考[自建 buildroot package](http://vh21.github.io/linux/2016/05/07/add-customized-buildroot-package.html),建立 local package * 在 `buildroot-riscv-2018-10-20/package` 下建立 directory `kilo` * 在 directory `kilo` 中建立 `Config.in` 和 `kilo.mk` * 修改 `buildroot-riscv-2018-10-20/package/Config.in` 的內容,在 `menu Text editors and viewers` 增加 `source "package/kilo/Config.in"` 參考 The Buildroot user manual [17.2](https://buildroot.org/downloads/manual/manual.html#adding-packages) , [17.5](https://buildroot.org/downloads/manual/manual.html#_infrastructure_for_packages_with_specific_build_systems) , [17.23](https://buildroot.org/downloads/manual/manual.html#_tips_and_tricks) ,以及同學 `rebvivi` [共筆](https://hackmd.io/s/S1fWAc2UV),建立 `Config.in` 和 `.mk` `Config.in` : ``` config BR2_PACKAGE_KILO bool "kilo" help Kilo is a small text editor in less than 1K lines of code (counted with cloc). https://github.com/sysprog21/kilo ``` `kilo.mk` : ``` KILO_VERSION = af3919d68cb2e70a3d9a2309596cf290cf6bc1ac KILO_SITE = $(call github,sysprog21,kilo,$(KILO_VERSION)) LIBFOO_LICENSE = BSD 2-Clause define KILO_BUILD_CMDS $(MAKE) $(TARGET_CONFIGURE_OPTS) -C $(@D) all endef define KILO_INSTALL_TARGET_CMDS $(INSTALL) -D -m 0755 $(@D)/kilo $(TARGET_DIR)/usr/bin endef $(eval $(generic-package)) ``` `make menuconfig` 時可以在 `Target packages ---> Text editors and viewer` 找到上述步驟加入的新的 source `kilo` ![](https://i.imgur.com/kHVQmCt.png) 選取之後編譯,就能在 guest 環境中執行 kilo ``` [root@localhost bin]# ./kilo Usage: kilo <filename> ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up