MOSA Ahead-Of-Time Compiler¶
The MOSA Ahead-Of-Time compiler is used to create native code binaries and bootable kernel images from managed code. The compiler uses the facilities provided by the MOSA Compiler Framework. This wiki page describes the general usage, compiler switches and provides examples of its use:
General Usage¶
The compiler is a command line application, which provides a set of command line switches to control various operations. Use the following example command line to check the availability and version of the compiler.
mosacl
If the compiler is available on your system, the following output should be visible (as of release 0.1)
MOSA AOT Compiler, Version 0.1 'Wake'
(C) 2008 by the MOSA Project, Licensed under the new BSD license.
Usage: mosacl -o outputfile --arch=[x86] --format=[ELF32|ELF64|PE] {--boot=[mb0.
7]} {additional options} inputfiles
Run 'mosacl --help' for more information.
Command Line Switches¶
The compiler command line switches are split into various categories described below. There may be additional switches available in your mosacl version. These are documented if you run mosacl with the -h switch.
General¶
| Switch | Description |
|---|---|
| -a | Sets the compilation target architecture. As of release 0.1 x86 is the only supported target architecture. |
| -h, -?, --help | Displays the full help of all compiler switches available. |
| -o | Sets the output file of the compiler. |
| -v | Displays the mosa compiler version |
Optimizations¶
Linker¶
| Switch | Description |
|---|---|
| -f, --format | Sets the format of the output file to produce. As of release 0.1 this switch can take the values PE, ELF32 or ELF64. The first indicates a portable executable format binary, the second a 32-bit ELF binary and the third is a 64-bit ELF binary. |
| --map | Emits a map file of the generated binary. The map file specifies the file and memory positions of functions, static data members and compiler generated members. |
| --pe-no-checksum | Disables setting the checksum in the generated portable executable file. Note that the checksum is used to verify MOSA kernel images, drivers and other system services. These will not run without a checksum. |
| --pe-file-alignment | Determines the alignment of sections in the generated PE file. This must be a multiple of 512 bytes. |
| --pe-section-alignment | Determines the alignment of sections in virtual memory. This must be a multiple of 4096 bytes. |
Booting¶
| Switch | Description |
|---|---|
| -b, --boot | Indicates that the generated binary is a bootable kernel image. A regular executable is generated without this switch. Release 0.1 only supports the multiboot specification 0.6.95. To use it, specify mb0.7. |
| --multiboot-video-mode | Specifies the video mode to be set by the boot loader before launching the kernel image. The supported values are text or graphics. The support also depends on the boot loader used. |
| --multiboot-video-width | Determines the width of the selected graphics mode in characters (for text modes) or pixels (for graphic modes) |
| --multiboot-video-height | Determines the height of the selected graphics mode in characters (for text modes) or pixels (for graphic modes) |
| --multiboot-video-depth | Specifies the bit depth (number of bits per pixel) of the graphics mode |
| --multiboot-module | Selects an module to be loaded along with the kernel by the bootloader. This switch has the format modulename:*virtual-address*. |
Examples¶
The following examples show the usage of mosacl for certain tasks.
Creating a native portable executable for a managed executable¶
mosacl -a=x86 -f=PE -o name-native.exe name.exe
Generating a map file for a binary¶
mosacl -a=x86 -f=PE --map=name-native.map -o name-native.exe name.exe
Creating a bootable kernel image using the portable executable format using a multiboot compliant bootloader¶
mosacl -a=x86 -f=PE --pe-file-alignment=4096 -b=mb0.7 -o kernel-image.exe kernel.exe
The portable executable format is not supported by most boot loaders. In order to be usable anyways, the file and virtual section alignments must match.