Skip to content

Commit

Permalink
Machine: resolve some printf format warnings for build on 32-bit syst…
Browse files Browse the repository at this point in the history
…ems.

The emulated CPU registers are declared as 64-bit in QtRVSim
but there is used format "lx" in many places. But long is
only 32-bit on x86 MAC OS 32-bit build.

Signed-off-by: Pavel Pisa <[email protected]>
  • Loading branch information
ppisa committed Mar 12, 2022
1 parent 4193079 commit 4f3f5a7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/machine/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "execute/alu.h"
#include "utils.h"

#include <cinttypes>

LOG_CATEGORY("machine.core");

using namespace machine;
Expand Down Expand Up @@ -626,8 +628,8 @@ bool StopExceptionHandler::handle_exception(
Address mem_ref_addr) {
Q_UNUSED(core)
DEBUG(
"Exception cause %d instruction PC 0x%08lx next PC 0x%08lx jump branch PC 0x%08lx "
"registers PC 0x%08lx mem ref 0x%08lx",
"Exception cause %d instruction PC 0x%08" PRIx64 " next PC 0x%08" PRIx64 " jump branch PC 0x%08" PRIx64
"registers PC 0x%08" PRIx64 " mem ref 0x%08" PRIx64,
excause, inst_addr.get_raw(), next_addr.get_raw(), jump_branch_pc.get_raw(),
regs->read_pc().get_raw(), mem_ref_addr.get_raw());
return true;
Expand Down
6 changes: 4 additions & 2 deletions src/machine/memory/backend/memory.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "machine/memory/memory_utils.h"
#include "tests/utils/integer_decomposition.h"

#include <cinttypes>

using namespace machine;

// Default memory testing data. Some tests may use other values, where it
Expand Down Expand Up @@ -85,7 +87,7 @@ constexpr void prepare_data(
auto result_value
= (endian == BIG) ? (value << (stride * 8)) : (value >> (stride * 8));
QTest::addRow(
"endian=%s, address=0x%lx, stride=%ld, value=0x%lx", to_string(endian),
"endian=%s, address=0x%lx, stride=%ld, value=0x%" PRIx64, to_string(endian),
address, stride, value)
<< endian << address << stride << IntegerDecomposition(value, endian)
<< IntegerDecomposition(result_value, endian);
Expand Down Expand Up @@ -328,4 +330,4 @@ void TestMemory::memory_read_ctl() {
}
}

QTEST_APPLESS_MAIN(TestMemory)
QTEST_APPLESS_MAIN(TestMemory)
6 changes: 4 additions & 2 deletions src/machine/memory/cache/cache.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <tests/utils/integer_decomposition.h>

#include <cinttypes>

using namespace machine;
using std::array;
using std::pair;
Expand Down Expand Up @@ -158,8 +160,8 @@ void TestCache::cache_correctness_data() {
auto result_value
= (endian == BIG) ? (value << (stride * 8)) : (value >> (stride * 8));
QTest::addRow(
"endian=%s, address=0x%lx, stride=%ld, "
"value=0x%lx, cache_config={ %d, "
"endian=%s, address=0x%" PRIx64 ", stride=%ld, "
"value=0x%" PRIx64 ", cache_config={ %d, "
"r=%d, wr=%d, s=%d, b=%d, a=%d }",
to_string(endian), address, stride, value, cache_config.enabled(),
cache_config.replacement_policy(), cache_config.write_policy(),
Expand Down
19 changes: 10 additions & 9 deletions src/os_emulation/ossyscall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,12 @@ bool OsSyscallExceptionHandler::handle_exception(

#if 1
printf(
"Exception cause %d instruction PC 0x%08lx next PC 0x%08lx jump branch "
"PC 0x%08lx "
"registers PC 0x%08lx mem ref 0x%08lx\n",
excause, (unsigned long)inst_addr.get_raw(), (unsigned long)next_addr.get_raw(),
(unsigned long)jump_branch_pc.get_raw(), (unsigned long)regs->read_pc().get_raw(),
(unsigned long)mem_ref_addr.get_raw());
"Exception cause %d instruction PC 0x%08" PRIx64 " next PC 0x%08" PRIx64 " jump branch "
"PC 0x%08" PRIx64
"registers PC 0x%08" PRIx64 " mem ref 0x%08" PRIx64 "\n",
excause, inst_addr.get_raw(), next_addr.get_raw(),
jump_branch_pc.get_raw(), regs->read_pc().get_raw(),
mem_ref_addr.get_raw());
#else
(void)excause;
(void)inst_addr;
Expand Down Expand Up @@ -607,7 +607,7 @@ bool OsSyscallExceptionHandler::handle_exception(

#if 1
printf(
"Syscall %s number %ld/0x%lx a1=%" PRIu64 " a2=%" PRIu64 " a3=%" PRIu64 " a4=%" PRIu64 "\n",
"Syscall %s number %" PRId64 "/0x%" PRIx64 " a1=%" PRIu64 " a2=%" PRIu64 " a3=%" PRIu64 " a4=%" PRIu64 "\n",
sdesc->name, syscall_num, syscall_num, a1.as_u64(), a2.as_u64(), a3.as_u64(), a4.as_u64());

#endif
Expand Down Expand Up @@ -787,7 +787,8 @@ int OsSyscallExceptionHandler::syscall_default_handler(
const rv_syscall_desc_t *sdesc = &rv_syscall_args[syscall_num];
#if 1
printf(
"Unimplemented syscall %s number %ld/0x%lx a1 %ld a2 %ld a3 %ld a4 %ld\n", sdesc->name,
"Unimplemented syscall %s number %" PRId64 "/0x%" PRIx64 " a1 %" PRId64
" a2 %" PRId64 " a3 %" PRId64 " a4 %" PRId64 "\n", sdesc->name,
syscall_num, syscall_num, a1, a2, a3, a4);

#endif
Expand Down Expand Up @@ -1052,7 +1053,7 @@ int OsSyscallExceptionHandler::do_sys_openat(

result = 0;
if (int64_t(a1) != TARGET_AT_FDCWD) {
printf("Unimplemented openat argument a1 %ld", a1);
printf("Unimplemented openat argument a1 %" PRId64, a1);
if (unknown_syscall_stop) { emit core->stop_on_exception_reached(); }
return TARGET_ENOSYS;
}
Expand Down

0 comments on commit 4f3f5a7

Please sign in to comment.