Is there a way to call functions defined in linked assembly? The goal is to wright a kernel with low-level stuff like input/output in assembly and just build on top of it so that all the platform dependent code is assembly and crystal simplifies it for the user from there in a non-platform dependent way.
Kernel development requires stuff you can’t have with Crystal. The first thing that comes to mind: you can’t have a garbage collector popping anytime while you do low-level stuff, or it could be hazardous for your hardware.
There are ways to write crystal without GC. I am not sure if you would want to. But you could write an OS and use GC but then write the lower level stuff without GC.
If your linked assembly exposes symbols to the linker and follows the C call convention, you can just treat it like any other linked library and add a
lib definition for it.
Thanks for the replies!
@karchnu doesn’t --prelude=empty disable the GC allong with any standard libraries (I just kind of assumed this ig). If it doesn’t how do I disable it?
@jhass that sounds like a good option! The lib defenition I can check Crystals DOCs for but is there any special way to write the Assembly functions? How can I expose symbols to the linker?
(Sry I know this topic is a bit more Assembly than Crystal)
Sorry I don’t know that much about it either :) I guess worst case you can also use inline assembly like so: https://github.com/crystal-lang/crystal/blob/master/src/fiber/context/x86_64.cr#L18
thanks for the reply!
after a quick look at your link these are my thoughts:
i prefer to avoid vibers as they are usually platform specific. inline assembly is possibly (maybe even likely, more info would be appreciated) “doable” but my top priorty is to make porting to new platforms as easy as possible so that is more important. also are multiboot headers possible in inline asm?