如何编译一个简单的multiboot2裸机可执行文件? [英] How to compile a simple multiboot2 bare-metal executable?

查看:746
本文介绍了如何编译一个简单的multiboot2裸机可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开始编写一个os内核,然后,我发现一个文档引入multboot2规范。

有三个示例代码文件,名为 boot.S kernel.c multiboot2.h ,属于分支中的 multiboot2 分支首先,我试着用一些选项(使用i686-elf-gcc)来编译和链接代码,比如<$ c> $ c> -nostartfiles -nodefaultlibs -freestanding ,但qemu向我展示了格式是错误的。

然后我找到一个名为 Makefile.am 的文件,并在此文件中编译选项是 -fno-builtin -nostdinc -O -g -Wall ,并且此文件中的链接器选项是 -nostdlib -Wl,-N -Wl ,-Ttext -Wl,80100000 -Wl, - build-id = none



所以我用上面的选项构建了内核, qemu开始启动内核( qemu-system-i386 -kernel kernel )。所以我克隆了项目的分支,并使用gnulib来生成一些文件,并开始 make 但出现了一些错误。

这里没有显示错误信息,因为阅读文档,我看到我需要做的只是将 boot.S 转换为二进制文件并将其粘贴到已编译和未链接的内核文件的前面( kernel.o ),不是吗?如何完成它?

解决方案

这是微不足道的。下面是一个如何使用grub设置multiboot2裸机可执行文件。

-kernel /rel =nofollow noreferrer> https://os.phil-opp.com/multiboot-kernel/



尝试运行bare可执行文件 -kernel ,它会失败。



尝试运行包含ISO的ISO,它会起作用。


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?

解决方案

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.

这篇关于如何编译一个简单的multiboot2裸机可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆