Okie, I think I see the problem. Since I use pushfl and popfl which modify the esp, there is a problem when the inline asm returns to C code. GCC has no way of knowing that the esp has been modified, so any accesses it does based on esp would be wrong. Even though I specify that esp has been modified, I don't think GCC takes that into account. Is there any way I can tell GCC that I have modified the esp by a certain value? Thanks, Yamin Quoting y2bismil@xxxxxxxxxxxxxxxxxxxx: > > > Hi all, > > Okay, this is the issue. I've isolated it way down to some very basic > functionality, and made a reasonable test bed. I'll post the code below. > > When MYINLINE = 1, then the program executes correctly. When MYINLINE is 0, > then it stops with a single step exception. I was stepping through the code > and > from my understanding there is something definitely wrong when a function > call > is made instead of the inline code. Bare in mind, my understaind could be > what > is wrong :) > > >From my understand this is what happens. > > pushf - pushes the eflags onto the stack, decrements esp > mymemcpy - simple memcpy > popf - pops the eflags from the stack into the eflgs register, increments > esp > > This is basically the program below. When the inlining is not used, for > some > reason, the stack gets corrupted. When the variables to be passed into > memcpy > are done, they overwrite the location where the eflags register was stored > (from > the pushf). This then causes some things to mess up. When inlining is used. > > this nicely does not happen. > > I always hesitate to say bug as its probably something i'm not specifying or > some misunderstanding. > Any ideas? > > Yamin > > > ***************************************************** > main.cpp > ***************************************************** > #include <io.h> > #include <stdio.h> > > #if 0 > #include "chead.h" > #else > #define KS_DISABLE() \ > __asm__ __volatile__ ( \ > "pushfl;" \ > : \ > : \ > : "memory", "%esp"); > > #define KS_ENABLE() \ > __asm__ __volatile__ ( \ > "popfl;" \ > : \ > : \ > : "memory", "%esp"); > > char * mymemcpy(void *dv, void *sv, int num) > { > char * d = (char*)dv; > char * s = (char*)sv; > int i; > > for( i = 0; i < num; i++) *d++ = *s++; > > } > > > #endif > > > > #define MYINLINE 1 > int main() > { > #if MYINLINE > char *d; > char *s; > int i; > #endif > char mysrc[] = "HELLO YAMIN\r\n"; > char mydst[32]; > printf ("starting popf test\r\n"); > KS_DISABLE(); > #if MYINLINE > d = (char*) mydst; > s = (char*) mysrc; > for( i = 0; i < sizeof(mysrc); i++) *d++ = *s++; > #else > mymemcpy( mydst, mysrc, sizeof(mysrc) ); > #endif > KS_ENABLE(); > printf ("ending popf test: %s\r\n", mydst); > } > ***************************************************** > > ---------------------------------------- > This mail sent through www.mywaterloo.ca > ---------------------------------------- This mail sent through www.mywaterloo.ca