What real platforms map hardware ports to memory addresses?

后端 未结 8 985
孤街浪徒
孤街浪徒 2021-02-03 12:47

I sometimes see statements that on some platforms the following C or C++ code:

int* ptr;
*ptr = 0;

can result in writing to a hardware input-ou

相关标签:
8条回答
  • 2021-02-03 13:20

    You can do this in modern Windows (and I'm pretty sure Linux offers it too). It's called memory mapped files. You can load a file into memory on Windows and then write/alter it just by manipulating pointers.

    0 讨论(0)
  • 2021-02-03 13:23

    This is called Memory-mapped I/O, and a good place to start is the Wikipedia article.

    Modern operating systems usually protect you from this unless you're writing drivers, but this technique is relevant even on PC architectures. Remember the DOS 640Kb limit? That's because memory addresses from 640K to 1Mb were allocated for I/O.

    0 讨论(0)
  • 2021-02-03 13:24

    It is mostly used when writing drivers, since most peripheral devices communicate with the main CPU through memory mapped registers.

    0 讨论(0)
  • 2021-02-03 13:30

    Most systems in my experience use memory-mapped I/O. The x86 platform has a separate, non-memory-mapped I/O address space (that uses the in/out family of processor op-codes), but the PC architecture also extensively uses the standard memory address space for device I/O, which has a larger address space, faster access (generally), and easier programming (generally).

    I think that the separate I/O address space was used initially because the memory address space of processors was sometimes quite limited and it made little sense to use a portion of it for device access. Once the memory address space was opened up to megabytes or more, that reason to separate I/O addresses from memory addresses became less important.

    I'm not sure how many processors provide a separate I/O address space like the x86 does. As an indication of how the separate I/O address space has fallen out of favor, when the x86 architecture moved into the 32-bit realm, nothing was done to increase the I/O address space from 64KB (though they did add the ability to move 32-bit chunks of data in one instruction). When x86 moved into the 64-realm, the I/O address space remained at 64KB and they didn't even add the ability to move data in 64-bit units...

    Also note that modern desktop and server platforms (or other systems that use virtual memory) generally don't permit an application to access I/O ports, whether they're memory-mapped or not. That access is restricted to device drivers, and even device drivers will have some OS interface to deal with virtual memory mappings of the physical address and/or to set up DMA access.

    On smaller systems, like embedded systems, I/O addresses are often accessed directly by the application. For systems that use memory-mapped addresses, that will usually be done by simply setting a pointer with the physical address of the device's I/O port and using that pointer like any other. However, to ensure that the access occurs and occurs in the right order, the pointer must be declared as pointing to a volatile object.

    To access a device that uses something other than a memory-mapped I/O port (like the x86's I/O address space), a compiler will generally provide an extension that allows you to read or write to that address space. In the absence of such an extension, you'd need to call an assembly language function to perform the I/O.

    0 讨论(0)
  • 2021-02-03 13:32

    PlayStation. That was how we got some direct optimized access to low-level graphics (and other) features of the system.

    0 讨论(0)
  • 2021-02-03 13:33

    See Embedded-Systems for examples of devices that use Memory-mapped I/O e.g. routers,adsl-modems, microcontroller etc.

    0 讨论(0)
提交回复
热议问题