📄 操作系统引导探究.htm
字号:
style="COLOR: blue"><SPAN style="mso-spacerun: yes"> </SPAN></SPAN><SPAN
style="COLOR: blue; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">段基址</SPAN><SPAN
lang=EN style="COLOR: blue"> + </SPAN><SPAN
style="COLOR: blue; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">段限值</SPAN><SPAN
lang=EN style="COLOR: blue"> * </SPAN><SPAN
style="COLOR: blue; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">段限单位</SPAN><SPAN
lang=EN style="COLOR: blue"> = </SPAN><SPAN
style="COLOR: blue; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">此段最大可访问地址</SPAN><SPAN
style="COLOR: blue"> <SPAN lang=EN><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果一个偏移地址大于了此段最大可访地址的话,</SPAN><SPAN
lang=EN>CPU</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就将产生一个错误中断,这样一来就可以访止一个程序非法访问另一个程序的内存空间,这对内存起到了保护作用,因此“保护模式”由此得名。</SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所以,如果段限是</SPAN><SPAN
lang=EN>0</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,那么此段最大可能访问地址就是段的基址,因此,当段限单位为一字节时,此段的段大小就是</SPAN><SPAN
lang=EN>1</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">字节;当段限单位为</SPAN><SPAN
lang=EN>4KB</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">时,因为</SPAN><SPAN
lang=EN>CPU</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将不检测偏移量的最左</SPAN><SPAN
lang=EN>12</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位,而这</SPAN><SPAN
lang=EN>12</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位最大可能为</SPAN><SPAN
lang=EN>0xFFF</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,因此,这时,此段的可访问范围就为</SPAN><SPAN
lang=EN>4KB</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,所以:</SPAN></P>
<P class=MsoNormal style="TEXT-ALIGN: center" align=center><SPAN
style="COLOR: blue; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">(段限值</SPAN><SPAN
lang=EN style="COLOR: blue"> + 1</SPAN><SPAN
style="COLOR: blue; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">)</SPAN><SPAN
lang=EN style="COLOR: blue">* </SPAN><SPAN
style="COLOR: blue; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">段限单位</SPAN><SPAN
lang=EN style="COLOR: blue"> = </SPAN><SPAN
style="COLOR: blue; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">此段大小</SPAN><SPAN
lang=EN style="COLOR: blue"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 21.75pt"><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">现在我们可以正始开始描述在保护模式下段模式是怎样访问内存的了。这里之所以是要强调“段模式”是因为在保护模式下还有一种前述的内存访问模式——页模式,它负责将线性地址再转换为物理地址。<SPAN
style="COLOR: blue">“页模式”也是其于段模式的,在不使用它的情况下,线性地址会被直接放到地址线上当做物理地址使用。</SPAN>“段模式”是不可避免的,所谓的“纯页模式”只是将整个线性地址当做一个整段,没有什么方法可以真正绕过“段模式”,因为这是由</SPAN><SPAN
lang=EN>CPU</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">内存访问机制所规定的。本篇只描述段模式,原因正如前所述,“页模式”的实验我还没做。</SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 21.75pt"><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们已经知道从程序使用的逻辑地址到线性地址的映射是通过“描述符”来完成的,而“描述符”又是放在描述符表中的,那么一个描述表中有许多描述符,到底选用哪一个描述符呢?这就由一个索引来决定,这个索引将指出是表中的第几个描述符,这个索引有一个专门的术语来描述,常常称它为<SPAN
style="COLOR: blue">“段选择子”</SPAN>。“段选择子”由</SPAN><SPAN lang=EN>2</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个字节共</SPAN><SPAN
lang=EN>16</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位组成,下面,我们就来看看它提供了哪些信息:</SPAN></P>
<P class=MsoNormal><SPAN lang=EN></SPAN></P>
<P class=MsoNormal style="TEXT-ALIGN: center" align=center><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><IMG
alt="" src="操作系统引导探究_files/200446212912624.gif" onload=""><BR>(图七)</SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 21.75pt"><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其中:</SPAN></P>
<P class=MsoNormal
style="TEXT-INDENT: 42.75pt; mso-char-indent-count: 4.07"><SPAN
lang=EN>RPL</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">:指示出特权级,</SPAN><SPAN
lang=EN>00~11</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,共</SPAN><SPAN
lang=EN>0</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN
lang=EN>1</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN
lang=EN>2</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN
lang=EN>3</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">四个特权级,与前述一样。</SPAN></P>
<P class=MsoNormal
style="TEXT-INDENT: 42.75pt; mso-char-indent-count: 4.07"><SPAN
lang=EN>TI</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">:为</SPAN><SPAN
lang=EN>0</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">时表明这是一个用于全局描述符表的选择子,为</SPAN><SPAN
lang=EN>1</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">时表明用于局部描述符表。</SPAN></P>
<P class=MsoNormal
style="TEXT-INDENT: 42.75pt; mso-char-indent-count: 4.07"><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">索引值:用来指示表中第几个描述符。索引值共有</SPAN><SPAN
lang=EN>13</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位,因此,每张描述符表共可有</SPAN><SPAN
lang=EN>8K</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个表项,而一个表项如前的述,占</SPAN><SPAN
lang=EN>8</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个字节,因此一张描述符表最大可达</SPAN><SPAN
lang=EN> 64K</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 21.75pt"><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不知道大家是否注意到这样一个事实,如果将“段选择子”的最后</SPAN><SPAN
lang=EN>3</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位置位零,这整个段选择子其实就是一个描述符在描述符表中的偏移量!这里我们可以发现</SPAN><SPAN
lang=EN>Intel</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的工程师在设计的时候真的是非常精巧,如此的安排,可以使选取一个描述符的速度极大加快,因为将一个段选择子最后</SPAN><SPAN
lang=EN>3</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位清零后与描述符表的基址相加,就立即可以得到一个描述符的物理地址,通过这个地址就可以直接得到一个描述符。那么这个描述符表的基址又是放在哪儿的呢?</SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 21.75pt"><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所为描述符表的基址也就是此描述符表在内存中的起始地址,也即表中第一个描述符所在的内存地址,系统中用两个特殊的寄存器来存放,一个用于存放全局描述符表的基址,称之为<SPAN
style="COLOR: blue">“全局描述符表寄存器(</SPAN></SPAN><SPAN lang=EN
style="COLOR: blue">GDTR</SPAN><SPAN
style="COLOR: blue; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">)”</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,另一个用来存放局部描述符表的基址,称之为<SPAN
style="COLOR: blue">“局部描述符表寄存器(</SPAN></SPAN><SPAN lang=EN
style="COLOR: blue">LDTR</SPAN><SPAN
style="COLOR: blue; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">)”</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,它们的结构如下图所示:</SPAN></P>
<P class=MsoNormal><SPAN lang=EN></SPAN></P>
<P class=MsoNormal style="TEXT-ALIGN: center" align=center><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><IMG
alt="" src="操作系统引导探究_files/200446212931779.gif" onload=""><BR>(图八)</SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其中表限也即表的大小限制,它的使用与前面所描述的段限是类似的,因此,这里就不在描述了。</SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在保护模式下,以前实模式下的段寄存器还是有用的,不过它不在用来存放段的基址,而是用来存放“段选择子”,它的名子也变成了“段选择子寄存器”,在访问内存的时候,我们需要给出的是“段选择子”,而不是段基址了。</SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比如,我现在想使用全局描述符表中第二个表项,即其中的第二个“段描述符”,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -