⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 write your own operating system - lesson 2.htm

📁 使用汇编语言编写的一个操作系统DIY的手册
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0047)http://www.cse.unl.edu/~jgompert/OS/lesson2.htm -->
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:o = 
"urn:schemas-microsoft-com:office:office" xmlns:w = 
"urn:schemas-microsoft-com:office:word"><HEAD><TITLE>Write Your Own Operating System - Lesson 2</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="./lesson2_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>14</o:Revision>  <o:TotalTime>27</o:TotalTime>  <o:Created>2001-12-28T03:15:00Z</o:Created>  <o:LastSaved>2001-12-28T05:01:00Z</o:LastSaved>  <o:Pages>2</o:Pages>  <o:Words>759</o:Words>  <o:Characters>4329</o:Characters>  <o:Company>The Flaming Gymsocks</o:Company>  <o:Lines>36</o:Lines>  <o:Paragraphs>8</o:Paragraphs>  <o:CharactersWithSpaces>5316</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-pagination: widow-orphan; mso-bidi-font-weight: normal; mso-style-next: Normal; mso-outline-level: 1; mso-bidi-font-size: 12.0pt; 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
}
P.ComputerText {
	FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt 0.5in; FONT-FAMILY: "Courier New"; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman"; mso-bidi-font-weight: bold; mso-style-name: "Computer Text"
}
LI.ComputerText {
	FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt 0.5in; FONT-FAMILY: "Courier New"; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman"; mso-bidi-font-weight: bold; mso-style-name: "Computer Text"
}
DIV.ComputerText {
	FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt 0.5in; FONT-FAMILY: "Courier New"; mso-pagination: widow-orphan; mso-fareast-font-family: "Times New Roman"; mso-bidi-font-weight: bold; mso-style-name: "Computer Text"
}
DIV.Section1 {
	page: Section1
}
</STYLE>
</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><AHREF="LESSON1.HTM"><SPAN 
style="mso-bookmark: _Toc534120514">Previous 
Lesson</SPAN><SPANSTYLE='MSO-BOOKMARK:_TOC534120514'></SPAN></A><SPAN 
style="mso-bookmark: _Toc534120514"><SPANSTYLE='MSO-TAB-COUNT:1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN></SPAN><A 
href="http://www.cse.unl.edu/~jgompert/OS/TableOfContents.htm"><SPANSTYLE='MSO-BOOKMARK:_TOC534120514'>Table 
of Contents</SPAN><SPANSTYLE='MSO-BOOKMARK:_TOC534120514'></SPAN></A><SPAN 
style="mso-bookmark: _Toc534120514"><SPANSTYLE='MSO-TAB-COUNT:1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN></SPAN><A 
href="http://www.cse.unl.edu/~jgompert/OS/lesson3.htm"><SPANSTYLE='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=_Toc534120515>Lesson 2: Making Our First Bootable Disk</A></H1>
<P class=MsoNormal>In this lesson, we will learn how to create a boot program on 
a floppy disk.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>We will start by 
modifying the Microsoft DOS Boot Record.</P>
<P class=MsoNormal>For our purposes, we want to replace the boot loader code 
without changing the other data in the boot sector.<SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN>If we change the data to something 
invalid, then DOS and Windows will not recognize the disk as being valid.<SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN>Windows will give an error saying the 
disk is not formatted.<SPANSTYLE="MSO-SPACERUN: yes?>&nbsp; </SPAN>This will 
cause you to be unable to access any of the files on the disk.<SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN>However, we can change the boot program 
code all we want and, as long as we don抰 mess with the other data, DOS and 
Windows will be able to read and write the files on the disk just fine.</P>
<P class=MsoNormal>We will leave the first instruction (<SPAN 
style="FONT-FAMILY: 'Courier New'">jmp 0x3E</SPAN>) alone, because we need to 
jump over the Boot Record data.<SPAN style="mso-spacerun: yes">&nbsp; 
</SPAN>Thus we can begin modifying the code at 0x3E.<SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN>Run the DOS DEBUG program and load the 
first sector of a formatted floppy disk into memory at address 0.<SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN>Then type the command</P>
<P class=ComputerText>-u 3E</P>
<P class=ComputerText><![if !supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></P>
<P class=MsoNormal>to view the instructions there.<SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN>Now, we will begin modifying the 
code.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Type the command</P>
<P class=ComputerText>-a 3E</P>
<P class=ComputerText><![if !supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></P>
<P class=MsoNormal>to begin assembling instructions.<SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN>The prompt changes from a hyphen to the 
address at the location that we gave.<SPAN style="mso-spacerun: yes">&nbsp; 
</SPAN>Type the following instruction and press enter.</P>
<P class=ComputerText>jmp 3E</P>
<P class=ComputerText><![if !supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></P>
<P class=MsoNormal>The instruction is assembled to machine code and placed into 
memory, and the following prompt is the next available memory after the 
instruction you just entered.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Press 
Enter once more to exit the assembly mode.<SPAN style="mso-spacerun: yes">&nbsp; 
</SPAN>The whole procedure on my computer looked like this.</P>
<P class=ComputerText>-a 3E</P>
<P class=ComputerText>0AFC:003E jmp 3E</P>
<P class=ComputerText>0AFC:0040</P>
<P class=ComputerText>-</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPANSTYLE="FONT-FAMILY:'COURIER 
New??><![if !supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal>The segment address (0x0AFC, in my case) can (an probably 
will be) different on your computer, or even between different sessions of 
DEBUG.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Now view the instruction you 
just entered by giving the unassembled command.</P>
<P class=ComputerText>-u 3E</P>
<P class=ComputerText><![if !supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></P>
<P class=MsoNormal>As you can see, the first instruction is now our jump 
instruction.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>This will create an 
infinite loop.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>If we quit DEBUG 
now, no changes will be saved, but we can now write our modified boot sector 
back to the disk (overwriting the previous one) by typing this command.</P>
<P class=ComputerText>-w 0 0 0 1</P>
<P class=ComputerText><![if !supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></P>
<P class=MsoNormal>This "write" command uses the same syntax as the "load" 
command.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>This writes the data found 
at memory address 0 to disk 0, starting with sector 0 and writing 1 sector.<SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN><I>Be very careful when using the write 
command.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>This command can be used 
to overwrite sectors on any drive, and cause loss of data.</I></P>
<P class=MsoNormal>You can now boot with this floppy.<SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN>When you boot, BIOS will load the first 
sector off the disk into memory and begin execution at the beginning of the 
sector.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>This will be the jump to 
0x3E instruction.<SPANSTYLE="MSO-SPACERUN: yes?>&nbsp; </SPAN>The instruction 
there is one to jump to 0x3E, so this will continue forever.<SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN>Try it.<SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN>Boot up a computer with this disk.<SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN>Nothing appears to happen.<SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN>The computer will just sit there and do 
nothing.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>But your new 搊perating 
system

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -