reading macro

R

roaher

hi

I have some trouble reading this macro:

#define SMC_inl(r) (*((volatile dword *)(SMC_BASE_ADDRESS+(r))))

also consider that SMC_BASE_ADDRESS is address base of I/O mapped
peripherial registers, r is register offset.
Does that read: return 32bits of data stored in memory location
SMC_BASE_ADDRESS+r.

with this "(volatile dword *)" we are casting pointer to point to 32bit
wide address and first * means get the value stored at that address.

Am i reading this right ?

regards, himba
 
M

Malcolm

roaher said:
I have some trouble reading this macro:

#define SMC_inl(r) (*((volatile dword *) (SMC_BASE_ADDRESS+(r))))

does that read: return 32bits of data stored in memory location
SMC_BASE_ADDRESS+r.
Presumably SMC_BASE_ADDRESS is defined as a constant. You will add r to that
address, and then cast the result to a dword *.
You then read the dword (probably 32 bits) from that address.
with this "(volatile dword *)" we are casting pointer to point to 32bit
wide address and first * means get the value stored at that address.
Yes. It is rather confusing that in C * is used both to declare a pointer.

char *ptr; /* ptr is variable of type char pointer */

and as the indirection operator

*ptr = 'X'; /* write the character 'X' to location pointer to by ptr */

The "volatile" just means that the variable will never be held temporarily
in a register, which makes sense for memory mapped io.
 
J

Jan Engelhardt

Yes. It is rather confusing that in C * is used both to declare a pointer.
char *ptr; /* ptr is variable of type char pointer */

and as the indirection operator

*ptr = 'X'; /* write the character 'X' to location pointer to by ptr */

As long as the people implementing the compiler got it to work as they wanted,
there is nothing against it.
(/* */ Exception holds)
 
B

Barry Schwarz

hi

I have some trouble reading this macro:

#define SMC_inl(r) (*((volatile dword *)(SMC_BASE_ADDRESS+(r))))

also consider that SMC_BASE_ADDRESS is address base of I/O mapped
peripherial registers, r is register offset.
Does that read: return 32bits of data stored in memory location
SMC_BASE_ADDRESS+r.

with this "(volatile dword *)" we are casting pointer to point to 32bit
wide address and first * means get the value stored at that address.

Am i reading this right ?

regards, himba

It depends on the definition of SMC_BASE_ADDRESS.

If it is a numeric constant or variable, then the value of the
expression (r) added to the value of SMC_BASE_ADDRESS using normal
arithmetic, the resulting value is treated as the address of a dword
(which is not a standard type), and the value of the dword at that
address is the result of the expression. If the address is not
properly aligned for a dword, it invokes undefined behavior.

If it is a pointer expression, then the value of the expression
(r) is added to the value of SMC_BASE_ADDRESS using pointer arithmetic
(where +1 means the number of bytes in one object of the type the
pointer points to), the resulting value is treated the same as above.

For what it's worth, the second '(' and the next to last ')' are
superfluous.


<<Remove the del for email>>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top