我想执行asm代码行的循环。 其实我正在尝试读取我的核心的CPUID,需要读取CPUID的所有参数。 如果我将0写入eax寄存器,那么我将获得制造商名称,如果我将1写入eax,则将收到下一组CPUID信息。等等... 现在我想执行最多15组asm指令以获得完整的CPUID输出。
例: unsigned int cpuid_reg [4];
__asm__ volatile("mov $1, %eax");
__asm__ volatile("cpuid" : "=a" (cpuid_reg[0]), "=b" (cpuid_reg[1]), "=c" (cpuid_reg[2]), "=d" (cpuid_reg[3]));
printf("reg[0] 0x%x , cpuid_reg[1] 0x%x, cpuid_reg[2] 0x%x, cpuid_reg[3] 0x%x\n", cpuid_reg[0], cpuid_reg[1], cpuid_reg[2], cpuid_reg[3]);
__asm__ volatile("mov $2, %eax");
__asm__ volatile("cpuid" : "=a" (cpuid_reg[0]), "=b" (cpuid_reg[1]), "=c" (cpuid_reg[2]), "=d" (cpuid_reg[3]));
printf("cpuid_reg[0] 0x%x , cpuid_reg[1] 0x%x, cpuid_reg[2] 0x%x, cpuid_reg[3] 0x%x\n", cpuid_reg[0], cpuid_reg[1], cpuid_reg[2], cpuid_reg[3]);
代替这两组代码,我需要一组我可以将0到15写入'eax'寄存器以获取完整的CPUID数据。 谢谢你的帮助。
答案 0 :(得分:1)
static inline void cpuid(int code, uint32_t *a, uint32_t *d) {
asm volatile("cpuid":"=a"(*a),"=d"(*d):"a"(code):"ecx","ebx");
}
/** issue a complete request, storing general registers output as a string
*/
static inline int cpuid_string(int code, uint32_t where[4]) {
asm volatile("cpuid":"=a"(*where),"=b"(*(where+1)),
"=c"(*(where+2)),"=d"(*(where+3)):"a"(code));
return (int)where[0];
}