From 7d07b40163b7674977f55ee600baeed9e109029d Mon Sep 17 00:00:00 2001 From: pjht Date: Thu, 6 Jun 2024 22:03:58 -0500 Subject: [PATCH] Work --- .cargo/config.toml | 4 +- Cargo.lock | 346 +++++++++++++++++++------------------------- Cargo.toml | 10 +- rust-toolchain.toml | 2 +- src/ata.rs | 151 ++++++++++--------- src/main.rs | 28 +++- 6 files changed, 258 insertions(+), 283 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index a7cfd25..bec4b7a 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,5 +1,5 @@ [build] -target = "x86_64-unknown-none" +target = "x86_64-unknown-mikros" [install] -root = "../kernel/sysroot" +root = "../os_build/sysroot" diff --git a/Cargo.lock b/Cargo.lock index 82dfe70..8d12d05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,28 +2,17 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bit_field" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" +checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" [[package]] name = "bitflags" @@ -31,6 +20,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + [[package]] name = "cfg-if" version = "1.0.0" @@ -43,44 +38,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" -[[package]] -name = "core2" -version = "0.4.0" -dependencies = [ - "memchr", - "serde", -] - -[[package]] -name = "crossbeam-queue" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd42583b04998a5363558e5f9291ee5a5ff6b49944332103f251e7479a82aa7" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "derive-try-from-primitive" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302ccf094df1151173bb6f5a2282fcd2f45accd5eae1bdf82dcbfefbc501ad5c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "dev_driver_rpc" version = "0.1.0" @@ -88,19 +45,13 @@ dependencies = [ "postcard", "serde", "spin", - "std", ] [[package]] -name = "elfloader" -version = "0.14.0" +name = "embedded-io" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a249d6a9d50f3bf5a3cb7bfd75e84989cad89c6c77b5996c8b084e844146ff04" -dependencies = [ - "bitflags", - "log", - "xmas-elf", -] +checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" [[package]] name = "file_rpc" @@ -109,174 +60,143 @@ dependencies = [ "postcard", "serde", "spin", - "std", -] - -[[package]] -name = "getrandom" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash", ] [[package]] name = "libc" -version = "0.2.132" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" - -[[package]] -name = "linked_list_allocator" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "636c3bc929db632724303109c88d5d559a2a60f62243bb041387f03fa081d94a" -dependencies = [ - "spinning_top", -] +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", ] [[package]] -name = "log" -version = "0.4.17" +name = "once_cell" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ - "cfg-if", + "lock_api", + "parking_lot_core", ] [[package]] -name = "memchr" -version = "2.5.0" +name = "parking_lot_core" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "once_cell" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] [[package]] name = "postcard" -version = "1.0.2" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c2b180dc0bade59f03fd005cb967d3f1e5f69b13922dad0cd6e047cb8af2363" +checksum = "a55c51ee6c0db07e68448e336cf8ea4131a620edefebf9893e759b2d793420f8" dependencies = [ "cobs", + "embedded-io", "serde", ] [[package]] name = "proc-macro2" -version = "1.0.43" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.21" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] [[package]] -name = "rustversion" -version = "1.0.9" +name = "redox_syscall" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags 2.5.0", +] + +[[package]] +name = "rustversion" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.144" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.144" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + [[package]] name = "spin" -version = "0.9.4" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" dependencies = [ "lock_api", ] -[[package]] -name = "spinning_top" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75adad84ee84b521fb2cca2d4fd0f1dab1d8d026bda3c5bea4ca63b5f9f9293c" -dependencies = [ - "lock_api", -] - -[[package]] -name = "std" -version = "0.1.0" -dependencies = [ - "core2", - "crossbeam-queue", - "derive-try-from-primitive", - "elfloader", - "hashbrown", - "linked_list_allocator", - "postcard", - "serde", - "spin", - "x86_64 0.14.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "syn" -version = "1.0.99" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -293,75 +213,99 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" name = "test_proc" version = "0.1.0" dependencies = [ - "bitflags", + "bitflags 1.3.2", "dev_driver_rpc", "file_rpc", - "postcard", - "serde", - "spin", - "std", + "once_cell", + "parking_lot", "tap", - "x86_64 0.14.10 (git+https://github.com/pjht/x86_64)", + "x86_64", ] [[package]] name = "unicode-ident" -version = "1.0.3" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "volatile" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3ca98349dda8a60ae74e04fd90c7fb4d6a4fbe01e6d3be095478aa0b76f6c0c" +checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793" [[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +name = "windows-targets" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "x86_64" -version = "0.14.10" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "100555a863c0092238c2e0e814c1096c1e5cf066a309c696a87e907b5f8c5d69" +checksum = "4bc79523af8abf92fb1a970c3e086c5a343f6bcc1a0eb890f575cbb3b45743df" dependencies = [ "bit_field", - "bitflags", + "bitflags 2.5.0", "rustversion", "volatile", ] - -[[package]] -name = "x86_64" -version = "0.14.10" -source = "git+https://github.com/pjht/x86_64#5d941e68fa70779e07576d42a9f49bc89afdb9ed" -dependencies = [ - "bit_field", - "bitflags", - "rustversion", - "volatile", -] - -[[package]] -name = "xmas-elf" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d29b4d8e7beaceb4e77447ba941a7600d23d0319ab52da0461abea214832d5a" -dependencies = [ - "zero", -] - -[[package]] -name = "zero" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f1bc8a6b2005884962297587045002d8cfb8dcec9db332f4ca216ddc5de82c5" diff --git a/Cargo.toml b/Cargo.toml index 1e99ce5..afe5c5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,14 +7,14 @@ edition = "2021" [dependencies] dev_driver_rpc = { version = "0.1.0", path = "../dev_driver_rpc" } -postcard = { version = "1.0.2", default-features = false, features = ["alloc"] } -serde = { version = "1.0.144", default-features = false, features = ["alloc", "derive"] } -std = { path = "../std" } bitflags = "1.3.2" -spin = "0.9.4" +# spin = "0.9.4" tap = "1.0.1" -x86_64 = { git = "https://github.com/pjht/x86_64", features = ["experimental"] } +# x86_64 = { git = "https://gitea.pterpstra.com/mikros/x86_64" } file_rpc = { version = "0.1.0", path = "../file_rpc" } +parking_lot = "0.12.3" +once_cell = "1.19.0" +x86_64 = "0.15.1" [profile.dev] panic = "abort" diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 5d56faf..a5535e3 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly" +channel = "dev-x86_64-unknown-mikros" diff --git a/src/ata.rs b/src/ata.rs index 1df8ece..28b5411 100644 --- a/src/ata.rs +++ b/src/ata.rs @@ -1,11 +1,12 @@ use std::cmp::Ordering; use bitflags::bitflags; -use spin::{Lazy, Mutex}; +use parking_lot::Mutex; +use once_cell::sync::Lazy; use std::io::{self, Read, Seek}; use tap::Tap; use x86_64::instructions::port::{ - PortRead, PortSafe, PortSafeReadOnly, PortSafeWriteOnly, PortWrite, + PortRead, Port, PortReadOnly, PortWriteOnly, PortWrite, }; bitflags! { @@ -189,15 +190,15 @@ impl From for IdentifyError { #[derive(Clone, Debug, PartialEq, Eq)] pub struct Bus { - data: PortSafe, - error: PortSafeReadOnly, - sector_count: PortSafe, - sector_num_lba_lo: PortSafe, - cyl_low_lba_mid: PortSafe, - cyl_high_lba_hi: PortSafe, - drive_head: PortSafe, - status: PortSafeReadOnly, - command: PortSafeWriteOnly, + data: Port, + error: PortReadOnly, + sector_count: Port, + sector_num_lba_lo: Port, + cyl_low_lba_mid: Port, + cyl_high_lba_hi: Port, + drive_head: Port, + status: PortReadOnly, + command: PortWriteOnly, selected_drive: Option, // None represents the initial state with an unknown drive selected } @@ -205,80 +206,91 @@ impl Bus { /// SAFETY /// io_base must be a valid base for the ATA bus's IO registers const unsafe fn new(io_base: u16) -> Self { - unsafe { - Self { - data: PortSafe::new(io_base), - error: PortSafeReadOnly::new(io_base + 1), - sector_count: PortSafe::new(io_base + 2), - sector_num_lba_lo: PortSafe::new(io_base + 3), - cyl_low_lba_mid: PortSafe::new(io_base + 4), - cyl_high_lba_hi: PortSafe::new(io_base + 5), - drive_head: PortSafe::new(io_base + 6), - status: PortSafeReadOnly::new(io_base + 7), - command: PortSafeWriteOnly::new(io_base + 7), - selected_drive: None, - } + Self { + data: Port::new(io_base), + error: PortReadOnly::new(io_base + 1), + sector_count: Port::new(io_base + 2), + sector_num_lba_lo: Port::new(io_base + 3), + cyl_low_lba_mid: Port::new(io_base + 4), + cyl_high_lba_hi: Port::new(io_base + 5), + drive_head: Port::new(io_base + 6), + status: PortReadOnly::new(io_base + 7), + command: PortWriteOnly::new(io_base + 7), + selected_drive: None, } } pub fn select(&mut self, drive: DriveNumber, lba: bool, data: u8) { - if self.selected_drive != Some(drive) { - self.drive_head.write(DriveHead::empty().tap_mut(|v| { - v.set(DriveHead::DRV, drive == DriveNumber::Slave); - v.set(DriveHead::LBA, lba); - v.set_head_block(data); - })); - for _ in 0..14 { - self.status.read(); + unsafe { + if self.selected_drive != Some(drive) { + self.drive_head.write(DriveHead::empty().tap_mut(|v| { + v.set(DriveHead::DRV, drive == DriveNumber::Slave); + v.set(DriveHead::LBA, lba); + v.set_head_block(data); + })); + for _ in 0..14 { + self.status.read(); + } + self.selected_drive = Some(drive); } - self.selected_drive = Some(drive); } } pub fn read_data(&mut self) -> Result<[u16; 256], Error> { - self.poll()?; - let mut arr = [0; 256]; - arr.fill_with(|| self.data.read()); - Ok(arr) + unsafe { + self.poll()?; + let mut arr = [0; 256]; + arr.fill_with(|| self.data.read()); + Ok(arr) + } } fn poll(&mut self) -> Result<(), Error> { - while self.status.read().contains(Status::BSY) {} - while !(self.status.read().intersects(Status::DRQ | Status::ERR)) {} - self.error() + unsafe { + while self.status.read().contains(Status::BSY) {} + while !(self.status.read().intersects(Status::DRQ | Status::ERR)) {} + self.error() + } } fn send_command(&mut self, command: Command) { - self.command.write(command as u8); + unsafe { + self.command.write(command as u8); + } } pub fn identify(&mut self) -> Result<(DriveKind, [u16; 256]), IdentifyError> { - self.command.write(Command::Identify as u8); - if self.status.read().bits() == 0 { - return Err(IdentifyError::Error(Error::NonexistentDrive)); - }; - self.poll()?; - if self.status.read().contains(Status::ERR) { - if self.cyl_low_lba_mid.read() == 0x14 && self.cyl_high_lba_hi.read() == 0xEB { - self.command.write(Command::IdentifyPacket as u8); - if self.status.read().bits() == 0 { - return Err(IdentifyError::Error(Error::NonexistentDrive)); - }; - Ok((DriveKind::ATAPI, self.read_data()?)) + unsafe { + self.command.write(Command::Identify as u8); + if self.status.read().bits() == 0 { + return Err(IdentifyError::Error(Error::NonexistentDrive)); + }; + self.poll()?; + if self.status.read().contains(Status::ERR) { + if self.cyl_low_lba_mid.read() == 0x14 && self.cyl_high_lba_hi.read() == 0xEB { + self.command.write(Command::IdentifyPacket as u8); + if self.status.read().bits() == 0 { + return Err(IdentifyError::Error(Error::NonexistentDrive)); + }; + Ok((DriveKind::ATAPI, self.read_data()?)) + } else { + Err(IdentifyError::SATADrive) + } } else { - Err(IdentifyError::SATADrive) + dbg!(); + Ok((DriveKind::ATA, self.read_data()?)) } - } else { - Ok((DriveKind::ATA, self.read_data()?)) } } fn error(&mut self) -> Result<(), Error> { - if self.status.read().contains(Status::ERR) { - panic!("Drive Error: {:?}", Error::from(self.error.read())); - Err(self.error.read().into()) - } else { - Ok(()) + unsafe { + if self.status.read().contains(Status::ERR) { + panic!("Drive Error: {:?}", Error::from(self.error.read())); + Err(self.error.read().into()) + } else { + Ok(()) + } } } } @@ -322,20 +334,25 @@ pub enum NewDeviceError { impl Device { fn new(bus: &'static Mutex, drive_number: DriveNumber) -> Result { + dbg!(bus, drive_number); bus.lock().select(drive_number, true, 0); + dbg!(); let id_result = bus .lock() .identify() .map_err(NewDeviceError::IdentifyError)?; + dbg!(); if let (DriveKind::ATA, ident_data) = id_result { + dbg!(); Ok(Self { bus, drive_number, lba: true, pos: 0, - len: (u64::from(ident_data[60]) * 512), + len: (((u64::from(ident_data[1]) << 16) | u64::from(ident_data[60])) * 512), }) } else { + dbg!(); Err(NewDeviceError::ATAPIDevice) } } @@ -361,10 +378,12 @@ impl Read for Device { if sector < 0x1000_0000 { self.select(((sector & 0xF00_0000) >> 24) as u8); let mut bus = self.bus.lock(); - bus.sector_count.write(num_sectors as u8); - bus.sector_num_lba_lo.write(sector as u8); - bus.cyl_low_lba_mid.write((sector >> 8) as u8); - bus.cyl_high_lba_hi.write((sector >> 16) as u8); + unsafe { + bus.sector_count.write(num_sectors as u8); + bus.sector_num_lba_lo.write(sector as u8); + bus.cyl_low_lba_mid.write((sector >> 8) as u8); + bus.cyl_high_lba_hi.write((sector >> 16) as u8); + } bus.send_command(Command::ReadSectors); } else { unimplemented!(); diff --git a/src/main.rs b/src/main.rs index a548139..01db560 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,3 @@ -#![no_std] -#![no_main] #![feature(int_roundings)] #![deny(unsafe_op_in_unsafe_fn)] @@ -12,8 +10,7 @@ use dev_driver_rpc::Server as DevServer; use file_rpc::Server as FileServer; use std::{ io::{self, Read, Seek, SeekFrom}, - ipc, - prelude::*, + os::mikros::ipc, }; struct Serv; @@ -30,37 +27,52 @@ fn get_drive_from_number(num: u64) -> Result { impl DevServer for Serv { fn open(&self, path: &str) -> Result { - match path { + dbg!(); + let rval = match path { "sda" => { + dbg!(); if PRIMARY_MASTER.is_ok() { + dbg!(); Ok(0) } else { + dbg!(); Err(io::ErrorKind::NotFound.into()) } } "sdb" => { + dbg!(); if PRIMARY_SLAVE.is_ok() { + dbg!(); Ok(1) } else { + dbg!(); Err(io::ErrorKind::NotFound.into()) } } "sdc" => { + dbg!(); if SECONDARY_MASTER.is_ok() { + dbg!(); Ok(2) } else { + dbg!(); Err(io::ErrorKind::NotFound.into()) } } "sdd" => { + dbg!(); if SECONDARY_SLAVE.is_ok() { + dbg!(); Ok(3) } else { + dbg!(); Err(io::ErrorKind::NotFound.into()) } } _ => Err(io::ErrorKind::NotFound.into()), - } + }; + dbg!(); + rval } } impl FileServer for Serv { @@ -82,10 +94,10 @@ impl FileServer for Serv { fn close(&self, _fd: u64) {} } -main!({ +fn main() { dev_driver_rpc::register_server(Box::new(Serv)); file_rpc::register_server(Box::new(Serv)); loop { ipc::process_messages() } -}); +}