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摘录

gcc and stdarg.h

高版本的gcc,如3.4.3,将stdarg.h头文件独立出来放在针对特定编译器的include文件夹中。比如/usr/lib/gcc/i386-redhat-linux/3.4.3/include

这个路径应该在gcc configure时自动指定的。
可以通过这个命令查看gcc –print-file-name=include

程序中#include ,编译时用-E进行预处理,应该可以看到gcc使用了# 1 “”。否则也可通过-I`gcc –print-file-name=include`显式制定包含路径

Page 1 of 11