[LLVMdev] OS Development

Chris Lattner sabre at nondot.org
Sat Jun 16 01:33:22 PDT 2007


On Fri, 15 Jun 2007, Willow Schlanger wrote:
> I'm interested in developing a 64-bit operating system to run inside a
> version of BOCHS compiled with x86-64 support enabled
> (bochs-2.2.6-x86-64.exe) that I found on the web.
>
> Can I use LLVM as a GCC replacement for OS development? I need to
> generate 64-bit x86-64 assembly language output which I can then
> assemble with the normal 'as' and link via 'ld' commands.

llvm-gcc works as a drop-in replacement for GCC.  By default it produces 
normal native .s files, just like GCC.

> How do I do this? Can I run LLVM inside coLinux under Windows? How do I
> build it from the source and install it and what is the command for a
> GCC replacement (how do I generate x86-64 assembly source from C/C++ files)?

llvm-gcc foo.c -S -o foo.s -O3

> It would be really cool if I could use the LLVM intermediate
> representation in my OS, so all drivers can be supplied in intermediate
> form. The OS will compile the drivers when the driver is first loaded
> and cache the resulting program (after assembling and linking it) to disk.

Sure, this is easy.  You can get llvm-gcc to emit llvm bytecode by adding 
the -emit-llvm option:

llvm-gcc foo.c -c -o foo.bc -O3 -emit-llvm

> This way the back-end can optimize drivers globally (inter-procedural
> analysis) and the back-end can generate code optimized for the current
> machine. If you boot up the OS on a 32-bit PC the SAME driver can be
> used, the IR is simply 'recompiled' (code is generated) for a new target.

Unfortunately, LLVM IR produced by llvm-gcc is not "portable" across 
different architectures.

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list