문제

I make a fasm program with cpuid and the output is:

EAX -> 0x00000662
EBX -> 0x00000000
ECX -> 0x00000000
EDX -> 0x0383FBFF

I use fprint from /lib/ld-linux.so.2 to show this output.

So I need to read all flags from EAX,... regs with some function to see all specifications.

This mean to read the bits from registers or to make one structure of cpuid output.

Can you give me one solution to do that ?

도움이 되었습니까?

해결책

Although not fasm, please take a look at how Linux kernel uses it (GNU asm):

static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
                                unsigned int *ecx, unsigned int *edx)
{
        /* ecx is often an input as well as an output. */
        asm volatile("cpuid"
            : "=a" (*eax),
              "=b" (*ebx),
              "=c" (*ecx),
              "=d" (*edx)
            : "0" (*eax), "2" (*ecx)
            : "memory");
}


/* Some CPUID calls want 'count' to be placed in ecx */
static inline void cpuid_count(unsigned int op, int count,
                               unsigned int *eax, unsigned int *ebx,
                               unsigned int *ecx, unsigned int *edx)
{
        *eax = op;
        *ecx = count;
        __cpuid(eax, ebx, ecx, edx);
}

Finally read all the registers into a struct:

struct cpuid_regs {
        u32 eax, ebx, ecx, edx;
};

static void cpuid_smp_cpuid(void *cmd_block)
{
        struct cpuid_regs *cmd = (struct cpuid_regs *)cmd_block;

        cpuid_count(cmd->eax, cmd->ecx,
                    &cmd->eax, &cmd->ebx, &cmd->ecx, &cmd->edx);
}

다른 팁

From my very old kernel project, and with GCC assembly inline:

#define CPUID(VALUE, EAX, EBX, ECX, EDX)                            \
  __asm__ __volatile__ ("   cpuid                   \n\t"           \
                    "       movl    %%eax, %0       \n\t"           \
                    "       movl    %%ebx, %1       \n\t"           \
                    "       movl    %%ecx, %2       \n\t"           \
                    "       movl    %%edx, %3"                      \
                    : "=m" (*EAX), "=m" (*EBX), "=m" (*ECX), "=m" (*EDX) \
                    : "a" (VALUE)                                   \
                    : "%ebx", "%ecx", "%edx"                        \
                    );

By the way, I am not sure that what you're looking for...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top