Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format pointer types using Pointer trait #791

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/arch/aarch64/kernel/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ pub(crate) fn init() {
let gicc_size = u64::from_be_bytes(slice.try_into().unwrap());

info!(
"Found GIC Distributor interface at {:#X} (size {:#X})",
"Found GIC Distributor interface at {:p} (size {:#X})",
gicd_start, gicd_size
);
info!(
"Found generic interrupt controller at {:#X} (size {:#X})",
"Found generic interrupt controller at {:p} (size {:#X})",
gicc_start, gicc_size
);

Expand Down
2 changes: 1 addition & 1 deletion src/arch/aarch64/kernel/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub fn init() {

let pci_address =
virtualmem::allocate_aligned(size.try_into().unwrap(), 0x10000000).unwrap();
info!("Mapping PCI Enhanced Configuration Space interface to virtual address {:#X} (size {:#X})", pci_address, size);
info!("Mapping PCI Enhanced Configuration Space interface to virtual address {:p} (size {:#X})", pci_address, size);

let mut flags = PageTableEntryFlags::empty();
flags.device().writable().execute_disable();
Expand Down
6 changes: 3 additions & 3 deletions src/arch/aarch64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl TaskStacks {
.expect("Failed to allocate Physical Memory for TaskStacks");

debug!(
"Create stacks at {:#X} with a size of {} KB",
"Create stacks at {:p} with a size of {} KB",
virt_addr,
total_size >> 10
);
Expand Down Expand Up @@ -174,7 +174,7 @@ impl TaskStacks {

pub fn from_boot_stacks() -> TaskStacks {
let stack = VirtAddr::from_u64(CURRENT_STACK_ADDRESS.load(Ordering::Relaxed));
debug!("Using boot stack {:#X}", stack);
debug!("Using boot stack {:p}", stack);

TaskStacks::Boot(BootStack { stack })
}
Expand Down Expand Up @@ -217,7 +217,7 @@ impl Drop for TaskStacks {
TaskStacks::Boot(_) => {}
TaskStacks::Common(stacks) => {
debug!(
"Deallocating stacks at {:#X} with a size of {} KB",
"Deallocating stacks at {:p} with a size of {} KB",
stacks.virt_addr,
stacks.total_size >> 10,
);
Expand Down
2 changes: 1 addition & 1 deletion src/arch/aarch64/kernel/systemtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn init() {
let (slice, _residual_slice) = residual_slice.split_at(core::mem::size_of::<u64>());
let size = u64::from_be_bytes(slice.try_into().unwrap());

debug!("Found RTC at {:#X} (size {:#X})", addr, size);
debug!("Found RTC at {:p} (size {:#X})", addr, size);

let pl031_address = virtualmem::allocate_aligned(
size.try_into().unwrap(),
Expand Down
14 changes: 7 additions & 7 deletions src/arch/aarch64/mm/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl PageTableEntry {
assert_eq!(
physical_address % BasePageSize::SIZE,
0,
"Physical address is not on a 4 KiB page boundary (physical_address = {:#X})",
"Physical address is not on a 4 KiB page boundary (physical_address = {:p})",
physical_address
);

Expand Down Expand Up @@ -256,7 +256,7 @@ impl<S: PageSize> Page<S> {
fn including_address(virtual_address: VirtAddr) -> Self {
assert!(
Self::is_valid_address(virtual_address),
"Virtual address {:#X} is invalid",
"Virtual address {:p} is invalid",
virtual_address
);

Expand Down Expand Up @@ -556,15 +556,15 @@ fn get_page_range<S: PageSize>(virtual_address: VirtAddr, count: usize) -> PageI
}

pub fn get_page_table_entry<S: PageSize>(virtual_address: VirtAddr) -> Option<PageTableEntry> {
trace!("Looking up Page Table Entry for {:#X}", virtual_address);
trace!("Looking up Page Table Entry for {:p}", virtual_address);

let page = Page::<S>::including_address(virtual_address);
let root_pagetable = unsafe { &mut *(L0TABLE_ADDRESS.as_mut_ptr() as *mut PageTable<L0Table>) };
root_pagetable.get_page_table_entry(page)
}

pub fn get_physical_address<S: PageSize>(virtual_address: VirtAddr) -> Option<PhysAddr> {
trace!("Getting physical address for {:#X}", virtual_address);
trace!("Getting physical address for {:p}", virtual_address);

let page = Page::<S>::including_address(virtual_address);
let root_pagetable = unsafe { &mut *(L0TABLE_ADDRESS.as_mut_ptr() as *mut PageTable<L0Table>) };
Expand Down Expand Up @@ -592,7 +592,7 @@ pub fn map<S: PageSize>(
flags: PageTableEntryFlags,
) {
trace!(
"Mapping virtual address {:#X} to physical address {:#X} ({} pages)",
"Mapping virtual address {:p} to physical address {:p} ({} pages)",
virtual_address,
physical_address,
count
Expand Down Expand Up @@ -620,7 +620,7 @@ pub fn map_heap<S: PageSize>(virt_addr: VirtAddr, count: usize) {

pub fn unmap<S: PageSize>(virtual_address: VirtAddr, count: usize) {
trace!(
"Unmapping virtual address {:#X} ({} pages)",
"Unmapping virtual address {:p} ({} pages)",
virtual_address,
count
);
Expand All @@ -639,7 +639,7 @@ pub unsafe fn init() {
let aa64mmfr0: u64;

let ram_start = get_ram_address();
info!("RAM starts at physical address 0x{:x}", ram_start);
info!("RAM starts at physical address {:p}", ram_start);

// determine physical address size
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/arch/aarch64/mm/physicalmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn allocate_aligned(size: usize, alignment: usize) -> Result<PhysAddr, Alloc
pub fn deallocate(physical_address: PhysAddr, size: usize) {
assert!(
physical_address >= PhysAddr(mm::kernel_end_address().as_u64()),
"Physical address {:#X} is not >= KERNEL_END_ADDRESS",
"Physical address {:p} is not >= KERNEL_END_ADDRESS",
physical_address
);
assert!(size > 0);
Expand Down
6 changes: 3 additions & 3 deletions src/arch/aarch64/mm/virtualmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ pub fn allocate_aligned(size: usize, alignment: usize) -> Result<VirtAddr, Alloc
pub fn deallocate(virtual_address: VirtAddr, size: usize) {
assert!(
virtual_address >= mm::kernel_end_address() || virtual_address < mm::kernel_start_address(),
"Virtual address {:#X} belongs to the kernel",
"Virtual address {:p} belongs to the kernel",
virtual_address
);
assert!(
virtual_address < KERNEL_VIRTUAL_MEMORY_END,
"Virtual address {:#X} is not < KERNEL_VIRTUAL_MEMORY_END",
"Virtual address {:p} is not < KERNEL_VIRTUAL_MEMORY_END",
virtual_address
);
assert_eq!(
virtual_address % BasePageSize::SIZE,
0,
"Virtual address {:#X} is not a multiple of {:#X}",
"Virtual address {:p} is not a multiple of {:#X}",
virtual_address,
BasePageSize::SIZE
);
Expand Down
10 changes: 5 additions & 5 deletions src/arch/x86_64/kernel/acpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,13 @@ fn parse_fadt(fadt: AcpiTable<'_>) {
// Check it.
assert!(
dsdt.header.signature() == "DSDT",
"DSDT at {:#X} has invalid signature \"{}\"",
"DSDT at {:p} has invalid signature \"{}\"",
dsdt_address,
dsdt.header.signature()
);
assert!(
verify_checksum(dsdt.header_start_address(), dsdt.header.length as usize).is_ok(),
"DSDT at {dsdt_address:#X} has invalid checksum"
"DSDT at {dsdt_address:p} has invalid checksum"
);

// Try to find the "_S5_" object for SLP_TYPA in the DSDT AML bytecode.
Expand Down Expand Up @@ -503,21 +503,21 @@ pub fn init() {
// Check and save the entire APIC table for the get_apic_table() call.
assert!(
verify_checksum(table.header_start_address(), table.header.length as usize).is_ok(),
"MADT at {table_physical_address:#X} has invalid checksum"
"MADT at {table_physical_address:p} has invalid checksum"
);
MADT.set(table).unwrap();
} else if table.header.signature() == "FACP" {
// The "Fixed ACPI Description Table" (FADT) aka "Fixed ACPI Control Pointer" (FACP)
// Check and parse this table for the poweroff() call.
assert!(
verify_checksum(table.header_start_address(), table.header.length as usize).is_ok(),
"FADT at {table_physical_address:#X} has invalid checksum"
"FADT at {table_physical_address:p} has invalid checksum"
);
parse_fadt(table);
} else if table.header.signature() == "SSDT" {
assert!(
verify_checksum(table.header_start_address(), table.header.length as usize).is_ok(),
"SSDT at {table_physical_address:#X} has invalid checksum"
"SSDT at {table_physical_address:p} has invalid checksum"
);
parse_ssdt(table);
}
Expand Down
6 changes: 3 additions & 3 deletions src/arch/x86_64/kernel/apic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ fn detect_from_mp() -> Result<PhysAddr, ()> {
2 => {
let io_entry: &ApicIoEntry = unsafe { &*(addr as *const ApicIoEntry) };
let ioapic = PhysAddr(io_entry.addr.into());
info!("Found IOAPIC at 0x{:x}", ioapic);
info!("Found IOAPIC at 0x{:p}", ioapic);

init_ioapic_address(ioapic);

Expand Down Expand Up @@ -456,7 +456,7 @@ pub fn init() {
let local_apic_address = virtualmem::allocate(BasePageSize::SIZE as usize).unwrap();
LOCAL_APIC_ADDRESS.set(local_apic_address).unwrap();
debug!(
"Mapping Local APIC at {:#X} to virtual address {:#X}",
"Mapping Local APIC at {:p} to virtual address {:p}",
local_apic_physical_address, local_apic_address
);

Expand Down Expand Up @@ -696,7 +696,7 @@ pub fn boot_application_processors() {

// Identity-map the boot code page and copy over the code.
debug!(
"Mapping SMP boot code to physical and virtual address {:#X}",
"Mapping SMP boot code to physical and virtual address {:p}",
SMP_BOOT_CODE_ADDRESS
);
let mut flags = PageTableEntryFlags::empty();
Expand Down
8 changes: 4 additions & 4 deletions src/arch/x86_64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl TaskStacks {
.expect("Failed to allocate Physical Memory for TaskStacks");

debug!(
"Create stacks at {:#X} with a size of {} KB",
"Create stacks at {:p} with a size of {} KB",
virt_addr,
total_size >> 10
);
Expand Down Expand Up @@ -153,11 +153,11 @@ impl TaskStacks {
let stack = VirtAddr::from_usize(
tss.privilege_stack_table[0].as_u64() as usize + Self::MARKER_SIZE - KERNEL_STACK_SIZE,
);
debug!("Using boot stack {:#X}", stack);
debug!("Using boot stack {:p}", stack);
let ist1 = VirtAddr::from_usize(
tss.interrupt_stack_table[0].as_u64() as usize + Self::MARKER_SIZE - IST_SIZE,
);
debug!("IST1 is located at {:#X}", ist1);
debug!("IST1 is located at {:p}", ist1);

TaskStacks::Boot(BootStack { stack, ist1 })
}
Expand Down Expand Up @@ -211,7 +211,7 @@ impl Drop for TaskStacks {
TaskStacks::Boot(_) => {}
TaskStacks::Common(stacks) => {
debug!(
"Deallocating stacks at {:#X} with a size of {} KB",
"Deallocating stacks at {:p} with a size of {} KB",
stacks.virt_addr,
stacks.total_size >> 10,
);
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/mm/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ where
{
assert!(
frame.start_address().as_u64() < mm::kernel_start_address().0,
"Address {:#X} to be identity-mapped is not below Kernel start address",
"Address {:p} to be identity-mapped is not below Kernel start address",
frame.start_address()
);

Expand All @@ -187,7 +187,7 @@ where
RecursivePageTable<'static>: Mapper<S>,
{
trace!(
"Unmapping virtual address {:#X} ({} pages)",
"Unmapping virtual address {:p} ({} pages)",
virtual_address,
count
);
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/mm/physicalmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn allocate_aligned(size: usize, alignment: usize) -> Result<PhysAddr, Alloc
pub fn deallocate(physical_address: PhysAddr, size: usize) {
assert!(
physical_address >= PhysAddr(mm::kernel_end_address().as_u64()),
"Physical address {physical_address:#X} is not >= KERNEL_END_ADDRESS"
"Physical address {physical_address:p} is not >= KERNEL_END_ADDRESS"
);
assert!(size > 0);
assert_eq!(
Expand All @@ -179,7 +179,7 @@ pub fn reserve(physical_address: PhysAddr, size: usize) {
assert_eq!(
physical_address % BasePageSize::SIZE as usize,
0,
"Physical address {:#X} is not a multiple of {:#X}",
"Physical address {:p} is not a multiple of {:#X}",
physical_address,
BasePageSize::SIZE
);
Expand Down
6 changes: 3 additions & 3 deletions src/arch/x86_64/mm/virtualmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ pub fn allocate_aligned(size: usize, alignment: usize) -> Result<VirtAddr, Alloc
pub fn deallocate(virtual_address: VirtAddr, size: usize) {
assert!(
virtual_address >= VirtAddr(mm::kernel_end_address().as_u64()),
"Virtual address {virtual_address:#X} is not >= KERNEL_END_ADDRESS"
"Virtual address {virtual_address:p} is not >= KERNEL_END_ADDRESS"
);
assert!(
virtual_address < kernel_heap_end(),
"Virtual address {virtual_address:#X} is not < kernel_heap_end()"
"Virtual address {virtual_address:p} is not < kernel_heap_end()"
);
assert_eq!(
virtual_address % BasePageSize::SIZE,
0,
"Virtual address {:#X} is not a multiple of {:#X}",
"Virtual address {:p} is not a multiple of {:#X}",
virtual_address,
BasePageSize::SIZE
);
Expand Down
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ pub(crate) extern "C" fn __sys_malloc(size: usize, align: usize) -> *mut u8 {
let ptr = unsafe { ALLOCATOR.alloc(layout) };

trace!(
"__sys_malloc: allocate memory at {:#x} (size {:#x}, align {:#x})",
ptr as usize,
"__sys_malloc: allocate memory at {:p} (size {:#x}, align {:#x})",
ptr,
size,
align
);
Expand Down Expand Up @@ -175,8 +175,8 @@ pub(crate) extern "C" fn __sys_realloc(
let layout_res = Layout::from_size_align(size, align);
if layout_res.is_err() || size == 0 || new_size == 0 {
warn!(
"__sys_realloc called with ptr {:#x}, size {:#x}, align {:#x}, new_size {:#x} is an invalid layout!",
ptr as usize, size, align, new_size
"__sys_realloc called with ptr {:p}, size {:#x}, align {:#x}, new_size {:#x} is an invalid layout!",
ptr, size, align, new_size
);
return core::ptr::null::<*mut u8>() as *mut u8;
}
Expand All @@ -185,14 +185,14 @@ pub(crate) extern "C" fn __sys_realloc(

if new_ptr.is_null() {
debug!(
"__sys_realloc failed to resize ptr {:#x} with size {:#x}, align {:#x}, new_size {:#x} !",
ptr as usize, size, align, new_size
"__sys_realloc failed to resize ptr {:p} with size {:#x}, align {:#x}, new_size {:#x} !",
ptr, size, align, new_size
);
} else {
trace!(
"__sys_realloc: resized memory at {:#x}, new address {:#x}",
ptr as usize,
new_ptr as usize
"__sys_realloc: resized memory at {:p}, new address {:p}",
ptr,
new_ptr
);
}
new_ptr
Expand Down Expand Up @@ -222,8 +222,8 @@ pub(crate) extern "C" fn __sys_free(ptr: *mut u8, size: usize, align: usize) {
debug_assert_ne!(size, 0, "__sys_free error: size cannot be 0");
} else {
trace!(
"sys_free: deallocate memory at {:#x} (size {:#x})",
ptr as usize,
"sys_free: deallocate memory at {:p} (size {:#x})",
ptr,
size
);
}
Expand Down Expand Up @@ -303,7 +303,7 @@ fn boot_processor_main() -> ! {
}

info!("Welcome to HermitCore-rs {}", env!("CARGO_PKG_VERSION"));
info!("Kernel starts at {:#x}", env::get_base_address());
info!("Kernel starts at {:p}", env::get_base_address());

extern "C" {
static mut __bss_start: u8;
Expand All @@ -312,7 +312,7 @@ fn boot_processor_main() -> ! {
core::ptr::addr_of_mut!(__bss_start)
});
info!(
"TLS starts at {:#x} (size {} Bytes)",
"TLS starts at {:p} (size {} Bytes)",
env::get_tls_start(),
env::get_tls_memsz()
);
Expand Down
Loading