Memory mapped IO: pros/cons?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
xlq
Member
Member
Posts: 36
Joined: Mon Dec 11, 2006 7:51 am

Memory mapped IO: pros/cons?

Post by xlq »

What are the pros/cons of using memory-mapped io? I would have thought it would be slower, and would risk writing to random IO addresses if code somewhere fails.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

In all cases i know (for the x86), the device decides wether to use memory accesses or port accesses. In essence, you're stuck with it.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
JoeKayzA
Member
Member
Posts: 79
Joined: Wed Aug 24, 2005 11:00 pm
Location: Graz/Austria

Re: Memory mapped IO: pros/cons?

Post by JoeKayzA »

xlq wrote:I would have thought it would be slower, and would risk writing to random IO addresses if code somewhere fails.
That's what you would use an MMU for. AFAIK there is no difference in speed at all, btw, it's just a different set of instructions.
m
Member
Member
Posts: 67
Joined: Sat Nov 25, 2006 6:33 am
Location: PRC

Re: Memory mapped IO: pros/cons?

Post by m »

Hi.
xlq wrote:What are the pros/cons of using memory-mapped io?
Exactly,memory-mapping I/O has got both advantages and disadvantages.
I would have thought it would be slower,
(I think)It would be no slower than isolated I/O because it's implemented on hardware layer.It may take the I/O module little extra time to process the uniformed opcodes(or commands) and schedule the common resource.
and would risk writing to random IO addresses if code somewhere fails.
If the hardware doesn't provide such checks or protection,the error would occur.It's the softwares' responsibility to avoid its happening.

Another pro for memory-mapped I/O is that we can use almost all opcodes for memory operation to operate I/O as well,because in a system programmer's view,the opcodes are uniform.This would be convenient to process I/O in an efficient way.

And...What else? :roll:
User avatar
Hadrien
Posts: 9
Joined: Thu Oct 19, 2006 2:30 pm

Post by Hadrien »

The pros of memory mapped IO I can think of are :

1) it may be easier to understand

Maybe this is just me, but here are my thoughts. I started on Amiga / 680x0 where a range of addresses were used for IO. You just used the legacy instructions to move an int but used those special addresses. Simple to use and understand.

When I started to look at the x86, I was quite confused by the "in" and "out" instructions. It's only later I understood the concept of a dedicated IO piece of hardware inside the CPU.

2) it can be directly accessed without any assembly instruction

As shown in this hypothetical C++ example:

Code: Select all

// Read the mouse on my cool YBox 720 platform
int32* pRegMouseXY = (int32*) 0xffff4000;

int32 nMouseX = pRegMouseXY[0];
int32 nMouseY = pRegMouseXY[1];
Post Reply