#
include
int main(
)//fixme: 打出來的字串是:in^htel(r) pentium(r^h) d cpu 2.80ghz
//其中^h是個不可見字元,會把它前乙個吃掉
printf
("/n");
}/**
* eax == 0
* eax : cpuid指令允許的最大eax輸入值
* ebx : "genu"
* ecx : "ntel"
* edx : "inel"
*/asm
volatile
("cpuid"
:"=a"
(eax)
,"=b"
(ebx)
,"=c"
(ecx)
,"=d"
(edx)
:"0"
(0))
;printf
("maximum cpuid input eax : %p/n"
, eax)
;char
string
[128]
;snprintf(
string
, 5,
"%s",(
char*)
&ebx)
;snprintf(
string
+ 4, 5,
"%s",(
char*)
&edx)
;snprintf(
string
+ 8, 5,
"%s",(
char*)
&ecx)
;printf
("vendor/t/t: %s/n"
,string);
printf
("/n");
/*** eax == 1,
* edx的第18位元為1,則cpu支援serial number
* 為0,則不支援,或者被disabled
* 序列號有96位,其中最高32位即是eax的輸出值。應當把它儲存下來,然後
* 再設定eax==3, 取剩下的64位
*/asm
volatile
("cpuid"
:"=a"
(eax)
,"=d"
(edx)
:"a"
(1));if
( edx &
(1 <
< 18)
)else
printf
("serial number not supported./n");
printf
("/n");
asmvolatile
("cpuid"
:"=c"
(ecx)
:"a"
(0x80000006));
printf
("l2 cache size/t : %dkbytes/n"
,( ecx >
> 16 ));
printf
("l2 cache line size/t : %dbytes/n"
,(ecx & 0xff));
printf
("l2 cache associativity/t : ");
switch
((ecx & 0xf000)
>
> 12 )
printf
("/n");
/*** input : eax == 4 && ecx == 0
** (eax[31:26] + 1) 是該物理處理器package上實現的core cpus數目
*/asm
volatile
("cpuid"
:"=a"
(eax)
,"=b"
(ebx)
,"=c"
(ecx)
,"=d"
(edx)
:"0"
(4),
"2"(0));
printf
("number of cores on this physical package/t : %d/n"
,(eax >
> 27)
+ 1 )
;printf
("/n");
/*** input : eax == 1,則edx返回feature flag**/
return 0;
}
Linux下獲取CPUID 硬碟序列
linux下獲取cpuid 硬碟序列號與mac位址 woonjoon 按照網上提供的說明,cpuid並不是所有的intel cpu都支援的。如果支援,彙編呼叫為 eax置0000 0003,呼叫cpuid。以下為實現 在我的cpu上,並沒有得到 define cpuid in,a,b,c,d asm...
Linux下獲取CPUID 硬碟序列號
在很多系統軟體的開發中,需要使用一些系統的唯一性資訊。所以,得到主機的cpuid 硬碟序列號及網絡卡的mac位址,就成個一件很重要的應用。需要的準備知識有 1.gcc的嵌入彙編,具體的gcc嵌入彙編知識,請參考相關手冊 2.ioctl系統呼叫,具體的呼叫方法,請檢視手冊頁 按照網上提供的說明,cpu...
Linux系統下的chattr指令詳解用法
chattr 主要一般是用來修改檔案的隱藏許可權 語法 chattr rv option file i 如果對檔案設定 i 屬性,那麼不允許對檔案進行刪除 改名,也不能新增和修改資料 如果對目錄設定 i 屬性,那麼只能修改目錄下檔案中的資料,但不允許建立和刪除檔案 a 如果對檔案設定 a 屬性,那麼...