hardware register access

Programming, for all ages and all languages.
Post Reply
a5498828
Member
Member
Posts: 99
Joined: Thu Aug 12, 2010 7:25 am

hardware register access

Post by a5498828 »

when hardware has mapped register and i access it via port or memory, what happens when length does not match?

for example, register has 2 bytes, and is mapped under 0x1000 port


what if i:
- access 4 bytes at 0x1000, will 2 higher bytes go to 0x1002 port?
- access 1 byte at 0x1000, will hardware zero/sign extend all other bytes, or continue to wait untill access to full register is completed
- access 1 byte at 0x1001

how does hardware detect access to register?
is it like it has OnWrite()/OnRead() functions, and when i access it 1 of them is called? What about instruction fetch from register (only mmio)
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

Re: hardware register access

Post by skyking »

In general you cannot tell, you have to consult the documentation for the CPU and the hardware you're trying to access (especially the latter). The hardware may be specific that it has to be accessed with a specific word length (there are signals on the bus that tells if it is 32-bit access or just 16-bit access or whatever). Also different data width may alter the side effects of the access.

Putting the program counter in I/O space is probably a very bad idea since the CPU is probably constructed for the scenario when code is executed from memory (which means it may take whatever shortcuts that are possible when dealing with memory like accessing it in larger chunks).
a5498828
Member
Member
Posts: 99
Joined: Thu Aug 12, 2010 7:25 am

Re: hardware register access

Post by a5498828 »

cpu is x86, i have 4 possible access types for ports.
in/out b/w/d/q

for memory much more because some instruction store even 64 bytes in memory (SSE).

simple example is apic/acpi/cmos, everything build on x86 mobo.

when i write 2 bytes instead of 1 word, what results will it produce?
hardware wait/ignore/interrupt on wrong type?


it would be easier if i would have emulator for this, but i dont have. i have only a pc and that is not enough to be efficient in learning this.
nikito
Member
Member
Posts: 42
Joined: Thu Jul 15, 2010 7:16 pm

Re: hardware register access

Post by nikito »

You have to read the specification for the device accessed. For example some devices that accepts 32 bits writes to port ignores the 16 bits and 8 bits writes to the same port. Thus, in such case it is even possible to map more that one devices in the exactly the same port.

And if you want to speed up you learning I recommend to you an hypervisor.

cheers

niki
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: hardware register access

Post by Owen »

Get yourself an emulator, but it wouldn't help for this specific case...

Theres one precise way of defining the behaviour of using the wrong operation size for IO:
Undefined
Post Reply