人生如逆旅,我亦是行人!江湖人称wsjjeremy.blog.chinaunix.net
ubuntuer
全部博文(930)
intern(3)
string(19)
正则表达式(5)
2011年(60)
2010年(220)
2009年(371)
2008年(279)
baocheng
nba76ers
renjian2
qq576709
mcn304
zibuyule
西农魔峰
曾德标
zhuqing_
shanck
tendy
moshangx
wb123456
smile124
hjshajsh
chenhong
bzhao
python16
分类: LINUX
2009-09-15 14:52:25
#include <stdio.h> typedef struct { unsigned int eax; unsigned int edx; unsigned int ecx;} cpusn_t; int get_cpusn(cpusn_t *sn){ sn->eax = 1; __asm__ ( "cpuid\n\t" :"=c"(sn->ecx), "=d"(sn->edx), "=a" (sn->eax) :"2" (sn->eax) ); if ((sn->edx & (1<<17)) == 0) return 1; sn->eax = 3; __asm__ ( "cpuid\n\t" :"=c"(sn->ecx), "=d"(sn->edx), "=a" (sn->eax) :"2" (sn->eax) ); return 0;}void print_cpusn(cpusn_t sn){ char buf[30]; snprintf(buf, sizeof(buf), "%04X-%04X-%04X-%04X-%04X-%04X", sn.eax>> 16, sn.eax & 0xffff, sn.edx>> 16, sn.edx & 0xffff, sn.ecx>> 16, sn.ecx & 0xffff); printf("%s\n", buf); } int main(void){ cpusn_t sn = {0, 0, 0}; if (get_cpusn(&sn) == 0) { print_cpusn(sn); } else { //printf("edx = %x\n", sn.edx); printf("Doesn't support this.\n"); } return 0;}
上一篇:SYN Cookie原理及其在Linux内核中的实现
下一篇:Linux内核使用的GNU C扩展
登录 注册