Chinaunix首页 | 论坛 | 博客
  • 博客访问: 335284
  • 博文数量: 79
  • 博客积分: 2466
  • 博客等级: 大尉
  • 技术积分: 880
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-07 16:47
文章分类

全部博文(79)

文章存档

2014年(3)

2012年(7)

2011年(14)

2010年(2)

2009年(2)

2008年(2)

2007年(18)

2006年(31)

分类: LINUX

2007-05-13 17:56:03

网上找到一本关于x86汇编的书,其中有一段,用很清晰很简洁的叙述,讲清楚了以下几个概念:
实模式
16位保护模式
32位保护模式
内存管理中的段(segment)和页(page)
很有用,保存下来以备以后用到。

Real Mode
In real mode, memory is limited to only one megabyte (2^20 bytes). Valid
address range from (in hex) 00000 to FFFFF. These addresses require a 20-
bit number. Obviously, a 20-bit number will not fit into any of the 8086's
16-bit registers. Intel solved this problem, by using two 16-bit values to
determine an address. The first 16-bit value is called the selector. Selector
values must be stored in segment registers. The second 16-bit value is called
the offset. The physical address referenced by a 32-bit selector:offset pair is
computed by the formula
16 * selector + offset
Multiplying by 16 in hex is easy, just add a 0 to the right of the number.
For example, the physical addresses referenced by 047C:0048 is given by:
047C0
+0048
-----
04808
In effect, the selector value is a paragraph number.
Real segmented addresses have disadvantages:
o A single selector value can only reference 64K of memory (the upper
limit of the 16-bit offset). What if a program has more than 64K of
code? A single value in CS can not be used for the entire execution
of the program. The program must be split up into sections (called
segments) less than 64K in size. When execution moves from one segment
to another, the value of CS must be changed. Similar problems
occur with large amounts of data and the DS register. This can be
very awkward!
o Each byte in memory does not have a unique segmented address. The
physical address 04808 can be referenced by 047C:0048, 047D:0038,
047E:0028 or 047B:0058. This can complicate the comparison of segmented
addresses.

16-bit Protected Mode
In the 80286's 16-bit protected mode, selector values are interpreted
completely differently than in real mode. In real mode, a selector value
is a paragraph number of physical memory. In protected mode, a selector
value is an index into a descriptor table. In both modes, programs are
divided into segments. In real mode, these segments are at fixed positions
in physical memory and the selector value denotes the paragraph number
of the beginning of the segment. In protected mode, the segments are not
at fixed positions in physical memory. In fact, they do not have to be in
memory at all!
Protected mode uses a technique called virtual memory . The basic idea
of a virtual memory system is to only keep the data and code in memory that
programs are currently using. Other data and code are stored temporarily
on disk until they are needed again. In 16-bit protected mode, segments are
moved between memory and disk as needed. When a segment is returned
to memory from disk, it is very likely that it will be put into a different area
of memory that it was in before being moved to disk. All of this is done
transparently by the operating system. The program does not have to be
written differently for virtual memory to work.
In protected mode, each segment is assigned an entry in a descriptor
table. This entry has all the information that the system needs to know
about the segment. This information includes: is it currently in memory;
if in memory, where is it; access permissions (e.g., read-only). The index
of the entry of the segment is the selector value that is stored in segment
registers.
One big disadvantage of 16-bit protected mode is that offsets are still
16-bit quantities. As a consequence of this, segment sizes are still limited to
at most 64K. This makes the use of large arrays problematic!

32-bit Protected Mode
The 80386 introduced 32-bit protected mode. There are two major differences
between 386 32-bit and 286 16-bit protected modes:
1. Offsets are expanded to be 32-bits. This allows an offset to range up
to 4 billion. Thus, segments can have sizes up to 4 gigabytes.
2. Segments can be divided into smaller 4K-sized units called pages. The
virtual memory system works with pages now instead of segments.
This means that only parts of segment may be in memory at any one
time. In 286 16-bit mode, either the entire segment is in memory or
none of it is. This is not practical with the larger segments that 32-bit
mode allows.
In Windows 3.x, standard mode referred to 286 16-bit protected mode
and enhanced mode referred to 32-bit mode. Windows 9X, Windows NT/2000/XP,
OS/2 and Linux all run in paged 32-bit protected mode.
阅读(2759) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~