Code cleanup - make clippy happier

This commit is contained in:
guillaume didier 2020-02-04 12:00:03 +01:00
parent 0a4fb34d32
commit 45f4ac5ef9
4 changed files with 11 additions and 21 deletions

View File

@ -8,15 +8,17 @@ extern crate alloc;
use alloc::vec::Vec; use alloc::vec::Vec;
use core::arch::x86_64 as arch_x86; use core::arch::x86_64 as arch_x86;
use polling_serial::serial_println;
use vga_buffer::println; pub mod prefetcher;
const CACHE_INFO_CPUID_LEAF: u32 = 0x4;
pub fn get_cache_info() -> Vec<CacheInfo> { pub fn get_cache_info() -> Vec<CacheInfo> {
let mut ret = Vec::new(); let mut ret = Vec::new();
let mut i = 0; let mut i = 0;
while let Some(cache_info) = while let Some(cache_info) =
CacheInfo::fromCpuidResult(&unsafe { arch_x86::__cpuid_count(0x04, i) }) CacheInfo::from_cpuid_result(&unsafe { arch_x86::__cpuid_count(CACHE_INFO_CPUID_LEAF, i) })
{ {
ret.push(cache_info); ret.push(cache_info);
i += 1; i += 1;
@ -51,7 +53,7 @@ pub struct CacheInfo {
} }
impl CacheInfo { impl CacheInfo {
pub fn fromCpuidResult(cr: &arch_x86::CpuidResult) -> Option<CacheInfo> { pub fn from_cpuid_result(cr: &arch_x86::CpuidResult) -> Option<CacheInfo> {
let ctype = cr.eax & 0x1f; let ctype = cr.eax & 0x1f;
let cache_type = match ctype { let cache_type = match ctype {
0 => { 0 => {
@ -77,11 +79,6 @@ impl CacheInfo {
let inclusive = (cr.edx & 0x2) != 0; let inclusive = (cr.edx & 0x2) != 0;
let complex_cache_indexing = (cr.edx & 0x4) != 0; let complex_cache_indexing = (cr.edx & 0x4) != 0;
println!(
"CR(eax{:x},ebx{:x},ecx{:x},edx{:x})",
cr.eax, cr.ebx, cr.ecx, cr.edx
);
Some(CacheInfo { Some(CacheInfo {
cache_type, cache_type,
level, level,

View File

@ -0,0 +1 @@

View File

@ -1,8 +1,6 @@
use alloc::alloc::{GlobalAlloc, Layout}; use alloc::alloc::{GlobalAlloc, Layout};
use core::ptr::null_mut; use core::ptr::null_mut;
use polling_serial::serial_println; use polling_serial::serial_println;
use x86_64::instructions::bochs_breakpoint;
use x86_64::structures::paging::mapper::MapToError::PageAlreadyMapped;
use x86_64::{ use x86_64::{
structures::paging::{ structures::paging::{
mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB, mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB,
@ -37,8 +35,7 @@ pub fn init_heap(
Page::range_inclusive(heap_start_page, heap_end_page) Page::range_inclusive(heap_start_page, heap_end_page)
}; };
let mut i = 0; for (i, page) in page_range.enumerate() {
for page in page_range {
let frame = frame_allocator let frame = frame_allocator
.allocate_frame() .allocate_frame()
.ok_or(MapToError::FrameAllocationFailed)?; .ok_or(MapToError::FrameAllocationFailed)?;
@ -47,7 +44,6 @@ pub fn init_heap(
if i == 0 { if i == 0 {
serial_println!("Mapped {:?} at {:?}", page, frame); serial_println!("Mapped {:?} at {:?}", page, frame);
} }
i = i + 1;
} }
unsafe { unsafe {

View File

@ -8,7 +8,6 @@
#![reexport_test_harness_main = "test_main"] #![reexport_test_harness_main = "test_main"]
extern crate alloc; extern crate alloc;
use alloc::boxed::Box;
use bootloader::{entry_point, BootInfo}; use bootloader::{entry_point, BootInfo};
use cache_info; use cache_info;
use core::panic::PanicInfo; use core::panic::PanicInfo;
@ -22,7 +21,6 @@ use x86_64;
#[cfg(not(test))] #[cfg(not(test))]
use dendrobates_tinctoreus_azureus::hlt_loop; use dendrobates_tinctoreus_azureus::hlt_loop;
use dendrobates_tinctoreus_azureus::memory::create_example_mapping;
#[cfg(not(test))] #[cfg(not(test))]
use vga_buffer::{set_colors, Color, ForegroundColor}; use vga_buffer::{set_colors, Color, ForegroundColor};
@ -53,8 +51,8 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
x86_64::instructions::interrupts::int3(); x86_64::instructions::interrupts::int3();
use dendrobates_tinctoreus_azureus::memory; use dendrobates_tinctoreus_azureus::memory;
use x86_64::structures::paging::{MapperAllSizes, PageTable}; use x86_64::structures::paging::MapperAllSizes;
use x86_64::{structures::paging::Page, VirtAddr}; use x86_64::VirtAddr;
let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset); let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset);
// new: initialize a mapper // new: initialize a mapper
@ -67,7 +65,7 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
// the identity-mapped vga buffer page // the identity-mapped vga buffer page
0xb8000, 0xb8000,
// some code page // some code page
0x201008, 0x20_1008,
// some stack page // some stack page
0x0100_0020_1a10, 0x0100_0020_1a10,
// virtual address mapped to physical address 0 // virtual address mapped to physical address 0
@ -83,8 +81,6 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed"); allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed");
let x = Box::new(41);
let caches = cache_info::get_cache_info(); let caches = cache_info::get_cache_info();
serial_println!("Caches:"); serial_println!("Caches:");
serial_println!("{:#?}", caches); serial_println!("{:#?}", caches);