Linux x86上:哪里是实模式地址空间保护的内核模式映射到? [英] Linux x86: Where is the real mode address space mapped to in protected kernel mode?

查看:321
本文介绍了Linux x86上:哪里是实模式地址空间保护的内核模式映射到?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在x86平台上运行Linux,是实模式地址空间映射到受保护的内核模式?在内核模式中,一个线程可以直接访问内核地址空间。内核是在较低8MB,所述页表是在一定的位置,等等(如描述的这里)。但是,在没有实模式地址空间中去?它可以被直接访问?例如BIOS和BIOS插件(请参见这里)?

In Linux running on an x86 platform where is the real mode address space mapped to in protected kernel mode? In kernel mode, a thread can access the kernel address space directly. The kernel is in the lower 8MB, The page table is at a certain position, etc (as describe here). But where does the real mode address space go? Can it be accessed directly? For example the BIOS and BIOS addons (See here)?

推荐答案

(我的x86福是有点弱,我会添加一些标记,以便其他人可以(希望)纠正我,如果我躺在任何地方。)

物理地址是在实模式和保护模式是相同的。唯一的区别是在你如何从一个地址(偏移)中的指令指定一个物理地址获得:

Physical addresses are the same in real and protected mode. The only difference is in how you get from an address (offset) specified in an instruction to a physical address:


  • 在实模式下,物理地址基本上是(segment_reg<< 4)+偏移

在保护模式下,物理地址是 translate_via_page_table([segment_reg] +偏移量)

In protected mode, the physical address is translate_via_page_table([segment_reg] + offset).

通过 [segment_reg] 我的意思是段的基址,在的全局或局部描述符表在 segment_reg >。 translate_via_page_table()表示通过分页进行(如果启用)地址转换。

By [segment_reg] I mean the base address of the segment, looked up in the Global or Local Descriptor Table at the offset in segment_reg. translate_via_page_table() means the address translation done via paging (if enabled).

这里,似乎BIOS ROM出现在物理地址0x000F0000- 0x000FFFFF。为了获得在寻呼保护模式的记忆,你将不得不通过它树立正确的某处映射到虚拟地址空间页表项。假设4 KB页(通常情况下),映射整个范围应需要16((0xFFFFF-0xF0000 + 1)/ 4096)的条目。

Looking here, it seems the BIOS ROM appears at physical addresses 0x000F0000-0x000FFFFF. To get at that memory in protected mode with paging, you would have to map it into the virtual address space somewhere by setting up correct page table entries. Assuming 4 KB pages (the usual case), mapping the entire range should require 16 ((0xFFFFF-0xF0000+1)/4096) entries.

要看看Linux内核是如何做的事情,你可以看看如何如的/ dev / MEM ,它允许任意物理地址的阅读,实现的。实现在的司机/字符/ mem.c

To see how the Linux kernel does things, you could look into how e.g. /dev/mem, which allows reading of arbitrary physical addresses, is implemented. The implementation is in drivers/char/mem.c.

下面的命令(例如从这个答案)将转储内存范围0xC0000-0xFFFFF(这意味着它包括视频BIOS也一样,每个内存映射上面链接):

The following command (from e.g. this answer) will dump the memory range 0xC0000-0xFFFFF (meaning it includes the video BIOS too, per the memory map linked above):

$ dd if=/dev/mem bs=1k skip=768 count=256 > bios

1024 * 768 = 0xC0000,和1024 *(768 + 256) - 1 = 0xFFFFF,这给预期物理存储器范围

1024*768 = 0xC0000, and 1024*(768+256) - 1 = 0xFFFFF, which gives the expected physical memory range.

追踪事情有点, read_mem()中的司机/字符/ mem.c 的通话 xlate_dev_mem_ptr(),它在的弓/ 86 / MM / ioremap.c 。在在函数ioremap_cache()通话似乎是负责,如果需要的页面的映射。

Tracing things a bit, read_mem() in drivers/char/mem.c calls xlate_dev_mem_ptr(), which has an x86-specific implementation in arch/x86/mm/ioremap.c. The ioremap_cache() call in that function seems to be responsible for mapping in the page if needed.

注意,BIOS例程将不通过的方式在保护模式下运行。他们假设CPU在实模式中运行。

Note that BIOS routines won't work in protected mode by the way. They assume the CPU is running in real mode.

这篇关于Linux x86上:哪里是实模式地址空间保护的内核模式映射到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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