diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index 79d7cafa..f9d3aefd 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -697,7 +697,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum buddy_system_allocator 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "59da15ef556589ee78370281d75b67f2d69ed26465ec0e0f3961e2021502426f" "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" "checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427" -"checksum cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ce8bb087aacff865633f0bd5aeaed910fe2fe55b55f4739527f2e023a2e53d" +"checksum cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a0c56216487bb80eec9c4516337b2588a4f2a2290d72a1416d930e4dcdb0c90d" "checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" "checksum console-traits 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f711b3d1d5c3f7ae7d6428901c0f3e5d5f5c800fcfac86bf0252e96373a2cec6" "checksum deque 0.3.2 (git+https://github.com/rcore-os/deque.git?branch=no_std)" = "" @@ -762,7 +762,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum x86 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "841e1ca5a87068718a2a26f2473c6f93cf3b8119f9778fa0ae4b39b664d9e66a" "checksum x86_64 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f9258d7e2dd25008d69e8c9e9ee37865887a5e1e3d06a62f1cb3f6c209e6f177" -"checksum x86_64 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1d0a8201f52d2c7b373c7243dcdfb27c0dd5012f221ef6a126f507ee82005204" +"checksum x86_64 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bb8f09c32a991cc758ebcb9b7984f530095d32578a4e7b85db6ee1f0bbe4c9c6" "checksum x86_64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d69bf2d256c74df90fcc68aaf99862dd205310609e9d56247a5c82ead2f28a93" "checksum xmas-elf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "22678df5df766e8d1e5d609da69f0c3132d794edf6ab5e75e7abcd2270d4cf58" "checksum zero 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5f1bc8a6b2005884962297587045002d8cfb8dcec9db332f4ca216ddc5de82c5" diff --git a/kernel/Makefile b/kernel/Makefile index b6620a4b..6133f11f 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -98,6 +98,7 @@ export DTB = $(dtb) qemu_opts := \ -smp cores=$(smp) qemu_net_opts := +qemu_ui_opts := ifeq ($(arch), x86_64) qemu_opts += \ @@ -120,6 +121,8 @@ qemu_opts += \ -machine accel=kvm qemu_net_opts += \ -device vfio-pci,host=$(pci_passthru) +qemu_ui_opts += \ + -vga std endif ifeq ($(extra_nic), on) qemu_net_opts += \ @@ -138,6 +141,9 @@ qemu_opts += \ qemu_net_opts += \ -netdev type=tap,id=net0,script=no,downscript=no \ -device virtio-net-device,netdev=net0 +qemu_ui_opts += \ + -device virtio-gpu-device \ + -device virtio-mouse-device else ifeq ($(arch), riscv64) ifeq ($(board), u540) @@ -158,6 +164,9 @@ endif qemu_net_opts += \ -netdev type=tap,id=net0,script=no,downscript=no \ -device virtio-net-device,netdev=net0 +qemu_ui_opts += \ + -device virtio-gpu-device \ + -device virtio-mouse-device else ifeq ($(arch), aarch64) qemu_opts += \ @@ -271,9 +280,7 @@ justrunnet: build @sudo qemu-system-$(arch) $(qemu_opts) $(qemu_net_opts) justrunui: build - @qemu-system-$(arch) $(qemu_opts) \ - -device virtio-gpu-device \ - -device virtio-mouse-device + @qemu-system-$(arch) $(qemu_opts) $(qemu_ui_opts) justruntest: build @qemu-system-$(arch) $(filter-out -serial mon:stdio, $(qemu_opts)) --append $(init) -serial file:../tests/stdout -monitor null diff --git a/kernel/src/arch/x86_64/board/mod.rs b/kernel/src/arch/x86_64/board/mod.rs index b6da4cee..f936e17d 100755 --- a/kernel/src/arch/x86_64/board/mod.rs +++ b/kernel/src/arch/x86_64/board/mod.rs @@ -1,15 +1,16 @@ #[path = "../../../drivers/gpu/fb.rs"] pub mod fb; -use fb::{ColorConfig, FramebufferInfo, FramebufferResult, FRAME_BUFFER}; use crate::consts::KERNEL_OFFSET; +use crate::memory::phys_to_virt; +use fb::{ColorConfig, FramebufferInfo, FramebufferResult, FRAME_BUFFER}; pub fn init_driver() { #[cfg(not(feature = "nographic"))] fb::init(); } -pub fn probe_fb_info(width : u32, height : u32, depth : u32) -> FramebufferResult { +pub fn probe_fb_info(width: u32, height: u32, depth: u32) -> FramebufferResult { let fb_info = FramebufferInfo { xres: 1024, yres: 768, @@ -22,5 +23,9 @@ pub fn probe_fb_info(width : u32, height : u32, depth : u32) -> FramebufferResul bus_addr: 0xfd00_0000, screen_size: 1024 * 768 * 3, }; - Ok((fb_info, fb::ColorConfig::BGRA8888, KERNEL_OFFSET + 0xf000_0000)) + Ok(( + fb_info, + fb::ColorConfig::BGRA8888, + phys_to_virt(0xfd00_0000), + )) } diff --git a/kernel/src/arch/x86_64/io.rs b/kernel/src/arch/x86_64/io.rs index 2b0b54a0..d6f8dcb7 100644 --- a/kernel/src/arch/x86_64/io.rs +++ b/kernel/src/arch/x86_64/io.rs @@ -1,6 +1,6 @@ +use super::driver::console::CONSOLE; use super::driver::serial::*; use core::fmt::{Arguments, Write}; -use super::driver::console::CONSOLE; pub fn getchar() -> char { unsafe { @@ -26,7 +26,7 @@ pub fn putfmt(fmt: Arguments) { COM1.lock().write_fmt(fmt).unwrap(); //unsafe { CONSOLE.force_unlock() } //if let Some(console) = CONSOLE.lock().as_mut() { - //console.write_fmt(fmt).unwrap(); + //console.write_fmt(fmt).unwrap(); //} } } diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index fc86c822..edda7272 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -2,6 +2,7 @@ use bootloader::bootinfo::{BootInfo, MemoryRegionType}; use core::sync::atomic::*; use log::*; +pub mod board; pub mod consts; pub mod cpu; pub mod driver; @@ -15,8 +16,6 @@ pub mod paging; pub mod rand; pub mod syscall; pub mod timer; -pub mod ipi; -pub mod board; static AP_CAN_INIT: AtomicBool = AtomicBool::new(false); diff --git a/kernel/src/drivers/gpu/fb.rs b/kernel/src/drivers/gpu/fb.rs index 45b74c0d..136c5815 100644 --- a/kernel/src/drivers/gpu/fb.rs +++ b/kernel/src/drivers/gpu/fb.rs @@ -153,7 +153,7 @@ impl Framebuffer { 8 => ColorDepth8, 16 => ColorDepth16, 32 => ColorDepth32, - 24=> ColorDepth24, + 24 => ColorDepth24, _ => Err(format!("unsupported color depth {}", info.depth))?, }; Ok(Framebuffer { diff --git a/kernel/src/drivers/serial/16550_reg.rs b/kernel/src/drivers/serial/16550_reg.rs index e4d7dc0f..cd0e87f4 100644 --- a/kernel/src/drivers/serial/16550_reg.rs +++ b/kernel/src/drivers/serial/16550_reg.rs @@ -73,11 +73,11 @@ impl Write for SerialPort { self.putchar(8); self.putchar(b' '); self.putchar(8); - }, + } b'\n' => { self.putchar(b'\r'); self.putchar(b'\n'); - }, + } c => { self.putchar(c); } diff --git a/kernel/src/drivers/serial/simple_uart.rs b/kernel/src/drivers/serial/simple_uart.rs index 584fc339..0d01b537 100644 --- a/kernel/src/drivers/serial/simple_uart.rs +++ b/kernel/src/drivers/serial/simple_uart.rs @@ -64,11 +64,11 @@ impl Write for SerialPort { self.putchar(8); self.putchar(b' '); self.putchar(8); - }, + } b'\n' => { self.putchar(b'\r'); self.putchar(b'\n'); - }, + } c => { self.putchar(c); } diff --git a/kernel/src/drivers/serial/ti_16c550c.rs b/kernel/src/drivers/serial/ti_16c550c.rs index e4b1973c..49ad0e29 100644 --- a/kernel/src/drivers/serial/ti_16c550c.rs +++ b/kernel/src/drivers/serial/ti_16c550c.rs @@ -73,11 +73,11 @@ impl Write for SerialPort { self.putchar(8); self.putchar(b' '); self.putchar(8); - }, + } b'\n' => { self.putchar(b'\r'); self.putchar(b'\n'); - }, + } c => { self.putchar(c); } diff --git a/kernel/src/fs/file.rs b/kernel/src/fs/file.rs index 5d8505e1..83ecc557 100644 --- a/kernel/src/fs/file.rs +++ b/kernel/src/fs/file.rs @@ -49,15 +49,16 @@ impl FileHandle { if !self.options.read { return Err(FsError::InvalidParam); // FIXME: => EBADF } - let mut len : usize = 0; - if !self.options.nonblock { // block + let mut len: usize = 0; + if !self.options.nonblock { + // block loop { len = self.inode.read_at(offset, buf)?; if len > 0 { break; } } - }else{ + } else { len = self.inode.read_at(offset, buf)?; } Ok(len) diff --git a/kernel/src/fs/stdio.rs b/kernel/src/fs/stdio.rs index ccb82041..fae5dc74 100644 --- a/kernel/src/fs/stdio.rs +++ b/kernel/src/fs/stdio.rs @@ -94,7 +94,7 @@ impl INode for Stdin { if self.can_read() { buf[0] = self.pop() as u8; Ok(1) - }else{ + } else { Ok(0) } } diff --git a/kernel/src/fs/vga.rs b/kernel/src/fs/vga.rs index d5909af5..3c40e427 100755 --- a/kernel/src/fs/vga.rs +++ b/kernel/src/fs/vga.rs @@ -1,8 +1,9 @@ use rcore_fs::vfs::*; +use crate::arch::board::fb::FRAME_BUFFER; +use crate::memory::phys_to_virt; use alloc::{string::String, sync::Arc, vec::Vec}; use core::any::Any; -use crate::arch::board::fb::FRAME_BUFFER; #[derive(Default)] pub struct Vga; @@ -31,15 +32,19 @@ impl INode for Vga { } fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result { info!("the _offset is {} {}", _offset, _buf[0]); - use crate::consts::KERNEL_OFFSET; use core::slice; - let frame_buffer_data = - unsafe { slice::from_raw_parts_mut((KERNEL_OFFSET + 0xf000_0000) as *mut u8, ( 1024 * 768 * 3) as usize) }; + let frame_buffer_data = unsafe { + slice::from_raw_parts_mut( + phys_to_virt(0xfd00_0000) as *mut u8, + (1024 * 768 * 3) as usize, + ) + }; frame_buffer_data.copy_from_slice(&_buf); return Ok(1024 * 768 * 3); } fn poll(&self) -> Result { - Ok(PollStatus { // TOKNOW and TODO + Ok(PollStatus { + // TOKNOW and TODO read: true, write: false, error: false, diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index e3291b58..5e3c46fd 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -836,11 +836,8 @@ impl Syscall<'_> { return Ok(total_written); } - pub fn sys_fcntl(&mut self, fd : usize, cmd : usize, arg : usize) -> SysResult{ - info!( - "fcntl: fd: {}, cmd: {:x}, arg: {}", - fd, cmd, arg - ); + pub fn sys_fcntl(&mut self, fd: usize, cmd: usize, arg: usize) -> SysResult { + info!("fcntl: fd: {}, cmd: {:x}, arg: {}", fd, cmd, arg); let mut proc = self.process(); let file_like = proc.get_file_like(fd)?; file_like.fcntl(cmd, arg) @@ -888,11 +885,11 @@ impl Process { match path { "/proc/self/exe" => { return Ok(Arc::new(Pseudo::new(&self.exec_path, FileType::SymLink))); - }, + } "/dev/fb0" => { info!("/dev/fb0 will be opened"); return Ok(Arc::new(Vga::default())); - }, + } _ => {} } let (fd_dir_path, fd_name) = split_path(&path); diff --git a/kernel/src/syscall/mem.rs b/kernel/src/syscall/mem.rs index 26bb2f0c..57278023 100644 --- a/kernel/src/syscall/mem.rs +++ b/kernel/src/syscall/mem.rs @@ -51,7 +51,6 @@ impl Syscall<'_> { ); return Ok(addr); } else { - let file = proc.get_file(fd)?; info!("mmap path is {} ", &*file.path); match &*file.path { @@ -62,15 +61,15 @@ impl Syscall<'_> { addr, addr + len, prot.to_attr(), - Linear::new( - ( fb.bus_addr() - addr ) as isize, - ), + Linear::new((fb.bus_addr() - addr) as isize), "mmap_file", ); info!("mmap for /dev/fb0"); + return Ok(addr); + } else { + return Err(SysError::ENOENT); } - return Ok(addr); - }, + } _ => { let inode = file.inode(); self.vm().push( @@ -87,7 +86,7 @@ impl Syscall<'_> { "mmap_file", ); return Ok(addr); - }, + } }; } } diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index 989e9225..0317b14a 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -102,9 +102,12 @@ impl Syscall<'_> { SYS_WRITEV => self.sys_writev(args[0], args[1] as *const IoVec, args[2]), SYS_SENDFILE => self.sys_sendfile(args[0], args[1], args[2] as *mut usize, args[3]), SYS_FCNTL => { - info!("SYS_FCNTL : {} {} {} {}", args[0], args[1], args[2], args[3]); + info!( + "SYS_FCNTL : {} {} {} {}", + args[0], args[1], args[2], args[3] + ); self.sys_fcntl(args[0], args[1], args[2]) - }, + } SYS_FLOCK => self.unimplemented("flock", Ok(0)), SYS_FSYNC => self.sys_fsync(args[0]), SYS_FDATASYNC => self.sys_fdatasync(args[0]), @@ -292,7 +295,7 @@ impl Syscall<'_> { ), SYS_GETRANDOM => { self.sys_getrandom(args[0] as *mut u8, args[1] as usize, args[2] as u32) - }, + } SYS_RT_SIGQUEUEINFO => self.unimplemented("rt_sigqueueinfo", Ok(0)), // custom