Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add platform abstraction layer to parameterise for different platforms #9

Open
TomKeddie opened this issue Jun 23, 2019 · 1 comment

Comments

@TomKeddie
Copy link
Contributor

Need to be able to parameterise the software to allow the same s/w binary to run on different platforms.

An incomplete list would be

  • USB PID/VID
  • FPGA bitstream header used to search for valid images
  • LED capabilites
  • User input capabilities (touch vs. button)

Some/all of this could come from a litex platform capabilities mechanism.

@TomKeddie
Copy link
Contributor Author

@xobs moving conversation from #7 to this issue. Quoting the whole response here for continuity.

I was having a chat with @mithro, and the idea came up to use a thunked syscall interface.

The idea being that you'd have a function at a well-known address, or an address defined in a LiteX CSR, or an address defined in a RISC-V MSR, that has a function signature such as:

int syscall(uint32_t family, uint32_t syscall, uint32_t arg1, void *arg2);

...or similar. Maybe the params would be different. But we'd define family and syscall as enum pairs. For example, "reboot" might be in the "system" family. Using 32-bit IFF-style tags, such a call might be:

syscall('syst', 'boot', 0x20040000, NULL);

Because the boot ROM is currently always memory-mapped, we could fix it at address 0x100, so any machine-level program could cast that value to a function pointer and make syscalls.

Then, as part of the BIOS for various platforms, you'd implement syscall:

__attribute__((section(".text.syscall")))
int syscall(uint32_t family, uint32_t call, uint32_t arg1, void *arg2) {
    switch (family) {
        case 'syst':
            return do_syst(call, arg1, arg2);
        default:
            return -EIMPL;
    }
}

static int do_syst(uint32_t call, uint32_t arg1, void *arg2) {
    switch (family) {
        case 'boot':
            return do_reboot(arg1);
        default:
            return -EIMPL;
    }
}

Agreed, we could also define inlines/macros to make the code more readable.

syscall('syst', 'boot', 0x20040000, NULL);
could become
syscall_syst_boot(0x20040000);

Once we have the i/o for the bootloader defined in this manner we can take a look at defining some platform i/o for micropython. Stuff like rgb would be platform specific but we can define a very basic interface that exposes n buttons, n leds and a set of n io pins. On fomu the buttons could be touch under the hood. We'd also want to look ahead to circuitpython and make sure we can define an optional platform i2c in some manner too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant