embedded - Controlling read and write access width to memory mapped registers in C -


I am using the 32-bit memory map register to manipulate and x86 based core. My hardware behaves correctly if the CPU reads 32-bit extensions and writes this register. Register is aligned to a 32-bit address and it is not eligible to be addressable on byte granularity.

What can I do to guarantee that my C (or C99) compiler only reads 32-bit extensions and writes in all cases?

For example, if I work with such a read-modify-write:

  volatile uint32_t * p_reg = 0xCAFE0000; * P_reg | = 0x01;  

I do not want the compiler to be clever about this fact that only bytes down and generates 8-bit detailed read / write. Since the machine code is often more dense for 8-bit operations on x86, I am afraid of unwanted optimization. Disabling optimization in general is not an option.

----- Edit -------
An interesting and very relevant paper:

Your concerns are covered by the variable qualifier.

6.7.3 / 6 "type qualifiers say":

An object that can be modified by unknown ways to implement the type of volatile qualification or Other unknown side effects can occur. Therefore, any expression referring to such a thing will be strictly assessed according to the rules of the abstract machine described in 5.1.2.3. In addition, at each sequence point, the final stored value in the object will agree according to the set by the intangible machine, except that it was modified by the previously unknown factors described. Whether the access to the object is formed, which is an unstable type, is implemented-defined.

5.1.2.3 "In addition to program execution" (among other things):

abstract machine, is used to evaluate all expressions as syntax Has been specified by

is an actual implementation need not evaluate part of an expression, if it can detect that there is no value and does not generate any necessary side effects (called any function or volatile object of Due to arrive).

But, 6.7.3 / 6 essentially says that the 'non-if' rule can not be used in the unstable type of expression - the actual abstract machine words Should be followed. Therefore, if the vaporative 32-bit type indicator is dereferenced, then the full 32-bit value should be read or written (depending on the operation).


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -