Writing of Windows 95 device drivers

zhaozj2021-02-11  217

Write an Equipment Driver for Windows95 Extraction / Jianghu Kid 1999.08.07

1  Why do I need a device driver starting from Windows 3.1, a method of devices driver is taken from the access to the hardware device, and the client obtains hardware parameters or settings through the device driver, but due to the 16-bit operating system based on the original DOS, so the client can still be used to achieve the hardware by some BIOS or DOS DPMI interrupt calls. 32-bit operating systems, such as Windows 95 & NT, no longer base in 16-bit DOS, the use of users, if you need to realize the hardware, DMA, I / O, oriental is a reserved storage, and youdomllically need to pass the device driver. Windows 95 operating system enables multi-threaded, multi-process applications, and system through a virtual machine manager VMM 32, VXD (Virtual Machine Manager, with other device drivers, to achieve coordination work between multiple processes Prevent the operation of a process lead to the crash of another process. 2 What is the preparation of the driver's order setup drive program is used to manage system resources (hardware or software) can be executed, and multiple processes can be used in parallel with the same time, and can be implemented in parallel. The preparation driver is in the case of "VXD" as a compact name, which means that virtuality is virtualized some of the devices (virtual "Something" Device). In general, the device driver and virtual equipment are synonymous, and they will be mixed underneath. 386 microprocessors have 4 superior levels: 0, level 1, level 2, level 3, generally operated system operations in the first grade 0, and the user program is running 3. VXD is running at level 0, and its location in memory is also within the space of the operating system. Windows 95 is inheriting Windows 3.x, so the device driver of both is the same mode, that is, the device driver typically written by Windows 3.x, can not be turned to Windows 95 Next; but there are some differences: General Windows 95 The driver below is "VXD" as a suffix name, and Windows 3.x is called "386" as a suffix; Windows 3.x device driver must start in Windows Static load, and Windows 95's device drivers can be dynamically loaded during program operation.

Windows NT uses a full mode in which Windows 95 & 3.x is used in Windows 95 & 3.x, which cannot be compatible with Windows NT. In addition, Windows also provides a driving process on prior grade 3, and the primary is the serial order of the serial port and the printer of the parallel port. These procedures are "DRV" as the suffix name. But it is a short period of time, the I / O competition in the superior level 3 is 6. 3  Device driver writing Introduction to the preparation of the device driver has a certain specification, it is necessary to be more familiar with 32-bit assembly and C language; generally prepared by assembly language, but can also be implemented with C and compilation; first need Microsoft DDK (Device Driver Kit), general tools are Masm6 11 and VC2  0 or higher. Tongyi Equipment driver is composed of five segments, they are divided: vxd - code, vxd- data, vxd - icode, vxd - iData, and vxd - real - init. Vxd -code is the code segment in the protection mode. Generally, this segment includes the control program of the device driver, the recycling function, the service, and the interface function. This segment is also named -ltext; vxd - data is the data segment in the protection mode, Generally, a descriptor table of the device driver, and some global variables, this segment is also named - LDATA; VXD- icode is the initialization code segment in the protection mode, including some service programs used in initialization, virtual machine manager (VMM) Cance this segment after the end of the initialization, this segment is also named - IText; VXD - iDATA is the initial data segment in the protection mode, including some of the data used in initialization, the virtual machine manager (VMM) after the initialization Cancel this section, this section is also named - iData; vxd -real - init includes initialization data and code segments in real mode, the virtual machine manager (VMM) first is loaded into this code segment, after the process returns this Cancellation, then load other code segments, this section is named - RTEXT.

What needs to be noted is that in addition to the initialization data and code segment under the real mode, his four paragraphs are the para-square plate model (Flat model). Each device driver must first first sound a virtual machine's name, version number, initialization process, virtual imperial control program (corresponding to the program); Some setup drivers can also make a sound sign number and interface function (API). Virtual machine generally uses Declare -Virtual - Device macro, such as the following example: Declare - Virtual - Device vsampled, 4,0, vsampled - control, / vsampled - device - id, vsampled - init - order, / vsampled - v86 API - Handler, VSAMpled - PM - API - Handler Means Sample Virtual Machine INIT - ORDER Describes the process of initialization, and the two interface functions in V86 mode and protection mode are supported in the following description. Through these sounds, we can determine a single virtual machine, the system can use it and other virtual machine parts. Each virtual machine requires a virtual machine control program. The virtual machine pipetter (VMM) passes through this order to pass control information to the virtual machine, and systematically pass control information to control the virtual machine's execution, such as the initialized virtual machine, the change of the virtual machine status. A virtual machine requires some service functions, which can be used by virtual machine tube (VMM) or other virtual machine. However, the virtual machine does not provide an exit function (Export function), the virtual machine manager (VMM) through the 0x20 interrupt, and the interrupt handler is determined by a service number to determine which virtual machine support through a service number through a service number through a service number. This service function. A virtual machine defines two macros of BeginProc and EndProc to define its service function, which is very similar to the language.

For example, the next example: beginproc vsMap - service - routine, servicemain body of the service ... Endproc vsampled - service - Routine General BeginProc's name is a parameter: Service or Async - Service, the latter is the service program Can be called asynchronously, in the interrupt service program, the asynchronous service program must be reinforced, so it cannot call the service program that cannot be re-entered. Second, the image acquisition card device driver Due to the actual needs, we design a piece of image capture card to implement the real-time acquisition of the image. Due to the large amount of image data transmission, the real-time demand is strong, so we use the PCI bus; the software platform uses Windows 95. 1 System Hardware Simple Due Series Take the SAA7110 of the Philips Division as a front-end image collector, while the PCI interface chip uses Zr36120 of the color Lay Zoran serve as a joint working chip, two chips are program-programmed chips. The ZR36120 is a controller for multimedia application design, which has both PCI bus operated, but also has multi-media control-controlled functionality, as shown in image data, is a multimedia Controller for PCI BUS. It has two sets of registers, a set of Configuration Registers; another group is based on user-applied registers, named ASR (Application - Specific Registers), which is primarily for users. Applying, including some image data formats, selection, interrupt mode settings, DMA channel selection, and address, etc. Register, ASR's access is used by memory mapping. 2  Software Settings The system must be operated on hardware, including: (1) DMA memory distribution. The data of the image is to transmit to the host through the DMA method, and must be distributed to the DMA channel with the image size of the image. Inform the PCI interface chip and client program, the address required by the PCI interface chip is an absolute physical address. The address used by the client is a virtual address (32-bit of the flat panel mode is linear address), how to correspond to both (2) Initialization of the interface chip Zr36120 and the image acquisition chip SAA7110.

You need to read and write the ZR36120's configuration register, and use I / O squares or is broken in the BIOS; the additional ZR36120 ASR uses memory mapping mode to read and write. The solutions of these issues are not retracted to avoid the preparation driver to realize the operation of the hardware, and the user-running program in prizer 3 is unmanaged. • DMA memory points must first be added to DMABUFFERSIZE = 2048k in Windows 95 System.ini (here you are 2M, and the actual size of DMA operations). The system will be used in the latter memory in the latter, and the user is used to use after DMA operation. The user is divided into memory in the order of self-issuance, which is now incorporated in the question of this memory. Microsoft DDK's kernel provides VDMAD -REQUEST - Buffer system call, and the system is applied to the system, and the linear address of the DMA buffer is transmitted through ESI, the size of the buffer is incorporated by ECX. The physical address of the DMA region is passed out through the EDX, and the sign number is passed by EBX. After the application of the DMA area, we must use VDMAD - LOCK - DMA - Region to lock the zone to our back. After distributing DFMA memory, it is necessary to implement the exchange of DMA memory and user space data. DDK provides VDMAD - COPY - From - Buffer This system call is currently transmitted from the DMA zone to the user data area. Among them, in the parameter in which the ESI storage is used, the ECX storage data area is small, and the deployment of the displacement mark in EBX, and EDI deposits. If the operation is successful, the CF bit is reset; if the failure, the CF position is located. An additional provision of VDMAD - COPY - TO - Buffer is now copied to the DMA buffer to the DMA buffer area, and its input and output parameters are in the same manner. The ASR of the memory mapping method ZR36120 must use the square of the memory mapping to realistically read and write.

The so-called memory mapping is that some chips make some registers on a certain period, and the system can access them like usually accessing memory; but this memory map must be a blank memory segment on the host, not saved. Memory conflict, such as 0xF00000000; the address of the map is a physical address, read and written in the client, and we must convert this physical address to a linear address. DDK provides - MAPPHYSTOLINEAR This call to implement the mapping of the physical address as a linear address, but this call can only be converted to the physical address of the peripheral to linear, not the memory space of the computer itself; incoming parameters are three A, the first parameter is the start address of the physical address, the second parameter is the length, the third is the flag bit, typically 0; the returned parameter is the linear address below the priority 0. For example, VMMCall - MAPPHYSTOLINEAR, <0F0000000H, 1000h, 0> is a segment of the standby physical address to 0xF0000000 to be transmitted to the memory. • Port Operations WINDOWS 95 does not protect the ports, which can be mainly considered for serial communication equipment and parallel printing equipment. The application program can be used to realize the operation of the port with the transfer system function or a direct contact language. For example, in the VC, there is -Outp, - OUTPW, - OUTPD, - INP, - INPW, - INPD and other functions. However, it is fast in the superior level 0, and can be operated with multi-process, and the port operation of the general hardware is the best in the device driver. According to the standard of PCI bus 2  0, the Configuraiotn Registers consists of 256 bytes, with the first 64-bit constitutes a Configuraiotn Header, mainly including some hosts (Client). Interface information, such as device numbers, vendors, interrupt numbers used, range (I / O mode), memory address (memory mapping mode) .... For the read and write of the Configuration Registers, there are two formulas: first, through the sub-function number 0xB1 of the BIOS in the BIOS, it is completed, which is the system set by the previous system.

The second, through the reading and writing of the two-port site 0xcf8 and 0xcfc, the read and write is read, and this method is the same system-compatible system, and the feature is simple. We detail the second method in detail: Port Address 0xcf8 is the address register of the configuration register, and each of its 32-bit operations is as follows: bus number, FunctionNumber and Device Number are allocated by the system when the computer is started, register Number is the register number we need to read and write, the lowest two digits are 0, and 8 bits just constitute a 256-byte configuration register address space. The mouth address 0xcfc is the data register. After writing the address, the double word read by the port is sent to the value of the parallel register, and a double word is written to the write operation of the corresponding register. After understanding the meaning of each operation, we can use two assembly instructions in and out to achieve our goal, note that this operation must be two-word operation, for example: in Eax, DX or Out DX, EAX One type of instead of converting a double-word operation into a two-word word or four byte operations. • The customer program is written on the preparation drive program. It is a write-down programming. The next step is given a detailed analysis of the customer's procedure (the general user program, the most common is to use C and C write), such as the modulation of the device. If the result is a standard API function, the customer program can be operated by a function library through the call system standard. But if the defined is not the standard function provided by the system, the interface function is the user's hardware or software development, so it generally does not adopt a standard interface function, which cannot be called from the standard library, but this is also the most Something often appearing, let's take a detailed description of the call in the C language. After a hardware is deficient, this hardware is used as a file system and is used by system; UNIX uses this mode, and now Windows 95 & NT is also useful.

32-bit system calls provide a createfile to open or create "files", where the "file" that can be opened is: files, pipes, communication devices, disk devices, controls, directories ...; We may wish to suppose our The driver name is called PCLIDEVICE.VXD. As mentioned earlier, let's open this device file with the CreateFile system function, get a handle, as shown in the following example: hcvxd = cretefile ("pcidevice.vxd", 0, 0, 0, create - new, file - flag - DELETE - ON - Close, 0); After opening this device, we can exchange it with it. For example, the image data acquisition card has passed the data into the memory through the DMA mode, we need to transfer the data through the device driver into our program's memory, our device drivers have subroutines Vxd - Copy - Out - Of - DMA - Buffer, it is input to two parameters, one is the address of the application buffer, the second is the length of the buffer; the output is a parameter, the representative operation is successful or failed. This task can be completed in the following examples: DeviceIocontrol (HcVXD, VXD - Copy - Out - Of - DMA -Buffer, (LPVOID) ININFO, SIZEOF (ININFO), (LPVOID) Retinfo, Sizeof (Retinfo), & CbbytesReturned, NULL); where the first parameter is the handle of the device we open in front, the second is the code, the third parameter, and the fourth parameters we have to perform, the parameters and size of the incoming parameters (generally used How much bits are indicated, such as the two parameters in our example are long plastic surgery, then the fourth parameter is 8; the second, sixth and seventh parameters are returned parameters and their size, respectively; the eighth parameters are Device drivers for asynchronous mode, such as interrupt service programs. Third, the program references the following programs are some key subroutines for the device driver of my image capture card, but not to list the routines related to the hardware device. For the convenience of the description, I will replace the global variables, below The program is compiled with VC5  0, MASM6  11 and DDK.

.386p.xlistinclude vmm.incinclude vdmad.incinclude configmg.inc.listextern - lineadr: DWORDextern - bufsize: DWORDextern - physadr: DWORDextern - buffid: DWORDVxD - LOCKED - CODE - SEG linear address returned in EAX, high-level languages ​​can be like general procedure call to obtain the same linear address public Phys2LinearPhys2Linear PROCVMMCall - MapPhysToLinear, <080000000h, 1000h, 0> on the starting physical address 0x80000000 memory section length linear address 0x1000 retPhys2Linear ENDP; DMA memory allocation area, and a latch section phblic Alloc - Lick - DMA - Regionalloc - Lock - DMA - Region Procmov ESI, - LineAdr , EBX; marker number in EBX MOV ESI, - LineAdr Mov ECX, - BUFSIZE MOV D1, 1 VXDCALL VDMAD - LOCK - DMA - Region Retalloc - Lock - DMA - Region Endp; Copy data from the DMA area to the user's memory PUBLIC COPY - From - DMA - Buffercopy - From - DMA - Buffer Proc Mov EBX, - Buffid; Sign Number MOV ESI, - LineAdr; User Linear Address XOR EDI, EDI; DMA Buffer relative start address MOV ECX, - buffs; long vxdcall vdmad - copy - from - buffercopy - from - DMA - BUFFER ENDP; DMA memory FREE - DMA - Region Proc MOV ESI, - LineAdr Mov ECX, - BUFSIZE VXDCALL VDMAD - UNLOCK - DMA - Region Mov EBX, - Buffid vxdcall vdmad - Release -

转载请注明原文地址:https://www.9cbs.com/read-4016.html

New Post(0)