对内存映射感到困惑

发布于 2024-11-19 07:38:20 字数 305 浏览 5 评论 0原文

我最近开始研究低级内容并研究引导加载程序和操作系统等...

据我了解,至少对于 ARM 处理器,外设由引导加载程序初始化,然后将它们映射到物理内存空间。从这里,代码只需将值写入映射到外设寄存器的内存空间即可访问外设。稍后,如果芯片具有 MMU,则可以使用它进一步重新映射到虚拟内存空间。我说得对吗?

我不明白的是(假设我上面所说的是正确的):

  • 如果外设尚未映射到地址空间,引导加载程序如何初始化外设?
  • 对于虚拟内存映射,有一些表告诉 MMU 将什么映射到哪里。但是什么决定了外设在物理内存中的映射位置呢?

I've recently started getting into low level stuff and looking into bootloaders and operating systems etc...

As I understand it, for ARM processors at least, peripherals are initialized by the bootloader and then they are mapped into the physical memory space. From here, code can access the peripherals by simply writing values to the memory space mapped to the peripherals registers. Later if the chip has a MMU, it can be used to further remap into virtual memory spaces. Am I right?

What I don't understand are (assuming what I have said above is correct):

  • How does the bootloader initialize the peripherals if they haven't been mapped to an address space yet?
  • With virtual memory mapping, there are tables that tell the MMU where to map what. But what determines where peripherals are mapped in physical memory?

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

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

发布评论

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

评论(3

極樂鬼 2024-11-26 07:38:20

当设备启动时,MMU 会关闭,您通常会在管理模式下运行。这意味着提供的任何地址都是物理地址。

每个 ARM SOC(片上系统)都会有一个内存映射。地址与设备的对应关系取决于哪些物理数据和地址线连接到处理器的哪些部分。所有这些信息都可以在技术参考手册中找到。对于 OMAP4 芯片,可以在此处找到。

连接片外设备的方法有多种。一种是使用 GPMC。在这里,您需要指定要在芯片上使用的 GPMC 中的地址。

当 MMU 打开时,这些地址可能会根据 MMU 的编程方式而改变。通常,对硬件的直接访问也只能在内核模式下使用。

When a device boots, the MMU is turned off and you will be typically running in supervisor mode. This means that any addresses provide are physical addresses.

Each ARM SOC (system on Chip) will have a memory map. The correspondece of addresses to devices is determined by which physical data and address line are connect to which parts of the processor. All this information can be found in a Technical reference manual. For OMAP4 chips this can be found here.

There are several ways to connect off-chip device. One is using the GPMC. Here you will need to sepcify the address in the GPMC that you want to use on the chip.

When the MMU is then turned on, these addresses may change depending on how the MMU is programmed. Typically direct access to hardware will also only be available in kernel mode.

近箐 2024-11-26 07:38:20

虽然这是一个老问题,但考虑回答这个问题,因为它可能会帮助像我这样的其他人尝试从 stackoverflow 获得足够的答案。

你的解释几乎是正确的,但想对此给出一点解释:
外设由引导加载程序初始化,然后映射到物理内存空间

。片上外设已经具有预定义的物理地址空间。对于其他外部IO映射外设(如PCIe),我们需要配置物理地址空间,但它们的物理地址空间范围仍然是预定义的。它们不能在随机地址空间进行配置。

现在针对您的问题,这是我的答案。
如果外设尚未映射到地址空间,引导加载程序如何初始化外设?

正如我上面提到的,所有(片上)外设都有预定义的物理地址空间(通常会在处理器 RM 的内存映射章节中列出)。因此,引导加载程序(假设 MMU 关闭)可以直接访问它们。

对于虚拟内存映射,有一些表告诉 MMU 将什么映射到哪里。但是什么决定了外设在物理内存中的映射位置呢?

对于 VMM,页表(由内核创建并存储在物理 DRAM 中)告诉 MMU 将虚拟地址映射到物理地址。在具有 1G 内核虚拟空间的 Linux 内核中(例如从 0xc0000000-0xffffffff 的内核虚拟地址),片上外设需要在上述内核 VM 空间内拥有一个 VM 空间(以便内核且只有内核可以访问它);并且将设置页表以将该外设 virt addr 映射到其实际物理地址(RM 中定义的地址)

Though this is an old question, thought of answering this as it might help some others like me trying to get sufficient answers from stackoverflow.

you explanation is almost correct but want to give little explanation on this one:
peripherals are initialized by the bootloader and then they are mapped into the physical memory space

Onchip peripherals already have a predefined physical address space. For other external IO mapped peripherals (like PCIe), we need to config a physical addr space, but their physical address space range is still predefined. They cannot be configured at random address space.

Now to your questions, here are my answers..
How does the bootloader initialize the peripherals if they haven't been mapped to an address space yet?

As I mentioned above, all (on-chip)peripherals have physical address space predefined (usually will be listed in Memory map chapter of processor RM). So, boot loaders (assuming MMU is off) can directly access them.

With virtual memory mapping, there are tables that tell the MMU where to map what. But what determines where peripherals are mapped in physical memory?

With VMM, there are page tables (created and stored in physical DRAM by kernel) that tells MMU to map virtual addr to physical addr. In linux kernel with 1G kernel virt space (say kernel virtual addrs from 0xc0000000-0xffffffff), on-chip peripherals will need to have a VM space from within the above kernel VM space (so that kernel & only kernel can access it); and page tables will be setup to map that peripheral virt addr to its actual physical addr (the ones defined in RM)

终止放荡 2024-11-26 07:38:20

您无法在 ARM 处理器中重新映射外设,所有外设都对应于内存映射中的固定位置。甚至寄存器也被映射到具有永久固定位置的内部 RAM 存储器。您唯一可以通过 FSMC 或类似核心功能重新映射的是 SRAM、FLASH 等存储设备。然而,您可以重新映射不属于核心本身一部分的内存映射附加自定义外设,例如硬盘控制器,但 ARM 核心内部的内容是固定的。

一个好的开始是查看 Philips 和 ST 等公司网站上的处理器数据表,或者浏览 www.arm.com 上的 ARM 架构本身。

You can't remap peripherals in ARM processor, all peripheral devices correspond to fixed positions in memory map. Even registers are mapped to internal RAM memory that has permanent fixed positions. The only things you can remap are memory devices like SRAM, FLASH, etc. via FSMC or similar core feature. You can however remap a memory mapped add-on custom peripheral that is not part of the core itself, lets say a hard disk controller for instance, but what is inside ARM core its fixed.

A good start is to take a look at processor datasheets at company sites like Philips and ST, or ARM architecture itself at www.arm.com.

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