Skip to content

Commit

Permalink
use pointer address formatter instead of casting
Browse files Browse the repository at this point in the history
To print addresses of objects, use address pointer formatter directly
instead of casting to other types to print.
  • Loading branch information
cagatay-y committed Oct 25, 2023
1 parent 7f83025 commit 92d5675
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/arch/aarch64/kernel/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub(crate) extern "C" fn do_sync(state: &State) {

// add page fault handler

error!("Current stack pointer {:#x}", state as *const _ as u64);
error!("Current stack pointer {state:p}");
error!("Unable to handle page fault at {:#x}", far);
error!("Exception return address {:#x}", ELR_EL1.get());
error!("Thread ID register {:#x}", TPIDR_EL0.get());
Expand Down
11 changes: 4 additions & 7 deletions src/arch/x86_64/kernel/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn detect_network() -> Result<&'static mut MmioRegisterLayout, &'static str>
let version = mmio.get_version();

if magic != MAGIC_VALUE {
trace!("It's not a MMIO-device at {:#X}", mmio as *const _ as usize);
trace!("It's not a MMIO-device at {mmio:p}");
continue;
}

Expand All @@ -84,20 +84,17 @@ pub fn detect_network() -> Result<&'static mut MmioRegisterLayout, &'static str>
}

// We found a MMIO-device (whose 512-bit address in this structure).
trace!("Found a MMIO-device at {:#X}", mmio as *const _ as usize);
trace!("Found a MMIO-device at {mmio:p}");

// Verify the device-ID to find the network card
let id = mmio.get_device_id();

if id != DevId::VIRTIO_DEV_ID_NET {
trace!(
"It's not a network card at {:#X}",
mmio as *const _ as usize
);
trace!("It's not a network card at {mmio:p}");
continue;
}

info!("Found network card at {:#X}", mmio as *const _ as usize);
info!("Found network card at {mmio:p}");

crate::arch::mm::physicalmem::reserve(
PhysAddr::from(current_address.align_down(BasePageSize::SIZE as usize)),
Expand Down
16 changes: 5 additions & 11 deletions src/mm/freelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ impl FreeList {
}

pub fn allocate(&mut self, size: usize, alignment: Option<usize>) -> Result<usize, AllocError> {
trace!(
"Allocating {} bytes from Free List {:#X}",
size,
self as *const Self as usize
);
trace!("Allocating {} bytes from Free List {self:p}", size);

let new_size = if let Some(align) = alignment {
size + align
Expand Down Expand Up @@ -90,10 +86,9 @@ impl FreeList {
#[cfg(all(target_arch = "x86_64", not(feature = "pci")))]
pub fn reserve(&mut self, address: usize, size: usize) -> Result<(), AllocError> {
trace!(
"Try to reserve {} bytes at {:#X} from Free List {:#X}",
"Try to reserve {} bytes at {:#X} from Free List {self:p}",
size,
address,
self as *const Self as usize
address
);

// Find a region in the Free List that has at least the requested size.
Expand All @@ -119,10 +114,9 @@ impl FreeList {

pub fn deallocate(&mut self, address: usize, size: usize) {
trace!(
"Deallocating {} bytes at {:#X} from Free List {:#X}",
"Deallocating {} bytes at {:#X} from Free List {self:p}",
size,
address,
self as *const Self as usize
address
);

let end = address + size;
Expand Down

0 comments on commit 92d5675

Please sign in to comment.