Skip to content

Commit

Permalink
Format address types using Pointer trait
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Jul 12, 2023
1 parent 3726e03 commit 53d845f
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 44 deletions.
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
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
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
8 changes: 4 additions & 4 deletions src/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn init() {

info!("Total memory size: {} MB", total_memory_size() >> 20);
info!(
"Kernel region: [{:#x} - {:#x}]",
"Kernel region: [{:p} - {:p}]",
kernel_start_address(),
kernel_end_address()
);
Expand Down Expand Up @@ -152,7 +152,7 @@ pub fn init() {
};

info!(
"Heap: size {} MB, start address {:#x}",
"Heap: size {} MB, start address {:p}",
virt_size >> 20,
virt_addr
);
Expand Down Expand Up @@ -254,7 +254,7 @@ pub fn deallocate(virtual_address: VirtAddr, sz: usize) {
arch::mm::physicalmem::deallocate(phys_addr, size);
} else {
panic!(
"No page table entry for virtual address {:#X}",
"No page table entry for virtual address {:p}",
virtual_address
);
}
Expand Down Expand Up @@ -303,7 +303,7 @@ pub fn unmap(virtual_address: VirtAddr, sz: usize) {
arch::mm::virtualmem::deallocate(virtual_address, size);
} else {
panic!(
"No page table entry for virtual address {:#X}",
"No page table entry for virtual address {:p}",
virtual_address
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ impl PerCoreScheduler {
if id != new_id {
// Tell the scheduler about the new task.
debug!(
"Switching task from {} to {} (stack {:#X} => {:#X})",
"Switching task from {} to {} (stack {:#X} => {:p})",
id,
new_id,
unsafe { *last_stack_pointer },
Expand Down

0 comments on commit 53d845f

Please sign in to comment.