Creating a tiny operating system in Mojo #3334
Replies: 1 comment 1 reply
-
This also links to this topic. LLVM already supports a myriad of objects files and it would be great if the mojo compiler to support to compile to specific object file format. That also include for example compile to elf32 on a desktop x64 platform for cross compilation. Another option that is missing is the partial compilation (usually stated by -c in other compilers) which means that it only compiles the source file in question without inserting main. It would be absolutely great to add these features as it also enables integration into Compiler Explorer like godbolt.org. There people can make small Mojo code snippets in order to investigate the output (MLIR, LLVM IR and assembler). |
Beta Was this translation helpful? Give feedback.
-
This weekend I tried to create a tiny operating system in Mojo as a proof of concept. This proof of concept could greatly increase the language's reputation, placing it in a select group of elite system languages that very few languages such as rust and C/C++ belong to.
When reading the documentation, apparently Mojo has almost everything I need, for example, writing directly to a specific memory address using the UnsafePointer.
However, some compilation options are not yet available so that the generated kernel object (generated from Mojo) cannot properly link to boot object (generated from Assembly) generating a final kernel binary image to be emulated in QEMU.
So I list these missing features:
A compiler option to emit LLVM IR (
--emmit-llvm
, or another name) and another one to generate object files (--binary-format=elf32
, or another name). This allows you to customize the linking of object files into binaries, changing the entry point, etc. Feature request: 3337 and 3338A decorator to disable the obfuscation of a function name (
@no-mangle
, or another name), so that the boot binary written in assembly calls the main kernel function (k_main
, for example) by the original name that was written. Feature request: 3339. Update: It already there's the@export
decorator.An option in the compiler that make the binary not dependending of external operating system to work (
--freestanding
, or another name) which is present in C compilers(clang -ffreestanding -c my_program.c).
In the context of C compilers, "freestanding" refers to a program that is compiled to run in a bare-metal environment or an embedded system, where there might not be full support for all standard libraries and functionalities expected in a "hosted" environment, like a complete operating system. In a freestanding environment, the only mandatory functionalities from the standard library are those defined in section 4 of the C standard specification, which include the minimum functionalities necessary for compiling programs. For example, functions likeprintf
,malloc
, orexit
are not guaranteed to be available. Feature request 3370A built function to write inline assembly (to write device drivers). Feature request 3385 Update: It already there's the
inlined_assembly
function where examples were posted in the original feature request issue.In my research, I did not find these options. If they already exist, please kindly say to me where I can find them. Otherwise, it would be interesting if Modular could prioritize these features that are common in many compilers.
Beta Was this translation helpful? Give feedback.
All reactions