From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e0fd0b6258908ca5,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.219.170 with SMTP id pp10mr19998693pbc.1.1341806083700; Sun, 08 Jul 2012 20:54:43 -0700 (PDT) Path: l9ni11215pbj.0!nntp.google.com!news1.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: "Jim C." Newsgroups: comp.lang.ada Subject: Help with Inline assembly Date: Sun, 8 Jul 2012 20:53:05 -0700 (PDT) Organization: http://groups.google.com Message-ID: <85b57cc7-352e-4cee-a161-b0aaf1665305@googlegroups.com> NNTP-Posting-Host: 76.20.243.45 Mime-Version: 1.0 X-Trace: posting.google.com 1341806083 9789 127.0.0.1 (9 Jul 2012 03:54:43 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 9 Jul 2012 03:54:43 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=76.20.243.45; posting-account=JqutYwoAAAC8IGXNQJ34VIRLaJ4LKhwz User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-07-08T20:53:05-07:00 List-Id: I am running into problems translating Intel style visual C inline assembly= to something gnat can understand (http://gcc.gnu.org/onlinedocs/gnat_ugn_u= nw/Inline-Assembler.html#Inline-Assembler). The goal of the program is to t= est for the existence of the CPUID command which only exists after the 386. The program as it stands compiles without any errors, but it will fail at r= untime with the following printed: "raised PROGRAM_ERROR : EXCEPTION_ACCESS= _VIOLATION" -- I can't tell if I am violating syntax or something more comp= licated is involved. ///////////////////////////////////// Visual C code static bool HasCPUID( void ) { __asm=20 { pushfd // save eflags pop eax test eax, 0x00200000 // check ID bit jz set21 // bit 21 is not set, so jump to set_21 and eax, 0xffdfffff // clear bit 21 push eax // save new value in register popfd // store new value in flags pushfd pop eax test eax, 0x00200000 // check ID bit jz good jmp err // cpuid not supported set21: or eax, 0x00200000 // set ID bit push eax // store new value popfd // store new value in EFLAGS pushfd pop eax test eax, 0x00200000 // if bit 21 is on jnz good jmp err } err: return false; good: return true; } --------------------------------------- Ada code with Ada.Text_IO, Interfaces, System.Machine_Code; use Ada.Text_IO, Interfaces, System.Machine_Code; procedure Assembly_Test is C : Character :=3D Ascii.Nul; Result : Unsigned_32 :=3D 0; begin Asm( ------------------------------------------------------- " pushf " & Ascii.LF & Ascii.HT & " pop %%eax " & Ascii.LF & Ascii.HT &=20 " test %%eax, 0x00200000 " & Ascii.LF & Ascii.HT & " jz set21 " & Ascii.LF & Ascii.HT & " and %%eax, 0xffdfffff " & Ascii.LF & Ascii.HT & " push %%eax " & Ascii.LF & Ascii.HT & " popf " & Ascii.LF & Ascii.HT & " pushf " & Ascii.LF & Ascii.HT &=20 " pop %%eax " & Ascii.LF & Ascii.HT &=20 " test %%eax, 0x00200000 " & Ascii.LF & Ascii.HT & " jz good " & Ascii.LF & Ascii.HT &=20 " jmp err " & Ascii.LF & Ascii.HT & ------------------------------------------------------- " set21: " & Ascii.LF & Ascii.HT &=20 " or %%eax, 0x00200000 " & Ascii.LF & Ascii.HT & " push %%eax " & Ascii.LF & Ascii.HT & " popf " & Ascii.LF & Ascii.HT & " pushf " & Ascii.LF & Ascii.HT &=20 " pop %%eax " & Ascii.LF & Ascii.HT &=20 " test %%eax, 0x00200000 " & Ascii.LF & Ascii.HT & " jnz good " & Ascii.LF & Ascii.HT &=20 " jmp err " & Ascii.LF & Ascii.HT & =20 ------------------------------------------------------- " err: " & Ascii.LF & Ascii.HT &=20 " mov 0x0, %%eax " & Ascii.LF & Ascii.HT &=20 ------------------------------------------------------- " good: " & Ascii.LF & Ascii.HT &=20 " mov 0x1, %%eax " & Ascii.LF & Ascii.HT ,=20 ------------------------------------------------------- Outputs =3D> Unsigned_32'Asm_Output("=3Da", Result), Volatile =3D> True); if Result /=3D 1 then Put_Line("False"); end if; Put_Line("True"); Get(C); end Assembly_Test;