Skip to content

Commit b543a03

Browse files
committed
feat: simple drawing board GUI
1 parent 971a9a9 commit b543a03

33 files changed

+185
-664
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ os/src/link_app.S
99
os/src/linker.ld
1010
os/last-*
1111
os/.gdb_history
12+
os/virt.out
1213
tools/
1314
pushall.sh

os/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ virtio-input-decoder = "0.1.4"
1919
embedded-graphics = "0.7.1"
2020
tinybmp = "0.3.1"
2121

22+
2223
[profile.release]
2324
debug = true

os/Makefile

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ BOARD := qemu
1212
SBI ?= rustsbi
1313
BOOTLOADER := ../bootloader/$(SBI)-$(BOARD).bin
1414

15+
# GUI
16+
GUI ?= off
17+
ifeq ($(GUI), off)
18+
GUI_OPTION := -display none
19+
endif
20+
1521
# Building mode argument
1622
ifeq ($(MODE), release)
1723
MODE_ARG := --release
@@ -67,27 +73,12 @@ disasm-vim: kernel
6773

6874
run: run-inner
6975

70-
gui: build
71-
ifeq ($(BOARD),qemu)
72-
@qemu-system-riscv64 \
73-
-M 128m \
74-
-machine virt \
75-
-bios $(BOOTLOADER) \
76-
-device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) \
77-
-drive file=$(FS_IMG),if=none,format=raw,id=x0 \
78-
-device virtio-blk-device,drive=x0 \
79-
-device virtio-gpu-device \
80-
-device virtio-keyboard-device \
81-
-device virtio-mouse-device \
82-
-serial stdio
83-
endif
84-
8576
run-inner: build
8677
@qemu-system-riscv64 \
8778
-M 128m \
8879
-machine virt \
8980
-bios $(BOOTLOADER) \
90-
-display none \
81+
$(GUI_OPTION) \
9182
-device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) \
9283
-drive file=$(FS_IMG),if=none,format=raw,id=x0 \
9384
-device virtio-blk-device,drive=x0 \
@@ -96,6 +87,10 @@ run-inner: build
9687
-device virtio-mouse-device \
9788
-serial stdio
9889

90+
fdt:
91+
@qemu-system-riscv64 -M 128m -machine virt,dumpdtb=virt.out
92+
fdtdump virt.out
93+
9994
debug: build
10095
@tmux new-session -d \
10196
"qemu-system-riscv64 -machine virt -nographic -bios $(BOOTLOADER) -device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) -s -S" && \
@@ -109,4 +104,4 @@ gdbserver: build
109104
gdbclient:
110105
@riscv64-unknown-elf-gdb -ex 'file $(KERNEL_ELF)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234'
111106

112-
.PHONY: build env kernel clean disasm disasm-vim run-inner fs-img gdbserver gdbclient
107+
.PHONY: build env kernel clean disasm disasm-vim run-inner fs-img gdbserver gdbclient fdt

os/run-fdt.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

os/run-nodisp.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

os/run.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

os/src/boards/qemu.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub const VIRT_PLIC: usize = 0xC00_0000;
1414
pub const VIRT_UART: usize = 0x1000_0000;
1515

1616
pub const VIRTGPU_XRES: u32 = 1280;
17+
#[allow(unused)]
1718
pub const VIRTGPU_YRES: u32 = 800;
1819

1920
use crate::drivers::block::BLOCK_DEVICE;
@@ -30,7 +31,7 @@ pub fn device_init() {
3031
plic.set_threshold(hart_id, supervisor, 0);
3132
plic.set_threshold(hart_id, machine, 1);
3233
//irq nums: 5 keyboard, 6 mouse, 8 block, 10 uart
33-
for intr_src_id in [5usize, 6, 8 , 10] {
34+
for intr_src_id in [5usize, 6, 8, 10] {
3435
plic.enable(hart_id, supervisor, intr_src_id);
3536
plic.set_priority(intr_src_id, 1);
3637
}

os/src/drivers/block/virtio_blk.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use super::BlockDevice;
2+
use crate::drivers::bus::virtio::VirtioHal;
23
use crate::sync::{Condvar, UPIntrFreeCell};
34
use crate::task::schedule;
45
use crate::DEV_NON_BLOCKING_ACCESS;
56
use alloc::collections::BTreeMap;
67
use virtio_drivers::{BlkResp, RespStatus, VirtIOBlk, VirtIOHeader};
7-
use crate::drivers::bus::virtio::VirtioHal;
88

99
#[allow(unused)]
1010
const VIRTIO0: usize = 0x10008000;
@@ -69,7 +69,9 @@ impl BlockDevice for VirtIOBlock {
6969
impl VirtIOBlock {
7070
pub fn new() -> Self {
7171
let virtio_blk = unsafe {
72-
UPIntrFreeCell::new(VirtIOBlk::<VirtioHal>::new(&mut *(VIRTIO0 as *mut VirtIOHeader)).unwrap())
72+
UPIntrFreeCell::new(
73+
VirtIOBlk::<VirtioHal>::new(&mut *(VIRTIO0 as *mut VirtIOHeader)).unwrap(),
74+
)
7375
};
7476
let mut condvars = BTreeMap::new();
7577
let channels = virtio_blk.exclusive_access().virt_queue_size();
@@ -83,4 +85,3 @@ impl VirtIOBlock {
8385
}
8486
}
8587
}
86-

os/src/drivers/bus/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub mod virtio;
1+
pub mod virtio;

os/src/drivers/bus/virtio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use alloc::vec::Vec;
21
use crate::mm::{
32
frame_alloc, frame_dealloc, kernel_token, FrameTracker, PageTable, PhysAddr, PhysPageNum,
43
StepByOne, VirtAddr,
54
};
65
use crate::sync::UPIntrFreeCell;
6+
use alloc::vec::Vec;
77
use lazy_static::*;
88
use virtio_drivers::Hal;
99

@@ -49,4 +49,4 @@ impl Hal for VirtioHal {
4949
.unwrap()
5050
.0
5151
}
52-
}
52+
}

0 commit comments

Comments
 (0)