当前位置: 技术问答>linux和unix
关于虚拟地址的困惑
来源: 互联网 发布时间:2016-03-03
本文导语: 本人刚刚学习Linux,对虚拟地址,逻辑地址和线性地址,物理地址有好多困惑: 1、虚拟地址是由段选择符合段内偏移地址形成的,我的困惑是:如果段选择符所选择的段描述符的基地址是0x10000000;而段偏移地址是0xf0...
本人刚刚学习Linux,对虚拟地址,逻辑地址和线性地址,物理地址有好多困惑:
1、虚拟地址是由段选择符合段内偏移地址形成的,我的困惑是:如果段选择符所选择的段描述符的基地址是0x10000000;而段偏移地址是0xf0000000;这样算出来的线性地址是什么?如果只是分段机制书上说线性地址就是物理地址,那这样是不是超出了4G的无理地址范围而无法表示?还是说段偏移地址根本就不可以超过某个范围以保证不超出4G空间?这个问题十分困惑
2、逻辑地址和虚拟地址到底有什么差别??
小弟十分困惑,夜不能寐,,还望各位前辈高手指教一二,,希望能拨开迷雾见晴天,,,不胜感激,,谢谢!
1、虚拟地址是由段选择符合段内偏移地址形成的,我的困惑是:如果段选择符所选择的段描述符的基地址是0x10000000;而段偏移地址是0xf0000000;这样算出来的线性地址是什么?如果只是分段机制书上说线性地址就是物理地址,那这样是不是超出了4G的无理地址范围而无法表示?还是说段偏移地址根本就不可以超过某个范围以保证不超出4G空间?这个问题十分困惑
2、逻辑地址和虚拟地址到底有什么差别??
小弟十分困惑,夜不能寐,,还望各位前辈高手指教一二,,希望能拨开迷雾见晴天,,,不胜感激,,谢谢!
|
Well, maybe you have not yet fully understood the mechanism of the virtual memory.
First of all, segmentation and paging are different concepts.
In segmentation-only mode, the offset (0xf0000000 in your case) is used "as is", and won't be interpreted by the VMM.
In paging mode, the offset will be divided into three sections and you could refer to your textbook for more information.
Remember that under protected more, the segment does NOT add up to the offset anymore, it is a descriptor rather than a starting point. DS/CS/ES has the range which the segment covers in the memory and will be used when some memory faults are generated.
In your case, friend, your DS (0x10000000) points to GDT+0x10000000 and the range of your linear address will be there.
Suppose your address ranges from 0 to 0xffffffff which is the whole space, and then your offset (0xf0000000) will be dissected into 0x3C0, 0x0 and 0x0, which have 10, 10 and 12 bit respectively. Then the first part 0x3C0 is added with register CR3 to give you the level-1 page entry which points to the starting point of your level-2 page entry; your second part 0x0 is then added with the level-2 page entry to get the address of your page frame; and finally the third part 0x0 is added with the page frame to get your final physical address.
Therefore, 0xf0000000 will NEVER be added up with 0x10000000 in your case, but rather, they're interpreted in the way discussed above.
Try to understand the segmentation and paging first, friend, and you'll love it. :)
First of all, segmentation and paging are different concepts.
In segmentation-only mode, the offset (0xf0000000 in your case) is used "as is", and won't be interpreted by the VMM.
In paging mode, the offset will be divided into three sections and you could refer to your textbook for more information.
Remember that under protected more, the segment does NOT add up to the offset anymore, it is a descriptor rather than a starting point. DS/CS/ES has the range which the segment covers in the memory and will be used when some memory faults are generated.
In your case, friend, your DS (0x10000000) points to GDT+0x10000000 and the range of your linear address will be there.
Suppose your address ranges from 0 to 0xffffffff which is the whole space, and then your offset (0xf0000000) will be dissected into 0x3C0, 0x0 and 0x0, which have 10, 10 and 12 bit respectively. Then the first part 0x3C0 is added with register CR3 to give you the level-1 page entry which points to the starting point of your level-2 page entry; your second part 0x0 is then added with the level-2 page entry to get the address of your page frame; and finally the third part 0x0 is added with the page frame to get your final physical address.
Therefore, 0xf0000000 will NEVER be added up with 0x10000000 in your case, but rather, they're interpreted in the way discussed above.
Try to understand the segmentation and paging first, friend, and you'll love it. :)