有人可以解释一下我如何使用来自 grub 的 C 数据结构吗?我不明白 hi mem 和 lo mem

发布于 2024-10-03 19:30:52 字数 1014 浏览 6 评论 0原文

Grub 是一个兼容多重引导的引导加载程序。当它启动操作系统时,它会创建一个定义可用内存的结构,并在内存中留下指向该结构的指针。

我在这里得到了该信息:

http://wiki.osdev.org/Detecting_Memory_(x86)#Memory_Map_Via_GRUB

这是我认为我感兴趣的结构:

 typedef struct memory_map
 {
   unsigned long size;
   unsigned long base_addr_low;
   unsigned long base_addr_high;
   unsigned long length_low;
   unsigned long length_high;
   unsigned long type;
 } memory_map_t;

所以我得到了内存映射结构的集合。正如上面页面提到的,你可以看到 通过在 grub 提示符下键入“displaymem”来查看内存映射。这是我的 输出

但我不完全理解结构......

为什么长度是这样的设置为 0 (0x0)?我必须将低内存和高内存结合起来吗?

它说这些值是 64 位的,所以它是否将“低内存和高内存”组合在一起,如下所示:

__int64 full_address = (low_mem_addr + high_mem_addr);

或者我得到 1 个包含低内存和高内存的列表高地址专门在其中吗?

由于我使用的是 32 位机器,我基本上是否用两个值引用每个唯一地址?

我期待一个地址列表,如 displaymem 显示,但填充了实际长度字段,但我没有看到这一点。有什么我不明白的吗?

Grub is a multiboot compliant boot loader. When it boots an operating system it creates a structure defining the available memory and leaves a pointer to that structure in memory.

I got that information here:

http://wiki.osdev.org/Detecting_Memory_(x86)#Memory_Map_Via_GRUB

This is the structure that I think I'm interested in:

 typedef struct memory_map
 {
   unsigned long size;
   unsigned long base_addr_low;
   unsigned long base_addr_high;
   unsigned long length_low;
   unsigned long length_high;
   unsigned long type;
 } memory_map_t;

So I've got a collection of memory map structures. As the above page mentions, you can see
the memory map by typing "displaymem" at the grub prompt. This is my output

But I don't fully understand the structure....

Why are the lengths set to 0 (0x0)? Do I have to combine low memory and high memory?

It says the values are in 64 bit so did it push together "low mem and high mem" together like this:

__int64 full_address = (low_mem_addr + high_mem_addr);

or am I getting 1 list containing both low and high addresses exclusively in them?

and since I'm using a 32bit machine do I basically refer to each unique address with both values?

I was expecting one single list of addresses, like displaymem shows but with actual length fields populated but I'm not seeing that. Is there something I don't understand?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离鸿 2024-10-10 19:30:52

好吧,基本上它只是两个变量......都是 64 位数字,所以上面的和下面的是相同的!

typedef struct memory_map
 {
   unsigned long size;
   //unsigned long base_addr_low;
   //unsigned long base_addr_high;
   unsigned long long base_addr;
   // unsigned long length_low;
   // unsigned long length_high;
   unsigned long long length; //holds both halves.
   unsigned long type;
 } memory_map_t;

你可以像这样把两半拿出来:

unsigned long base_addr_low = base_addr
unsigned long base_addr_high = base_addr >> 32

问题就是这么简单。 :-s

Ok, basically it's just two variables...that are 64 bit numbers, so what is above and what is below are IDENTICAL!

typedef struct memory_map
 {
   unsigned long size;
   //unsigned long base_addr_low;
   //unsigned long base_addr_high;
   unsigned long long base_addr;
   // unsigned long length_low;
   // unsigned long length_high;
   unsigned long long length; //holds both halves.
   unsigned long type;
 } memory_map_t;

You can get the two halves out like this:

unsigned long base_addr_low = base_addr
unsigned long base_addr_high = base_addr >> 32

The question was just that simple. :-s

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文