elf-x86 target successfully running in a freestanding i686 kernel environment #3444
Shagedoorn1
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
elf-x86 target successfully running in a freestanding i686 kernel environment
I'm building my own hobby OS, Phonon. It is a 32 bit x86 OS.
I've been interested in C3 for a while, and noticed that the support matrix in the README lists ELF freestanding x86 as untested.
So I figured: let's just try it.
It works!
The initial test was deliberately simple: a C3 function that calls the kernel's existing
printk()and prints:hello from C3!Although, given that printk is a printf clone that ultimately outputs to both VGA memory and serial, perhaps calling this a "simple print test" is underselling how much kernel machinery is actually involved.
My build scheme is very simple: turn every source file into an object file, then throw all the objects at the linker. No special project structure required.
It took a little bit of experimentation to get
c3cto emit exactly the object files I wanted. Eventually I ended up with:The resulting files are normal ELF32 relocatable objects, which I can feed directly to
i686-elf-ldalongside object files produced by GCC and GAS. The linker resolves everything without any special treatment.C <> C3 works too. The C3 test function calls printk(), which is defined in C, and a C function successfully calls the exported C3 function.
The test executes correctly under both QEMU and VirtualBox, and I've inspected the resulting kernel with both IDA and Ghidra. The generated code looks completely sane and healthy.
For example, the C3 function is just a tiny bit of 32-bit x86 code:
The generated object has the expected ELF32header and normal R_386_* relocations.
So while I obviously haven't tested the entire C3 feature set on this target, basic freestanding ELF32 compilation, C <> C3, linking and execution appear to work quite nicely.
The compiler does still print:
WARNING! This architecture is unsupported.which is quite funny, considering the resulting code is now happily running inside my kernel. :)
Screenshots
All reactions