📄 操作系统引导探究.htm
字号:
eqn="sum 0 0 @1 "></v:f><v:f eqn="prod @2 1 2 "></v:f><v:f
eqn="prod @3 21600 pixelWidth "></v:f><v:f
eqn="prod @3 21600 pixelHeight "></v:f><v:f eqn="sum @0 0 1 "></v:f><v:f
eqn="prod @6 1 2 "></v:f><v:f eqn="prod @7 21600 pixelWidth "></v:f><v:f
eqn="sum @8 21600 0 "></v:f><v:f eqn="prod @7 21600 pixelHeight "></v:f><v:f
eqn="sum @10 21600 0 "></v:f></v:formulas><v:path o:connecttype="rect"
gradientshapeok="t" o:extrusionok="f"></v:path><o:lock aspectratio="t"
v:ext="edit"></o:lock></v:shapetype></SPAN></P>
<P class=MsoCaption style="TEXT-ALIGN: center" align=center><SPAN
style="FONT-SIZE: 10.5pt; FONT-FAMILY: SimSun"><IMG alt=""
src="操作系统引导探究_files/200446212548880.jpg" onload=""><BR>(图一)<SPAN
lang=EN><o:p></o:p></SPAN></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>BIOS</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>BIOS</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一次只读一个扇区也即</SPAN><SPAN
lang=EN>512</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
lang=EN><o:p> </o:p></SPAN></P>
<P class=MsoNormal style="TEXT-ALIGN: center" align=center><B
style="mso-bidi-font-weight: normal"><SPAN
style="COLOR: #ff6600; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">三、通过</SPAN><SPAN
lang=EN style="COLOR: #ff6600">BIOS</SPAN></B><B
style="mso-bidi-font-weight: normal"><SPAN
style="COLOR: #ff6600; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">读磁盘扇区</SPAN><SPAN
lang=EN style="COLOR: #ff6600"><o:p></o:p></SPAN></B></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>I/O</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">端口,一种是通过</SPAN><SPAN
lang=EN>BIOS</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中断实现。前一种方法是最低层的方法(后一种方法也是在它的基础上实现的),具有极高的灵活性,可以将磁盘上的内容读到内存中的任意地方,但编程复杂。第二种方法是前一种方法稍微高层一点的实现,牺牲了一点灵活性,比如,它不能把磁盘上的内容读到</SPAN><SPAN
lang=EN>0x0000:0x0000 ~ 0x0000:0x03FF</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></P>
<P class=MsoNormal style="TEXT-ALIGN: center" align=center><B
style="mso-bidi-font-weight: normal"><SPAN lang=EN style="COLOR: #ff6600">3.1
BIOS</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN
style="COLOR: #ff6600; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的中断处理</SPAN><SPAN
lang=EN style="COLOR: #ff6600"><o:p></o:p></SPAN></B></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><SPAN style="mso-spacerun: yes"> </SPAN></SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">唐朔飞),上面有非常详尽的描述,而一般的汇编教材也多有谈及,因此这里只打算讲讲</SPAN><SPAN
lang=EN>BIOS</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/200446212617220.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><SPAN
class=SpellE><SPAN lang=EN>jmp</SPAN></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></P>
<P class=MsoNormal style="TEXT-ALIGN: center" align=center><B
style="mso-bidi-font-weight: normal"><SPAN lang=EN style="COLOR: #ff6600">3.2
</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN
style="COLOR: #ff6600; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">系统的内存安排(</SPAN><st1:chmetcnv
style="BACKGROUND-POSITION: left bottom; BACKGROUND-IMAGE: url(res://ietag.dll/#34/#1001); BACKGROUND-REPEAT: repeat-x"
tabIndex=0 UnitName="m" SourceValue="1" HasSpace="False" Negative="False"
NumberType="1" TCSC="0" w:st="on"><SPAN lang=EN
style="COLOR: #ff6600">1M</SPAN></st1:chmetcnv></B><B
style="mso-bidi-font-weight: normal"><SPAN
style="COLOR: #ff6600; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">)</SPAN><SPAN
lang=EN style="COLOR: #ff6600"><o:p></o:p></SPAN></B></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>CPU</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">被加点的时候,最初的</SPAN><st1:chmetcnv
style="BACKGROUND-POSITION: left bottom; BACKGROUND-IMAGE: url(res://ietag.dll/#34/#1001); BACKGROUND-REPEAT: repeat-x"
tabIndex=0 UnitName="m" SourceValue="1" HasSpace="False" Negative="False"
NumberType="1" TCSC="0" w:st="on"><SPAN lang=EN>1M</SPAN></st1:chmetcnv><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的内存,是由</SPAN><SPAN
lang=EN>BIOS</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 lang=EN><IMG
alt="" src="操作系统引导探究_files/200446212638303.gif" onload=""><BR>(</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图三</SPAN><SPAN
lang=EN>)</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>0x00000~0x003FF</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是中断向量表所在,因此不能将磁盘从的操作系统读到此处,因为这样会覆盖中断向量表,就无法再通过</SPAN><SPAN
lang=EN>BIOS</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中断读取磁盘内容了。你也许会说:我是先调用中断,再读的啊。但事实在</SPAN><SPAN
lang=EN>BIOS</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><B
style="mso-bidi-font-weight: normal"><SPAN lang=EN style="COLOR: #ff6600">3.3
</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN
style="COLOR: #ff6600; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">利用</SPAN><SPAN
lang=EN style="COLOR: #ff6600">BIOS 13</SPAN></B><B
style="mso-bidi-font-weight: normal"><SPAN
style="COLOR: #ff6600; FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">号中断读取磁盘扇区</SPAN><SPAN
lang=EN style="COLOR: #ff6600"><o:p></o:p></SPAN></B></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>BIOS</SPAN><SPAN
style="FONT-FAMILY: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中断读取磁盘扇区了。要读取磁盘扇区,我们需要使用</SPAN><SPAN
lang=EN>BIOS</SPAN><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>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>13</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: 42pt; mso-char-indent-count: 4.0"><SPAN
lang=EN style="COLOR: blue">AH</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">2</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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -