diff --git a/src/arch/aarch64/kernel/mod.rs b/src/arch/aarch64/kernel/mod.rs index 62cb4b71ad33c40e55dbcd8883676fb5e743ba79..054f19bf03d51a35c578f13569bfc2cbc274100e 100644 --- a/src/arch/aarch64/kernel/mod.rs +++ b/src/arch/aarch64/kernel/mod.rs @@ -21,10 +21,10 @@ use crate::arch::aarch64::kernel::serial::SerialPort; pub use crate::arch::aarch64::kernel::stubs::*; pub use crate::arch::aarch64::kernel::systemtime::get_boot_time; use crate::arch::aarch64::mm::{PhysAddr, VirtAddr}; +use crate::config::*; use crate::environment; use crate::kernel_message_buffer; use crate::synch::spinlock::Spinlock; -use crate::config::*; use core::ptr; const SERIAL_PORT_BAUDRATE: u32 = 115200; @@ -138,7 +138,7 @@ pub fn get_cmdsize() -> usize { } pub fn get_cmdline() -> VirtAddr { - VirtAddr(unsafe { core::ptr::read_volatile(&BOOT_INFO.cmdline)}) + VirtAddr(unsafe { core::ptr::read_volatile(&BOOT_INFO.cmdline) }) } /// Earliest initialization function called by the Boot Processor. @@ -148,14 +148,18 @@ pub fn message_output_init() { if environment::is_single_kernel() { // We can only initialize the serial port here, because VGA requires processor // configuration first. - unsafe { COM1.init(SERIAL_PORT_BAUDRATE); } + unsafe { + COM1.init(SERIAL_PORT_BAUDRATE); + } } } pub fn output_message_byte(byte: u8) { if environment::is_single_kernel() { // Output messages to the serial port and VGA screen in unikernel mode. - unsafe { COM1.write_byte(byte); } + unsafe { + COM1.write_byte(byte); + } } else { // Output messages to the kernel message buffer in multi-kernel mode. kernel_message_buffer::write_byte(byte); @@ -164,7 +168,7 @@ pub fn output_message_byte(byte: u8) { pub fn output_message_buf(buf: &[u8]) { for byte in buf { - output_message_byte(*byte); + output_message_byte(*byte); } } @@ -287,14 +291,13 @@ pub fn network_adapter_init() -> i32 { -1 } -pub fn print_statistics() { -} +pub fn print_statistics() {} #[inline(never)] #[no_mangle] pub unsafe fn pre_init() -> ! { - let com1 = SerialPort::new(0x9000000); + let com1 = SerialPort::new(0x9000000); - com1.write_byte('H' as u8); - loop {} + com1.write_byte('H' as u8); + loop {} } diff --git a/src/arch/aarch64/kernel/pci.rs b/src/arch/aarch64/kernel/pci.rs index fd1b11a7d609830cd2f47c995fc6581215bd938c..1b4410eb76c21d6913374f666f36eddd09de5023 100644 --- a/src/arch/aarch64/kernel/pci.rs +++ b/src/arch/aarch64/kernel/pci.rs @@ -1,46 +1,44 @@ +use crate::synch::spinlock::SpinlockIrqSave; use alloc::rc::Rc; use core::cell::RefCell; -use crate::synch::spinlock::SpinlockIrqSave; // Currently, onbly a dummy implementation pub struct VirtioNetDriver; impl VirtioNetDriver { - pub fn init_vqs(&mut self) { - } + pub fn init_vqs(&mut self) {} - pub fn set_polling_mode(&mut self, value: bool) { - //(self.vqueues.as_deref_mut().unwrap())[VIRTIO_NET_RX_QUEUE].set_polling_mode(value); - } + pub fn set_polling_mode(&mut self, value: bool) { + //(self.vqueues.as_deref_mut().unwrap())[VIRTIO_NET_RX_QUEUE].set_polling_mode(value); + } - pub fn get_mac_address(&self) -> [u8; 6] { - [0; 6] - } + pub fn get_mac_address(&self) -> [u8; 6] { + [0; 6] + } - pub fn get_mtu(&self) -> u16 { - 1500 //self.device_cfg.mtu - } + pub fn get_mtu(&self) -> u16 { + 1500 //self.device_cfg.mtu + } - pub fn get_tx_buffer(&mut self, len: usize) -> Result<(*mut u8, usize), ()> { - Err(()) - } + pub fn get_tx_buffer(&mut self, len: usize) -> Result<(*mut u8, usize), ()> { + Err(()) + } - pub fn send_tx_buffer(&mut self, index: usize, len: usize) -> Result<(), ()> { - Err(()) - } + pub fn send_tx_buffer(&mut self, index: usize, len: usize) -> Result<(), ()> { + Err(()) + } - pub fn has_packet(&self) -> bool { - false - } + pub fn has_packet(&self) -> bool { + false + } - pub fn receive_rx_buffer(&self) -> Result<&'static [u8], ()> { - Err(()) - } + pub fn receive_rx_buffer(&self) -> Result<&'static [u8], ()> { + Err(()) + } - pub fn rx_buffer_consumed(&mut self) { - } + pub fn rx_buffer_consumed(&mut self) {} } -pub fn get_network_driver() -> Option<&'static SpinlockIrqSave<VirtioNetDriver>> { - None +pub fn get_network_driver() -> Option<&'static SpinlockIrqSave<VirtioNetDriver>> { + None } diff --git a/src/arch/aarch64/kernel/scheduler.rs b/src/arch/aarch64/kernel/scheduler.rs index 4d4f36f42dabef1b3f4bee90b73d2dbd62c38317..31d2c8982aa8a808d6ca295d182b8db12400ea97 100644 --- a/src/arch/aarch64/kernel/scheduler.rs +++ b/src/arch/aarch64/kernel/scheduler.rs @@ -6,19 +6,18 @@ // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms. - //! Architecture dependent interface to initialize a task -use alloc::rc::Rc; use crate::arch::aarch64::kernel::percore::*; use crate::arch::aarch64::kernel::processor; -use crate::{DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; +use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags}; use crate::arch::aarch64::mm::{PhysAddr, VirtAddr}; -use crate::arch::aarch64::mm::paging::{PageSize,BasePageSize,PageTableEntryFlags}; +use crate::environment; +use crate::scheduler::task::{Task, TaskFrame}; +use crate::{DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; +use alloc::rc::Rc; use core::cell::RefCell; use core::{mem, ptr}; -use crate::scheduler::task::{Task, TaskFrame}; -use crate::environment; extern "C" { static tls_start: u8; @@ -123,42 +122,42 @@ impl TaskStacks { pub fn get_user_stack_size(&self) -> usize { match self { - TaskStacks::Boot(_) => 0, - TaskStacks::Common(stacks) => { - stacks.total_size - DEFAULT_STACK_SIZE - KERNEL_STACK_SIZE - } + TaskStacks::Boot(_) => 0, + TaskStacks::Common(stacks) => { + stacks.total_size - DEFAULT_STACK_SIZE - KERNEL_STACK_SIZE + } } } pub fn get_user_stack(&self) -> VirtAddr { match self { - TaskStacks::Boot(_) => VirtAddr::zero(), - TaskStacks::Common(stacks) => { - stacks.virt_addr + KERNEL_STACK_SIZE + DEFAULT_STACK_SIZE + 3 * BasePageSize::SIZE - } + TaskStacks::Boot(_) => VirtAddr::zero(), + TaskStacks::Common(stacks) => { + stacks.virt_addr + KERNEL_STACK_SIZE + DEFAULT_STACK_SIZE + 3 * BasePageSize::SIZE + } } } pub fn get_kernel_stack(&self) -> VirtAddr { match self { - TaskStacks::Boot(stacks) => stacks.stack, - TaskStacks::Common(stacks) => { - stacks.virt_addr + KERNEL_STACK_SIZE + 2 * BasePageSize::SIZE - } + TaskStacks::Boot(stacks) => stacks.stack, + TaskStacks::Common(stacks) => { + stacks.virt_addr + KERNEL_STACK_SIZE + 2 * BasePageSize::SIZE + } } } pub fn get_kernel_stack_size(&self) -> usize { match self { - TaskStacks::Boot(_) => KERNEL_STACK_SIZE, - TaskStacks::Common(_) => DEFAULT_STACK_SIZE, + TaskStacks::Boot(_) => KERNEL_STACK_SIZE, + TaskStacks::Common(_) => DEFAULT_STACK_SIZE, } } pub fn get_interupt_stack(&self) -> VirtAddr { match self { - TaskStacks::Boot(stacks) => stacks.ist0, - TaskStacks::Common(stacks) => stacks.virt_addr + BasePageSize::SIZE, + TaskStacks::Boot(stacks) => stacks.ist0, + TaskStacks::Common(stacks) => stacks.virt_addr + BasePageSize::SIZE, } } @@ -169,12 +168,12 @@ impl TaskStacks { impl Clone for TaskStacks { fn clone(&self) -> TaskStacks { - match self { - TaskStacks::Boot(_) => TaskStacks::new(0), - TaskStacks::Common(stacks) => { - TaskStacks::new(stacks.total_size - DEFAULT_STACK_SIZE - KERNEL_STACK_SIZE) - } + match self { + TaskStacks::Boot(_) => TaskStacks::new(0), + TaskStacks::Common(stacks) => { + TaskStacks::new(stacks.total_size - DEFAULT_STACK_SIZE - KERNEL_STACK_SIZE) } + } } } @@ -212,31 +211,33 @@ pub struct TaskTLS { impl TaskTLS { pub fn new(tls_size: usize) -> Self { - Self { address: VirtAddr::zero() } + Self { + address: VirtAddr::zero(), + } } #[inline] - pub fn address(&self) -> VirtAddr { - self.address - } + pub fn address(&self) -> VirtAddr { + self.address + } } impl Drop for TaskTLS { fn drop(&mut self) { - /*debug!( - "Deallocate TLS at 0x{:x} (layout {:?})", - self.address, self.layout, - ); + /*debug!( + "Deallocate TLS at 0x{:x} (layout {:?})", + self.address, self.layout, + ); - unsafe { - dealloc(self.address.as_mut_ptr::<u8>(), self.layout); - }*/ + unsafe { + dealloc(self.address.as_mut_ptr::<u8>(), self.layout); + }*/ } } impl Clone for TaskTLS { fn clone(&self) -> Self { - TaskTLS::new(environment::get_tls_memsz()) + TaskTLS::new(environment::get_tls_memsz()) } } diff --git a/src/arch/aarch64/mm/paging.rs b/src/arch/aarch64/mm/paging.rs index 85ac5d1204cb9e3fab44cd5be40d2d92f2dd6a13..8e548ef912ea03cb8921836f43df2c0766efd9bb 100644 --- a/src/arch/aarch64/mm/paging.rs +++ b/src/arch/aarch64/mm/paging.rs @@ -121,7 +121,11 @@ pub struct PageTableEntry { impl PageTableEntry { /// Return the stored physical address. pub fn address(&self) -> PhysAddr { - PhysAddr(self.physical_address_and_flags.as_u64() & !(BasePageSize::SIZE as u64 - 1u64) & !(u64::MAX << 48)) + PhysAddr( + self.physical_address_and_flags.as_u64() + & !(BasePageSize::SIZE as u64 - 1u64) + & !(u64::MAX << 48), + ) } /// Returns whether this entry is valid (present). @@ -259,7 +263,8 @@ impl<S: PageSize> Page<S> { /// Returns the index of this page in the table given by L. fn table_index<L: PageTableLevel>(&self) -> usize { assert!(L::LEVEL <= S::MAP_LEVEL); - self.virtual_address.as_usize() >> PAGE_BITS >> (3 - L::LEVEL) * PAGE_MAP_BITS & PAGE_MAP_MASK + self.virtual_address.as_usize() >> PAGE_BITS >> (3 - L::LEVEL) * PAGE_MAP_BITS + & PAGE_MAP_MASK } } @@ -456,7 +461,8 @@ where // Does the table exist yet? if !self.entries[index].is_present() { // Allocate a single 4 KiB page for the new entry and mark it as a valid, writable subtable. - let physical_address = physicalmem::allocate(BasePageSize::SIZE).expect("Unable to allocate physical memory"); + let physical_address = physicalmem::allocate(BasePageSize::SIZE) + .expect("Unable to allocate physical memory"); self.entries[index].set( physical_address, PageTableEntryFlags::NORMAL | PageTableEntryFlags::TABLE_OR_4KIB_PAGE, @@ -599,8 +605,7 @@ pub fn map<S: PageSize>( root_pagetable.map_pages(range, physical_address, flags); } -pub fn unmap<S: PageSize>(virtual_address: VirtAddr, count: usize) { -} +pub fn unmap<S: PageSize>(virtual_address: VirtAddr, count: usize) {} #[inline] pub fn get_application_page_size() -> usize { diff --git a/src/arch/aarch64/mm/physicalmem.rs b/src/arch/aarch64/mm/physicalmem.rs index 88dd8010ef7ae4dc4529c1c8bebff2416189979c..5ebbed291730a1a7f22cc0d61223bb0592c962be 100644 --- a/src/arch/aarch64/mm/physicalmem.rs +++ b/src/arch/aarch64/mm/physicalmem.rs @@ -9,9 +9,9 @@ use core::convert::TryInto; use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize}; use crate::arch::aarch64::mm::{PhysAddr, VirtAddr}; -use crate::synch::spinlock::SpinlockIrqSave; use crate::mm; use crate::mm::freelist::{FreeList, FreeListEntry}; +use crate::synch::spinlock::SpinlockIrqSave; extern "C" { static limit: usize; @@ -58,7 +58,7 @@ pub fn allocate(size: usize) -> Result<PhysAddr, ()> { .lock() .allocate(size, None)? .try_into() - .unwrap() + .unwrap(), )) } @@ -85,7 +85,7 @@ pub fn allocate_aligned(size: usize, alignment: usize) -> Result<PhysAddr, ()> { .lock() .allocate(size, Some(alignment))? .try_into() - .unwrap() + .unwrap(), )) } @@ -106,9 +106,13 @@ pub fn deallocate(physical_address: PhysAddr, size: usize) { BasePageSize::SIZE ); - PHYSICAL_FREE_LIST.lock().deallocate(physical_address.as_usize(), size); + PHYSICAL_FREE_LIST + .lock() + .deallocate(physical_address.as_usize(), size); } pub fn print_information() { - PHYSICAL_FREE_LIST.lock().print_information(" PHYSICAL MEMORY FREE LIST "); + PHYSICAL_FREE_LIST + .lock() + .print_information(" PHYSICAL MEMORY FREE LIST "); } diff --git a/src/arch/aarch64/mm/virtualmem.rs b/src/arch/aarch64/mm/virtualmem.rs index 82bf6eabbf627ba91040715201ea006834dc19ff..9c6849a3ba6cde8d8767d7bd28ed74e3e66bb36b 100644 --- a/src/arch/aarch64/mm/virtualmem.rs +++ b/src/arch/aarch64/mm/virtualmem.rs @@ -43,7 +43,11 @@ pub fn allocate(size: usize) -> Result<VirtAddr, ()> { ); Ok(VirtAddr( - KERNEL_FREE_LIST.lock().allocate(size, None)?.try_into().unwrap(), + KERNEL_FREE_LIST + .lock() + .allocate(size, None)? + .try_into() + .unwrap(), )) } @@ -51,26 +55,26 @@ pub fn allocate_aligned(size: usize, alignment: usize) -> Result<VirtAddr, ()> { assert!(size > 0); assert!(alignment > 0); assert_eq!( - size % alignment, - 0, - "Size {:#X} is not a multiple of the given alignment {:#X}", - size, - alignment + size % alignment, + 0, + "Size {:#X} is not a multiple of the given alignment {:#X}", + size, + alignment ); assert_eq!( - alignment % BasePageSize::SIZE, - 0, - "Alignment {:#X} is not a multiple of {:#X}", - alignment, - BasePageSize::SIZE + alignment % BasePageSize::SIZE, + 0, + "Alignment {:#X} is not a multiple of {:#X}", + alignment, + BasePageSize::SIZE ); Ok(VirtAddr( - KERNEL_FREE_LIST - .lock() - .allocate(size, Some(alignment))? - .try_into() - .unwrap(), + KERNEL_FREE_LIST + .lock() + .allocate(size, Some(alignment))? + .try_into() + .unwrap(), )) } @@ -101,7 +105,9 @@ pub fn deallocate(virtual_address: VirtAddr, size: usize) { BasePageSize::SIZE ); - KERNEL_FREE_LIST.lock().deallocate(virtual_address.as_usize(), size); + KERNEL_FREE_LIST + .lock() + .deallocate(virtual_address.as_usize(), size); } /*pub fn reserve(virtual_address: VirtAddr, size: usize) { @@ -141,7 +147,9 @@ pub fn deallocate(virtual_address: VirtAddr, size: usize) { }*/ pub fn print_information() { - KERNEL_FREE_LIST.lock().print_information(" KERNEL VIRTUAL MEMORY FREE LIST "); + KERNEL_FREE_LIST + .lock() + .print_information(" KERNEL VIRTUAL MEMORY FREE LIST "); } #[inline] diff --git a/src/arch/mod.rs b/src/arch/mod.rs index af68318b05cb6e81d3fbc0776003ac424750738f..51ba2519b5ef7b6b4bfb3d75dc21c10b1173b16f 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -23,7 +23,7 @@ pub use crate::arch::aarch64::kernel::stubs::{set_oneshot_timer, switch_to_task, #[cfg(target_arch = "aarch64")] pub use crate::arch::aarch64::kernel::{ application_processor_init, boot_application_processors, boot_processor_init, - get_processor_count, message_output_init, output_message_byte, output_message_buf, + get_processor_count, message_output_init, output_message_buf, output_message_byte, }; #[cfg(target_arch = "aarch64")] diff --git a/src/drivers/mod.rs b/src/drivers/mod.rs index ea33cc58d5895a0c73d2b9ed4459f39279e153a7..f11df6cec5e58ad0b0aff27fcd3a20c1b228bb1f 100644 --- a/src/drivers/mod.rs +++ b/src/drivers/mod.rs @@ -16,13 +16,13 @@ //#[cfg(not(feature = "newlib"))] pub mod net; -#[cfg(feature = "pci")] +#[cfg(all(feature = "pci", not(target_arch = "aarch64")))] pub mod virtio; /// A common error module for drivers. /// [DriverError](enums.drivererror.html) values will be /// passed on to higher layers. -#[cfg(feature = "pci")] +#[cfg(all(feature = "pci", not(target_arch = "aarch64")))] pub mod error { use crate::drivers::net::rtl8139::RTL8139Error; use crate::drivers::virtio::error::VirtioError; diff --git a/src/lib.rs b/src/lib.rs index f4f54e850f2f4b48eae75939cbaccbd57752490f..925c692e805625b9858257bd835d504645b7e42d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,10 +55,10 @@ extern crate num_derive; #[cfg(not(target_os = "hermit"))] #[macro_use] extern crate std; -#[cfg(target_arch = "x86_64")] -extern crate x86; #[cfg(target_arch = "aarch64")] extern crate aarch64; +#[cfg(target_arch = "x86_64")] +extern crate x86; use alloc::alloc::Layout; use core::alloc::GlobalAlloc; diff --git a/src/macros.rs b/src/macros.rs index c18d2c099228cd434461f588929274effbd2ae86..4de96496f434db5e65663303b5716bfe59755ca1 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -89,4 +89,4 @@ macro_rules! kernel_function { ($f:ident($($x:tt)*)) => {{ $f($($x)*) }}; -} \ No newline at end of file +} diff --git a/src/scheduler/mod.rs b/src/scheduler/mod.rs index a80fb164ca05b04e3fb25d86e8d675d961141046..90628c6de13a08f3bf2c18d0362d454785e0c97b 100644 --- a/src/scheduler/mod.rs +++ b/src/scheduler/mod.rs @@ -17,7 +17,6 @@ use core::convert::TryInto; use core::sync::atomic::{AtomicU32, Ordering}; use crossbeam_utils::Backoff; -use crate::{DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; use crate::arch; use crate::arch::irq; use crate::arch::mm::VirtAddr; @@ -28,6 +27,7 @@ use crate::config::*; use crate::kernel::scheduler::TaskStacks; use crate::scheduler::task::*; use crate::synch::spinlock::*; +use crate::{DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; pub mod task; diff --git a/src/syscalls/interfaces/mod.rs b/src/syscalls/interfaces/mod.rs index 9a60907604d4073ae73bba9c82a8c6f73ee0716f..29212671204f2c0750660cb5bc1e2ae588143662 100644 --- a/src/syscalls/interfaces/mod.rs +++ b/src/syscalls/interfaces/mod.rs @@ -115,67 +115,67 @@ pub trait SyscallInterface: Send + Sync { } fn get_mac_address(&self) -> Result<[u8; 6], ()> { - #[cfg(feature = "pci")] + #[cfg(all(feature = "pci", not(target_arch = "aarch64")))] match arch::kernel::pci::get_network_driver() { Some(driver) => Ok(driver.lock().get_mac_address()), _ => Err(()), } - #[cfg(not(feature = "pci"))] + #[cfg(not(all(feature = "pci", not(target_arch = "aarch64"))))] Err(()) } fn get_mtu(&self) -> Result<u16, ()> { - #[cfg(feature = "pci")] + #[cfg(all(feature = "pci", not(target_arch = "aarch64")))] match arch::kernel::pci::get_network_driver() { Some(driver) => Ok(driver.lock().get_mtu()), _ => Err(()), } - #[cfg(not(feature = "pci"))] + #[cfg(not(all(feature = "pci", not(target_arch = "aarch64"))))] Err(()) } fn has_packet(&self) -> bool { - #[cfg(feature = "pci")] + #[cfg(all(feature = "pci", not(target_arch = "aarch64")))] match arch::kernel::pci::get_network_driver() { Some(driver) => driver.lock().has_packet(), _ => false, } - #[cfg(not(feature = "pci"))] + #[cfg(not(all(feature = "pci", not(target_arch = "aarch64"))))] false } fn get_tx_buffer(&self, len: usize) -> Result<(*mut u8, usize), ()> { - #[cfg(feature = "pci")] + #[cfg(all(feature = "pci", not(target_arch = "aarch64")))] match arch::kernel::pci::get_network_driver() { Some(driver) => driver.lock().get_tx_buffer(len), _ => Err(()), } - #[cfg(not(feature = "pci"))] + #[cfg(not(all(feature = "pci", not(target_arch = "aarch64"))))] Err(()) } fn send_tx_buffer(&self, handle: usize, len: usize) -> Result<(), ()> { - #[cfg(feature = "pci")] + #[cfg(all(feature = "pci", not(target_arch = "aarch64")))] match arch::kernel::pci::get_network_driver() { Some(driver) => driver.lock().send_tx_buffer(handle, len), _ => Err(()), } - #[cfg(not(feature = "pci"))] + #[cfg(not(all(feature = "pci", not(target_arch = "aarch64"))))] Err(()) } fn receive_rx_buffer(&self) -> Result<(&'static [u8], usize), ()> { - #[cfg(feature = "pci")] + #[cfg(all(feature = "pci", not(target_arch = "aarch64")))] match arch::kernel::pci::get_network_driver() { Some(driver) => driver.lock().receive_rx_buffer(), _ => Err(()), } - #[cfg(not(feature = "pci"))] + #[cfg(not(all(feature = "pci", not(target_arch = "aarch64"))))] Err(()) } fn rx_buffer_consumed(&self, handle: usize) -> Result<(), ()> { - #[cfg(feature = "pci")] + #[cfg(all(feature = "pci", not(target_arch = "aarch64")))] match arch::kernel::pci::get_network_driver() { Some(driver) => { driver.lock().rx_buffer_consumed(handle); @@ -183,7 +183,7 @@ pub trait SyscallInterface: Send + Sync { } _ => Err(()), } - #[cfg(not(feature = "pci"))] + #[cfg(not(all(feature = "pci", not(target_arch = "aarch64"))))] Err(()) }