diff --git a/cache_utils/src/calibration.rs b/cache_utils/src/calibration.rs index a5cc81a..d26ce64 100644 --- a/cache_utils/src/calibration.rs +++ b/cache_utils/src/calibration.rs @@ -1,8 +1,8 @@ use crate::{flush, maccess, rdtsc_fence}; use polling_serial::serial_println; -use vga_buffer::println; extern crate alloc; +use alloc::vec; use alloc::vec::Vec; use core::cmp::min; @@ -13,32 +13,28 @@ use core::cmp::min; unsafe fn only_reload(p: *const u8) -> u64 { let t = rdtsc_fence(); maccess(p); - let d = rdtsc_fence() - t; - d + rdtsc_fence() - t } unsafe fn flush_and_reload(p: *const u8) -> u64 { flush(p); let t = rdtsc_fence(); maccess(p); - let d = rdtsc_fence() - t; - d + rdtsc_fence() - t } unsafe fn load_and_flush(p: *const u8) -> u64 { maccess(p); let t = rdtsc_fence(); flush(p); - let d = rdtsc_fence() - t; - d + rdtsc_fence() - t } unsafe fn flush_and_flush(p: *const u8) -> u64 { flush(p); let t = rdtsc_fence(); flush(p); - let d = rdtsc_fence() - t; - d + rdtsc_fence() - t } const BUCKET_SIZE: usize = 5; @@ -57,19 +53,13 @@ pub fn calibrate_access() -> u64 { // Histograms bucket of 5 and max at 400 cycles // Magic numbers to be justified // 80 is a size of screen - let mut hit_histogram = Vec::::with_capacity(BUCKET_NUMBER); - hit_histogram.resize(BUCKET_NUMBER, 0); + let mut hit_histogram = vec![0; BUCKET_NUMBER]; //Vec::::with_capacity(BUCKET_NUMBER); + //hit_histogram.resize(BUCKET_NUMBER, 0); let mut miss_histogram = hit_histogram.clone(); // the address in memory we are going to target let pointer = (&array[2048] as *const usize) as *const u8; - // sanity check - println!( - "&array[0]: {:p}, array[2048]{:p}", - (&array[0] as *const usize) as *const u8, - (&array[2048] as *const usize) as *const u8 - ); // do a large sample of accesses to a cached line unsafe { maccess(pointer) }; @@ -136,19 +126,12 @@ pub fn calibrate_flush() -> u64 { // Histograms bucket of 5 and max at 400 cycles // Magic numbers to be justified // 80 is a size of screen - let mut hit_histogram = Vec::::with_capacity(CFLUSH_BUCKET_NUMBER); - hit_histogram.resize(CFLUSH_BUCKET_NUMBER, 0); + let mut hit_histogram = vec![0; CFLUSH_BUCKET_NUMBER]; let mut miss_histogram = hit_histogram.clone(); // the address in memory we are going to target let pointer = (&array[2048] as *const usize) as *const u8; - // sanity check - println!( - "&array[0]: {:p}, array[2048]{:p}", - (&array[0] as *const usize) as *const u8, - (&array[2048] as *const usize) as *const u8 - ); // do a large sample of accesses to a cached line for _ in 0..(4 << 20) { diff --git a/cache_utils/src/lib.rs b/cache_utils/src/lib.rs index e7798da..ddc88a9 100644 --- a/cache_utils/src/lib.rs +++ b/cache_utils/src/lib.rs @@ -19,12 +19,12 @@ pub unsafe fn rdtsc_fence() -> u64 { tsc } -pub unsafe fn maccess(p: *const T) -> () { +pub unsafe fn maccess(p: *const T) { ptr::read_volatile(p); } // flush (cflush) -pub unsafe fn flush(p: *const u8) -> () { +pub unsafe fn flush(p: *const u8) { arch_x86::_mm_clflush(p); } diff --git a/polling_serial/src/lib.rs b/polling_serial/src/lib.rs index 95c9848..7cfbf83 100644 --- a/polling_serial/src/lib.rs +++ b/polling_serial/src/lib.rs @@ -46,7 +46,7 @@ const DISABLE_INTERRUPTS: u8 = 0x00; // const DLAB: u8 = 0x80; -const BASE_RATE: u32 = 115200; +const BASE_RATE: u32 = 115_200; const DIVISOR: u16 = 0x03; // The baud rate is 38400 diff --git a/src/allocator.rs b/src/allocator.rs index 81d58e3..5a4d4c1 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -6,7 +6,7 @@ use x86_64::{ }; pub const HEAP_START: usize = 0x4444_4444_0000; -pub const HEAP_SIZE: usize = 0x1 << 20; // 1MB Heap +pub const HEAP_SIZE: usize = 1 << 20; // 1MB Heap pub fn init_heap( mapper: &mut impl Mapper, diff --git a/src/main.rs b/src/main.rs index a276038..2759eff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,13 +9,10 @@ extern crate alloc; use bootloader::{entry_point, BootInfo}; -use cache_utils; use core::panic::PanicInfo; use dendrobates_tinctoreus_azureus::allocator; use polling_serial::serial_println; -use vga_buffer; // required for custom panic handler -use vga_buffer::{print, println}; -use x86_64; +use vga_buffer::println; use core::cmp::Ord; use core::ops::Sub; @@ -23,8 +20,17 @@ use core::ops::Sub; #[cfg(not(test))] use dendrobates_tinctoreus_azureus::hlt_loop; +use bootloader::bootinfo::MemoryRegionType::{InUse, Usable}; +use bootloader::bootinfo::{FrameRange, MemoryMap, MemoryRegion}; +use dendrobates_tinctoreus_azureus::memory; #[cfg(not(test))] use vga_buffer::{set_colors, Color, ForegroundColor}; +use x86_64::structures::paging::frame::PhysFrameRange; +use x86_64::structures::paging::{ + Mapper, Page, PageSize, PageTableFlags, PhysFrame, Size4KiB, UnusedPhysFrame, +}; +use x86_64::PhysAddr; +use x86_64::VirtAddr; // Custom panic handler, required for freestanding program #[cfg(not(test))] @@ -104,12 +110,6 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { cache_utils::prefetcher::prefetcher_status() ); - print!("Testing reverse range:"); - for i in (0..2).rev() { - print!(" {}", i); - } - println!(); - let threshold_access_p = cache_utils::calibration::calibrate_access(); let threshold_flush_p = cache_utils::calibration::calibrate_flush(); cache_utils::prefetcher::enable_prefetchers(false); diff --git a/src/memory.rs b/src/memory.rs index 93bfcaa..524668b 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -55,7 +55,7 @@ pub fn create_example_mapping( /// A FrameAllocator that returns usable frames from the bootloader's memory map. pub struct BootInfoFrameAllocator { - memory_map: &'static MemoryMap, + memory_map: MemoryMap, next: usize, } @@ -65,14 +65,14 @@ impl BootInfoFrameAllocator { /// This function is unsafe because the caller must guarantee that the passed /// memory map is valid. The main requirement is that all frames that are marked /// as `USABLE` in it are really unused. - pub unsafe fn init(memory_map: &'static MemoryMap) -> Self { + pub unsafe fn init(memory_map: MemoryMap) -> Self { BootInfoFrameAllocator { memory_map, next: 0, } } - fn usable_frames(&self) -> impl Iterator { + fn usable_frames(&self) -> impl Iterator + '_ { // get usable regions from memory map let regions = self.memory_map.iter(); let usable_regions = regions.filter(|r| r.region_type == MemoryRegionType::Usable); @@ -81,8 +81,7 @@ impl BootInfoFrameAllocator { // transform to an iterator of frame start addresses let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096)); // TODO Magic number, this is where 4k pages are enforced // create `PhysFrame` types from the start addresses - let frames = frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr))); - frames + frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr))) } }