Browse Source

fix for nightly-2021-03-01 and OpenSBI 0.8

Runji Wang 4 years ago
parent
commit
6c5c8e281e
8 changed files with 17 additions and 28 deletions
  1. 0 2
      README.md
  2. 2 2
      examples/riscv/Cargo.toml
  3. 5 15
      examples/riscv/Makefile
  4. 1 1
      examples/riscv/rust-toolchain
  5. 1 0
      examples/riscv/src/main.rs
  6. 3 3
      src/blk.rs
  7. 2 2
      src/gpu.rs
  8. 3 3
      src/net.rs

+ 0 - 2
README.md

@@ -4,8 +4,6 @@
 
 VirtIO guest drivers in Rust. For **no_std + no_alloc** environment.
 
-🚧 Working In Progress. We are now moving code from [rCore kernel](https://github.com/rcore-os/rCore/tree/master/kernel/src/drivers) to here.
-
 ## Components
 
 | Device | Status            |

+ 2 - 2
examples/riscv/Cargo.toml

@@ -8,8 +8,8 @@ edition = "2018"
 
 [dependencies]
 log = "0.4"
-riscv = "0.5"
-opensbi-rt = { git = "https://github.com/rcore-os/opensbi-rt.git", rev = "38399b6" }
+riscv = "0.6"
+opensbi-rt = { git = "https://github.com/rcore-os/opensbi-rt.git", rev = "1308cc5" }
 device_tree = { git = "https://github.com/rcore-os/device_tree-rs", rev = "2fa8411" }
 virtio-drivers = { path = "../.." }
 lazy_static = { version = "1.4", features = ["spin_no_std"] }

+ 5 - 15
examples/riscv/Makefile

@@ -2,7 +2,6 @@ arch ?= riscv64
 target := $(arch)imac-unknown-none-elf
 mode := release
 kernel := target/$(target)/$(mode)/riscv
-bin := target/$(target)/$(mode)/kernel.bin
 img := target/$(target)/$(mode)/img
 
 sysroot := $(shell rustc --print sysroot)
@@ -14,12 +13,6 @@ ifeq ($(mode), release)
 	BUILD_ARGS += --release
 endif
 
-ifeq ($(arch), riscv32)
-	START_ADDR := 0x80400000
-else ifeq ($(arch), riscv64)
-	START_ADDR := 0x80200000
-endif
-
 .PHONY: kernel build clean qemu run env
 
 build: $(bin)
@@ -31,9 +24,6 @@ env:
 kernel:
 	cargo build $(BUILD_ARGS)
 
-$(bin): kernel
-	$(objcopy) $(kernel) --strip-all -O binary $@
-
 asm:
 	$(objdump) -d $(kernel) | less
 
@@ -46,18 +36,18 @@ header:
 clean:
 	cargo clean
 
-qemu: $(bin) $(img)
-	sudo qemu-system-$(arch) \
+qemu: kernel $(img)
+	qemu-system-$(arch) \
 		-machine virt \
 		-serial mon:stdio \
 		-bios default \
-		-device loader,file=$(bin),addr=$(START_ADDR) \
+		-kernel $(kernel) \
 		-drive file=$(img),if=none,format=raw,id=x0 \
 		-device virtio-blk-device,drive=x0 \
 		-device virtio-gpu-device \
 		-device virtio-mouse-device \
-		-netdev type=tap,id=net0,script=no,downscript=no \
-		-device virtio-net-device,netdev=net0
+		# -netdev type=tap,id=net0,script=no,downscript=no \
+		# -device virtio-net-device,netdev=net0
 
 $(img):
 	dd if=/dev/zero of=$@ bs=512 count=32

+ 1 - 1
examples/riscv/rust-toolchain

@@ -1 +1 @@
-nightly-2020-04-07
+nightly-2021-03-01

+ 1 - 0
examples/riscv/src/main.rs

@@ -25,6 +25,7 @@ extern "C" fn main(_hartid: usize, device_tree_paddr: usize) {
 
 fn init_dt(dtb: usize) {
     info!("device tree @ {:#x}", dtb);
+    #[repr(C)]
     struct DtbHeader {
         be_magic: u32,
         be_size: u32,

+ 3 - 3
src/blk.rs

@@ -2,7 +2,7 @@ use super::*;
 use crate::header::VirtIOHeader;
 use crate::queue::VirtQueue;
 use bitflags::*;
-use core::sync::atomic::spin_loop_hint;
+use core::hint::spin_loop;
 use log::*;
 use volatile::Volatile;
 
@@ -62,7 +62,7 @@ impl VirtIOBlk<'_> {
         self.queue.add(&[req.as_buf()], &[buf, resp.as_buf_mut()])?;
         self.header.notify(0);
         while !self.queue.can_pop() {
-            spin_loop_hint();
+            spin_loop();
         }
         self.queue.pop_used()?;
         match resp.status {
@@ -83,7 +83,7 @@ impl VirtIOBlk<'_> {
         self.queue.add(&[req.as_buf(), buf], &[resp.as_buf_mut()])?;
         self.header.notify(0);
         while !self.queue.can_pop() {
-            spin_loop_hint();
+            spin_loop();
         }
         self.queue.pop_used()?;
         match resp.status {

+ 2 - 2
src/gpu.rs

@@ -1,7 +1,7 @@
 use super::*;
 use crate::queue::VirtQueue;
 use bitflags::*;
-use core::sync::atomic::spin_loop_hint;
+use core::hint::spin_loop;
 use log::*;
 use volatile::{ReadOnly, Volatile, WriteOnly};
 
@@ -155,7 +155,7 @@ impl VirtIOGpu<'_> {
             .add(&[self.queue_buf_send], &[self.queue_buf_recv])?;
         self.header.notify(QUEUE_TRANSMIT as u32);
         while !self.control_queue.can_pop() {
-            spin_loop_hint();
+            spin_loop();
         }
         self.control_queue.pop_used()?;
         Ok(unsafe { (self.queue_buf_recv.as_ptr() as *const Rsp).read() })

+ 3 - 3
src/net.rs

@@ -2,7 +2,7 @@ use core::mem::{size_of, MaybeUninit};
 
 use super::*;
 use bitflags::*;
-use core::sync::atomic::spin_loop_hint;
+use core::hint::spin_loop;
 use log::*;
 use volatile::{ReadOnly, Volatile};
 
@@ -75,7 +75,7 @@ impl VirtIONet<'_> {
         self.recv_queue.add(&[], &[header_buf, buf])?;
         self.header.notify(QUEUE_RECEIVE as u32);
         while !self.recv_queue.can_pop() {
-            spin_loop_hint();
+            spin_loop();
         }
 
         let (_, len) = self.recv_queue.pop_used()?;
@@ -89,7 +89,7 @@ impl VirtIONet<'_> {
         self.send_queue.add(&[header.as_buf(), buf], &[])?;
         self.header.notify(QUEUE_TRANSMIT as u32);
         while !self.send_queue.can_pop() {
-            spin_loop_hint();
+            spin_loop();
         }
         self.send_queue.pop_used()?;
         Ok(())