Memory management in virtual 8086 mode

Source: Internet
Author: User

The V86 we use below refers to the virtual 8086 mode. In previous tutorials, you learned how to simulate V86 interrupts, but there was one problem that was not resolved: exchanging data between VxD and V86 code. Here we will learn how to use the V86 memory Manager to implement this feature. Download the example program here

Theory

If your VxD runs with some V86 programs, how to transfer large amounts of data to V86 programs or transfer large amounts of data from V86 programs is a big problem sooner or later. It is not realistic to transmit large amounts of data through registers. Perhaps your next idea is to allocate a chunk of memory in the RING0 and pass the pointer over some registers to the V86 program so that it can access the data. If you do this, you may damage your system because V86 address positioning requires segment:offset, not linear positioning. There are many ways to solve this problem. However, I chose a simple method provided by the V86 memory manager.

If you can find a free block of memory within the range of V86 memory you can use as a communication buffer, this will solve one of the problems. However, the problem of pointer transfer still exists. You can solve these two problems by V86 the Memory Manager service. The V86 memory Manager is a static VxD that manages memory for V86 applications. It also provides EMS and XMS services for V86 applications and API delivery services for other VxD. API routing is the process of copying data from RING0 to V86 range and transmitting V86 buffer address to V86 code. The V86 memory manager has a transfer buffer within the V86 memory range that contains the data that the VxD copies to the V86 memory range, and vice versa. The initial buffer is 4K. You increase its size by calling V86mmgr_set_mapping_info.

Now that you know the transmission buffer, how do we copy or copy the data? This problem is solved by invoking two services: V86mmgr_allocate_buffer and V86mmgr_free_buffer.

V86mmgr_allocate_buffer allocates a chunk of memory from the transfer buffer and copies some data from the RING0 to the allocated V86 buffer. V86mmgr_free_buffer is just the opposite: it copies some data from the allocated V86 memory block to the RING0 buffer and frees the memory blocks allocated by the V86mmgr_allocate_buffer.

Remember, the V86 manages the allocated buffer as the memory manager does on the stack. This means that the allocation/release must be in accordance with the advanced rules. So if you call two times V86mmgr_allocate_buffer, the first v86mmgr_free_buffer will release the buffer allocated by the second V86mmgr_allocate_buffer call.

Let's take a look at the definition of V86mmgr_allocate_buffer, which is a service for basic register transfer parameters.

EBX the handle of the current VM
EBP Pointer to the client register structure of the current VM
ECX the number of bytes allocated from the transfer buffer CARRY FLAG carry flag bits, such as you do not want to copy data from the RING0 buffer to the allocated memory block to clear zero, if you want to copy data from the RING0 buffer to the allocated memory block 1
Fs:esi points to the Selector:offset pointer to the RING0 buffer, which has data to be copied into the allocated buffer if the carry flag bit is zeroed, ignore it.
If the call succeeds, the carry flag bit is cleared 0 and the ECX contains the number of bytes contained in the transfer buffer. This value should be smaller than the number you requested, so you should keep the value, V86mmgr_free_buffer will use it later. The high word EDI contains the V86 segment address of the allocated memory block, and the offset address is in the low word. The digit of the carry flag is placed when the error occurs.

V86mmgr_free_buffer and V86mmgr_allocate_buffer accept the same parameters.

When you call V86mmgr_allocate_buffer, you allocate a chunk of memory to the current VM's V86 memory range and place its address in EDI. You can use these services to transfer data to V86 interrupts or to obtain data from V86 interrupts.

In additional API routing, the V86 memory Manager also provides API mapping services to other VxDs. The API mapping service maps some pages in extended memory to the V86 memory range of each VM. You can use V86mmgr_map_pages to perform API mapping. With this service, the page is mapped to the same linear address space of each VM. If you are only working on a VM, this will waste the address space. Because API mapping is slower than API routing, you can use API routing as much as possible. API mappings are used only on V86 operations that have access to the same linear address space and function to all VMS.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.