I've been experimenting with writing very basic operating system-like programs on the Arduino, and so far I have been running user-defined programs on a small virtual machine I wrote. This has been an interesting experience, but the VM runs on an assembly-like language and not C.
I want to be able to do something more. I would like to be able to write a core OS, and then install new programs, written in C. The core OS would get user input for which program to run, and then jump to that program.
Now, I know that I can do this trivially by writing the OS along with all of the programs into a single sketch. The programs are then just functions, and the OS just calls those functions. However, I want to do this with functions I've written after I've burned the main OS.
From what I can tell, this is just a bootloader with additional user functionality. However, I don't think that's quite right for two reasons:
First, I keep hearing that you can't write to progmem at runtime. But isn't that what a bootloader does? Which is correct?
Second, once a user program ends, I should return to the OS. As far as I understand it, on the ATMega, once the main function terminates it jumps into a no-operation function and that's that. I'd need it to jump back to the bootloader and continue the bootloader's operation. Is that even possible?