delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/14/00:35:29

Sender: nate AT cartsys DOT com
Message-ID: <362426CB.111F69C6@cartsys.com>
Date: Tue, 13 Oct 1998 21:21:31 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.05 [en] (X11; I; Linux 2.0.35 i486)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: -O3 breaks my code: inline assembler & optimization
References: <36237ef5 DOT 671209 AT crispin>
Reply-To: djgpp AT delorie DOT com

Ignacio Garcma Pirez wrote:
> 
> Hi,
> 
> I posted recently a help request about -O3 optimization (more
> precisely -finline-functions) breaking my code.
> 
> I've traced down the problem to the following function:
> 
> //------------------------------
> volatile dword Com::TimTicks=0;
> 
> dword Com::Ticks(void) {
>         dword TRef T;
>         asm ("pushf");
>         asm ("cli");
>         T=TimTicks;
>         asm ("popf");
>         return T;
>         }
> //------------------------------
> 
> As you see, TimTicks is a volatile variable that is updated by a timer
> interrupt function. The reason because of which the read of the
> variable is enclosed between interrupt disable/enable is because
> originally this code was 16 bit and then a DWORD read is split in
> several instructions, which could potentially be interrupted in
> between by a timer tick.
> 
> I KNOW that with DJGPP this is a single instruction and then
> enabling/disabling is not needed. But what I want to discover is why
> GCC is producing a code that produces a general protection fault when
> this function is inlined.

I expect it's due to the stack being in an unexpected state between the
push/pop pair.  Try using the functions `enable' and `disable'.  You
might also look at the assembly (compile with `-S') and see if anything
suspicious is going on.
-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


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