How do you detect the CPU architecture type during run-time with GCC and inline asm?

后端 未结 1 1312
野趣味
野趣味 2020-12-20 04:34

I need to find the architecture type of a CPU. I do not have access to /proc/cpuinfo, as the machine is running syslinux. I know there is a way to do it with inline ASM, how

相关标签:
1条回答
  • 2020-12-20 05:09

    How many bugs can you fit in so few lines ;)

    Try

    static int is64bit(void) {
            int iedx = 0;
            asm volatile ("movl $0x80000001, %%eax\n"
                    "cpuid\n"
            : "=d"(iedx)
            : /* No Inputs */
            : "eax", "ebx", "ecx"
            );
    
            if(iedx & (1 << 29))
            {
                    return 1;
            }
            return 0;
    }
    
    0 讨论(0)
提交回复
热议问题