Reliable reading and writing of physical memory cells under Windows95

xiaoxiao2021-03-06  39

When the computer is running under the DOS platform, the memory addressing mode is a real mode. The memory paging linear management technology of the 20-bit address line of 80286 is used. The memory capacity is 1MB, the linear address is consistent with the physical address, and the physical memory cell read and write directly ,flexible. However, due to limited to 640K basic memory, the use of large amounts of extended memory is restricted, and the 64K scope limit of the paging affects the continuity of memory access, so that the system's memory resources are difficult to obtain fully utilization.

When the computer is running in Windows95 protection mode, the system may be one of the two memory addressing modes due to the system or system of driver compatibility. Virtual 8086 Memory Address Mode (V86 mode) in mode. For these two modes, you must implement reading and writing of physical memory cells, and the method is very different. When we run Windows programs with memory read and write, we often fail to fail because you don't know what addressing mode is currently in the system, so it is necessary to discuss this.

2. Memory addressing mode in protection mode

When the CPU runs in the protection mode of the segmentation management, the virtual memory of 4G byte address access space can be utilized, and complete protection functions can be implemented through the check of the privilege and the definition value. At this point, Windows Memory is controlled by the Global Descriptor Table (GDT) and the Local Descriptor Table (LDT) and is used in a selector-based manner. The description of each segment corresponds to one of the descriptors, called a segment descriptor, respectively corresponds to a corresponding physical memory segment. Each segment descriptor is constructed of three parameters: Segment Base (BASE) specifies the start address of the linear address space; the segment limit (limit) represents the maximum offset within the segment; Proterty means this paragraph Some features. The far pointer of physical memory access is made by the selector: Offset (OFFSET), which represents the real address of a certain segment register, but is used to determine the segment descriptor in the description. The entrance address in the table, the data content stored in the corresponding position in the descriptor table is its real physical memory address. In the case where there is no paging (the page case is determined by Property), the three-bit memory physical address is formed by shifting the BASE left left to the left descriptor.

This addressing mode in protective mode breaks the restrictions of memory addressing in real mode, and improves the efficiency of memory resources.

3. V86 mode in Protection mode In order to make DOS real mode applications without modification, you can run directly in DOWS95 protection mode, and the system provides V86 mode. It is very similar to the memory addressing mode in the real mode, providing the linear paging management technology within the segment, controls the paging features by the attribute part of the segment. When the system enters the V86 mode, the reading and writing method of the physical memory cell is identical to the DOS real mode in the application. When running the application in the DOS real mode in the protective mode mode, Windows Virtual Machine Manager (VMM) creates a virtual 8086 machine, which simulates all 8086 processors, including memory, I / O devices, and All TSRs, device drivers, and network software running while starting Windows, so that the application is running, and then resumes the original protection mode after executing the application. It is worth noting that although the program code of the DOS real mode is running in V86 mode, it is not running similar to the real model, but is running similar to the protection mode, so it is said that the V86 model is a function. The protection mode of the mode software.

If the system is in a V86 mode, the physical memory unit cannot be read and written using the memory addressing mode in the protection mode, but must be read and written in the memory addressing mode in the real mode. Under Windows95 you can view the "Control Panel" System | Performance page, if you see the "Drive C: Paging Storage Technology" "Compatible Paging Storage Technology Reduces the entire system performance", it means that the system is In V86 mode; if you see "Your system is information according to the optimal performance", the system is in the memory log in the protection mode. 4. Reliable reading and writing of physical memory cells under Windows95

Due to the above reasons, we must take into account two addressing patterns when writing procedures under Windows95, so that the procedures can be run in real protection mode, but also function properly when the system is in V86 mode to improve program operation. Reliability. Below is the main code of the program:

(Long Far Pascal _export WndProc (HWND HWND, Unit Message,

WPARPAM WPARAM, LPARAM LPARAM)

{

Unsigned Int i;

Char far * pt; // memory unit read writing pointer

Uint selector1, selector2;

Word segment, offset, start;

DWORD BASE, LIMIT;

Bool flag;

Flag = true;

CHAR TEST [10];

Switch (Message)

{

Case WM_CREATE:

__ASM Move Selector1, DS; // Put the Data Segment Register DS as a template

Selector2 = allocselector (selector1); // Assign a new selector

IF (selector2 == null) // protection mode failed

{

Flag = false;

PT = (Char Far *) 0xD000; // V86 pointer

}

Else

{

Segment = 0xD000; // Accessing Physical Segment Biye

OFFSET = 0x0100; // Access boundary

START = 0x0000; // Access the offset start address

Base = (unsigned long) segment)

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

New Post(0)