Commit fd6aada0 authored by Radim Krčmář's avatar Radim Krčmář
Browse files

use %# instead of 0x% in all format strings



It's one character shorter, properly prefixed, and also provides error
detection: %#d triggers a warning.

Done with `sed -i 's/0x%/%#/g' **/*.[ch]` to motivate the use of %#,
existing padding was raised by 2 to account for the counted "0x" (output
should be the same).
Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
parent c9af8739
......@@ -153,7 +153,7 @@ static bool check_pmcr(void)
pmcr = get_pmcr();
report_info("PMU implementer/ID code/counters: 0x%x(\"%c\")/0x%x/%d",
report_info("PMU implementer/ID code/counters: %#x(\"%c\")/%#x/%d",
(pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK,
((pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK) ? : ' ',
(pmcr >> PMU_PMCR_ID_SHIFT) & PMU_PMCR_ID_MASK,
......
......@@ -25,7 +25,7 @@ void phys_alloc_show(void)
int i;
spin_lock(&lock);
printf("phys_alloc minimum alignment: 0x%" PRIx64 "\n",
printf("phys_alloc minimum alignment: %#" PRIx64 "\n",
(u64)align_min);
for (i = 0; i < nr_regions; ++i)
printf("%016" PRIx64 "-%016" PRIx64 " [%s]\n",
......@@ -75,10 +75,10 @@ static phys_addr_t phys_alloc_aligned_safe(phys_addr_t size,
size += addr - base;
if ((top_safe - base) < size) {
printf("phys_alloc: requested=0x%" PRIx64
" (align=0x%" PRIx64 "), "
"need=0x%" PRIx64 ", but free=0x%" PRIx64 ". "
"top=0x%" PRIx64 ", top_safe=0x%" PRIx64 "\n",
printf("phys_alloc: requested=%#" PRIx64
" (align=%#" PRIx64 "), "
"need=%#" PRIx64 ", but free=%#" PRIx64 ". "
"top=%#" PRIx64 ", top_safe=%#" PRIx64 "\n",
(u64)size_orig, (u64)align, (u64)size, top_safe - base,
(u64)top, top_safe);
spin_unlock(&lock);
......
......@@ -114,14 +114,14 @@ static void bad_exception(enum vector v, struct pt_regs *regs,
printf("Got bad vector=%d\n", v);
} else if (esr_valid) {
if (ec_names[ec])
printf("Unhandled exception ec=0x%x (%s)\n", ec,
printf("Unhandled exception ec=%#x (%s)\n", ec,
ec_names[ec]);
else
printf("Got bad ec=0x%x\n", ec);
printf("Got bad ec=%#x\n", ec);
}
printf("Vector: %d (%s)\n", v, vector_names[v]);
printf("ESR_EL1: %8s%08x, ec=0x%x (%s)\n", "", esr, ec, ec_names[ec]);
printf("ESR_EL1: %8s%08x, ec=%#x (%s)\n", "", esr, ec, ec_names[ec]);
printf("FAR_EL1: %016lx (%svalid)\n", far, far_valid ? "" : "not ");
printf("Exception frame registers:\n");
show_regs(regs);
......
......@@ -48,7 +48,7 @@ void edu_dma(struct pci_edu_dev *dev, iova_t iova,
assert(size <= EDU_DMA_SIZE_MAX);
assert(dev_offset < EDU_DMA_SIZE_MAX);
printf("edu device DMA start %s addr 0x%" PRIx64 " size %lu off 0x%x\n",
printf("edu device DMA start %s addr %#" PRIx64 " size %lu off %#x\n",
from_device ? "FROM" : "TO",
iova, (ulong)size, dev_offset);
......
......@@ -49,7 +49,7 @@ bool pci_setup_msi(struct pci_dev *dev, uint64_t msi_addr, uint32_t msi_data)
assert(dev);
if (!dev->msi_offset) {
printf("MSI: dev 0x%x does not support MSI.\n", dev->bdf);
printf("MSI: dev %#x does not support MSI.\n", dev->bdf);
return false;
}
......@@ -295,10 +295,10 @@ static void pci_cap_print(struct pci_dev *dev, int cap_offset, int cap_id)
break;
}
default:
printf("\tcapability 0x%02x ", cap_id);
printf("\tcapability %#04x ", cap_id);
break;
}
printf("at offset 0x%02x\n", cap_offset);
printf("at offset %#04x\n", cap_offset);
}
void pci_dev_print(struct pci_dev *dev)
......
......@@ -38,7 +38,7 @@ void do_handle_exception(struct pt_regs *regs)
return;
}
printf("unhandled cpu exception 0x%lx\n", regs->trap);
printf("unhandled cpu exception %#lx\n", regs->trap);
abort();
}
......
......@@ -69,7 +69,7 @@ static void unhandled_exception(struct ex_regs *regs, bool cpu)
cpu ? "cpu " : "", regs->vector,
exception_mnemonic(regs->vector), regs->rip);
if (regs->vector == 14)
printf("PF at 0x%lx addr 0x%lx\n", regs->rip, read_cr2());
printf("PF at %#lx addr %#lx\n", regs->rip, read_cr2());
printf("error_code=%04lx rflags=%08lx cs=%08lx\n"
"rax=%016lx rcx=%016lx rdx=%016lx rbx=%016lx\n"
......
......@@ -115,9 +115,9 @@ static void vtd_dump_init_info(void)
/* Major version >= 1 */
assert(((version >> 3) & 0xf) >= 1);
printf("VT-d version: 0x%x\n", version);
printf(" cap: 0x%016lx\n", vtd_readq(DMAR_CAP_REG));
printf(" ecap: 0x%016lx\n", vtd_readq(DMAR_ECAP_REG));
printf("VT-d version: %#x\n", version);
printf(" cap: %#018lx\n", vtd_readq(DMAR_CAP_REG));
printf(" ecap: %#018lx\n", vtd_readq(DMAR_ECAP_REG));
}
static void vtd_setup_root_table(void)
......@@ -127,7 +127,7 @@ static void vtd_setup_root_table(void)
memset(root, 0, PAGE_SIZE);
vtd_writeq(DMAR_RTADDR_REG, virt_to_phys(root));
vtd_gcmd_or(VTD_GCMD_ROOT);
printf("DMAR table address: 0x%016lx\n", vtd_root_table());
printf("DMAR table address: %#018lx\n", vtd_root_table());
}
static void vtd_setup_ir_table(void)
......@@ -138,7 +138,7 @@ static void vtd_setup_ir_table(void)
/* 0xf stands for table size (2^(0xf+1) == 65536) */
vtd_writeq(DMAR_IRTA_REG, virt_to_phys(root) | 0xf);
vtd_gcmd_or(VTD_GCMD_IR_TABLE);
printf("IR table address: 0x%016lx\n", vtd_ir_table());
printf("IR table address: %#018lx\n", vtd_ir_table());
}
static void vtd_install_pte(vtd_pte_t *root, iova_t iova,
......@@ -219,14 +219,14 @@ void vtd_map_range(uint16_t sid, iova_t iova, phys_addr_t pa, size_t size)
ce->present = 1;
/* No error reporting yet */
ce->disable_fault_report = 1;
printf("allocated vt-d context entry for devfn 0x%x\n",
printf("allocated vt-d context entry for devfn %#x\n",
devfn);
} else
slptptr = phys_to_virt(ce->slptptr << VTD_PAGE_SHIFT);
while (size) {
/* TODO: currently we only map 4K pages (level = 1) */
printf("map 4K page IOVA 0x%lx to 0x%lx (sid=0x%04x)\n",
printf("map 4K page IOVA %#lx to %#lx (sid=%#06x)\n",
iova, pa, sid);
vtd_install_pte(slptptr, iova, pa, 1);
size -= VTD_PAGE_SIZE;
......@@ -324,7 +324,7 @@ bool vtd_setup_msi(struct pci_dev *dev, int vector, int dest_id)
msi_addr.head = 0xfee;
msi_data.subhandle = 0;
printf("%s: msi_addr=0x%" PRIx64 ", msi_data=0x%x\n", __func__,
printf("%s: msi_addr=%#" PRIx64 ", msi_data=%#x\n", __func__,
*(uint64_t *)&msi_addr, *(uint32_t *)&msi_data);
return pci_setup_msi(dev, *(uint64_t *)&msi_addr,
......
......@@ -12,10 +12,10 @@ static void free_memory(void *mem, unsigned long size)
assert_msg((unsigned long) mem % PAGE_SIZE == 0,
"mem not page aligned: %p", mem);
assert_msg(size % PAGE_SIZE == 0, "size not page aligned: 0x%lx", size);
assert_msg(size % PAGE_SIZE == 0, "size not page aligned: %#lx", size);
assert_msg(size == 0 || mem + size > mem,
"mem + size overflow: %p + 0x%lx", mem, size);
"mem + size overflow: %p + %#lx", mem, size);
if (size == 0) {
free = NULL;
......
......@@ -14,7 +14,7 @@ static void program_check_handler(struct pt_regs *regs, void *opaque)
int *data = opaque;
if (verbose) {
printf("Detected invalid instruction 0x%016lx: %08x\n",
printf("Detected invalid instruction %#018lx: %08x\n",
regs->nip, *(uint32_t*)regs->nip);
}
......@@ -36,7 +36,7 @@ static void alignment_handler(struct pt_regs *regs, void *opaque)
int *data = opaque;
if (verbose) {
printf("Detected alignment exception 0x%016lx: %08x\n",
printf("Detected alignment exception %#018lx: %08x\n",
regs->nip, *(uint32_t*)regs->nip);
}
......
......@@ -49,7 +49,7 @@ static void test_h_set_sprg0(int argc, char **argv)
rc = hcall(H_SET_SPRG0, sprg0_orig);
sprg0 = mfspr(SPR_SPRG0);
report("sprg0 = 0x%" PRIx64,
report("sprg0 = %#" PRIx64,
rc == H_SUCCESS && sprg0 == sprg0_orig, sprg0_orig);
}
......
......@@ -271,7 +271,7 @@ int main(int argc, char **argv)
}
}
printf("Settings SPRs to 0x%lx...\n", pat);
printf("Settings SPRs to %#lx...\n", pat);
set_sprs(pat);
memset(before, 0, sizeof(before));
......@@ -296,7 +296,7 @@ int main(int argc, char **argv)
puts("Checking SPRs...\n");
for (i = 0; i < 1024; i++) {
if (before[i] != 0 || after[i] != 0)
report("SPR %d:\t0x%016lx <==> 0x%016lx",
report("SPR %d:\t%#018lx <==> %#018lx",
before[i] == after[i], i, before[i], after[i]);
}
......
......@@ -52,13 +52,13 @@ static void pf_isr(struct ex_regs *r)
switch (reason) {
case 0:
report("unexpected #PF at 0x%lx", false, read_cr2());
report("unexpected #PF at %#lx", false, read_cr2());
break;
case KVM_PV_REASON_PAGE_NOT_PRESENT:
phys = virt_to_phys_cr3(virt);
install_pte(phys_to_virt(read_cr3()), 1, virt, phys, 0);
write_cr3(read_cr3());
report("Got not present #PF token %lx virt addr %p phys addr 0x%" PRIx64,
report("Got not present #PF token %lx virt addr %p phys addr %#" PRIx64,
true, read_cr2(), virt, phys);
while(phys) {
safe_halt(); /* enables irq */
......
......@@ -90,7 +90,7 @@ static void synic_test_prepare(void *ctx)
}
r = rdmsr(HV_X64_MSR_EOM);
if (r != 0) {
report("Hyper-V SynIC test, EOM read 0x%" PRIx64, false, r);
report("Hyper-V SynIC test, EOM read %#" PRIx64, false, r);
goto ret;
}
......
......@@ -82,13 +82,13 @@ static void test_msr_rw(int msr_index, unsigned long long input, unsigned long l
if ((index = find_msr_info(msr_index)) != -1) {
sptr = msr_info[index].name;
} else {
printf("couldn't find name for msr # 0x%x, skipping\n", msr_index);
printf("couldn't find name for msr # %#x, skipping\n", msr_index);
return;
}
wrmsr(msr_index, input);
r = rdmsr(msr_index);
if (expected != r) {
printf("testing %s: output = 0x%x:0x%x expected = 0x%x:0x%x\n", sptr,
printf("testing %s: output = %#x:%#x expected = %#x:%#x\n", sptr,
(u32)(r >> 32), (u32)r, (u32)(expected >> 32), (u32)expected);
}
report(sptr, expected == r);
......
......@@ -524,7 +524,7 @@ int main(int ac, char **av)
membar = pcidev.resource[PCI_TESTDEV_BAR_MEM];
pci_test.memaddr = ioremap(membar, PAGE_SIZE);
pci_test.iobar = pcidev.resource[PCI_TESTDEV_BAR_IO];
printf("pci-testdev at 0x%x membar %lx iobar %x\n",
printf("pci-testdev at %#x membar %lx iobar %x\n",
pcidev.bdf, membar, pci_test.iobar);
}
......
......@@ -521,16 +521,16 @@ void print_vmexit_info()
guest_rsp = vmcs_read(GUEST_RSP);
printf("VMEXIT info:\n");
printf("\tvmexit reason = %ld\n", reason);
printf("\texit qualification = 0x%lx\n", exit_qual);
printf("\texit qualification = %#lx\n", exit_qual);
printf("\tBit 31 of reason = %lx\n", (vmcs_read(EXI_REASON) >> 31) & 1);
printf("\tguest_rip = 0x%lx\n", guest_rip);
printf("\tRAX=0x%lx RBX=0x%lx RCX=0x%lx RDX=0x%lx\n",
printf("\tguest_rip = %#lx\n", guest_rip);
printf("\tRAX=%#lx RBX=%#lx RCX=%#lx RDX=%#lx\n",
regs.rax, regs.rbx, regs.rcx, regs.rdx);
printf("\tRSP=0x%lx RBP=0x%lx RSI=0x%lx RDI=0x%lx\n",
printf("\tRSP=%#lx RBP=%#lx RSI=%#lx RDI=%#lx\n",
guest_rsp, regs.rbp, regs.rsi, regs.rdi);
printf("\tR8 =0x%lx R9 =0x%lx R10=0x%lx R11=0x%lx\n",
printf("\tR8 =%#lx R9 =%#lx R10=%#lx R11=%#lx\n",
regs.r8, regs.r9, regs.r10, regs.r11);
printf("\tR12=0x%lx R13=0x%lx R14=0x%lx R15=0x%lx\n",
printf("\tR12=%#lx R13=%#lx R14=%#lx R15=%#lx\n",
regs.r12, regs.r13, regs.r14, regs.r15);
}
......@@ -553,7 +553,7 @@ print_vmentry_failure_info(struct vmentry_failure *failure) {
u64 reason = vmcs_read(EXI_REASON);
u64 qual = vmcs_read(EXI_QUALIFICATION);
printf("Non-early %s failure (reason=0x%lx, qual=0x%lx): ",
printf("Non-early %s failure (reason=%#lx, qual=%#lx): ",
failure->instr, reason, qual);
switch (reason & 0xff) {
......
......@@ -755,8 +755,8 @@ do { \
binstr(_a, _bin_a); \
binstr(_b, _bin_b); \
report("%s:%d: %s failed: (%s) == (%s)\n" \
"\tLHS: 0x%016lx - %s - %lu\n" \
"\tRHS: 0x%016lx - %s - %lu%s" fmt, 0, \
"\tLHS: %#018lx - %s - %lu\n" \
"\tRHS: %#018lx - %s - %lu%s" fmt, 0, \
__FILE__, __LINE__, \
assertion ? "Assertion" : "Expectation", a_str, b_str, \
(unsigned long) _a, _bin_a, (unsigned long) _a, \
......
......@@ -719,7 +719,7 @@ static int iobmp_exit_handler()
vmcs_write(GUEST_RIP, guest_rip + insn_len);
return VMX_TEST_RESUME;
default:
printf("guest_rip = 0x%lx\n", guest_rip);
printf("guest_rip = %#lx\n", guest_rip);
printf("\tERROR : Undefined exit reason, reason = %ld.\n", reason);
break;
}
......
......@@ -75,7 +75,7 @@ void test_xsave(void)
printf("Legal instruction testing:\n");
supported_xcr0 = get_supported_xcr0();
printf("Supported XCR0 bits: 0x%lx\n", supported_xcr0);
printf("Supported XCR0 bits: %#lx\n", supported_xcr0);
test_bits = XSTATE_FP | XSTATE_SSE;
report("Check minimal XSAVE required bits",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment