C中引用汇编格式如下:
asm( code-string [ : output-list [ : input-list [ : overwrite-list ] ] ] );
#define __get_user_asm(x, addr, err, itype, rtype, ltype, errno) \
__asm__ __volatile__( \
"1: mov"itype" %2,%"rtype"1\n" \
"2:\n" \
".section .fixup,\"ax\"\n" \
"3: mov %3,%0\n" \
" xor"itype" %"rtype"1,%"rtype"1\n" \
" jmp 2b\n" \
".previous\n" \
".section __ex_table,\"a\"\n" \
" .align 8\n" \
" .quad 1b,3b\n" \
".previous" \
: "=r"(err), ltype (x) \
: "m"(__m(addr)), "i"(errno), "0"(err))
其中最后两行分别是output-list和input-list,第一行是把addr移到x中去。
"=r"(err)表示输出为整数。
"m"(__m(addr))应该表示引用内存,但是内存地址还是内存中的内容?还需进一步核实。
调用函数中根据size不同指明了ltype的具体类型,
switch (size) {
case 1:__get_user_asm(*(u8*)dst,(u8 *)src,ret,"b","b","=q",1);
return ret;
case 2:__get_user_asm(*(u16*)dst,(u16*)src,ret,"w","w","=r",2);
return ret;
case 4:__get_user_asm(*(u32*)dst,(u32*)src,ret,"l","k","=r",4);
return ret;
case 8:__get_user_asm(*(u64*)dst,(u64*)src,ret,"q","","=r",8);
return ret;
阅读(969) | 评论(0) | 转发(0) |