根据页面分割内存的程序寿命 [英] program life in terms of paged segmentation memory

查看:89
本文介绍了根据页面分割内存的程序寿命的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对细分&在x86 linux机器上进行分页.如果有人从头到尾弄清楚所有涉及的步骤,我们将很高兴.

I have a confusing notion about the process of segmentation & paging in x86 linux machines. Will be glad if some clarify all the steps involved from the start to the end.

x86使用分页分段内存技术进行内存管理.

x86 uses paged segmentation memory technique for memory management.

任何人都可以解释一下将可执行的.elf格式文件从硬盘加载到主存储器后到死之前发生的情况.编译后,可执行文件中包含不同的部分(文本,数据,堆栈,堆,bss).如何加载?如何使用分页分段存储技术来设置它们.

Can any one please explain what happens from the moment an executable .elf format file is loaded from hard disk in to main memory to the time it dies. when compiled the executable has different sections in it (text, data, stack, heap, bss). how will this be loaded ? how will they be set up under paged segmentation memory technique.

是否想知道如何为已加载的程序设置页表?想知道如何建立GDT表.寄存器如何加载?以及为什么当它是32位机器时,逻辑地址(由MMU的分割单元处理的逻辑地址为48位(段选择器的16位+ 32位偏移)),其他16位将如何存储?从ram访问的任何东西都必须是32位或4字节,如何访问其余的16位(以加载到段寄存器中)?

Wanted to know how the page tables get set up for the loaded program ? Wanted to know how GDT table gets set up. how the registers are loaded ? and why it is said that logical addresses (the ones that are processed by segmentation unit of MMU are 48 bits (16 bits of segment selector + 32 bit offset) when it is a bit 32 bit machine. how will other 16 bits be stored ? any thing accessed from ram must be 32 bits or 4 bytes how does the rest of 16 bits be accessed (to be loaded into segment registers) ?

先谢谢了.这个问题可能有很多事情.但想弄清楚可执行文件的整个生命周期.如果能找到答案并对此进行讨论,将非常高兴.

Thanks in advance. the question can have a lot of things. but wanted to get clarification about the entire life cycle of an executable. Will be glad if some answers and pulls up a discussion on this.

推荐答案

至少没有官方文档中的分页细分之类的东西.有两种不同的机制协同工作,彼此之间或多或少相互独立:

There's no such thing as paged segmentation, not in the official documentation at least. There are two different mechanisms working together and more or less independently of each other:

  1. 16-bit segment selector value:16/32/64-bit segment offset value形式的逻辑地址(即,两个2对数字)转换为32/64-bit virtual address.
  2. virtual address转换为32/64-bit physical address.
  1. Translation of a logical address of the form 16-bit segment selector value:16/32/64-bit segment offset value, that is, a pair of 2 numbers into a 32/64-bit virtual address.
  2. Translation of the virtual address into a 32/64-bit physical address.

逻辑地址是您的应用程序直接使用的地址.然后按照上述两步将它们转换为RAM可以理解的物理地址.

Logical addresses is what your applications operate directly with. Then follows the above 2-step translation of them into what the RAM will understand, physical addresses.

第一步,由选择器对GDT(或者可以是LDT,取决于选择器值)进行索引,以找到相关段的基址和大小.虚拟地址将是段基地址和偏移量的总和.需要使用段描述符中的段大小和其他内容来提供保护.

In the first step the GDT (or it can be LDT, depends on the selector value) is indexed by the selector to find the relevant segment's base address and size. The virtual address will be the sum of the segment base address and the offset. The segment size and other things in segment descriptors are needed to provide protection.

在第二步中,页表由虚拟地址的不同部分建立索引,层次结构中的最后一个索引表提供最终的物理地址,该地址在地址总线上流向RAM以供查看.就像段描述符一样,页表条目不仅包含地址,而且还包含保护控制位.

In the second step the page tables are indexed by different parts of the virtual address and the last indexed table in the hierarchy gives the final, physical address that goes out on the address bus for the RAM to see. Just like with segment descriptors, page table entries contain not only addresses but also protection control bits.

关于机制的问题.

现在,在许多x86操作系统中,用于应用程序的段选择器是固定的,它们在所有选择器中都是相同的,它们从未改变,它们指向基地址等于0,大小等于segment的段描述符.可能的最大值(例如,在非64位模式下为4GB).这样的GDT设置有效地意味着第一步没有任何用处,并且逻辑地址的偏移量部分转换为在数值上相等的虚拟地址.

Now, in many x86 OSes the segment selectors that are used for applications are fixed, they are the same in all of them, they never change and they point to segment descriptors that have base addresses equal to 0 and sizes equal to the possible maximum (e.g. 4GB in non-64-bit modes). Such a GDT setup effectively means that the first step does no useful work and the offset part of the logical address translates into numerically equal virtual address.

这使得段选择器值实际上无用.它们仍然必须加载到CPU的段寄存器中(在非64位模式下,至少应加载到CS,SS,DS和ES中),但在此之后,它们可能会被遗忘.

This makes the segment selector values practically useless. They still have to be loaded into the CPU's segment registers (in non-64-bit modes into at least CS, SS, DS and ES), but beyond that point they can be forgotten about.

所有这些内容(与Linux相关的详细信息和ELF格式除外)在Intel和AMD的x86 CPU手册中进行了解释或直接遵循.您将在此处找到更多详细信息.

This all (except Linux-related details and the ELF format) is explained in or directly follows from Intel's and AMD's x86 CPU manuals. You'll find many more details there.

这篇关于根据页面分割内存的程序寿命的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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