fixup! Format Rust code with rustfmt

This commit is contained in:
github-actions 2021-09-26 18:14:57 +00:00
parent eadab15759
commit 5f56472982
4 changed files with 47 additions and 54 deletions

View file

@ -1,11 +1,11 @@
// ATA Driver! // ATA Driver!
use crate::println;
use alloc::{string::String, vec::Vec}; use alloc::{string::String, vec::Vec};
use bit_field::BitField;
use core::hint::spin_loop; use core::hint::spin_loop;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use spin::Mutex; use spin::Mutex;
use x86_64::instructions::port::{Port, PortReadOnly, PortWriteOnly}; use x86_64::instructions::port::{Port, PortReadOnly, PortWriteOnly};
use bit_field::BitField;
use crate::println;
// Commands to send to the drives // Commands to send to the drives
#[repr(u16)] #[repr(u16)]
@ -47,15 +47,15 @@ pub struct Bus {
alternate_status_register: PortReadOnly<u8>, alternate_status_register: PortReadOnly<u8>,
control_register: PortWriteOnly<u8>, control_register: PortWriteOnly<u8>,
drive_blockless_register: PortReadOnly<u8> drive_blockless_register: PortReadOnly<u8>,
} }
#[allow(dead_code)] #[allow(dead_code)]
impl Bus { impl Bus {
pub fn new(id: u8, io_base: u16, ctrl_base: u16, irq: u8) -> Self { pub fn new(id: u8, io_base: u16, ctrl_base: u16, irq: u8) -> Self {
Bus { Bus {
id, irq, id,
irq,
data_register: Port::new(io_base), data_register: Port::new(io_base),
error_register: PortReadOnly::new(io_base + 1), error_register: PortReadOnly::new(io_base + 1),
@ -71,7 +71,6 @@ impl Bus {
alternate_status_register: PortReadOnly::new(ctrl_base), alternate_status_register: PortReadOnly::new(ctrl_base),
control_register: PortWriteOnly::new(ctrl_base), control_register: PortWriteOnly::new(ctrl_base),
drive_blockless_register: PortReadOnly::new(ctrl_base + 1), drive_blockless_register: PortReadOnly::new(ctrl_base + 1),
} }
} }
@ -106,21 +105,15 @@ impl Bus {
} }
fn status(&mut self) -> u8 { fn status(&mut self) -> u8 {
unsafe { unsafe { self.status_register.read() }
self.status_register.read()
}
} }
fn lba1(&mut self) -> u8 { fn lba1(&mut self) -> u8 {
unsafe { unsafe { self.lba1_register.read() }
self.lba1_register.read()
}
} }
fn lba2(&mut self) -> u8 { fn lba2(&mut self) -> u8 {
unsafe { unsafe { self.lba2_register.read() }
self.lba2_register.read()
}
} }
fn read_data(&mut self) -> u16 { fn read_data(&mut self) -> u16 {
@ -136,7 +129,7 @@ impl Bus {
} }
spin_loop(); spin_loop();
} }
} }
fn is_busy(&mut self) -> bool { fn is_busy(&mut self) -> bool {
@ -164,45 +157,43 @@ impl Bus {
self.write_command(Command::Identify); self.write_command(Command::Identify);
if self.status() == 0 { if self.status() == 0 {
println!("status 0"); println!("status 0");
return None; return None;
} }
self.busy_loop(); self.busy_loop();
if self.lba1() != 0 || self.lba2() != 0 { if self.lba1() != 0 || self.lba2() != 0 {
println!("lba thingies"); println!("lba thingies");
return None; return None;
} }
for i in 0.. { for i in 0.. {
if i == 256 { if i == 256 {
println!("i 256"); println!("i 256");
self.reset(); self.reset();
return None; return None;
} }
if self.is_error() { if self.is_error() {
println!("Is error"); println!("Is error");
return None; return None;
} }
if self.is_ready() { if self.is_ready() {
println!("ready"); println!("ready");
break; break;
} }
} }
let mut res = [0; 256]; let mut res = [0; 256];
for i in 0..256 { for i in 0..256 {
res[i] = self.read_data(); res[i] = self.read_data();
} }
Some(res) Some(res)
} }
} }
lazy_static! { lazy_static! {
pub static ref BUS: Mutex<Bus> = Mutex::new(Bus::new(0, 0x170, 0x376, 15)); pub static ref BUS: Mutex<Bus> = Mutex::new(Bus::new(0, 0x170, 0x376, 15));
} }
@ -244,4 +235,3 @@ pub fn info() -> Vec<(u8, String, String, u32, String)> {
} }
res res
} }

View file

@ -1,5 +1,5 @@
use core::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
use core::hint::spin_loop; use core::hint::spin_loop;
use core::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
use x86_64::instructions::port::Port; use x86_64::instructions::port::Port;
static CLOCKS_PER_NANOSECOND: AtomicU64 = AtomicU64::new(0); static CLOCKS_PER_NANOSECOND: AtomicU64 = AtomicU64::new(0);
@ -51,7 +51,7 @@ pub fn nanowait(nanoseconds: u64) {
let start = rdtsc(); let start = rdtsc();
let delta = nanoseconds * CLOCKS_PER_NANOSECOND.load(Ordering::Relaxed); let delta = nanoseconds * CLOCKS_PER_NANOSECOND.load(Ordering::Relaxed);
while rdtsc() - start < delta { while rdtsc() - start < delta {
spin_loop(); spin_loop();
} }
} }

View file

@ -43,7 +43,10 @@ extern "x86-interrupt" fn page_fault_handler(
error_code: x86_64::structures::idt::PageFaultErrorCode, error_code: x86_64::structures::idt::PageFaultErrorCode,
) { ) {
println!("EXCEPTION : PAGE FAULT"); 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!("Error Code: {:?}", error_code);
println!("{:#?}", stack_frame); println!("{:#?}", stack_frame);
x86_64::instructions::interrupts::enable_and_hlt(); x86_64::instructions::interrupts::enable_and_hlt();

View file

@ -16,8 +16,8 @@ mod memory;
mod shell; mod shell;
mod vga_buffer; mod vga_buffer;
use bootloader::BootInfo;
use bootloader::entry_point; use bootloader::entry_point;
use bootloader::BootInfo;
use core::panic::PanicInfo; use core::panic::PanicInfo;
extern crate alloc; extern crate alloc;
@ -49,15 +49,15 @@ macro_rules! status {
print!("OK"); print!("OK");
change_color(Color::White, Color::Black); change_color(Color::White, Color::Black);
println!(" ] {}", $n); println!(" ] {}", $n);
} };
} }
entry_point!(main); entry_point!(main);
fn main(boot_info: &'static BootInfo) -> ! { fn main(boot_info: &'static BootInfo) -> ! {
use crate::vga_buffer::{change_color, Color};
use memory::BootInfoFrameAllocator; use memory::BootInfoFrameAllocator;
use x86_64::VirtAddr; use x86_64::VirtAddr; // For status! macro
use crate::vga_buffer::{change_color, Color}; // For status! macro
init(); init();
status!("Initialized GDT and Interrupts"); status!("Initialized GDT and Interrupts");