Hi,
I've tried to build nimkernel (https://github.com/dom96/nimkernel), a tiny OS kernel written in nim & compiled with --os:standalone. It fails with this error message. I have asked there but seems like the project has been abandoned, and since it concerns nim in general and other projects wanting to write bare metal applications, I have decided to ask you guys too.
Looks like we need a new implementation of appendString() to get it to run, but tried to write a stub with two strings and string as return which did nothing.
Any help?
Try to compile with --gc:arc --os:any -d:useMalloc or with --os:any -d:StandaloneHeapSize=1048576 (heap of 1 MB). But I don't remember what nimkernel uses and needs.
Same errors with nim 1.2.0 (the oldest version I was able to get, 1.1.0 gives a 404)
There is no 1.1.0, it would be the 1.0.x line.
Thanks, I tried JackOS now - they fixed the first issue but I get another one:
Error: system module needs: nimErrorFlag
Afaik we don't yet have a more advanced kernel around in Nim, do we?
Hmm, I hoped maybe somebody already ported nim to another architecture not supported by mainline and left some notes about. Like what procedures I need to implement first to have a basic set of nim functions up and running (I see, the StandaloneHeapSize already fixes much, but to go dynamic). Guess I'll just need to read the source.
My next experiment will be a x86_64 kernel in nim. Using an asm base to go from multiboot to long mode and then jump into nim.
How do I get nim to create .o files, and are they self-containing or do I need to compile and link some library files too? I read about nimcache but nim -c c doesn't create it for me or files get deleted after compilation completed. Found ~/.cache/nim, is this where I need to look?
Hmm, I hoped maybe somebody already ported nim to another os/architecture not supported by mainline and left some notes about.
That happened multiple times already, for example Nim was ported and does support Haiku. It also runs on bare metal that offers IO routines via Ansi C's facilities. Unfortunately it doesn't help you all that much as you're still struggling with the Nim compiler.
How do I get nim to create .c or .o files, and are they self-containing or do I need to compile and link some library files too? I read about nimcache but nim -c c doesn't create it for me or files get deleted after compilation completed. Found ~/.cache/nim, is this where I need to look?
Yes but you can also simply set --nimcache:dir via the command line. The C files are self-containing.
Hmm, I hoped maybe somebody already ported nim to another os/architecture not supported by mainline and left some notes about. Like what procedures I need to implement first to have a basic set of nim functions up and running (I see, the StandaloneHeapSize already fixes much, but to go dynamic). Guess I'll just need to read the source.
The recent FreeRTOS port brought me down that path a bit. I started out tinkering with --os:standalone on Arduino, which can give you a lot of Nim basics (no net stuff, or most of os). You might look at some of the Nim on Arduino projects. Though you should try playing with --os:any as well as --os:standalone as you get basic support up. Also you'll probably want --threads:off as it expects locks on malloc bits, IIRC.
Here's one good writeup on barebones Arduino: nim-on-adruino. Though now you can use --gc:arc with the standaloneheap settings. I found it useful just to open nim/ sources and grep for various things. A lot of the important parts seem to be in either alloc.nim or osalloc.nim. I never did need to find the panic stuff. The os.nim file contains a lot of things on how the system wraps files, time, etc.
The Nim codebase is refreshlingly straightforward for all it includes. You also don't need to recompile the Nim compiler if you modify the standard library! Just note that you'll mostly want to look in the standard library sections, not the compiler portions. Though the compiler portions can be handy to figuring out which defines to pass (eg like cpu16 can be useful for Arduino targets).
Happy living the bare-metal lifestyle.