titzer / virgil

A fast and lightweight native programming language
1.13k stars 40 forks source link

Feature: Compile to standalone x86_64 code for bare metal. #251

Open ApplePieCodes opened 2 weeks ago

ApplePieCodes commented 2 weeks ago

If possible, could you attempt to implement this feature. It would make Operating System Development much easier.

titzer commented 2 weeks ago

Interesting, and not too far-fetched. Currently the compiler can produce ELF and Mach-O x86-64 binaries. In both cases, the compiler inserts only a little bit of startup asm code, and the rest of the runtime system and GC is written in Virgil. There are a handful of syscalls in the compiler-inserted asm code to set up signal handling and the stack, but the rest is in Virgil using Linux.syscall or Darwin.syscall. So switches to turn off that would allow generating a standalone ELF file, which a bootloader could load into memory.