diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index 8d7b1e9..79d7caf 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -31,6 +31,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" @@ -61,7 +70,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)", ] @@ -109,7 +118,7 @@ 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]] @@ -130,7 +139,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" @@ -158,9 +167,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)", @@ -176,9 +193,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)", ] @@ -204,7 +222,7 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.50" +version = "0.2.54" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -253,7 +271,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]] @@ -261,10 +279,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]] @@ -275,24 +293,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)", @@ -303,15 +321,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]] @@ -320,10 +338,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]] @@ -345,7 +363,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)", ] @@ -362,10 +380,10 @@ dependencies = [ "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)", "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)", @@ -390,7 +408,7 @@ dependencies = [ [[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)", ] @@ -398,7 +416,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)", @@ -445,7 +463,7 @@ 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]] @@ -510,6 +528,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" @@ -517,11 +540,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)", ] @@ -550,7 +573,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]] @@ -580,7 +603,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)", @@ -621,14 +644,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)", ] @@ -662,6 +685,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum aarch64 2.6.1 (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" @@ -682,12 +706,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" @@ -698,10 +723,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" @@ -720,8 +745,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" @@ -731,7 +757,7 @@ 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" 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..b6da4ce --- /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: 0xfd00_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 855854f..2b0b54a 100644 --- a/kernel/src/arch/x86_64/io.rs +++ b/kernel/src/arch/x86_64/io.rs @@ -1,5 +1,6 @@ use super::driver::serial::*; use core::fmt::{Arguments, Write}; +use super::driver::console::CONSOLE; pub fn getchar() -> char { unsafe { @@ -20,8 +21,12 @@ pub fn putfmt(fmt: Arguments) { { use super::driver::vga::VGA_WRITER; unsafe { - VGA_WRITER.force_unlock(); + COM1.force_unlock(); } - VGA_WRITER.lock().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/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index b6b77fb..fc86c82 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -15,6 +15,8 @@ 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); @@ -59,8 +61,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); + // 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..45b74c0 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 { @@ -159,12 +172,18 @@ 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 { 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 +194,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), } } 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/mod.rs b/kernel/src/fs/mod.rs index 12e50bf..240d030 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/stdio.rs b/kernel/src/fs/stdio.rs index 57e242c..ccb8204 100644 --- a/kernel/src/fs/stdio.rs +++ b/kernel/src/fs/stdio.rs @@ -91,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/fs/vga.rs b/kernel/src/fs/vga.rs new file mode 100755 index 0000000..d5909af --- /dev/null +++ b/kernel/src/fs/vga.rs @@ -0,0 +1,66 @@ +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]); + 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 + 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/process/structs.rs b/kernel/src/process/structs.rs index 384d2d5..b783b37 100644 --- a/kernel/src/process/structs.rs +++ b/kernel/src/process/structs.rs @@ -261,6 +261,7 @@ impl Thread { read: true, write: false, append: false, + nonblock: false, }, String::from("stdin"), )), @@ -273,6 +274,7 @@ impl Thread { read: false, write: true, append: false, + nonblock: false, }, String::from("stdout"), )), @@ -285,6 +287,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 375d870..e3291b5 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -708,6 +708,7 @@ impl Syscall<'_> { read: true, write: false, append: false, + nonblock: false, }, String::from("pipe_r:[]"), ))); @@ -718,6 +719,7 @@ impl Syscall<'_> { read: false, write: true, append: false, + nonblock: false, }, String::from("pipe_w:[]"), ))); @@ -833,6 +835,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 { @@ -876,7 +888,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); @@ -979,6 +995,7 @@ impl OpenFlags { read: self.readable(), write: self.writable(), append: self.contains(OpenFlags::APPEND), + nonblock: false, } } } diff --git a/kernel/src/syscall/mem.rs b/kernel/src/syscall/mem.rs index 1a031da..26bb2f0 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::PAGE_SIZE; @@ -51,21 +51,44 @@ 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" => { + 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); }, - "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); + }, + }; } } diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index b20b092..989e922 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -101,7 +101,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]),