3 ms·
I have made a codebase where all the C and C++ glue is already taken care of, as well as the build system: https://github.com/fwsGonzo/barebones https://github
by fwsgonzo 7y ago
I have made a codebase where all the C and C++ glue is already taken care of, as well as the build system:
https://github.com/fwsGonzo/barebones https://github.com/fwsGonzo/barebones
However, nothing else. So it's a starting point for a beginner. I don't know if its the perfect starting point or not, but at least you won't be stuck with all the setup. If you are writing an OS in another language you can probably get some inspiration as well, as for example I did implement basic ubsan support.
Some fun facts:
There is a C++ exceptions example that shows that with the compiler runtime as well as a libunwind you can catch C++ exceptions, but only if you create the exception fully yourself, as there is no standard library. It does add a bit of bloat, so it's not really intended for OS development.
There is an example of how to runtime load a library, and call into it. No runtime linking, just an exchange of call table.
There is very primitive backtrace functionality in the panic function simply by using compiler builtins. No way to convert the addresses to function + offset because there is no symbol table. One cool way to do this is to link the kernel, generate an ELF section that contains only the function symbols, and then append it to the end of your kernel. During initialization you can then use it for backtraces. It's also fairly architecture independent, as you will only have to distinguish between 32- and 64-bit symbols.