Date: Fri, 23 Sep 94 18:37:19 -0600 From: "Clifford T. Matthews" To: djgpp AT sun DOT soe DOT clarkson DOT edu Subject: pascal calling conventions Hi Folks, Over here we've had to deal with pascal calling conventions for the few years that we've had Macintosh emulator running in house. Our first solution was indeed to modify the compiler to support a pascal keyword. Since Michael Bushnell was working for us, and he's a monster programmer, he did the work in two weeks and his solution worked exceedingly well. However, since the FSF wasn't interested in incorporating our changes, we didn't update our gcc as often as we'd like, because it always seemed to make more sense to wait for a new release or two before we'd roll in our mods, shake out any existing bugs and get on with our work. Eventually we decided to scrap the mods in favor of something more maintainable. What we went was a couple of routines: PascalToCCall and CToPascalCall, which take an additional argument that specifies what arguments are passed in and the size of the return value, if any. We then have some routines that automatically figure out the magic numbers for all the routines that we need to be able to access both as pascal and as C routines and because we have to have pascal routine addresses, we also have some code that generates some PascalToCCalls with the correct flags pushed on, so we can then hand the addresses of these new glue routines to functions that expect pascal function pointers. Now we can use whatever the latest bug-free version of GCC is that we can get our hands on, and we're in total control of the calling conventions, which is important, because in addition to the pascal/C calling conventions mentioned above, we also have a synthetic CPU to deal with so we also have to interface between native routines and emulated 68k routines. I'm not trying to tell others how to deal with similar issues, only telling you what we used to do and what we currently do. I doubt that the routines we've come up with are directly useful to anyone but ourselves, but if anyone wants to look at them to get an idea of what we are doing, feel free to send me e-mail and I'll try to excise enough of what we do for it to make sense (although there's no documentation and we're also pretty busy over here). --Cliff ctm AT ardi DOT com