in reply to Accessing Memory-mapped I/O

Would you please provide the smallest snippet of code that doesn't work, so that we can reproduce the problem to better understand it?

Adding the C example showing it working would be of benefit as well.

Replies are listed 'Best First'.
Re^2: Accessing Memory-mapped I/O
by Anonymous Monk on Oct 31, 2019 at 16:39 UTC

    Here is a snippet of perl code:

    open(FH, "<", "/dev/mem"); binmode(FH); seek(FH,0xff230180,0); #Fails with bad address

    Here is a snippet of C code:

    devmem_fd = open("/dev/mem", O_RDWR | O_SYNC); bridge_map = (uint32_t*)mmap(NULL, 0x100, PROT_READ|PROT_WRITE, MAP_SHARED, devmem_fd, 0xff230180); reg = (uint32_t*) bridge_map; printf("Register contents: 0x08x\n", *reg); munmap (bridge_map, 0x100); close(devmem_fd);

      You're doing two completely different thing between the Perl code and the C code. Does the C code still work when using seek? Does the Perl code work when using (for example) File::Map?

        I have not tried C code using seek. Nor have I tried File::Map on my limited system as I don't have access to File::Map. CPAN is not functioning to install it.