I'm still doing some cpuid code; but now I want to get the brand string. I've sort of got about half of it... If you have a browser that supports it; search for "/* relevant */" to seek straight to the relevant part of the code

Important edit: if I strncpy() it into a data structure or itself, it works :l; so this is probably a problem with something else.

cpuid_t do_cpuid(void) {
    cpuid_t stcpuid;

    /* Get vendor string: */ {
        unsigned a[3] = {0};
        int eax;
     
        asm volatile(
            "cpuid\n\t"
            :"=a"(eax), "=b"(a[0]), "=d"(a[1]), "=c"(a[2])
            :"a"(CPUID_GET_VENDORSTRING)
        );
       
        if (eax == 0) {
            fprintf(stderr, "cpuid not supported on this CPU.\n");
            exit(1);
        }
        
            memmove(stcpuid.vstring, a, 12);
            strncpy(stcpuid.manufacturer, get_manufacturer(stcpuid.vstring), 24);    
    }
    /* relevant */
    /* Get brandstring: */ {
        unsigned _bstr[12 + 1] = {0};
        char bstr[48 + 1] = {0};
        
        asm(
            "cpuid\n\t"
            :"=a"(_bstr[0]), "=b"(_bstr[1]), "=c"(_bstr[2]), "=d"(_bstr[3])
            :"a"(0x80000002)
        );
        
        asm(
            "cpuid\n\t"
            :"=a"(_bstr[4]), "=b"(_bstr[5]), "=c"(_bstr[6]), "=d"(_bstr[7])
            :"a"(0x80000003)
        );
        
        asm(
            "cpuid\n\t"
            :"=a"(_bstr[8]), "=b"(_bstr[9]), "=c"(_bstr[10]), "=d"(_bstr[11])
            :"a"(0x80000004)
        );
    
        /* I decided that the asm above was best to do in 3 seperate calls; it is
         * clearer this way, I hope.
         */
 
        memmove(bstr, _bstr, 48 + 1);
        
#if 1   /* What I should be getting: Intel(R) Core(TM)2 Quad  CPU   Q8200  @ 2.33GHz
         * What I am getting:        ItlR oeT) ud P  80 @23Gz
         * As you can see there are some slight differences.
         */
        int n = 0;
        for (n = 0; n < 49; n++) {
            putchar(bstr[n]);
            ++n;
        }
    
        putchar('\n');
    
#endif
    }
        
    return stcpuid;
}

Essentially my problem is that the code above gives me

ItlR oeT) ud P 80 @23Gz

instead of

Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz

Looks like your problem is that the for loop is incrementing n , but you're also incrementing it at the end of the loop:

for (n = 0; n < 49; n++) {
  putchar(bstr[n]);
  ++n;
}

That'll print every other character in the string, which is what you appear to be getting. Try this instead:

for (n = 0; n < 49; n++) {
  putchar(bstr[n]);
}

Looks like your problem is that the for loop is incrementing n , but you're also incrementing it at the end of the loop:

for (n = 0; n < 49; n++) {
  putchar(bstr[n]);
  ++n;
}

That'll print every other character in the string, which is what you appear to be getting. Try this instead:

for (n = 0; n < 49; n++) {
  putchar(bstr[n]);
}

Lol, I feel stupid now...

Nah, these things happen to all of us.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.