grub源代码中的grub/machine include目录是什么?

huangapple go评论61阅读模式
英文:

What is the grub/machine include directory in GRUB source code?

问题

我一直好奇 GRUB 2 是如何工作的。在阅读其源代码时,我看到了一些 #include 指令,其中包含了看似不存在的 "grub/machine/...",例如在 grub-core/boot/i386/pc/boot.S 引导加载程序文件中有以下代码:

#include <grub/machine/boot.h>

看起来,它提供了一些与体系结构相关的宏,我目前的猜测是,在针对特定体系结构进行编译时,它是从 include/grub 中的文件和宏的混合物中创建的(例如,#include <grub/machine/boot.h> 可能直接从 include/grub/i386/pc/boot.h 复制而来,这可以通过在 boot.S 中查看宏引用和在 i386/pc/boot.h 中查看相应的定义来假设),但是我对我的假设非常不确定,因为我未能找到任何关于这方面的文档或文章。此外,我无法理解,如果我的假设至少在某种程度上是正确的,为什么 include/grub 中的一些目录不仅不相似(例如,没有一些共同的文件,如 arm/ 有其自己的 boot.h),而且在某些情况下完全不同,这从我的角度看似乎是违反直觉的。

我将很高兴得到关于这些幕后发生的真正情况的解释,因为我正试图自己学习内核开发。

英文:

I have always wondered how does GRUB 2 work. While reading it's source code, I saw that there are some #include directives which include seemingly nonexistent "grub/machine/...", for example in grub-core/boot/i386/pc/boot.S bootloader file there is

#include &lt;grub/machine/boot.h&gt;

As it seems, it provides some architecture-specific macros, and my current guess is that it is created from sort of a mixin of files and macros from include/grub when compiling for a specific architecture (e.g. #include &lt;grub/machine/boot.h&gt; might be directly copied from include/grub/i386/pc/boot.h, which I can assume by looking at macro references in boot.S and corresponding definitions in i386/pc/boot.h), but I am very unsure about my assumption as I have failed to find any documentation or article about that. Also I'm failing to understand, in case my assumptions are at least somewhat correct, why are some directories in include/grub not just not similar to eachother (with, for example, having some files in common, like arm/ having it's own boot.h), but, in some cases, completely different, which seems counterintuitive from my perspective.

I would be glad to get some explanation on what is really going on behind those curtains as I'm trying to learn kernel development myself.

答案1

得分: 1

在./configure.ac中,有这一行

AC_CONFIG_LINKS([include/grub/machine:include/grub/$cpudir/$platform])

这一行在我在我的机器上运行了./autogen.sh && ./configure && make之后,创建了一个符号链接到正确的CPU架构../../include/grub/i386/pc。在该目录中将包含依赖于架构的boot.h文件。

我发现运行一些本地构建命令可以更容易理解这样的存储库。

英文:

In ./configure.ac, there is this line

      AC_CONFIG_LINKS([include/grub/machine:include/grub/$cpudir/$platform])

That line creates a symlink to the right CPU architecture ../../include/grub/i386/pc after I ran ./autogen.sh &amp;&amp; ./configure &amp;&amp; make on my machine. Inside of that directory will be the architecture dependent boot.h file.

I find it easier to understand repos like this running some of the build commands locally.

huangapple
  • 本文由 发表于 2023年6月18日 19:16:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76500256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定