From a0fc20169525f5a061c5737d731e5bf33afe4807 Mon Sep 17 00:00:00 2001 From: PanQL Date: Thu, 9 May 2019 21:16:25 +0800 Subject: [PATCH 1/8] set up vga 320x200 --- kernel/Cargo.lock | 6 +++--- kernel/Cargo.toml | 2 +- kernel/src/arch/x86_64/io.rs | 20 ++++++++++---------- kernel/src/arch/x86_64/mod.rs | 11 +++++++++++ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index 15dc395..f2ba0ff 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -78,7 +78,7 @@ source = "git+https://github.com/myrrlyn/bitvec.git#8ab20a3e33fe068fc3a4a05eda12 [[package]] name = "bootloader" version = "0.4.0" -source = "git+https://github.com/rcore-os/bootloader#18e4fec0d82e8a5571abceb69d1d11fc0edccba1" +source = "git+https://github.com/rcore-os/bootloader?branch=vga#adc3ceda509e18b0d5a5623473dab4f8801a2551" 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)", @@ -354,7 +354,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.0 (git+https://github.com/myrrlyn/bitvec.git)", - "bootloader 0.4.0 (git+https://github.com/rcore-os/bootloader)", + "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.31 (registry+https://github.com/rust-lang/crates.io-index)", "console-traits 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -650,7 +650,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.0 (git+https://github.com/myrrlyn/bitvec.git)" = "" "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)" = "" +"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 cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ce8bb087aacff865633f0bd5aeaed910fe2fe55b55f4739527f2e023a2e53d" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 9547d31..f7562f8 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -70,7 +70,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" } +bootloader = { git = "https://github.com/rcore-os/bootloader", branch="vga", features=["vga_320x200"] } apic = { git = "https://github.com/rcore-os/apic-rs" } x86_64 = "0.5" raw-cpuid = "6.0" diff --git a/kernel/src/arch/x86_64/io.rs b/kernel/src/arch/x86_64/io.rs index c78b014..a25c655 100644 --- a/kernel/src/arch/x86_64/io.rs +++ b/kernel/src/arch/x86_64/io.rs @@ -10,18 +10,18 @@ pub fn getchar() -> char { } pub fn putfmt(fmt: Arguments) { - #[cfg(feature = "nographic")] - { + //#[cfg(feature = "nographic")] + //{ unsafe { COM1.force_unlock(); } COM1.lock().write_fmt(fmt).unwrap(); - } - #[cfg(not(feature = "nographic"))] - { - unsafe { - VGA_WRITER.force_unlock(); - } - VGA_WRITER.lock().write_fmt(fmt).unwrap(); - } + //} + //#[cfg(not(feature = "nographic"))] + //{ + //unsafe { + //VGA_WRITER.force_unlock(); + //} + //VGA_WRITER.lock().write_fmt(fmt).unwrap(); + //} } diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index 2d0e6ca..c0087ec 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -54,6 +54,17 @@ pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! { crate::process::init(); // wake up other CPUs AP_CAN_INIT.store(true, Ordering::Relaxed); + unsafe{ + 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, 64000 as usize) }; + for x in 0..320 { + for y in 0..200 { + frame_buffer_data[x + y * 320] = (x % 16 + ( y % 16) * 16) as u8; + } + } + } // call the first main function in kernel. crate::kmain(); } From 66b783de2121b05c0d4b013875c0dd8524311626 Mon Sep 17 00:00:00 2001 From: PanQL Date: Fri, 10 May 2019 14:56:14 +0800 Subject: [PATCH 2/8] should not be so rude --- kernel/src/arch/x86_64/io.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/kernel/src/arch/x86_64/io.rs b/kernel/src/arch/x86_64/io.rs index a25c655..c59ac60 100644 --- a/kernel/src/arch/x86_64/io.rs +++ b/kernel/src/arch/x86_64/io.rs @@ -10,18 +10,22 @@ pub fn getchar() -> char { } pub fn putfmt(fmt: Arguments) { - //#[cfg(feature = "nographic")] - //{ + #[cfg(feature = "nographic")] + { + unsafe { + COM1.force_unlock(); + } + COM1.lock().write_fmt(fmt).unwrap(); + } + #[cfg(not(feature = "nographic"))] + { unsafe { COM1.force_unlock(); } COM1.lock().write_fmt(fmt).unwrap(); - //} - //#[cfg(not(feature = "nographic"))] - //{ //unsafe { //VGA_WRITER.force_unlock(); //} //VGA_WRITER.lock().write_fmt(fmt).unwrap(); - //} + } } From 9ac8f1b887459511da2bd8858ee31d1e928cc3a9 Mon Sep 17 00:00:00 2001 From: PanQL Date: Sun, 12 May 2019 01:43:02 +0800 Subject: [PATCH 3/8] some work for console-vga(1024*7683) adaption --- kernel/Cargo.lock | 130 +++++++++++++++++---------- kernel/src/arch/x86_64/board/mod.rs | 26 ++++++ kernel/src/arch/x86_64/driver/mod.rs | 11 +++ kernel/src/arch/x86_64/io.rs | 9 +- kernel/src/arch/x86_64/mod.rs | 14 +-- kernel/src/drivers/gpu/fb.rs | 15 ++++ 6 files changed, 141 insertions(+), 64 deletions(-) create mode 100755 kernel/src/arch/x86_64/board/mod.rs diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index f2ba0ff..d7e4213 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -30,6 +30,15 @@ dependencies = [ "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "as-slice" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bare-metal" version = "0.2.4" @@ -60,7 +69,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bitmap-allocator" version = "0.1.0" -source = "git+https://github.com/rcore-os/bitmap-allocator#891867c95bc81f2376ec6eca9e349c42dc26c7fb" +source = "git+https://github.com/rcore-os/bitmap-allocator#5077c47649c1bfe12606ab222e79c70b54940906" dependencies = [ "bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -78,7 +87,7 @@ source = "git+https://github.com/myrrlyn/bitvec.git#8ab20a3e33fe068fc3a4a05eda12 [[package]] name = "bootloader" version = "0.4.0" -source = "git+https://github.com/rcore-os/bootloader?branch=vga#adc3ceda509e18b0d5a5623473dab4f8801a2551" +source = "git+https://github.com/rcore-os/bootloader?branch=vga#4ba8680bda6f355b80f11b685ee95a92599924e4" 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)", @@ -101,9 +110,14 @@ name = "byteorder" version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cast" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "cc" -version = "1.0.31" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -124,7 +138,7 @@ source = "git+https://github.com/rcore-os/deque.git?branch=no_std#b13a836dd69ae8 [[package]] name = "device_tree" version = "1.0.3" -source = "git+https://github.com/rcore-os/device_tree-rs#7945459093f49a39996291283b8894753c8a638d" +source = "git+https://github.com/rcore-os/device_tree-rs#2fa8411c421c6b4761992fd3d1a9b2427bf0cfc4" [[package]] name = "fixedvec" @@ -152,9 +166,17 @@ dependencies = [ "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "generic-array" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "getopts" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -170,9 +192,10 @@ dependencies = [ [[package]] name = "heapless" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "as-slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash32 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -198,7 +221,7 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.50" +version = "0.2.54" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -247,7 +270,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "paste-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -255,10 +278,10 @@ name = "paste-impl" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -269,24 +292,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pci" version = "0.0.1" -source = "git+https://github.com/rcore-os/pci-rs#30f2e83aa51dd313957f3fd6c3b233d3c905a4d0" +source = "git+https://github.com/rcore-os/pci-rs#3f5ca7b27f8d365f1a9b5e45d249e78bff944927" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro-hack" -version = "0.5.4" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro2" -version = "0.4.27" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -297,15 +320,15 @@ name = "pulldown-cmark" version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "quote" -version = "0.6.11" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -314,10 +337,10 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -339,7 +362,7 @@ version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -356,10 +379,10 @@ dependencies = [ "bitvec 0.11.0 (git+https://github.com/myrrlyn/bitvec.git)", "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.31 (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)", "device_tree 1.0.3 (git+https://github.com/rcore-os/device_tree-rs)", - "heapless 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "heapless 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "isomorphic_drivers 0.1.0 (git+https://github.com/rcore-os/isomorphic_drivers)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -377,14 +400,14 @@ dependencies = [ "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "uart_16550 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "volatile 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "x86_64 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "x86_64 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "xmas-elf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rcore-fs" version = "0.1.0" -source = "git+https://github.com/rcore-os/rcore-fs#41ccb1675cbea1df079f39fdc1bcd50c609df707" +source = "git+https://github.com/rcore-os/rcore-fs#585eb6197aa687320618ee8c3c550a4e32aa9d15" dependencies = [ "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -392,7 +415,7 @@ dependencies = [ [[package]] name = "rcore-fs-sfs" version = "0.1.0" -source = "git+https://github.com/rcore-os/rcore-fs#41ccb1675cbea1df079f39fdc1bcd50c609df707" +source = "git+https://github.com/rcore-os/rcore-fs#585eb6197aa687320618ee8c3c550a4e32aa9d15" dependencies = [ "bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -411,7 +434,7 @@ dependencies = [ [[package]] name = "rcore-thread" version = "0.1.0" -source = "git+https://github.com/rcore-os/rcore-thread#fd972c7e3aa2b7618f625f143655c16adfd2ca78" +source = "git+https://github.com/rcore-os/rcore-thread#77e8e0778154734ee59525e043caab6339e14d75" dependencies = [ "deque 0.3.2 (git+https://github.com/rcore-os/deque.git?branch=no_std)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -439,13 +462,13 @@ name = "remove_dir_all" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "riscv" version = "0.5.0" -source = "git+https://github.com/rcore-os/riscv#e8be9f93513225596709a2dccd9064324591fc3c" +source = "git+https://github.com/rcore-os/riscv#8e25d63d123773145911f4a1f718fc1bc73d80c6" dependencies = [ "bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -504,6 +527,11 @@ name = "spin" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "stable_deref_trait" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "static_assertions" version = "0.3.1" @@ -511,11 +539,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "0.15.30" +version = "0.15.34" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -544,7 +572,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "x86_64 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "x86_64 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -574,7 +602,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -615,14 +643,14 @@ dependencies = [ [[package]] name = "x86_64" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "array-init 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "ux 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -643,6 +671,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum aarch64 2.5.0 (git+https://github.com/rcore-os/aarch64)" = "" "checksum apic 0.1.0 (git+https://github.com/rcore-os/apic-rs)" = "" "checksum array-init 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "23589ecb866b460d3a0f1278834750268c607e8e28a1b982c907219f3178cd72" +"checksum as-slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "293dac66b274fab06f95e7efb05ec439a6b70136081ea522d270bc351ae5bb27" "checksum bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3caf393d93b2d453e80638d0674597020cef3382ada454faacd43d1a55a735a" "checksum bcm2837 1.0.0 (git+https://github.com/rcore-os/bcm2837)" = "" "checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56" @@ -653,7 +682,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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 cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ce8bb087aacff865633f0bd5aeaed910fe2fe55b55f4739527f2e023a2e53d" +"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427" +"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)" = "" @@ -662,12 +692,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum font8x8 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b81d84c3c978af7d05d31a2198af4b9ba956d819d15d8f6d58fc150e33f8dc1f" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum generic-array 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8107dafa78c80c848b71b60133954b4a58609a3a1a5f9af037ecc7f67280f369" -"checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797" +"checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592" +"checksum getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)" = "72327b15c228bfe31f1390f93dd5e9279587f0463836393c9df719ce62a3e450" "checksum hash32 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "12d790435639c06a7b798af9e1e331ae245b7ef915b92f70a39b4cf8c00686af" -"checksum heapless 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "56b960caff1a46f1fb3c1eb05f0575ac21c6248364ebebde11b11116e099881c" +"checksum heapless 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e1ae80bbc62401ae8096976857172507cadbd2200f36670e5144634360a05959" "checksum isomorphic_drivers 0.1.0 (git+https://github.com/rcore-os/isomorphic_drivers)" = "" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" -"checksum libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "aab692d7759f5cd8c859e169db98ae5b52c924add2af5fbbca11d12fefb567c1" +"checksum libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)" = "c6785aa7dd976f5fbf3b71cfd9cd49d7f783c1ff565a858d71031c6c313aa5c6" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" @@ -678,10 +709,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum paste-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "26e796e623b8b257215f27e6c80a5478856cae305f5b59810ff9acdaa34570e6" "checksum pc-keyboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c48392db76c4e9a69e0b3be356c5f97ebb7b14413c5e4fd0af4755dbf86e2fce" "checksum pci 0.0.1 (git+https://github.com/rcore-os/pci-rs)" = "" -"checksum proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3e90aa19cd73dedc2d0e1e8407473f073d735fef0ab521438de6da8ee449ab66" -"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" +"checksum proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0c1dd4172a1e1f96f709341418f49b11ea6c2d95d53dca08c0f74cbd332d9cf3" +"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum pulldown-cmark 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8361e81576d2e02643b04950e487ec172b687180da65c731c03cf336784e6c07" -"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" +"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" "checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" @@ -700,8 +731,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum smoltcp 0.5.0 (git+https://github.com/rcore-os/smoltcp)" = "" "checksum spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ceac490aa12c567115b40b7b7fceca03a6c9d53d5defea066123debc83c5dc1f" "checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55" +"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum static_assertions 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "389ce475f424f267dbed6479cbd8f126c5e1afb053b0acdaa019c74305fc65d1" -"checksum syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)" = "66c8865bf5a7cbb662d8b011950060b3c8743dca141b054bf7195b20d314d8e2" +"checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum tock-registers 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3a385d94f3f62e60445a0adb9ff8d9621faa272234530d4c0f848ec98f88e316" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" @@ -711,11 +743,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f70329e2cbe45d6c97a5112daad40c34cd9a4e18edb5a2a18fefeb584d8d25e5" "checksum ux 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "88dfeb711b61ce620c0cb6fd9f8e3e678622f0c971da2a63c4b3e25e88ed012f" "checksum volatile 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6af0edf5b4faacc31fc51159244d78d65ec580f021afcef7bd53c04aeabc7f29" -"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "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 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/src/arch/x86_64/board/mod.rs b/kernel/src/arch/x86_64/board/mod.rs new file mode 100755 index 0000000..ccd85d9 --- /dev/null +++ b/kernel/src/arch/x86_64/board/mod.rs @@ -0,0 +1,26 @@ +#[path = "../../../drivers/gpu/fb.rs"] +pub mod fb; + +use fb::{ColorConfig, FramebufferInfo, FramebufferResult, FRAME_BUFFER}; +use crate::consts::KERNEL_OFFSET; + +pub fn init_driver() { + #[cfg(not(feature = "nographic"))] + fb::init(); +} + +pub fn probe_fb_info(width : u32, height : u32, depth : u32) -> FramebufferResult { + let fb_info = FramebufferInfo { + xres: 1024, + yres: 768, + xres_virtual: 1024, + yres_virtual: 768, + xoffset: 0, + yoffset: 0, + depth: 24, + pitch: 1024, // TOKNOW + bus_addr: 0xf000_0000, + screen_size: 1024 * 768 * 3, + }; + Ok((fb_info, fb::ColorConfig::BGRA8888, KERNEL_OFFSET + 0xf000_0000)) +} diff --git a/kernel/src/arch/x86_64/driver/mod.rs b/kernel/src/arch/x86_64/driver/mod.rs index cbc4d67..e0ca105 100644 --- a/kernel/src/arch/x86_64/driver/mod.rs +++ b/kernel/src/arch/x86_64/driver/mod.rs @@ -6,6 +6,12 @@ pub mod rtc_cmos; pub mod serial; pub mod vga; +use super::board; + +pub use self::board::fb; +#[path = "../../../drivers/console/mod.rs"] +pub mod console; + pub fn init() { // Use IOAPIC instead of PIC pic::disable(); @@ -29,4 +35,9 @@ pub fn init() { enable_irq(consts::PIRQG); enable_irq(consts::PIRQH); */ + board::init_driver(); + console::init(); + if let Some(con) = console::CONSOLE.lock().as_mut() { + con.clear(); + } } diff --git a/kernel/src/arch/x86_64/io.rs b/kernel/src/arch/x86_64/io.rs index c59ac60..2903934 100644 --- a/kernel/src/arch/x86_64/io.rs +++ b/kernel/src/arch/x86_64/io.rs @@ -1,6 +1,7 @@ use super::driver::serial::*; use super::driver::vga::VGA_WRITER; use core::fmt::{Arguments, Write}; +use super::driver::console::CONSOLE; pub fn getchar() -> char { unsafe { @@ -23,9 +24,9 @@ pub fn putfmt(fmt: Arguments) { COM1.force_unlock(); } COM1.lock().write_fmt(fmt).unwrap(); - //unsafe { - //VGA_WRITER.force_unlock(); - //} - //VGA_WRITER.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/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index c0087ec..09c8cc0 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -15,6 +15,7 @@ pub mod rand; pub mod syscall; pub mod timer; pub mod ipi; +pub mod board; static AP_CAN_INIT: AtomicBool = AtomicBool::new(false); @@ -52,19 +53,10 @@ pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! { crate::drivers::init(); // init cpu scheduler and process manager, and add user shell app in process manager crate::process::init(); + // wake up other CPUs AP_CAN_INIT.store(true, Ordering::Relaxed); - unsafe{ - 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, 64000 as usize) }; - for x in 0..320 { - for y in 0..200 { - frame_buffer_data[x + y * 320] = (x % 16 + ( y % 16) * 16) as u8; - } - } - } + // call the first main function in kernel. crate::kmain(); } diff --git a/kernel/src/drivers/gpu/fb.rs b/kernel/src/drivers/gpu/fb.rs index 01fbe6a..3d3f9df 100644 --- a/kernel/src/drivers/gpu/fb.rs +++ b/kernel/src/drivers/gpu/fb.rs @@ -40,6 +40,7 @@ pub struct FramebufferInfo { pub enum ColorDepth { ColorDepth8 = 8, ColorDepth16 = 16, + ColorDepth24 = 24, ColorDepth32 = 32, } use self::ColorDepth::*; @@ -74,6 +75,9 @@ impl ColorBuffer { ColorDepth16 => ColorBuffer { buf16: core::slice::from_raw_parts_mut(base_addr as *mut u16, size / 2), }, + ColorDepth24 => ColorBuffer { + buf8: core::slice::from_raw_parts_mut(base_addr as *mut u8, size), + }, ColorDepth32 => ColorBuffer { buf32: core::slice::from_raw_parts_mut(base_addr as *mut u32, size / 4), }, @@ -106,6 +110,14 @@ impl ColorBuffer { unsafe { self.buf16[index as usize] = pixel } } + #[inline] + fn write24(&mut self, index: u32, pixel: u32) { + let index = index * 3; + unsafe { self.buf8[2 + index as usize] = (pixel >> 16) as u8 } + unsafe { self.buf8[1 + index as usize] = (pixel >> 8) as u8 } + unsafe { self.buf8[index as usize] = pixel as u8 } + } + #[inline] fn write32(&mut self, index: u32, pixel: u32) { unsafe { self.buf32[index as usize] = pixel } @@ -141,6 +153,7 @@ impl Framebuffer { 8 => ColorDepth8, 16 => ColorDepth16, 32 => ColorDepth32, + 24=> ColorDepth24, _ => Err(format!("unsupported color depth {}", info.depth))?, }; Ok(Framebuffer { @@ -165,6 +178,7 @@ impl Framebuffer { match self.color_depth { ColorDepth8 => self.buf.read8(y * self.fb_info.xres + x) as u32, ColorDepth16 => self.buf.read16(y * self.fb_info.xres + x) as u32, + ColorDepth24 => self.buf.read16(y * self.fb_info.xres + x) as u32, // TODO ColorDepth32 => self.buf.read32(y * self.fb_info.xres + x), } } @@ -175,6 +189,7 @@ impl Framebuffer { match self.color_depth { ColorDepth8 => self.buf.write8(y * self.fb_info.xres + x, pixel as u8), ColorDepth16 => self.buf.write16(y * self.fb_info.xres + x, pixel as u16), + ColorDepth24 => self.buf.write24(y * self.fb_info.xres + x, pixel), ColorDepth32 => self.buf.write32(y * self.fb_info.xres + x, pixel), } } From 9e4a3f9662cb2793b57d664d2b92a4ffbaf65111 Mon Sep 17 00:00:00 2001 From: PanQL Date: Mon, 13 May 2019 20:57:03 +0800 Subject: [PATCH 4/8] create virtual vga file, now can draw fb on user state --- kernel/src/arch/x86_64/io.rs | 8 ++-- kernel/src/fs/mod.rs | 2 + kernel/src/fs/vga.rs | 74 ++++++++++++++++++++++++++++++++++++ kernel/src/syscall/fs.rs | 6 ++- 4 files changed, 85 insertions(+), 5 deletions(-) create mode 100755 kernel/src/fs/vga.rs diff --git a/kernel/src/arch/x86_64/io.rs b/kernel/src/arch/x86_64/io.rs index 2903934..7727c1d 100644 --- a/kernel/src/arch/x86_64/io.rs +++ b/kernel/src/arch/x86_64/io.rs @@ -24,9 +24,9 @@ pub fn putfmt(fmt: Arguments) { COM1.force_unlock(); } COM1.lock().write_fmt(fmt).unwrap(); - unsafe { CONSOLE.force_unlock() } - if let Some(console) = CONSOLE.lock().as_mut() { - console.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/fs/mod.rs b/kernel/src/fs/mod.rs index 0c47c8f..22982c3 100644 --- a/kernel/src/fs/mod.rs +++ b/kernel/src/fs/mod.rs @@ -11,6 +11,7 @@ pub use self::file_like::*; pub use self::pipe::Pipe; pub use self::pseudo::*; pub use self::stdio::{STDIN, STDOUT}; +pub use self::vga::*; mod device; mod file; @@ -19,6 +20,7 @@ mod ioctl; mod pipe; mod pseudo; mod stdio; +mod vga; /// Hard link user programs #[cfg(feature = "link_user")] diff --git a/kernel/src/fs/vga.rs b/kernel/src/fs/vga.rs new file mode 100755 index 0000000..2e4fa80 --- /dev/null +++ b/kernel/src/fs/vga.rs @@ -0,0 +1,74 @@ +use rcore_fs::vfs::*; + +use alloc::{string::String, sync::Arc, vec::Vec}; +use core::any::Any; +use crate::arch::board::fb::FRAME_BUFFER; + +#[derive(Default)] +pub struct Vga; + +macro_rules! impl_inode { + () => { + fn set_metadata(&self, _metadata: &Metadata) -> Result<()> { Ok(()) } + fn sync_all(&self) -> Result<()> { Ok(()) } + fn sync_data(&self) -> Result<()> { Ok(()) } + fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) } + fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result> { Err(FsError::NotDir) } + fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) } + fn link(&self, _name: &str, _other: &Arc) -> Result<()> { Err(FsError::NotDir) } + fn move_(&self, _old_name: &str, _target: &Arc, _new_name: &str) -> Result<()> { Err(FsError::NotDir) } + fn find(&self, _name: &str) -> Result> { Err(FsError::NotDir) } + fn get_entry(&self, _id: usize) -> Result { Err(FsError::NotDir) } + fn io_control(&self, cmd: u32, data: usize) -> Result<()> { Err(FsError::NotSupported) } + fn fs(&self) -> Arc { unimplemented!() } + fn as_any_ref(&self) -> &Any { self } + }; +} + +impl INode for Vga { + fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result { + Err(FsError::NotSupported) + } + fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result { + info!("the _offset is {} {}", _offset, _buf[0]); + let mut result : usize = 0; + if let Some(fb) = FRAME_BUFFER.lock().as_mut() { + for x in 0..1024 { // TODO, should not use CONSTS + for y in 0..768 { + let blue = _buf[3 * (x * 768 + y)]; + let green = _buf[3 * (x * 768 + y) + 1]; + let red = _buf[3 * (x * 768 + y) + 2]; + let pixel : u32 = ((blue as u32) << 16) | ((green as u32) << 8) | (red as u32); + fb.write(x as u32, y as u32, pixel); + result += 3; + } + } + } + return Ok(result); + } + fn poll(&self) -> Result { + Ok(PollStatus { // TOKNOW and TODO + read: true, + write: false, + error: false, + }) + } + fn metadata(&self) -> Result { + Ok(Metadata { + dev: 0, + inode: 0, + size: 0x24000, + blk_size: 0, + blocks: 0, + atime: Timespec { sec: 0, nsec: 0 }, + mtime: Timespec { sec: 0, nsec: 0 }, + ctime: Timespec { sec: 0, nsec: 0 }, + type_: FileType::SymLink, + mode: 0, + nlinks: 0, + uid: 0, + gid: 0, + }) + } + impl_inode!(); +} diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index 401a950..f997f5f 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -871,7 +871,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); From 545d9d301c31e5c985e7ce6ceacfc53fd79284bb Mon Sep 17 00:00:00 2001 From: PanQL Date: Fri, 17 May 2019 00:53:23 +0800 Subject: [PATCH 5/8] use copy_from_slice to speed up --- kernel/src/fs/stdio.rs | 3 ++- kernel/src/fs/vga.rs | 33 +++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/kernel/src/fs/stdio.rs b/kernel/src/fs/stdio.rs index 57e242c..db70ec8 100644 --- a/kernel/src/fs/stdio.rs +++ b/kernel/src/fs/stdio.rs @@ -35,7 +35,8 @@ impl Stdin { match buf_lock.pop_front() { Some(c) => return c, None => { - self.pushed.wait(buf_lock); + //self.pushed.wait(buf_lock); + return 0 as char; } } } diff --git a/kernel/src/fs/vga.rs b/kernel/src/fs/vga.rs index 2e4fa80..bea4ae6 100755 --- a/kernel/src/fs/vga.rs +++ b/kernel/src/fs/vga.rs @@ -31,20 +31,25 @@ impl INode for Vga { } fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result { info!("the _offset is {} {}", _offset, _buf[0]); - let mut result : usize = 0; - if let Some(fb) = FRAME_BUFFER.lock().as_mut() { - for x in 0..1024 { // TODO, should not use CONSTS - for y in 0..768 { - let blue = _buf[3 * (x * 768 + y)]; - let green = _buf[3 * (x * 768 + y) + 1]; - let red = _buf[3 * (x * 768 + y) + 2]; - let pixel : u32 = ((blue as u32) << 16) | ((green as u32) << 8) | (red as u32); - fb.write(x as u32, y as u32, pixel); - result += 3; - } - } - } - return Ok(result); + //let mut result : usize = 0; + //if let Some(fb) = FRAME_BUFFER.lock().as_mut() { + //for x in 0..1024 { // TODO, should not use CONSTS + //for y in 0..768 { + //let blue = _buf[3 * (x * 768 + y)]; + //let green = _buf[3 * (x * 768 + y) + 1]; + //let red = _buf[3 * (x * 768 + y) + 2]; + //let pixel : u32 = ((blue as u32) << 16) | ((green as u32) << 8) | (red as u32); + //fb.write(x as u32, y as u32, pixel); + //result += 3; + //} + //} + //} + 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) }; + frame_buffer_data.copy_from_slice(&_buf); + return Ok(1024 * 768 * 3); } fn poll(&self) -> Result { Ok(PollStatus { // TOKNOW and TODO From f9734b61347f1a25115173e909b1a9233c968365 Mon Sep 17 00:00:00 2001 From: PanQL Date: Sun, 19 May 2019 17:09:05 +0800 Subject: [PATCH 6/8] mmap support for mgba's partical redraw --- kernel/src/fs/vga.rs | 13 ---------- kernel/src/syscall/mem.rs | 50 +++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/kernel/src/fs/vga.rs b/kernel/src/fs/vga.rs index bea4ae6..d5909af 100755 --- a/kernel/src/fs/vga.rs +++ b/kernel/src/fs/vga.rs @@ -31,19 +31,6 @@ impl INode for Vga { } fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result { info!("the _offset is {} {}", _offset, _buf[0]); - //let mut result : usize = 0; - //if let Some(fb) = FRAME_BUFFER.lock().as_mut() { - //for x in 0..1024 { // TODO, should not use CONSTS - //for y in 0..768 { - //let blue = _buf[3 * (x * 768 + y)]; - //let green = _buf[3 * (x * 768 + y) + 1]; - //let red = _buf[3 * (x * 768 + y) + 2]; - //let pixel : u32 = ((blue as u32) << 16) | ((green as u32) << 8) | (red as u32); - //fb.write(x as u32, y as u32, pixel); - //result += 3; - //} - //} - //} use crate::consts::KERNEL_OFFSET; use core::slice; let frame_buffer_data = diff --git a/kernel/src/syscall/mem.rs b/kernel/src/syscall/mem.rs index 3a3d4a8..66817c1 100644 --- a/kernel/src/syscall/mem.rs +++ b/kernel/src/syscall/mem.rs @@ -1,4 +1,4 @@ -use rcore_memory::memory_set::handler::{Delay, File}; +use rcore_memory::memory_set::handler::{Delay, File, Linear}; use rcore_memory::memory_set::MemoryAttr; use rcore_memory::paging::PageTable; use rcore_memory::Page; @@ -53,21 +53,41 @@ impl Syscall<'_> { ); return Ok(addr); } else { - let inode = proc.get_file(fd)?.inode(); - self.vm().push( - addr, - addr + len, - prot.to_attr(), - File { - file: INodeForMap(inode), - mem_start: addr, - file_start: offset, - file_end: offset + len, - allocator: GlobalFrameAlloc, + + let file = proc.get_file(fd)?; + info!("mmap path is {} ", &*file.path); + match &*file.path { + "/dev/fb0" => { + self.vm().push( + addr, + addr + len, + prot.to_attr(), + Linear::new( + ( 0xfd00_0000 - addr ) as isize, + ), + "mmap_file", + ); + info!("mmap for /dev/fb0"); + return Ok(addr); }, - "mmap_file", - ); - return Ok(addr); + _ => { + let inode = file.inode(); + self.vm().push( + addr, + addr + len, + prot.to_attr(), + File { + file: INodeForMap(inode), + mem_start: addr, + file_start: offset, + file_end: offset + len, + allocator: GlobalFrameAlloc, + }, + "mmap_file", + ); + return Ok(addr); + }, + }; } } From f8c88baeea2f935124992483f0294d6b2ad54d21 Mon Sep 17 00:00:00 2001 From: PanQL Date: Mon, 20 May 2019 10:28:27 +0800 Subject: [PATCH 7/8] nonblock stdin for mgba keyboard support --- kernel/src/fs/file.rs | 20 +++++++++++++++++++- kernel/src/fs/file_like.rs | 10 ++++++++++ kernel/src/fs/stdio.rs | 11 +++++++---- kernel/src/process/structs.rs | 3 +++ kernel/src/syscall/fs.rs | 13 +++++++++++++ kernel/src/syscall/mod.rs | 5 ++++- 6 files changed, 56 insertions(+), 6 deletions(-) diff --git a/kernel/src/fs/file.rs b/kernel/src/fs/file.rs index aefd349..5d8505e 100644 --- a/kernel/src/fs/file.rs +++ b/kernel/src/fs/file.rs @@ -19,6 +19,7 @@ pub struct OpenOptions { pub write: bool, /// Before each write, the file offset is positioned at the end of the file. pub append: bool, + pub nonblock: bool, } #[derive(Debug)] @@ -48,7 +49,17 @@ impl FileHandle { if !self.options.read { return Err(FsError::InvalidParam); // FIXME: => EBADF } - let len = self.inode.read_at(offset, buf)?; + let mut len : usize = 0; + if !self.options.nonblock { // block + loop { + len = self.inode.read_at(offset, buf)?; + if len > 0 { + break; + } + } + }else{ + len = self.inode.read_at(offset, buf)?; + } Ok(len) } @@ -123,6 +134,13 @@ impl FileHandle { pub fn inode(&self) -> Arc { self.inode.clone() } + + pub fn fcntl(&mut self, cmd: usize, arg: usize) -> Result<()> { + if arg == 2048 && cmd == 4 { + self.options.nonblock = true; + } + Ok(()) + } } impl fmt::Debug for FileHandle { diff --git a/kernel/src/fs/file_like.rs b/kernel/src/fs/file_like.rs index 5e847f1..d489e01 100644 --- a/kernel/src/fs/file_like.rs +++ b/kernel/src/fs/file_like.rs @@ -56,6 +56,16 @@ impl FileLike { }; Ok(status) } + + pub fn fcntl(&mut self, cmd: usize, arg: usize) -> SysResult { + match self { + FileLike::File(file) => file.fcntl(cmd, arg)?, + FileLike::Socket(socket) => { + //TODO + } + } + Ok(0) + } } impl fmt::Debug for FileLike { diff --git a/kernel/src/fs/stdio.rs b/kernel/src/fs/stdio.rs index db70ec8..ccb8204 100644 --- a/kernel/src/fs/stdio.rs +++ b/kernel/src/fs/stdio.rs @@ -35,8 +35,7 @@ impl Stdin { match buf_lock.pop_front() { Some(c) => return c, None => { - //self.pushed.wait(buf_lock); - return 0 as char; + self.pushed.wait(buf_lock); } } } @@ -92,8 +91,12 @@ macro_rules! impl_inode { impl INode for Stdin { fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result { - buf[0] = self.pop() as u8; - Ok(1) + if self.can_read() { + buf[0] = self.pop() as u8; + Ok(1) + }else{ + Ok(0) + } } fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result { unimplemented!() diff --git a/kernel/src/process/structs.rs b/kernel/src/process/structs.rs index 3f7c272..5a3a88e 100644 --- a/kernel/src/process/structs.rs +++ b/kernel/src/process/structs.rs @@ -260,6 +260,7 @@ impl Thread { read: true, write: false, append: false, + nonblock: false, }, String::from("stdin"), )), @@ -272,6 +273,7 @@ impl Thread { read: false, write: true, append: false, + nonblock: false, }, String::from("stdout"), )), @@ -284,6 +286,7 @@ impl Thread { read: false, write: true, append: false, + nonblock: false, }, String::from("stderr"), )), diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index f997f5f..ef11a83 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -703,6 +703,7 @@ impl Syscall<'_> { read: true, write: false, append: false, + nonblock: false, }, String::from("pipe_r:[]"), ))); @@ -713,6 +714,7 @@ impl Syscall<'_> { read: false, write: true, append: false, + nonblock: false, }, String::from("pipe_w:[]"), ))); @@ -828,6 +830,16 @@ 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 + ); + let mut proc = self.process(); + let file_like = proc.get_file_like(fd)?; + file_like.fcntl(cmd, arg) + } } impl Process { @@ -978,6 +990,7 @@ impl OpenFlags { read: self.readable(), write: self.writable(), append: self.contains(OpenFlags::APPEND), + nonblock: false, } } } diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index 896d5d1..268771c 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -99,7 +99,10 @@ impl Syscall<'_> { SYS_READV => self.sys_readv(args[0], args[1] as *const IoVec, args[2]), 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 => self.unimplemented("fcntl", Ok(0)), + SYS_FCNTL => { + 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]), From a6f211cef51cc106e2659588948e4f58867adb70 Mon Sep 17 00:00:00 2001 From: PanQL Date: Thu, 23 May 2019 20:59:04 +0800 Subject: [PATCH 8/8] fix mmap for framebuffer --- kernel/src/arch/x86_64/board/mod.rs | 2 +- kernel/src/drivers/gpu/fb.rs | 5 +++++ kernel/src/syscall/mem.rs | 23 +++++++++++++---------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/kernel/src/arch/x86_64/board/mod.rs b/kernel/src/arch/x86_64/board/mod.rs index ccd85d9..b6da4ce 100755 --- a/kernel/src/arch/x86_64/board/mod.rs +++ b/kernel/src/arch/x86_64/board/mod.rs @@ -19,7 +19,7 @@ pub fn probe_fb_info(width : u32, height : u32, depth : u32) -> FramebufferResul yoffset: 0, depth: 24, pitch: 1024, // TOKNOW - bus_addr: 0xf000_0000, + bus_addr: 0xfd00_0000, screen_size: 1024 * 768 * 3, }; Ok((fb_info, fb::ColorConfig::BGRA8888, KERNEL_OFFSET + 0xf000_0000)) diff --git a/kernel/src/drivers/gpu/fb.rs b/kernel/src/drivers/gpu/fb.rs index 3d3f9df..45b74c0 100644 --- a/kernel/src/drivers/gpu/fb.rs +++ b/kernel/src/drivers/gpu/fb.rs @@ -172,6 +172,11 @@ impl Framebuffer { unsafe { self.buf.base_addr } } + #[inline] + pub fn bus_addr(&self) -> usize { + self.fb_info.bus_addr as usize + } + /// Read pixel at `(x, y)`. #[inline] pub fn read(&self, x: u32, y: u32) -> u32 { diff --git a/kernel/src/syscall/mem.rs b/kernel/src/syscall/mem.rs index 66817c1..44ac35f 100644 --- a/kernel/src/syscall/mem.rs +++ b/kernel/src/syscall/mem.rs @@ -58,16 +58,19 @@ impl Syscall<'_> { info!("mmap path is {} ", &*file.path); match &*file.path { "/dev/fb0" => { - self.vm().push( - addr, - addr + len, - prot.to_attr(), - Linear::new( - ( 0xfd00_0000 - addr ) as isize, - ), - "mmap_file", - ); - info!("mmap for /dev/fb0"); + use crate::arch::board::fb::FRAME_BUFFER; + if let Some(fb) = FRAME_BUFFER.lock().as_mut() { + self.vm().push( + addr, + addr + len, + prot.to_attr(), + Linear::new( + ( fb.bus_addr() - addr ) as isize, + ), + "mmap_file", + ); + info!("mmap for /dev/fb0"); + } return Ok(addr); }, _ => {