943,097 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 1389
  • Assembly RSS
Nov 23rd, 2009
0

More cpuid

Expand Post »
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.

  1. cpuid_t do_cpuid(void) {
  2. cpuid_t stcpuid;
  3.  
  4. /* Get vendor string: */ {
  5. unsigned a[3] = {0};
  6. int eax;
  7.  
  8. asm volatile(
  9. "cpuid\n\t"
  10. :"=a"(eax), "=b"(a[0]), "=d"(a[1]), "=c"(a[2])
  11. :"a"(CPUID_GET_VENDORSTRING)
  12. );
  13.  
  14. if (eax == 0) {
  15. fprintf(stderr, "cpuid not supported on this CPU.\n");
  16. exit(1);
  17. }
  18.  
  19. memmove(stcpuid.vstring, a, 12);
  20. strncpy(stcpuid.manufacturer, get_manufacturer(stcpuid.vstring), 24);
  21. }
  22. /* relevant */
  23. /* Get brandstring: */ {
  24. unsigned _bstr[12 + 1] = {0};
  25. char bstr[48 + 1] = {0};
  26.  
  27. asm(
  28. "cpuid\n\t"
  29. :"=a"(_bstr[0]), "=b"(_bstr[1]), "=c"(_bstr[2]), "=d"(_bstr[3])
  30. :"a"(0x80000002)
  31. );
  32.  
  33. asm(
  34. "cpuid\n\t"
  35. :"=a"(_bstr[4]), "=b"(_bstr[5]), "=c"(_bstr[6]), "=d"(_bstr[7])
  36. :"a"(0x80000003)
  37. );
  38.  
  39. asm(
  40. "cpuid\n\t"
  41. :"=a"(_bstr[8]), "=b"(_bstr[9]), "=c"(_bstr[10]), "=d"(_bstr[11])
  42. :"a"(0x80000004)
  43. );
  44.  
  45. /* I decided that the asm above was best to do in 3 seperate calls; it is
  46.   * clearer this way, I hope.
  47.   */
  48.  
  49. memmove(bstr, _bstr, 48 + 1);
  50.  
  51. #if 1 /* What I should be getting: Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz
  52. * What I am getting: ItlR oeT) ud P 80 @23Gz
  53. * As you can see there are some slight differences.
  54. */
  55. int n = 0;
  56. for (n = 0; n < 49; n++) {
  57. putchar(bstr[n]);
  58. ++n;
  59. }
  60.  
  61. putchar('\n');
  62.  
  63. #endif
  64. }
  65.  
  66. return stcpuid;
  67. }

Essentially my problem is that the code above gives me
Quote ...
ItlR oeT) ud P 80 @23Gz
instead of
Quote ...
Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz
Last edited by chrisname; Nov 23rd, 2009 at 5:22 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
chrisname is offline Offline
26 posts
since Oct 2009
Nov 23rd, 2009
0
Re: More cpuid
Looks like your problem is that the for loop is incrementing n , but you're also incrementing it at the end of the loop:

  1. for (n = 0; n < 49; n++) {
  2. putchar(bstr[n]);
  3. ++n;
  4. }

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

  1. for (n = 0; n < 49; n++) {
  2. putchar(bstr[n]);
  3. }
Reputation Points: 182
Solved Threads: 70
Posting Pro in Training
gusano79 is offline Offline
474 posts
since May 2004
Nov 24th, 2009
0
Re: More cpuid
Click to Expand / Collapse  Quote originally posted by gusano79 ...
Looks like your problem is that the for loop is incrementing n , but you're also incrementing it at the end of the loop:

  1. for (n = 0; n < 49; n++) {
  2. putchar(bstr[n]);
  3. ++n;
  4. }

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

  1. for (n = 0; n < 49; n++) {
  2. putchar(bstr[n]);
  3. }
Lol, I feel stupid now...
Reputation Points: 10
Solved Threads: 0
Light Poster
chrisname is offline Offline
26 posts
since Oct 2009
Nov 25th, 2009
0
Re: More cpuid
Nah, these things happen to all of us.
Reputation Points: 182
Solved Threads: 70
Posting Pro in Training
gusano79 is offline Offline
474 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Help me print '*' digit
Next Thread in Assembly Forum Timeline: strange 1 line problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC