diff --git a/src/arch/x86_64/driver/acpi/mod.rs b/src/arch/x86_64/driver/acpi/mod.rs index a68a2be..d8752af 100644 --- a/src/arch/x86_64/driver/acpi/mod.rs +++ b/src/arch/x86_64/driver/acpi/mod.rs @@ -4,23 +4,23 @@ mod structs; use self::structs::*; use consts::*; -pub fn init() -> Result { +pub fn init() -> Result { let rsdp = find_rsdp().expect("acpi: rsdp not found."); - if rsdp.RsdtPhysicalAddress > PHYSICAL_MEMORY_LIMIT { - return Err(ACPI_Error::NotMapped); + if rsdp.rsdt_physical_address > PHYSICAL_MEMORY_LIMIT { + return Err(AcpiError::NotMapped); } - debug!("RSDT at {:#x}", rsdp.RsdtPhysicalAddress); - let rsdt = unsafe{ &*(rsdp.RsdtPhysicalAddress as *const rsdt) }; - let mut madt: Option<&'static madt> = None; + debug!("RSDT at {:#x}", rsdp.rsdt_physical_address); + let rsdt = unsafe{ &*(rsdp.rsdt_physical_address as *const Rsdt) }; + let mut madt: Option<&'static Madt> = None; for i in 0 .. rsdt.entry_count() { let entry = rsdt.entry_at(i); if entry > PHYSICAL_MEMORY_LIMIT { - return Err(ACPI_Error::NotMapped); + return Err(AcpiError::NotMapped); } - let header = unsafe{ &*(entry as *const header) }; + let header = unsafe{ &*(entry as *const Header) }; // debug!("{:?}", header); - if &header.Signature == b"APIC" { - madt = Some(unsafe{ &*(entry as *const madt) }); + if &header.signature == b"APIC" { + madt = Some(unsafe{ &*(entry as *const Madt) }); } } debug!("{:?}", madt); @@ -33,7 +33,7 @@ const PHYSICAL_MEMORY_LIMIT: u32 = 0x0E000000; const PHYSICAL_MEMORY_LIMIT: u32 = 0x80000000; #[derive(Debug)] -pub struct ACPI_Result { +pub struct AcpiResult { pub cpu_num: u8, pub cpu_acpi_ids: [u8; MAX_CPU_NUM], pub ioapic_id: u8, @@ -41,13 +41,13 @@ pub struct ACPI_Result { } #[derive(Debug)] -pub enum ACPI_Error { +pub enum AcpiError { NotMapped, - IOACPI_NotFound, + IoacpiNotFound, } -fn config_smp(madt: &'static madt) -> Result { - let lapic_addr = madt.LapicAddress as *const (); +fn config_smp(madt: &'static Madt) -> Result { + let lapic_addr = madt.lapic_address as *const (); let mut cpu_num = 0u8; let mut cpu_acpi_ids: [u8; MAX_CPU_NUM] = [0; MAX_CPU_NUM]; @@ -56,33 +56,33 @@ fn config_smp(madt: &'static madt) -> Result { debug!("{:?}", entry); match &entry { &MadtEntry::LocalApic(ref lapic) => { - cpu_acpi_ids[cpu_num as usize] = lapic.Id; + cpu_acpi_ids[cpu_num as usize] = lapic.id; cpu_num += 1; }, &MadtEntry::IoApic(ref ioapic) => { - ioapic_id = Some(ioapic.Id); + ioapic_id = Some(ioapic.id); }, _ => {}, } } if ioapic_id.is_none() { - return Err(ACPI_Error::IOACPI_NotFound); + return Err(AcpiError::IoacpiNotFound); } let ioapic_id = ioapic_id.unwrap(); - Ok(ACPI_Result { cpu_num, cpu_acpi_ids, ioapic_id, lapic_addr }) + Ok(AcpiResult { cpu_num, cpu_acpi_ids, ioapic_id, lapic_addr }) } /// See https://wiki.osdev.org/RSDP -- Detecting the RSDP -fn find_rsdp() -> Option<&'static rsdp> { +fn find_rsdp() -> Option<&'static Rsdp> { use util::{Checkable, find_in_memory}; let ebda = unsafe { *(0x40E as *const u16) as usize } << 4; debug!("EBDA at {:#x}", ebda); macro_rules! return_if_find_in { ($begin:expr, $end:expr) => ( - if let Some(addr) = unsafe{ find_in_memory::($begin, $end, 4) } { - return Some(unsafe{ &*(addr as *const rsdp) }); + if let Some(addr) = unsafe{ find_in_memory::($begin, $end, 4) } { + return Some(unsafe{ &*(addr as *const Rsdp) }); } ) } diff --git a/src/arch/x86_64/driver/acpi/structs.rs b/src/arch/x86_64/driver/acpi/structs.rs index 0ec80cf..de38829 100644 --- a/src/arch/x86_64/driver/acpi/structs.rs +++ b/src/arch/x86_64/driver/acpi/structs.rs @@ -6,48 +6,48 @@ use core::mem::size_of; #[repr(C)] #[derive(Debug)] -pub struct rsdp { - pub Signature: [u8; 8], - pub Checksum: u8, - pub OemId: [i8; 6], - pub Revision: u8, - pub RsdtPhysicalAddress: u32, - pub Length: u32, - pub XsdtPhysicalAddress: u64, - pub ExtendedChecksum: u8, - pub Reserved: [u8; 3], +pub struct Rsdp { + pub signature: [u8; 8], + pub checksum: u8, + pub oem_id: [i8; 6], + pub revision: u8, + pub rsdt_physical_address: u32, + pub length: u32, + pub xsdt_physical_address: u64, + pub extended_checksum: u8, + pub reserved: [u8; 3], } -impl Checkable for rsdp { +impl Checkable for Rsdp { fn check(&self) -> bool { - &self.Signature == b"RSD PTR " && bytes_sum(self) == 0 + &self.signature == b"RSD PTR " && bytes_sum(self) == 0 } } #[repr(C)] #[derive(Debug)] -pub struct header { - pub Signature: [u8; 4], - pub Length: u32, - pub Revision: u8, - pub Checksum: u8, - pub OemId: [i8; 6], - pub OemTableId: [i8; 8], - pub OemRevision: u32, - pub AslCompilerId: [i8; 4], - pub AslCompilerRevision: u32, +pub struct Header { + pub signature: [u8; 4], + pub length: u32, + pub revision: u8, + pub checksum: u8, + pub oem_id: [i8; 6], + pub oem_table_id: [i8; 8], + pub oem_revision: u32, + pub asl_compiler_id: [i8; 4], + pub asl_compiler_revision: u32, } #[repr(C)] #[derive(Debug)] -pub struct rsdt { - pub Header: header, - TableOffsetEntry: [u32; 0], +pub struct Rsdt { + pub header: Header, + table_offset_entry: [u32; 0], } -impl rsdt { +impl Rsdt { pub fn entry_count(&self) -> usize { - (self.Header.Length as usize - size_of::()) / 4 + (self.header.length as usize - size_of::()) / 4 } pub fn entry_at(&self, id: usize) -> u32 { assert!(id < self.entry_count()); @@ -60,62 +60,62 @@ impl rsdt { #[repr(C)] #[derive(Debug)] -pub struct madt { - pub Header: header, - pub LapicAddress: u32, - pub Flags: u32, - Table: [u32; 0], +pub struct Madt { + pub header: Header, + pub lapic_address: u32, + pub flags: u32, + table: [u32; 0], } -impl Checkable for madt { +impl Checkable for Madt { fn check(&self) -> bool { - &self.Header.Signature == b"APIC" && self.Header.Length >= size_of::() as u32 + &self.header.signature == b"APIC" && self.header.length >= size_of::() as u32 } } #[derive(Debug)] pub enum MadtEntry { - Unknown(MadtEntry_Unknown), - LocalApic(MadtEntry_LocalApic), - IoApic(MadtEntry_IoApic), + Unknown(MadtEntryUnknown), + LocalApic(MadtEntryLocalApic), + IoApic(MadtEntryIoApic), } #[repr(C)] #[derive(Debug, Clone)] -pub struct MadtEntry_Unknown { - pub Type: u8, - pub Length: u8, +pub struct MadtEntryUnknown { + pub type_: u8, + pub length: u8, } #[repr(C)] #[derive(Debug, Clone)] -pub struct MadtEntry_LocalApic { - pub Type: u8, // 0 - pub Length: u8, - pub ProcessorId: u8, - pub Id: u8, - pub LapicFlags: u32, +pub struct MadtEntryLocalApic { + pub type_: u8, // 0 + pub length: u8, + pub processor_id: u8, + pub id: u8, + pub lapic_flags: u32, } #[repr(C)] #[derive(Debug, Clone)] -pub struct MadtEntry_IoApic { - pub Type: u8, // 1 - pub Length: u8, - pub Id: u8, - pub Reserved: u8, - pub Address: u32, - pub GlobalIrqBase: u32, +pub struct MadtEntryIoApic { + pub type_: u8, // 1 + pub length: u8, + pub id: u8, + pub reserved: u8, + pub address: u32, + pub global_irq_base: u32, } #[derive(Debug)] pub struct MadtEntryIter<'a> { - madt: &'a madt, + madt: &'a Madt, ptr: *const u8, end_ptr: *const u8, } -impl madt { +impl Madt { pub fn entry_iter(&self) -> MadtEntryIter { let ptr = unsafe{ (self as *const Self).offset(1) } as *const u8; - let end_ptr = unsafe{ ptr.offset(self.Header.Length as isize) }; + let end_ptr = unsafe{ ptr.offset(self.header.length as isize) }; MadtEntryIter { madt: self, ptr, end_ptr } } } @@ -127,12 +127,12 @@ impl<'a> Iterator for MadtEntryIter<'a> { return None; } unsafe { - let typeId = *self.ptr.offset(0); + let type_id = *self.ptr.offset(0); let len = *self.ptr.offset(1); - let ret = Some(match typeId { - 0 => MadtEntry::LocalApic( (&*(self.ptr as *const MadtEntry_LocalApic)).clone() ), - 1 => MadtEntry::IoApic( (&*(self.ptr as *const MadtEntry_IoApic)).clone() ), - _ => MadtEntry::Unknown( (&*(self.ptr as *const MadtEntry_Unknown)).clone() ), + let ret = Some(match type_id { + 0 => MadtEntry::LocalApic( (&*(self.ptr as *const MadtEntryLocalApic)).clone() ), + 1 => MadtEntry::IoApic( (&*(self.ptr as *const MadtEntryIoApic)).clone() ), + _ => MadtEntry::Unknown( (&*(self.ptr as *const MadtEntryUnknown)).clone() ), }); self.ptr = self.ptr.offset(len as isize); ret diff --git a/src/arch/x86_64/driver/apic/lapic.rs b/src/arch/x86_64/driver/apic/lapic.rs index 51f1d46..83aa7e6 100644 --- a/src/arch/x86_64/driver/apic/lapic.rs +++ b/src/arch/x86_64/driver/apic/lapic.rs @@ -1,4 +1,5 @@ extern { + //noinspection RsStaticConstNaming static mut lapic: *const (); fn lapicinit(); // must set `lapic` first fn lapiceoi(); // ack diff --git a/src/arch/x86_64/driver/apic/local_apic.rs b/src/arch/x86_64/driver/apic/local_apic.rs index 0b5c175..edb228b 100644 --- a/src/arch/x86_64/driver/apic/local_apic.rs +++ b/src/arch/x86_64/driver/apic/local_apic.rs @@ -3,7 +3,7 @@ use x86::cpuid::CpuId; use x86::msr::*; use memory::Frame; -use paging::{ActivePageTable, PhysicalAddress, Page, VirtualAddress}; +use paging::{ActivePageTable, PhysAddr, Page, VirtualAddress}; use paging::entry::EntryFlags; pub static mut LOCAL_APIC: LocalApic = LocalApic { @@ -32,7 +32,7 @@ impl LocalApic { if ! self.x2 { let page = Page::containing_address(VirtualAddress::new(self.address)); - let frame = Frame::containing_address(PhysicalAddress::new(self.address - ::KERNEL_OFFSET)); + let frame = Frame::containing_address(PhysAddr::new(self.address - ::KERNEL_OFFSET)); let result = active_table.map_to(page, frame, EntryFlags::PRESENT | EntryFlags::WRITABLE | EntryFlags::NO_EXECUTE); result.flush(active_table); } diff --git a/src/arch/x86_64/driver/mod.rs b/src/arch/x86_64/driver/mod.rs index a6cf151..708b326 100644 --- a/src/arch/x86_64/driver/mod.rs +++ b/src/arch/x86_64/driver/mod.rs @@ -7,7 +7,7 @@ pub mod pic; pub mod keyboard; pub mod pit; -pub fn init(mut page_map: F) -> acpi::ACPI_Result +pub fn init(mut page_map: F) -> acpi::AcpiResult where F: FnMut(usize) { assert_has_not_been_called!(); diff --git a/src/arch/x86_64/paging/entry.rs b/src/arch/x86_64/paging/entry.rs index 8f1edf1..813f567 100644 --- a/src/arch/x86_64/paging/entry.rs +++ b/src/arch/x86_64/paging/entry.rs @@ -18,7 +18,7 @@ impl Entry { pub fn pointed_frame(&self) -> Option { if self.flags().contains(EntryFlags::PRESENT) { - Some(Frame::containing_address( + Some(Frame::of_addr( self.0 as usize & 0x000fffff_fffff000 )) } else { @@ -27,7 +27,7 @@ impl Entry { } pub fn set(&mut self, frame: Frame, flags: EntryFlags) { - assert!(frame.start_address().0 & !0x000fffff_fffff000 == 0); + assert_eq!(frame.start_address().0 & !0x000fffff_fffff000, 0); self.0 = (frame.start_address().0) | flags.bits(); } } diff --git a/src/arch/x86_64/paging/mapper.rs b/src/arch/x86_64/paging/mapper.rs index d9a394c..3524638 100644 --- a/src/arch/x86_64/paging/mapper.rs +++ b/src/arch/x86_64/paging/mapper.rs @@ -22,10 +22,10 @@ impl Mapper { unsafe { self.p4.as_mut() } } - pub fn translate(&self, virtual_address: VirtualAddress) -> Option { + pub fn translate(&self, virtual_address: VirtAddr) -> Option { let offset = virtual_address % PAGE_SIZE; - self.translate_page(Page::containing_address(virtual_address)) - .map(|frame| PhysicalAddress((frame.start_address().get() + offset) as u64)) + self.translate_page(Page::of_addr(virtual_address)) + .map(|frame| PhysAddr((frame.start_address().get() + offset) as u64)) } pub fn translate_page(&self, page: Page) -> Option { @@ -38,8 +38,8 @@ impl Mapper { if let Some(start_frame) = p3_entry.pointed_frame() { if p3_entry.flags().contains(EntryFlags::HUGE_PAGE) { // address must be 1GiB aligned - assert!(start_frame.start_address().get() % (ENTRY_COUNT * ENTRY_COUNT * PAGE_SIZE) == 0); - return Some(Frame::containing_address( + assert_eq!(start_frame.start_address().get() % (ENTRY_COUNT * ENTRY_COUNT * PAGE_SIZE), 0); + return Some(Frame::of_addr( start_frame.start_address().get() + (page.p2_index() * ENTRY_COUNT + page.p1_index()) * PAGE_SIZE )); @@ -51,8 +51,8 @@ impl Mapper { if let Some(start_frame) = p2_entry.pointed_frame() { if p2_entry.flags().contains(EntryFlags::HUGE_PAGE) { // address must be 2MiB aligned - assert!(start_frame.start_address().get() % ENTRY_COUNT == 0); - return Some(Frame::containing_address( + assert_eq!(start_frame.start_address().get() % ENTRY_COUNT, 0); + return Some(Frame::of_addr( start_frame.start_address().get() + page.p1_index() * PAGE_SIZE )); } @@ -91,7 +91,7 @@ impl Mapper { pub fn identity_map(&mut self, frame: Frame, flags: EntryFlags, allocator: &mut A) where A: FrameAllocator { - let page = Page::containing_address(frame.start_address().to_identity_virtual()); + let page = Page::of_addr(frame.start_address().to_identity_virtual()); self.map_to(page, frame, flags, allocator) } diff --git a/src/arch/x86_64/paging/mod.rs b/src/arch/x86_64/paging/mod.rs index f913067..ebfc8fa 100644 --- a/src/arch/x86_64/paging/mod.rs +++ b/src/arch/x86_64/paging/mod.rs @@ -17,7 +17,7 @@ pub struct Page { } impl Page { - pub fn containing_address(address: VirtualAddress) -> Page { + pub fn of_addr(address: VirtAddr) -> Page { assert!(address < 0x0000_8000_0000_0000 || address >= 0xffff_8000_0000_0000, "invalid address: 0x{:x}", address); @@ -43,8 +43,8 @@ impl Page { pub fn range_inclusive(start: Page, end: Page) -> PageIter { PageIter { - start: start, - end: end, + start, + end, } } } @@ -113,7 +113,7 @@ impl ActivePageTable { use x86_64::registers::control_regs; { - let backup = Frame::containing_address( + let backup = Frame::of_addr( control_regs::cr3().0 as usize); // map temporary_page to current p4 table @@ -139,7 +139,7 @@ impl ActivePageTable { use x86_64::registers::control_regs; let old_table = InactivePageTable { - p4_frame: Frame::containing_address( + p4_frame: Frame::of_addr( control_regs::cr3().0 as usize ), }; diff --git a/src/arch/x86_64/paging/temporary_page.rs b/src/arch/x86_64/paging/temporary_page.rs index 4ba6a9a..e884fe1 100644 --- a/src/arch/x86_64/paging/temporary_page.rs +++ b/src/arch/x86_64/paging/temporary_page.rs @@ -1,6 +1,6 @@ use super::{Page, ActivePageTable}; use super::table::{Table, Level1}; -use memory::{Frame, FrameAllocator, VirtualAddress}; +use memory::{Frame, FrameAllocator, VirtAddr}; pub struct TemporaryPage { page: Page, @@ -12,7 +12,7 @@ impl TemporaryPage { where A: FrameAllocator { TemporaryPage { - page: page, + page, allocator: TinyAllocator::new(allocator), } } @@ -20,7 +20,7 @@ impl TemporaryPage { /// Maps the temporary page to the given frame in the active table. /// Returns the start address of the temporary page. pub fn map(&mut self, frame: Frame, active_table: &mut ActivePageTable) - -> VirtualAddress + -> VirtAddr { use super::entry::EntryFlags; diff --git a/src/arch/x86_64/smp.rs b/src/arch/x86_64/smp.rs index 3bc2af0..707174c 100644 --- a/src/arch/x86_64/smp.rs +++ b/src/arch/x86_64/smp.rs @@ -1,5 +1,5 @@ -use arch::driver::{acpi::ACPI_Result, apic::start_ap}; -use memory::{MemoryController, PhysicalAddress}; +use arch::driver::{acpi::AcpiResult, apic::start_ap}; +use memory::{MemoryController, PhysAddr}; extern { fn entryother_start(); // physical addr of entryother @@ -8,11 +8,11 @@ extern { const ENTRYOTHER_ADDR: u32 = 0x7000; -pub fn start_other_cores(acpi: &ACPI_Result, mc: &mut MemoryController) { +pub fn start_other_cores(acpi: &AcpiResult, mc: &mut MemoryController) { mc.map_page_identity(ENTRYOTHER_ADDR as usize - 1); mc.map_page_identity(ENTRYOTHER_ADDR as usize); mc.map_page_identity(entryother_start as usize); - mc.map_page_p2v(PhysicalAddress(0)); + mc.map_page_p2v(PhysAddr(0)); copy_entryother(); let args = unsafe{ &mut *(ENTRYOTHER_ADDR as *mut EntryArgs).offset(-1) }; @@ -21,7 +21,7 @@ pub fn start_other_cores(acpi: &ACPI_Result, mc: &mut MemoryController) { let apic_id = acpi.cpu_acpi_ids[i as usize]; *args = EntryArgs { kstack: mc.alloc_stack(7).unwrap().top() as u64, - page_table: page_table, + page_table, stack: 0x8000, // just enough stack to get us to entry64mp }; start_ap(apic_id, ENTRYOTHER_ADDR); diff --git a/src/consts.rs b/src/consts.rs index 19f5cb3..74026b0 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] pub const MAX_CPU_NUM: usize = 8; // Copy from Redox consts.rs: diff --git a/src/io/vga_writer.rs b/src/io/vga_writer.rs index 034b994..23b966e 100644 --- a/src/io/vga_writer.rs +++ b/src/io/vga_writer.rs @@ -21,7 +21,7 @@ impl VgaWriter { VgaWriter { column_position: 0, color: Color::LightGray, - buffer: buffer, + buffer, } } diff --git a/src/memory/address.rs b/src/memory/address.rs index 153b189..e575b5e 100644 --- a/src/memory/address.rs +++ b/src/memory/address.rs @@ -1,27 +1,27 @@ use consts::{KERNEL_OFFSET, KERNEL_SIZE}; -pub use x86_64::{PhysicalAddress}; -pub type VirtualAddress = usize; +pub use x86_64::PhysicalAddress as PhysAddr; +pub type VirtAddr = usize; pub trait FromToVirtualAddress { fn get(&self) -> usize; - fn to_identity_virtual(&self) -> VirtualAddress; - fn to_kernel_virtual(&self) -> VirtualAddress; - fn from_kernel_virtual(addr: VirtualAddress) -> Self; + fn to_identity_virtual(&self) -> VirtAddr; + fn to_kernel_virtual(&self) -> VirtAddr; + fn from_kernel_virtual(addr: VirtAddr) -> Self; } -impl FromToVirtualAddress for PhysicalAddress { +impl FromToVirtualAddress for PhysAddr { fn get(&self) -> usize { self.0 as usize } - fn to_identity_virtual(&self) -> VirtualAddress { + fn to_identity_virtual(&self) -> VirtAddr { self.0 as usize } - fn to_kernel_virtual(&self) -> VirtualAddress { + fn to_kernel_virtual(&self) -> VirtAddr { assert!((self.0 as usize) < KERNEL_SIZE); self.0 as usize + KERNEL_OFFSET } - fn from_kernel_virtual(addr: VirtualAddress) -> Self { + fn from_kernel_virtual(addr: VirtAddr) -> Self { assert!(addr >= KERNEL_OFFSET && addr < KERNEL_OFFSET + KERNEL_SIZE); - PhysicalAddress((addr - KERNEL_OFFSET) as u64) + PhysAddr((addr - KERNEL_OFFSET) as u64) } } \ No newline at end of file diff --git a/src/memory/area_frame_allocator.rs b/src/memory/area_frame_allocator.rs index d0e3824..bba943c 100644 --- a/src/memory/area_frame_allocator.rs +++ b/src/memory/area_frame_allocator.rs @@ -1,4 +1,4 @@ -use memory::{Frame, FrameAllocator, PhysicalAddress}; +use memory::{Frame, FrameAllocator, PhysAddr}; use multiboot2::{MemoryAreaIter, MemoryArea}; pub struct AreaFrameAllocator { @@ -21,7 +21,7 @@ impl FrameAllocator for AreaFrameAllocator { // the last frame of the current area let current_area_last_frame = { let address = area.base_addr + area.length - 1; - Frame::containing_address(address as usize) + Frame::of_addr(address as usize) }; if frame > current_area_last_frame { @@ -55,18 +55,18 @@ impl FrameAllocator for AreaFrameAllocator { } impl AreaFrameAllocator { - pub fn new(kernel_start: PhysicalAddress, kernel_end: PhysicalAddress, - multiboot_start: PhysicalAddress, multiboot_end: PhysicalAddress, - memory_areas: MemoryAreaIter) -> AreaFrameAllocator + pub fn new(kernel_start: PhysAddr, kernel_end: PhysAddr, + multiboot_start: PhysAddr, multiboot_end: PhysAddr, + memory_areas: MemoryAreaIter) -> AreaFrameAllocator { let mut allocator = AreaFrameAllocator { - next_free_frame: Frame::containing_address(0), + next_free_frame: Frame::of_addr(0), current_area: None, areas: memory_areas, - kernel_start: Frame::containing_address(kernel_start.0 as usize), - kernel_end: Frame::containing_address(kernel_end.0 as usize), - multiboot_start: Frame::containing_address(multiboot_start.0 as usize), - multiboot_end: Frame::containing_address(multiboot_end.0 as usize), + kernel_start: Frame::of_addr(kernel_start.0 as usize), + kernel_end: Frame::of_addr(kernel_end.0 as usize), + multiboot_start: Frame::of_addr(multiboot_start.0 as usize), + multiboot_end: Frame::of_addr(multiboot_end.0 as usize), }; allocator.choose_next_area(); allocator @@ -75,11 +75,11 @@ impl AreaFrameAllocator { fn choose_next_area(&mut self) { self.current_area = self.areas.clone().filter(|area| { let address = area.base_addr + area.length - 1; - Frame::containing_address(address as usize) >= self.next_free_frame + Frame::of_addr(address as usize) >= self.next_free_frame }).min_by_key(|area| area.base_addr); if let Some(area) = self.current_area { - let start_frame = Frame::containing_address(area.base_addr as usize); + let start_frame = Frame::of_addr(area.base_addr as usize); if self.next_free_frame < start_frame { self.next_free_frame = start_frame; } diff --git a/src/memory/frame.rs b/src/memory/frame.rs index 6b9be48..746dea5 100644 --- a/src/memory/frame.rs +++ b/src/memory/frame.rs @@ -1,4 +1,4 @@ -use super::address::PhysicalAddress; +use super::address::PhysAddr; pub const PAGE_SIZE: usize = 4096; @@ -8,12 +8,12 @@ pub struct Frame { } impl Frame { - pub fn containing_address(address: usize) -> Frame { + pub fn of_addr(address: usize) -> Frame { Frame{ number: address / PAGE_SIZE } } //TODO: Set private - pub fn start_address(&self) -> PhysicalAddress { - PhysicalAddress((self.number * PAGE_SIZE) as u64) + pub fn start_address(&self) -> PhysAddr { + PhysAddr((self.number * PAGE_SIZE) as u64) } pub fn clone(&self) -> Frame { @@ -22,8 +22,8 @@ impl Frame { //TODO: Set private pub fn range_inclusive(start: Frame, end: Frame) -> FrameIter { FrameIter { - start: start, - end: end, + start, + end, } } } diff --git a/src/memory/mod.rs b/src/memory/mod.rs index d039ddb..9886d14 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -22,13 +22,13 @@ pub fn init(boot_info: &BootInformation) -> MemoryController { let elf_sections_tag = boot_info.elf_sections_tag().expect( "Elf sections tag required"); - let kernel_start = PhysicalAddress(elf_sections_tag.sections() + let kernel_start = PhysAddr(elf_sections_tag.sections() .filter(|s| s.is_allocated()).map(|s| s.start_address()).min().unwrap() as u64); - let kernel_end = PhysicalAddress::from_kernel_virtual(elf_sections_tag.sections() + let kernel_end = PhysAddr::from_kernel_virtual(elf_sections_tag.sections() .filter(|s| s.is_allocated()).map(|s| s.end_address()).max().unwrap()); - let boot_info_start = PhysicalAddress(boot_info.start_address() as u64); - let boot_info_end = PhysicalAddress(boot_info.end_address() as u64); + let boot_info_start = PhysAddr(boot_info.start_address() as u64); + let boot_info_end = PhysAddr(boot_info.end_address() as u64); println!("kernel start: {:#x}, kernel end: {:#x}", kernel_start, @@ -51,8 +51,8 @@ pub fn init(boot_info: &BootInformation) -> MemoryController { use self::paging::Page; use consts::{KERNEL_HEAP_OFFSET, KERNEL_HEAP_SIZE}; - let heap_start_page = Page::containing_address(KERNEL_HEAP_OFFSET); - let heap_end_page = Page::containing_address(KERNEL_HEAP_OFFSET + KERNEL_HEAP_SIZE-1); + let heap_start_page = Page::of_addr(KERNEL_HEAP_OFFSET); + let heap_end_page = Page::of_addr(KERNEL_HEAP_OFFSET + KERNEL_HEAP_SIZE-1); for page in Page::range_inclusive(heap_start_page, heap_end_page) { active_table.map(page, EntryFlags::WRITABLE, &mut frame_allocator); @@ -67,9 +67,9 @@ pub fn init(boot_info: &BootInformation) -> MemoryController { }; MemoryController { - active_table: active_table, - frame_allocator: frame_allocator, - stack_allocator: stack_allocator, + active_table, + frame_allocator, + stack_allocator, } } @@ -77,7 +77,7 @@ pub fn remap_the_kernel(allocator: &mut A, boot_info: &BootInformation) -> ActivePageTable where A: FrameAllocator { - let mut temporary_page = TemporaryPage::new(Page::containing_address(0xcafebabe), allocator); + let mut temporary_page = TemporaryPage::new(Page::of_addr(0xcafebabe), allocator); let mut active_table = unsafe { ActivePageTable::new() }; let mut new_table = { @@ -94,8 +94,7 @@ pub fn remap_the_kernel(allocator: &mut A, boot_info: &BootInformation) // section is not loaded to memory continue; } - assert!(section.start_address() % PAGE_SIZE == 0, - "sections need to be page aligned"); + assert_eq!(section.start_address() % PAGE_SIZE, 0, "sections need to be page aligned"); println!("mapping section at addr: {:#x}, size: {:#x}", section.addr, section.size); @@ -103,7 +102,7 @@ pub fn remap_the_kernel(allocator: &mut A, boot_info: &BootInformation) let flags = EntryFlags::from_elf_section_flags(section); fn to_physical_frame(addr: usize) -> Frame { - Frame::containing_address( + Frame::of_addr( if addr < KERNEL_OFFSET { addr } else { addr - KERNEL_OFFSET }) } @@ -112,18 +111,18 @@ pub fn remap_the_kernel(allocator: &mut A, boot_info: &BootInformation) let end_frame = to_physical_frame(section.end_address() - 1); for frame in Frame::range_inclusive(start_frame, end_frame) { - let page = Page::containing_address(frame.start_address().to_kernel_virtual()); + let page = Page::of_addr(frame.start_address().to_kernel_virtual()); mapper.map_to(page, frame, flags, allocator); } } // identity map the VGA text buffer - let vga_buffer_frame = Frame::containing_address(0xb8000); + let vga_buffer_frame = Frame::of_addr(0xb8000); mapper.identity_map(vga_buffer_frame, EntryFlags::WRITABLE, allocator); // identity map the multiboot info structure - let multiboot_start = Frame::containing_address(boot_info.start_address()); - let multiboot_end = Frame::containing_address(boot_info.end_address() - 1); + let multiboot_start = Frame::of_addr(boot_info.start_address()); + let multiboot_end = Frame::of_addr(boot_info.end_address() - 1); for frame in Frame::range_inclusive(multiboot_start, multiboot_end) { mapper.identity_map(frame, EntryFlags::PRESENT, allocator); } @@ -134,8 +133,8 @@ pub fn remap_the_kernel(allocator: &mut A, boot_info: &BootInformation) // turn the stack bottom into a guard page extern { fn stack_bottom(); } - let stack_bottom = PhysicalAddress(stack_bottom as u64).to_kernel_virtual(); - let stack_bottom_page = Page::containing_address(stack_bottom); + let stack_bottom = PhysAddr(stack_bottom as u64).to_kernel_virtual(); + let stack_bottom_page = Page::of_addr(stack_bottom); active_table.unmap(stack_bottom_page, allocator); println!("guard page at {:#x}", stack_bottom_page.start_address()); @@ -157,13 +156,13 @@ impl MemoryController { size_in_pages) } pub fn map_page_identity(&mut self, addr: usize) { - let frame = Frame::containing_address(addr); + let frame = Frame::of_addr(addr); let flags = EntryFlags::WRITABLE; self.active_table.identity_map(frame, flags, &mut self.frame_allocator); } - pub fn map_page_p2v(&mut self, addr: PhysicalAddress) { - let page = Page::containing_address(addr.to_kernel_virtual()); - let frame = Frame::containing_address(addr.get()); + pub fn map_page_p2v(&mut self, addr: PhysAddr) { + let page = Page::of_addr(addr.to_kernel_virtual()); + let frame = Frame::of_addr(addr.get()); let flags = EntryFlags::WRITABLE; self.active_table.map_to(page, frame, flags, &mut self.frame_allocator); } diff --git a/src/memory/stack_allocator.rs b/src/memory/stack_allocator.rs index 7249874..02c864c 100644 --- a/src/memory/stack_allocator.rs +++ b/src/memory/stack_allocator.rs @@ -64,8 +64,8 @@ impl Stack { fn new(top: usize, bottom: usize) -> Stack { assert!(top > bottom); Stack { - top: top, - bottom: bottom, + top, + bottom, } }