cartesi/machine-emulator

Expose pma address ranges in Lua binding

Closed this issue · 1 comments

Context

The proliferation of hard-coded start address and length of pma ranges in Lua programs is an inconvenience that can be solved by exposing all relevant values in the Lua binding of the Cartesi Machine.

Possible solutions

Expose in the Lua binding of the Cartesi Machine all start addresses and lengths of pmas currently defined in pma-defines.h

I think this issue is related to #47. The way I see it, we should have code that works like this:

for pma in m:get_pmas() do
    print(pma.start)
    print(pma.length)
    print(pma.name)
    print(pma.flags.DID)
    print(pma.flags.W)
    print(pma.flags.R)
    ...
end

and similar code for C++, C, and jsonrpc. What do you think? That way you could do, in C++, for example

    const auto &pmas = m.get_pmas();
    if (const auto tlb = std::find_if(std:begin(pmas), std::end(pmas), [](auto &pma) { return pma.DID == DID_TLB; }); it != std::end(pmas)) {
        std::cerr << tlb->start << std::endl;
    }

Or some such.