Running another kernel on top of FreeRTOS vs adding a compatibility layer for tasks into FreeRTOS's task scheduler and IPC routines


I’ve been thinking about the possibility of running another kernel as a task on top of FreeRTOS. The motivation for this project is that I would like to possibly port MINIX2 to the ESP32.
The ESP32 has a FreeRTOS port, and it is AFAIK, the only way to access the wifi and bluetooth features on the SoC, and thus to access those features, I’d need to have FreeRTOS running on it as well.

The overall goal I have in mind is to run MINIX2 as a task on FreeRTOS. To accomplish this, I can see 2 possible options.

The first option, which is that once the MINIX kernel is started as a FreeRTOS task, it handles context switching, task scheduling, and interprocess communications for all MINIX processes. To do this however, it seems that I would need to be able to directly access the CPU’s registers from the context of the FreeRTOS task, so that MINIX can save the context of every job it is scheduling, and to be able to copy tasks into memory, and begin executing said tasks; thus direct access to the program counter, stack pointer, etc would be seemingly necessary. I would also need a way to pass interrupts from the CPU or perhaps accept signals from FreeRTOS, to change jobs when a time quantum is exhausted for a task.

The alternative is to write a compatibility layer into FreeRTOS’s task scheduler and interprocess communications, to support MINIX task communications. Thus, every “MINIX” job would in fact be a FreeRTOS task, but with special decorations such that interprocess communications, system calls, etc, would from the perspective of the task, look like it was running on MINIX anyways. The apparent disadvantage of this is that I’d need to implement a complete POSIX layer for FreeRTOS, such as fork(), exec(), which from what I’ve read, is not available for FreeRTOS (as they are fairly memory heavy, though the ESP32 does have 4MB of ram).

My reference text for MINIX2 has been Operating Systems Design and Implementation 2nd ed by Tannenbaum and Woodhull for what its worth, and my FreeRTOS reference text has been the Mastering the FreeRTOS™ Real Time Kernel by Richard Barry.

What would be the most practicable option of these 2? Is there a better alternative option? Has anyone tried something like this before (ie turning FreeRTOS into a hypervisor for some other kernel?)?


We have not used FreeRTOS as hypervisor and I think there will be some issues as both the OSes will try to the touch the same set of hardware registers (PC, SP et.).

Have you thought about porting MINIX to ESP32? You will need to take WiFi and BLE stacks from ESP-IDF and change the FreeRTOS APIs to corresponding APIs from MINIX.