免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5143 | 回复: 16
打印 上一主题 下一主题

effecitve address作何解释? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-01 21:07 |只看该作者 |正序浏览
比如LEA语句,LEA r32, m意思是load effective address fro m in register r32.
这里的effecitve address何解

论坛徽章:
0
17 [报告]
发表于 2008-09-05 14:07 |只看该作者
Virtual Address: 以 segmentffset 形式表示的地址。在X86架构下,segment是隐含的,比如访问数据会硬件会自动加上ds段的偏移;IP则自动加上cs段的偏移。
Linear Address: segment base加上offset之后得到的地址。
physical address: Linear Address经过硬件MMU转换之后的地址,也就是bus地址。

但是在windows/linux下,所有段的基地址都为0,所以对于软件开发者来说,看到的效果就是virtual address = linear address

论坛徽章:
0
16 [报告]
发表于 2008-09-04 22:38 |只看该作者

回复 #15 耿耿于怀 的帖子

lea啊,load effecitve address

论坛徽章:
0
15 [报告]
发表于 2008-09-04 22:09 |只看该作者
lz说的是什么呢??

论坛徽章:
0
14 [报告]
发表于 2008-09-03 09:09 |只看该作者
我发现,我在说分段、分页的时候,是从操作系统角度来看的。比如我说,linux不用分段的机制,因为linux操作系统的虚存管理用的是三级页表(其实在PC上中间一级占0bit,所以事实上是两级)的页式存储管理。当linux启动的时候设置了X86的GDT之后,在整个操作系统的运行过程中,linux都不再使用分段的概念。当操作系统从程序中拿出来一个32位的地址之后,linux就认为这个是虚拟地址了。
相信看过linux代码的人都会有这个印象:linux的虚拟地址分为四个部分,分别是
[PGD][PMD][PTE][OFFSET]吧,而且,在PC上,PMD的长度是0。
事实上,X86的硬件必须用它的段,linux为了能够用x86的保护模式,只好在启动的时候将GDT的表项的基值设置为0,这样,当linux将自己认为的虚拟地址发出的时候,还是会被硬件自动的加上0。而硬件却认为,加了0之后的地址才是虚拟地址。
再比如说,我说在操作系统支持虚拟地址的时候,程序员使用的地址就是虚拟地址。用objdump看一个二进制代码,里面打出来的地址,和linux认为的虚拟地址是一致的。当程序执行的时候,用得也是那些地址,而这些地址总是会被CPU自动地加上0。

而版主在说的时候,总是直接用处理器来说,认为只要经过X86的段逻辑之后,得到的地址就是虚拟地址。

我一开始的时候确实犯了一个错误。我在讨论虚拟地址的时候,没有用X86的机器模型来讨论。以至于当版主说虚拟地址是MMU产生的时候,立刻就予以反驳。从这张图看来,X86用的虚拟地址,的确是由硬件产生的。

习惯上,我在一般讨论问题的时候,大脑里面想的机器模型总是一个类似MIPS处理器的模型,而使用的操作系统模型就是linux。呵呵,看来这个习惯要改了,马上就要工作了,要开始用产业界的习惯了。

原帖由 cjaizss 于 2008-9-3 00:50 发表

对于这张图,我还是把原书中的相关内容应用一下,以便理解。
The memory management facilities of the IA-32 architecture are divided into two

parts: segmentation and paging. Segmentation provide ...

[ 本帖最后由 freearth 于 2008-9-3 09:32 编辑 ]

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11数据库技术版块每日发帖之星
日期:2016-08-03 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
13 [报告]
发表于 2008-09-03 00:50 |只看该作者
原帖由 mik 于 2008-9-2 22:48 发表


你这样就颠倒概念了,本来 effecitive address 这个概念只有 x86 上才有的,怎么扯上 power 上去了。
你看了这么多《微机原理》这类书籍,有些东西根深蒂固,我也不打算去说服你。

我不看国内的《微机 ...

对于这张图,我还是把原书中的相关内容应用一下,以便理解。
The memory management facilities of the IA-32 architecture are divided into two

parts: segmentation and paging. Segmentation provides a mechanism of isolating

individual code, data, and stack modules so that multiple programs (or tasks) can

run on the same processor without interfering with one another. Paging provides a

mechanism for implementing a conventional demand-paged, virtual-memory system

where sections of a program’s execution environment are mapped into physical

memory as needed. Paging can also be used to provide isolation between multiple

tasks. When operating in protected mode, some form of segmentation must be used.

There is no mode bit to disable segmentation. The use of paging, however, is

optional.

These two mechanisms (segmentation and paging) can be configured to support

simple single-program (or single-task) systems, multitasking systems, or multipleprocessor

systems that used shared memory.


As shown in Figure 3-1, segmentation provides a mechanism for dividing the

processor’s addressable memory space (called the linear address space) into

smaller protected address spaces called segments. Segments can be used to hold

the code, data, and stack for a program or to hold system data structures (such as a

TSS or LDT). If more than one program (or task) is running on a processor, each

program can be assigned its own set of segments. The processor then enforces the

boundaries between these segments and insures that one program does not interfere

with the execution of another program by writing into the other program’s segments.

The segmentation mechanism also allows typing of segments so that the operations

that may be performed on a particular type of segment can be restricted.

All the segments in a system are contained in the processor’s linear address space.

To locate a byte in a particular segment, a logical address (also called a far pointer)

must be provided. A logical address consists of a segment selector and an offset. The

segment selector is a unique identifier for a segment. Among other things it provides

an offset into a descriptor table (such as the global descriptor table, GDT) to a data

structure called a segment descriptor. Each segment has a segment descriptor, which

specifies the size of the segment, the access rights and privilege level for the segment, the segment type, and the l
ocation of the first byte of the segment in the

linear address space (called the base address of the segment). The offset part of the

logical address is added to the base address for the segment to locate a byte within

the segment. The base address plus the offset thus forms a linear address in the

processor’s linear address space.

If paging is not used, the linear address space of the processor is mapped directly

into the physical address space of processor. The physical address space is defined as

the range of addresses that the processor can generate on its address bus.

Because multitasking computing systems commonly define a linear address space

much larger than it is economically feasible to contain all at once in physical memory,

some method of “virtualizing” the linear address space is needed. This virtualization

of the linear address space is handled through the processor’s paging mechanism.

Paging supports a “virtual memory” environment where a large linear address space

is simulated with a small amount of physical memory (RAM and ROM) and some disk storage. When using paging,

each segment is divided into pages (typically 4 KBytes

each in size), which are stored either in physical memory or on the disk. The operating

system or executive maintains a page directory and a set of page tables to keep

track of the pages. When a program (or task) attempts to access an address location

in the linear address space, the processor uses the page directory and page tables to

translate the linear address into a physical address and then performs the requested

operation (read or write) on the memory location.

If the page being accessed is not currently in physical memory, the processor interrupts

execution of the program (by generating a page-fault exception). The operating

system or executive then reads the page into physical memory from the disk

and continues executing the program.

When paging is implemented properly in the operating-system or executive, the

swapping of pages between physical memory and the disk is transparent to the

correct execution of a program. Even programs written for 16-bit IA-32 processors

can be paged (transparently) when they are run in virtual-8086 mode.

[ 本帖最后由 cjaizss 于 2008-9-3 01:01 编辑 ]

论坛徽章:
0
12 [报告]
发表于 2008-09-03 00:11 |只看该作者

回复 #9 mik 的帖子

看来的确我的基础比较差,我没有给x86维护过编译器和kernel的代码。我做的事情都是基于power和另外一种RISC的处理器的。Power上也有有效地址的概念,这个不是x86才有的。

你的图中有段表GDT,对的,这是x86 CPU启用保护模式必须的,而且在linux下,这个表中应该有四个表项,本别对应于user code, user data, kernel code, kernel data。这四个表项的base都是0x00000000,而且,内核启动之后,这个表是不会改的。正如我在7楼所说,“linux只使用了x86的一个段”,在虚存管理中,只使用分页的概念。之所以必须设置这个段表,是因为你不设置,x86不工作。如果要说使用了分段,那只是形式上的,事实上不使用。

机器就是机器,哪管你在什么模式下,这是一个物理构造上
Dos在X86上没有虚拟地址空间。这个地址空间只有CPU是做不出来的。所有不启用MMU的操作系统,都不会有虚拟地址空间。在6楼中你认为,经过x86的段表之后的地址就是虚拟地址,在Dos中,那个地址绝对不能叫虚拟地址。

至少根据我的理解,你在9楼的关于有效地址和寻址模式的解释和我在7楼的解释一致,与你在6楼的解释矛盾。

[ 本帖最后由 freearth 于 2008-9-3 00:31 编辑 ]

论坛徽章:
0
11 [报告]
发表于 2008-09-02 23:11 |只看该作者
原帖由 zx_wing 于 2008-9-2 23:02 发表
牛!花这么多时间讨论自己知道的东西。

论坛徽章:
0
10 [报告]
发表于 2008-09-02 23:02 |只看该作者
牛!花这么多时间讨论自己知道的东西。

论坛徽章:
0
9 [报告]
发表于 2008-09-02 22:48 |只看该作者
原帖由 freearth 于 2008-9-2 00:55 发表
“,是指令层面上地址元素。是最原始的”
我记得这个是指令系统体系结构中的“寻址模式”而不能叫做有效地址。比如,
lea r,
你是把“”计算出来的值放入了寄存器中,这个值是一个数字,二进制无符号数,这 ...


你这样就颠倒概念了,本来 effecitive address 这个概念只有 x86 上才有的,怎么扯上 power 上去了。
你看了这么多《微机原理》这类书籍,有些东西根深蒂固,我也不打算去说服你。

我不看国内的《微机原理》之类的书籍,我只会看 AMD & Intel 官方的文档及 Addison-Wesley 的 System Architecture 系列的书籍
且我推荐看这些权威的书籍,其它什么微机原理相比已经没什么价值了。
在<computer orgranization & design>一书也没找到你这些概念。

说回正题:

>> 我记得这个是指令系统体系结构中的“寻址模式”而不能叫做有效地址。比如,

在这里你又混淆了,“寻址模式”是“寻址模式”,与“有效地址”完全是两个概念
寻址模式是指出寻找数据的方式,它是一个寻找数据方法上的一个概念。
有效地址是内存地址上的一个概念,完全两码事。


mov eax, 1         --->  这个数据的“寻址模式”就是:立即数寻址。
mov eax, ebx     ---->   这个数据的“寻址模式”就是:寄存器寻址。

[base + index * scale + disp]:这是一个内存寻址模式,数据在内存里,它是 x86 的最复杂的一个寻址模式,可以转化为几种形式:
[eax];  [eax+ebx*2+0xc];  [0x11223344] 等寻址方式。 无论以何种寻址方式得出的是一个“有效地址”。




>> 在当前的linux地址空间中,没有“segmentation”这个概念。

你这个概念非常的错误!!! 说明你根本不了解“保护模式”,我建议你仔细地了解“保护模式”, linux 只是用了平坦的内存方式。没有"segmentation"这个概念,selector 是什么? GDT 是什么?
在x86上,任何操作系统都逃不过 segmentation,除非不是 x86,即使在 x64 上,还是没完全逃脱 segmentation


>>  在dos下没有虚拟地址的概念, 因为Dos并不启用MMU。Dos也不实现虚拟地址空间,而且这个对于CPU而言也不能
    叫做线性地址,因为这时候的地址空间是分段式的。

机器就是机器,哪管你在什么模式下,这是一个物理构造上。 真得很诚心的建议你深入学习 x86。


开始还认为你基础不错,看来不是这样的!

最后,上个图你看看:
  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP