hk_043
hk_043

Reputation: 15

Can someone explain the following code statement?

Can someone explain the below statement?

static inline void cpu_write_dtlb(uint32_t vpn, unsigned attr)
{
    asm volatile ("wdtlb  %1, %0; dsync\n" :: "r" (vpn), "r" (attr));
}

Upvotes: 0

Views: 76

Answers (1)

Jens
Jens

Reputation: 72619

If your question is about the syntax, that's GCC inline assembly language syntax. In particular, the %0 and %1 are replaced with registers where GCC stored the "r" arguments.

The volatile keyword has this effect:

GCC’s optimizers sometimes discard asm statements if they determine there is no need for the output variables. Also, the optimizers may move code out of loops if they believe that the code will always return the same result (i.e. none of its input values change between calls). Using the volatile qualifier disables these optimizations. asm statements that have no output operands, including asm goto statements, are implicitly volatile.

For details on this extended syntax, see the GCC docs for Extended Asm - Assembler Instructions with C Expression Operands.

Upvotes: 2

Related Questions