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

📄 lib0021.html

📁 Memory Management—Algorithms and implementation in C/C++ Introduction Chapter 1 - Memory Manag
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Case Study: MMURTL</title>
<link rel="STYLESHEET" type="text/css" href="images/xpolecat.css">
<link rel="STYLESHEET" type="text/css" href="images/ie.content.books24x7.css">
</head>
<body >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<td><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle"  alt="Team LiB"></a></div></td>
<td valign="top" class="v2" align="right"><div STYLE="MARGIN-RIGHT: 0.15in"><a href="LiB0020.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0022.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr>
</table>

<div class="chapter">
<a name="ch02"></a>
<div class="section">
<h2 class="first-section-title"><a name="157"></a><a name="ch02lev1sec2"></a>Case Study: MMURTL</h2><blockquote class="blockquote">
<p class="first-para">"There are two types of people in this world, good and bad. The good sleep better, but the bad seem to enjoy the waking hours much more."</p>
<p class="last-para">&mdash; Woody Allen</p>
</blockquote>
<p class="para">Richard Burgess is a one-man army. He is the sole creator of the MMURTL operating system. Not only did he build his own protected mode multitasking operating system, but he also wrote a 32-bit compiler, assembler, and debugger to go with it. I guess this is what happens when you retire. Like Ken Thompson, Burgess was bitten by the operating system bug. It is just one of those things. Even if you try to resist, you find yourself compelled to design and implement an operating system. You pace, you rant, and you lose sleep over all sorts of tiny hardware idiosyncrasies.</p>
<p class="para">I can only guess that Burgess spent a lot of his time munching on chocolate-covered coffee beans and washing them down with Jolt. I bought a copy of Richard's book on MMURTL back in 1995, and I am glad to see that it has been brought back from the dead. After a stint of being out-of-print, Sensory Publishing came out with a new release in 2000.</p>
<p class="para">Like DOS, MMURTL is an operating system that runs on Intel hardware. Compared to DOS, MMURTL is a huge step forward. Nevertheless, on the complexity spectrum, MMURTL lies somewhere between DOS and Linux. This explains why I have decided to present MMURTL before Linux. You will get a better understanding of exactly how MMURTL is "simple" in the next few sections.</p>
<a name="158"></a><a name="IDX-60"></a>
<div class="section">
<h3 class="sect3-title">
<a name="159"></a><a name="ch02lev2sec7"></a>Background and Design Goals</h3>
<p class="first-para">Burgess was careful to invest effort in deciding on a set of design goals. It is actually possible to understand what some of these goals are just by dissecting the operating system's name (Message-based, MUltitasking Real-Time kerneL). To get a better idea of what Richard wanted to build, here is a complete list:</p>
<ul class="itemizedlist">
<li class="first-listitem">
<p class="first-para">Single-user environment</p>
</li>
<li class="listitem">
<p class="first-para">Message-passing kernel</p>
</li>
<li class="listitem">
<p class="first-para">Priority-based, pre-emptive, multitasking</p>
</li>
<li class="listitem">
<p class="first-para">Real-time operation</p>
</li>
<li class="listitem">
<p class="first-para">32-bit protected mode memory management</p>
</li>
</ul>
<p class="para">MMURTL is not meant to be a multiuser machine, like a UNIX box or mainframe. Instead, it is meant to interact with other users via the client-server model. This is in the same vein as Microsoft's Distributed Network Architecture (DNA), where the computing workload is spread out among users.</p>
<table border="0" cellspacing="0" cellpadding="0" class="note">
<tr>
<td valign="top" class="admon-check"></td><td valign="top" class="admon-title">Note&nbsp;</td><td valign="top" class="admon-body">
<p class="first-para">When Windows NT 4.0 was released in 1996, Microsoft really marketed DNA. DNA, however, was built around the limitations of the NT system more than anything else. It was not an independent movement with its own agenda. In other words, rather than point out the fact that NT was hobbled by its lack of multiuser support, the DNA campaign seemed to say, "yes, of course NT is not a multiuser system &mdash; we meant to do that."</p>
<p class="para">The Intel Pentium of 1996 was not capable of handling the kind of massive transaction load that high-end RISC hardware did. Again, the marketing people piped up, "oh, of course Windows machines can't handle 10 million transactions a day ... that's because Windows machines are meant to be clustered."</p>
<p class="last-para">I imagine that when some poor sysadmin pointed out NT's propensity to bluescreen back in 1996, years before the advent of service pack 5, a Microsoft marketing guy jumped onto a table and said, "hey, that's not a bluescreen. That's a nifty screen saver you can watch while the memory image dumps."</p>
</td>
</tr>
</table>
<p class="para">The primary IPC and synchronization mechanism in MMURTL is message passing. MMURTL's message-passing code is buried deep in the bowels of the kernel so that it is an integral part of the kernel's normal operation. For example, the task-switch mechanism in MMURTL is firmly rooted in the message-passing API.</p>
<p class="para">Instituting real-time response features also shaped MMURTL to a greater extent. With real-time systems, certain outside events must be acknowledged and processed in a specific amount of time. A good example of this would be patient monitoring equipment in a hospital. The primary impact that this had on MMURTL was to <a name="160"></a><a name="IDX-61"></a>allow outside events (i.e., the user) to force a task switch. Some multiuser operating systems implement their own strict policies and individual users have little or no control. With MMURTL, however, the user has much more control over what gets the processor's attention. Given that MMURTL is a single-user operating system, this makes sense.</p>
<p class="last-para">Unlike DOS, MMURTL was originally designed to use Intel's protected mode memory management. Surprisingly, MMURTL uses only minimal segmentation and does not bother to implement memory protection on the segment level. Instead, MMURTL makes use of paging to provide both memory allocation features and protection. These architectural idiosyncrasies are what make this operating system a good place to start.</p>
<a></a>
</div>
<div class="section">
<h3 class="sect3-title">
<a name="161"></a><a name="ch02lev2sec8"></a>MMURTL and Segmentation</h3>
<p class="first-para">MMURTL has only three memory segments. That is it. They are described in the operating system's GDT MMURTL constructs a segment for the operating system, a segment for application code, and a segment for application data. The best way to see this is to look at MMURTL's GDT definitions:</p>
<div class="informalexample">
<pre class="literallayout">
NullDesc    DQ 0000000000000000h ;The first desc is always null

OSCodeDesc  DW 0FFFFh         ; Limit 15-0 (4Gb)
            DW 0000h          ; Base  15-0
            DB 00h            ; Base  23-16  ;10000h
            DB 10011010b      ; P(1) DPL(00) 1 1 C(0) R(1) A(0)
            DB 11001111b      ; G(1) D(1) 0 0 Limit[19-16]
            DB 00h            ; Base  31-24

DataDesc    DW 0FFFFh         ; Limit (bits 0:15) at linear 00K
            DW 0000h          ; base (bits 15:0)
            DB 00h            ; base (bits 23:16)
            DB 10010010b      ; P(1) DPL(00) 1 0 E(0) W(1) A(0)
            DB 11001111b      ; G(1), B(1) 0 0 limit[19-16)
            DB 00h            ; Base at 0 (bits 31:24)

CodeDesc    DW 0FFFFh         ; Limit 15-0 (0FFFFh)
            DW 0000h          ; Base  15-0
            DB 00h            ; Base  23-16
            DB 10011010b      ; P(1)-DPL(00)-1-1-C(0)-R(1)-A(0)
            DB 11001111b      ; G(1) D(1) 0 0 Limit[19-16]
            DB 00h            ; Base  31-24
</pre>
</div>
<p class="para">It might be easier to see what this means if we decode the fields in each descriptor and construct a matrix. This is what I have done in <a class="internaljump" href="#ch02table01">Table 2.1</a>. I have always had a hard time reading descriptor tables myself:</p>
<a name="162"></a><a name="ch02table01"></a>
<table class="table" border="1">
<caption class="table-title">
<span class="table-title"><span class="table-titlelabel">Table 2.1</span></span>
</caption>
<thead>
<tr valign="top">
<th class="th" scope="col" align="left">&nbsp;</th><th class="th" scope="col" align="left">
<p class="table-para">
<b class="bold">OsCodeDesc</b>
</p>
</th><th class="th" scope="col" align="left">
<p class="table-para">
<b class="bold">DataDesc</b>
</p>
</th><th class="th" scope="col" align="left">
<p class="table-para">
<b class="bold">CodeDesc</b>
</p>
</th>
</tr>
</thead>
<tbody>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">Base address</b>
</p>
</td><td class="td" align="left">
<p class="table-para">0x00000000</p>
</td><td class="td" align="left">
<p class="table-para">0x00000000</p>
</td><td class="td" align="left">
<p class="table-para">0x00000000</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">Size limit</b>
</p>
</td><td class="td" align="left">
<p class="table-para">0xFFFFF</p>
</td><td class="td" align="left">
<p class="table-para">0xFFFFF</p>
</td><td class="td" align="left">
<p class="table-para">0xFFFFF</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">Limit units</b>
</p>
</td><td class="td" align="left">
<p class="table-para">4KB increments</p>
</td><td class="td" align="left">
<p class="table-para">4KB increments</p>
</td><td class="td" align="left">
<p class="table-para">4KB increments</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">32-bit code/data</b>
</p>
</td><td class="td" align="left">
<p class="table-para">Yes</p>
</td><td class="td" align="left">
<p class="table-para">Yes</p>
</td><td class="td" align="left">
<p class="table-para">Yes</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">Present in memory</b>
</p>
</td><td class="td" align="left">
<p class="table-para">Yes</p>
</td><td class="td" align="left">
<p class="table-para">Yes</p>
</td><td class="td" align="left">
<p class="table-para">Yes</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">
<b class="bold">Privilege</b>
</p>
</td><td class="td" align="left">
<p class="table-para">0x0</p>
</td><td class="td" align="left">
<p class="table-para">0x0</p>
</td><td class="td" align="left">

⌨️ 快捷键说明

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