From e9c0bcadf7f0b761eef65e8681ca39e9fee1a825 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Fri, 24 May 2019 15:20:39 +0800 Subject: [PATCH] Add graphic=console option and fix vga on x86_64 --- kernel/Cargo.lock | 6 +++--- kernel/Cargo.toml | 3 ++- kernel/Makefile | 8 ++++++-- kernel/src/arch/x86_64/io.rs | 24 ++++++++++-------------- kernel/src/drivers/bus/pci.rs | 3 ++- kernel/src/fs/file.rs | 4 ++++ 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index f9d3aef..f2b38df 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -88,7 +88,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bootloader" version = "0.4.0" -source = "git+https://github.com/rcore-os/bootloader?branch=linear#a535573bf83d5b916b5424a6b64e85e9197db40b" +source = "git+https://github.com/rcore-os/bootloader?branch=vga#472731f974eb9cddbee030d5bda11fd1ee6959db" dependencies = [ "apic 0.1.0 (git+https://github.com/rcore-os/apic-rs)", "fixedvec 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -378,7 +378,7 @@ dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "bitmap-allocator 0.1.0 (git+https://github.com/rcore-os/bitmap-allocator)", "bitvec 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bootloader 0.4.0 (git+https://github.com/rcore-os/bootloader?branch=linear)", + "bootloader 0.4.0 (git+https://github.com/rcore-os/bootloader?branch=vga)", "buddy_system_allocator 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)", "console-traits 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -693,7 +693,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bitmap-allocator 0.1.0 (git+https://github.com/rcore-os/bitmap-allocator)" = "" "checksum bitvec 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c28d4291b516ccfbb897d45de3c468c135e6af7c4f1f1aacfaae0a5bc2e6ea2c" "checksum bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cfadef5c4e2c2e64067b9ecc061179f12ac7ec65ba613b1f60f3972bbada1f5b" -"checksum bootloader 0.4.0 (git+https://github.com/rcore-os/bootloader?branch=linear)" = "" +"checksum bootloader 0.4.0 (git+https://github.com/rcore-os/bootloader?branch=vga)" = "" "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" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index cf5c3b0..0b67d6b 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -25,6 +25,7 @@ board_k210 = ["link_user"] board_rocket_chip = ["link_user"] # (for aarch64 RaspberryPi3) nographic = [] +consolegraphic = [] board_raspi3 = ["bcm2837", "link_user"] raspi3_use_generic_timer = ["bcm2837/use_generic_timer"] # for qemu machine @@ -68,7 +69,7 @@ rcore-fs = { git = "https://github.com/rcore-os/rcore-fs" } rcore-fs-sfs = { git = "https://github.com/rcore-os/rcore-fs" } [target.'cfg(target_arch = "x86_64")'.dependencies] -bootloader = { git = "https://github.com/rcore-os/bootloader", branch = "linear" } +bootloader = { git = "https://github.com/rcore-os/bootloader", branch = "vga" } apic = { git = "https://github.com/rcore-os/apic-rs" } x86_64 = "0.6" raw-cpuid = "6.0" diff --git a/kernel/Makefile b/kernel/Makefile index 6133f11..69c9fc1 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -21,7 +21,7 @@ # LOG = off | error | warn | info | debug | trace # SFSIMG = SFS image path of user programs # smp = 1 | 2 | ... SMP core number -# graphic = on | off Enable/disable qemu graphical output +# graphic = on | off | console Enable/disable qemu graphical output, or print console to graphic output # board = none Running on QEMU # | pc Only available on x86_64, run on real pc # | u540 Only available on riscv64, run on HiFive U540, use Sv39 @@ -202,10 +202,14 @@ qemu_opts += -nographic endif ### build args ### -ifneq ($(graphic), on) +ifeq ($(graphic), off) features += nographic endif +ifeq ($(graphic), console) +features += consolegraphic +endif + ifneq ($(init), ) features += run_cmdline endif diff --git a/kernel/src/arch/x86_64/io.rs b/kernel/src/arch/x86_64/io.rs index d6f8dcb..08893bc 100644 --- a/kernel/src/arch/x86_64/io.rs +++ b/kernel/src/arch/x86_64/io.rs @@ -10,23 +10,19 @@ pub fn getchar() -> char { } pub fn putfmt(fmt: Arguments) { - #[cfg(feature = "nographic")] - { - unsafe { - COM1.force_unlock(); - } - COM1.lock().write_fmt(fmt).unwrap(); + // print to console + unsafe { + COM1.force_unlock(); } - #[cfg(not(feature = "nographic"))] + COM1.lock().write_fmt(fmt).unwrap(); + + // print to graphic + #[cfg(feature = "consolegraphic")] { use super::driver::vga::VGA_WRITER; - unsafe { - COM1.force_unlock(); + unsafe { CONSOLE.force_unlock() } + if let Some(console) = CONSOLE.lock().as_mut() { + console.write_fmt(fmt).unwrap(); } - COM1.lock().write_fmt(fmt).unwrap(); - //unsafe { CONSOLE.force_unlock() } - //if let Some(console) = CONSOLE.lock().as_mut() { - //console.write_fmt(fmt).unwrap(); - //} } } diff --git a/kernel/src/drivers/bus/pci.rs b/kernel/src/drivers/bus/pci.rs index 60ca629..1c6f103 100644 --- a/kernel/src/drivers/bus/pci.rs +++ b/kernel/src/drivers/bus/pci.rs @@ -157,8 +157,9 @@ pub fn init_driver(dev: &PCIDevice) { ); } } - (0x8086, 0x2922) | (0x8086, 0x8d02) => { + (0x8086, 0x2922) | (0x8086, 0xa282) | (0x8086, 0x8d02) => { // 82801IR/IO/IH (ICH9R/DO/DH) 6 port SATA Controller [AHCI mode] + // 200 Series PCH SATA controller [AHCI mode] // C610/X99 series chipset 6-Port SATA Controller [AHCI mode] if let Some(BAR::Memory(addr, len, _, _)) = dev.bars[5] { let irq = unsafe { enable(dev.loc) }; diff --git a/kernel/src/fs/file.rs b/kernel/src/fs/file.rs index 83ecc55..538b53c 100644 --- a/kernel/src/fs/file.rs +++ b/kernel/src/fs/file.rs @@ -50,6 +50,7 @@ impl FileHandle { return Err(FsError::InvalidParam); // FIXME: => EBADF } let mut len: usize = 0; + /* if !self.options.nonblock { // block loop { @@ -61,6 +62,9 @@ impl FileHandle { } else { len = self.inode.read_at(offset, buf)?; } + */ + // TODO: handle block/nonblock correctly + len = self.inode.read_at(offset, buf)?; Ok(len) }