Page 1 of 1

hardware register access

Posted: Thu Aug 12, 2010 7:36 am
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)

Re: hardware register access

Posted: Thu Aug 12, 2010 8:03 am
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).

Re: hardware register access

Posted: Thu Aug 12, 2010 10:57 am
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.

Re: hardware register access

Posted: Thu Aug 12, 2010 11:22 am
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

Re: hardware register access

Posted: Thu Aug 12, 2010 11:23 am
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