OS Development

Hi,
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.

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)?

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.

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.

Obviously there will be some drivers that must be pre-built, such as those that run early in system initialization and those that are specific to the architecture, e.g. some low-level memory management etc.

Any thoughts?

Thanks,
Willow

You still have to know the sizes of datatypes, calling convention,
etc, on various platforms, if you want it to interoperate. LLVM IR
won't help you with that.

Compiler IR's rarely make a good match for direct coding of
applications/drivers, even if they are as nice as LLVM's IR.

:slight_smile:

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

Hi Chris, thanks for the comments.

Does LLVM support cross-compiling, e.g. can I use the x86-64 backend to generate 64-bit assembly sources, on a 32-bit Linux installation? I am using coLinux on Windows (Debian-based) and creating a gcc cross compiler failed because it needs a 64-bit native assembler.

Thanks,
Willow

Chris Lattner wrote: