📄 write your own operating system - lesson 6.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0047)http://www.cse.unl.edu/~jgompert/OS/lesson6.htm -->
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:v =
"urn:schemas-microsoft-com:vml" xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:w =
"urn:schemas-microsoft-com:office:word"><HEAD><TITLE>Write Your Own Operating System - Lesson 6</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content=Word.Document name=ProgId>
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<META content="Microsoft Word 9" name=Originator><LINK
href="./lesson6_files/filelist.xml" rel=File-List><!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>Joel Matthias Gompert</o:Author> <o:LastAuthor>Joel Matthias Gompert</o:LastAuthor> <o:Revision>5</o:Revision> <o:TotalTime>24</o:TotalTime> <o:Created>2001-12-28T03:25:00Z</o:Created> <o:LastSaved>2001-12-28T04:23:00Z</o:LastSaved> <o:Pages>2</o:Pages> <o:Words>807</o:Words> <o:Characters>4601</o:Characters> <o:Company>The Flaming Gymsocks</o:Company> <o:Lines>38</o:Lines> <o:Paragraphs>9</o:Paragraphs> <o:CharactersWithSpaces>5650</o:CharactersWithSpaces> <o:Version>9.2720</o:Version> </o:DocumentProperties></xml><![endif]-->
<STYLE>@page Section1 {size: 8.5in 11.0in; margin: 1.0in 1.25in 1.0in 1.25in; mso-header-margin: .5in; mso-footer-margin: .5in; mso-paper-source: 0; }
P.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 12pt; FONT-FAMILY: "Times New Roman"; mso-style-parent: ""; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman"; mso-bidi-font-weight: bold
}
LI.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 12pt; FONT-FAMILY: "Times New Roman"; mso-style-parent: ""; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman"; mso-bidi-font-weight: bold
}
DIV.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 12pt; FONT-FAMILY: "Times New Roman"; mso-style-parent: ""; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman"; mso-bidi-font-weight: bold
}
H1 {
FONT-SIZE: 16pt; MARGIN: 0in 0in 12pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-pagination: widow-orphan; mso-bidi-font-weight: normal; mso-style-next: Normal; mso-outline-level: 1; mso-bidi-font-family: "Courier New"; mso-font-kerning: 0pt
}
P.MsoTitle {
FONT-WEIGHT: bold; FONT-SIZE: 16pt; MARGIN: 12pt 0in 3pt; FONT-FAMILY: Arial; TEXT-ALIGN: center; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman"; mso-outline-level: 1; mso-font-kerning: 14.0pt
}
LI.MsoTitle {
FONT-WEIGHT: bold; FONT-SIZE: 16pt; MARGIN: 12pt 0in 3pt; FONT-FAMILY: Arial; TEXT-ALIGN: center; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman"; mso-outline-level: 1; mso-font-kerning: 14.0pt
}
DIV.MsoTitle {
FONT-WEIGHT: bold; FONT-SIZE: 16pt; MARGIN: 12pt 0in 3pt; FONT-FAMILY: Arial; TEXT-ALIGN: center; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman"; mso-outline-level: 1; mso-font-kerning: 14.0pt
}
P.MsoBodyText {
FONT-SIZE: 12pt; MARGIN: 0in 0in 12pt; FONT-FAMILY: "Times New Roman"; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman"
}
LI.MsoBodyText {
FONT-SIZE: 12pt; MARGIN: 0in 0in 12pt; FONT-FAMILY: "Times New Roman"; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman"
}
DIV.MsoBodyText {
FONT-SIZE: 12pt; MARGIN: 0in 0in 12pt; FONT-FAMILY: "Times New Roman"; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman"
}
A:link {
COLOR: blue; TEXT-DECORATION: underline; text-underline: single
}
SPAN.MsoHyperlink {
COLOR: blue; TEXT-DECORATION: underline; text-underline: single
}
A:visited {
COLOR: purple; TEXT-DECORATION: underline; text-underline: single
}
SPAN.MsoHyperlinkFollowed {
COLOR: purple; TEXT-DECORATION: underline; text-underline: single
}
DIV.Section1 {
page: Section1
}
OL {
MARGIN-BOTTOM: 0in
}
UL {
MARGIN-BOTTOM: 0in
}
</STYLE>
<!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="1026"/></xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]--></HEAD>
<BODY lang=EN-US style="tab-interval: .5in" vLink=purple link=blue>
<DIV class=Section1>
<P class=MsoTitle><A name=_Toc534120514>Write Your Own Operating System
Tutorial</A></P>
<DIV
style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; PADDING-BOTTOM: 1pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 0.75pt solid">
<P class=MsoNormal
style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-bottom-alt: solid windowtext .75pt; mso-padding-alt: 0in 0in 1.0pt 0in"><SPAN
style="mso-bookmark: _Toc534120514"></SPAN><A
href="http://www.cse.unl.edu/~jgompert/OS/lesson5.htm"><SPAN
style="mso-bookmark: _Toc534120514">Previous Lesson</SPAN><SPAN
style="mso-bookmark: _Toc534120514"></SPAN></A><SPAN
style="mso-bookmark: _Toc534120514"><SPAN
style="mso-tab-count: 1">
</SPAN></SPAN><A
href="http://www.cse.unl.edu/~jgompert/OS/TableOfContents.htm"><SPAN
style="mso-bookmark: _Toc534120514">Table of Contents</SPAN><SPAN
style="mso-bookmark: _Toc534120514"></SPAN></A><SPAN
style="mso-bookmark: _Toc534120514"><SPAN
style="mso-tab-count: 1">
</SPAN></SPAN><A href="http://www.cse.unl.edu/~jgompert/OS/lesson7.htm"><SPAN
style="mso-bookmark: _Toc534120514">Next Lesson</SPAN><SPAN
style="mso-bookmark: _Toc534120514"></SPAN></A><SPAN
style="mso-bookmark: _Toc534120514"></SPAN></P></DIV><SPAN
style="mso-bookmark: _Toc534120514"></SPAN>
<H1><A name=_Toc534120519>Lesson 6: Boot Loader</A></H1>
<P class=MsoNormal>Everything we抳e done so far has been placed entirely inside
the boot sector.<SPAN style="mso-spacerun: yes"> </SPAN>We can抰 make our
operating system very big at all if it is to fit in one sector.<SPAN
style="mso-spacerun: yes"> </SPAN>We need a way of expanding.<SPAN
style="mso-spacerun: yes"> </SPAN>We will do this by making a boot program
that simply loads an executable file off the disk and begins executing it.<SPAN
style="mso-spacerun: yes"> </SPAN>This is called a boot loader.<SPAN
style="mso-spacerun: yes"> </SPAN>This file loaded off the disk can be as
big as we want, since it will not be constrained to one sector.</P>
<P class=MsoNormal>This is more difficult than anything else we抳e done so
far.<SPAN style="mso-spacerun: yes"> </SPAN>It might be a good idea, now,
to locate a reference on the FAT file system (or the file system of your choice,
but I will be assuming the use of the FAT system).<SPAN
style="mso-spacerun: yes"> </SPAN>I will give a brief overview of the boot
loading process.</P>
<P class=MsoNormal>A floppy disk contains, in this order, the DOS Boot Record
(the first sector we have been working with), the File Allocation Table (FAT),
the Root Directory, and then the data contained in the files on the disk.<SPAN
style="mso-spacerun: yes"> </SPAN>(A hard disk is more complicated.<SPAN
style="mso-spacerun: yes"> </SPAN>It has a Master Boot Record and multiple
partitions.)<SPAN style="mso-spacerun: yes"> </SPAN>Suppose we write an
operating system, compile/assemble it to a file named LOADER.BIN, and place it
on the disk.<SPAN style="mso-spacerun: yes"> </SPAN>The boot loader will
load it as follows.</P>
<OL style="MARGIN-TOP: 0in" type=1>
<LI class=MsoNormal style="mso-list: l0 level1 lfo3; tab-stops: list .5in">The
DOS Boot Record (DBR) is read to determine the size of the DBR, FAT, and Root
Directory.<SPAN style="mso-spacerun: yes"> </SPAN>The location of each
on the disk is then determined.
<LI class=MsoNormal style="mso-list: l0 level1 lfo3; tab-stops: list .5in">The
Root Directory is read in to memory.
<LI class=MsoNormal style="mso-list: l0 level1 lfo3; tab-stops: list .5in">The
Root Directory is searched for the file name LOADER.BIN.<SPAN
style="mso-spacerun: yes"> </SPAN>If found, we can look in the directory
entry to find out which is the file抯 first cluster (file allocation
unit).<SPAN style="mso-spacerun: yes"> </SPAN>If not found, we give an
error message.
<LI class=MsoNormal style="mso-list: l0 level1 lfo3; tab-stops: list .5in">The
File Allocation Table is read off the disk in to memory.
<LI class=MsoNormal
style="mso-list: l0 level1 lfo3; tab-stops: list .5in">Starting with the
file抯 first cluster, we use the FAT to locate all the clusters belonging to
the file.<SPAN style="mso-spacerun: yes"> </SPAN>We read them all off
the disk into memory at a specific location.
<LI class=MsoNormal style="mso-list: l0 level1 lfo3; tab-stops: list .5in">We
jump to that location to begin execution of the operating system. </LI></OL>
<P class=MsoNormal>All of the reading from the disk will be done using calls to
BIOS.<SPAN style="mso-spacerun: yes"> </SPAN>If you feel adventurous, use
a reference of BIOS functions to learn how to read sectors from the disk and try
writing your own boot loader.<SPAN style="mso-spacerun: yes">
</SPAN>Otherwise, I have provided a slightly modified version of John S. Fine抯
<A href="http://www.cse.unl.edu/~jgompert/OS/BOOT12.ASM">FAT12 bootstrap
loader</A>.<SPAN style="mso-spacerun: yes"> </SPAN>If you can find a copy
of his utility 損artcopy,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -