0

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 ?

nrz
  • 10,435
  • 4
  • 39
  • 71
  • yeah just move from register to variables. http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Example%20of%20asm%20with%20clobbered%20asm%20reg (i am assuming you're using gcc) – thang Jan 15 '13 at 12:40
  • No i use fasm assembly code . I make a format ELF format executable with use32 I take the with " _start: mov eax,0x01 cpuid... I use fprint just to show the regs. I need a fasm solution to parse the output. Maybe is strange for you , but I need learning assembly. – Cătălin George Feștilă Jan 16 '13 at 22:00
  • What have you tried? This should be broken up into subproblems, e.g. http://stackoverflow.com/questions/2114163/reading-a-register-value-into-a-c-variable – Ciro Santilli OurBigBook.com Aug 05 '15 at 07:55

2 Answers2

1

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);
}
Cong Wang
  • 2,001
  • 12
  • 13
0

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...

Benny
  • 4,095
  • 1
  • 26
  • 27