Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: SPARC assembly, How a C pointer to struct is accessed

Andak:

Goodmorning, I have a small piece of SPARC assembly code that I'm trying to understand.


.section ".text"
.global tt_0x09
tt_0x09:
/* Find AHBSTAT */
set ahbstat, %l3
ld [%l3], %l3
/* Get failing address from AHBSTAT faddr. */
ld [%l3 + 4], %l4

set 0xDEADBEEF, %l5
st %l5, [%l4]

/*st %g0, [%l3]*/
/* Re-execute trapped instruction. */
jmp %l1
rett %l2

where ahbstat is defined in a C file


#define AHBSTAT_REGS 0x80000f00
struct ahbstat_regs { unsigned int status, faddr; };
...
volatile struct ahbstat_regs *ahbstat = (void *) AHBSTAT_REGS;

For the sake of completeness, the assembly snippet I showed above is the code of a trap which is mapped using a particular library function:

extern void tt_0x09(void); static const int TT_DATA_ACCESS_EXCEPTION = 0x09; ... bcc_set_trap(TT_DATA_ACCESS_EXCEPTION, tt_0x09);

The point which I do not understand is how the Struct is accessed in the assembly code. In fact, if l3contains the address of the struct, then using ld [%l3], %l3 I'm loading a word from the memory to l3 it self, So I'm copy the value of the unsigned int status of the struct into l3.

Another problem is in the consecutive lines: It set l5 to 0xDEADBEEF and then store l5 in the memory location pointed to l4. But l4 has been loaded with the value at memory location [%l3+4] which is a non-sense as far i understand because l3 contains the value of unsigned int status of the struct.

I'm wrong somewhere, but I think I'm clear with the load instruction: ld [addr], rd -> Load a word from addr into rd.

So I do not think it's clear to me how a C struct pointer is "translated" in assembly.

Thanks in advance for your help, excuse me if something I wrote is not clear.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: SPARC assembly, How a C pointer to struct is accessed

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×