diff --git a/sdbuild/boot/meta-pynq/recipes-apps/pynq-cpp/files/cpp/mmio.cc b/sdbuild/boot/meta-pynq/recipes-apps/pynq-cpp/files/cpp/mmio.cc index 17d99248c..59312505b 100644 --- a/sdbuild/boot/meta-pynq/recipes-apps/pynq-cpp/files/cpp/mmio.cc +++ b/sdbuild/boot/meta-pynq/recipes-apps/pynq-cpp/files/cpp/mmio.cc @@ -5,9 +5,9 @@ MMIO::MMIO(off_t base_address, size_t length_p) : mem_fd(-1), virt_base(0), virt_offset(0), length(0), mapped_base(nullptr) { - if (base_address < 0 || length_p < 0) + if (length_p < 0) { - std::cerr << "Error: Base address or length cannot be negative." << std::endl; + std::cerr << "Error: Length cannot be negative." << std::endl; return; } mem_fd = open("/dev/mem", O_RDWR | O_SYNC); @@ -17,7 +17,7 @@ MMIO::MMIO(off_t base_address, size_t length_p) return; } virt_base = base_address & ~(4096 - 1); - virt_offset = base_address - virt_base; + virt_offset = base_address & (4096 - 1); length = length_p; mapped_base = mmap(nullptr, length + virt_offset, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, virt_base); @@ -70,4 +70,4 @@ void MMIO::write(uint32_t data, uint64_t offset) std::cout << "MMIO Write to " << static_cast(mapped_base) << " Data: " << data << " Offset: " << offset << std::endl; #endif ptr[idx] = data; -} \ No newline at end of file +}