Because desktop windows runs on the x86 Platform in most cases, there is no portability problem between different platforms. However, Windows CE runs on the CPUs of four architectures (x86, shx, MIPS, and arm), so you need to consider porting it when writing applications.
The following describes how to write a portable application by accessing the physical address in the wince system.
First, two concepts must be clarified.
1. I/O addresses are available on the X86 platform. I/O ports are not available on CPUs of other systems (such as ARM/MIPS. Because I/O and memory are separated from each other in x86, there are two types of addresses, and other CPUs are the unified addressing of the two, that is, the I/O is mapped to the memory.
2. The storage management of Wince is implemented through MMU. After the system is started, we can only access the virtual storage space, which must pass through MMU. However, in x86, the access to the I/O port is different from the address bus used by the memory, without passing through MMU.
For example, if we want to access a port with a physical address of H attached to a bus, we can directly embed the physical address for the assembly operation on the X86 platform, or use the address pointer to access the physical address. However, for other platforms, we must first map physical addresses to virtual addresses and then operate on their virtual addresses. Obviously, the program is not portable. We need to define # ifdef _ x86... # Elif defined _ arm so that the program can run smoothly on different platforms.
If the following code is used, we don't need to define different platforms so hard:
First define
Iniospace = 1;
Iophysicalbase. quadpart = 0x360;
If (haltranslatebusaddress (ISA, // This function maps the physical address on the ISA bus to the physical address of the system.
0,
Iophysicalbase,
& Iniospace, // This parameter = 1 indicates that the I/O space address is converted, and the memory address is equal to 0.
& Iophysicalbase ))
{
If (! Iniospace) // if it is a memory address, for non-x86 platforms
{
Ioportbase = (puchar) mmmapiospace (// This function converts the physical address of the system to a virtual address
Iophysicalbase,
Iolen,
False );
If (ioportbase = NULL)
{
// Todo: Error Handling
}
}
Else // For I/O, that is, in x86, address ing is not required.
{
Ioportbase = (puchar) iophysicalbase. lowpart;
}
}
Else
{
// Todo: Error Handling
}
Then we can fully explore the portability of port operations (ioportbase. By using read_port_uchar,
Write_port_uchar and other windows under wince to implement port read/write. Instead of using a pointer in x86 (not only poor portability, but also prone to problems ). Macros under CE are encapsulated API functions internally. For example, the macro write_port_uchar is converted into an out assembly instruction on the x86 processor, while the macro is converted into a write instruction on the virtual address on the ARM processor.
In wince5.0, you can use createbusaccesshandle (bus registry path) + bustransbusaddrtovirtual to directly change the physical address of the bus to the virtual address of the system. This method is more portable on different platforms than oemaddresstable + virtualalloc + virtualcopy.