delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2007/10/25/05:25:19

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Recipient: djgpp AT delorie DOT com
From: "Gerrit van Niekerk" <gerritvn AT gpvno DOT co DOT za>
Organization: GPvNO
To: djgpp AT delorie DOT com
Date: Thu, 25 Oct 2007 11:24:48 +0200
MIME-Version: 1.0
Subject: Re: Using inline asm
Message-ID: <47207D00.5963.31E6A13C@gerritvn.gpvno.co.za>
In-reply-to: <ffpkhp$p9o$1@aioe.org>
References: <471FEAC8 DOT 5179 DOT 2FAB88DB AT gerritvn DOT gpvno DOT co DOT za>, <ffpkhp$p9o$1 AT aioe DOT org>
X-mailer: Pegasus Mail for Windows (4.41)
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> >    asm ("cpuid" : "=a" (iRet) : : "ebx", "ecx", "edx");
> Thanks.  Okay, it doesn't, so correct the code...  I wasn't sure if the asm
> directive inserted a pusha; popa combination into the stackframe, say
> instead of push ebp; pop ebp, or used some other method.  That might mess up
> returns...

Thanks DJ and RP - you put me on the right track.
My example was just a simplified version to show my main problem. For other people who 
battle with the same problem, here is my full code. The stack frame and saving of registers 
are taken care of by GCC - I checked with GDB and the code runs without crashing :)

int IsSc410Processor (void)
{
   int iRet;
   asm ( "xorl %%eax,%%eax\n\t"
         "cpuid\n\t"
         "cmpl $1,%%eax\n\t"
         "jnz NotMine\n\t"
         "cmpw $0x7541,%%bx\n\t"    // Check low order string portions
         "jnz NotSc410\n\t"
         "cmpw $0x4163,%%cx\n\t"
         "jnz NotSc410\n\t"
         "cmpw $0x6e65,%%dx\n\t"
         "jnz NotSc410\n\t"
         "cpuid\n\t"
         "orw %%cx,%%bx\n\t"
         "orw %%bx,%%dx\n\t"
         "jnz NotSc410\n\t"       // Jump if FPU or other feature present
         "movw %%ax,%%bx\n\t"
         "andw $0x0f,%%bx\n\t"
         "xorw %%bx,%%ax\n\t"
         "cmpw $4,%%bx\n\t"      // Check for stepping 4 or greater
         "jb NotSc410\n\t"
         "cmpw $0x4a0,%%ax\n\t"  // Check features
         "jnz NotSc410\n\t"
         "movl $1,%%eax\n\t"
         "jmp ok\n\t"
         "NotSc410: xorl %%eax,%%eax\n\t"
         "ok:\n\t" : "=a" (iRet) :: "ebx","ecx","edx");
   return iRet;
}
-- 
Gerrit van Niekerk
GP van Niekerk Ondernemings BK
Roosstraat 211, Meyerspark, 0184, South Africa
Tel: +27(12)8036501 Fax SA: 0866 413 555
Cell: +27(73)6891370
Fax Int'l: +1(206)2034139
Email: gerritvn AT gpvno DOT co DOT za
Web: http://www.gpvno.co.za



- Raw text -


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