[Libre-soc-bugs] [Bug 982] Support PowerPC ABI in ISACaller

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Mon Sep 18 03:53:24 BST 2023


https://bugs.libre-soc.org/show_bug.cgi?id=982

--- Comment #40 from Jacob Lifshay <programmerjake at gmail.com> ---
(In reply to Jacob Lifshay from comment #39)
> a fixed address is not necessary, all we need is to allocate a memory block
> and then add the base address of that block to all simulated memory
> operations. if we bind the allocated block to a python buffer object, python
> will do that for us, as well as bounds checking.

e.g.:
import mmap
mem = mmap.mmap(-1, 1 << 32, mmap.MAP_PRIVATE)  # create 4GiB block
print(mem[0x12345])  # read byte at 0x12345
mem[0x6789] = 0x12  # write byte at 0x6789

# emulate mmap helper code
import ctypes
libc = ctypes.CDLL("libc.so.6")
off_t = ctypes.c_long  # valid on ppc64le and x86_64 afaict
libc.mmap.argtypes = [
    ctypes.c_void_p, ctypes.c_size_t, ctypes.c_int,
    ctypes.c_int, ctypes.c_int, off_t]
libc.mmap.restype = ctypes.c_void_p
MAP_FIXED = 0x10

# emulate mmap
addr = pick_free_addr()
p = ctypes.c_char.from_buffer(mem, addr)
r = libc.mmap(p, MAP_FIXED, ...)
if r != p:
    return make_error_from_errno()
return addr

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the libre-soc-bugs mailing list