www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/15/14:01:50

Message-ID: <38F8B55B.5BFDA8E0@home.com>
From: Robin Johnson <robbat2 AT home DOT com>
Organization: Orbit Computers
X-Mailer: Mozilla 4.7 [en] (Win98; U)
X-Accept-Language: en,af,es
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: CPUID Opcode
X-Priority: 1 (Highest)
Lines: 67
Date: Sat, 15 Apr 2000 18:30:42 GMT
NNTP-Posting-Host: 24.113.36.103
X-Complaints-To: abuse AT home DOT net
X-Trace: news1.rdc1.bc.home.com 955823442 24.113.36.103 (Sat, 15 Apr 2000 11:30:42 PDT)
NNTP-Posting-Date: Sat, 15 Apr 2000 11:30:42 PDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Whenever I call the CPUID Opcode in the inline asm, my program seems to fail.

source:
#include <stdio.h>
#include <iostream.h>
#include <string.h>

typedef long longreg;
typedef char chars[4];

void get_cpuid(const long int cpuidval, longreg &r_eax, longreg &r_ebx, longreg
&r_ecx, longreg &r_edx)
{ __asm__ __volatile__
  (	" pushl %%eax\n pushl %%ebx\n pushl %%ecx\n pushl %%edx\n
          movl %4, %%eax	\n
          cpuid      \n
	  movl %%eax, %0	\n
  	  movl %%ebx, %1	\n
  	  movl %%ecx, %2	\n
  	  movl %%edx, %3	\n
          popl %%edx\n popl %%ecx\n popl %%ebx\n popl %%eax"
   :	"=g" (r_eax), "=g" (r_ebx), "=g" (r_ecx), "=g" (r_edx)
   : "g" (cpuidval)
   : "ax", "bx", "cx", "dx", "memory"
   );
 }

void main()
{ long int a,b,c,d;
  char nb[4],nc[4],nd[4];
  printf("cpuid\n");
  get_cpuid(0,a,b,c,d);
  memcpy(nb,b,4);
  memcpy(nc,c,4);
  memcpy(nd,d,4);
  printf("Max EAX: %i\nName: %s%s%s\n",a,nb,nc,nd);
 }


stderr dump:
G:\prog\cpudetect>cpuid
cpuid
Exiting due to signal SIGSEGV
General Protection Fault at eip=000015c8
eax=00000001 ebx=756e6547 ecx=6c65746e edx=49656e69 esi=0008eec4 edi=0008eec0
ebp=0008ee98 esp=0008ee6c program=G:\PROG\CPUDET~1\CPUID.EXE
cs: sel=00a7  base=86008000  limit=0009ffff
ds: sel=00af  base=86008000  limit=0009ffff
es: sel=00af  base=86008000  limit=0009ffff
fs: sel=0087  base=00011220  limit=0000ffff
gs: sel=00bf  base=00000000  limit=0010ffff
ss: sel=00af  base=86008000  limit=0009ffff
App stack: [0008eef0..0000eef0]  Exceptn stack: [0000edd8..0000ce98]

Call frame traceback EIPs:
  0x000015c8
  0x00001626
  0x0000263a

-- 
Robin Hugh Johnson
"Robbat2"
QTOD: "I used to be an idealist, but I got mugged by reality."
E-Mail     : robbat2 AT tesla DOT t-p-l DOT com
ICQ#       : 30269588 or 41961639
Home Page  : http://robbat2.t-p-l.com
Time Zone  : Pacific Daylight (GMT - 8)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019