Mail Archives: djgpp/1998/10/14/00:35:29
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 -