diff --git a/src/ata.rs b/src/ata.rs index 4d2bd93..6fa74e3 100644 --- a/src/ata.rs +++ b/src/ata.rs @@ -1,11 +1,11 @@ // ATA Driver! +use crate::println; use alloc::{string::String, vec::Vec}; +use bit_field::BitField; use core::hint::spin_loop; use lazy_static::lazy_static; use spin::Mutex; use x86_64::instructions::port::{Port, PortReadOnly, PortWriteOnly}; -use bit_field::BitField; -use crate::println; // Commands to send to the drives #[repr(u16)] @@ -47,15 +47,15 @@ pub struct Bus { alternate_status_register: PortReadOnly, control_register: PortWriteOnly, - drive_blockless_register: PortReadOnly + drive_blockless_register: PortReadOnly, } - #[allow(dead_code)] impl Bus { pub fn new(id: u8, io_base: u16, ctrl_base: u16, irq: u8) -> Self { Bus { - id, irq, + id, + irq, data_register: Port::new(io_base), error_register: PortReadOnly::new(io_base + 1), @@ -71,7 +71,6 @@ impl Bus { alternate_status_register: PortReadOnly::new(ctrl_base), control_register: PortWriteOnly::new(ctrl_base), drive_blockless_register: PortReadOnly::new(ctrl_base + 1), - } } @@ -106,21 +105,15 @@ impl Bus { } fn status(&mut self) -> u8 { - unsafe { - self.status_register.read() - } + unsafe { self.status_register.read() } } fn lba1(&mut self) -> u8 { - unsafe { - self.lba1_register.read() - } + unsafe { self.lba1_register.read() } } fn lba2(&mut self) -> u8 { - unsafe { - self.lba2_register.read() - } + unsafe { self.lba2_register.read() } } fn read_data(&mut self) -> u16 { @@ -136,7 +129,7 @@ impl Bus { } spin_loop(); - } + } } fn is_busy(&mut self) -> bool { @@ -164,45 +157,43 @@ impl Bus { self.write_command(Command::Identify); - if self.status() == 0 { - println!("status 0"); + if self.status() == 0 { + println!("status 0"); return None; - } + } - self.busy_loop(); + self.busy_loop(); - if self.lba1() != 0 || self.lba2() != 0 { - println!("lba thingies"); - return None; - } + if self.lba1() != 0 || self.lba2() != 0 { + println!("lba thingies"); + return None; + } - for i in 0.. { - if i == 256 { - println!("i 256"); - self.reset(); - return None; - } - if self.is_error() { - println!("Is error"); - return None; - } - if self.is_ready() { - println!("ready"); - break; - } - } + for i in 0.. { + if i == 256 { + println!("i 256"); + self.reset(); + return None; + } + if self.is_error() { + println!("Is error"); + return None; + } + if self.is_ready() { + println!("ready"); + break; + } + } - let mut res = [0; 256]; - for i in 0..256 { - res[i] = self.read_data(); - } + let mut res = [0; 256]; + for i in 0..256 { + res[i] = self.read_data(); + } - Some(res) + Some(res) } } - - lazy_static! { pub static ref BUS: Mutex = Mutex::new(Bus::new(0, 0x170, 0x376, 15)); } @@ -244,4 +235,3 @@ pub fn info() -> Vec<(u8, String, String, u32, String)> { } res } - diff --git a/src/clock.rs b/src/clock.rs index 18191bd..92e50a8 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -1,5 +1,5 @@ -use core::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; use core::hint::spin_loop; +use core::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; use x86_64::instructions::port::Port; static CLOCKS_PER_NANOSECOND: AtomicU64 = AtomicU64::new(0); @@ -51,7 +51,7 @@ pub fn nanowait(nanoseconds: u64) { let start = rdtsc(); let delta = nanoseconds * CLOCKS_PER_NANOSECOND.load(Ordering::Relaxed); while rdtsc() - start < delta { - spin_loop(); + spin_loop(); } } diff --git a/src/interrupts.rs b/src/interrupts.rs index 7fca3e3..12298ab 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -43,7 +43,10 @@ extern "x86-interrupt" fn page_fault_handler( error_code: x86_64::structures::idt::PageFaultErrorCode, ) { println!("EXCEPTION : PAGE FAULT"); - println!("Accessed Address: {:?}", x86_64::registers::control::Cr2::read()); + println!( + "Accessed Address: {:?}", + x86_64::registers::control::Cr2::read() + ); println!("Error Code: {:?}", error_code); println!("{:#?}", stack_frame); x86_64::instructions::interrupts::enable_and_hlt(); diff --git a/src/main.rs b/src/main.rs index d8df381..9f81dda 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,8 +16,8 @@ mod memory; mod shell; mod vga_buffer; -use bootloader::BootInfo; use bootloader::entry_point; +use bootloader::BootInfo; use core::panic::PanicInfo; extern crate alloc; @@ -49,15 +49,15 @@ macro_rules! status { print!("OK"); change_color(Color::White, Color::Black); println!(" ] {}", $n); - } + }; } entry_point!(main); fn main(boot_info: &'static BootInfo) -> ! { + use crate::vga_buffer::{change_color, Color}; use memory::BootInfoFrameAllocator; - use x86_64::VirtAddr; - use crate::vga_buffer::{change_color, Color}; // For status! macro + use x86_64::VirtAddr; // For status! macro init(); status!("Initialized GDT and Interrupts");