简体   繁体   中英

C Compiler in Bios/Real Mode?

So, i want to program an OS. The bootloader is written in assembly. Now i do the Kernel but it is possible to write it in C? I Tried it on gcc -S but im on windows and the outputfile is: .file "Kernel.c".text.ident "GCC: (MinGW.org GCC Build-2) 9.2.0"

The "Watcom" compiler supports Real-Mode code. You can even select 8086 as target CPU (however, you can also chose 80286 or 80386).

The compiler supports segmented code, too.

However, at least the old version 10.6 only supports the old OMF object file format (later versions seem to support COFF, but I doubt that COFF is supported for segmented code).

This object file format is quite tricky to convert to a better readable file format.

If your kernel is less than 64K in size, you may create a "DOS COM" file (supported by the compiler).

It is a rather complicated process - but provided you have access to gnu-binutils you can use objcopy:

gcc -c -m16 -Os -ffreestanding -Wall -Wextra -fno-exceptions -o main.o main.c 
ld -melf_i686 -static -nostdlib --nmagic -Ttext 0x1000 -o boot/kernel_entry.elf main.o
objcopy -Obinary boot/kernel_entry.elf kernel.bin

This should output a binary which you can execute using qemu

If you need an example then you can find a good example project with makefile here: https://github.com/cfenollosa/os-tutorial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM