GCC内联汇编笔记

#ifdef __ASSEMBLER__
#define C0_SR $12
#else
#define C0_SR 12
#endif

Reg.h

#define save_static(frame) \
__asm__ __volatile__( \
“sw\t$16,”__str(PT_R16)”(%0)\n\t” \
“sw\t$17,”__str(PT_R17)”(%0)\n\t” \
“sw\t$18,”__str(PT_R18)”(%0)\n\t” \
“sw\t$19,”__str(PT_R19)”(%0)\n\t” \
“sw\t$20,”__str(PT_R20)”(%0)\n\t” \
“sw\t$21,”__str(PT_R21)”(%0)\n\t” \
“sw\t$22,”__str(PT_R22)”(%0)\n\t” \
“sw\t$23,”__str(PT_R23)”(%0)\n\t” \
“sw\t$30,”__str(PT_R30)”(%0)\n\t” \
: /* No outputs */ \
: “r” (frame))

R4kc0.h

#define _mips_mfc0(reg) \
({ \
register reg32_t __r; \
__asm__ __volatile (“%(mfc0 %0,$%1; nop; nop%)” \
: “=d” (__r) \
: “JK” (reg)); \
__r; \
})

#define _mips_mtc0(reg, val) \
({ \
__asm__ __volatile (“%(mtc0 %z0,$%1; nop; nop; nop%)” \
: \
: “dJ” ((reg32_t)(val)), “JK” (reg) \
: “memory”); \
})

6.2 Constraint Modifiers

“=” : Means that this operand is write-only for this instruction; the previous value is discarded and replaced by output data.
“&” : Means that this operand is an earlyclobber operand, which is modified before the instruction is finished using the input operands. Therefore, this operand may not lie in a register that is used as an input operand or as part of any memory address. An input operand can be tied to an earlyclobber operand if its only use as an input occurs before the early result is written.

—————————————————————
http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#ss5.1
及Kernel Source摘录


相关文章

Speak Your Mind

If you want a pic to show with your comment, go get a gravatar!