[英]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?
现在我做了 Kernel 但可以将它写在 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"
我在 gcc -S 上试过,但我在 windows 上试过,输出文件是: .file "Kernel.c".text.ident "GCC: (MinGW.org Z32D8B233E3C58A262A0B7582729.9.D58)9.
The "Watcom" compiler supports Real-Mode code. “Watcom”编译器支持实模式代码。 You can even select 8086 as target CPU (however, you can also chose 80286 or 80386).
您甚至可以将 select 8086 作为目标 CPU(但是,您也可以选择 80286 或 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).不过至少老版本10.6只支持老的OMF object文件格式(后面的版本好像支持COFF,但是我怀疑分片代码是否支持COFF)。
This object file format is quite tricky to convert to a better readable file format.这种 object 文件格式很难转换为可读性更好的文件格式。
If your kernel is less than 64K in size, you may create a "DOS COM" file (supported by the compiler).如果您的 kernel 的大小小于 64K,您可以创建一个“DOS COM”文件(编译器支持)。
It is a rather complicated process - but provided you have access to gnu-binutils you can use objcopy:这是一个相当复杂的过程 - 但如果您可以访问 gnu-binutils,您可以使用 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这应该是 output 一个可以使用 qemu 执行的二进制文件
If you need an example then you can find a good example project with makefile here: https://github.com/cfenollosa/os-tutorial如果你需要一个例子,那么你可以在这里找到一个带有 makefile 的很好的示例项目: https://github.com/cfenollosa/os-tutorial
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.