How to compile a simple multiboot2 bare-metal executable?

安稳与你 提交于 2019-12-25 04:07:34

问题


I want to start to write an os kernel, and then, i found a document introducing multboot2 spec.

There are three example code files, named boot.S, kernel.c and multiboot2.h, belonging to the multiboot2 branch of grub project.

Firstly, i tried to compile and link the code with some option (using i686-elf-gcc) such as -nostartfiles, -nodefaultlibs and -ffreestanding, but qemu showed me the format was error.

And then i found a file named Makefile.am, and the compiler option in this file is -fno-builtin -nostdinc -O -g -Wall, and the linker option in this file is -nostdlib -Wl,-N -Wl,-Ttext -Wl,80100000 -Wl,--build-id=none.

So i built the kernel with options above, and qemu started to booting the kernel(qemu-system-i386 -kernel kernel). But the kernel traped into infinite loop immediately.

So i cloned the branch of the project, and used gnulib to generate some files and started make but got some errors.

I don't show the error message here, because reading the document, i see what i need to do is just transforming boot.S to binary file and pasting it in the front of the compiled and non-linked kernel file(kernel.o), isn't it? How to complete it?


回答1:


This is trivial. Here's a how-to get a multiboot2 bare-metal executable set up using grub.

https://os.phil-opp.com/multiboot-kernel/

Try running the bare executable with -kernel and it will fail.

Try running the ISO containing grub and it will work.



来源:https://stackoverflow.com/questions/40714127/how-to-compile-a-simple-multiboot2-bare-metal-executable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!