diff --git a/bootloader/src/splash.rs b/bootloader/src/splash.rs index 9729426..ef29061 100644 --- a/bootloader/src/splash.rs +++ b/bootloader/src/splash.rs @@ -1,5 +1,5 @@ -pub const SPLASH: &'static str = -"▄ ▄ ▄ +pub const SPLASH: &'static str = + "▄ ▄ ▄ ██▄ ▄██ █ ▀█▄ ▄█▀▐█ █ ▀▄ ▄▀ ▐█ @@ -23,7 +23,7 @@ pub const SPLASH: &'static str = ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀▀▀▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ Press any key to start..."; - + #[allow(dead_code)] pub fn splash() { for c in SPLASH.chars() { @@ -33,8 +33,8 @@ pub fn splash() { '▌' => print!("{}", 0xdd as char), '▄' => print!("{}", 0xdc as char), '█' => print!("{}", 0xdb as char), - '\n' => {}, + '\n' => {} _ => print!("{}", c), } } -} \ No newline at end of file +} diff --git a/kernel/src/filesystem/fat.rs b/kernel/src/filesystem/fat.rs index 8640fc8..98e15e1 100755 --- a/kernel/src/filesystem/fat.rs +++ b/kernel/src/filesystem/fat.rs @@ -2,24 +2,20 @@ use crate::drivers::disk::DISK; use core::mem; -use core::sync::atomic::AtomicBool; use libfelix::mutex::Mutex; -//Warning! Mutable static here -pub static mut FAT_MUTEX: Mutex = Mutex::new( FatDriver { +pub static mut FAT: Mutex = Mutex::new(FatDriver { header: NULL_HEADER, entries: [NULL_ENTRY; ENTRY_COUNT], table: [0; FAT_SIZE], buffer: [0; 2048], -} ); +}); const ENTRY_COUNT: usize = 512; const FAT_START: u16 = 36864; const FAT_SIZE: usize = 256; - - //FAT16 header #[derive(Copy, Clone, Debug)] #[repr(C, packed)] @@ -51,7 +47,7 @@ pub struct Header { zero: [u8; 460], //needed to make struct 512 bytes big } -pub static NULL_HEADER: Header = Header { +static NULL_HEADER: Header = Header { boot_jump_instructions: [0; 3], oem_identifier: [0; 8], @@ -95,7 +91,7 @@ pub struct Entry { size: u32, } -pub static NULL_ENTRY: Entry = Entry { +static NULL_ENTRY: Entry = Entry { name: [0; 11], attributes: 0, reserved: 0, @@ -142,7 +138,7 @@ impl FatDriver { let lba: u64 = FAT_START as u64 + (self.header.reserved_sectors - + self.header.sectors_per_fat * self.header.fat_count as u16) as u64; + + self.header.sectors_per_fat * self.header.fat_count as u16) as u64; let size: u16 = entry_size * self.header.dir_entries_count; let sectors: u16 = size / self.header.bytes_per_sector; @@ -193,12 +189,12 @@ impl FatDriver { //read first cluster of file to buffer pub fn read_file_to_buffer(&self, entry: &Entry) { - let target = self.buffer.as_ptr() as *mut u8; + let target = self.buffer.as_ptr() as *mut u8; let data_lba: u64 = FAT_START as u64 + (self.header.reserved_sectors - + self.header.sectors_per_fat * self.header.fat_count as u16 - + 32) as u64; + + self.header.sectors_per_fat * self.header.fat_count as u16 + + 32) as u64; let lba: u64 = data_lba + ((entry.first_cluster_low - 2) * self.header.sectors_per_cluster as u16) as u64; @@ -218,8 +214,8 @@ impl FatDriver { loop { let data_lba: u64 = FAT_START as u64 + (self.header.reserved_sectors - + self.header.sectors_per_fat * self.header.fat_count as u16 - + 32) as u64; + + self.header.sectors_per_fat * self.header.fat_count as u16 + + 32) as u64; let lba: u64 = data_lba + ((next_cluster - 2) * self.header.sectors_per_cluster as u16) as u64; diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 1237398..5959cc7 100755 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -22,11 +22,11 @@ use memory::allocator::Allocator; use memory::paging::PAGING; use shell::shell::SHELL; use syscalls::print::PRINTER; +use filesystem::fat::FAT; use multitasking::task::TASK_MANAGER; use libfelix; -use crate::filesystem::fat::{FAT_MUTEX, FatDriver, NULL_ENTRY, NULL_HEADER}; #[global_allocator] static ALLOCATOR: Allocator = Allocator; @@ -80,11 +80,11 @@ pub extern "C" fn _start() -> ! { //init filesystem if DISK.enabled { - let fat = FAT_MUTEX.acquire_mut(); + let fat = FAT.acquire_mut(); fat.load_header(); fat.load_table(); fat.load_entries(); - FAT_MUTEX.free(); + FAT.free(); } //print name, version and copyright diff --git a/kernel/src/shell/shell.rs b/kernel/src/shell/shell.rs index 1f88382..effda02 100755 --- a/kernel/src/shell/shell.rs +++ b/kernel/src/shell/shell.rs @@ -1,6 +1,6 @@ //SHELL -use crate::filesystem::fat::{FAT_MUTEX}; +use crate::filesystem::fat::FAT; use crate::multitasking::task::TASK_MANAGER; use crate::syscalls::print::PRINTER; @@ -97,8 +97,8 @@ impl Shell { //list root directory _b if self.is_command("ls") => unsafe { - FAT_MUTEX.acquire().list_entries(); - FAT_MUTEX.free(); + FAT.acquire().list_entries(); + FAT.free(); }, //list running tasks @@ -170,15 +170,14 @@ impl Shell { for i in 4..15 { self.arg[i - 4] = b[i]; } - let fat_driver = FAT_MUTEX.acquire(); + let fat = FAT.acquire(); - let entry = fat_driver.search_file(&self.arg); + let entry = fat.search_file(&self.arg); if entry.name[0] != 0 { + fat.read_file_to_buffer(entry); - fat_driver.read_file_to_buffer(entry); - - for c in fat_driver.buffer { + for c in fat.buffer { if c != 0 { libfelix::print!("{}", c as char); } @@ -187,7 +186,7 @@ impl Shell { } else { libfelix::println!("File not found!"); } - FAT_MUTEX.free(); + FAT.free(); } //loads an executable as a task @@ -195,9 +194,9 @@ impl Shell { for i in 4..15 { self.arg[i - 4] = b[i]; } - let ft = FAT_MUTEX.acquire(); + let fat = FAT.acquire(); - let entry = ft.search_file(&self.arg); + let entry = fat.search_file(&self.arg); if entry.name[0] != 0 { let slot = TASK_MANAGER.get_free_slot(); let target = APP_TARGET + (slot as u32 * APP_SIZE); @@ -206,7 +205,7 @@ impl Shell { TABLES[8].set(target); PAGING.set_table(8, &TABLES[8]); - ft.read_file_to_target(&entry, target as *mut u32); + fat.read_file_to_target(&entry, target as *mut u32); unsafe { let signature = *(target as *mut u32); @@ -220,8 +219,7 @@ impl Shell { } else { libfelix::println!("Program not found!"); } - FAT_MUTEX.free(); - + FAT.free(); } pub fn is_command(&self, command: &str) -> bool { diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 0ae7548..8cc6829 100755 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -1,5 +1,4 @@ #![no_std] - -pub mod print; pub mod mutex; +pub mod print; diff --git a/lib/src/mutex.rs b/lib/src/mutex.rs index c3abc54..fe5f372 100755 --- a/lib/src/mutex.rs +++ b/lib/src/mutex.rs @@ -1,15 +1,14 @@ -use core::fmt; use core::sync::atomic::{AtomicBool, Ordering}; /* - This is a oversimplified mutex created from scratch. Meant to be used for global, static definitions of objects, visible for all active threads. Once a thread acquires the target object, all other threads trying to do so will wait until it is freed. - - There is plenty of room for improvements, since there are no mechanisms for e.g. creating a queue of threads that requested access to an object and giving it to the first that needs it. - - TODO: Improve it + This is a oversimplified mutex created from scratch. Meant to be used for global, static definitions of objects, visible for all active threads. Once a thread acquires the target object, all other threads trying to do so will wait until it is freed. + + There is plenty of room for improvements, since there are no mechanisms for e.g. creating a queue of threads that requested access to an object and giving it to the first that needs it. + + TODO: Improve it */ pub struct Mutex { - target: T, - free: AtomicBool, + target: T, + free: AtomicBool, } impl Mutex { @@ -39,9 +38,8 @@ impl Mutex { } } -impl Drop for Mutex { +impl Drop for Mutex { fn drop(&mut self) { self.free = AtomicBool::from(true); } } -