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

📄 vxd-e3.html

📁 汇编语言编写的虚拟驱动程序
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta name="Author" content="Iczelion">
   <meta name="GENERATOR" content="Mozilla/4.7 [en] (Win98; I) [Netscape]">
   <title>Virtual Device Driver Skeleton</title>
</head>
<body text="#FFFFFF" bgcolor="#000080" link="#FFFF00" vlink="#8080FF" alink="#FF00FF">

<center>
<h1>
<font face="Arial,Helvetica"><font color="#FFFF99">Virtual Device Driver
Skeleton</font></font></h1></center>
<font face="Arial,Helvetica"><font size=-1>Now that you know something
about VMM and VxD, we can learn how to code a VxD. You need <b><font color="#66FF99">Windows
95/98 Device Driver Development Kit</font></b>. It's essential that you
have it. Windows 95 DDK is available only to MSDN subscribers. However,
Windows 98 DDK is available free of charge from Microsoft. You can also
use Windows 98 DDK to develop VxDs even if it is oriented toward WDM. You
can download Windows 98 DDK from&nbsp; <a href="http://www.microsoft.com/hwdev/ddk/install98ddk.htm?">http://www.microsoft.com/hwdev/ddk/install98ddk.htm?</a></font></font>
<br><font face="Arial,Helvetica"><font size=-1>You can download the whole
package, about 30 MBs or you can selectively download only the parts you're
interested in. If you choose not to download the whole package, don't forget
to download the Windows 95 DDK documentation included in <b><font color="#FFFF99">other.exe</font></b></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Windows
98 DDK contains MASM version 6.11d. You should upgrade it to the latest
version. For the information about where to download the latest version
upgrade, check my <a href="http://win32asm.cjb.net">main page</a>.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Windows
9x DDK contains several essential include files which are not included
in MASM32 package.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>You
can download the example in this tutorial <a href="files/firstvxd.zip">here</a>.</font></font></font>
<h3>
<font face="Arial,Helvetica"><font color="#66FFFF"><font size=+0>LE File
Format</font></font></font></h3>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>VxD uses
linear executable (LE) file format. This is the file format designed for
OS/2 version 2.0. It can contain both 16- and 32-bit code which is one
of the requirement of VxDs. Remember that VxDs date back from the days
of Windows 3.x. During that time, Windows boots from DOS so VxDs may need
to do some initialization in real mode before Windows switches the machine
into protected mode. Real-mode 16-bit code must be in the same executable
file as the 32-bit protected mode code. So LE file format is the logical
choice. Windows NT drivers blissfully don't have to deal with real mode
initialization so they don't have to use LE file format. Instead they use
PE file format.</font></font></font><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1></font></font></font>
<p><font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">Code
and data in an LE file are stored in </font><b><font color="#FFFF99">segments</font></b><font color="#FFFFFF">
with different runtime attributes. Below are the available </font><b><font color="#FFFF99">segment
classes</font></b><font color="#FFFFFF">.</font></font></font>
<ul>
<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">LCODE</font></b><font color="#FFFFFF">&nbsp;
Page-locked code and data. This segment is locked into memory. In other
words, this segment will not be paged to disk, thus you should use this
segment class judiciously so as not to waste precious system memory. Code
and data that must be present in memory at all time should be in this segment.
Especially the hardware interrupt handlers.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">PCODE</font></b><font color="#FFFFFF">
Pageable code. This segment is pageable by VMM. Code in this segment needs
not be present in memory all the time. VMM will page this segment to disk
if it needs physical memory.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">PDATA</font></b><font color="#FFFFFF">
Pageable data.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">ICODE</font></b><font color="#FFFFFF">
Initialization-only code. The code in this segment is used during initialization
of the VxD only. After initialization, this segment will be discarded by
VMM to reclaim physical memory.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">DBOCODE</font></b><font color="#FFFFFF">
debug-only code and data. The code and data in this segment is used when
you run the VxD under a debugger. It contains the handler for Debug_Query
control message, for example.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">SCODE</font></b><font color="#FFFFFF">
Static code and data. This segment will always be present in memory even
when the VxD is unloaded. This segment is especially useful for dynamic
VxD when it must be loaded/unloaded many times during a Window session
and wants to remember the last configuration/state.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">RCODE</font></b><font color="#FFFFFF">
Real-mode initialization code and data. This segment contains the 16-bit
code and data for real mode initialization.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">16ICODE</font></b><font color="#FFFFFF">
USE16 protected-mode initialization data. This segment is a 16-bit one
which contains the code that the VxD will copy from protected mode to V86
mode. For example, if you want to paste some V86 code into a VM, the code
you intend to paste must be in this segment. If you put the code in other
segment, the assembler will generate wrong code, i.e. it will generate
32-bit code instead of the intended 16-bit one.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font size=-1><b><font color="#FFFF99">MCODE</font></b><font color="#FFFFFF">
Locked message strings. This segment contains message strings which are
compiled with the help of VMM message macros. This helps you create international
versions of your driver.</font></font></font></li>
</ul>
<font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">It doesn't
mean your VxD must have </font><b><font color="#FFFF99">ALL</font></b><font color="#FFFFFF">
those segments. You can choose the segments you want to use in your VxD.
For example, if your VxD doesn't have real-mode initialization, it doesn't
have to have </font><b><font color="#FFFF99">RCODE</font></b><font color="#FFFFFF">
segment.</font></font></font>
<br><font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">Most
of the time, you would use </font><b><font color="#FFFF99">LCODE</font></b><font color="#FFFFFF">,
</font><b><font color="#FFFF99">PCODE</font></b><font color="#FFFFFF">
and </font><b><font color="#FFFF99">PDATA</font></b><font color="#FFFFFF">.
It's your judgement as a VxD writer to choose the appropriate segments
for your code/data. In general, you should use </font><b><font color="#FFFF99">PCODE</font></b><font color="#FFFFFF">
and </font><b><font color="#FFFF99">PDATA</font></b><font color="#FFFFFF">
as much as possible because VMM can page the segments in and out of memory
if necessary. You should use </font><b><font color="#FFFF99">LCODE</font></b><font color="#FFFFFF">
to store hardware interrupt handlers and services that will be called by
hardware interrupt handlers.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>You
don't use those segment classes directly. You must declare segments based
on those classes. Those segment declarations are stored in the module definition
file (.def). The full-scale module definition file for a VxD is below:</font></font></font>
<blockquote><tt><font color="#FFFF99"><font size=-1>VXD FIRSTVXD</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>SEGMENTS</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _LPTEXT&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'LCODE'&nbsp;&nbsp;&nbsp; PRELOAD NONDISCARDABLE</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _LTEXT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'LCODE'&nbsp;&nbsp;&nbsp; PRELOAD NONDISCARDABLE</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _LDATA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'LCODE'&nbsp;&nbsp;&nbsp; PRELOAD NONDISCARDABLE</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _TEXT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'LCODE'&nbsp;&nbsp;&nbsp; PRELOAD NONDISCARDABLE</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _DATA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'LCODE'&nbsp;&nbsp;&nbsp; PRELOAD NONDISCARDABLE</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; CONST&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'LCODE'&nbsp;&nbsp;&nbsp; PRELOAD NONDISCARDABLE</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _TLS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'LCODE'&nbsp;&nbsp;&nbsp; PRELOAD NONDISCARDABLE</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _BSS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'LCODE'&nbsp;&nbsp;&nbsp; PRELOAD NONDISCARDABLE</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _LMGTABLE&nbsp;&nbsp;
CLASS 'MCODE'&nbsp;&nbsp;&nbsp; PRELOAD NONDISCARDABLE IOPL</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _LMSGDATA&nbsp;&nbsp;
CLASS 'MCODE'&nbsp;&nbsp;&nbsp; PRELOAD NONDISCARDABLE IOPL</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _IMSGTABLE&nbsp;
CLASS 'MCODE'&nbsp;&nbsp;&nbsp; PRELOAD DISCARDABLE IOPL</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _IMSGDATA&nbsp;&nbsp;
CLASS 'MCODE'&nbsp;&nbsp;&nbsp; PRELOAD DISCARDABLE IOPL</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _ITEXT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'ICODE'&nbsp;&nbsp;&nbsp; DISCARDABLE</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _IDATA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'ICODE'&nbsp;&nbsp;&nbsp; DISCARDABLE</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _PTEXT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'PCODE'&nbsp;&nbsp;&nbsp; NONDISCARDABLE</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _PMSGTABLE&nbsp;
CLASS 'MCODE'&nbsp;&nbsp;&nbsp; NONDISCARDABLE IOPL</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _PMSGDATA&nbsp;&nbsp;
CLASS 'MCODE'&nbsp;&nbsp;&nbsp; NONDISCARDABLE IOPL</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _PDATA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'PDATA'&nbsp;&nbsp;&nbsp; NONDISCARDABLE SHARED</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _STEXT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'SCODE'&nbsp;&nbsp;&nbsp; RESIDENT</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _SDATA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'SCODE'&nbsp;&nbsp;&nbsp; RESIDENT</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _DBOSTART&nbsp;&nbsp;
CLASS 'DBOCODE'&nbsp; PRELOAD NONDISCARDABLE CONFORMING</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _DBOCODE&nbsp;&nbsp;&nbsp;
CLASS 'DBOCODE'&nbsp; PRELOAD NONDISCARDABLE CONFORMING</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _DBODATA&nbsp;&nbsp;&nbsp;
CLASS 'DBOCODE'&nbsp; PRELOAD NONDISCARDABLE CONFORMING</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _16ICODE&nbsp;&nbsp;&nbsp;
CLASS '16ICODE'&nbsp; PRELOAD DISCARDABLE</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; _RCODE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CLASS 'RCODE'</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>EXPORTS</font></font></tt>
<br><tt><font color="#FFFF99"><font size=-1>&nbsp;&nbsp;&nbsp; FIRSTVXD_DDB&nbsp;
@1</font></font></tt></blockquote>
<font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">The first
statement is for declaration of the VxD name. The name of a VxD
</font><b><font color="#FFFF99">MUST</font></b><font color="#FFFFFF">
be all uppercase. I experimented with the lowercase name, and the VxD refused
to perform anything except loading itself into memory.</font></font></font>
<br><font face="Arial,Helvetica"><font size=-1><font color="#FFFFFF">Next

⌨️ 快捷键说明

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