vladturcuman · GitHub

Adding a runtime variant for bare metal and gating most OS-dependent parts on not bare metal. It forces single domain, no threads or signals, has no-op mutexes and malloc-based memory mapping.

The runtime is meant to provide the minimum necessary surface with no-op stubs for the necessary but not relevant functions. At a minimum the user needs to provide:

  • a uint64_t caml_bare_metal_time_ns(void)
  • a platform which include:
    • read and write for fds 0-2, all the other fail with ENOSYS
    • malloc, realloc and free
    • abort and exit
    • a libm and standard memory/string/stdio functions.

Testing:

  • Compiled and linked a hello world minimal Ocaml and an open! Core. For Core some extra ENOSYS stubs were needed. Both ran successfully on the hardware with stdout and stderr over UART.

Potential problems:

  • compiles the runtime with -march=armv8-a -mtune=cortex-a72. Maybe this should be an external flag/target? Or make the runtime croscc compiled against a aarch64-none-elf-gcc--this would also remove the glibc/newlib conflicts.
  • the runtime is compiled for every build. Maybe this should be gated by target and make --enable-runtime-baremetal defaulting to off?
  • getenv returns NULL which makes the runtime untunable for things like fiber/thread stack sizes. It currently defaults to 8Mb which might be unsuitable for small embedded devices.

Read the original on github.com ↗